]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
iio: adc: ad7173: fix calibration channel
authorDavid Lechner <dlechner@baylibre.com>
Wed, 9 Jul 2025 01:38:33 +0000 (20:38 -0500)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Wed, 16 Jul 2025 07:47:42 +0000 (08:47 +0100)
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>
Link: https://patch.msgid.link/20250708-iio-adc-ad7313-fix-calibration-channel-v1-1-e6174e2c7cbf@baylibre.com
Cc: <Stable@vger.kernel.org>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/adc/ad7173.c

index 1f9e91a2e3f989e741f836c4b46bcea9e97e77ca..2173455c016962bc8f2e67cdc693da86bcaaf55d 100644 (file)
@@ -391,13 +391,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;
                }