Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2223460rwd; Sun, 28 May 2023 10:36:56 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6gd4l3wmNdDUXjUN1Spc4+5n+08DFlmmI8gBh4N1qQ0F5kuvsn1U8CV6grJ1Kvh8bCKNLK X-Received: by 2002:a17:902:e752:b0:1ac:40f7:8b52 with SMTP id p18-20020a170902e75200b001ac40f78b52mr9183417plf.64.1685295416028; Sun, 28 May 2023 10:36:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685295416; cv=none; d=google.com; s=arc-20160816; b=SgAqiquKFycLh32UTtMac/ojfRJ+9WvAfpaBlpVHqQOeUpmyQGyISPSRcDSxz5FQ+M uEgCd1iNck1wtZoFMZleaz1d6AYxGa5nM4OpHhwZJR5jaKhWlvH1knkNrrCHDoV15WbO IiwKVVgBURJfGYLKJQD9VoByMTo2TyDRo+Rknh0cL1gwDB5CM+5JNWz2g53m2s+ODx84 JyodEd/1p7Wxt8M+O7nnunB5WPFUP9xSB/0tTw6TjRd9O8quaD66CC2BNnImSO1/o9Sz SY1iSQDbca1USkA6lV0lWKEGLEPEtNWJQClLOHcg3CERUkapg9J6/qTenQpt0RLFzVTA 1Bwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=iwjJoEpu+a7OCv+0+pq68k0lfHSQ9DD0Nbhe3P8/u+8=; b=RaRBl3/qCHgJ2jyLEM9Xka08H8O3+UXVchsv52F9Hzg/n0BIve9BF8l8RoRftPhZ1L a34ZsLpCJDm517sPnUgTzkvbdumHmN2DPZJorAzuRi+ccUsh0aZOnwMz4gTDvQGSInjR 7STNamCcFSNoeKlLrZze/KTFImdxeWfdlFEnJqRJrdmCelnSwAA4jIclS1kUcXIIC3Ic MmygxnpW4Eqd6543vZTvp17BouFLea3o7uHVpFfAaX5xWSKIE9mnScbDBrVm4+aWg61y xbJgJ07NHgKJGSa/q8+o24dH2muVDwcJQkCppUKNsZK8s0u3MB1zmuRDvgNtVXOLTTzq Dcxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=UXtD9ZFB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jk16-20020a170903331000b001ae141947acsi940073plb.183.2023.05.28.10.36.39; Sun, 28 May 2023 10:36:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=UXtD9ZFB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229527AbjE1RdT (ORCPT + 99 others); Sun, 28 May 2023 13:33:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42528 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229448AbjE1RdT (ORCPT ); Sun, 28 May 2023 13:33:19 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7AC1BD; Sun, 28 May 2023 10:33:17 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 70B6160DFC; Sun, 28 May 2023 17:33:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 33080C433EF; Sun, 28 May 2023 17:33:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685295196; bh=qzJfjzEEjZiZQ5UutuKr+0+hvV5RgYLuzJPm3/PtkBE=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=UXtD9ZFB/1BoG67nX257ClGZvhetKEoCIktc3yq7ycXgBpJJi1/C9aoLCes39jG8R fPgYnl0X49kJEyTZ10gYxvKqMhFNsBii/GEl6qKVrEgMy82whBIvqSzCjiiUJQ4cmj eiIQbMT4PyKROjCcoMrchGNdGPErG6DwXzSN1hvkf/Vm9uslvb+8O9YwygTqazfXgi exaFiXwTEP25yWd+LHL+VSRN8TI8gWL5fan9NHmhVRO5EpPWp11kVsOA8SxII55xwC /L2G/NN7bJC7YRGZHQ4T3CO7wPrYpVstgUeCgkAPnQRWIiaDC27VGU0+sj6aF7opRN i5poptqSBLXJg== Date: Sun, 28 May 2023 18:49:35 +0100 From: Jonathan Cameron To: Artur Rojek Cc: Paul Cercueil , Dmitry Torokhov , Chris Morgan , Andy Shevchenko , linux-mips@vger.kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-input@vger.kernel.org Subject: Re: [PATCH v2 1/2] iio/adc: ingenic: Fix channel offsets in buffer Message-ID: <20230528184935.15dd91fa@jic23-huawei> In-Reply-To: <20230521225901.388455-2-contact@artur-rojek.eu> References: <20230521225901.388455-1-contact@artur-rojek.eu> <20230521225901.388455-2-contact@artur-rojek.eu> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 22 May 2023 00:59:00 +0200 Artur Rojek wrote: > Consumers expect the buffer to only contain enabled channels. While > preparing the buffer, the driver makes two mistakes: > 1) It inserts empty data for disabled channels. > 2) Each ADC readout contains samples for two 16-bit channels. If either > of them is active, the whole 32-bit sample is pushed into the buffer > as-is. > > Both of those issues cause the active channels to appear at the wrong > offsets in the buffer. Fix the above by demuxing samples for active > channels only. > > This has remained unnoticed, as all the consumers so far were only using > channels 0 and 1, leaving them unaffected by changes introduced in this > commit. > > Signed-off-by: Artur Rojek > Tested-by: Paul Cercueil Lazy me suggestions that, as we didn't notice this before, clearly the vast majority of times the channels are both enabled. As such you 'could' just set available_scan_masks and burn the overhead of reading channels you don't want, instead letting the IIO core demux deal with the data movement if needed. > --- > > v2: - demux active channels from ADC readouts > - clarify in the commit description that this patch doesn't impact > existing consumers of this driver > > drivers/iio/adc/ingenic-adc.c | 20 +++++++++++++------- > 1 file changed, 13 insertions(+), 7 deletions(-) > > diff --git a/drivers/iio/adc/ingenic-adc.c b/drivers/iio/adc/ingenic-adc.c > index a7325dbbb99a..093710a7ad4c 100644 > --- a/drivers/iio/adc/ingenic-adc.c > +++ b/drivers/iio/adc/ingenic-adc.c > @@ -802,13 +802,19 @@ static irqreturn_t ingenic_adc_irq(int irq, void *data) > struct ingenic_adc *adc = iio_priv(iio_dev); > unsigned long mask = iio_dev->active_scan_mask[0]; > unsigned int i; > - u32 tdat[3]; > - > - for (i = 0; i < ARRAY_SIZE(tdat); mask >>= 2, i++) { > - if (mask & 0x3) > - tdat[i] = readl(adc->base + JZ_ADC_REG_ADTCH); > - else > - tdat[i] = 0; > + u16 tdat[6]; > + u32 val; > + > + memset(tdat, 0, ARRAY_SIZE(tdat)); > + for (i = 0; mask && i < ARRAY_SIZE(tdat); mask >>= 2) { > + if (mask & 0x3) { > + val = readl(adc->base + JZ_ADC_REG_ADTCH); > + /* Two channels per sample. Demux active. */ > + if (mask & BIT(0)) > + tdat[i++] = val & 0xffff; > + if (mask & BIT(1)) > + tdat[i++] = val >> 16; > + } > } > > iio_push_to_buffers(iio_dev, tdat);