* [PATCH 0/7] iio: imu: adis: Use a kfifo buffer for the devices with a FIFO
@ 2026-11-23 13:25 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
` (6 more replies)
0 siblings, 7 replies; 10+ messages in thread
From: Radu Sabau via B4 Relay @ 2026-11-23 13:25 UTC (permalink / raw)
To: Nuno Sá,
Michael Hennerich, Jonathan Cameron, David Lechner,
Andy Shevchenko, Ramona Gradinariu, Radu Sabau
Cc: linux-iio, linux, linux-kernel, Jonathan Cameron
This series follows the ADIS16607 driver, which was applied without its
buffered capture so that the adislib part could be done first, as
suggested in the review of that series.
The devices with a hardware FIFO (has_fifo, the ADIS1657x variants of the
adis16475 driver so far) capture through the triggered buffer. Their FIFO
interrupt is requested with iio_trigger_generic_data_rdy_poll() as the
threaded handler, which calls iio_trigger_poll() from the IRQ thread, even
though that helper is meant for hard interrupt context, and the capture then
depends on whatever trigger is selected.
Patch 1 is a fix on its own and does not depend on the rest. The ADIS1657x
variants of the adis16475 driver wait less after a reset than their
datasheets give, so the product ID mismatch warning is printed and the
registers written at probe are lost, including the FIFO configuration. It
was found while testing this series, and comes first so that it can be
applied separately.
Patch 2 adds a helper to adislib that sets up a kfifo buffer and requests
the FIFO interrupt as a oneshot threaded IRQ running a handler supplied by
the driver. The interrupt is requested disabled and the driver enables and
disables it from its buffer setup functions. A second helper registers the
trigger of the same name as before, for the devices that already had one.
Patches 3 and 4 convert the adis16475 FIFO variants. Patch 3 passes the
device and the timestamp to the sample helpers instead of the poll
function, so they do not depend on being called from a trigger handler,
and patch 4 does the conversion. The trigger/current_trigger attribute of
these devices is kept as it was, so there is no change in the interface,
but the buffer does not use the trigger any more: writing it is accepted
and has no effect, and a buffer can now also be enabled without selecting
one. This is the same approach hid-sensor-trigger takes for the same
reason.
Patch 5 removes the FIFO handling from the data ready trigger, which no
device uses any more.
Patches 6 and 7 add the buffered capture to the adis16607 on top of the
helper, and the reporting of loss of external sync, which was left out of
the base series as it is reported from the FIFO interrupt handler.
Notable points for reviewers:
- The FIFO interrupt is level triggered and oneshot, so the line stays
masked until the handler has drained the FIFO, and it is enabled only
while the buffer is, from the buffer setup functions. disable_irq() is
called without the adis lock, as the handler takes it and
disable_irq() waits for it.
- The adis16607 does not register a trigger: it never had that
interface, so there is nothing to keep compatible. The helper that
registers one is only called by the adis16475.
- On the adis16607 the device cannot mask DEV_NOK by itself: unrouting it
leaves the pin on its weak pull-up, which reads as asserted. The
interrupt is therefore masked on the host.
- The series was tested on a Raspberry Pi 4 with an ADIS16607 and an
ADIS16577-2 wired over SPI.
Link to the ADIS16607 series: https://lore.kernel.org/r/20261118-adis16607-v7-0-707609737691@analog.com
---
Radu Sabau (7):
iio: imu: adis16475: Use the reset timeouts of the ADIS1657x
iio: imu: adis: Add a kfifo buffer setup helper for FIFO devices
iio: imu: adis16475: Pass the device and timestamp to the sample helpers
iio: imu: adis16475: Use a kfifo buffer for the devices with a FIFO
iio: imu: adis: Drop the FIFO handling from the data ready trigger
iio: imu: adis16607: Add FIFO-based buffered capture
iio: imu: adis16607: Report loss of external sync
drivers/iio/imu/Kconfig | 3 +
drivers/iio/imu/adis16475.c | 87 +++++----
drivers/iio/imu/adis16607.c | 399 +++++++++++++++++++++++++++++++++++++++--
drivers/iio/imu/adis_buffer.c | 45 +++++
drivers/iio/imu/adis_trigger.c | 73 ++++++--
include/linux/iio/imu/adis.h | 32 ++++
6 files changed, 584 insertions(+), 55 deletions(-)
---
base-commit: f2cbef9101b9fc979a324bb1242b8b802a2484b6
change-id: 20261123-adis-fifo-29a9b493f3b5
Best regards,
--
Radu Sabau <radu.sabau@analog.com>
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 1/7] iio: imu: adis16475: Use the reset timeouts of the ADIS1657x
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 ` Radu Sabau via B4 Relay
2026-11-26 13:34 ` Joshua Crofts
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
` (5 subsequent siblings)
6 siblings, 1 reply; 10+ messages in thread
From: Radu Sabau via B4 Relay @ 2026-11-23 13:25 UTC (permalink / raw)
To: Nuno Sá,
Michael Hennerich, Jonathan Cameron, David Lechner,
Andy Shevchenko, Ramona Gradinariu, Radu Sabau
Cc: linux-iio, linux, linux-kernel, Jonathan Cameron
From: Radu Sabau <radu.sabau@analog.com>
The ADIS1657x variants share the timeouts of the ADIS1647x parts, which
wait 200 ms after a reset. The ADIS1657x datasheets give a longer
recovery: about 275 ms after a hardware reset, 241 ms after a software
reset and 282 ms from power on.
Reading the product ID right after the shorter wait returns 0 on an
ADIS16577-2, so the warning about a product ID mismatch is printed, and
the registers written while the part is still starting up are lost. This
includes the FIFO control bits written at probe (watermark pin polarity
and enable, and the overflow behaviour), so the watermark pin is never
driven and the FIFO does not behave as configured.
Give the ADIS1657x variants their own timeouts, a bit above the typical
values from the datasheet.
Fixes: f95920baa066 ("drivers: iio: imu: Add support for adis1657x family")
Signed-off-by: Radu Sabau <radu.sabau@analog.com>
---
drivers/iio/imu/adis16475.c | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
diff --git a/drivers/iio/imu/adis16475.c b/drivers/iio/imu/adis16475.c
index 5f21dceda8f7..44520d9216a2 100644
--- a/drivers/iio/imu/adis16475.c
+++ b/drivers/iio/imu/adis16475.c
@@ -887,6 +887,12 @@ static const struct adis_timeout adis16475_timeouts = {
.self_test_ms = 20,
};
+static const struct adis_timeout adis1657x_timeouts = {
+ .reset_ms = 300,
+ .sw_reset_ms = 260,
+ .self_test_ms = 20,
+};
+
static const struct adis_timeout adis1650x_timeouts = {
.reset_ms = 260,
.sw_reset_ms = 260,
@@ -1331,7 +1337,7 @@ static const struct adis16475_chip_info adis16475_chip_info[] = {
ADIS16475_HAS_BURST_DELTA_DATA |
ADIS16475_NEEDS_BURST_REQUEST |
ADIS16475_HAS_TIMESTAMP32,
- .adis_data = ADIS16475_DATA(16575, &adis16475_timeouts,
+ .adis_data = ADIS16475_DATA(16575, &adis1657x_timeouts,
ADIS16575_BURST32_DATA_TS32,
ADIS16575_BURST_MAX_SPEED, true),
},
@@ -1354,7 +1360,7 @@ static const struct adis16475_chip_info adis16475_chip_info[] = {
ADIS16475_HAS_BURST_DELTA_DATA |
ADIS16475_NEEDS_BURST_REQUEST |
ADIS16475_HAS_TIMESTAMP32,
- .adis_data = ADIS16475_DATA(16575, &adis16475_timeouts,
+ .adis_data = ADIS16475_DATA(16575, &adis1657x_timeouts,
ADIS16575_BURST32_DATA_TS32,
ADIS16575_BURST_MAX_SPEED, true),
},
@@ -1377,7 +1383,7 @@ static const struct adis16475_chip_info adis16475_chip_info[] = {
ADIS16475_HAS_BURST_DELTA_DATA |
ADIS16475_NEEDS_BURST_REQUEST |
ADIS16475_HAS_TIMESTAMP32,
- .adis_data = ADIS16475_DATA(16576, &adis16475_timeouts,
+ .adis_data = ADIS16475_DATA(16576, &adis1657x_timeouts,
ADIS16575_BURST32_DATA_TS32,
ADIS16575_BURST_MAX_SPEED, true),
},
@@ -1400,7 +1406,7 @@ static const struct adis16475_chip_info adis16475_chip_info[] = {
ADIS16475_HAS_BURST_DELTA_DATA |
ADIS16475_NEEDS_BURST_REQUEST |
ADIS16475_HAS_TIMESTAMP32,
- .adis_data = ADIS16475_DATA(16576, &adis16475_timeouts,
+ .adis_data = ADIS16475_DATA(16576, &adis1657x_timeouts,
ADIS16575_BURST32_DATA_TS32,
ADIS16575_BURST_MAX_SPEED, true),
},
@@ -1423,7 +1429,7 @@ static const struct adis16475_chip_info adis16475_chip_info[] = {
ADIS16475_HAS_BURST_DELTA_DATA |
ADIS16475_NEEDS_BURST_REQUEST |
ADIS16475_HAS_TIMESTAMP32,
- .adis_data = ADIS16475_DATA(16577, &adis16475_timeouts,
+ .adis_data = ADIS16475_DATA(16577, &adis1657x_timeouts,
ADIS16575_BURST32_DATA_TS32,
ADIS16575_BURST_MAX_SPEED, true),
},
@@ -1446,7 +1452,7 @@ static const struct adis16475_chip_info adis16475_chip_info[] = {
ADIS16475_HAS_BURST_DELTA_DATA |
ADIS16475_NEEDS_BURST_REQUEST |
ADIS16475_HAS_TIMESTAMP32,
- .adis_data = ADIS16475_DATA(16577, &adis16475_timeouts,
+ .adis_data = ADIS16475_DATA(16577, &adis1657x_timeouts,
ADIS16575_BURST32_DATA_TS32,
ADIS16575_BURST_MAX_SPEED, true),
},
--
2.43.0
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 2/7] iio: imu: adis: Add a kfifo buffer setup helper for FIFO devices
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-23 13:25 ` Radu Sabau via B4 Relay
2026-11-26 9:33 ` Sabau, Radu bogdan
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
` (4 subsequent siblings)
6 siblings, 1 reply; 10+ messages in thread
From: Radu Sabau via B4 Relay @ 2026-11-23 13:25 UTC (permalink / raw)
To: Nuno Sá,
Michael Hennerich, Jonathan Cameron, David Lechner,
Andy Shevchenko, Ramona Gradinariu, Radu Sabau
Cc: linux-iio, linux, linux-kernel, Jonathan Cameron
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.
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>
---
drivers/iio/imu/Kconfig | 1 +
drivers/iio/imu/adis_buffer.c | 45 ++++++++++++++++++++++++++++++++++
drivers/iio/imu/adis_trigger.c | 55 ++++++++++++++++++++++++++++++++++++++++++
include/linux/iio/imu/adis.h | 32 ++++++++++++++++++++++++
4 files changed, 133 insertions(+)
diff --git a/drivers/iio/imu/Kconfig b/drivers/iio/imu/Kconfig
index 8b91426f60d0..b00acccab061 100644
--- a/drivers/iio/imu/Kconfig
+++ b/drivers/iio/imu/Kconfig
@@ -151,6 +151,7 @@ config IIO_ADIS_LIB
config IIO_ADIS_LIB_BUFFER
bool
+ select IIO_KFIFO_BUF
select IIO_TRIGGERED_BUFFER
help
A set of buffer helper functions for the Analog Devices ADIS* device
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);
+ 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
@@ -104,3 +104,58 @@ int devm_adis_probe_trigger(struct adis *adis, struct iio_dev *indio_dev)
}
EXPORT_SYMBOL_NS_GPL(devm_adis_probe_trigger, "IIO_ADISLIB");
+/**
+ * devm_adis_request_fifo_irq() - Requests the FIFO interrupt of an adis device
+ * @adis: The adis device
+ * @indio_dev: The IIO device
+ * @thread_fn: Threaded interrupt handler, called with @indio_dev as dev_id
+ *
+ * Requests the (level triggered) FIFO interrupt as a oneshot threaded IRQ. The
+ * IRQ is requested disabled: the driver enables it with enable_irq() once the
+ * device FIFO is running and disables it with disable_irq() before stopping
+ * it, without holding the adis lock as @thread_fn takes it.
+ *
+ * Returns 0 on success or a negative error code
+ */
+int devm_adis_request_fifo_irq(struct adis *adis, struct iio_dev *indio_dev,
+ irq_handler_t thread_fn)
+{
+ int ret;
+
+ ret = adis_validate_irq_flag(adis);
+ if (ret)
+ return ret;
+
+ adis->irq_flag |= IRQF_NO_AUTOEN;
+
+ return devm_request_threaded_irq(&adis->spi->dev, adis->spi->irq, NULL,
+ thread_fn, adis->irq_flag | IRQF_ONESHOT,
+ indio_dev->name, indio_dev);
+}
+EXPORT_SYMBOL_NS_GPL(devm_adis_request_fifo_irq, "IIO_ADISLIB");
+
+/**
+ * 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.
+ *
+ * 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");
diff --git a/include/linux/iio/imu/adis.h b/include/linux/iio/imu/adis.h
index c9016f636530..4f87321a2d5e 100644
--- a/include/linux/iio/imu/adis.h
+++ b/include/linux/iio/imu/adis.h
@@ -569,6 +569,16 @@ devm_adis_setup_buffer_and_trigger_with_attrs(struct adis *adis,
int devm_adis_probe_trigger(struct adis *adis, struct iio_dev *indio_dev);
+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 devm_adis_request_fifo_irq(struct adis *adis, struct iio_dev *indio_dev,
+ irq_handler_t thread_fn);
+
+int devm_adis_register_fifo_trigger(struct adis *adis, struct iio_dev *indio_dev);
+
int adis_update_scan_mode(struct iio_dev *indio_dev,
const unsigned long *scan_mask);
@@ -590,6 +600,28 @@ static inline int devm_adis_probe_trigger(struct adis *adis,
return 0;
}
+static inline 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)
+{
+ return 0;
+}
+
+static inline int
+devm_adis_request_fifo_irq(struct adis *adis, struct iio_dev *indio_dev,
+ irq_handler_t thread_fn)
+{
+ return 0;
+}
+
+static inline int
+devm_adis_register_fifo_trigger(struct adis *adis, struct iio_dev *indio_dev)
+{
+ return 0;
+}
+
#define adis_update_scan_mode NULL
#endif /* CONFIG_IIO_BUFFER */
--
2.43.0
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 3/7] iio: imu: adis16475: Pass the device and timestamp to the sample helpers
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-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-23 13:25 ` 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
` (3 subsequent siblings)
6 siblings, 0 replies; 10+ messages in thread
From: Radu Sabau via B4 Relay @ 2026-11-23 13:25 UTC (permalink / raw)
To: Nuno Sá,
Michael Hennerich, Jonathan Cameron, David Lechner,
Andy Shevchenko, Ramona Gradinariu, Radu Sabau
Cc: linux-iio, linux, linux-kernel, Jonathan Cameron
From: Radu Sabau <radu.sabau@analog.com>
adis16475_push_single_sample() and adis16575_custom_burst_read() take the
struct iio_poll_func only to get the IIO device and the timestamp from it.
Pass those two instead, so the helpers don't depend on being called from a
trigger handler.
No functional change.
Signed-off-by: Radu Sabau <radu.sabau@analog.com>
---
drivers/iio/imu/adis16475.c | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/drivers/iio/imu/adis16475.c b/drivers/iio/imu/adis16475.c
index 44520d9216a2..6922ffb48516 100644
--- a/drivers/iio/imu/adis16475.c
+++ b/drivers/iio/imu/adis16475.c
@@ -1561,9 +1561,8 @@ static void adis16475_burst32_check(struct adis16475 *st)
}
}
-static int adis16475_push_single_sample(struct iio_poll_func *pf)
+static int adis16475_push_single_sample(struct iio_dev *indio_dev, s64 timestamp)
{
- struct iio_dev *indio_dev = pf->indio_dev;
struct adis16475 *st = iio_priv(indio_dev);
struct adis *adis = &st->adis;
int ret, bit, buff_offset = 0, i = 0;
@@ -1652,7 +1651,7 @@ static int adis16475_push_single_sample(struct iio_poll_func *pf)
}
/* There might not be a timestamp option for some devices. */
- iio_push_to_buffers_with_timestamp(indio_dev, st->data, pf->timestamp);
+ iio_push_to_buffers_with_timestamp(indio_dev, st->data, timestamp);
return 0;
}
@@ -1663,7 +1662,7 @@ static irqreturn_t adis16475_trigger_handler(int irq, void *p)
struct iio_dev *indio_dev = pf->indio_dev;
struct adis16475 *st = iio_priv(indio_dev);
- adis16475_push_single_sample(pf);
+ adis16475_push_single_sample(indio_dev, pf->timestamp);
/*
* We only check the burst mode at the end of the current capture since
* it takes a full data ready cycle for the device to update the burst
@@ -1694,9 +1693,9 @@ static void adis16575_update_msg_for_burst(struct adis *adis, u8 burst_req)
tx[0] = ADIS_READ_REG(burst_req);
}
-static int adis16575_custom_burst_read(struct iio_poll_func *pf, u8 burst_req)
+static int adis16575_custom_burst_read(struct iio_dev *indio_dev, u8 burst_req,
+ s64 timestamp)
{
- struct iio_dev *indio_dev = pf->indio_dev;
struct adis16475 *st = iio_priv(indio_dev);
struct adis *adis = &st->adis;
@@ -1705,7 +1704,7 @@ static int adis16575_custom_burst_read(struct iio_poll_func *pf, u8 burst_req)
if (burst_req)
return spi_sync(adis->spi, &adis->msg);
- return adis16475_push_single_sample(pf);
+ return adis16475_push_single_sample(indio_dev, timestamp);
}
/*
@@ -1748,18 +1747,19 @@ static irqreturn_t adis16475_trigger_handler_with_fifo(int irq, void *p)
* First burst request - FIFO pop: popped data will be returned in the
* next burst request.
*/
- ret = adis16575_custom_burst_read(pf, adis->data->burst_reg_cmd);
+ ret = adis16575_custom_burst_read(indio_dev, adis->data->burst_reg_cmd,
+ pf->timestamp);
if (ret)
goto unlock;
for (i = 0; i < fifo_cnt - 1; i++) {
- ret = adis16475_push_single_sample(pf);
+ ret = adis16475_push_single_sample(indio_dev, pf->timestamp);
if (ret)
goto unlock;
}
/* FIFO read without popping */
- ret = adis16575_custom_burst_read(pf, 0);
+ ret = adis16575_custom_burst_read(indio_dev, 0, pf->timestamp);
unlock:
/*
--
2.43.0
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 4/7] iio: imu: adis16475: Use a kfifo buffer for the devices with a FIFO
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
` (2 preceding siblings ...)
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 ` Radu Sabau via B4 Relay
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
` (2 subsequent siblings)
6 siblings, 0 replies; 10+ messages in thread
From: Radu Sabau via B4 Relay @ 2026-11-23 13:25 UTC (permalink / raw)
To: Nuno Sá,
Michael Hennerich, Jonathan Cameron, David Lechner,
Andy Shevchenko, Ramona Gradinariu, Radu Sabau
Cc: linux-iio, linux, linux-kernel, Jonathan Cameron
From: Radu Sabau <radu.sabau@analog.com>
The ADIS1657x variants read their FIFO from a trigger handler, which runs
from iio_trigger_poll() called in the FIFO interrupt thread, and the
capture depends on the selected trigger.
Switch them to devm_adis_setup_kfifo_buffer(): the FIFO interrupt thread
now reads the FIFO and pushes the samples to a kfifo buffer. The interrupt
is requested disabled and is enabled once the device FIFO is running, and
disabled before it is stopped, from the buffer setup functions. This
replaces the trigger's set_trigger_state(), which did the same through
adis_enable_irq().
The trigger is still registered and trigger/current_trigger is unchanged
for users: the buffer simply does not use it any more, so writing it has
no effect and a buffer can now also be enabled without selecting one.
Signed-off-by: Radu Sabau <radu.sabau@analog.com>
---
drivers/iio/imu/adis16475.c | 55 ++++++++++++++++++++++++++++++---------------
1 file changed, 37 insertions(+), 18 deletions(-)
diff --git a/drivers/iio/imu/adis16475.c b/drivers/iio/imu/adis16475.c
index 6922ffb48516..394b13431ae8 100644
--- a/drivers/iio/imu/adis16475.c
+++ b/drivers/iio/imu/adis16475.c
@@ -517,9 +517,26 @@ static int adis16475_buffer_postenable(struct iio_dev *indio_dev)
{
struct adis16475 *st = iio_priv(indio_dev);
struct adis *adis = &st->adis;
+ int ret;
+
+ ret = adis_update_bits(adis, ADIS16475_REG_FIFO_CTRL,
+ ADIS16575_FIFO_EN_MASK, (u16)ADIS16575_FIFO_EN(1));
+ if (ret)
+ return ret;
+
+ enable_irq(adis->spi->irq);
- return adis_update_bits(adis, ADIS16475_REG_FIFO_CTRL,
- ADIS16575_FIFO_EN_MASK, (u16)ADIS16575_FIFO_EN(1));
+ return 0;
+}
+
+static int adis16475_buffer_predisable(struct iio_dev *indio_dev)
+{
+ struct adis16475 *st = iio_priv(indio_dev);
+
+ /* Not under the adis lock: this waits for the IRQ thread, which takes it */
+ disable_irq(st->adis.spi->irq);
+
+ return 0;
}
static int adis16475_buffer_postdisable(struct iio_dev *indio_dev)
@@ -541,6 +558,7 @@ static int adis16475_buffer_postdisable(struct iio_dev *indio_dev)
static const struct iio_buffer_setup_ops adis16475_buffer_ops = {
.postenable = adis16475_buffer_postenable,
+ .predisable = adis16475_buffer_predisable,
.postdisable = adis16475_buffer_postdisable,
};
@@ -1708,7 +1726,7 @@ static int adis16575_custom_burst_read(struct iio_dev *indio_dev, u8 burst_req,
}
/*
- * This handler is meant to be used for devices which support burst readings
+ * This IRQ thread is meant to be used for devices which support burst readings
* from FIFO (namely devices from adis1657x family).
* In order to pop the FIFO the 0x68 0x00 FIFO pop burst request has to be sent.
* If the previous device command was not a FIFO pop burst request, the FIFO pop
@@ -1721,12 +1739,12 @@ static int adis16575_custom_burst_read(struct iio_dev *indio_dev, u8 burst_req,
* different from a 0x68 0x00 or a 0x00 0x00 burst request, the FIFO data popped
* previously will be lost.
*/
-static irqreturn_t adis16475_trigger_handler_with_fifo(int irq, void *p)
+static irqreturn_t adis16475_fifo_irq_thread(int irq, void *p)
{
- struct iio_poll_func *pf = p;
- struct iio_dev *indio_dev = pf->indio_dev;
+ struct iio_dev *indio_dev = p;
struct adis16475 *st = iio_priv(indio_dev);
struct adis *adis = &st->adis;
+ s64 timestamp = iio_get_time_ns(indio_dev);
int ret;
u16 fifo_cnt, i;
@@ -1736,10 +1754,7 @@ static irqreturn_t adis16475_trigger_handler_with_fifo(int irq, void *p)
if (ret)
goto unlock;
- /*
- * If no sample is available, nothing can be read. This can happen if
- * a the used trigger has a higher frequency than the selected sample rate.
- */
+ /* If no sample is available, nothing can be read. */
if (!fifo_cnt)
goto unlock;
@@ -1748,18 +1763,18 @@ static irqreturn_t adis16475_trigger_handler_with_fifo(int irq, void *p)
* next burst request.
*/
ret = adis16575_custom_burst_read(indio_dev, adis->data->burst_reg_cmd,
- pf->timestamp);
+ timestamp);
if (ret)
goto unlock;
for (i = 0; i < fifo_cnt - 1; i++) {
- ret = adis16475_push_single_sample(indio_dev, pf->timestamp);
+ ret = adis16475_push_single_sample(indio_dev, timestamp);
if (ret)
goto unlock;
}
/* FIFO read without popping */
- ret = adis16575_custom_burst_read(indio_dev, 0, pf->timestamp);
+ ret = adis16575_custom_burst_read(indio_dev, 0, timestamp);
unlock:
/*
@@ -1767,7 +1782,6 @@ static irqreturn_t adis16475_trigger_handler_with_fifo(int irq, void *p)
* reading data from registers will impact the FIFO reading.
*/
adis16475_burst32_check(st);
- iio_trigger_notify_done(indio_dev->trig);
return IRQ_HANDLED;
}
@@ -1978,10 +1992,15 @@ static int adis16475_probe(struct spi_device *spi)
return ret;
if (st->adis.data->has_fifo) {
- ret = devm_adis_setup_buffer_and_trigger_with_attrs(&st->adis, indio_dev,
- adis16475_trigger_handler_with_fifo,
- &adis16475_buffer_ops,
- adis16475_fifo_attributes);
+ ret = devm_adis_setup_kfifo_buffer(&st->adis, indio_dev,
+ adis16475_fifo_irq_thread,
+ &adis16475_buffer_ops,
+ adis16475_fifo_attributes);
+ if (ret)
+ return ret;
+
+ /* Keep the trigger/current_trigger interface of these devices */
+ ret = devm_adis_register_fifo_trigger(&st->adis, indio_dev);
if (ret)
return ret;
--
2.43.0
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 5/7] iio: imu: adis: Drop the FIFO handling from the data ready trigger
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
` (3 preceding siblings ...)
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-23 13:25 ` 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-23 13:25 ` [PATCH 7/7] iio: imu: adis16607: Report loss of external sync Radu Sabau via B4 Relay
6 siblings, 0 replies; 10+ messages in thread
From: Radu Sabau via B4 Relay @ 2026-11-23 13:25 UTC (permalink / raw)
To: Nuno Sá,
Michael Hennerich, Jonathan Cameron, David Lechner,
Andy Shevchenko, Ramona Gradinariu, Radu Sabau
Cc: linux-iio, linux, linux-kernel, Jonathan Cameron
From: Radu Sabau <radu.sabau@analog.com>
No device with a FIFO uses the data ready trigger any more, they all use
devm_adis_setup_kfifo_buffer(). Remove the threaded oneshot interrupt
request meant for them from devm_adis_probe_trigger(), which now only
serves the data ready devices.
Signed-off-by: Radu Sabau <radu.sabau@analog.com>
---
drivers/iio/imu/adis_trigger.c | 18 +++++-------------
1 file changed, 5 insertions(+), 13 deletions(-)
diff --git a/drivers/iio/imu/adis_trigger.c b/drivers/iio/imu/adis_trigger.c
index ea8661bff901..14d29ea60273 100644
--- a/drivers/iio/imu/adis_trigger.c
+++ b/drivers/iio/imu/adis_trigger.c
@@ -84,19 +84,11 @@ int devm_adis_probe_trigger(struct adis *adis, struct iio_dev *indio_dev)
if (ret)
return ret;
- if (adis->data->has_fifo)
- ret = devm_request_threaded_irq(&adis->spi->dev, adis->spi->irq,
- NULL,
- &iio_trigger_generic_data_rdy_poll,
- adis->irq_flag | IRQF_ONESHOT,
- indio_dev->name,
- adis->trig);
- else
- ret = devm_request_irq(&adis->spi->dev, adis->spi->irq,
- &iio_trigger_generic_data_rdy_poll,
- adis->irq_flag | IRQF_NO_THREAD,
- indio_dev->name,
- adis->trig);
+ ret = devm_request_irq(&adis->spi->dev, adis->spi->irq,
+ &iio_trigger_generic_data_rdy_poll,
+ adis->irq_flag | IRQF_NO_THREAD,
+ indio_dev->name,
+ adis->trig);
if (ret)
return ret;
--
2.43.0
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 6/7] iio: imu: adis16607: Add FIFO-based buffered capture
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
` (4 preceding siblings ...)
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 ` Radu Sabau via B4 Relay
2026-11-23 13:25 ` [PATCH 7/7] iio: imu: adis16607: Report loss of external sync Radu Sabau via B4 Relay
6 siblings, 0 replies; 10+ messages in thread
From: Radu Sabau via B4 Relay @ 2026-11-23 13:25 UTC (permalink / raw)
To: Nuno Sá,
Michael Hennerich, Jonathan Cameron, David Lechner,
Andy Shevchenko, Ramona Gradinariu, Radu Sabau
Cc: linux-iio, linux, linux-kernel, Jonathan Cameron
From: Radu Sabau <radu.sabau@analog.com>
Add buffered capture via the device's hardware FIFO, the only capture
mode this driver supports. Popping the FIFO uses a dedicated command and
payload format (FIFO_DATA_CMD, 52 bytes, no checksum). The channels are
described as big endian words with the value in their upper bits, as the
device sends them, so the samples are copied to the buffer unchanged.
The samples go to a kfifo buffer set up with the adislib kfifo helper,
filled from a threaded interrupt: the device raises one interrupt per
watermark, not per sample, so there is nothing to trigger on. The
watermark-met condition is signaled via DEV_NOK on the device's one
interrupt pin, which stays asserted until DIAG_STAT is read and cleared.
The interrupt is therefore level-triggered and oneshot, and it is enabled
only while the buffer is. DEV_NOK fires on any DIAG_STAT flag, not just
FIFO_THRESH_MET, so the handler checks that specific bit before popping
anything and leaves interrupts it did not raise to the core. DR_GPIO_MASK
stays enabled unconditionally: DR pulses drive the FIFO controller's
internal sample enqueue, independent of pin routing.
Watermark is configurable via the standard hwfifo_set_watermark callback
and the usual hwfifo_* sysfs attributes. Changing the sampling frequency
while the buffer is enabled returns -EBUSY, as the decimation can't change
during capture.
Signed-off-by: Radu Sabau <radu.sabau@analog.com>
---
drivers/iio/imu/Kconfig | 2 +
drivers/iio/imu/adis16607.c | 386 ++++++++++++++++++++++++++++++++++++++++++--
2 files changed, 377 insertions(+), 11 deletions(-)
diff --git a/drivers/iio/imu/Kconfig b/drivers/iio/imu/Kconfig
index b00acccab061..b56af04e003d 100644
--- a/drivers/iio/imu/Kconfig
+++ b/drivers/iio/imu/Kconfig
@@ -69,6 +69,8 @@ config ADIS16607
tristate "Analog Devices ADIS16607 and similar IMU driver"
depends on SPI
select IIO_ADIS_LIB
+ select IIO_ADIS_LIB_BUFFER
+ select IIO_BUFFER
help
Say yes here to build support for Analog Devices ADIS16607-2
and ADIS16607-3 inertial sensors containing triaxis
diff --git a/drivers/iio/imu/adis16607.c b/drivers/iio/imu/adis16607.c
index 749ed7445f73..60433c97a855 100644
--- a/drivers/iio/imu/adis16607.c
+++ b/drivers/iio/imu/adis16607.c
@@ -11,8 +11,11 @@
#include <linux/clk.h>
#include <linux/debugfs.h>
#include <linux/delay.h>
+#include <linux/iio/buffer.h>
#include <linux/iio/iio.h>
#include <linux/iio/imu/adis.h>
+#include <linux/iio/sysfs.h>
+#include <linux/interrupt.h>
#include <linux/math.h>
#include <linux/minmax.h>
#include <linux/module.h>
@@ -20,6 +23,7 @@
#include <linux/regulator/consumer.h>
#include <linux/seq_file.h>
#include <linux/spi/spi.h>
+#include <linux/stringify.h>
#include <linux/unaligned.h>
#include <linux/units.h>
@@ -43,9 +47,12 @@
#define ADIS16607_REG_Y_DELTANG 0x1A
#define ADIS16607_REG_Z_DELTANG 0x1C
#define ADIS16607_REG_TEMP 0x20
+#define ADIS16607_REG_FIFO_WORD_CNT 0x2B
#define ADIS16607_REG_USER_GPIO_CFG 0x2F
#define ADIS16607_REG_SPI_HALFDUPLEX 0x32
#define ADIS16607_REG_USER_SYNC 0x33
+#define ADIS16607_REG_USER_DATA_CFG 0x34
+#define ADIS16607_REG_USER_FIFO_CFG 0x35
#define ADIS16607_REG_SOFT_RESET 0x36
#define ADIS16607_REG_SELF_TEST 0x39
#define ADIS16607_REG_DEC_RATE 0x3A
@@ -63,9 +70,30 @@
/* Masks */
#define ADIS16607_RESET_GPIO_MASK GENMASK(2, 0)
#define ADIS16607_SYNC_GPIO_MASK GENMASK(8, 6)
+#define ADIS16607_DR_GPIO_MASK GENMASK(11, 9)
+#define ADIS16607_DEV_NOK_MASK GENMASK(14, 12)
+#define ADIS16607_DATA_CNTR_EN_MASK BIT(14)
+#define ADIS16607_BURST32_MASK BIT(15)
#define ADIS16607_SYNC_MODE_MASK BIT(15)
#define ADIS16607_BOOTLOADER_BUSY_MASK BIT(0)
+/* FIFO masks */
+#define ADIS16607_FIFO_THR_MASK GENMASK(10, 0)
+#define ADIS16607_FIFO_FLUSH_MASK BIT(15)
+#define ADIS16607_FIFO_THR_MET_MASK BIT(0)
+#define ADIS16607_FIFO_DATA_CMD 0xA9
+
+/* FIFO limits */
+#define ADIS16607_MAX_FIFO_WM 38
+#define ADIS16607_FIFO_WORDS_PER_SAMPLE 26
+#define ADIS16607_FIFO_DATA_LEN 52
+
+/* FIFO_DATA read - Half-Duplex: 2-byte command phase, then the FIFO data */
+#define ADIS16607_FIFO_DATA_CMD_SIZE 2
+
+/* Largest scan: 12 channels of 24 bits stored as 32, plus 16-bit temperature */
+#define ADIS16607_SCAN_DATA_SIZE (12 * sizeof(s32) + sizeof(s16))
+
/* Self-test registers and masks */
#define ADIS16607_REG_SELF_TEST_DATA(x) ((x) + 0x23)
#define ADIS16607_SNSR_SELF_TEST_MASK BIT(6)
@@ -114,6 +142,12 @@ struct adis16607 {
u32 sync_mode;
u16 sync_scale;
u16 dec;
+ u16 fifo_watermark;
+ /* IIO buffer for reordered data - sized for max channels */
+ IIO_DECLARE_BUFFER_WITH_TS(u8, data, ADIS16607_SCAN_DATA_SIZE);
+ /* Scratch buffer used for FIFO pop operations, see adis16607_fifo_pop() */
+ u8 fifo_buf[ADIS16607_FIFO_DATA_CMD_SIZE + ADIS16607_FIFO_DATA_LEN]
+ __aligned(IIO_DMA_MINALIGN);
};
enum {
@@ -257,6 +291,267 @@ static const struct adis_ops adis16607_ops = {
.reset = adis16607_reset,
};
+/*
+ * FIFO_DATA layout (52 bytes after the 2-byte command phase, DATA_CNTR
+ * enabled, no DIAG_STAT and no checksum). Each inertial channel is a big
+ * endian 32-bit word holding the 24-bit value in its upper bits, TEMP is a
+ * big endian 16-bit word:
+ * 0-3 ACCEL_X, 4-7 ACCEL_Y, 8-11 ACCEL_Z, 12-15 GYRO_X, 16-19 GYRO_Y,
+ * 20-23 GYRO_Z, 24-27 DELTVEL_X, 28-31 DELTVEL_Y, 32-35 DELTVEL_Z,
+ * 36-39 DELTANG_X, 40-43 DELTANG_Y, 44-47 DELTANG_Z, 48-49 TEMP,
+ * 50-51 DATA_CNTR
+ */
+static const u8 adis16607_fifo_offsets[] = {
+ [ADIS16607_SCAN_ACCEL_X] = 0,
+ [ADIS16607_SCAN_ACCEL_Y] = 4,
+ [ADIS16607_SCAN_ACCEL_Z] = 8,
+ [ADIS16607_SCAN_GYRO_X] = 12,
+ [ADIS16607_SCAN_GYRO_Y] = 16,
+ [ADIS16607_SCAN_GYRO_Z] = 20,
+ [ADIS16607_SCAN_DELTVEL_X] = 24,
+ [ADIS16607_SCAN_DELTVEL_Y] = 28,
+ [ADIS16607_SCAN_DELTVEL_Z] = 32,
+ [ADIS16607_SCAN_DELTANG_X] = 36,
+ [ADIS16607_SCAN_DELTANG_Y] = 40,
+ [ADIS16607_SCAN_DELTANG_Z] = 44,
+ [ADIS16607_SCAN_TEMP] = 48,
+};
+
+/* Pop one sample from the FIFO into st->fifo_buf with the FIFO_DATA command */
+static int adis16607_fifo_pop(struct adis16607 *st)
+{
+ struct spi_message msg;
+ struct spi_transfer xfer = {
+ .tx_buf = st->fifo_buf,
+ .rx_buf = st->fifo_buf,
+ .len = ADIS16607_FIFO_DATA_CMD_SIZE + ADIS16607_FIFO_DATA_LEN,
+ };
+
+ st->fifo_buf[0] = ADIS16607_FIFO_DATA_CMD;
+
+ spi_message_init_with_transfers(&msg, &xfer, 1);
+
+ return spi_sync(st->adis.spi, &msg);
+}
+
+/*
+ * Push the scan just popped into st->fifo_buf. The channels are described as
+ * big endian with their value in the upper bits, so the bytes are copied as
+ * they come from the device.
+ */
+static void adis16607_fifo_push_scan(struct iio_dev *indio_dev, s64 timestamp)
+{
+ struct adis16607 *st = iio_priv(indio_dev);
+ const u8 *sample = st->fifo_buf + ADIS16607_FIFO_DATA_CMD_SIZE;
+ unsigned int offset = 0;
+ int bit;
+
+ memset(st->data, 0, sizeof(st->data));
+
+ iio_for_each_active_channel(indio_dev, bit) {
+ unsigned int size = bit == ADIS16607_SCAN_TEMP ? sizeof(s16) :
+ sizeof(s32);
+
+ memcpy(&st->data[offset], &sample[adis16607_fifo_offsets[bit]],
+ size);
+ offset += size;
+ }
+
+ iio_push_to_buffers_with_ts(indio_dev, st->data, sizeof(st->data),
+ timestamp);
+}
+
+/* Called with the adis lock held, so dec and clk_freq_mHz match each other */
+static s64 adis16607_sample_period_ns(struct adis16607 *st)
+{
+ u64 period_ns;
+
+ /* clk_freq_mHz is in millihertz, hence the MILLIHZ_PER_HZ factor */
+ period_ns = NSEC_PER_SEC;
+ period_ns *= MILLIHZ_PER_HZ;
+ period_ns *= st->dec + 1;
+
+ return DIV_ROUND_CLOSEST_ULL(period_ns, st->clk_freq_mHz);
+}
+
+/*
+ * Drain the device FIFO. DEV_NOK raises the interrupt on any DIAG_STAT flag,
+ * not just FIFO_THRESH_MET - the DIAG_STAT read below both checks which flag
+ * raised it and clears the latched status, and must happen before any FIFO
+ * pop, or we would pop for nothing on an unrelated flag.
+ */
+static irqreturn_t adis16607_irq_thread(int irq, void *p)
+{
+ struct iio_dev *indio_dev = p;
+ struct adis16607 *st = iio_priv(indio_dev);
+ s64 irq_timestamp = iio_get_time_ns(indio_dev);
+ u16 diag_stat, word_cnt, sample_cnt;
+ s64 period_ns, timestamp;
+ int ret;
+
+ adis_dev_auto_lock(&st->adis);
+
+ /* A failed read says nothing about who raised the interrupt */
+ ret = __adis_read_reg_16(&st->adis, ADIS16607_REG_DIAG_STAT, &diag_stat);
+ if (ret)
+ return IRQ_HANDLED;
+
+ if (!(diag_stat & ADIS16607_FIFO_THR_MET_MASK))
+ return IRQ_NONE;
+
+ ret = __adis_read_reg_16(&st->adis, ADIS16607_REG_FIFO_WORD_CNT, &word_cnt);
+ if (ret)
+ return IRQ_HANDLED;
+
+ sample_cnt = word_cnt / ADIS16607_FIFO_WORDS_PER_SAMPLE;
+ if (!sample_cnt)
+ return IRQ_HANDLED;
+
+ /*
+ * irq_timestamp is when the newest sample tipped the FIFO over its
+ * watermark. The FIFO pops oldest-first, so back-date the first
+ * popped sample by the batch duration: the loop then counts up to
+ * irq_timestamp for the newest sample, instead of projecting past it.
+ */
+ period_ns = adis16607_sample_period_ns(st);
+ timestamp = irq_timestamp - (sample_cnt - 1) * period_ns;
+
+ for (unsigned int i = 0; i < sample_cnt; i++) {
+ ret = adis16607_fifo_pop(st);
+ if (ret)
+ return IRQ_HANDLED;
+
+ adis16607_fifo_push_scan(indio_dev, timestamp);
+ timestamp += period_ns;
+ }
+
+ return IRQ_HANDLED;
+}
+
+/* FIFO sysfs attributes */
+IIO_STATIC_CONST_DEVICE_ATTR(hwfifo_watermark_min, "1");
+IIO_STATIC_CONST_DEVICE_ATTR(hwfifo_watermark_max, __stringify(ADIS16607_MAX_FIFO_WM));
+
+static ssize_t hwfifo_watermark_show(struct device *dev,
+ struct device_attribute *attr,
+ char *buf)
+{
+ struct iio_dev *indio_dev = dev_to_iio_dev(dev);
+ struct adis16607 *st = iio_priv(indio_dev);
+
+ return sysfs_emit(buf, "%u\n", st->fifo_watermark);
+}
+
+static ssize_t hwfifo_enabled_show(struct device *dev,
+ struct device_attribute *attr,
+ char *buf)
+{
+ struct iio_dev *indio_dev = dev_to_iio_dev(dev);
+ struct adis16607 *st = iio_priv(indio_dev);
+ u16 val;
+ int ret;
+
+ ret = adis_read_reg_16(&st->adis, ADIS16607_REG_USER_FIFO_CFG, &val);
+ if (ret)
+ return ret;
+
+ return sysfs_emit(buf, "%d\n", (val & ADIS16607_FIFO_THR_MASK) ? 1 : 0);
+}
+
+static IIO_DEVICE_ATTR_RO(hwfifo_watermark, 0);
+static IIO_DEVICE_ATTR_RO(hwfifo_enabled, 0);
+
+static const struct iio_dev_attr *adis16607_fifo_attributes[] = {
+ &iio_dev_attr_hwfifo_watermark_min,
+ &iio_dev_attr_hwfifo_watermark_max,
+ &iio_dev_attr_hwfifo_watermark,
+ &iio_dev_attr_hwfifo_enabled,
+ NULL
+};
+
+static int adis16607_buffer_postenable(struct iio_dev *indio_dev)
+{
+ struct adis16607 *st = iio_priv(indio_dev);
+ struct adis *adis = &st->adis;
+ u16 threshold;
+ int ret;
+
+ adis_dev_auto_lock(adis);
+
+ /* Flush FIFO to start clean */
+ ret = __adis_write_reg_16(adis, ADIS16607_REG_USER_FIFO_CFG,
+ ADIS16607_FIFO_FLUSH_MASK);
+ if (ret)
+ return ret;
+
+ /* Enable FIFO with watermark threshold (in word count) */
+ threshold = st->fifo_watermark * ADIS16607_FIFO_WORDS_PER_SAMPLE;
+ ret = __adis_write_reg_16(adis, ADIS16607_REG_USER_FIFO_CFG,
+ threshold & ADIS16607_FIFO_THR_MASK);
+ if (ret)
+ return ret;
+
+ /*
+ * The device cannot mask DEV_NOK for us: unrouting it leaves the pin
+ * on its weak pull-up, which reads as asserted. Mask it on the host.
+ */
+ enable_irq(adis->spi->irq);
+
+ return 0;
+}
+
+static int adis16607_buffer_predisable(struct iio_dev *indio_dev)
+{
+ struct adis16607 *st = iio_priv(indio_dev);
+
+ /* Waits for a running handler, so no drain races the FIFO disable */
+ disable_irq(st->adis.spi->irq);
+
+ return 0;
+}
+
+static int adis16607_buffer_postdisable(struct iio_dev *indio_dev)
+{
+ struct adis16607 *st = iio_priv(indio_dev);
+ struct adis *adis = &st->adis;
+ u16 diag_stat;
+ int ret;
+
+ adis_dev_auto_lock(adis);
+
+ /* Disable FIFO */
+ ret = __adis_write_reg_16(adis, ADIS16607_REG_USER_FIFO_CFG, 0);
+ if (ret)
+ return ret;
+
+ /*
+ * Leave the device clean at the end of a session, so the next one
+ * does not start on leftover samples and a still-latched
+ * FIFO_THR_MET.
+ */
+ ret = __adis_write_reg_16(adis, ADIS16607_REG_USER_FIFO_CFG,
+ ADIS16607_FIFO_FLUSH_MASK);
+ if (ret)
+ return ret;
+
+ return __adis_read_reg_16(adis, ADIS16607_REG_DIAG_STAT, &diag_stat);
+}
+
+static const struct iio_buffer_setup_ops adis16607_buffer_ops = {
+ .postenable = adis16607_buffer_postenable,
+ .predisable = adis16607_buffer_predisable,
+ .postdisable = adis16607_buffer_postdisable,
+};
+
+static int adis16607_set_watermark(struct iio_dev *indio_dev, unsigned int val)
+{
+ struct adis16607 *st = iio_priv(indio_dev);
+
+ st->fifo_watermark = clamp(val, 1, ADIS16607_MAX_FIFO_WM);
+
+ return 0;
+}
+
/*
* Check if the delta between two values is within specified range.
*/
@@ -344,7 +639,8 @@ static int adis16607_sensor_self_test(struct adis16607 *st)
/*
* Called by __adis_initial_startup() right after reset, before self-test:
- * SPI Half-Duplex locking, dev_id verification and the bootloader check.
+ * SPI Half-Duplex locking, dev_id verification, the bootloader check,
+ * enabling 32-bit burst mode + DATA_CNTR and the DR/DEV_NOK pin routing.
*/
static int adis16607_init(struct adis *adis)
{
@@ -385,7 +681,29 @@ static int adis16607_init(struct adis *adis)
if (digital_status & ADIS16607_BOOTLOADER_BUSY_MASK)
return dev_err_probe(dev, -EBUSY, "bootloader is busy\n");
- return 0;
+ /* Enable 32-bit burst mode and DATA_CNTR - one-time, used by FIFO pops */
+ ret = __adis_update_bits_base(adis, ADIS16607_REG_USER_DATA_CFG,
+ ADIS16607_BURST32_MASK | ADIS16607_DATA_CNTR_EN_MASK,
+ ADIS16607_BURST32_MASK | ADIS16607_DATA_CNTR_EN_MASK, 2);
+ if (ret)
+ return ret;
+
+ /*
+ * DR_GPIO_MASK and DEV_NOK_MASK are updated here rather than written
+ * blind, so this doesn't clobber the RESET_GPIO_MASK bit already
+ * configured earlier in probe(). Per datasheet, DR pulses are what
+ * drive the FIFO controller's internal enqueue logic. DR and
+ * DEV_NOK are separate physical pins, so enabling DR_GPIO_MASK here
+ * does not put DR's full-sample-rate pulses onto the interrupt line
+ * - DEV_NOK_MASK routes the aggregate "any DIAG_STAT flag asserted"
+ * signal onto the one physically-wired interrupt pin, which is what
+ * actually fires on FIFO_THRESH_MET, at the (much lower) watermark
+ * rate, not the sample rate.
+ */
+ return __adis_update_bits_base(adis, ADIS16607_REG_USER_GPIO_CFG,
+ ADIS16607_DR_GPIO_MASK | ADIS16607_DEV_NOK_MASK,
+ FIELD_PREP(ADIS16607_DR_GPIO_MASK, 1) |
+ FIELD_PREP(ADIS16607_DEV_NOK_MASK, 1), 2);
}
/*
@@ -602,21 +920,16 @@ static int adis16607_set_freq(struct adis16607 *st, u32 freq)
/*
* .address is an index into adis16607_chan_regs[] for this driver, not a
- * literal register like adis_single_conversion() expects, and the channel
- * spec carries no scan_type for it to take the register width and sign
- * extension from. Resolve both on a local copy rather than reimplementing
- * the helper's locking logic ourselves.
+ * literal register like adis_single_conversion() expects - resolve it on a
+ * local copy rather than reimplementing the helper's locking and
+ * sign-extension logic ourselves.
*/
static int adis16607_raw_read(struct iio_dev *indio_dev,
const struct iio_chan_spec *chan, int *val)
{
struct iio_chan_spec raw_chan = *chan;
- bool is_temp = chan->type == IIO_TEMP;
raw_chan.address = adis16607_chan_regs[chan->address].raw_reg;
- raw_chan.scan_type.sign = 's';
- raw_chan.scan_type.realbits = is_temp ? 16 : 24;
- raw_chan.scan_type.storagebits = is_temp ? 16 : 32;
return adis_single_conversion(indio_dev, &raw_chan, 0, val);
}
@@ -693,7 +1006,12 @@ static int adis16607_write_raw(struct iio_dev *indio_dev,
u32 tmp;
switch (info) {
- case IIO_CHAN_INFO_SAMP_FREQ:
+ case IIO_CHAN_INFO_SAMP_FREQ: {
+ /* The decimation must not change while the buffer is running */
+ IIO_DEV_ACQUIRE_DIRECT_MODE(indio_dev, claim);
+ if (IIO_DEV_ACQUIRE_FAILED(claim))
+ return -EBUSY;
+
if (val < 0 || val2 < 0)
return -EINVAL;
@@ -701,6 +1019,7 @@ static int adis16607_write_raw(struct iio_dev *indio_dev,
tmp = val * MILLIHZ_PER_HZ +
val2 / (MICROHZ_PER_HZ / MILLIHZ_PER_HZ);
return adis16607_set_freq(st, tmp);
+ }
case IIO_CHAN_INFO_CALIBBIAS: {
u16 reg = adis16607_chan_regs[chan->address].calib_bias_reg;
@@ -725,6 +1044,14 @@ static int adis16607_write_raw(struct iio_dev *indio_dev,
.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
.info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), \
.address = (_idx), \
+ .scan_index = (_idx), \
+ .scan_type = { \
+ .sign = 's', \
+ .realbits = 24, \
+ .storagebits = 32, \
+ .shift = 8, \
+ .endianness = IIO_BE, \
+ }, \
}
#define ADIS16607_ACCEL_CHANNEL(_mod) \
@@ -744,6 +1071,14 @@ static int adis16607_write_raw(struct iio_dev *indio_dev,
.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
.info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), \
.address = (_idx), \
+ .scan_index = (_idx), \
+ .scan_type = { \
+ .sign = 's', \
+ .realbits = 24, \
+ .storagebits = 32, \
+ .shift = 8, \
+ .endianness = IIO_BE, \
+ }, \
}
#define ADIS16607_DELTANG_CHAN(_mod) \
@@ -776,13 +1111,22 @@ static const struct iio_chan_spec adis16607_channels[] = {
BIT(IIO_CHAN_INFO_OFFSET),
.info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ),
.address = ADIS16607_SCAN_TEMP,
+ .scan_index = ADIS16607_SCAN_TEMP,
+ .scan_type = {
+ .sign = 's',
+ .realbits = 16,
+ .storagebits = 16,
+ .endianness = IIO_BE,
+ },
},
+ IIO_CHAN_SOFT_TIMESTAMP(ADIS16607_SCAN_MAX),
};
static const struct iio_info adis16607_info = {
.read_raw = adis16607_read_raw,
.write_raw = adis16607_write_raw,
.debugfs_reg_access = adis_debugfs_reg_access,
+ .hwfifo_set_watermark = adis16607_set_watermark,
};
/*
@@ -814,6 +1158,7 @@ static const struct adis_data adis16607_data = {
.diag_stat_size = 2,
.prod_id_reg = ADIS16607_REG_DEV_ID,
.prod_id = 0x6000,
+ .has_fifo = true,
.unmasked_drdy = true,
.init = adis16607_init,
.self_test = adis16607_self_test,
@@ -972,7 +1317,19 @@ static int adis16607_probe(struct spi_device *spi)
indio_dev->info = &adis16607_info;
indio_dev->modes = INDIO_DIRECT_MODE;
+ if (!spi->irq)
+ return dev_err_probe(dev, -EINVAL, "interrupt is required\n");
+
+ /* The core's default; the device watermark follows buffer/watermark */
+ st->fifo_watermark = 1;
+
st->adis.ops = &adis16607_ops;
+ /*
+ * DEV_NOK is the OR of the DIAG_STAT flags and stays high until
+ * DIAG_STAT is read. Use a level interrupt so a flag raised while it
+ * is already high is not lost.
+ */
+ st->adis.irq_flag = IRQF_TRIGGER_HIGH;
ret = devm_regulator_get_enable(dev, "vdd");
if (ret)
@@ -1010,6 +1367,13 @@ static int adis16607_probe(struct spi_device *spi)
if (ret)
return ret;
+ ret = devm_adis_setup_kfifo_buffer(&st->adis, indio_dev,
+ adis16607_irq_thread,
+ &adis16607_buffer_ops,
+ adis16607_fifo_attributes);
+ if (ret)
+ return ret;
+
ret = devm_iio_device_register(dev, indio_dev);
if (ret)
return ret;
--
2.43.0
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 7/7] iio: imu: adis16607: Report loss of external sync
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
` (5 preceding siblings ...)
2026-11-23 13:25 ` [PATCH 6/7] iio: imu: adis16607: Add FIFO-based buffered capture Radu Sabau via B4 Relay
@ 2026-11-23 13:25 ` Radu Sabau via B4 Relay
6 siblings, 0 replies; 10+ messages in thread
From: Radu Sabau via B4 Relay @ 2026-11-23 13:25 UTC (permalink / raw)
To: Nuno Sá,
Michael Hennerich, Jonathan Cameron, David Lechner,
Andy Shevchenko, Ramona Gradinariu, Radu Sabau
Cc: linux-iio, linux, linux-kernel, Jonathan Cameron
From: Radu Sabau <radu.sabau@analog.com>
Loss of the external clock or of the sync PLL lock raises DEV_NOK like any
other DIAG_STAT flag, and the interrupt handler already reads DIAG_STAT.
Warn about SYNC_LOST and DPLL_UNLOCKED there, rate limited, without
stopping the capture, since a short loss of the clock can recover. An
interrupt raised by one of these flags is handled even when the FIFO
threshold is not met.
Signed-off-by: Radu Sabau <radu.sabau@analog.com>
---
drivers/iio/imu/adis16607.c | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/drivers/iio/imu/adis16607.c b/drivers/iio/imu/adis16607.c
index 60433c97a855..dddbe3c7fb52 100644
--- a/drivers/iio/imu/adis16607.c
+++ b/drivers/iio/imu/adis16607.c
@@ -83,6 +83,10 @@
#define ADIS16607_FIFO_THR_MET_MASK BIT(0)
#define ADIS16607_FIFO_DATA_CMD 0xA9
+/* DIAG_STAT sync flags */
+#define ADIS16607_DIAG_DPLL_UNLOCKED BIT(1)
+#define ADIS16607_DIAG_SYNC_LOST BIT(2)
+
/* FIFO limits */
#define ADIS16607_MAX_FIFO_WM 38
#define ADIS16607_FIFO_WORDS_PER_SAMPLE 26
@@ -396,8 +400,17 @@ static irqreturn_t adis16607_irq_thread(int irq, void *p)
if (ret)
return IRQ_HANDLED;
+ /* Only warn: a short loss of the clock should not stop the capture */
+ if (diag_stat & ADIS16607_DIAG_SYNC_LOST)
+ dev_warn_ratelimited(&st->adis.spi->dev, "external sync lost\n");
+
+ if (diag_stat & ADIS16607_DIAG_DPLL_UNLOCKED)
+ dev_warn_ratelimited(&st->adis.spi->dev, "sync PLL unlocked\n");
+
if (!(diag_stat & ADIS16607_FIFO_THR_MET_MASK))
- return IRQ_NONE;
+ return diag_stat & (ADIS16607_DIAG_SYNC_LOST |
+ ADIS16607_DIAG_DPLL_UNLOCKED) ?
+ IRQ_HANDLED : IRQ_NONE;
ret = __adis_read_reg_16(&st->adis, ADIS16607_REG_FIFO_WORD_CNT, &word_cnt);
if (ret)
--
2.43.0
^ permalink raw reply [flat|nested] 10+ messages in thread
* RE: [PATCH 2/7] iio: imu: adis: Add a kfifo buffer setup helper for FIFO devices
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
0 siblings, 0 replies; 10+ messages in thread
From: Sabau, Radu bogdan @ 2026-11-26 9:33 UTC (permalink / raw)
To: Sabau, Radu bogdan, Sa, Nuno, Hennerich, Michael,
Jonathan Cameron, David Lechner, Andy Shevchenko,
Ramona Gradinariu
Cc: linux-iio, linux, linux-kernel
> -----Original Message-----
> From: Radu Sabau via B4 Relay <devnull+radu.sabau.analog.com@kernel.org>
> Sent: Monday, November 23, 2026 3:25 PM
...
> +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);
> + 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);
Sashiko wrote:
> This problem wasn't introduced by this patch, but can
> adis_buffer_cleanup() double free adis->buffer [1]?
> [...]
> [1] https://sashiko.dev/#/bug/linux-966f0cd4-488a-4d69-b8a5-449c751365d2
It is already addressed by Lee Jones' patch, which clears both pointers
after freeing them:
https://lore.kernel.org/all/LV9PR03MB84143639E37408B29B8A1935F7452@LV9PR03MB8414.namprd03.prod.outlook.com/
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 1/7] iio: imu: adis16475: Use the reset timeouts of the ADIS1657x
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
0 siblings, 0 replies; 10+ messages in thread
From: Joshua Crofts @ 2026-11-26 13:34 UTC (permalink / raw)
To: radu.sabau, Nuno Sá,
Michael Hennerich, Jonathan Cameron, David Lechner,
Andy Shevchenko, Ramona Gradinariu
Cc: linux-iio, linux, linux-kernel
On 23-Nov-26 14:25, Radu Sabau via B4 Relay wrote:
> From: Radu Sabau <radu.sabau@analog.com>
>
> The ADIS1657x variants share the timeouts of the ADIS1647x parts, which
> wait 200 ms after a reset. The ADIS1657x datasheets give a longer
> recovery: about 275 ms after a hardware reset, 241 ms after a software
> reset and 282 ms from power on.
>
> Reading the product ID right after the shorter wait returns 0 on an
> ADIS16577-2, so the warning about a product ID mismatch is printed, and
> the registers written while the part is still starting up are lost. This
> includes the FIFO control bits written at probe (watermark pin polarity
> and enable, and the overflow behaviour), so the watermark pin is never
> driven and the FIFO does not behave as configured.
>
> Give the ADIS1657x variants their own timeouts, a bit above the typical
> values from the datasheet.
>
> Fixes: f95920baa066 ("drivers: iio: imu: Add support for adis1657x family")
> Signed-off-by: Radu Sabau <radu.sabau@analog.com>
> ---
Reviewed-by: Joshua Crofts <crofts@kernel.org>
--
Kind regards,
Joshua Crofts
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2026-11-26 13:34 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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-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-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-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-23 13:25 ` [PATCH 7/7] iio: imu: adis16607: Report loss of external sync Radu Sabau via B4 Relay
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®