Skip to content

Commit 1d9a21f

Browse files
dlechjic23
authored andcommitted
iio: adc: ad7173: fix calibration channel
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: 031bdc8 ("iio: adc: ad7173: add calibration support") Signed-off-by: David Lechner <[email protected]> Reviewed-by: Nuno Sá <[email protected]> Link: https://patch.msgid.link/20250708-iio-adc-ad7313-fix-calibration-channel-v1-1-e6174e2c7cbf@baylibre.com Cc: <[email protected]> Signed-off-by: Jonathan Cameron <[email protected]>
1 parent 92c2472 commit 1d9a21f

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

drivers/iio/adc/ad7173.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -391,13 +391,12 @@ static int ad7173_calibrate_all(struct ad7173_state *st, struct iio_dev *indio_d
391391
if (indio_dev->channels[i].type != IIO_VOLTAGE)
392392
continue;
393393

394-
ret = ad_sd_calibrate(&st->sd, AD7173_MODE_CAL_INT_ZERO, st->channels[i].ain);
394+
ret = ad_sd_calibrate(&st->sd, AD7173_MODE_CAL_INT_ZERO, i);
395395
if (ret < 0)
396396
return ret;
397397

398398
if (st->info->has_internal_fs_calibration) {
399-
ret = ad_sd_calibrate(&st->sd, AD7173_MODE_CAL_INT_FULL,
400-
st->channels[i].ain);
399+
ret = ad_sd_calibrate(&st->sd, AD7173_MODE_CAL_INT_FULL, i);
401400
if (ret < 0)
402401
return ret;
403402
}

0 commit comments

Comments
 (0)