]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
iio: adc: ad7124: Really disable all channels at probe time
authorUwe Kleine-König <u.kleine-koenig@baylibre.com>
Tue, 4 Feb 2025 11:50:23 +0000 (12:50 +0100)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Sat, 8 Feb 2025 15:16:30 +0000 (15:16 +0000)
If one or more of the 16 channels are enabled and the driver is not
aware of that, unexpected things happen because different channels are
used than intended. To prevent that, all channels should be disabled at
probe time. In Commit 4be339af334c ("iio: adc: ad7124: Disable all
channels at probe time") I intended do that, however only the channels
that are potentially used by the driver and not all channels are
disabled since then. So disable all 16 channels and not only the used
ones.

Also fix the same issue in the .disable_all() callback.

Fixes: 4be339af334c ("iio: adc: ad7124: Disable all channels at probe time")
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com>
Link: https://patch.msgid.link/20250204115023.265813-2-u.kleine-koenig@baylibre.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/adc/ad7124.c

index 2fdeb32479522123668ff5c7f00a9c1f76ca3cdf..6bc418d388202c6f00e0e19c958bb336e24df158 100644 (file)
@@ -550,11 +550,10 @@ static int ad7124_disable_one(struct ad_sigma_delta *sd, unsigned int chan)
 
 static int ad7124_disable_all(struct ad_sigma_delta *sd)
 {
-       struct ad7124_state *st = container_of(sd, struct ad7124_state, sd);
        int ret;
        int i;
 
-       for (i = 0; i < st->num_channels; i++) {
+       for (i = 0; i < 16; i++) {
                ret = ad7124_disable_one(sd, i);
                if (ret < 0)
                        return ret;
@@ -1017,11 +1016,10 @@ 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);
        }
 
+       ad7124_disable_all(&st->sd);
+
        ret = ad_sd_write_reg(&st->sd, AD7124_ADC_CONTROL, 2, st->adc_control);
        if (ret < 0)
                return dev_err_probe(dev, ret, "Failed to setup CONTROL register\n");