Re: [PATCH 2/7] iio: imu: adis: Add a kfifo buffer setup helper for FIFO devices

From: Jonathan Cameron

Date: Sat Nov 28 2026 - 16:47:27 EST


On Mon, 23 Nov 2026 15:25:26 +0200
Radu Sabau via B4 Relay <devnull+radu.sabau.analog.com@xxxxxxxxxx> wrote:

> From: Radu Sabau <radu.sabau@xxxxxxxxxx>
>
> Devices with a hardware FIFO (has_fifo) currently go through the
> triggered buffer: the FIFO interrupt is requested with
> iio_trigger_generic_data_rdy_poll() as its thread function, which calls
> iio_trigger_poll() from the IRQ thread, and the samples are read from a
> trigger handler. iio_trigger_poll() is meant to be called from hard
> interrupt context, and the FIFO then depends on whatever trigger is
> selected.
>
> Add devm_adis_setup_kfifo_buffer() for such devices. It sets up a kfifo
> buffer and requests the FIFO interrupt as a oneshot threaded IRQ running a
> handler supplied by the driver, which reads the FIFO and pushes the
> samples. The interrupt is requested disabled, and the driver enables and
> disables it with enable_irq() and disable_irq() from its buffer setup
> functions. This is done without the adis lock, which the handler takes.

Why is it masked host side rather than than device side? The rules around
host side masking are vague and inconsistent for instance on whether interrupts
that come whilst it is disabled are dropped or queued up. As a result
device side masking is much preferred.


>
> The trigger/current_trigger attribute is user visible on the existing FIFO
> devices, so add devm_adis_register_fifo_trigger() for them to keep it. It
> registers a trigger with the usual name and sets INDIO_HARDWARE_TRIGGERED
> so the attribute exists. The buffer runs in software mode, so the trigger
> has no effect on it: writing it is accepted and ignored, as
> hid-sensor-trigger does for the same reason. New drivers do not need it.
>
> No driver uses the helpers yet.
>
> Signed-off-by: Radu Sabau <radu.sabau@xxxxxxxxxx>

A few things inline.

> diff --git a/drivers/iio/imu/adis_buffer.c b/drivers/iio/imu/adis_buffer.c
> index 501da4eaef69..e49e02adeda6 100644
> --- a/drivers/iio/imu/adis_buffer.c
> +++ b/drivers/iio/imu/adis_buffer.c
> @@ -15,6 +15,7 @@
>
> #include <linux/iio/iio.h>
> #include <linux/iio/buffer.h>
> +#include <linux/iio/kfifo_buf.h>
> #include <linux/iio/trigger_consumer.h>
> #include <linux/iio/triggered_buffer.h>
> #include <linux/iio/imu/adis.h>
> @@ -220,3 +221,47 @@ devm_adis_setup_buffer_and_trigger_with_attrs(struct adis *adis, struct iio_dev
> adis);
> }
> EXPORT_SYMBOL_NS_GPL(devm_adis_setup_buffer_and_trigger_with_attrs, "IIO_ADISLIB");
> +
> +/**
> + * devm_adis_setup_kfifo_buffer() - Sets up a kfifo buffer for a FIFO adis device
> + * @adis: The adis device
> + * @indio_dev: The IIO device
> + * @thread_fn: Threaded interrupt handler which reads the device FIFO and
> + * pushes the samples to the buffer. It is called with @indio_dev
> + * as dev_id.
> + * @ops: Optional buffer setup functions, may be NULL.
> + * @buffer_attrs: Extra buffer attributes.
> + *
> + * Returns 0 on success, a negative error code otherwise.
> + *
> + * Unlike devm_adis_setup_buffer_and_trigger_with_attrs(), the samples are not
> + * captured from a trigger handler. The device FIFO interrupt is requested as a
> + * threaded oneshot IRQ running @thread_fn, and the data goes straight to a
> + * kfifo buffer. The IRQ is requested disabled and the driver enables and
> + * disables it with enable_irq() and disable_irq() from its buffer setup
> + * functions, without holding the adis lock. Devices which already had a
> + * trigger/current_trigger attribute can keep it with
> + * devm_adis_register_fifo_trigger().
> + */
> +int devm_adis_setup_kfifo_buffer(struct adis *adis, struct iio_dev *indio_dev,
> + irq_handler_t thread_fn,
> + const struct iio_buffer_setup_ops *ops,
> + const struct iio_dev_attr **buffer_attrs)
> +{
> + int ret;
> +
> + ret = devm_iio_kfifo_buffer_setup_ext(&adis->spi->dev, indio_dev, ops,
> + buffer_attrs);

Does it work without the irq?

> + if (ret)
> + return ret;
> +
> + if (adis->spi->irq) {
> + ret = devm_adis_request_fifo_irq(adis, indio_dev, thread_fn);
> + if (ret)
> + return ret;
> + }
> +
> + return devm_add_action_or_reset(&adis->spi->dev, adis_buffer_cleanup,
> + adis);
> +}
> +EXPORT_SYMBOL_NS_GPL(devm_adis_setup_kfifo_buffer, "IIO_ADISLIB");
> diff --git a/drivers/iio/imu/adis_trigger.c b/drivers/iio/imu/adis_trigger.c
> index 3e6a7af6ab01..ea8661bff901 100644
> --- a/drivers/iio/imu/adis_trigger.c
> +++ b/drivers/iio/imu/adis_trigger.c

> +
> +/**
> + * devm_adis_register_fifo_trigger() - Registers the legacy trigger of a FIFO device
> + * @adis: The adis device
> + * @indio_dev: The IIO device
> + *
> + * Registers an IIO trigger named after the device. It is never used to push
> + * samples, as the data goes to a kfifo buffer. It only keeps the
> + * trigger/current_trigger interface of devices that always had it, so writing
> + * it is accepted but has no effect. New drivers do not need it.

We want to keep the current_trigger interface for existing parts but
not add it for new ones. There can't be a regression on devices we haven't
supported yet. So I think we either need to push the setting of
INDIO_HARDWARE_TRIGGERED to the caller or have multiple helpers for
the different cases.

> + *
> + * Returns 0 on success or a negative error code
> + */
> +int devm_adis_register_fifo_trigger(struct adis *adis, struct iio_dev *indio_dev)
> +{
> + adis->trig = devm_iio_trigger_alloc(&adis->spi->dev, "%s-dev%d",
> + indio_dev->name,
> + iio_device_id(indio_dev));
> + if (!adis->trig)
> + return -ENOMEM;
> +
> + indio_dev->modes |= INDIO_HARDWARE_TRIGGERED;
> +
> + return devm_iio_trigger_register(&adis->spi->dev, adis->trig);
> +}
> +EXPORT_SYMBOL_NS_GPL(devm_adis_register_fifo_trigger, "IIO_ADISLIB");

>