* [PATCH] iio: adc: ad7313: fix calibration channel
@ 2025-07-09 1:38 David Lechner
2025-07-09 9:33 ` Nuno Sá
0 siblings, 1 reply; 4+ messages in thread
From: David Lechner @ 2025-07-09 1:38 UTC (permalink / raw)
To: Michael Hennerich, Jonathan Cameron, Nuno Sá,
Andy Shevchenko, Guillaume Ranquet
Cc: Jonathan Cameron, linux-iio, linux-kernel, David Lechner
Fix the channel index values passed to ad_sd_calibrate() in
ad7173_calibrate_all().
ad7173_calibrate_all() expects these values to be that of the CHANNELx
register assigned to the channel, not the datasheet INPUTx number of the
channel. The incorrect values were causing register writes to fail for
some channels because they set the WEN bit that must always be 0 for
register access and set the R/W bit to read instead of write. For other
channels, the channel number was just wrong because the CHANNELx
registers are generally assigned in reverse order and so almost never
match the INPUTx numbers.
Fixes: 031bdc8aee01 ("iio: adc: ad7173: add calibration support")
Signed-off-by: David Lechner <dlechner@baylibre.com>
---
drivers/iio/adc/ad7173.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/drivers/iio/adc/ad7173.c b/drivers/iio/adc/ad7173.c
index c41bc5b9ac597f57eea6a097cc3a118de7b42210..61749586670d4f0730ca423d6e4c0ee1bf19edfa 100644
--- a/drivers/iio/adc/ad7173.c
+++ b/drivers/iio/adc/ad7173.c
@@ -392,13 +392,12 @@ static int ad7173_calibrate_all(struct ad7173_state *st, struct iio_dev *indio_d
if (indio_dev->channels[i].type != IIO_VOLTAGE)
continue;
- ret = ad_sd_calibrate(&st->sd, AD7173_MODE_CAL_INT_ZERO, st->channels[i].ain);
+ ret = ad_sd_calibrate(&st->sd, AD7173_MODE_CAL_INT_ZERO, i);
if (ret < 0)
return ret;
if (st->info->has_internal_fs_calibration) {
- ret = ad_sd_calibrate(&st->sd, AD7173_MODE_CAL_INT_FULL,
- st->channels[i].ain);
+ ret = ad_sd_calibrate(&st->sd, AD7173_MODE_CAL_INT_FULL, i);
if (ret < 0)
return ret;
}
---
base-commit: 2233378a8c606f7f6893d4c16aa6eb6fea027a52
change-id: 20250708-iio-adc-ad7313-fix-calibration-channel-198ed65d9b0a
Best regards,
--
David Lechner <dlechner@baylibre.com>
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] iio: adc: ad7313: fix calibration channel
2025-07-09 1:38 [PATCH] iio: adc: ad7313: fix calibration channel David Lechner
@ 2025-07-09 9:33 ` Nuno Sá
2025-07-09 15:58 ` Jonathan Cameron
0 siblings, 1 reply; 4+ messages in thread
From: Nuno Sá @ 2025-07-09 9:33 UTC (permalink / raw)
To: David Lechner, Michael Hennerich, Jonathan Cameron, Nuno Sá,
Andy Shevchenko, Guillaume Ranquet
Cc: Jonathan Cameron, linux-iio, linux-kernel
On Tue, 2025-07-08 at 20:38 -0500, David Lechner wrote:
> Fix the channel index values passed to ad_sd_calibrate() in
> ad7173_calibrate_all().
>
> ad7173_calibrate_all() expects these values to be that of the CHANNELx
> register assigned to the channel, not the datasheet INPUTx number of the
> channel. The incorrect values were causing register writes to fail for
> some channels because they set the WEN bit that must always be 0 for
> register access and set the R/W bit to read instead of write. For other
> channels, the channel number was just wrong because the CHANNELx
> registers are generally assigned in reverse order and so almost never
> match the INPUTx numbers.
>
> Fixes: 031bdc8aee01 ("iio: adc: ad7173: add calibration support")
> Signed-off-by: David Lechner <dlechner@baylibre.com>
> ---
Reviewed-by: Nuno Sá <nuno.sa@analog.com>
> drivers/iio/adc/ad7173.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/iio/adc/ad7173.c b/drivers/iio/adc/ad7173.c
> index
> c41bc5b9ac597f57eea6a097cc3a118de7b42210..61749586670d4f0730ca423d6e4c0ee1bf19
> edfa 100644
> --- a/drivers/iio/adc/ad7173.c
> +++ b/drivers/iio/adc/ad7173.c
> @@ -392,13 +392,12 @@ static int ad7173_calibrate_all(struct ad7173_state *st,
> struct iio_dev *indio_d
> if (indio_dev->channels[i].type != IIO_VOLTAGE)
> continue;
>
> - ret = ad_sd_calibrate(&st->sd, AD7173_MODE_CAL_INT_ZERO, st-
> >channels[i].ain);
> + ret = ad_sd_calibrate(&st->sd, AD7173_MODE_CAL_INT_ZERO, i);
> if (ret < 0)
> return ret;
>
> if (st->info->has_internal_fs_calibration) {
> - ret = ad_sd_calibrate(&st->sd,
> AD7173_MODE_CAL_INT_FULL,
> - st->channels[i].ain);
> + ret = ad_sd_calibrate(&st->sd,
> AD7173_MODE_CAL_INT_FULL, i);
> if (ret < 0)
> return ret;
> }
>
> ---
> base-commit: 2233378a8c606f7f6893d4c16aa6eb6fea027a52
> change-id: 20250708-iio-adc-ad7313-fix-calibration-channel-198ed65d9b0a
>
> Best regards,
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] iio: adc: ad7313: fix calibration channel
2025-07-09 9:33 ` Nuno Sá
@ 2025-07-09 15:58 ` Jonathan Cameron
2025-07-10 22:03 ` David Lechner
0 siblings, 1 reply; 4+ messages in thread
From: Jonathan Cameron @ 2025-07-09 15:58 UTC (permalink / raw)
To: Nuno Sá
Cc: David Lechner, Michael Hennerich, Nuno Sá, Andy Shevchenko,
Guillaume Ranquet, Jonathan Cameron, linux-iio, linux-kernel
On Wed, 09 Jul 2025 10:33:32 +0100
Nuno Sá <noname.nuno@gmail.com> wrote:
> On Tue, 2025-07-08 at 20:38 -0500, David Lechner wrote:
> > Fix the channel index values passed to ad_sd_calibrate() in
> > ad7173_calibrate_all().
> >
> > ad7173_calibrate_all() expects these values to be that of the CHANNELx
> > register assigned to the channel, not the datasheet INPUTx number of the
> > channel. The incorrect values were causing register writes to fail for
> > some channels because they set the WEN bit that must always be 0 for
> > register access and set the R/W bit to read instead of write. For other
> > channels, the channel number was just wrong because the CHANNELx
> > registers are generally assigned in reverse order and so almost never
> > match the INPUTx numbers.
> >
> > Fixes: 031bdc8aee01 ("iio: adc: ad7173: add calibration support")
> > Signed-off-by: David Lechner <dlechner@baylibre.com>
> > ---
>
> Reviewed-by: Nuno Sá <nuno.sa@analog.com>
>
Applied to the fixes-togreg branch of iio.git.
> > drivers/iio/adc/ad7173.c | 5 ++---
> > 1 file changed, 2 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/iio/adc/ad7173.c b/drivers/iio/adc/ad7173.c
> > index
> > c41bc5b9ac597f57eea6a097cc3a118de7b42210..61749586670d4f0730ca423d6e4c0ee1bf19
> > edfa 100644
> > --- a/drivers/iio/adc/ad7173.c
> > +++ b/drivers/iio/adc/ad7173.c
> > @@ -392,13 +392,12 @@ static int ad7173_calibrate_all(struct ad7173_state *st,
> > struct iio_dev *indio_d
> > if (indio_dev->channels[i].type != IIO_VOLTAGE)
> > continue;
> >
> > - ret = ad_sd_calibrate(&st->sd, AD7173_MODE_CAL_INT_ZERO, st-
> > >channels[i].ain);
> > + ret = ad_sd_calibrate(&st->sd, AD7173_MODE_CAL_INT_ZERO, i);
> > if (ret < 0)
> > return ret;
> >
> > if (st->info->has_internal_fs_calibration) {
> > - ret = ad_sd_calibrate(&st->sd,
> > AD7173_MODE_CAL_INT_FULL,
> > - st->channels[i].ain);
> > + ret = ad_sd_calibrate(&st->sd,
> > AD7173_MODE_CAL_INT_FULL, i);
> > if (ret < 0)
> > return ret;
> > }
> >
> > ---
> > base-commit: 2233378a8c606f7f6893d4c16aa6eb6fea027a52
> > change-id: 20250708-iio-adc-ad7313-fix-calibration-channel-198ed65d9b0a
> >
> > Best regards,
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] iio: adc: ad7313: fix calibration channel
2025-07-09 15:58 ` Jonathan Cameron
@ 2025-07-10 22:03 ` David Lechner
0 siblings, 0 replies; 4+ messages in thread
From: David Lechner @ 2025-07-10 22:03 UTC (permalink / raw)
To: Jonathan Cameron, Nuno Sá
Cc: Michael Hennerich, Nuno Sá, Andy Shevchenko,
Guillaume Ranquet, Jonathan Cameron, linux-iio, linux-kernel
On 7/9/25 10:58 AM, Jonathan Cameron wrote:
> On Wed, 09 Jul 2025 10:33:32 +0100
> Nuno Sá <noname.nuno@gmail.com> wrote:
>
>> On Tue, 2025-07-08 at 20:38 -0500, David Lechner wrote:
>>> Fix the channel index values passed to ad_sd_calibrate() in
>>> ad7173_calibrate_all().
>>>
>>> ad7173_calibrate_all() expects these values to be that of the CHANNELx
>>> register assigned to the channel, not the datasheet INPUTx number of the
>>> channel. The incorrect values were causing register writes to fail for
>>> some channels because they set the WEN bit that must always be 0 for
>>> register access and set the R/W bit to read instead of write. For other
>>> channels, the channel number was just wrong because the CHANNELx
>>> registers are generally assigned in reverse order and so almost never
>>> match the INPUTx numbers.
>>>
>>> Fixes: 031bdc8aee01 ("iio: adc: ad7173: add calibration support")
>>> Signed-off-by: David Lechner <dlechner@baylibre.com>
>>> ---
>>
>> Reviewed-by: Nuno Sá <nuno.sa@analog.com>
>>
> Applied to the fixes-togreg branch of iio.git.
>
Just noticed a typo in the subject. Should be ad7173, not ad7313.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-07-10 22:03 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-09 1:38 [PATCH] iio: adc: ad7313: fix calibration channel David Lechner
2025-07-09 9:33 ` Nuno Sá
2025-07-09 15:58 ` Jonathan Cameron
2025-07-10 22:03 ` David Lechner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox