]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
iio: adc: ad7124: Disable all channels at probe time
authorUwe Kleine-König <u.kleine-koenig@baylibre.com>
Mon, 4 Nov 2024 10:19:04 +0000 (11:19 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 17 Jan 2025 12:34:47 +0000 (13:34 +0100)
commit 4be339af334c283a1a1af3cb28e7e448a0aa8a7c upstream.

When during a measurement two channels are enabled, two measurements are
done that are reported sequencially in the DATA register. As the code
triggered by reading one of the sysfs properties expects that only one
channel is enabled it only reads the first data set which might or might
not belong to the intended channel.

To prevent this situation disable all channels during probe. This fixes
a problem in practise because the reset default for channel 0 is
enabled. So all measurements before the first measurement on channel 0
(which disables channel 0 at the end) might report wrong values.

Fixes: 7b8d045e497a ("iio: adc: ad7124: allow more than 8 channels")
Reviewed-by: Nuno Sa <nuno.sa@analog.com>
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com>
Link: https://patch.msgid.link/20241104101905.845737-2-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 0d0884d3b246000fb2a421871797a58aef6426c6..5d4abe81d2a2b4e9aabd73a444233937b859d23b 100644 (file)
@@ -931,6 +931,9 @@ static int ad7124_setup(struct ad7124_state *st)
                 * set all channels to this default value.
                 */
                ad7124_set_channel_odr(st, i, 10);
+
+               /* Disable all channels to prevent unintended conversions. */
+               ad_sd_write_reg(&st->sd, AD7124_CHANNEL(i), 2, 0);
        }
 
        return ret;