iio: imu: Add support for the ADI ADIS16607
Subsystems (4)
v4 cover iio: imu: Add support for the ADI ADIS16607
This series adds support for the Analog Devices ADIS16607, a precision MEMS IMU with triaxial gyroscope, triaxial accelerometer, and temperature sensor, communicating over a non-standard SPI Half-Duplex protocol.
Patch 1 adds an optional self_test callback to adislib, for devices whose self-test sequence doesn't fit the generic mask-write/sleep/check-status pattern.
Patch 2 fixes the reset dispatch: both __adis_initial_startup()'s reset fallback and the public adis_reset() wrapper were calling __adis_reset() directly instead of dispatching through adis->ops->reset(). That bug is invisible for every existing adislib driver (adis_default_ops.reset is __adis_reset() itself), but silently breaks a driver with fully custom ops - like this one - on any board without a reset-gpios property, or any caller of adis_reset() on a device like adis16550 whose custom reset op needs a different write size than __adis_reset()'s hardcoded 8-bit one. Carries a Fixes tag for the commit that introduced the hardcoded call; no stable backport is needed since the bug only manifests for a custom-ops driver, and this is the first one.
Patch 3 adds an optional post_reset_setup callback to adislib, for devices that need extra device-specific bring-up between reset and self-test (SPI mode locking, status/bootloader checks, pin or burst-mode configuration, etc.) - not all ADIS devices need this, so it's only called when set, same as self_test.
Patch 4 adds the devicetree binding.
Patches 5-8 add the driver in functional groupings, as requested in v1 review:
- Patch 5: base driver - probe, raw channel reads, decimation/sample frequency, startup and self-test via adislib, debugfs identity entries. No buffered capture yet.
- Patch 6: buffered capture via the device's hardware FIFO.
- Patch 7: external clock sync support.
- Patch 8: calibration bias support for gyro/accel.
Notable points for reviewers:
- The device does not implement the standard ADIS SPI protocol used by other parts in the family; reads/writes are done over a custom Half-Duplex sequence (see adis16607_spi_read()/adis16607_spi_write() and the adis_ops overrides).
- Startup is split across the two new adislib callbacks rather than a driver-private initial_startup(): adis16607_post_reset_setup() does SPI Half-Duplex locking, dev_id verification, the bootloader-busy check, and (once FIFO is wired up in patch 6) burst-mode and DR/DEV_NOK interrupt-pin configuration; adis16607_self_test() does the actual per-axis delta-check, clearing the SELF_TEST register on every exit path (not just success) so a failure doesn't leave the sensor sitting in its self-test/force state.
- GPIO0's reset-pin routing (RESET_GPIO_MASK in USER_GPIO_CFG) is runtime-writable on this part, so a prior write (bug, firmware, direct register access) could leave it de-routed, silently defeating reset-gpios. Patch 5's probe() forces it back to the reset function over SPI before relying on toggling the pin - warning rather than erroring out on failure, so a still-responsive device still gets a real chance at reset. Patch 6 adds the DR/DEV_NOK pins to the same USER_GPIO_CFG register via a read-modify-write, so it can't clobber what probe() already set.
- The hardware FIFO is the *only* buffered capture path - there is no single-sample direct burst-read trigger mode. The FIFO-pop command and the regular burst-read command are genuinely different protocols on this device (different payload shapes, no checksum on the FIFO side), so this stays driver-private rather than going through adislib's generic burst-read helpers.
- The FIFO drain in the trigger handler just reads DIAG_STAT (which clears FIFO_THRESH_MET as a side effect) and pops however many complete samples are available - no disabling, flushing, or re-enabling around the drain. The datasheet's dual-port FIFO architecture means reads and writes don't contend, so there's nothing for a disable step to protect against.
- The FIFO-threshold interrupt is signaled via DEV_NOK on the device's one physically-wired interrupt pin, which stays asserted (level-triggered) until DIAG_STAT is read and cleared - this sets has_fifo on adis_data and requests the IRQ through adislib's threaded/level path, matching adislib's actual contract for that flag.
- An optional external clock (clocks property) selects between SYNC_DIRECT and SYNC_SCALED modes depending on the supplied frequency, with the internal 8 kHz clock used as the default when no clock is provided (adis16607_config_clk()).
This has been tested on a Raspberry Pi 4 (arm64) with the device wired over SPI, exercising the FIFO buffered-capture path with the updated DEV_NOK/level-triggered interrupt wiring.
To: Lars-Peter Clausen <[email protected]>
To: Michael Hennerich <[email protected]>
To: Jonathan Cameron <[email protected]>
To: David Lechner <[email protected]>
To: Nuno Sá <[email protected]>
To: Andy Shevchenko <[email protected]>
To: Rob Herring <[email protected]>
To: Krzysztof Kozlowski <[email protected]>
To: Conor Dooley <[email protected]>
To: Alexandru Ardelean <[email protected]>
Changes in v4:
- Split the combined adislib commit into three: self_test callback, the reset-dispatch fix, and post_reset_setup callback, each its own patch - the original bundled all three under one "Also..." (Jonathan).
- Simplified the reset-dispatch fix: removed the internal settle-time sleep from __adis_reset() entirely and made both call sites (__adis_initial_startup(), adis_reset()) sleep unconditionally after dispatching through adis->ops->reset() - no more comparing against __adis_reset() to decide whether to sleep (Jonathan).
- dt-bindings: commit message now states how adis16607-2/-3 actually differ (gyro full-scale range only) instead of just asserting two variants exist (Jonathan). Narrowed reset-gpios's description to just itself, and expanded the top-level description to explain the device's five GPIO pins and where each one's function is actually modeled (clocks, interrupts, or not exposed) (Jonathan).
- Base driver: moved the RESET_GPIO_MASK force-write from after reset to before it, in probe() - a previously-defeated reset-pin routing (buggy driver, direct reg access) now gets a chance to be corrected before relying on the GPIO toggle, instead of too late to matter; only warns rather than erroring out on failure, so a still-live device keeps its chance at a real reset (Jonathan). Removed the now-redundant duplicate of that same write from adis16607_post_reset_setup() (Andy).
- Base driver: large style/cleanup batch - dropped an unneeded <linux/kernel.h> include, reordered struct adis16607 so struct adis is first (cheaper container_of(), measured -0.41% code size via bloat-o-meter), use spi_message_init_with_transfers() instead of repeated spi_message_add_tail(), ARRAY_SIZE() instead of hardcoded loop bounds, put_unaligned_be16(), combined the firmware/revision debugfs files into one "major.minor"-formatted entry, dropped an unnecessary #ifdef CONFIG_DEBUG_FS wrapper, guard()/ adis_dev_auto_lock() instead of manual mutex lock/unlock, -ENODATA instead of -EINVAL for an unmatched chip_info, unit-suffixed clk_freq_mhz/int_clk_hz field names with MILLI from <linux/units.h> instead of a bare magic 1000, de-duplicated/inlined several single- or two-use macros (Andy, Jonathan).
- Base driver: the self-test startup delay now cites the actual datasheet value (Inertial Settling Time, 40ms) instead of an unexplained 100ms that didn't match anything in the datasheet (Andy). Self-test now clears the SELF_TEST register on every failure path, not just on success (Sashiko AI).
- FIFO: dropped disabling the FIFO before draining and the flush-and-re-enable afterward entirely - the datasheet confirms overflow-only overwrite (not overwrite-during-read) and a dual-port architecture with no read/write contention, so there was nothing for the disable step to protect against, and it was costing real samples during its own disabled window (Jonathan). fifo_buf is now a fixed-size array instead of a heap allocation reallocated on every scan-mode change; deleted the now-unnecessary update_scan_mode() and its devm cleanup entirely (Jonathan). guard()/adis_dev_auto_lock() and direct returns in buffer postenable/postdisable (Jonathan). clamp() instead of clamp_t() - confirmed by building that the forced cast wasn't needed (Jonathan).
- Sync: adis16607_config_clk() now reads DEC_RATE live instead of assuming it's 0 after reset, the same way adis16607_get_freq() already does - consistent with how USER_SYNC is already written explicitly rather than relying on its own reset default (Jonathan).
- Link to v3: https://lore.kernel.org/r/20261015-adis16607-v3-0-f972d4efee85@a
Changes in v3:
- Fixed the public adis_reset() wrapper (adis.h) to also dispatch
through adis->ops->reset() instead of hardcoding __adis_reset() -
the same bug class as the v2 __adis_initial_startup() fix, just a second call site that was missed. Switched both checks from
comparing against adis_default_ops to adis->ops->reset != __adis_reset, which also works from the header, where adis_default_ops isn't
visible (Sashiko).
- Fixed dt-binding wording: dropped "compatible" from the variant description (reads as a DT compatible-string fallback claim, which doesn't exist here - the two variants aren't interchangeable) and dropped a Linux-driver-specific sentence from reset-gpios's
description (Conor); removed a stale commit-message bullet claiming
a FIFO watermark property that was never in the binding (Sashiko).
- Dropped a redundant <linux/mod_devicetable.h> include - <linux/spi/spi.h> already provides it (Uwe, Andy); switched adis16607_id[] to named initializers (Uwe).
- Fixed FIFO sample timestamps: they were projected forward from the IRQ-fire time instead of back-dated, so the newest sample in a batch ended up timestamped in the future. Now back-dated so the newest
sample lands on the IRQ-fire time and earlier ones count back from
it (Sashiko).
- Added a comment explaining why disabling the FIFO during drain, and
the flush afterward, don't lose in-flight samples - no new samples
are enqueued at all while disabled, so nothing can arrive in that window for the flush to drop (Sashiko asked twice, independently).
- Reworked external clock sync configuration (adis16607_config_clk())
so every mode (default/direct/scaled) explicitly writes its own complete SYNC_GPIO_MASK/USER_SYNC state, instead of only writing conditionally when enabling non-default sync (Sashiko x2); switched
the sync scale factor from truncating to rounding division (Sashiko); fixed a real bug where SCALED mode's effective clock was hardcoded
to the nominal internal rate instead of the actual achieved rate (ext_clk_hz * sync_scale), which would have caused FIFO timestamps
to drift whenever the external clock didn't divide the internal
clock exactly (Sashiko).
- Added range validation before writing calibration bias - out-of-
range values were silently truncated to 16 bits instead of being rejected (Sashiko).
- Link to v2: https://lore.kernel.org/r/[email protected]
Changes in v2:
- Split the driver commit into functional groupings per review:
base, FIFO, external clock sync, calibration bias (Nuno).
- Added adis_data.self_test and adis_data.post_reset_setup callbacks
to adislib instead of duplicating startup/self-test logic in the
driver (Nuno). post_reset_setup is a second, honestly-named hook
added after review feedback that overloading self_test to also mean "everything else the device needs at startup" was misleading.
- Fixed __adis_initial_startup()'s reset fallback to dispatch through adis->ops->reset() instead of a hardcoded __adis_reset() call -
found while wiring up this driver's custom reset op. Added a Fixes
tag for the originating commit.
- Removed the direct single-sample burst-read capture path entirely;
the hardware FIFO is now the only buffered capture mode. Dropped adi,fifo-enable from the binding accordingly.
- Fixed FIFO-threshold interrupt wiring: set has_fifo on adis_data and switch the DT interrupt type from edge to level, matching the
DEV_NOK signal this now uses (previously only the data-ready pulse
was wired, which never actually generated a FIFO interrupt).
- Moved the optional reset-status GPIO output into the base driver
patch (where it conceptually belongs) instead of bundling it into
the FIFO patch's USER_GPIO_CFG write; the FIFO patch now updates
that register with a read-modify-write instead of a blind write.
- Fixed cover letter: "Three compatible variants (-1, -2, -3)" was
wrong, there are only two (-2, -3); "configurable data-ready
interrupt pin (DIO1-4)" was wrong, there's a single fixed pin.
- Corrected spi-max-frequency to 10 MHz (datasheet maximum), from
15 MHz.
- Renamed ADIS16607_REG_SW_RES to ADIS16607_REG_SOFT_RESET to match
the datasheet's register name; renamed burst_buf to fifo_buf and dropped the redundant "fifo_" prefix from the buffer postenable/ postdisable/ops names, since FIFO is the only capture mode and
"burst" no longer described what that scratch buffer is used for.
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Radu Sabau (8):
iio: imu: adis: Add optional self_test callback
iio: imu: adis: Fix custom reset dispatch in adislib
iio: imu: adis: Add optional post_reset_setup callback
dt-bindings: iio: imu: Add bindings for ADI ADIS16607
iio: imu: Add driver for the ADI ADIS16607
iio: imu: adis16607: Add FIFO-based buffered/triggered capture
iio: imu: adis16607: Add external clock sync support
iio: imu: adis16607: Add calibration bias support for gyro/accel
.../devicetree/bindings/iio/imu/adi,adis16607.yaml | 94 ++ MAINTAINERS | 8 + drivers/iio/imu/Kconfig | 13 + drivers/iio/imu/Makefile | 1 + drivers/iio/imu/adis.c | 15 +- drivers/iio/imu/adis16607.c | 1325 ++++++++++++++++++++ include/linux/iio/imu/adis.h | 26 +- 7 files changed, 1477 insertions(+), 5 deletions(-)
---
base-commit: 0fcb05b72344f40806cbe810de8872f1698bf053
change-id: 20260617-adis16607-089ffc655ceb
Best regards,
Signature · 1 line
Radu Sabau <[email protected]>
PATCH v4 1/8 iio: imu: adis: Add optional self_test callback
Add an optional self_test callback to struct adis_data, for devices whose self-test doesn't fit the generic mask-write/sleep/check-status sequence. Purely additive: defaults to NULL, no change for existing drivers.
--- drivers/iio/imu/adis.c | 3 +++ include/linux/iio/imu/adis.h | 7 +++++++ 2 files changed, 10 insertions(+)
drivers/iio/imu/adis.c +3 -0
@@ -360,6 +360,9 @@ static int adis_self_test(struct adis *adis)int ret;const struct adis_timeout *timeouts = adis->data->timeouts; +if (adis->data->self_test) +return adis->data->self_test (adis); + ret =__adis_write_reg_16 (adis, adis->data->self_test_reg, adis->data->self_test_mask);if (ret) {
include/linux/iio/imu/adis.h +7 -0
@@ -51,6 +51,12 @@ struct adis_timeout {* @self_test_mask: Bitmask of supported self-test operations * @self_test_reg: Register address to request self test command * @self_test_no_autoclear: True if device's self-test needs clear of ctrl reg +* @self_test: Optional device-specific self-test override. When set, +* it is called instead of the generic mask-write/sleep/ +* check-status sequence. The callback owns its own pass/fail +* determination entirely (it should call __adis_check_status() +* itself if it wants status-register checks). Must return 0 on +* success, a negative error code otherwise. * @status_error_msgs: Array of error messages * @status_error_mask: Bitmask of errors supported by the device * @timeouts: Chip specific delays
@@ -81,6 +87,7 @@ struct adis_data {unsigned int self_test_mask;unsigned int self_test_reg;bool self_test_no_autoclear; +int (*self_test)(struct adis *adis);const struct adis_timeout *timeouts;const char *const *status_error_msgs;
Signature · 1 line
2.43.0
Re: [PATCH v4 1/8] iio: imu: adis: Add optional self_test callback
Quoted 6 lines · Radu Sabau
Add an optional
self_testcallback to structadis_data, for devices whose self-test doesn't fit the generic mask-write/sleep/check-status sequence. Purely additive: defaults to NULL, no change for existing drivers.Signed-off-by Radu Sabau <[email protected]>
I would say that the fix patch should come first than this one. Other than that:
Signature · 1 line
Nuno Sá <[email protected]>
PATCH v4 2/8 iio: imu: adis: Fix custom reset dispatch in adislib
In reply to Radu Sabau__adis_initial_startup()'s no-reset-gpio path called __adis_reset() directly instead of adis->ops->reset(), silently ignoring any driver's custom reset implementation. Invisible until now since adis_default_ops.reset is __adis_reset() itself. Dispatch through adis->ops->reset() instead - the same bug existed in the public adis_reset() wrapper, fixed here too.
Move the settle-time sleep out of __adis_reset() and into both call sites instead, so every reset op (default or custom) is treated
uniformly: adis->ops->reset() is expected to just do the write, and the library always sleeps the settle time afterwards. This removes the previous asymmetric "sleep here only for custom ops" special case entirely.
--- drivers/iio/imu/adis.c | 6 ++---- include/linux/iio/imu/adis.h | 12 +++++++++++- 2 files changed, 13 insertions(+), 5 deletions(-)
drivers/iio/imu/adis.c +2 -4
@@ -340,7 +340,6 @@ EXPORT_SYMBOL_NS_GPL(__adis_check_status, "IIO_ADISLIB");int __adis_reset (struct adis *adis) {int ret; -const struct adis_timeout *timeouts = adis->data->timeouts; ret =__adis_write_reg_8 (adis, adis->data->glob_cmd_reg,ADIS_GLOB_CMD_SW_RESET );
@@ -349,8 +348,6 @@ int __adis_reset(struct adis *adis)return ret; } -msleep (timeouts->sw_reset_ms); -return 0 ; }EXPORT_SYMBOL_NS_GPL (__adis_reset,"IIO_ADIS_LIB" );
@@ -416,9 +413,10 @@ int __adis_initial_startup(struct adis *adis)gpiod_set_value_cansleep (gpio,0 );msleep (timeouts->reset_ms); }else { - ret =__adis_reset (adis); + ret = adis->ops->reset (adis);if (ret)return ret; +msleep (timeouts->sw_reset_ms); } ret =adis_self_test (adis);
include/linux/iio/imu/adis.h +11 -1
@@ -10,6 +10,7 @@#define __IIO_ADIS_H__#include <linux/cleanup.h> +#include <linux/delay.h> #include <linux/spi/spi.h> #include <linux/interrupt.h> #include <linux/iio/iio.h>
@@ -178,8 +179,17 @@ int __adis_reset(struct adis *adis);*/ static inline int adis_reset (struct adis *adis) { +int ret; +guard (mutex)(&adis->state_lock); -return __adis_reset (adis); + + ret = adis->ops->reset (adis); +if (ret) +return ret; + +msleep (adis->data->timeouts->sw_reset_ms); + +return 0 ; } int __adis_write_reg(struct adis *adis, unsigned int reg,
Signature · 1 line
2.43.0
Re: [PATCH v4 2/8] iio: imu: adis: Fix custom reset dispatch in adislib
Quoted 8 lines · Radu Sabau
__adis_initial_startup()'s no-reset-gpio path called
__adis_reset()directly instead ofadis->ops->reset(), silently ignoring any driver's custom reset implementation. Invisible until now since adis_default_ops.reset is__adis_reset()itself. Dispatch throughadis->ops->reset()instead - the same bug existed in the publicadis_reset()wrapper, fixed here too.[...]
Signature · 1 line
Nuno Sá <[email protected]>
PATCH v4 3/8 iio: imu: adis: Add optional post_reset_setup callback
In reply to Radu SabauAdd an optional post_reset_setup callback to struct adis_data, called right after reset and before self-test. Not all ADIS devices need extra bring-up between reset and self-test (SPI mode locking, status or bootloader checks, pin or burst-mode configuration, etc.) - purely
additive: defaults to NULL, no change for existing drivers.
--- drivers/iio/imu/adis.c | 6 ++++++ include/linux/iio/imu/adis.h | 7 +++++++ 2 files changed, 13 insertions(+)
drivers/iio/imu/adis.c +6 -0
@@ -419,6 +419,12 @@ int __adis_initial_startup(struct adis *adis)msleep (timeouts->sw_reset_ms); } +if (adis->data->post_reset_setup) { + ret = adis->data->post_reset_setup (adis); +if (ret) +return ret; + } + ret =adis_self_test (adis);if (ret)return ret;
include/linux/iio/imu/adis.h +7 -0
@@ -52,6 +52,12 @@ struct adis_timeout {* @self_test_mask: Bitmask of supported self-test operations * @self_test_reg: Register address to request self test command * @self_test_no_autoclear: True if device's self-test needs clear of ctrl reg +* @post_reset_setup: Optional device-specific hook called after reset, +* before self-test. Not all ADIS devices need extra bring-up +* between reset and self-test (SPI mode locking, status or +* bootloader checks, pin or burst-mode configuration, etc.) - +* only called when set. Must return 0 on success, a negative +* error code otherwise. * @self_test: Optional device-specific self-test override. When set, * it is called instead of the generic mask-write/sleep/ * check-status sequence. The callback owns its own pass/fail
@@ -88,6 +94,7 @@ struct adis_data {unsigned int self_test_mask;unsigned int self_test_reg;bool self_test_no_autoclear; +int (*post_reset_setup)(struct adis *adis);int (*self_test)(struct adis *adis);const struct adis_timeout *timeouts;
Signature · 1 line
2.43.0
Jonathan Cameron
maintainerRe: [PATCH v4 3/8] iio: imu: adis: Add optional post_reset_setup callback
Quoted 9 lines · On Fri, 23 Oct 2026 12:30:20 +0300 Radu Sabau via B4 Relay…
From: Radu Sabau <[email protected]>
Add an optional
post_reset_setupcallback to structadis_data, called right after reset and before self-test. Not all ADIS devices need extra bring-up between reset and self-test (SPI mode locking, status or bootloader checks, pin or burst-mode configuration, etc.) - purely
additive: defaults to NULL, no change for existing drivers.Signed-off-by Radu Sabau <[email protected]>
Hi Radu,
As it seems you will be doing a v5 for other feedback, time to argue about the bikeshed colour.
Quoted 5 lines
include/linux/iio/imu/adis.h +0
-0
include/linux/iio/imu/adis.h struct adis_timeout { · line 60
Quoted 9 lines
include/linux/iio/imu/adis.h +6
-0@@ -52,6 +52,12 @@ struct adis_timeout {* @self_test_mask: Bitmask of supported self-test operations * @self_test_reg: Register address to request self test command * @self_test_no_autoclear: True if device's self-test needs clear of ctrl reg +* @post_reset_setup: Optional device-specific hook called after reset, +* before self-test. Not all ADIS devices need extra bring-up +* between reset and self-test (SPI mode locking, status or +* bootloader checks, pin or burst-mode configuration, etc.) - +* only called when set. Must return 0 on success, a negative +* error code otherwise.
Trivial but I wonder if this naming focuses unnecessarily on bit being after reset. Maybe simply calling it init() would be enough with assumption that any intialization is always after reset if there is one done?
Quoted 12 lines
include/linux/iio/imu/adis.h +1
-0* @self_test: Optional device-specific self-test override. When set, * it is called instead of the generic mask-write/sleep/ * check-status sequence. The callback owns its own pass/fail @@ -88,6 +94,7 @@ struct adis_data {unsigned int self_test_mask;unsigned int self_test_reg;bool self_test_no_autoclear; +int (*post_reset_setup)(struct adis *adis);int (*self_test)(struct adis *adis);const struct adis_timeout *timeouts;
RE: [PATCH v4 3/8] iio: imu: adis: Add optional post_reset_setup callback
Quoted 3 lines
-----Original Message-----
From: Jonathan Cameron <[email protected]>
Sent: Monday, October 26, 2026 1:52 AM
...
Quoted 9 lines
Quoted 8 lines
* @self_test_reg: Register address to request self test command
* @self_test_no_autoclear: True if device's self-test needs clear of ctrl reg
+ * @post_reset_setup: Optional device-specific hook called after reset,
+ * before self-test. Not all ADIS devices need extra bring-up
+ * between reset and self-test (SPI mode locking, status or
+ * bootloader checks, pin or burst-mode configuration, etc.) -
+ * only called when set. Must return 0 on success, a negative
+ * error code otherwise.
Quoted 5 lines
Trivial but I wonder if this naming focuses unnecessarily on bit being after reset. Maybe simply calling it
init()would be enough with assumption that any intialization is always after reset if there is one done?
Totally agree - renaming it to init() for v5.
Quoted 12 lines
Quoted 12 lines
* @self_test: Optional device-specific self-test override. When set,
* it is called instead of the generic mask-write/sleep/
* check-status sequence. The callback owns its own pass/failinclude/linux/iio/imu/adis.h +1
-0@@ -88,6 +94,7 @@ struct adis_data {unsigned int self_test_mask;unsigned int self_test_reg;bool self_test_no_autoclear; +int (*post_reset_setup)(struct adis *adis);int (*self_test)(struct adis *adis);const struct adis_timeout *timeouts;
PATCH v4 4/8 dt-bindings: iio: imu: Add bindings for ADI ADIS16607
In reply to Radu SabauAdd device tree bindings for the Analog Devices ADIS16607 Precision MEMS Inertial Measurement Unit. The ADIS16607 integrates a triaxial gyroscope, triaxial accelerometer, and temperature sensor, and communicates over SPI Half-Duplex.
Two variants are supported, adis16607-2 and adis16607-3, differing only in gyroscope full-scale range (±450°/s and ±2000°/s respectively).
The binding exposes optional properties for:
- An external clock for sync mode (falling back to the internal 8 kHz clock when absent)
- A hardware reset GPIO (active low)
--- .../devicetree/bindings/iio/imu/adi,adis16607.yaml | 94 ++++++++++++++++++++++ MAINTAINERS | 7 ++ 2 files changed, 101 insertions(+)
Documentation/devicetree/bindings/iio/imu/adi,adis16607.yaml new file +94 -0
@@ -0,0 +1,94 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/imu/adi,adis16607.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Analog Devices ADIS16607 IMU + +maintainers: + - Radu Sabau <[email protected]> + +description: | + Analog Devices ADIS16607 Precision MEMS Inertial Measurement Unit (IMU) + with a triaxial gyroscope, triaxial accelerometer, and temperature sensor. + Uses SPI Half-Duplex communication protocol. + + The device has five GPIO pins (GPIO0-GPIO4 in the datasheet), each + independently selectable for a single fixed function. This binding + exposes GPIO0's reset function as reset-gpios; GPIO2's sync function + is modeled via the clocks property, and GPIO4's DEV_NOK interrupt via + the interrupts property. GPIO3 (data-ready) is required internally + regardless of board wiring and isn't exposed. GPIO1 (wake) gates + whether the bootloader auto-loads its NVM contents after reset; it + defaults to enabled with a weak pull-up, which already gives normal + operation with no configuration needed, so it isn't exposed either. + +properties: + compatible: + enum: + - adi,adis16607-2 + - adi,adis16607-3 + + reg: + maxItems: 1 + + spi-cpha: true + + spi-cpol: true + + spi-max-frequency: + maximum: 10000000 + + vdd-supply: true + + interrupts: + maxItems: 1 + + clocks: + description: + Optional external clock for sync mode. If not provided, the internal + 8 kHz clock is used. + maxItems: 1 + + reset-gpios: + description: + Optional GPIO for hardware reset, active low. Routes to the + device's GPIO0 pin, which can be independently set to the reset + function or left idle via an on-chip register. + maxItems: 1 + +required: + - compatible + - reg + - interrupts + - spi-cpha + - spi-cpol + - vdd-supply + +allOf: + - $ref: /schemas/spi/spi-peripheral-props.yaml# + +unevaluatedProperties: false + +examples: + - | + #include <dt-bindings/interrupt-controller/irq.h> + #include <dt-bindings/gpio/gpio.h> + spi { + #address-cells = <1>; + #size-cells = <0>; + + imu@0 { + compatible = "adi,adis16607-2"; + reg = <0>; + spi-cpha; + spi-cpol; + spi-max-frequency = <10000000>; + vdd-supply = <&vdd>; + interrupts = <4 IRQ_TYPE_LEVEL_HIGH>; + interrupt-parent = <&gpio>; + clocks = <&sync_clk>; + reset-gpios = <&gpio 10 GPIO_ACTIVE_LOW>; + }; + };
MAINTAINERS +7 -0
@@ -1792,6 +1792,13 @@ S: Supported W: https://ez.analog.com/linux-software-drivers F: Documentation/devicetree/bindings/iio/imu/adi,adis16550.yaml +ANALOG DEVICES INC ADIS16607 DRIVER +M: Radu Sabau <[email protected]> +L: [email protected] +S: Supported +W: https://ez.analog.com/linux-software-drivers +F: Documentation/devicetree/bindings/iio/imu/adi,adis16607.yaml + ANALOG DEVICES INC ADL8113 DRIVER M: Antoniu Miclaus <[email protected]> L: [email protected]
Signature · 1 line
2.43.0
Jonathan Cameron
maintainerRe: [PATCH v4 4/8] dt-bindings: iio: imu: Add bindings for ADI ADIS16607
Quoted 11 lines · On Fri, 23 Oct 2026 12:30:21 +0300 Radu Sabau via B4 Relay…
From: Radu Sabau <[email protected]>
Add device tree bindings for the Analog Devices ADIS16607 Precision MEMS Inertial Measurement Unit. The ADIS16607 integrates a triaxial gyroscope, triaxial accelerometer, and temperature sensor, and communicates over SPI Half-Duplex.
Two variants are supported, adis16607-2 and adis16607-3, differing only in gyroscope full-scale range (±450°/s and ±2000°/s respectively).
Quoted 6 lines
The binding exposes optional properties for:
- An external clock for sync mode (falling back to the internal 8 kHz clock when absent)
- A hardware reset GPIO (active low)Reviewed-by Rob Herring (Arm) <[email protected]>
There is enough new stuff in here I'd have dropped Rob's tag.
Quoted 2 lines
Signed-off-by Radu Sabau <[email protected]>---
and noted you had done so here with a breadcrumb of why, which is the gpio handling
Quoted 123 lines
.../devicetree/bindings/iio/imu/adi,adis16607.yaml | 94 ++++++++++++++++++++++ MAINTAINERS | 7 ++ 2 files changed, 101 insertions(+)Documentation/devicetree/bindings/iio/imu/adi,adis16607.yaml new file +94
-0@@ -0,0 +1,94 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/imu/adi,adis16607.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Analog Devices ADIS16607 IMU + +maintainers: + - Radu Sabau <[email protected]> + +description: | + Analog Devices ADIS16607 Precision MEMS Inertial Measurement Unit (IMU) + with a triaxial gyroscope, triaxial accelerometer, and temperature sensor. + Uses SPI Half-Duplex communication protocol. + + The device has five GPIO pins (GPIO0-GPIO4 in the datasheet), each + independently selectable for a single fixed function. This binding + exposes GPIO0's reset function as reset-gpios; GPIO2's sync function + is modeled via the clocks property, and GPIO4's DEV_NOK interrupt via + the interrupts property. GPIO3 (data-ready) is required internally + regardless of board wiring and isn't exposed. GPIO1 (wake) gates + whether the bootloader auto-loads its NVM contents after reset; it + defaults to enabled with a weak pull-up, which already gives normal + operation with no configuration needed, so it isn't exposed either. + +properties: + compatible: + enum: + - adi,adis16607-2 + - adi,adis16607-3 + + reg: + maxItems: 1 + + spi-cpha: true + + spi-cpol: true + + spi-max-frequency: + maximum: 10000000 + + vdd-supply: true + + interrupts: + maxItems: 1 + + clocks: + description: + Optional external clock for sync mode. If not provided, the internal + 8 kHz clock is used. + maxItems: 1 + + reset-gpios: + description: + Optional GPIO for hardware reset, active low. Routes to the + device's GPIO0 pin, which can be independently set to the reset + function or left idle via an on-chip register. + maxItems: 1 + +required: + - compatible + - reg + - interrupts + - spi-cpha + - spi-cpol + - vdd-supply + +allOf: + - $ref: /schemas/spi/spi-peripheral-props.yaml# + +unevaluatedProperties: false + +examples: + - | + #include <dt-bindings/interrupt-controller/irq.h> + #include <dt-bindings/gpio/gpio.h> + spi { + #address-cells = <1>; + #size-cells = <0>; + + imu@0 { + compatible = "adi,adis16607-2"; + reg = <0>; + spi-cpha; + spi-cpol; + spi-max-frequency = <10000000>; + vdd-supply = <&vdd>; + interrupts = <4 IRQ_TYPE_LEVEL_HIGH>; + interrupt-parent = <&gpio>; + clocks = <&sync_clk>; + reset-gpios = <&gpio 10 GPIO_ACTIVE_LOW>; + }; + };MAINTAINERS +7
-0@@ -1792,6 +1792,13 @@ S: Supported W: https://ez.analog.com/linux-software-drivers F: Documentation/devicetree/bindings/iio/imu/adi,adis16550.yaml +ANALOG DEVICES INC ADIS16607 DRIVER +M: Radu Sabau <[email protected]> +L: [email protected] +S: Supported +W: https://ez.analog.com/linux-software-drivers +F: Documentation/devicetree/bindings/iio/imu/adi,adis16607.yaml + ANALOG DEVICES INC ADL8113 DRIVER M: Antoniu Miclaus <[email protected]> L: [email protected]
PATCH v4 5/8 iio: imu: Add driver for the ADI ADIS16607
In reply to Radu SabauThe ADIS16607 is a Precision MEMS IMU from Analog Devices with triaxial gyroscope and accelerometer, delta angle/velocity, and temperature channels, communicating over a custom SPI Half-Duplex protocol. ADIS16607-2 has a ±450°/s gyroscope range, ADIS16607-3 ±2000°/s; both share a ±40g accelerometer range and an 8 kHz internal clock.
This is the base driver: probe, raw channel reads, sampling-frequency control, startup/self-test via adislib, and debugfs identity entries. No buffered capture, external clock sync, or calibration bias yet - those follow in later patches.
Self-test leaves the device's SELF_TEST register cleared on every exit path, not just on success, so a read failure or a failed delta check doesn't leave the sensor stuck in its self-test/force state until the next reset.
--- MAINTAINERS | 1 + drivers/iio/imu/Kconfig | 13 + drivers/iio/imu/Makefile | 1 + drivers/iio/imu/adis16607.c | 842 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 857 insertions(+)
MAINTAINERS +1 -0
@@ -1798,6 +1798,7 @@ L: [email protected] S: Supported W: https://ez.analog.com/linux-software-drivers F: Documentation/devicetree/bindings/iio/imu/adi,adis16607.yaml +F: drivers/iio/imu/adis16607.c ANALOG DEVICES INC ADL8113 DRIVER M: Antoniu Miclaus <[email protected]>
drivers/iio/imu/Kconfig +13 -0
@@ -65,6 +65,19 @@ config ADIS16550 To compile this driver as a module, choose M here: the module will be called adis16550. +config ADIS16607 + tristate "Analog Devices ADIS16607 and similar IMU driver" + depends on SPI + select IIO_ADIS_LIB + select IIO_ADIS_LIB_BUFFER if IIO_BUFFER + help + Say yes here to build support for Analog Devices ADIS16607-2 + and ADIS16607-3 inertial sensors containing triaxis + gyroscope and triaxis accelerometer. + + To compile this driver as a module, choose M here: the module will be + called adis16607. + source "drivers/iio/imu/bmi160/Kconfig" source "drivers/iio/imu/bmi270/Kconfig" source "drivers/iio/imu/bmi323/Kconfig"
drivers/iio/imu/Makefile +1 -0
@@ -9,6 +9,7 @@ obj-$(CONFIG_ADIS16460) += adis16460.o obj-$(CONFIG_ADIS16475) += adis16475.o obj-$(CONFIG_ADIS16480) += adis16480.o obj-$(CONFIG_ADIS16550) += adis16550.o +obj-$(CONFIG_ADIS16607) += adis16607.o adis_lib-y += adis.o adis_lib-$(CONFIG_IIO_ADIS_LIB_BUFFER) += adis_trigger.o
drivers/iio/imu/adis16607.c new file +842 -0
842 lines not on this page · raw message
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v4 5/8] iio: imu: Add driver for the ADI ADIS16607
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] iio: imu: adis16607: negative frequency wraparound in adis16607_write_raw() --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] iio: imu: adis16607: negative frequency wraparound in adis16607_write_raw() --
commit 686b8ffae8bb8850532fb9fd2ba72d9f11184ab1
Author: Radu Sabau <[email protected]>
iio: imu: Add driver for the ADI ADIS16607
This commit adds the base IIO driver for the Analog Devices ADIS16607-2 and ADIS16607-3 precision MEMS IMUs over a custom SPI Half-Duplex protocol. It provides support for raw channel reads, sampling frequency control, startup/self-test via adislib, and debugfs identity entries.
Quoted 5 lines
drivers/iio/imu/adis16607.c new file +0
-0
[ ... ]
Quoted 25 lines
drivers/iio/imu/adis16607.c new file +25
-0+static int adis16607_set_freq (struct adis16607 *st,u32 freq) +{ +u32 dec; +int ret; + +if (!freq) +return -EINVAL ; + +adis_dev_auto_lock (&st->adis); + + dec =DIV_ROUND_CLOSEST (st->clk_freq_mhz, freq); +if (dec) + dec--; + + dec =min_t (u32, dec, st->info->max_dec); + + ret =__adis_write_reg_16 (&st->adis,ADIS16607_REG_DEC_RATE , dec); +if (ret) +return ret; + + st->sample_period_ns =DIV_ROUND_CLOSEST_ULL ((u64 )NSEC_PER_SEC *1000ULL * (dec +1 ), + st->clk_freq_mhz); + +return 0 ; +}
[ ... ]
drivers/iio/imu/adis16607.c line 574
Quoted 11 lines
drivers/iio/imu/adis16607.c new file +11
-0+static int adis16607_write_raw (struct iio_dev *indio_dev, +const struct iio_chan_spec *chan, +int val,int val2,long info) +{ +struct adis16607 *st =iio_priv (indio_dev); +u32 tmp; + +switch (info) { +case IIO_CHAN_INFO_SAMP_FREQ : + tmp = val *1000 + val2 /1000 ; +return adis16607_set_freq (st, tmp);
[Severity: Medium]
What happens in adis16607_write_raw() if userspace writes a negative sampling frequency via sysfs?
In drivers/iio/industrialio-core.c, iio_write_channel_info() parses the input string through __iio_str_to_fixpoint(), which accepts a leading '-' sign and passes signed negative val or val2 values into write_raw().
Without checking if (val < 0 || val2 < 0) return -EINVAL; (like adis16480_set_freq() does in drivers/iio/imu/adis16480.c), computing val * 1000 + val2 / 1000 and assigning a negative result to u32 tmp wraps around to a large unsigned value.
When that wrapped value is passed to adis16607_set_freq(), it bypasses the if (!freq) check, DIV_ROUND_CLOSEST(st->clk_freq_mhz, freq) evaluates to 0, and __adis_write_reg_16() programs ADIS16607_REG_DEC_RATE to 0 (the maximum 8 kHz rate) instead of rejecting the invalid input. Also, if val > INT_MAX / 1000, val * 1000 overflows signed 32-bit arithmetic.
Should adis16607_write_raw() validate that val and val2 are non-negative and within bounds before computing tmp?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
Re: [PATCH v4 5/8] iio: imu: Add driver for the ADI ADIS16607
In reply to Radu SabauQuoted 16 lines · On Fri, Oct 23, 2026 at 12:30:22PM +0300, Radu Sabau via B4 Relay wrote:
The ADIS16607 is a Precision MEMS IMU from Analog Devices with triaxial gyroscope and accelerometer, delta angle/velocity, and temperature channels, communicating over a custom SPI Half-Duplex protocol. ADIS16607-2 has a ±450°/s gyroscope range, ADIS16607-3 ±2000°/s; both share a ±40g accelerometer range and an 8 kHz internal clock.
This is the base driver: probe, raw channel reads, sampling-frequency control, startup/self-test via adislib, and debugfs identity entries. No buffered capture, external clock sync, or calibration bias yet - those follow in later patches.
Self-test leaves the device's
SELF_TESTregister cleared on every exit path, not just on success, so a read failure or a failed delta check doesn't leave the sensor stuck in its self-test/force state until the next reset.
...
drivers/iio/imu/Kconfig config ADIS16550 · line 69
Quoted 3 lines
+++ b/drivers/iio/imu/Kconfig
drivers/iio/imu/Kconfig +1
-0+ tristate "Analog Devices ADIS16607 and similar IMU driver"
(see below)
...
drivers/iio/imu/adis16607.c line 80
Quoted 12 lines
drivers/iio/imu/adis16607.c new file +12
-0+struct adis16607_chip_info { +const struct iio_chan_spec *channels; +const char *name; +u32 num_channels; +u32 gyro_max_val; +u32 gyro_max_scale; +u32 accel_max_val; +u32 accel_max_scale; +u32 temp_scale; +u32 deltang_max_val; +u32 deltvel_max_val; +u32 int_clk_hz;
_Hz
Quoted 2 lines
(quoted diff) +2
-0+ u16 max_dec; +};
...
drivers/iio/imu/adis16607.c line 87
Quoted 4 lines
drivers/iio/imu/adis16607.c new file +4
-0+struct adis16607 { +struct adis adis; +const struct adis16607_chip_info *info; +unsigned long clk_freq_mhz;
_MHz or _mHz? (I believe it's the first one.)
This is why case-sensitive units (as per physics) are important.
Quoted 2 lines
(quoted diff) +2
-0+ u64 sample_period_ns; +};
...
drivers/iio/imu/adis16607.c line 180
Quoted 1 line
drivers/iio/imu/adis16607.c new file +1
-0+/* Combine: 24-bit value with MSW in upper 16 bits, LSW in lower 8 bits */
Make it multi-line and to fix 80 characters.
drivers/iio/imu/adis16607.c line 181
Quoted 1 line
drivers/iio/imu/adis16607.c new file +1
-0+ *val = ((val_msw <<8 ) &0xFFFF00 ) | val_lsw;
Why not GENMASK()? Can val_msw be u16 or other 16-bit type?
...
drivers/iio/imu/adis16607.c line 243
Quoted 13 lines
drivers/iio/imu/adis16607.c new file +13
-0+static int adis16607_sensor_self_test (struct adis16607 *st) +{ +struct adis *adis = &st->adis; +u16 st1_val[6 ], st2_val[6 ]; +s16 delta_max[6 ] = { +ADIS16607_ACCEL_XY_DELTA_MAX , +ADIS16607_ACCEL_XY_DELTA_MAX , +ADIS16607_ACCEL_Z_DELTA_MAX , +ADIS16607_GYRO_DELTA_MAX , +ADIS16607_GYRO_DELTA_MAX , +ADIS16607_GYRO_DELTA_MAX , + }; +int ret, i;
Why is 'i' signed?
Quoted 18 lines
drivers/iio/imu/adis16607.c new file +18
-0+/* Enable sensor self-test */ + ret =__adis_write_reg_16 (adis,ADIS16607_REG_SELF_TEST , +ADIS16607_SNSR_SELF_TEST_MASK ); +if (ret) +return ret; + +/* Wait for self-test to settle before reading results */ +msleep (adis->data->timeouts->self_test_ms); + +/* Read first set of self-test data */ +for (i =0 ; i <ARRAY_SIZE (st1_val); i++) { + ret =__adis_read_reg_16 (adis,ADIS16607_REG_SELF_TEST_DATA (i), + &st1_val[i]); +if (ret) + goto clear_self_test; + } + +/* Force self-test */
drivers/iio/imu/adis16607.c line 272
Quoted 10 lines
drivers/iio/imu/adis16607.c new file +10
-0+ ret =__adis_write_reg_16 (adis,ADIS16607_REG_SELF_TEST , +ADIS16607_SNSR_SELF_TEST_MASK |ADIS16607_ST_FORCE_MASK ); +if (ret) + goto clear_self_test; + +/* Wait for forced self-test to settle before reading results */ +msleep (adis->data->timeouts->self_test_ms); + +/* Read second set of self-test data */ +for (i =0 ; i <ARRAY_SIZE (st2_val); i++) {
In both for-loops iterator is local, so
for (unsigned int i = 0; i < ARRAY_SIZE(st2_val); i++) {Quoted 29 lines
drivers/iio/imu/adis16607.c new file +29
-0+ ret =__adis_read_reg_16 (adis,ADIS16607_REG_SELF_TEST_DATA (i), + &st2_val[i]); +if (ret) + goto clear_self_test; + +if (!adis16607_delta_check ((s16 )st1_val[i], (s16 )st2_val[i], + delta_max[i])) { +dev_err (&adis->spi->dev, +"Self-test failed for axis %d: delta out of range\n" , i); + ret = -EINVAL ; + goto clear_self_test; + } + } + +/* Clear self-test register */ +return __adis_write_reg_16 (adis,ADIS16607_REG_SELF_TEST ,0 ); + +clear_self_test: +/* +* Best-effort cleanup after a failure above - leave the device out +* of its self-test/force state rather than stuck in it until the +* next reset. Warn rather than returning this write's own result, +* so a cleanup failure doesn't mask the real error that got us here. +*/ +if (__adis_write_reg_16 (adis,ADIS16607_REG_SELF_TEST ,0 )) +dev_warn (&adis->spi->dev,"failed to clear self-test register\n" ); + +return ret; +}
...
drivers/iio/imu/adis16607.c line 373
Quoted 8 lines
drivers/iio/imu/adis16607.c new file +8
-0+static int adis16607_self_test (struct adis *adis) +{ + struct adis16607 *st = container_of(adis, struct adis16607, adis); +struct device *dev = &adis->spi->dev; +u16 diag_stat; +int ret; + +/* Inertial Settling Time (Table 1), needed before self-test reads sensor data */
Make it fit 80.
Quoted 17 lines
drivers/iio/imu/adis16607.c new file +17
-0+msleep (40 ); + + ret =adis16607_sensor_self_test (st); +if (ret) +return ret; + +/* Read diag_stat again to clear any faults latched during self-test */ + ret =__adis_read_reg_16 (adis,ADIS16607_REG_DIAG_STAT , &diag_stat); +if (ret) +return ret; + + ret =__adis_check_status (adis); +if (ret) +dev_err (dev,"status check after self-test failed: %d\n" , ret); + +return ret; +}
...
drivers/iio/imu/adis16607.c line 395
Quoted 4 lines
drivers/iio/imu/adis16607.c new file +4
-0+static int adis16607_firmware_revision_show (struct seq_file *s,void *arg) +{ +struct adis16607 *st = s->private; +u16 rev;
Can this be
struct revision {
u8 minor;
u8 major;
} rev;?
Quoted 9 lines
drivers/iio/imu/adis16607.c new file +9
-0+int ret; + + ret =adis_read_reg_16 (&st->adis,ADIS16607_REG_REV_ID , &rev); +if (ret) +return ret; + +seq_printf (s,"%u.%u\n" , (rev >>8 ) &0xff , rev &0xff ); +return 0 ; +}
...
drivers/iio/imu/adis16607.c line 418
Quoted 12 lines
drivers/iio/imu/adis16607.c new file +12
-0+static int adis16607_show_serial_number (void *arg,u64 *val) +{ +struct adis16607 *st = arg; +u64 serial; +u16 tmp; +int ret; + + ret =adis_read_reg_16 (&st->adis,ADIS16607_REG_SERIAL_NUM0 , &tmp); +if (ret) +return ret; + + serial = (u64 )tmp;
How is explicit casting helpful here?
drivers/iio/imu/adis16607.c line 430
Quoted 11 lines
drivers/iio/imu/adis16607.c new file +11
-0+ ret =adis_read_reg_16 (&st->adis,ADIS16607_REG_SERIAL_NUM1 , &tmp); +if (ret) +return ret; + + serial |= ((u64 )tmp <<16 ); + + ret =adis_read_reg_16 (&st->adis,ADIS16607_REG_SERIAL_NUM2 , &tmp); +if (ret) +return ret; + + serial |= ((u64 )tmp <<32 );
What about reversing the order and shift serial instead?
u64 serial = 0; ret = adis_read_reg_16(&st->adis, ADIS16607_REG_SERIAL_NUM2, &tmp); if (ret) return ret; serial |= tmp; ret = adis_read_reg_16(&st->adis, ADIS16607_REG_SERIAL_NUM1, &tmp); if (ret) return ret; serial <<= 16; serial |= tmp; ret = adis_read_reg_16(&st->adis, ADIS16607_REG_SERIAL_NUM0, &tmp); if (ret) return ret; serial <<= 16; serial |= tmp;
Quoted 3 lines
drivers/iio/imu/adis16607.c new file +3
-0+ *val = serial; +return 0 ; +}
...
Quoted 5 lines
drivers/iio/imu/adis16607.c new file +5
-0+static int adis16607_set_freq (struct adis16607 *st,u32 freq) +{ +u32 dec; +int ret; +
drivers/iio/imu/adis16607.c line 497
Quoted 10 lines
drivers/iio/imu/adis16607.c new file +10
-0+if (!freq) +return -EINVAL ; + +adis_dev_auto_lock (&st->adis); + + dec =DIV_ROUND_CLOSEST (st->clk_freq_mhz, freq); +if (dec) + dec--; + + dec =min_t (u32, dec, st->info->max_dec);
No min_t(). Make the types to be compatible for min().
drivers/iio/imu/adis16607.c line 504
Quoted 6 lines
drivers/iio/imu/adis16607.c new file +6
-0+ ret =__adis_write_reg_16 (&st->adis,ADIS16607_REG_DEC_RATE , dec); +if (ret) +return ret; + + st->sample_period_ns =DIV_ROUND_CLOSEST_ULL ((u64 )NSEC_PER_SEC *1000ULL * (dec +1 ), + st->clk_freq_mhz);
Make it fit. Using temporary variable usually helps. Also you don't need (u64) casting or ULL suffix. On top of that, what is another 1000 multiplier for?
I would expect a comment on top with explaining magic(s).
Quoted 2 lines
(quoted diff) +2
-0+ return 0; +}
...
drivers/iio/imu/adis16607.c line 556
Quoted 6 lines
drivers/iio/imu/adis16607.c new file +6
-0+case IIO_CHAN_INFO_SAMP_FREQ : + ret =adis16607_get_freq (st, &tmp); +if (ret) +return ret; + *val = tmp /1000 ; + *val2 = (tmp %1000 ) *1000 ;
What is 1000? HZ_PER_KHZ? KHZ_PER_MHZ?
Quoted 1 line
drivers/iio/imu/adis16607.c new file +1
-0+return IIO_VAL_INT_PLUS_MICRO ;
...
drivers/iio/imu/adis16607.c line 574
Quoted 11 lines
drivers/iio/imu/adis16607.c new file +11
-0+static int adis16607_write_raw (struct iio_dev *indio_dev, +const struct iio_chan_spec *chan, +int val,int val2,long info) +{ +struct adis16607 *st =iio_priv (indio_dev); +u32 tmp; + +switch (info) { +case IIO_CHAN_INFO_SAMP_FREQ : + tmp = val *1000 + val2 /1000 ; +return adis16607_set_freq (st, tmp);
Ditto.
Quoted 4 lines
drivers/iio/imu/adis16607.c new file +4
-0+default : +return -EINVAL ; + } +}
...
Quoted 6 lines
drivers/iio/imu/adis16607.c new file +6
-0+#define ADIS16607_MOD_CHAN (_type, _mod, _address, _si) { \ + .type = (_type), \ + .modified = 1, \ + .channel2 = (_mod), \ + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
drivers/iio/imu/adis16607.c line 596
Quoted 10 lines
drivers/iio/imu/adis16607.c new file +10
-0+ .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), \ + .address = (_address), \ + .scan_index = (_si), \ + .scan_type = { \ + .sign = 's', \ + .realbits = 24, \ + .storagebits = 32, \ + .endianness = IIO_BE, \ + }, \ +}
This is not a function, I would rather shift it right by a tab with a split (also indent the backslashes, it makes it easier to read).
#define ADIS16607_MOD_CHAN(_type, _mod, _address, _si) \
{ \
.type = (_type), \
...
}...
Quoted 6 lines
drivers/iio/imu/adis16607.c new file +6
-0+#define ADIS16607_MOD_CHAN_DELTA (_type, _mod, _address, _si) { \ + .type = (_type), \ + .modified = 1, \ + .channel2 = (_mod), \ + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
drivers/iio/imu/adis16607.c line 623
Quoted 10 lines
drivers/iio/imu/adis16607.c new file +10
-0+ .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), \ + .address = (_address), \ + .scan_index = (_si), \ + .scan_type = { \ + .sign = 's', \ + .realbits = 24, \ + .storagebits = 32, \ + .endianness = IIO_BE, \ + }, \ +}
Ditto.
...
drivers/iio/imu/adis16607.c line 740
Quoted 7 lines
drivers/iio/imu/adis16607.c new file +7
-0+/* +* No external clock sync support yet: always run on the internal clock. +* Default dec=0 after reset, so period = 1 / clk_freq_mhz. +*/ +static int adis16607_config_clk (struct adis16607 *st) +{ + st->clk_freq_mhz = st->info->int_clk_hz *MILLI ;
So, it's milli-hertz then? We have MILLIHZ_PER_HZ.
drivers/iio/imu/adis16607.c line 744
Quoted 4 lines
drivers/iio/imu/adis16607.c new file +4
-0+ st->sample_period_ns = +DIV_ROUND_CLOSEST_ULL ((u64 )NSEC_PER_SEC *MILLI , st->clk_freq_mhz); +return 0 ; +}
Yeah, this magic 1000 should be explained everywhere.
...
Quoted 1 line
+MODULE_DESCRIPTION("Analog Devices ADIS16607 IMU driver");
Make the text the same as per Kconfig. Whatever wording you choose.
Signature · 2 lines
With Best Regards, Andy Shevchenko
RE: [PATCH v4 5/8] iio: imu: Add driver for the ADI ADIS16607
Quoted 5 lines
-----Original Message-----
From: Andy Shevchenko <[email protected]>
Sent: Friday, October 23, 2026 1:27 PM
...
Quoted 7 lines
drivers/iio/imu/adis16607.c line 395
Quoted 4 lines
drivers/iio/imu/adis16607.c new file +4
-0+static int adis16607_firmware_revision_show (struct seq_file *s,void *arg) +{ +struct adis16607 *st = s->private; +u16 rev;Can this be
Quoted 7 lines
struct revision { u8 minor; u8 major; } rev;?
Hi Andy! Thank you also for looking at this series.
Although I like the idea, I have a question here.
If u16 rev would be replaced by the struct and the read was done directly on the struct pointer, could it mess things up on big-endian targets? A native 16-bit store would place the value's low byte at the lower address on little-endian, but the high byte at the lower address on big-endian - so minor (at the lower offset) would only get the right byte on little-endian, and would actually get major's byte on big-endian, right?
What about we declare this struct and also have a u16 tmp declared, do the read on tmp, and then rev.minor/rev.major get assigned via FIELD_GET() - keeping the readability improvement without that risk?
struct {
u8 minor;
u8 major;
} rev;u16 tmp;
int ret;
ret = adis_read_reg_16(&st->adis, ADIS16607_REG_REV_ID, &tmp); if (ret)
return ret;
rev.major = FIELD_GET(GENMASK(15, 8), tmp);
rev.minor = FIELD_GET(GENMASK(7, 0), tmp);
seq_printf(s, "%u.%u\n", rev.major, rev.minor);
Re: [PATCH v4 5/8] iio: imu: Add driver for the ADI ADIS16607
Quoted 2 lines · Radu bogdan
Quoted 2 lines
From: Andy Shevchenko <[email protected]>
Sent: Friday, October 23, 2026 1:27 PM
...
Quoted 34 lines
Quoted 7 lines
drivers/iio/imu/adis16607.c line 395
Quoted 4 lines
drivers/iio/imu/adis16607.c new file +4
-0+static int adis16607_firmware_revision_show (struct seq_file *s,void *arg) +{ +struct adis16607 *st = s->private; +u16 rev;Can this be
Quoted 6 lines
struct revision { u8 minor; u8 major; } rev;?
Although I like the idea, I have a question here.
If u16 rev would be replaced by the struct and the read was done directly on the struct pointer, could it mess things up on big-endian targets? A native 16-bit store would place the value's low byte at the lower address on little-endian, but the high byte at the lower address on big-endian - so minor (at the lower offset) would only get the right byte on little-endian, and would actually get major's byte on big-endian, right?What about we declare this struct and also have a u16 tmp declared, do the read on tmp, and then rev.minor/rev.major get assigned via
FIELD_GET()- keeping the readability improvement without that risk?struct { u8 minor; u8 major; } rev;u16 tmp;
int ret;
Quoted 8 lines
ret =
adis_read_reg_16(&st->adis, ADIS16607_REG_REV_ID, &tmp); if (ret)return ret;rev.major =
FIELD_GET(GENMASK(15, 8), tmp);
rev.minor =FIELD_GET(GENMASK(7, 0), tmp);
seq_printf(s, "%u.%u\n", rev.major, rev.minor);
Yes, this will work for me.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Nuno Sá
maintainerRe: [PATCH v4 5/8] iio: imu: Add driver for the ADI ADIS16607
In reply to Radu Sabaudrivers/iio/imu/adis16607.c line 108
Quoted 13 lines · Radu Sabau
drivers/iio/imu/adis16607.c new file +0
-0@@ -0,0 +1,842 @@[ ... skip 102 lines ... ]
drivers/iio/imu/adis16607.c new file +6
-0+ADIS16607_SCAN_DELTANG_Z , + ADIS16607_SCAN_TEMP, +}; + +/* +* SPI Half-Duplex read operation for ADIS16607.
I assume you use half duplex because burst mode is not available in full duplex?
Quoted 7 lines
+ * Protocol:
+ * - First transfer: Send [reg | 0x80, 0, 0, 0] - device latches command + * - Second transfer: Send same command, device responds in bytes 2-3 + * - CS toggles between transfers (cs_change = 1 on first xfer)+ * For 4-byte reads (24-bit sensor data):
+ * - Read MSW from reg, read LSW from reg+1
+ * - Combine as: ((val_msw<< 8) &0xFFFF00) |val_lsw
Just repeat the above down in the code. I would only mention it close to the code,
drivers/iio/imu/adis16607.c line 125
Quoted 10 lines
+ */
drivers/iio/imu/adis16607.c new file +9
-0+static int adis16607_spi_read (struct adis *adis,unsigned int reg, +unsigned int *val,unsigned int size) +{ +struct spi_message msg; +struct spi_transfer xfers[2 ] = { + { + .tx_buf = adis->tx, + .len =4 , + .bits_per_word =8 ,
Isn't it the default already?
drivers/iio/imu/adis16607.c line 144
Quoted 7 lines
[ ... skip 13 lines ... ]
drivers/iio/imu/adis16607.c new file +6
-0+case 2 : + adis->tx[0 ] = reg |BIT (7 ); + adis->tx[1 ] =0 ; + adis->tx[2 ] =0 ; + adis->tx[3 ] =0 ; +
You should not need to set those values to 0.
drivers/iio/imu/adis16607.c line 329
Quoted 7 lines
[ ... skip 179 lines ... ]
drivers/iio/imu/adis16607.c new file +6
-0+ } + +/* Verify the correct device is attached */ + ret =__adis_read_reg_16 (adis,ADIS16607_REG_DEV_ID , &dev_id); +if (ret) +return ret;
This is not consistent. Above you print an error. Here you don't. FWIW, I would not print it above.
Quoted 5 lines
drivers/iio/imu/adis16607.c new file +5
-0+ +if (dev_id != adis->data->prod_id) { +dev_err (dev,"device ID mismatch: expected 0x%04x, got 0x%04x\n" , + adis->data->prod_id, dev_id); +return -ENODEV ;
drivers/iio/imu/adis16607.c line 344
Quoted 10 lines
drivers/iio/imu/adis16607.c new file +10
-0+ } + +/* Read diag_stat to clear any latched faults */ + ret =__adis_read_reg_16 (adis,ADIS16607_REG_DIAG_STAT , &diag_stat); +if (ret) +return ret; + + ret =__adis_check_status (adis); +if (ret) { +dev_err (dev,"status check failed: %d\n" , ret);
ditto
drivers/iio/imu/adis16607.c line 387
Quoted 7 lines
[ ... skip 37 lines ... ]
drivers/iio/imu/adis16607.c new file +6
-0+if (ret) +return ret; + + ret =__adis_check_status (adis); +if (ret) +dev_err (dev,"status check after self-test failed: %d\n" , ret);
The above already logs the specific failures! I would not add more log on top of it. So, return __adis_check_status()
drivers/iio/imu/adis16607.c line 472
Quoted 7 lines
[ ... skip 79 lines ... ]
drivers/iio/imu/adis16607.c new file +6
-0+static int adis16607_get_freq (struct adis16607 *st,u32 *freq) +{ +u16 dec =0 ; +int ret; + +adis_dev_auto_lock (&st->adis);
I don't see a reason for the explicit locking. At least in this patch, adis_read_reg_16(() should be enough...
drivers/iio/imu/adis16607.c line 491
Quoted 7 lines
[ ... skip 13 lines ... ]
drivers/iio/imu/adis16607.c new file +6
-0+int ret; + +if (!freq) +return -EINVAL ; + +adis_dev_auto_lock (&st->adis);
You can reduce the scope of the lock
Signature · 1 line
Nuno Sá <[email protected]>
RE: [PATCH v4 5/8] iio: imu: Add driver for the ADI ADIS16607
Quoted 3 lines
-----Original Message-----
From: Sa, Nuno <[email protected]>
Sent: Friday, October 30, 2026 4:07 PM
...
Quoted 5 lines
Quoted 2 lines
+/*
+ * SPI Half-Duplex read operation for ADIS16607.I assume you use half duplex because burst mode is not available in full duplex?
Yes - half-duplex is what gives access to the burst read function, which reads a whole set of samples in a single CS-held transfer. Full duplex doesn't.
PATCH v4 6/8 iio: imu: adis16607: Add FIFO-based buffered/triggered capture
In reply to Radu SabauAdd 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), handled directly rather than through adislib's generic burst-read helpers, which assume one fixed-shape read per trigger rather than a variable-count drain loop.
The watermark-met condition is signaled via DEV_NOK on the device's one interrupt pin, which stays asserted (level-triggered) until DIAG_STAT is read and cleared - matching adislib's has_fifo contract. DEV_NOK fires on any DIAG_STAT flag, not just FIFO_THRESH_MET, so the trigger handler checks that specific bit before popping anything. 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.
--- drivers/iio/imu/adis16607.c | 349 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 346 insertions(+), 3 deletions(-)
drivers/iio/imu/adis16607.c +346 -3
@@ -12,6 +12,9 @@#include <linux/iio/buffer.h> #include <linux/iio/iio.h> #include <linux/iio/imu/adis.h> +#include <linux/iio/sysfs.h> +#include <linux/iio/trigger_consumer.h> +#include <linux/interrupt.h> #include <linux/math.h> #include <linux/minmax.h> #include <linux/module.h>
@@ -42,8 +45,11 @@#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_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
@@ -54,8 +60,26 @@/* Masks */ #define ADIS16607_RESET_GPIO_MASK GENMASK(2, 0) +#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_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 + +/* Burst read - Half-Duplex mode (DATA_CNTR enabled) */ +#define ADIS16607_BURST_CMD_SIZE 4 +/* Self-test registers and masks */ #define ADIS16607_REG_SELF_TEST_DATA (x) ((x) + 0x23)#define ADIS16607_SNSR_SELF_TEST_MASK BIT(6)
@@ -86,6 +110,11 @@ struct adis16607 {const struct adis16607_chip_info *info;unsigned long clk_freq_mhz;u64 sample_period_ns; +u16 fifo_watermark; +/* Scratch buffer used for FIFO pop operations, see adis16607_fifo_pop() */ +u8 fifo_buf[ADIS16607_BURST_CMD_SIZE +ADIS16607_FIFO_DATA_LEN ]__aligned(IIO_DMA_MINALIGN) ; +/* IIO buffer for reordered data - sized for max channels */ +u8 data[64 ]__aligned(IIO_DMA_MINALIGN) ; };enum {
@@ -215,6 +244,286 @@ static const struct adis_ops adis16607_ops = { .reset = adis16607_reset, }; +/* +* FIFO/burst data offsets for each channel (in bytes from the data start, +* i.e. after the 4-byte command prefix). +* Each 32-bit inertial channel occupies 4 bytes (MSW + LSW), TEMP is 2 bytes. +* +* FIFO data layout (52 bytes, DATA_CNTR enabled, no checksum): +* Offset 0-3: ACCEL_X (32-bit: MSW, LSW) +* Offset 4-7: ACCEL_Y +* Offset 8-11: ACCEL_Z +* Offset 12-15: GYRO_X +* Offset 16-19: GYRO_Y +* Offset 20-23: GYRO_Z +* Offset 24-27: DELTVEL_X +* Offset 28-31: DELTVEL_Y +* Offset 32-35: DELTVEL_Z +* Offset 36-39: DELTANG_X +* Offset 40-43: DELTANG_Y +* Offset 44-47: DELTANG_Z +* Offset 48-49: TEMP (16-bit) +* Offset 50-51: DATA_CNTR (16-bit) +* +* Each 32-bit value encodes 24-bit sensor data as: +* value_24bit = (MSW << 8) | (LSW >> 8) +*/ +static const u8 adis16607_burst_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 a single sample from FIFO using FIFO_DATA command (0xA9). +* Returns the raw FIFO data in the provided buffer. +*/ +static int adis16607_fifo_pop (struct adis16607 *st,u8 *data) +{ +struct spi_message msg; +struct spi_transfer xfer = { + .tx_buf = st->fifo_buf, + .rx_buf = st->fifo_buf, + .len =ADIS16607_BURST_CMD_SIZE +ADIS16607_FIFO_DATA_LEN , + .bits_per_word =8 , + }; +int ret; + +/* FIFO data command */ + st->fifo_buf[0 ] =ADIS16607_FIFO_DATA_CMD ; + st->fifo_buf[1 ] =0 ; + st->fifo_buf[2 ] =0 ; + st->fifo_buf[3 ] =0 ; + +spi_message_init (&msg); +spi_message_add_tail (&xfer, &msg); + + ret =spi_sync (st->adis.spi, &msg); +if (ret) +return ret; + +/* Copy data starting after command bytes */ +memcpy (data, st->fifo_buf +ADIS16607_BURST_CMD_SIZE ,ADIS16607_FIFO_DATA_LEN ); +return 0 ; +} + +/* +* Process a single FIFO sample and push to IIO buffer. +* FIFO data format differs from regular burst - no DIAG_STAT, data starts immediately. +* +* FIFO data layout (52 bytes): +* Offset 0-3: ACCEL_X (32-bit) +* Offset 4-7: ACCEL_Y (32-bit) +* Offset 8-11: ACCEL_Z (32-bit) +* Offset 12-15: GYRO_X (32-bit) +* Offset 16-19: GYRO_Y (32-bit) +* Offset 20-23: GYRO_Z (32-bit) +* Offset 24-27: DELTVEL_X (32-bit) +* Offset 28-31: DELTVEL_Y (32-bit) +* Offset 32-35: DELTVEL_Z (32-bit) +* Offset 36-39: DELTANG_X (32-bit) +* Offset 40-43: DELTANG_Y (32-bit) +* Offset 44-47: DELTANG_Z (32-bit) +* Offset 48-49: TEMP (16-bit) +* Offset 50-51: DATA_CNTR (16-bit) +*/ +static void adis16607_fifo_push_sample (struct iio_dev *indio_dev, +u8 *fifo_data,s64 timestamp) +{ +struct adis16607 *st =iio_priv (indio_dev); +u16 msw, lsw; +s32 val24; +int bit, offset =0 ; + +memset (st->data,0 ,sizeof (st->data)); + +for_each_set_bit (bit, indio_dev->active_scan_mask, indio_dev->masklength) { +u8 burst_off; + +/* Skip the soft timestamp channel - it has no burst offset */ +if (bit >=ARRAY_SIZE (adis16607_burst_offsets)) +continue ; + + burst_off = adis16607_burst_offsets[bit]; + +if (bit ==ADIS16607_SCAN_TEMP ) { +/* TEMP is 16-bit */ +put_unaligned_be16 (get_unaligned_be16 (&fifo_data[burst_off]), + &st->data[offset]); + offset +=2 ; + }else { +/* All other channels are 24-bit stored as 32-bit */ + msw =get_unaligned_be16 (&fifo_data[burst_off]); + lsw =get_unaligned_be16 (&fifo_data[burst_off +2 ]); + val24 =sign_extend32 (((u32 )msw <<8 ) | (lsw >>8 ),23 ); +put_unaligned_be32 (val24, &st->data[offset]); + offset +=4 ; + } + } + +iio_push_to_buffers_with_timestamp (indio_dev, st->data, timestamp); +} + +/* +* Trigger handler - reads samples from the device FIFO. Triggered by the +* DEV_NOK interrupt, which fires on any DIAG_STAT flag, not just +* FIFO_THRESH_MET - the DIAG_STAT read below both checks which flag(s) +* raised the interrupt and clears the latched status, and must happen +* before any FIFO pop, or we'd pop for nothing on an unrelated flag. +*/ +static irqreturn_t adis16607_trigger_handler (int irq,void *p) +{ +struct iio_poll_func *pf = p; +struct iio_dev *indio_dev = pf->indio_dev; +struct adis16607 *st =iio_priv (indio_dev); +u8 fifo_sample[ADIS16607_FIFO_DATA_LEN ]; +u16 diag_stat, word_cnt, sample_cnt; +s64 timestamp; +int ret, i; + +mutex_lock (&st->adis.state_lock); + +/* Check if FIFO threshold is met */ + ret =__adis_read_reg_16 (&st->adis,ADIS16607_REG_DIAG_STAT , &diag_stat); +if (ret) + goto unlock; + +if (!(diag_stat &ADIS16607_FIFO_THR_MET_MASK )) + goto unlock; + +/* Read FIFO word count */ + ret =__adis_read_reg_16 (&st->adis,ADIS16607_REG_FIFO_WORD_CNT , &word_cnt); +if (ret) + goto unlock; + +/* Calculate number of complete samples */ + sample_cnt = word_cnt /ADIS16607_FIFO_WORDS_PER_SAMPLE ; +if (!sample_cnt) + goto unlock; + +/* +* pf->timestamp is the IRQ-fire time, i.e. when the newest (last +* enqueued) sample tipped the FIFO over watermark. The FIFO pops +* oldest-first, so back-date the first popped sample's timestamp by +* the batch duration - the loop then counts back up to pf->timestamp +* for the newest sample, instead of projecting past it. +*/ + timestamp = pf->timestamp - (s64)(sample_cnt -1 ) * st->sample_period_ns; + +/* Pop and process each sample */ +for (i =0 ; i < sample_cnt; i++) { + ret =adis16607_fifo_pop (st, fifo_sample); +if (ret) + goto unlock; + +adis16607_fifo_push_sample (indio_dev, fifo_sample, timestamp); + timestamp += st->sample_period_ns; + } + +unlock: +mutex_unlock (&st->adis.state_lock); +iio_trigger_notify_done (indio_dev->trig); +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 ; +return __adis_write_reg_16 (adis,ADIS16607_REG_USER_FIFO_CFG , + threshold &ADIS16607_FIFO_THR_MASK ); +} + +static int adis16607_buffer_postdisable (struct iio_dev *indio_dev) +{ +struct adis16607 *st =iio_priv (indio_dev); +struct adis *adis = &st->adis; + +adis_dev_auto_lock (adis); + +/* Disable FIFO */ +return __adis_write_reg_16 (adis,ADIS16607_REG_USER_FIFO_CFG ,0 ); +} + +static const struct iio_buffer_setup_ops adis16607_buffer_ops = { + .postenable = adis16607_buffer_postenable, + .postdisable = adis16607_buffer_postdisable, +}; + +static int adis16607_set_watermark (struct iio_dev *indio_dev,unsigned int val) +{ +struct adis16607 *st =iio_priv (indio_dev); + + val =clamp (val,1 ,ADIS16607_MAX_FIFO_WM ); + st->fifo_watermark = val; + +return 0 ; +} +/* * Check if the delta between two values is within specified range. */
@@ -306,8 +615,9 @@ static int adis16607_sensor_self_test(struct adis16607 *st)* has handled reset (hardware GPIO or SW reset, adislib's own job) and * before self-test - no mutex is taken here either, matching that * convention. Does the device-specific startup steps adislib has no -* concept of: SPI Half-Duplex locking, dev_id verification, and the -* bootloader-busy check. +* concept of: SPI Half-Duplex locking, dev_id verification, the +* bootloader-busy check, enabling 32-bit burst mode + DATA_CNTR, and +* the DR/DEV_NOK pin routing. */ static int adis16607_post_reset_setup (struct adis *adis) {
@@ -355,7 +665,29 @@ static int adis16607_post_reset_setup(struct adis *adis)return -EBUSY ; } -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 ); }/*
@@ -669,6 +1001,7 @@ 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, };static const char *const adis16607_status_error_msgs[] = {
@@ -690,6 +1023,7 @@ static const struct adis_data adis16607_data = { .prod_id_reg = ADIS16607_REG_DEV_ID, .prod_id = 0x6000, .unmasked_drdy = true, + .has_fifo = true, .post_reset_setup = adis16607_post_reset_setup, .self_test = adis16607_self_test, .status_error_msgs = adis16607_status_error_msgs,
@@ -765,6 +1099,8 @@ static int adis16607_probe(struct spi_device *spi) indio_dev->info = &adis16607_info; indio_dev->modes =INDIO_DIRECT_MODE ; + st->fifo_watermark =ADIS16607_MAX_FIFO_WM ; + st->adis.ops = &adis16607_ops; ret =devm_regulator_get_enable (dev,"vdd" );
@@ -803,6 +1139,13 @@ static int adis16607_probe(struct spi_device *spi)if (ret)return ret; + ret =devm_adis_setup_buffer_and_trigger_with_attrs (&st->adis, indio_dev, + adis16607_trigger_handler, + &adis16607_buffer_ops, + adis16607_fifo_attributes); +if (ret) +return ret; + ret =devm_iio_device_register (dev, indio_dev);if (ret)return ret;
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v4 6/8] iio: imu: adis16607: Add FIFO-based buffered/triggered capture
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [High] iio: imu: adis16607: unset irq_flag in adis16607_probe() forces edge IRQ - [Medium] iio: imu…
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] iio: imu: adis16607: unset irq_flag in adis16607_probe() forces edge IRQ
- [Medium] iio: imu: adis16607: stale FIFO data and uncleared DIAG_STAT on re-enable
- [Low] iio: imu: adis16607: direct access to private masklength in push helper --
commit f5af8f0b1c54166ac9ed077db3f6e76ce908f907
Author: Radu Sabau <[email protected]>
iio: imu: adis16607: Add FIFO-based buffered/triggered capture
This commit adds buffered capture support to the adis16607 IMU driver using the hardware FIFO, triggered by the DEV_NOK interrupt line when the configured FIFO watermark is met.
Quoted 4 lines
drivers/iio/imu/adis16607.c +0
-0
[ ... ]
Quoted 3 lines
drivers/iio/imu/adis16607.c +0
-0@@ -215,6 +244,286 @@ static const struct adis_ops adis16607_ops = { .reset = adis16607_reset, };
[ ... ]
drivers/iio/imu/adis16607.c static const struct adis_ops adis16607_ops = { · line 350
Quoted 11 lines
drivers/iio/imu/adis16607.c +11
-0+static void adis16607_fifo_push_sample (struct iio_dev *indio_dev, +u8 *fifo_data,s64 timestamp) +{ +struct adis16607 *st =iio_priv (indio_dev); +u16 msw, lsw; +s32 val24; +int bit, offset =0 ; + +memset (st->data,0 ,sizeof (st->data)); + +for_each_set_bit (bit, indio_dev->active_scan_mask, indio_dev->masklength) {
[Severity: Low]
In include/linux/iio/iio.h, struct iio_dev declares masklength with the __private annotation, which triggers a sparse noderef warning when accessed directly in adis16607_fifo_push_sample().
Should this use iio_for_each_active_channel(indio_dev, bit) (or iio_get_masklength(indio_dev)) instead of accessing indio_dev->masklength directly?
[ ... ]
Quoted 21 lines
drivers/iio/imu/adis16607.c +21
-0+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 ; +return __adis_write_reg_16 (adis,ADIS16607_REG_USER_FIFO_CFG , + threshold &ADIS16607_FIFO_THR_MASK ); +} +
drivers/iio/imu/adis16607.c static const struct adis_ops adis16607_ops = { · line 510
Quoted 10 lines
drivers/iio/imu/adis16607.c +10
-0+static int adis16607_buffer_postdisable (struct iio_dev *indio_dev) +{ +struct adis16607 *st =iio_priv (indio_dev); +struct adis *adis = &st->adis; + +adis_dev_auto_lock (adis); + +/* Disable FIFO */ +return __adis_write_reg_16 (adis,ADIS16607_REG_USER_FIFO_CFG ,0 ); +}
[Severity: Medium]
Can stale FIFO samples from a previous capture session be pushed into the IIO buffer when the buffer is disabled and re-enabled?
During buffer disable in iio_disable_buffers(), iio_trigger_detach_poll_func() disables the IRQ before calling adis16607_buffer_postdisable(). Because adis16607_buffer_postdisable() only writes 0 to ADIS16607_REG_USER_FIFO_CFG without flushing the FIFO or reading ADIS16607_REG_DIAG_STAT, any samples enqueued before USER_FIFO_CFG is cleared remain in the hardware FIFO, and ADIS16607_FIFO_THR_MET_MASK can remain latched in DIAG_STAT with DEV_NOK asserted.
On a subsequent buffer enable, iio_enable_buffers() enables the trigger IRQ before calling setup_ops->postenable:
drivers/iio/industrialio-buffer.c:iio_enable_buffers() {
if (iio_dev_opaque->currentmode == INDIO_BUFFER_TRIGGERED) {
ret = iio_trigger_attach_poll_func(indio_dev->trig,
indio_dev->pollfunc);
if (ret)
goto err_disable_buffers;
}
if (indio_dev->setup_ops->postenable) {
ret = indio_dev->setup_ops->postenable(indio_dev);
}If the interrupt fires immediately when iio_trigger_attach_poll_func() calls adis_enable_irq(), adis16607_trigger_handler() can run before adis16607_buffer_postenable(), see ADIS16607_FIFO_THR_MET_MASK still set in DIAG_STAT, and pop the leftover samples from the previous session with timestamps from the new session.
Additionally, adis16607_buffer_postenable() flushes the FIFO without reading ADIS16607_REG_DIAG_STAT to clear any latched fault or threshold flags holding DEV_NOK asserted. Should adis16607_buffer_postdisable() also flush the FIFO and clear DIAG_STAT, or should the FIFO and DIAG_STAT cleanup happen before the trigger IRQ is enabled?
[ ... ]
Quoted 18 lines
drivers/iio/imu/adis16607.c +3
-0@@ -690,6 +1023,7 @@ static const struct adis_data adis16607_data = { .prod_id_reg = ADIS16607_REG_DEV_ID, .prod_id = 0x6000, .unmasked_drdy = true, + .has_fifo = true, .post_reset_setup = adis16607_post_reset_setup, .self_test = adis16607_self_test, .status_error_msgs = adis16607_status_error_msgs,@@ -765,6 +1099,8 @@ static int adis16607_probe(struct spi_device *spi) indio_dev->info = &adis16607_info; indio_dev->modes =INDIO_DIRECT_MODE ; + st->fifo_watermark =ADIS16607_MAX_FIFO_WM ; + st->adis.ops = &adis16607_ops; ret =devm_regulator_get_enable (dev,"vdd" );
drivers/iio/imu/adis16607.c static int adis16607_probe(struct spi_device *spi) · line 1147
Quoted 9 lines
drivers/iio/imu/adis16607.c +6
-0@@ -803,6 +1139,13 @@ static int adis16607_probe(struct spi_device *spi)if (ret)return ret; + ret =devm_adis_setup_buffer_and_trigger_with_attrs (&st->adis, indio_dev, + adis16607_trigger_handler, + &adis16607_buffer_ops, + adis16607_fifo_attributes); +if (ret) +return ret;
[Severity: High]
Does leaving st->adis.irq_flag unset in adis16607_probe() force the DEV_NOK interrupt to be requested as rising-edge triggered instead of level-triggered?
While adis16607_data sets .has_fifo = true and DEV_NOK is a level-triggered signal that stays asserted until ADIS16607_REG_DIAG_STAT is read, adis16607_probe() never initializes st->adis.irq_flag from irq_get_trigger_type(spi->irq). As a result, st->adis.irq_flag is 0 (IRQF_TRIGGER_NONE) when devm_adis_setup_buffer_and_trigger_with_attrs() -> devm_adis_probe_trigger() -> adis_validate_irq_flag() runs:
drivers/iio/imu/adis_trigger.c:adis_validate_irq_flag() {
unsigned long direction = adis->irq_flag & IRQF_TRIGGER_MASK;
/* We cannot mask the interrupt so ensure it's not enabled at request */
if (adis->data->unmasked_drdy)
adis->irq_flag |= IRQF_NO_AUTOEN;
/*
* Typically this devices have data ready either on the rising edge or
* on the falling edge of the data ready pin. This checks enforces that
* one of those is set in the drivers... Defaults to
* IRQF_TRIGGER_RISING for backward compatibility with devices that
* don't support changing the pin polarity.
*/
if (direction == IRQF_TRIGGER_NONE) {
adis->irq_flag |= IRQF_TRIGGER_RISING;
return 0;
} else if (direction != IRQF_TRIGGER_RISING &&
direction != IRQF_TRIGGER_FALLING && !adis->data->has_fifo) {
dev_err(&adis->spi->dev, "Invalid IRQ mask: %08lx\n",
adis->irq_flag);
return -EINVAL;
} else if (direction != IRQF_TRIGGER_HIGH &&
direction != IRQF_TRIGGER_LOW && adis->data->has_fifo) {
}Because direction is IRQF_TRIGGER_NONE, adis_validate_irq_flag() takes the first branch and sets IRQF_TRIGGER_RISING before reaching the has_fifo check. devm_adis_probe_trigger() then passes IRQF_TRIGGER_RISING to devm_request_threaded_irq(), which overrides the firmware/devicetree IRQ_TYPE_LEVEL_HIGH trigger configuration in __setup_irq().
If the interrupt controller rejects rising-edge mode on that line, probe fails. If it accepts rising-edge mode, any condition where DEV_NOK is already asserted when the IRQ is enabled, or remains asserted across adis16607_trigger_handler() (for example, if a DIAG_STAT bit re-asserts after the initial __adis_read_reg_16() while the multi-sample adis16607_fifo_pop() loop is still running), will not generate a new rising edge and will stall FIFO capture.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
Jonathan Cameron
maintainerRe: [PATCH v4 6/8] iio: imu: adis16607: Add FIFO-based buffered/triggered capture
In reply to Radu SabauQuoted 34 lines · On Fri, 23 Oct 2026 12:30:23 +0300 Radu Sabau via B4 Relay…
From: Radu Sabau <[email protected]>
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), handled directly rather than through adislib's generic burst-read helpers, which assume one fixed-shape read per trigger rather than a variable-count drain loop.The watermark-met condition is signaled via
DEV_NOKon the device's one interrupt pin, which stays asserted (level-triggered) untilDIAG_STATis read and cleared - matching adislib'shas_fifocontract.DEV_NOKfires on anyDIAG_STATflag, not justFIFO_THRESH_MET, so the trigger handler checks that specific bit before popping anything.DR_GPIO_MASKstays enabled unconditionally: DR pulses drive the FIFO controller's internal sample enqueue, independent of pin routing.Watermark is configurable via the standard
hwfifo_set_watermarkcallback and the usual hwfifo_* sysfs attributes.Signed-off-by Radu Sabau <[email protected]>--- drivers/iio/imu/adis16607.c | 349 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 346 insertions(+), 3 deletions(-)drivers/iio/imu/adis16607.c +0
-0/* Self-test registers and masks */ #define ADIS16607_REG_SELF_TEST_DATA (x) ((x) + 0x23)#define ADIS16607_SNSR_SELF_TEST_MASK BIT(6)
drivers/iio/imu/adis16607.c struct adis16607 { · line 116
Quoted 7 lines
drivers/iio/imu/adis16607.c +4
-0@@ -86,6 +110,11 @@ struct adis16607 {const struct adis16607_chip_info *info;unsigned long clk_freq_mhz;u64 sample_period_ns; +u16 fifo_watermark; +/* Scratch buffer used for FIFO pop operations, see adis16607_fifo_pop() */ +u8 fifo_buf[ADIS16607_BURST_CMD_SIZE +ADIS16607_FIFO_DATA_LEN ]__aligned(IIO_DMA_MINALIGN) ; +/* IIO buffer for reordered data - sized for max channels */
That rather implies you never DMA into it. If so just move it before the fifo_buf and no need to mark it IIO_DMA_MINALIGN.
I'd also prefer that 64 was sized by maths, not a comment saying it is big enough. That may include use of IIO_DECLARE_BUFFER_WITH_TS() to ensure the timestamp spacing is there.
Quoted 24 lines
drivers/iio/imu/adis16607.c +22
-0+u8 data[64 ]__aligned(IIO_DMA_MINALIGN) ; }; +/* +* Process a single FIFO sample and push to IIO buffer. +* FIFO data format differs from regular burst - no DIAG_STAT, data starts immediately. +* +* FIFO data layout (52 bytes): +* Offset 0-3: ACCEL_X (32-bit) +* Offset 4-7: ACCEL_Y (32-bit) +* Offset 8-11: ACCEL_Z (32-bit) +* Offset 12-15: GYRO_X (32-bit) +* Offset 16-19: GYRO_Y (32-bit) +* Offset 20-23: GYRO_Z (32-bit) +* Offset 24-27: DELTVEL_X (32-bit) +* Offset 28-31: DELTVEL_Y (32-bit) +* Offset 32-35: DELTVEL_Z (32-bit) +* Offset 36-39: DELTANG_X (32-bit) +* Offset 40-43: DELTANG_Y (32-bit) +* Offset 44-47: DELTANG_Z (32-bit) +* Offset 48-49: TEMP (16-bit) +* Offset 50-51: DATA_CNTR (16-bit) +*/ +static void adis16607_fifo_push_sample(struct iio_dev *indio_dev,
drivers/iio/imu/adis16607.c static const struct adis_ops adis16607_ops = { · line 350
Quoted 10 lines
drivers/iio/imu/adis16607.c +10
-0+ u8 *fifo_data, s64 timestamp) +{ +struct adis16607 *st =iio_priv (indio_dev); +u16 msw, lsw; +s32 val24; +int bit, offset =0 ; + +memset (st->data,0 ,sizeof (st->data)); + +for_each_set_bit (bit, indio_dev->active_scan_mask, indio_dev->masklength) {
iio_for_each_active_channel()
As sashiko notes, masklength is private.
There are a load of places we need to update to stop accessing these directly but please don't add another one.
It's on my list to throw some LLM tokens ago once I get out from under review backlog.
https://sashiko.dev/#/patchset/20261023-adis16607-v4-0-a4d541ebfd13%40analog.com
Check everything else reported.
FWIW there are also some nasty race conditions around active_scan_mask being available when the buffer is being torn down. You might want to close those off by claiming buffered mode to prevent such a transition.
Quoted 14 lines
drivers/iio/imu/adis16607.c +14
-0+u8 burst_off; + +/* Skip the soft timestamp channel - it has no burst offset */ +if (bit >=ARRAY_SIZE (adis16607_burst_offsets)) +continue ; + + burst_off = adis16607_burst_offsets[bit]; + +if (bit ==ADIS16607_SCAN_TEMP ) { +/* TEMP is 16-bit */ +put_unaligned_be16 (get_unaligned_be16 (&fifo_data[burst_off]), + &st->data[offset]); + offset +=2 ; + }else {
drivers/iio/imu/adis16607.c static const struct adis_ops adis16607_ops = { · line 374
Quoted 10 lines
drivers/iio/imu/adis16607.c +10
-0+/* All other channels are 24-bit stored as 32-bit */ + msw =get_unaligned_be16 (&fifo_data[burst_off]); + lsw =get_unaligned_be16 (&fifo_data[burst_off +2 ]); + val24 =sign_extend32 (((u32 )msw <<8 ) | (lsw >>8 ),23 ); +put_unaligned_be32 (val24, &st->data[offset]); + offset +=4 ; + } + } + +iio_push_to_buffers_with_timestamp (indio_dev, st->data, timestamp);
Use iio_push_to_buffers_with_ts() as for once in an ADIS driver we actually have the size of data. Note that fixing the whole adis library is something that needs doing though I took a look at it on Friday and decided to leave it for now!
Jonathan
Quoted 1 line
+}
RE: [PATCH v4 6/8] iio: imu: adis16607: Add FIFO-based buffered/triggered capture
Quoted 3 lines
-----Original Message-----
From: Jonathan Cameron <[email protected]>
Sent: Monday, October 26, 2026 2:09 AM
...
Quoted 28 lines
Quoted 11 lines
drivers/iio/imu/adis16607.c +11
-0+static void adis16607_fifo_push_sample (struct iio_dev *indio_dev, +u8 *fifo_data,s64 timestamp) +{ +struct adis16607 *st =iio_priv (indio_dev); +u16 msw, lsw; +s32 val24; +int bit, offset =0 ; + +memset (st->data,0 ,sizeof (st->data)); + + for_each_set_bit(bit, indio_dev->active_scan_mask, indio_dev-Quoted 1 line
masklength) {
iio_for_each_active_channel()As sashiko notes, masklength is private.
There are a load of places we need to update to stop accessing these directly but please don't add another one.
It's on my list to throw some LLM tokens ago once I get out from under review backlog.
https://urldefense.com/v3/__https://sashiko.dev/*/patchset/20261023-
adis16607-v4-0- a4d541ebfd13*40analog.com__;IyU!!A3Ni8CS0y2Y!9cguUuIwYMdnmBcoNR ye0_U99KUnJt04T6XlSnvS-9rxh5-8Y2fQXC39Mxsw3erc_JwvyFp3ssecZg$ Check everything else reported.
Quoted 5 lines
FWIW there are also some nasty race conditions around
active_scan_maskbeing available when the buffer is being torn down. You might want to close those off by claiming buffered mode to prevent such a transition.
Agreed, I'll switch to iio_for_each_active_channel() and I'll go through the rest of the Sashiko findings for v5.
On the active_scan_mask races, I'd like to check which path you mean. In this driver the only reader of the mask is the trigger handler (fifo_push_sample()), which runs as the pollfunc.
As far as I can tell, iio_trigger_detach_poll_func()'s free_irq() waits for it to finish before iio_disable_buffers() frees the mask, so I couldn't find a window where the handler sees a stale or NULL mask today.
Even so, I'd like to close this off for good, so that a later change to the driver or to adislib can't introduce the race.
Claiming buffer mode inside the handler looks like it would deadlock against iio_disable_buffers(), which holds mlock while waiting for the handler in free_irq().
Would snapshotting the active-channel layout in update_scan_mode() (called before the pollfunc is attached) and having the handler read only that copy be an acceptable way to close it?
Jonathan Cameron
maintainerRe: [PATCH v4 6/8] iio: imu: adis16607: Add FIFO-based buffered/triggered capture
Quoted 43 lines · Radu bogdan
Quoted 3 lines
-----Original Message-----
From: Jonathan Cameron <[email protected]>
Sent: Monday, October 26, 2026 2:09 AM...
Quoted 28 lines
Quoted 11 lines
drivers/iio/imu/adis16607.c +11
-0+static void adis16607_fifo_push_sample (struct iio_dev *indio_dev, +u8 *fifo_data,s64 timestamp) +{ +struct adis16607 *st =iio_priv (indio_dev); +u16 msw, lsw; +s32 val24; +int bit, offset =0 ; + +memset (st->data,0 ,sizeof (st->data)); + + for_each_set_bit(bit, indio_dev->active_scan_mask, indio_dev-Quoted 1 line
masklength) {
iio_for_each_active_channel()As sashiko notes, masklength is private.
There are a load of places we need to update to stop accessing these directly but please don't add another one.
It's on my list to throw some LLM tokens ago once I get out from under review backlog.
https://urldefense.com/v3/__https://sashiko.dev/*/patchset/20261023-
adis16607-v4-0- a4d541ebfd13*40analog.com__;IyU!!A3Ni8CS0y2Y!9cguUuIwYMdnmBcoNR ye0_U99KUnJt04T6XlSnvS-9rxh5-8Y2fQXC39Mxsw3erc_JwvyFp3ssecZg$ Check everything else reported.Quoted 5 lines
FWIW there are also some nasty race conditions around
active_scan_maskbeing available when the buffer is being torn down. You might want to close those off by claiming buffered mode to prevent such a transition.Agreed, I'll switch to
iio_for_each_active_channel()and I'll go through the rest of the Sashiko findings for v5.
Quoted 6 lines
On the
active_scan_maskraces, I'd like to check which path you mean. In this driver the only reader of the mask is the trigger handler (fifo_push_sample()), which runs as the pollfunc.
As far as I can tell, iio_trigger_detach_poll_func()'sfree_irq()waits for it to finish beforeiio_disable_buffers()frees the mask, so I couldn't find a window where the handler sees a stale or NULL mask today.
Ah. I may have failed to distinguish between cases with a trigger involved and those without. The bug reports are probably on the ones without. Unfortunately I haven't found time to look at the overall issue in enough detail yet.
Quoted 6 lines
Even so, I'd like to close this off for good, so that a later change to the driver or to adislib can't introduce the race.
Claiming buffer mode inside the handler looks like it would deadlock against
iio_disable_buffers(), which holds mlock while waiting for the handler infree_irq().
We'd use a conditional claim in here - only the core code driving the state transitions should take a claim unconditionally (they can just grab the lock). If mlock is held it should fail and we just drop out of the handler having done nothing. So either disable buffer wins and we drop through the handler quickly or it looses and the attempt to take mlock blocks in iio_disable_buffers()
Or am I missing something worse?
Quoted 4 lines
Would snapshotting the active-channel layout in
update_scan_mode()(called before the pollfunc is attached) and having the handler read only that copy be an acceptable way to close it?
It would but that feels like we are just papering over a lifetime issue by creating another object rather than fixing it if necessary.
Anyhow, from your first comment this may all be irrelevant anyway.
Jonathan
Quoted 1 line
Jonathan Cameron
maintainerRe: [PATCH v4 6/8] iio: imu: adis16607: Add FIFO-based buffered/triggered capture
Quoted 65 lines · On Sun, 1 Nov 2026 23:50:10 +0000 Jonathan Cameron <[email protected]> wrote:
Quoted 43 lines · Radu bogdan
Quoted 3 lines
-----Original Message-----
From: Jonathan Cameron <[email protected]>
Sent: Monday, October 26, 2026 2:09 AM...
Quoted 28 lines
Quoted 11 lines
drivers/iio/imu/adis16607.c +11
-0+static void adis16607_fifo_push_sample (struct iio_dev *indio_dev, +u8 *fifo_data,s64 timestamp) +{ +struct adis16607 *st =iio_priv (indio_dev); +u16 msw, lsw; +s32 val24; +int bit, offset =0 ; + +memset (st->data,0 ,sizeof (st->data)); + + for_each_set_bit(bit, indio_dev->active_scan_mask, indio_dev-Quoted 1 line
masklength) {
iio_for_each_active_channel()As sashiko notes, masklength is private.
There are a load of places we need to update to stop accessing these directly but please don't add another one.
It's on my list to throw some LLM tokens ago once I get out from under review backlog.
https://urldefense.com/v3/__https://sashiko.dev/*/patchset/20261023-
adis16607-v4-0- a4d541ebfd13*40analog.com__;IyU!!A3Ni8CS0y2Y!9cguUuIwYMdnmBcoNR ye0_U99KUnJt04T6XlSnvS-9rxh5-8Y2fQXC39Mxsw3erc_JwvyFp3ssecZg$ Check everything else reported.Quoted 5 lines
FWIW there are also some nasty race conditions around
active_scan_maskbeing available when the buffer is being torn down. You might want to close those off by claiming buffered mode to prevent such a transition.Agreed, I'll switch to
iio_for_each_active_channel()and I'll go through the rest of the Sashiko findings for v5.Quoted 6 lines
On the
active_scan_maskraces, I'd like to check which path you mean. In this driver the only reader of the mask is the trigger handler (fifo_push_sample()), which runs as the pollfunc.
As far as I can tell, iio_trigger_detach_poll_func()'sfree_irq()waits for it to finish beforeiio_disable_buffers()frees the mask, so I couldn't find a window where the handler sees a stale or NULL mask today.Ah. I may have failed to distinguish between cases with a trigger involved and those without. The bug reports are probably on the ones without. Unfortunately I haven't found time to look at the overall issue in enough detail yet.
Quoted 6 lines
Even so, I'd like to close this off for good, so that a later change to the driver or to adislib can't introduce the race.
Claiming buffer mode inside the handler looks like it would deadlock against
iio_disable_buffers(), which holds mlock while waiting for the handler infree_irq().
Quoted 8 lines
We'd use a conditional claim in here - only the core code driving the state transitions should take a claim unconditionally (they can just grab the lock). If mlock is held it should fail and we just drop out of the handler having done nothing. So either disable buffer wins and we drop through the handler quickly or it looses and the attempt to take mlock blocks in
iio_disable_buffers()Or am I missing something worse?
I'm indeed being dopey today. Whilst it is a conditional claim we grab the lock unconditionally as part of that. Which makes sense because we want multiple simple read the state calls to block behind each other.
Quoted 15 lines
Quoted 5 lines
Would snapshotting the active-channel layout in
update_scan_mode()(called before the pollfunc is attached) and having the handler read only that copy be an acceptable way to close it?It would but that feels like we are just papering over a lifetime issue by creating another object rather than fixing it if necessary.
Anyhow, from your first comment this may all be irrelevant anyway.
Jonathan
Quoted 1 line
Nuno Sá
maintainerRe: [PATCH v4 6/8] iio: imu: adis16607: Add FIFO-based buffered/triggered capture
In reply to Radu Sabaudrivers/iio/imu/adis16607.c static const struct adis_ops adis16607_ops = { · line 322
Quoted 12 lines · Radu Sabau
drivers/iio/imu/adis16607.c +0
-0@@ -215,6 +244,286 @@ static const struct adis_ops adis16607_ops = {[ ... skip 73 lines ... ]
drivers/iio/imu/adis16607.c +6
-0+return 0 ; +} + +/* +* Process a single FIFO sample and push to IIO buffer. +* FIFO data format differs from regular burst - no DIAG_STAT, data starts immediately.
So FIFO is another command different from burst_mode? If so, is there any constrain with using SPI full duplex and FIFO?
drivers/iio/imu/adis16607.c static const struct adis_ops adis16607_ops = { · line 394
Quoted 7 lines
[ ... skip 66 lines ... ]
drivers/iio/imu/adis16607.c +6
-0+u8 fifo_sample[ADIS16607_FIFO_DATA_LEN ]; +u16 diag_stat, word_cnt, sample_cnt; +s64 timestamp; +int ret, i; + +mutex_lock (&st->adis.state_lock);
Use the helper.
Signature · 1 line
Nuno Sá <[email protected]>
RE: [PATCH v4 6/8] iio: imu: adis16607: Add FIFO-based buffered/triggered capture
Quoted 3 lines
-----Original Message-----
From: Sa, Nuno <[email protected]>
Sent: Friday, October 30, 2026 4:07 PM
...
Quoted 9 lines
drivers/iio/imu/adis16607.c static const struct adis_ops adis16607_ops = {
Quoted 4 lines
drivers/iio/imu/adis16607.c +4
-0+ +/* +* Process a single FIFO sample and push to IIO buffer. +* FIFO data format differs from regular burst - no DIAG_STAT, data starts immediately.
So FIFO is another command different from
burst_mode? If so, is there any constrain with using SPI full duplex and FIFO?
Burst Read Function can be used on two registers, DIAG_STAT and FIFO_DATA. On DIAG_STAT it returns a single set of the most recent samples directly from the sensor, bypassing the FIFO.
On FIFO_DATA each burst read pops one set of samples from the FIFO. Either way the whole set comes out in a single SPI transfer with CS held low. I used half-duplex because that is what gives access to the burst
read: in full duplex, register reads are separate transfers with CS toggling between them, so a set can't be popped in one transfer.
Nuno Sá
maintainerRe: [PATCH v4 6/8] iio: imu: adis16607: Add FIFO-based buffered/triggered capture
Quoted 16 lines · Radu bogdan
Quoted 3 lines
-----Original Message-----
From: Sa, Nuno <[email protected]>
Sent: Friday, October 30, 2026 4:07 PM...
Quoted 9 lines
drivers/iio/imu/adis16607.c static const struct adis_ops adis16607_ops = {
Quoted 4 lines
drivers/iio/imu/adis16607.c +4
-0+ +/* +* Process a single FIFO sample and push to IIO buffer. +* FIFO data format differs from regular burst - no DIAG_STAT, data starts immediately.
So FIFO is another command different from
burst_mode? If so, is there any constrain with using SPI full duplex and FIFO?
Quoted 8 lines
Burst Read Function can be used on two registers,
DIAG_STATandFIFO_DATA. OnDIAG_STATit returns a single set of the most recent samples directly from the sensor, bypassing the FIFO.
OnFIFO_DATAeach burst read pops one set of samples from the FIFO. Either way the whole set comes out in a single SPI transfer with CS held low. I used half-duplex because that is what gives access to the burst
read: in full duplex, register reads are separate transfers with CS toggling between them, so a set can't be popped in one transfer.
I see! Thanks to clear that out (too lazy to go look at the datashee :))!
- Nuno Sá
Quoted 1 line
PATCH v4 7/8 iio: imu: adis16607: Add external clock sync support
In reply to Radu SabauAdd support for an optional external clock (clocks property), selecting between SYNC_DIRECT and SYNC_SCALED modes depending on the supplied frequency, with the internal 8 kHz clock used as the default when no clock is provided.
--- drivers/iio/imu/adis16607.c | 121 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 114 insertions(+), 7 deletions(-)
drivers/iio/imu/adis16607.c +114 -7
@@ -7,6 +7,7 @@#include <linux/array_size.h> #include <linux/bitfield.h> #include <linux/bitops.h> +#include <linux/clk.h> #include <linux/debugfs.h> #include <linux/delay.h> #include <linux/iio/buffer.h>
@@ -48,6 +49,7 @@#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
@@ -60,10 +62,12 @@/* 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 */
@@ -90,8 +94,22 @@#define ADIS16607_ACCEL_Z_DELTA_MAX 4000#define ADIS16607_GYRO_DELTA_MAX 2600 +/* Sync modes */ +enum adis16607_sync_mode { +ADIS16607_SYNC_DEFAULT , +ADIS16607_SYNC_DIRECT , +ADIS16607_SYNC_SCALED , +}; + +struct adis16607_sync { +u16 sync_mode; +u16 min_rate; +u16 max_rate; +}; +struct adis16607_chip_info {const struct iio_chan_spec *channels; +const struct adis16607_sync *sync_mode;const char *name;u32 num_channels;u32 gyro_max_val;
@@ -103,6 +121,7 @@ struct adis16607_chip_info {u32 deltvel_max_val;u32 int_clk_hz;u16 max_dec; +u8 num_sync; };struct adis16607 {
@@ -110,6 +129,7 @@ struct adis16607 {const struct adis16607_chip_info *info;unsigned long clk_freq_mhz;u64 sample_period_ns; +u32 sync_mode;u16 fifo_watermark;/* Scratch buffer used for FIFO pop operations, see adis16607_fifo_pop() */ u8 fifo_buf[ADIS16607_BURST_CMD_SIZE +ADIS16607_FIFO_DATA_LEN ]__aligned(IIO_DMA_MINALIGN) ;
@@ -1004,6 +1024,12 @@ static const struct iio_info adis16607_info = { .hwfifo_set_watermark = adis16607_set_watermark, }; +static const struct adis16607_sync adis16607_sync_modes[] = { + {ADIS16607_SYNC_DEFAULT ,0 ,0 }, + {ADIS16607_SYNC_DIRECT ,401 ,8000 }, + {ADIS16607_SYNC_SCALED ,1 ,400 }, +}; +static const char *const adis16607_status_error_msgs[] = { [9 ] ="Boot Memory Failure" , [11 ] ="Power Supply Failure" ,
@@ -1048,6 +1074,8 @@ static const struct adis16607_chip_info adis16607_2_chip_info = { .deltvel_max_val = IIO_G_TO_M_S_2(40), .int_clk_hz = 8000, .max_dec = 65535, + .sync_mode = adis16607_sync_modes, + .num_sync = ARRAY_SIZE(adis16607_sync_modes), };static const struct adis16607_chip_info adis16607_3_chip_info = {
@@ -1063,17 +1091,96 @@ static const struct adis16607_chip_info adis16607_3_chip_info = { .deltvel_max_val = IIO_G_TO_M_S_2(40), .int_clk_hz = 8000, .max_dec = 65535, + .sync_mode = adis16607_sync_modes, + .num_sync = ARRAY_SIZE(adis16607_sync_modes), }; -/* -* No external clock sync support yet: always run on the internal clock. -* Default dec=0 after reset, so period = 1 / clk_freq_mhz. -*/ static int adis16607_config_clk (struct adis16607 *st) { - st->clk_freq_mhz = st->info->int_clk_hz *MILLI ; - st->sample_period_ns = -DIV_ROUND_CLOSEST_ULL ((u64 )NSEC_PER_SEC *MILLI , st->clk_freq_mhz); +struct device *dev = &st->adis.spi->dev; +const struct adis16607_sync *sync_mode_data =NULL ; +unsigned long ext_clk_hz =0 ; +u16 sync_scale =0 ; +u16 dec; +struct clk *clk; +int ret, i; + + clk =devm_clk_get_optional_enabled (dev,NULL ); +if (IS_ERR (clk)) +return PTR_ERR (clk); + +if (clk) { + ext_clk_hz =clk_get_rate (clk); + +for (i =1 ; i < st->info->num_sync; i++) { +if (ext_clk_hz >= st->info->sync_mode[i].min_rate && + ext_clk_hz <= st->info->sync_mode[i].max_rate) { + sync_mode_data = &st->info->sync_mode[i]; +break ; + } + } + +if (!sync_mode_data) +return dev_err_probe (dev, -EINVAL , +"Clk rate: %lu not in a valid range\n" , + ext_clk_hz); + + st->sync_mode = sync_mode_data->sync_mode; + }else { + st->sync_mode =ADIS16607_SYNC_DEFAULT ; + } + +/* +* Write the full desired sync state explicitly for every mode, +* rather than only when enabling non-default sync: USER_SYNC's +* documented reset default (0x0000, direct mode / scale 0) means +* this isn't fixing a known reset-state issue, but each mode +* establishing its own complete state here, instead of only +* touching bits conditionally, is simpler to reason about and +* doesn't depend on that default holding true. +*/ + ret =adis_update_bits_base (&st->adis,ADIS16607_REG_USER_GPIO_CFG , +ADIS16607_SYNC_GPIO_MASK , +FIELD_PREP (ADIS16607_SYNC_GPIO_MASK , + st->sync_mode !=ADIS16607_SYNC_DEFAULT ),2 ); +if (ret) +return ret; + +if (st->sync_mode ==ADIS16607_SYNC_SCALED ) + sync_scale =DIV_ROUND_CLOSEST (st->info->int_clk_hz, ext_clk_hz); + + ret =adis_write_reg_16 (&st->adis,ADIS16607_REG_USER_SYNC , + (st->sync_mode ==ADIS16607_SYNC_SCALED ) ? +ADIS16607_SYNC_MODE_MASK | sync_scale :0 ); +if (ret) +return ret; + +switch (st->sync_mode) { +case ADIS16607_SYNC_SCALED : +/* +* sync_scale is a rounded integer, so the hardware's actual +* effective rate is ext_clk_hz * sync_scale, not necessarily +* int_clk_hz - use the real value here so sample_period_ns (and +* therefore FIFO sample timestamps) don't drift from it. +*/ + st->clk_freq_mhz = (unsigned long )ext_clk_hz * sync_scale *1000 ; +break ; +case ADIS16607_SYNC_DIRECT : +/* DIRECT: external clock is the effective internal rate */ + st->clk_freq_mhz = ext_clk_hz *1000 ; +break ; +default : + st->clk_freq_mhz = (unsigned long )st->info->int_clk_hz *1000 ; +break ; + } + + ret =adis_read_reg_16 (&st->adis,ADIS16607_REG_DEC_RATE , &dec); +if (ret) +return ret; + + st->sample_period_ns =DIV_ROUND_CLOSEST_ULL ((u64 )NSEC_PER_SEC *1000ULL * (dec +1 ), + st->clk_freq_mhz); +return 0 ; }
Signature · 1 line
2.43.0
Jonathan Cameron
maintainerRe: [PATCH v4 7/8] iio: imu: adis16607: Add external clock sync support
Quoted 16 lines · On Fri, 23 Oct 2026 12:30:24 +0300 Radu Sabau via B4 Relay…
From: Radu Sabau <[email protected]>
Add support for an optional external clock (clocks property), selecting between
SYNC_DIRECTandSYNC_SCALEDmodes depending on the supplied frequency, with the internal 8 kHz clock used as the default when no clock is provided.Signed-off-by Radu Sabau <[email protected]>---
drivers/iio/imu/adis16607.c +0
-4-/* -* No external clock sync support yet: always run on the internal clock. -* Default dec=0 after reset, so period = 1 / clk_freq_mhz. -*/ static int adis16607_config_clk (struct adis16607 *st) {
drivers/iio/imu/adis16607.c static const struct adis16607_chip_info adis16607_3_chip_info = { · line 1106
Quoted 10 lines
drivers/iio/imu/adis16607.c +7
-3- st->clk_freq_mhz = st->info->int_clk_hz *MILLI ; - st->sample_period_ns = -DIV_ROUND_CLOSEST_ULL ((u64 )NSEC_PER_SEC *MILLI , st->clk_freq_mhz); +struct device *dev = &st->adis.spi->dev; +const struct adis16607_sync *sync_mode_data =NULL ; +unsigned long ext_clk_hz =0 ; +u16 sync_scale =0 ; +u16 dec; +struct clk *clk; +int ret, i;
where there is no other particular reason for ordering, reverse xmas tree preferred.
drivers/iio/imu/adis16607.c static const struct adis16607_chip_info adis16607_3_chip_info = { · line 1113
Quoted 7 lines
drivers/iio/imu/adis16607.c +7
-0+ + clk =devm_clk_get_optional_enabled (dev,NULL ); +if (IS_ERR (clk)) +return PTR_ERR (clk); + +if (clk) { + ext_clk_hz =clk_get_rate (clk);
Hmm. What if it is a controllable clock?
Review
Quoted 2 lines
(quoted diff) +2
-0+ + for (i = 1; i < st->info->num_sync; i++) {
for (unsigned int i = 1; ...
Quoted 72 lines
drivers/iio/imu/adis16607.c +68
-0+if (ext_clk_hz >= st->info->sync_mode[i].min_rate && + ext_clk_hz <= st->info->sync_mode[i].max_rate) { + sync_mode_data = &st->info->sync_mode[i]; +break ; + } + } + +if (!sync_mode_data) +return dev_err_probe (dev, -EINVAL , +"Clk rate: %lu not in a valid range\n" , + ext_clk_hz); + + st->sync_mode = sync_mode_data->sync_mode; + }else { + st->sync_mode =ADIS16607_SYNC_DEFAULT ; + } + +/* +* Write the full desired sync state explicitly for every mode, +* rather than only when enabling non-default sync: USER_SYNC's +* documented reset default (0x0000, direct mode / scale 0) means +* this isn't fixing a known reset-state issue, but each mode +* establishing its own complete state here, instead of only +* touching bits conditionally, is simpler to reason about and +* doesn't depend on that default holding true. +*/ + ret =adis_update_bits_base (&st->adis,ADIS16607_REG_USER_GPIO_CFG , +ADIS16607_SYNC_GPIO_MASK , +FIELD_PREP (ADIS16607_SYNC_GPIO_MASK , + st->sync_mode !=ADIS16607_SYNC_DEFAULT ),2 ); +if (ret) +return ret; + +if (st->sync_mode ==ADIS16607_SYNC_SCALED ) + sync_scale =DIV_ROUND_CLOSEST (st->info->int_clk_hz, ext_clk_hz); + + ret =adis_write_reg_16 (&st->adis,ADIS16607_REG_USER_SYNC , + (st->sync_mode ==ADIS16607_SYNC_SCALED ) ? +ADIS16607_SYNC_MODE_MASK | sync_scale :0 ); +if (ret) +return ret; + +switch (st->sync_mode) { +case ADIS16607_SYNC_SCALED : +/* +* sync_scale is a rounded integer, so the hardware's actual +* effective rate is ext_clk_hz * sync_scale, not necessarily +* int_clk_hz - use the real value here so sample_period_ns (and +* therefore FIFO sample timestamps) don't drift from it. +*/ + st->clk_freq_mhz = (unsigned long )ext_clk_hz * sync_scale *1000 ; +break ; +case ADIS16607_SYNC_DIRECT : +/* DIRECT: external clock is the effective internal rate */ + st->clk_freq_mhz = ext_clk_hz *1000 ; +break ; +default : + st->clk_freq_mhz = (unsigned long )st->info->int_clk_hz *1000 ; +break ; + } + + ret =adis_read_reg_16 (&st->adis,ADIS16607_REG_DEC_RATE , &dec); +if (ret) +return ret; + + st->sample_period_ns =DIV_ROUND_CLOSEST_ULL ((u64 )NSEC_PER_SEC *1000ULL * (dec +1 ), + st->clk_freq_mhz); +return 0 ; }
RE: [PATCH v4 7/8] iio: imu: adis16607: Add external clock sync support
Quoted 5 lines
-----Original Message-----
From: Jonathan Cameron <[email protected]>
Sent: Monday, October 26, 2026 2:12 AM
...
Quoted 9 lines
drivers/iio/imu/adis16607.c static const struct adis16607_chip_info adis16607_3_chip_info = { · line 1113
Quoted 7 lines
drivers/iio/imu/adis16607.c +7
-0+ + clk =devm_clk_get_optional_enabled (dev,NULL ); +if (IS_ERR (clk)) +return PTR_ERR (clk); + +if (clk) { + ext_clk_hz =clk_get_rate (clk);Hmm. What if it is a controllable clock?
Good point. What I'm thinking: add a clk_notifier (same pattern as adf4377_freq_change() in drivers/iio/frequency/adf4377.c) that re-runs the sync/scale setup on POST_RATE_CHANGE, under the same state_lock the trigger handler already uses, so it can't race with an in-flight FIFO drain. Splitting adis16607_config_clk() into a probe-time wrapper (gets the clk, registers the notifier if one's present) and the actual setup logic, so the notifier can re-run just the latter. A fixed-rate clock would simply never trigger it in practice, so this covers both cases with the same code.
Does that work for you?
Nuno Sá
maintainerRe: [PATCH v4 7/8] iio: imu: adis16607: Add external clock sync support
In reply to Radu Sabaudrivers/iio/imu/adis16607.c static const struct adis16607_chip_info adis16607_3_chip_info = { · line 1113
Quoted 12 lines · Radu Sabau
drivers/iio/imu/adis16607.c +0
-0@@ -1063,17 +1091,96 @@ static const struct adis16607_chip_info adis16607_3_chip_info = {[ ... skip 24 lines ... ]
drivers/iio/imu/adis16607.c +6
-0+ clk =devm_clk_get_optional_enabled (dev,NULL ); +if (IS_ERR (clk)) +return PTR_ERR (clk); + +if (clk) { + ext_clk_hz =clk_get_rate (clk);
The notifier might just be a lot of complication for something that I dunno we'll hit in practice. So, I would very much request exlusive rate for the clock if we want to care about this and deal with something more complex if we ever need.
FWIW, I guess you need to handle things on PRE_RATE_CHANGE. For example, if buffering is enabled we should deny the request!
drivers/iio/imu/adis16607.c static const struct adis16607_chip_info adis16607_3_chip_info = { · line 1166
Quoted 7 lines
[ ... skip 47 lines ... ]
drivers/iio/imu/adis16607.c +6
-0+* sync_scale is a rounded integer, so the hardware's actual +* effective rate is ext_clk_hz * sync_scale, not necessarily +* int_clk_hz - use the real value here so sample_period_ns (and +* therefore FIFO sample timestamps) don't drift from it. +*/ + st->clk_freq_mhz = (unsigned long )ext_clk_hz * sync_scale *1000 ;
On other devices, we actually control the scale when adjusting ODR. Here it looks like we keep it constant. Any reason for that? It does not give so much flexibility. See:
https://elixir.bootlin.com/linux/v7.3/source/drivers/iio/imu/adis16475.c#L336
Signature · 1 line
Nuno Sá <[email protected]>
PATCH v4 8/8 iio: imu: adis16607: Add calibration bias support for gyro/accel
In reply to Radu SabauAdd IIO_CHAN_INFO_CALIBBIAS support for the gyroscope and accelerometer axes, backed by the device's per-axis bias registers (XA/YA/ZA_BIAS, XG/YG/ZG_BIAS).
--- drivers/iio/imu/adis16607.c | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-)
drivers/iio/imu/adis16607.c +34 -1
@@ -55,6 +55,12 @@#define ADIS16607_REG_SOFT_RESET 0x36#define ADIS16607_REG_SELF_TEST 0x39#define ADIS16607_REG_DEC_RATE 0x3A +#define ADIS16607_REG_XA_BIAS 0x3B +#define ADIS16607_REG_YA_BIAS 0x3C +#define ADIS16607_REG_ZA_BIAS 0x3D +#define ADIS16607_REG_XG_BIAS 0x3E +#define ADIS16607_REG_YG_BIAS 0x3F +#define ADIS16607_REG_ZG_BIAS 0x40#define ADIS16607_REG_DIGITAL_STATUS 0x4E/* SPI Half-Duplex lock value */
@@ -153,6 +159,15 @@ enum { ADIS16607_SCAN_TEMP, }; +static const u32 adis16607_calib_bias[] = { + [ADIS16607_SCAN_ACCEL_X ] =ADIS16607_REG_XA_BIAS , + [ADIS16607_SCAN_ACCEL_Y ] =ADIS16607_REG_YA_BIAS , + [ADIS16607_SCAN_ACCEL_Z ] =ADIS16607_REG_ZA_BIAS , + [ADIS16607_SCAN_GYRO_X ] =ADIS16607_REG_XG_BIAS , + [ADIS16607_SCAN_GYRO_Y ] =ADIS16607_REG_YG_BIAS , + [ADIS16607_SCAN_GYRO_Z ] =ADIS16607_REG_ZG_BIAS , +}; +/* * SPI Half-Duplex read operation for ADIS16607. * Protocol:
@@ -863,6 +878,7 @@ static int adis16607_read_raw(struct iio_dev *indio_dev, int *val, int *val2, long info) { struct adis16607 *st = iio_priv(indio_dev); +const int idx = chan->scan_index;int ret;u32 tmp;
@@ -900,6 +916,16 @@ static int adis16607_read_raw(struct iio_dev *indio_dev, *val =5000 ;return IIO_VAL_INT ; +case IIO_CHAN_INFO_CALIBBIAS : { +u16 tmp16; + + ret =adis_read_reg_16 (&st->adis, adis16607_calib_bias[idx], &tmp16); +if (ret) +return ret; + *val =sign_extend32 (tmp16,15 ); +return IIO_VAL_INT ; + } +case IIO_CHAN_INFO_SAMP_FREQ : ret =adis16607_get_freq (st, &tmp);if (ret)
@@ -918,6 +944,7 @@ static int adis16607_write_raw(struct iio_dev *indio_dev, int val, int val2, long info) { struct adis16607 *st = iio_priv(indio_dev); +const int idx = chan->scan_index;u32 tmp;switch (info) {
@@ -925,6 +952,11 @@ static int adis16607_write_raw(struct iio_dev *indio_dev, tmp = val *1000 + val2 /1000 ;return adis16607_set_freq (st, tmp); +case IIO_CHAN_INFO_CALIBBIAS : +if (val <S16_MIN || val >S16_MAX ) +return -EINVAL ; +return adis_write_reg_16 (&st->adis, adis16607_calib_bias[idx], val); +default :return -EINVAL ; }
@@ -934,7 +966,8 @@ static int adis16607_write_raw(struct iio_dev *indio_dev, .type = (_type), \ .modified = 1, \ .channel2 = (_mod), \ - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ + .info_mask_separate =BIT (IIO_CHAN_INFO_RAW ) | \ + BIT(IIO_CHAN_INFO_CALIBBIAS), \ .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), \ .address = (_address), \
Signature · 1 line
2.43.0
Jonathan Cameron
maintainerRe: [PATCH v4 8/8] iio: imu: adis16607: Add calibration bias support for gyro/accel
Quoted 7 lines · On Fri, 23 Oct 2026 12:30:25 +0300 Radu Sabau via B4 Relay…
From: Radu Sabau <[email protected]>
Add
IIO_CHAN_INFO_CALIBBIASsupport for the gyroscope and accelerometer axes, backed by the device's per-axis bias registers (XA/YA/ZA_BIAS, XG/YG/ZG_BIAS).Signed-off-by Radu Sabau <[email protected]>
I'd missed the use of scan_index in here. That seems like very fragile coding to me. Moving over to address is going to require changes a few patches back.
drivers/iio/imu/adis16607.c static int adis16607_read_raw(struct iio_dev *indio_dev, · line 881
Quoted 9 lines
drivers/iio/imu/adis16607.c +2
-0+/* * SPI Half-Duplex read operation for ADIS16607. * Protocol: @@ -863,6 +878,7 @@ static int adis16607_read_raw(struct iio_dev *indio_dev, int *val, int *val2, long info) { struct adis16607 *st = iio_priv(indio_dev); +const int idx = chan->scan_index;
As below. This to me is hurting readability a little. Using scan_index for this is a bit fragile anyway as those can be changed by people expecting them to only about buffered capture. This should be using address and that may well mean you need that to become a lookup into an array of multiple register addresses needed for a given channel rather than directly to one register as currently.
Quoted 21 lines
drivers/iio/imu/adis16607.c +10
-0int ret;u32 tmp;@@ -900,6 +916,16 @@ static int adis16607_read_raw(struct iio_dev *indio_dev, *val =5000 ;return IIO_VAL_INT ; +case IIO_CHAN_INFO_CALIBBIAS : { +u16 tmp16; + + ret =adis_read_reg_16 (&st->adis, adis16607_calib_bias[idx], &tmp16); +if (ret) +return ret; + *val =sign_extend32 (tmp16,15 ); +return IIO_VAL_INT ; + } +case IIO_CHAN_INFO_SAMP_FREQ : ret =adis16607_get_freq (st, &tmp);if (ret)
drivers/iio/imu/adis16607.c static int adis16607_write_raw(struct iio_dev *indio_dev, · line 947
Quoted 4 lines
drivers/iio/imu/adis16607.c +1
-0@@ -918,6 +944,7 @@ static int adis16607_write_raw(struct iio_dev *indio_dev, int val, int val2, long info) { struct adis16607 *st = iio_priv(indio_dev); +const int idx = chan->scan_index;
I'd just go long on the line that uses this or at least push declaring it down to the case statement that uses it.
Quoted 26 lines
drivers/iio/imu/adis16607.c +7
-1u32 tmp;switch (info) {@@ -925,6 +952,11 @@ static int adis16607_write_raw(struct iio_dev *indio_dev, tmp = val *1000 + val2 /1000 ;return adis16607_set_freq (st, tmp); +case IIO_CHAN_INFO_CALIBBIAS : +if (val <S16_MIN || val >S16_MAX ) +return -EINVAL ; +return adis_write_reg_16 (&st->adis, adis16607_calib_bias[idx], val); +default :return -EINVAL ; }@@ -934,7 +966,8 @@ static int adis16607_write_raw(struct iio_dev *indio_dev, .type = (_type), \ .modified = 1, \ .channel2 = (_mod), \ - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ + .info_mask_separate =BIT (IIO_CHAN_INFO_RAW ) | \ + BIT(IIO_CHAN_INFO_CALIBBIAS), \ .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), \ .address = (_address), \