[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <0f9a15e6e2e6b7b2c82ef79d8cb883d9eb6c55dd.1736201898.git.Jonathan.Santos@analog.com>
Date: Tue, 7 Jan 2025 12:27:03 -0300
From: Jonathan Santos <Jonathan.Santos@...log.com>
To: <linux-iio@...r.kernel.org>, <devicetree@...r.kernel.org>,
<linux-kernel@...r.kernel.org>
CC: Jonathan Santos <Jonathan.Santos@...log.com>, <lars@...afoo.de>,
<Michael.Hennerich@...log.com>, <jic23@...nel.org>, <robh@...nel.org>,
<krzk+dt@...nel.org>, <conor+dt@...nel.org>,
<marcelo.schmitt1@...il.com>
Subject: [PATCH v1 14/15] iio: adc: ad7768-1: add support for Synchronization over SPI
The synchronization method using GPIO requires the generated pulse to be
truly synchronous with the base MCLK signal. When it is not possible to
do that in hardware, the datasheet recommends using synchronization over
SPI, where the generated pulse is already synchronous with MCLK. This
requires the SYNC_OUT pin to be connected to SYNC_IN pin.
Add the option to handle device synchronization over SPI.
Signed-off-by: Jonathan Santos <Jonathan.Santos@...log.com>
---
drivers/iio/adc/ad7768-1.c | 33 +++++++++++++++++++++++++++------
1 file changed, 27 insertions(+), 6 deletions(-)
diff --git a/drivers/iio/adc/ad7768-1.c b/drivers/iio/adc/ad7768-1.c
index 5e4e7d387f9a..0b0cb3b396ff 100644
--- a/drivers/iio/adc/ad7768-1.c
+++ b/drivers/iio/adc/ad7768-1.c
@@ -235,6 +235,7 @@ struct ad7768_state {
struct iio_trigger *trig;
struct gpio_desc *gpio_sync_in;
struct gpio_desc *gpio_reset;
+ bool en_spi_sync;
int irq;
const char *labels[ARRAY_SIZE(ad7768_channels)];
/*
@@ -295,6 +296,19 @@ static int ad7768_spi_reg_write_masked(struct ad7768_state *st,
return ad7768_spi_reg_write(st, addr, (reg_val & ~mask) | val);
}
+static int ad7768_send_sync_pulse(struct ad7768_state *st)
+{
+ if (st->en_spi_sync)
+ return ad7768_spi_reg_write(st, AD7768_REG_SYNC_RESET, 0x00);
+
+ if (st->gpio_sync_in) {
+ gpiod_set_value_cansleep(st->gpio_sync_in, 1);
+ gpiod_set_value_cansleep(st->gpio_sync_in, 0);
+ }
+
+ return 0;
+}
+
static int ad7768_set_mode(struct ad7768_state *st,
enum ad7768_conv_mode mode)
{
@@ -379,10 +393,7 @@ static int ad7768_set_dig_fil(struct ad7768_state *st,
return ret;
/* A sync-in pulse is required every time the filter dec rate changes */
- gpiod_set_value(st->gpio_sync_in, 1);
- gpiod_set_value(st->gpio_sync_in, 0);
-
- return 0;
+ return ad7768_send_sync_pulse(st);
}
static int ad7768_gpio_direction_input(struct gpio_chip *chip, unsigned int offset)
@@ -697,11 +708,21 @@ static int ad7768_setup(struct ad7768_state *st)
if (ret)
return ret;
- st->gpio_sync_in = devm_gpiod_get(&st->spi->dev, "adi,sync-in",
- GPIOD_OUT_LOW);
+ st->gpio_sync_in = devm_gpiod_get_optional(&st->spi->dev, "adi,sync-in",
+ GPIOD_OUT_LOW);
if (IS_ERR(st->gpio_sync_in))
return PTR_ERR(st->gpio_sync_in);
+ if (device_property_present(&st->spi->dev, "adi,sync-in-spi"))
+ st->en_spi_sync = true;
+
+ /*
+ * GPIO and SPI Synchronization are mutually exclusive.
+ * Return error if both are enabled
+ */
+ if (st->gpio_sync_in && st->en_spi_sync)
+ return -EINVAL;
+
ret = ad7768_gpio_init(st);
if (ret < 0)
return ret;
--
2.34.1
Powered by blists - more mailing lists