Skip to content

Commit 2416cec

Browse files
jonathannsjic23
authored andcommitted
iio: adc: ad7768-1: set MOSI idle state to prevent accidental reset
Datasheet recommends Setting the MOSI idle state to high in order to prevent accidental reset of the device when SCLK is free running. This happens when the controller clocks out a 1 followed by 63 zeros while the CS is held low. Check if SPI controller supports SPI_MOSI_IDLE_HIGH flag and set it. Fixes: a5f8c7d ("iio: adc: Add AD7768-1 ADC basic support") Signed-off-by: Jonathan Santos <[email protected]> Reviewed-by: Marcelo Schmitt <[email protected]> Link: https://patch.msgid.link/c2a2b0f3d54829079763a5511359a1fa80516cfb.1741268122.git.Jonathan.Santos@analog.com Signed-off-by: Jonathan Cameron <[email protected]>
1 parent 8236644 commit 2416cec

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

drivers/iio/adc/ad7768-1.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,21 @@ static int ad7768_probe(struct spi_device *spi)
572572
return -ENOMEM;
573573

574574
st = iio_priv(indio_dev);
575+
/*
576+
* Datasheet recommends SDI line to be kept high when data is not being
577+
* clocked out of the controller and the spi clock is free running,
578+
* to prevent accidental reset.
579+
* Since many controllers do not support the SPI_MOSI_IDLE_HIGH flag
580+
* yet, only request the MOSI idle state to enable if the controller
581+
* supports it.
582+
*/
583+
if (spi->controller->mode_bits & SPI_MOSI_IDLE_HIGH) {
584+
spi->mode |= SPI_MOSI_IDLE_HIGH;
585+
ret = spi_setup(spi);
586+
if (ret < 0)
587+
return ret;
588+
}
589+
575590
st->spi = spi;
576591

577592
st->vref = devm_regulator_get(&spi->dev, "vref");

0 commit comments

Comments
 (0)