]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
iio: adc: ad7124: fix temperature channel
authorDavid Lechner <dlechner@baylibre.com>
Fri, 10 Oct 2025 20:24:31 +0000 (15:24 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 6 Dec 2025 21:27:35 +0000 (06:27 +0900)
commit e2cc390a6629c76924a2740c54b144b9b28fca59 upstream.

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: 47036a03a303 ("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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/iio/adc/ad7124.c

index ed35d2a8bbf1b7cadd9e6522de04642311a4e9c4..57c0e5d80c73bc2e130c84f41ba5943db532e3d8 100644 (file)
@@ -1196,10 +1196,6 @@ static int __ad7124_calibrate_all(struct ad7124_state *st, struct iio_dev *indio
        int ret, i;
 
        for (i = 0; i < st->num_channels; i++) {
-
-               if (indio_dev->channels[i].type != IIO_VOLTAGE)
-                       continue;
-
                /*
                 * For calibration the OFFSET register should hold its reset default
                 * value. For the GAIN register there is no such requirement but
@@ -1209,6 +1205,14 @@ static int __ad7124_calibrate_all(struct ad7124_state *st, struct iio_dev *indio
                st->channels[i].cfg.calibration_offset = 0x800000;
                st->channels[i].cfg.calibration_gain = st->gain_default;
 
+               /*
+                * Only the main voltage input channels are important enough
+                * to be automatically calibrated here. For everything else,
+                * just use the default values set above.
+                */
+               if (indio_dev->channels[i].type != IIO_VOLTAGE)
+                       continue;
+
                /*
                 * Full-scale calibration isn't supported at gain 1, so skip in
                 * that case. Note that untypically full-scale calibration has