Re: [PATCH v14 3/6] iio: adc: ad4691: add triggered buffer support
From: Jonathan Cameron
Date: Sun May 31 2026 - 05:27:27 EST
On Fri, 29 May 2026 13:15:02 +0300
Radu Sabau via B4 Relay <devnull+radu.sabau.analog.com@xxxxxxxxxx> wrote:
> From: Radu Sabau <radu.sabau@xxxxxxxxxx>
>
> Add buffered capture support using the IIO triggered buffer framework.
>
> CNV Burst Mode: the GP pin identified by interrupt-names in the device
> tree is configured as DATA_READY output. The IRQ handler stops
> conversions and fires the IIO trigger; the trigger handler executes a
> pre-built SPI message that reads all active channels from the AVG_IN
> accumulator registers and then resets accumulator state and restarts
> conversions for the next cycle.
>
> Manual Mode: CNV is tied to SPI CS so each transfer simultaneously
> reads the previous result and starts the next conversion (pipelined
> N+1 scheme). At preenable time a pre-built, optimised SPI message of
> N+1 transfers is constructed (N channel reads plus one NOOP to drain
> the pipeline). The trigger handler executes the message in a single
> spi_sync() call and collects the results. An external trigger (e.g.
> iio-trig-hrtimer) is required to drive the trigger at the desired
> sample rate.
>
> Both modes share the same trigger handler and push a complete scan —
> one big-endian 16-bit (__be16) slot per active channel, densely packed
> in scan_index order, followed by a timestamp.
>
> The CNV Burst Mode sampling frequency (PWM period) is exposed as a
> buffer-level attribute via IIO_DEVICE_ATTR.
>
> Signed-off-by: Radu Sabau <radu.sabau@xxxxxxxxxx>
Hi,
> diff --git a/drivers/iio/adc/ad4691.c b/drivers/iio/adc/ad4691.c
> index e1febf80f21d..175c80129786 100644
> --- a/drivers/iio/adc/ad4691.c
> +++ b/drivers/iio/adc/ad4691.c
> @@ -11,19 +11,29 @@
> +static int ad4691_transfer(struct ad4691_state *st, u16 cmd)
> +{
> + u8 buf[2];
> +
> + put_unaligned_be16(cmd, buf);
> +
> + return spi_write(st->spi, buf, sizeof(buf));
Sashiko correctly identified this isn't using a DMA safe buffer.
If you want to keep this simple and use a local bugger use something like
return spi_write_then_read(st->spi, buf, sizeof(buf), NULL, 0);
as that already bounce buffers.
The rest of sashiko's comments look incorrect other than the range clamping
one that I think is intentional, if a little restrictive!)
If nothing else comes up in a final review from me that I'll do shortly
then I'll tweak this whilst applying.
> +}