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

Hungyu Lin posted 1 patch 1 month ago
There is a newer version of this series
drivers/staging/iio/addac/adt7316-spi.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
[PATCH v3] staging: iio: addac: adt7316: document SPI interface switching sequence
Posted by Hungyu Lin 1 month ago
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.

Add a comment to clarify this behavior.

Datasheet: https://www.analog.com/en/products/adt7316.html
Signed-off-by: Hungyu Lin <dennylin0707@gmail.com>
---
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);
-- 
2.34.1
Re: [PATCH v3] staging: iio: addac: adt7316: document SPI interface switching sequence
Posted by Jonathan Cameron 1 month ago
On Mon, 11 May 2026 02:31:27 +0000
Hungyu Lin <dennylin0707@gmail.com> 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@gmail.com>
> ---
> 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);
Re: [PATCH v3] staging: iio: addac: adt7316: document SPI interface switching sequence
Posted by Andy Shevchenko 1 month ago
On Mon, May 11, 2026 at 02:31:27AM +0000, Hungyu Lin 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.
> 
> Add a comment to clarify this behavior.
> 
> Datasheet: https://www.analog.com/en/products/adt7316.html
> Signed-off-by: Hungyu Lin <dennylin0707@gmail.com>

Thanks, almost there!
Please, address the below and feel free to add
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
to your v4 of this patch.

Also I think we don't need "staging" in the Subject, as we can deduce that,
in any case it's up to Jonathan (and yes, I see the common use of the pattern
in the Git history).

...

> Changes in v3:
> - Add Datasheet tag
> - Use datasheet name in code comment

...

> +	/*
> +	 * 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.

Yeah, but you dropped the section title...

	 * the datasheet "ADT7316/ADT7317/ADT7318", Rev. B in
	 * the section "...".

> +	 * 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!
> +	 */

-- 
With Best Regards,
Andy Shevchenko
Re: [PATCH v3] staging: iio: addac: adt7316: document SPI interface switching sequence
Posted by Jonathan Cameron 1 month ago
On Mon, 11 May 2026 13:19:21 +0300
Andy Shevchenko <andriy.shevchenko@intel.com> wrote:

> On Mon, May 11, 2026 at 02:31:27AM +0000, Hungyu Lin 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.
> > 
> > Add a comment to clarify this behavior.
> > 
> > Datasheet: https://www.analog.com/en/products/adt7316.html
> > Signed-off-by: Hungyu Lin <dennylin0707@gmail.com>  
> 
> Thanks, almost there!
> Please, address the below and feel free to add
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
> to your v4 of this patch.
> 
> Also I think we don't need "staging" in the Subject, as we can deduce that,
> in any case it's up to Jonathan (and yes, I see the common use of the pattern
> in the Git history).

I think keeping staging is appropriate for a couple of reasons.

1) Affects who looks at it.  
2) Aligns with the more general pattern for most of staging that goes
   directly through Greg rather than via another tree like IIO.

> 
> ...
> 
> > Changes in v3:
> > - Add Datasheet tag
> > - Use datasheet name in code comment  
> 
> ...
> 
> > +	/*
> > +	 * 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.  
> 
> Yeah, but you dropped the section title...
> 
> 	 * the datasheet "ADT7316/ADT7317/ADT7318", Rev. B in
> 	 * the section "...".

Absolutely agree on this! Can be hard to find this stuff in the bigger
datasheets :(
> 
> > +	 * 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!
> > +	 */  
>
Re: [PATCH v3] staging: iio: addac: adt7316: document SPI interface switching sequence
Posted by Maxwell Doose 1 month ago
On Sun, May 10, 2026 at 9:31 PM Hungyu Lin <dennylin0707@gmail.com> 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.
>
> Add a comment to clarify this behavior.
>
> Datasheet: https://www.analog.com/en/products/adt7316.html
> Signed-off-by: Hungyu Lin <dennylin0707@gmail.com>
> ---
> 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(-)
>
[snip]

Reviewed-by: Maxwell Doose <m32285159@gmail.com>

best regards,
max