From: Jonathan Cameron <jic23@kernel.org>
To: Radu Sabau via B4 Relay <devnull+radu.sabau.analog.com@kernel.org>
Cc: radu.sabau@analog.com, "Nuno Sá" <nuno.sa@analog.com>,
"Michael Hennerich" <Michael.Hennerich@analog.com>,
"David Lechner" <dlechner@baylibre.com>,
"Andy Shevchenko" <andy@kernel.org>,
"Ramona Gradinariu" <ramona.bolboaca13@gmail.com>,
linux-iio@vger.kernel.org, linux@analog.com,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/7] iio: imu: adis: Add a kfifo buffer setup helper for FIFO devices
Date: Sat, 28 Nov 2026 21:47:15 +0000 [thread overview]
Message-ID: <20261128214715.1791222b@jic23-hlaptop> (raw)
In-Reply-To: <20261123-adis-fifo-v1-2-f6ad9e493e19@analog.com>
On Mon, 23 Nov 2026 15:25:26 +0200
Radu Sabau via B4 Relay <devnull+radu.sabau.analog.com@kernel.org> wrote:
> From: Radu Sabau <radu.sabau@analog.com>
>
> 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@analog.com>
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");
>
next prev parent reply other threads:[~2026-11-28 21:47 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 13:25 [PATCH 0/7] iio: imu: adis: Use a kfifo buffer for the devices with a FIFO Radu Sabau via B4 Relay
2026-11-23 13:25 ` [PATCH 1/7] iio: imu: adis16475: Use the reset timeouts of the ADIS1657x Radu Sabau via B4 Relay
2026-11-26 13:34 ` Joshua Crofts
2026-11-28 21:49 ` Jonathan Cameron
2026-11-23 13:25 ` [PATCH 2/7] iio: imu: adis: Add a kfifo buffer setup helper for FIFO devices Radu Sabau via B4 Relay
2026-11-26 9:33 ` Sabau, Radu bogdan
2026-11-28 21:47 ` Jonathan Cameron [this message]
2026-11-23 13:25 ` [PATCH 3/7] iio: imu: adis16475: Pass the device and timestamp to the sample helpers Radu Sabau via B4 Relay
2026-11-23 13:25 ` [PATCH 4/7] iio: imu: adis16475: Use a kfifo buffer for the devices with a FIFO Radu Sabau via B4 Relay
2026-11-28 21:52 ` Jonathan Cameron
2026-11-23 13:25 ` [PATCH 5/7] iio: imu: adis: Drop the FIFO handling from the data ready trigger Radu Sabau via B4 Relay
2026-11-23 13:25 ` [PATCH 6/7] iio: imu: adis16607: Add FIFO-based buffered capture Radu Sabau via B4 Relay
2026-11-28 22:00 ` Jonathan Cameron
2026-11-23 13:25 ` [PATCH 7/7] iio: imu: adis16607: Report loss of external sync Radu Sabau via B4 Relay
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261128214715.1791222b@jic23-hlaptop \
--to=jic23@kernel.org \
--cc=Michael.Hennerich@analog.com \
--cc=andy@kernel.org \
--cc=devnull+radu.sabau.analog.com@kernel.org \
--cc=dlechner@baylibre.com \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@analog.com \
--cc=nuno.sa@analog.com \
--cc=radu.sabau@analog.com \
--cc=ramona.bolboaca13@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®