Re: [PATCH v3] staging: iio: addac: adt7316: document SPI interface switching sequence

From: Jonathan Cameron

Date: Mon May 11 2026 - 09:56:50 EST


On Mon, 11 May 2026 02:31:27 +0000
Hungyu Lin <dennylin0707@xxxxxxxxx> wrote:

> The device powers up in I2C mode. Switching to SPI mode
> requires sending a sequence of SPI writes as described in
> the datasheet.
>
> During this sequence, the device may still be in I2C mode,
> so SPI transactions may not be recognized and can fail.
> Such errors are expected and are ignored.

I'd not say they are 'expected' as such. That's because SPI
is a rather simple protocol so it is challenging to detect when
anything is wrong on writes. It might happen, it might not.

Perhaps

Such errors are therefore ignored.

Same below - otherwise we might get someone trying to verify
they get an error on this sequence ;)

>
> Add a comment to clarify this behavior.
>
> Datasheet: https://www.analog.com/en/products/adt7316.html
> Signed-off-by: Hungyu Lin <dennylin0707@xxxxxxxxx>
> ---
> Changes in v3:
> - Add Datasheet tag
> - Use datasheet name in code comment
>
> Changes in v2:
> - Add datasheet reference
> - Add TL;DR note
>
> drivers/staging/iio/addac/adt7316-spi.c | 12 +++++++++++-
> 1 file changed, 11 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/staging/iio/addac/adt7316-spi.c b/drivers/staging/iio/addac/adt7316-spi.c
> index f91325d11394..bd92dcddfd91 100644
> --- a/drivers/staging/iio/addac/adt7316-spi.c
> +++ b/drivers/staging/iio/addac/adt7316-spi.c
> @@ -106,7 +106,17 @@ static int adt7316_spi_probe(struct spi_device *spi_dev)
> return -EINVAL;
> }
>
> - /* switch from default I2C protocol to SPI protocol */
> + /*
> + * The device powers up in I2C mode. Switching to SPI mode
> + * requires sending a sequence of SPI writes as described in
> + * the datasheet "ADT7316/ADT7317/ADT7318", Rev. B.
> + *
> + * During this sequence, the device may still be in I2C mode,
> + * so SPI transactions may not be recognized and can fail.
> + * Such errors are expected and are ignored.
> + *
> + * TL;DR: Do not change this!
> + */
> adt7316_spi_write(spi_dev, 0, 0);
> adt7316_spi_write(spi_dev, 0, 0);
> adt7316_spi_write(spi_dev, 0, 0);