Skip to content

Commit 47c98d9

Browse files
committed
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. Signed-off-by: Jonathan Santos <Jonathan.Santos@analog.com>
1 parent 2158b73 commit 47c98d9

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

drivers/iio/adc/ad7768-1.c

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,8 @@ struct ad7768_state {
218218
const char *labels[ARRAY_SIZE(ad7768_channels)];
219219
struct gpio_desc *gpio_reset;
220220
bool spi_is_dma_mapped;
221+
bool en_spi_sync;
222+
bool en_gpio_sync;
221223
int irq;
222224
/*
223225
* DMA (thus cache coherency maintenance) may require the
@@ -286,6 +288,21 @@ static int ad7768_spi_reg_write_masked(struct ad7768_state *st,
286288
return ad7768_spi_reg_write(st, addr, (reg_val & ~mask) | val);
287289
}
288290

291+
static int ad7768_send_sync_pulse(struct ad7768_state *st)
292+
{
293+
int ret = 0;
294+
295+
if (st->en_spi_sync)
296+
ret = ad7768_spi_reg_write(st, AD7768_REG_SYNC_RESET, 0x00);
297+
298+
if (st->en_gpio_sync) {
299+
gpiod_set_value(st->gpio_sync_in, 1);
300+
gpiod_set_value(st->gpio_sync_in, 0);
301+
}
302+
303+
return ret;
304+
}
305+
289306
static int ad7768_set_mode(struct ad7768_state *st,
290307
enum ad7768_conv_mode mode)
291308
{
@@ -372,10 +389,7 @@ static int ad7768_set_dig_fil(struct ad7768_state *st,
372389
return ret;
373390

374391
/* A sync-in pulse is required every time the filter dec rate changes */
375-
gpiod_set_value(st->gpio_sync_in, 1);
376-
gpiod_set_value(st->gpio_sync_in, 0);
377-
378-
return 0;
392+
return ad7768_send_sync_pulse(st);
379393
}
380394

381395
int ad7768_gpio_direction_input(struct gpio_chip *chip, unsigned int offset)
@@ -689,10 +703,17 @@ static int ad7768_setup(struct ad7768_state *st)
689703
if (ret)
690704
return ret;
691705

692-
st->gpio_sync_in = devm_gpiod_get(&st->spi->dev, "adi,sync-in",
706+
if (device_property_present(&st->spi->dev, "adi,sync-in-gpios")) {
707+
st->en_gpio_sync = true;
708+
st->gpio_sync_in = devm_gpiod_get(&st->spi->dev, "adi,sync-in",
693709
GPIOD_OUT_LOW);
694-
if (IS_ERR(st->gpio_sync_in))
695-
return PTR_ERR(st->gpio_sync_in);
710+
if (IS_ERR(st->gpio_sync_in))
711+
return PTR_ERR(st->gpio_sync_in);
712+
713+
}
714+
715+
if (device_property_present(&st->spi->dev, "adi,sync-in-spi"))
716+
st->en_spi_sync = true;
696717

697718
ret = ad7768_gpio_init(st);
698719
if (ret < 0)

0 commit comments

Comments
 (0)