Re: [PATCH v7 08/12] iio: adc: ad7768-1: add multiple scan types to support 16-bits mode

From: David Lechner
Date: Thu May 08 2025 - 14:04:04 EST


On 5/8/25 12:04 PM, Jonathan Santos wrote:
> When the device is configured to decimation x8, only possible in the
> sinc5 filter, output data is reduced to 16-bits in order to support
> 1 MHz of sampling frequency due to clock limitation.
>
> Use multiple scan types feature to enable the driver to switch
> scan type at runtime, making it possible to support both 24-bit and
> 16-bit resolution.
>
> Reviewed-by: Marcelo Schmitt <marcelo.schmitt@xxxxxxxxxx>
> Reviewed-by: David Lechner <dlechner@xxxxxxxxxxx>
> Signed-off-by: Jonathan Santos <Jonathan.Santos@xxxxxxxxxx>
> ---
> v7 Changes:
> * Added TODO comment to use spi_bpw_to_bytes() helper function.
> * Minor commit description changes.
>

...

> @@ -675,9 +723,16 @@ static irqreturn_t ad7768_trigger_handler(int irq, void *p)
> struct iio_poll_func *pf = p;
> struct iio_dev *indio_dev = pf->indio_dev;
> struct ad7768_state *st = iio_priv(indio_dev);
> + const struct iio_scan_type *scan_type;
> int ret;
>
> - ret = spi_read(st->spi, &st->data.scan.chan, 3);
> + scan_type = iio_get_current_scan_type(indio_dev, &indio_dev->channels[0]);
> + if (IS_ERR(scan_type))
> + goto out;
> +
> + /* TODO: Use spi_bpw_to_bytes() helper function. */

spi_bpw_to_bytes() is to get buffer size when setting bits_per_word. It doesn't
apply to spi_read(). So we should drop this comment.

> + ret = spi_read(st->spi, &st->data.scan.chan,
> + BITS_TO_BYTES(scan_type->realbits));

If we replaced BITS_TO_BYTES() with spi_bpw_to_bytes(), then it would read 4
bytes instead of 3 when realbits == 24, which isn't what we want.

> if (ret < 0)
> goto out;
>