iio: ad9523: support for external signals via gpios
authorMichael Hennerich <michael.hennerich@analog.com>
Fri, 27 Jul 2018 06:41:09 +0000 (09:41 +0300)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Sat, 28 Jul 2018 09:41:14 +0000 (10:41 +0100)
The AD9523 supports external signals for power-down mode, resetting the
device and sync timing.
This change add support for specifying values for these signals via the
gpios and initializing them default values.

For the reset signal, the GPIO is toggled during probing to re-initialize
the device to a known state.

Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/frequency/ad9523.c

index 37504739c27797630d692eb74a773a6887d6c64c..38a8f73bd8d9c1eee5e395889cf62533c9b9b98e 100644 (file)
@@ -12,6 +12,7 @@
 #include <linux/sysfs.h>
 #include <linux/spi/spi.h>
 #include <linux/regulator/consumer.h>
+#include <linux/gpio/consumer.h>
 #include <linux/err.h>
 #include <linux/module.h>
 #include <linux/delay.h>
@@ -268,6 +269,9 @@ struct ad9523_state {
        struct regulator                *reg;
        struct ad9523_platform_data     *pdata;
        struct iio_chan_spec            ad9523_channels[AD9523_NUM_CHAN];
+       struct gpio_desc                *pwrdown_gpio;
+       struct gpio_desc                *reset_gpio;
+       struct gpio_desc                *sync_gpio;
 
        unsigned long           vcxo_freq;
        unsigned long           vco_freq;
@@ -988,6 +992,32 @@ static int ad9523_probe(struct spi_device *spi)
                        return ret;
        }
 
+       st->pwrdown_gpio = devm_gpiod_get_optional(&spi->dev, "powerdown",
+               GPIOD_OUT_HIGH);
+       if (IS_ERR(st->pwrdown_gpio)) {
+               ret = PTR_ERR(st->pwrdown_gpio);
+               goto error_disable_reg;
+       }
+
+       st->reset_gpio = devm_gpiod_get_optional(&spi->dev, "reset",
+               GPIOD_OUT_LOW);
+       if (IS_ERR(st->reset_gpio)) {
+               ret = PTR_ERR(st->reset_gpio);
+               goto error_disable_reg;
+       }
+
+       if (st->reset_gpio) {
+               udelay(1);
+               gpiod_direction_output(st->reset_gpio, 1);
+       }
+
+       st->sync_gpio = devm_gpiod_get_optional(&spi->dev, "sync",
+               GPIOD_OUT_HIGH);
+       if (IS_ERR(st->sync_gpio)) {
+               ret = PTR_ERR(st->sync_gpio);
+               goto error_disable_reg;
+       }
+
        spi_set_drvdata(spi, indio_dev);
        st->spi = spi;
        st->pdata = pdata;