Commit af37e470 authored by Dragos Bogdan's avatar Dragos Bogdan Committed by Jonathan Cameron

iio: adc: ad7476: Generate CONVST signal internally

Compared to the other supported parts, AD7091R are dependent of
a CONVST signal that initiates the conversion. At this moment, only
sampling in buffered mode is supported for AD7091R and the only
option until now was to generate this signal externally using an
IIO trigger. This patch adds the option of generating it internally,
more compatible triggers being available in this case.

Also, it is an intermediate step of adding support more devices.
Signed-off-by: default avatarDragos Bogdan <dragos.bogdan@analog.com>
Signed-off-by: default avatarBeniamin Bia <beniamin.bia@analog.com>
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 4be590e3
...@@ -12,9 +12,11 @@ ...@@ -12,9 +12,11 @@
#include <linux/sysfs.h> #include <linux/sysfs.h>
#include <linux/spi/spi.h> #include <linux/spi/spi.h>
#include <linux/regulator/consumer.h> #include <linux/regulator/consumer.h>
#include <linux/gpio/consumer.h>
#include <linux/err.h> #include <linux/err.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/bitops.h> #include <linux/bitops.h>
#include <linux/delay.h>
#include <linux/iio/iio.h> #include <linux/iio/iio.h>
#include <linux/iio/sysfs.h> #include <linux/iio/sysfs.h>
...@@ -34,6 +36,7 @@ struct ad7476_state { ...@@ -34,6 +36,7 @@ struct ad7476_state {
struct spi_device *spi; struct spi_device *spi;
const struct ad7476_chip_info *chip_info; const struct ad7476_chip_info *chip_info;
struct regulator *reg; struct regulator *reg;
struct gpio_desc *convst_gpio;
struct spi_transfer xfer; struct spi_transfer xfer;
struct spi_message msg; struct spi_message msg;
/* /*
...@@ -64,6 +67,17 @@ enum ad7476_supported_device_ids { ...@@ -64,6 +67,17 @@ enum ad7476_supported_device_ids {
ID_ADS7868, ID_ADS7868,
}; };
static void ad7091_convst(struct ad7476_state *st)
{
if (!st->convst_gpio)
return;
gpiod_set_value(st->convst_gpio, 0);
udelay(1); /* CONVST pulse width: 10 ns min */
gpiod_set_value(st->convst_gpio, 1);
udelay(1); /* Conversion time: 650 ns max */
}
static irqreturn_t ad7476_trigger_handler(int irq, void *p) static irqreturn_t ad7476_trigger_handler(int irq, void *p)
{ {
struct iio_poll_func *pf = p; struct iio_poll_func *pf = p;
...@@ -71,6 +85,8 @@ static irqreturn_t ad7476_trigger_handler(int irq, void *p) ...@@ -71,6 +85,8 @@ static irqreturn_t ad7476_trigger_handler(int irq, void *p)
struct ad7476_state *st = iio_priv(indio_dev); struct ad7476_state *st = iio_priv(indio_dev);
int b_sent; int b_sent;
ad7091_convst(st);
b_sent = spi_sync(st->spi, &st->msg); b_sent = spi_sync(st->spi, &st->msg);
if (b_sent < 0) if (b_sent < 0)
goto done; goto done;
...@@ -254,6 +270,12 @@ static int ad7476_probe(struct spi_device *spi) ...@@ -254,6 +270,12 @@ static int ad7476_probe(struct spi_device *spi)
if (ret) if (ret)
return ret; return ret;
st->convst_gpio = devm_gpiod_get_optional(&spi->dev,
"adi,conversion-start",
GPIOD_OUT_LOW);
if (IS_ERR(st->convst_gpio))
return PTR_ERR(st->convst_gpio);
spi_set_drvdata(spi, indio_dev); spi_set_drvdata(spi, indio_dev);
st->spi = spi; st->spi = spi;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment