]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
iio: adc: ad9467: add backend test mode helpers
authorNuno Sa <nuno.sa@analog.com>
Fri, 2 Aug 2024 14:27:05 +0000 (16:27 +0200)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Sat, 3 Aug 2024 13:36:45 +0000 (14:36 +0100)
Group the backend configurations to be done in preparing and stopping
calibration in two new helpers analogous to ad9467_testmode_set(). This
is in preparation for adding support for debugFS test_mode where
we need similar configurations as in the calibration process.

Signed-off-by: Nuno Sa <nuno.sa@analog.com>
Link: https://patch.msgid.link/20240802-dev-iio-backend-add-debugfs-v2-7-4cb62852f0d0@analog.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/adc/ad9467.c

index 557d98ca2f25f80c4c54e697b95dd70ed2438a77..2f4bbbd5611cdaca56b4f060cfaf9421982def34 100644 (file)
@@ -494,11 +494,49 @@ static int ad9467_testmode_set(struct ad9467_state *st, unsigned int chan,
                                AN877_ADC_TRANSFER_SYNC);
 }
 
-static int ad9647_calibrate_prepare(struct ad9467_state *st)
+static int ad9467_backend_testmode_on(struct ad9467_state *st,
+                                     unsigned int chan,
+                                     enum iio_backend_test_pattern pattern)
 {
        struct iio_backend_data_fmt data = {
                .enable = false,
        };
+       int ret;
+
+       ret = iio_backend_data_format_set(st->back, chan, &data);
+       if (ret)
+               return ret;
+
+       ret = iio_backend_test_pattern_set(st->back, chan, pattern);
+       if (ret)
+               return ret;
+
+       return iio_backend_chan_enable(st->back, chan);
+}
+
+static int ad9467_backend_testmode_off(struct ad9467_state *st,
+                                      unsigned int chan)
+{
+       struct iio_backend_data_fmt data = {
+               .enable = true,
+               .sign_extend = true,
+       };
+       int ret;
+
+       ret = iio_backend_chan_disable(st->back, chan);
+       if (ret)
+               return ret;
+
+       ret = iio_backend_test_pattern_set(st->back, chan,
+                                          IIO_BACKEND_NO_TEST_PATTERN);
+       if (ret)
+               return ret;
+
+       return iio_backend_data_format_set(st->back, chan, &data);
+}
+
+static int ad9647_calibrate_prepare(struct ad9467_state *st)
+{
        unsigned int c;
        int ret;
 
@@ -511,16 +549,8 @@ static int ad9647_calibrate_prepare(struct ad9467_state *st)
                if (ret)
                        return ret;
 
-               ret = iio_backend_data_format_set(st->back, c, &data);
-               if (ret)
-                       return ret;
-
-               ret = iio_backend_test_pattern_set(st->back, c,
-                                                  IIO_BACKEND_ADI_PRBS_9A);
-               if (ret)
-                       return ret;
-
-               ret = iio_backend_chan_enable(st->back, c);
+               ret = ad9467_backend_testmode_on(st, c,
+                                                IIO_BACKEND_ADI_PRBS_9A);
                if (ret)
                        return ret;
        }
@@ -601,24 +631,11 @@ static int ad9467_calibrate_apply(struct ad9467_state *st, unsigned int val)
 
 static int ad9647_calibrate_stop(struct ad9467_state *st)
 {
-       struct iio_backend_data_fmt data = {
-               .sign_extend = true,
-               .enable = true,
-       };
        unsigned int c, mode;
        int ret;
 
        for (c = 0; c < st->info->num_channels; c++) {
-               ret = iio_backend_chan_disable(st->back, c);
-               if (ret)
-                       return ret;
-
-               ret = iio_backend_test_pattern_set(st->back, c,
-                                                  IIO_BACKEND_NO_TEST_PATTERN);
-               if (ret)
-                       return ret;
-
-               ret = iio_backend_data_format_set(st->back, c, &data);
+               ret = ad9467_backend_testmode_off(st, c);
                if (ret)
                        return ret;