iio: adc: ad7606: Add debug mode for ad7616
authorBeniamin Bia <beniamin.bia@analog.com>
Thu, 18 Jul 2019 06:27:34 +0000 (09:27 +0300)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Sun, 28 Jul 2019 07:56:45 +0000 (08:56 +0100)
Support for register access was added for devices which have software
mode.

Signed-off-by: Beniamin Bia <beniamin.bia@analog.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/adc/ad7606.c

index be2330c8b2773a5eadaeb1df534d611a1dd19186..ed2d08437e5da52f03333f6562a66584c4457e3a 100644 (file)
@@ -60,6 +60,29 @@ static int ad7606_reset(struct ad7606_state *st)
        return -ENODEV;
 }
 
+static int ad7606_reg_access(struct iio_dev *indio_dev,
+                            unsigned int reg,
+                            unsigned int writeval,
+                            unsigned int *readval)
+{
+       struct ad7606_state *st = iio_priv(indio_dev);
+       int ret;
+
+       mutex_lock(&st->lock);
+       if (readval) {
+               ret = st->bops->reg_read(st, reg);
+               if (ret < 0)
+                       goto err_unlock;
+               *readval = ret;
+               ret = 0;
+       } else {
+               ret = st->bops->reg_write(st, reg, writeval);
+       }
+err_unlock:
+       mutex_unlock(&st->lock);
+       return ret;
+}
+
 static int ad7606_read_samples(struct ad7606_state *st)
 {
        unsigned int num = st->chip_info->num_channels;
@@ -501,6 +524,14 @@ static const struct iio_info ad7606_info_os_and_range = {
        .validate_trigger = &ad7606_validate_trigger,
 };
 
+static const struct iio_info ad7606_info_os_range_and_debug = {
+       .read_raw = &ad7606_read_raw,
+       .write_raw = &ad7606_write_raw,
+       .debugfs_reg_access = &ad7606_reg_access,
+       .attrs = &ad7606_attribute_group_os_and_range,
+       .validate_trigger = &ad7606_validate_trigger,
+};
+
 static const struct iio_info ad7606_info_os = {
        .read_raw = &ad7606_read_raw,
        .write_raw = &ad7606_write_raw,
@@ -617,7 +648,7 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
 
                /* After reset, in software mode, ±10 V is set by default */
                memset32(st->range, 2, ARRAY_SIZE(st->range));
-               indio_dev->info = &ad7606_info_os_and_range;
+               indio_dev->info = &ad7606_info_os_range_and_debug;
 
                ret = st->bops->sw_mode_config(indio_dev);
                if (ret < 0)