mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] iio: adc: ltc2471: Fix LTC2473 differential offset
@ 2026-11-09 10:06 raoxu
  2026-11-09 12:12 ` Joshua Crofts
  0 siblings, 1 reply; 3+ messages in thread
From: raoxu @ 2026-11-09 10:06 UTC (permalink / raw)
  To: jic23
  Cc: dlechner, nuno.sa, andy, luiz.von.dentz, brgl, pmenzel, pengpeng,
	u.kleine-koenig, raoxu, lars, mike.looijmans, linux-iio,
	linux-kernel, stable

From: Xu Rao <raoxu@uniontech.com>

The LTC2473 reports its differential conversion result as an unsigned
16-bit value spanning -VREF to +VREF. The IIO scale is consequently
reported as 2 * VREF divided by 2^16.

IIO offsets are expressed in raw codes, but the driver currently returns
-LTC2471_VREF, which is a millivolt value. This makes the processed
reading incorrect: with a 1.25 V reference, the midpoint raw code is
shifted by 1250 instead of 32768 codes.

Return the raw-code offset so that the midpoint maps to 0 mV and the
endpoints map to -VREF and +VREF as intended. The single-ended LTC2471
does not expose the offset attribute and is unaffected.

The supplied fix was reviewed and this commit message prepared with
OpenCode AI assistance.

Fixes: 1d3eacbfa644 ("iio: Add LTC2471/LTC2473 driver")
Signed-off-by: Xu Rao <raoxu@uniontech.com>
Cc: stable@vger.kernel.org
---
Changes in v2:
- Replace the raw -32768 literal with the named LTC2473_DIFF_OFFSET
  macro.

 drivers/iio/adc/ltc2471.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/iio/adc/ltc2471.c b/drivers/iio/adc/ltc2471.c
index 369af700969f..eb418c0fa732 100644
--- a/drivers/iio/adc/ltc2471.c
+++ b/drivers/iio/adc/ltc2471.c
@@ -25,6 +25,7 @@ struct ltc2471_data {

 /* Reference voltage is 1.25V */
 #define LTC2471_VREF 1250
+#define LTC2473_DIFF_OFFSET (-32768)

 /* Read two bytes from the I2C bus to obtain the ADC result */
 static int ltc2471_get_value(struct i2c_client *client)
@@ -69,7 +70,7 @@ static int ltc2471_read_raw(struct iio_dev *indio_dev,

 	case IIO_CHAN_INFO_OFFSET:
 		/* Only differential chip has this property */
-		*val = -LTC2471_VREF;
+		*val = LTC2473_DIFF_OFFSET;
 		return IIO_VAL_INT;

 	default:
--
2.50.1

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] iio: adc: ltc2471: Fix LTC2473 differential offset
  2026-11-09 10:06 [PATCH v2] iio: adc: ltc2471: Fix LTC2473 differential offset raoxu
@ 2026-11-09 12:12 ` Joshua Crofts
  2026-11-09 17:31   ` Andy Shevchenko
  0 siblings, 1 reply; 3+ messages in thread
From: Joshua Crofts @ 2026-11-09 12:12 UTC (permalink / raw)
  To: raoxu
  Cc: jic23, dlechner, nuno.sa, andy, luiz.von.dentz, brgl, pmenzel,
	pengpeng, u.kleine-koenig, lars, mike.looijmans, linux-iio,
	linux-kernel, stable

On Mon,  9 Nov 2026 18:06:59 +0800
raoxu <raoxu@uniontech.com> wrote:

> From: Xu Rao <raoxu@uniontech.com>
> 
> The LTC2473 reports its differential conversion result as an unsigned
> 16-bit value spanning -VREF to +VREF. The IIO scale is consequently
> reported as 2 * VREF divided by 2^16.
> 
> IIO offsets are expressed in raw codes, but the driver currently returns
> -LTC2471_VREF, which is a millivolt value. This makes the processed
> reading incorrect: with a 1.25 V reference, the midpoint raw code is
> shifted by 1250 instead of 32768 codes.
> 
> Return the raw-code offset so that the midpoint maps to 0 mV and the
> endpoints map to -VREF and +VREF as intended. The single-ended LTC2471
> does not expose the offset attribute and is unaffected.
> 
> The supplied fix was reviewed and this commit message prepared with
> OpenCode AI assistance.
> 
> Fixes: 1d3eacbfa644 ("iio: Add LTC2471/LTC2473 driver")
> Signed-off-by: Xu Rao <raoxu@uniontech.com>
> Cc: stable@vger.kernel.org
> ---

Looks fine, but please wait at least 24 hours before sending a
new version. If you spot an issue after sending the patch, please
reply to it describing the problem.

Reviewed-by: Joshua Crofts <crofts@kernel.org>

-- 
Kind regards,
Joshua Crofts

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] iio: adc: ltc2471: Fix LTC2473 differential offset
  2026-11-09 12:12 ` Joshua Crofts
@ 2026-11-09 17:31   ` Andy Shevchenko
  0 siblings, 0 replies; 3+ messages in thread
From: Andy Shevchenko @ 2026-11-09 17:31 UTC (permalink / raw)
  To: Joshua Crofts
  Cc: raoxu, jic23, dlechner, nuno.sa, andy, luiz.von.dentz, brgl,
	pmenzel, pengpeng, u.kleine-koenig, lars, mike.looijmans,
	linux-iio, linux-kernel, stable

On Mon, Nov 09, 2026 at 01:12:08PM +0100, Joshua Crofts wrote:
> On Mon,  9 Nov 2026 18:06:59 +0800
> raoxu <raoxu@uniontech.com> wrote:
> 
> > The LTC2473 reports its differential conversion result as an unsigned
> > 16-bit value spanning -VREF to +VREF. The IIO scale is consequently
> > reported as 2 * VREF divided by 2^16.
> > 
> > IIO offsets are expressed in raw codes, but the driver currently returns
> > -LTC2471_VREF, which is a millivolt value. This makes the processed
> > reading incorrect: with a 1.25 V reference, the midpoint raw code is
> > shifted by 1250 instead of 32768 codes.
> > 
> > Return the raw-code offset so that the midpoint maps to 0 mV and the
> > endpoints map to -VREF and +VREF as intended. The single-ended LTC2471
> > does not expose the offset attribute and is unaffected.
> > 
> > The supplied fix was reviewed and this commit message prepared with
> > OpenCode AI assistance.
> > 
> > Fixes: 1d3eacbfa644 ("iio: Add LTC2471/LTC2473 driver")
> > Signed-off-by: Xu Rao <raoxu@uniontech.com>
> > Cc: stable@vger.kernel.org
> > ---
> 
> Looks fine, but please wait at least 24 hours before sending a
> new version. If you spot an issue after sending the patch, please
> reply to it describing the problem.

Yep, it misses tag from Nuno now. So, v3 with changelog and all tags please!
Easy to get if you use `b4` for that.

> Reviewed-by: Joshua Crofts <crofts@kernel.org>

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-09 17:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-09 10:06 [PATCH v2] iio: adc: ltc2471: Fix LTC2473 differential offset raoxu
2026-11-09 12:12 ` Joshua Crofts
2026-11-09 17:31   ` Andy Shevchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®