linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iio: ad9523: support for external signals via gpios
@ 2018-07-27  6:41 Alexandru Ardelean
  2018-07-28  9:45 ` Jonathan Cameron
  0 siblings, 1 reply; 2+ messages in thread
From: Alexandru Ardelean @ 2018-07-27  6:41 UTC (permalink / raw)
  To: linux-iio, lars, Michael.Hennerich, jic23
  Cc: Michael Hennerich, Alexandru Ardelean

From: Michael Hennerich <michael.hennerich@analog.com>

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>
---
 drivers/iio/frequency/ad9523.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/drivers/iio/frequency/ad9523.c b/drivers/iio/frequency/ad9523.c
index 37504739c277..38a8f73bd8d9 100644
--- a/drivers/iio/frequency/ad9523.c
+++ b/drivers/iio/frequency/ad9523.c
@@ -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;
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] iio: ad9523: support for external signals via gpios
  2018-07-27  6:41 [PATCH] iio: ad9523: support for external signals via gpios Alexandru Ardelean
@ 2018-07-28  9:45 ` Jonathan Cameron
  0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Cameron @ 2018-07-28  9:45 UTC (permalink / raw)
  To: Alexandru Ardelean; +Cc: linux-iio, lars, Michael.Hennerich

On Fri, 27 Jul 2018 09:41:09 +0300
Alexandru Ardelean <alexandru.ardelean@analog.com> wrote:

> From: Michael Hennerich <michael.hennerich@analog.com>
> 
> 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>
Applied to the togreg branch of iio.git and pushed out as testing for
the autobuilders to play with it.

It might be worth putting together a DT binding doc for this device
(and fully dt bindings) as it is getting to be non trivial and presumably
most new users of this part are using DT.

Jonathan

> ---
>  drivers/iio/frequency/ad9523.c | 30 ++++++++++++++++++++++++++++++
>  1 file changed, 30 insertions(+)
> 
> diff --git a/drivers/iio/frequency/ad9523.c b/drivers/iio/frequency/ad9523.c
> index 37504739c277..38a8f73bd8d9 100644
> --- a/drivers/iio/frequency/ad9523.c
> +++ b/drivers/iio/frequency/ad9523.c
> @@ -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;


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-07-28 11:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-07-27  6:41 [PATCH] iio: ad9523: support for external signals via gpios Alexandru Ardelean
2018-07-28  9:45 ` Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).