From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 67EBD2DAFA5; Sat, 30 Aug 2025 18:43:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756579401; cv=none; b=iVnCj6yEvH+IxpDOgT2jp5q2ZojShwEpf0lDA5j9oA+RmYXjd0IbkcGpRTp6rGwW6YkbRKlpKUnc55uljCyM9beR8Uz9IOd81jS6a9b/PanAWkR48jTavHcRJ8FuwzsOTQhK+9CIMCI2RFPhjZGKBbuGwYQfHEBZwRhCc8uPyss= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756579401; c=relaxed/simple; bh=0/4i5sW5GYY43WWd8JCcpS/pAorDT72EtPMpDi0pbLs=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=nLf0QLbUQtKD67UomXkbXfA7AIoMlX4+3Jeoxsx5bCQXtinKLQJVvNTl3koIICFwymi8xA1oaCf+90886YwucusBB9tWq8pvEZuhecPDVuOwAoV9TUo1BgxXZhPszaa5ASEPSxMiyQ7R1l76/5kC6CKadhIQlPhqZ13pTWd8S7M= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hZpxBXs7; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="hZpxBXs7" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 63DACC4CEF1; Sat, 30 Aug 2025 18:43:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756579401; bh=0/4i5sW5GYY43WWd8JCcpS/pAorDT72EtPMpDi0pbLs=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=hZpxBXs7cohSvfKdWaw/D65K8ETuNQ91Ii3IKaomU/bGjTEgrB6KAKUe0sjuvPc7O Ox91lKmqCXqVsesTPjxsZImlJl4aCDXCpQUy54JiRhG1iOzkzOnqMLoFZtohhUKehy Zz2BHtPFtQUqiD461d6CEWuDzXyoNAoAR8MOjNioHQLRKr+zfDwZ7I+kFgcB2QLhqy PU0dI1Y+LTLwulxGFfppoZa0qwlSyFyWKKRu4NsmFwwWkPgeQA/TRex5BKQ4qAEovk QQ+YiGYQSq8YhIzjYg0SdjABh1e9/RE+4ZG01GrWH/Nw4FUma0HtOFAmcQjTwtgUPy aiGrbZuARHfTw== Date: Sat, 30 Aug 2025 19:43:08 +0100 From: Jonathan Cameron To: Marcelo Schmitt Cc: , , , , , , , , , , , , , , , , , , Subject: Re: [PATCH 01/15] iio: adc: ad4030: Fix _scale for when oversampling is enabled Message-ID: <20250830194308.32def0e5@jic23-huawei> In-Reply-To: References: X-Mailer: Claws Mail 4.3.1 (GTK 3.24.50; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: linux-doc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Fri, 29 Aug 2025 21:40:24 -0300 Marcelo Schmitt wrote: > Previously, the AD4030 driver was using the number of scan realbits for the > voltage channel to derive the scale to millivolts. Though, when sample > averaging is enabled (oversampling_ratio > 1), the number of scan realbits > for the channel is set to 30 and doesn't match the amount of conversion > precision bits. Due to that, the calculated channel scale did not correctly > scale raw sample data to millivolt units in those cases. Use chip specific > precision bits to derive the correct channel _scale on every and all > channel configuration. > > Fixes: dc78e71d7c15 ("iio: adc: ad4030: remove some duplicate code") > Signed-off-by: Marcelo Schmitt Hi Marcelo I was assuming that when this said 'averaging' it actually meant summing (there is a note about using the upper precision bits to get the same scaling which is what we'd expect it were simply summing over X samples). So given that we don't divide back down to get the original scaling I'm not following how this works. E.g. If we 'averaged' just 2 values of 3 then we'd go from a value of 3 to one of 6. Therefore I'd expect the scale to halve as each lsb represents half the voltage it did when we weren't averaging those 2 samples. I think that is what we'd see with the current code, so my reasoning is clearly wrong, but why? Jonathan > --- > This was probalby buggy since > commit 949abd1ca5a4 ("iio: adc: ad4030: add averaging support") > but I decided to set the fixes tag with dc78e71d7c15 because this patch will > not apply cleanly over 949abd1ca5a4. > > drivers/iio/adc/ad4030.c | 9 ++++++++- > 1 file changed, 8 insertions(+), 1 deletion(-) > > diff --git a/drivers/iio/adc/ad4030.c b/drivers/iio/adc/ad4030.c > index 1bc2f9a22470..82784593f976 100644 > --- a/drivers/iio/adc/ad4030.c > +++ b/drivers/iio/adc/ad4030.c > @@ -394,7 +394,14 @@ static int ad4030_get_chan_scale(struct iio_dev *indio_dev, > else > *val = st->vref_uv / MILLI; > > - *val2 = scan_type->realbits; > + /* > + * Even though the sample data comes in a 30-bit chunk when the ADC > + * is averaging samples, the conversion precision is still 16-bit or > + * 24-bit depending on the device. Thus, instead of scan_type->realbits, > + * use chip specific precision bits to derive the correct scale to mV. > + */ > + *val2 = scan_type->realbits == 30 ? st->chip->precision_bits > + : scan_type->realbits; > > return IIO_VAL_FRACTIONAL_LOG2; > }