Skip to content

Commit e2cc390

Browse files
dlechjic23
authored andcommitted
iio: adc: ad7124: fix temperature channel
Fix temperature channel not working due to gain and offset not being initialized. For channels other than the voltage ones calibration is skipped (which is OK). However that results in the calibration register values tracked in st->channels[i].cfg all being zero. These zeros are later written to hardware before a measurement is made which caused the raw temperature readings to be always 8388608 (0x800000). To fix it, we just make sure the gain and offset values are set to the default values and still return early without doing an internal calibration. While here, add a comment explaining why we don't bother calibrating the temperature channel. Fixes: 47036a0 ("iio: adc: ad7124: Implement internal calibration at probe time") Reviewed-by: Marcelo Schmitt <marcelo.schmitt@analog.com> Signed-off-by: David Lechner <dlechner@baylibre.com> Reviewed-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com> Cc: <Stable@vger.kernel.org> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
1 parent 2155325 commit e2cc390

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

drivers/iio/adc/ad7124.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,10 +1525,6 @@ static int __ad7124_calibrate_all(struct ad7124_state *st, struct iio_dev *indio
15251525
int ret, i;
15261526

15271527
for (i = 0; i < st->num_channels; i++) {
1528-
1529-
if (indio_dev->channels[i].type != IIO_VOLTAGE)
1530-
continue;
1531-
15321528
/*
15331529
* For calibration the OFFSET register should hold its reset default
15341530
* value. For the GAIN register there is no such requirement but
@@ -1538,6 +1534,14 @@ static int __ad7124_calibrate_all(struct ad7124_state *st, struct iio_dev *indio
15381534
st->channels[i].cfg.calibration_offset = 0x800000;
15391535
st->channels[i].cfg.calibration_gain = st->gain_default;
15401536

1537+
/*
1538+
* Only the main voltage input channels are important enough
1539+
* to be automatically calibrated here. For everything else,
1540+
* just use the default values set above.
1541+
*/
1542+
if (indio_dev->channels[i].type != IIO_VOLTAGE)
1543+
continue;
1544+
15411545
/*
15421546
* Full-scale calibration isn't supported at gain 1, so skip in
15431547
* that case. Note that untypically full-scale calibration has

0 commit comments

Comments
 (0)