Re: [PATCH v4 07/13] iio: adc: ad4134: Support buffered data read
From: Andy Shevchenko
Date: Tue Oct 13 2026 - 03:23:32 EST
On Tue, Oct 06, 2026 at 03:17:56PM -0300, Marcelo Schmitt wrote:
> Enable users to run buffered data captures triggered by IIO trigger device.
> Add an IIO timestamp channel so each data scan is provided with measurement
> time information. Require single-read operations to be in IIO device direct
> access mode to prevent buffered and single-shot data captures to disrupt
> each other.
...
> +static irqreturn_t ad4134_trigger_handler(int irq, void *p)
> +{
> + IIO_DECLARE_BUFFER_WITH_TS(u32, channels, AD4134_NUM_CHANNELS) = { };
> + unsigned int chan_bytes = BITS_TO_BYTES(AD4134_CHAN_PRECISION_BITS);
> + struct iio_poll_func *pf = p;
> + struct iio_dev *indio_dev = pf->indio_dev;
> + struct ad4134_state *st = iio_priv(indio_dev);
> + struct spi_transfer xfer = {
> + .rx_buf = st->rx_buf,
> + .cs_off = true,
> + .len = chan_bytes * AD4134_NUM_CHANNELS,
> + };
> + int ret;
> +
> + gpiod_set_value_cansleep(st->odr_gpio, 1);
> + fsleep(1);
> + gpiod_set_value_cansleep(st->odr_gpio, 0);
> +
> + /* Run enough DCLK cycles to match the data frame length. */
> + ret = spi_sync_transfer(st->spi, &xfer, 1);
> + if (ret)
> + goto out;
> + for (int ch = 0, i = 0; ch < AD4134_NUM_CHANNELS; ch++) {
> + if (!test_bit(ch, indio_dev->active_scan_mask))
> + continue;
for_each_set_bit() ?
> + channels[i++] = get_unaligned_be24(&st->rx_buf[ch * chan_bytes]);
> + }
> +
> + iio_push_to_buffers_with_ts(indio_dev, channels, sizeof(channels),
> + pf->timestamp);
> +
> +out:
> + iio_trigger_notify_done(indio_dev->trig);
> + return IRQ_HANDLED;
> +}
--
With Best Regards,
Andy Shevchenko