Skip to content

Commit 08900db

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. Add the option to handle device synchronization over SPI. Signed-off-by: Jonathan Santos <Jonathan.Santos@analog.com>
1 parent bd527bf commit 08900db

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

drivers/iio/adc/ad7768-1.c

Lines changed: 26 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,19 @@ 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+
if (st->en_spi_sync)
294+
return ad7768_spi_reg_write(st, AD7768_REG_SYNC_RESET, 0x00);
295+
296+
if (st->en_gpio_sync) {
297+
gpiod_set_value_cansleep(st->gpio_sync_in, 1);
298+
gpiod_set_value_cansleep(st->gpio_sync_in, 0);
299+
}
300+
301+
return 0;
302+
}
303+
289304
static int ad7768_set_mode(struct ad7768_state *st,
290305
enum ad7768_conv_mode mode)
291306
{
@@ -372,10 +387,7 @@ static int ad7768_set_dig_fil(struct ad7768_state *st,
372387
return ret;
373388

374389
/* 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;
390+
return ad7768_send_sync_pulse(st);
379391
}
380392

381393
int ad7768_gpio_direction_input(struct gpio_chip *chip, unsigned int offset)
@@ -689,10 +701,17 @@ static int ad7768_setup(struct ad7768_state *st)
689701
if (ret)
690702
return ret;
691703

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

697716
ret = ad7768_gpio_init(st);
698717
if (ret < 0)

0 commit comments

Comments
 (0)