Skip to contentSkip to conversation

Add Invensense ICM42607

PATCH Superseded Chris Morgan 8 participants 30 messages Jul 13 – Jul 23

Subsystems (4)

v16 of 21 Superseded Latest is v21 →

lore
Share & tools
lore
#0 lore raw

v16 cover Add Invensense ICM42607

From: Chris Morgan <[email protected]>

Add support for the ICM42607 IMU. This sensor shares the same functionality but a different register layout with the existing ICM42600.

This driver should work with the ICM42607 and ICM42607P over both I2C and SPI, however only the ICM42607P over I2C could be tested.

Changes Since V1:
- Instead of creating a new driver, merged with the existing inv_icm42600 driver. This necessitated adding some code to the existing driver to permit using a different register layout for the same functionality.
- Split changes up a bit more to decrease the size of the individual patches. Note that patch 0004 is still pretty hefty; if I need to split further I may need to create some temporary stub functions.
- Used guard() and PM_RUNTIME_ACQUIRE_AUTOSUSPEND() on the new functions per Jonathan's recommendations.

Changes Since V2:
- Went back to using a new driver on advice from Invensense engineer.
- Further split changes up into smaller chunks of functionality. Note still that the largest patch is approximately 900 lines, and that while the driver compiles cleanly at each commit it is not able to drive the hardware until the commit that adds the Interrupt (as it also adds the Makefile).
- Change the error to a warning when the devicetree binding does not match the hardware ID.
- Dropped the ack on the devicetree bindings, as I am creating a new file (for a new driver) instead of modifying the existing one.

Changes Since V3:
- Numerous small fixes (too many to list here). Thank you to everyone who provided feedback.
- Split power management additions into an additional commit to break things up further.
- Consolidated devicetree documentation in existing invensense,icm42600.yaml file.
- Removed most of the FIELD_PREP from header file to c files to make code easier to read.
- Changed scale values to 2D arrays for Gyro and Accelerometer.
- Removed IIO_CHAN_INFO_CALIBBIAS attribute.

Changes Since V4:
- Additional numerous small fixes, thank you again for all the feedback.
- Dropped power control API and instead run device in low noise mode.
- Split devicetree bindings into two distinct changes.
- Reordered adding of enums and structs to main header file so that they are only brought in when needed.
- Stopped using enum for driver data and instead am using pointer to device specific driver data.

Changes Since V5:
- Corrected use of "dev_warn_probe" to just "dev_warn".
- Fixed some return scenarios which would unconditionally return 0 when an error was present.
- Corrected use of max() to min() for bounds checking. max() was incorrect.
- Fixed using "st->conf.accel.odr" in the gyroscope function. It should have been "st->conf.gyro.odr" which it now is.
- Additional small fixes suggested by "sashiko.dev".
- Added a regmap cache. I used the datasheet to try and determine which registers might change without explicit writes.

Changes Since V6:
- Corrected additional errors identified by sashiko.dev, mostly fixing potential deadlocks, missing calls for pm runtime, and potential overflow issues.

Changes Since V7:
- Dropped Wake on Movement patches, since some of the functionality was only available for a device on which I cannot test.
- Dropped support for SPI 3-Wire mode, since it complicated the bus setup (and I lack the hardware to test such features anyway).
- Fixed a few additional bugs identified by sashiko.dev bot.

Changes Since V8:
- Added back IRQ dropped accidentally when dropping wake on movement patches.
- Dropped "Reviewed-By" tag on patch 2 because of substantial changes made to devicetree binding documentation.
- Additional small fixes as suggested.

Changes Since V9:
- Removed interrupts (and buffers) from the driver. I previously was unable to detect deadlocks because it turns out my IRQ was not even wired correctly in my device.
- Updated devicetree binding commits to make interrupts optional for users of the icm42607 driver.

Changes Since V10:
- Explicitly specified enum values in header file.
- Removed additional dead code for buffer handling.
- Cleaned up headers.
- Added additional locks as requested by sashiko.dev bot.

Changes Since V11:
- Since driver has shrunk in size considerably, moved i2c bits into first code commit. This ensures that the very first commit with code can now be compiled. The commit after that adds SPI support as it was in the previous versions.
- Used pahole to optimize inv_icm42607_state. Reordering elements reduced size in memory from 384 bytes to 256 bytes.
- Added a map of all readable registers and all writeable registers according to the datasheet.
- Added back some missing headers pointed out by the maintainers.
- Added FIELD_PREP in a few more places to make the code more obvious on what it's doing.
- Added a comment to the power management code to note that temperature sensor being enabled doesn't matter as the clocks are off by default when the gyro and accel channels are off.
- Removed iio_device_claim_direct() calls since it was no longer needed.
- Fixed shared_by_all attributes for temperature sensor.
- Additional miscellanous fixes as requested.

Changes Since V12:
- Removed aligned buffer from inv_icm42607_state struct as we do not currently have the need for it.
- Corrected the order of the odr values in the accel and gyro files as the values were out of order (the place in the array corresponds to the register value).
- Stopped setting the clock value depending upon the temp config. The datasheet advised to keep using the default value.
- Corrected logic when changing between states. We only need to pause when a sensor changes from off to an on state or when the gyro changes from an on state to off.
- Added missing includes for several files.

Changes Since V13:
- Refactored inv_icm42607_set_accel_conf() and inv_icm42607_set_gyro_conf() into a single function.
- Refactored inv_icm42607_accel_read_sensor() and inv_icm42607_gyro_read_sensor() into a single function.
- Merged inv_icm42607_set_temp_conf() into initial init function since it only really needs to be called once.
- Saved adding temp sensor for last and updated inv_icm42607_temp_read() to either confirm other sensors are already enabled or enable the accelerometer so it can get a reading.
- Updated inv_icm42607_set_pwr_mgmt0() so that it does not update the sensor mode and forcibly keep the sensor enabled.
- Added inv_icm42607_temp_filter_bw enums since it appears to use different values than the accel or gyro sensor.
- Set the temp startup time from 77ms to 77us, as I previously misread the datasheet.
- Additional minor fixes.

Changes Since V14:
- Added IIO_BE for temp sensor.
- Switched from ktime_get_real() to ktime_get().

Changes Since V15:
- Removed interrupts from required property per note from Jonathan. As a result of this change I've also removed one of Krzysztof's Reviewed-By tags as this change probably requires further review from them.
- Corrected a comment about reserved values from 0-5 to 0-4.
- Reordered some operations so that only runtime power management turns off the sensors now. This removes the "ping-pong" effect when switching between the accel and gyro sensor, at the expense of leaving either the accel or gyro sensor enabled until runtime power management turns it off.
- Fixed the shared frequency value not being available for the temp sensor.

Chris Morgan (10):
dt-bindings: iio: imu: icm42600: Add mount-matrix
dt-bindings: iio: imu: icm42600: Remove interrupts from required
dt-bindings: iio: imu: icm42600: Add icm42607
iio: imu: inv_icm42607: Add inv_icm42607 Core Driver
iio: imu: inv_icm42607: Add SPI For icm42607
iio: imu: inv_icm42607: Add PM support for icm42607
iio: imu: inv_icm42607: Add Accelerometer for icm42607
iio: imu: inv_icm42607: Add Gyroscope to icm42607
iio: imu: inv_icm42607: Add Temp Support in icm42607
arm64: dts: rockchip: Add icm42607p IMU for RG-DS

 .../bindings/iio/imu/invensense,icm42600.yaml |   5 +-
 .../dts/rockchip/rk3568-anbernic-rg-ds.dts    |   8 +-
 drivers/iio/imu/Kconfig                       |   1 +
 drivers/iio/imu/Makefile                      |   1 +
 drivers/iio/imu/inv_icm42607/Kconfig          |  30 +
 drivers/iio/imu/inv_icm42607/Makefile         |  13 +
 drivers/iio/imu/inv_icm42607/inv_icm42607.h   | 428 ++++++++++++
 .../iio/imu/inv_icm42607/inv_icm42607_accel.c | 308 +++++++++
 .../iio/imu/inv_icm42607/inv_icm42607_core.c  | 643 ++++++++++++++++++
 .../iio/imu/inv_icm42607/inv_icm42607_gyro.c  | 305 +++++++++
 .../iio/imu/inv_icm42607/inv_icm42607_i2c.c   |  97 +++
 .../iio/imu/inv_icm42607/inv_icm42607_spi.c   | 108 +++
 .../iio/imu/inv_icm42607/inv_icm42607_temp.c  |  98 +++
 .../iio/imu/inv_icm42607/inv_icm42607_temp.h  |  38 ++
 14 files changed, 2081 insertions(+), 2 deletions(-)
 create mode 100644 drivers/iio/imu/inv_icm42607/Kconfig
 create mode 100644 drivers/iio/imu/inv_icm42607/Makefile
 create mode 100644 drivers/iio/imu/inv_icm42607/inv_icm42607.h
 create mode 100644 drivers/iio/imu/inv_icm42607/inv_icm42607_accel.c
 create mode 100644 drivers/iio/imu/inv_icm42607/inv_icm42607_core.c
 create mode 100644 drivers/iio/imu/inv_icm42607/inv_icm42607_gyro.c
 create mode 100644 drivers/iio/imu/inv_icm42607/inv_icm42607_i2c.c
 create mode 100644 drivers/iio/imu/inv_icm42607/inv_icm42607_spi.c
 create mode 100644 drivers/iio/imu/inv_icm42607/inv_icm42607_temp.c
 create mode 100644 drivers/iio/imu/inv_icm42607/inv_icm42607_temp.h
Signature · 1 line
2.43.0
#1 lore raw

PATCH v16 1/10 dt-bindings: iio: imu: icm42600: Add mount-matrix

From: Chris Morgan <[email protected]>

Add mount-matrix attribute to schema. This attribute has been supported since the first revision of this driver, but was not documented.

---
 .../devicetree/bindings/iio/imu/invensense,icm42600.yaml        | 2 ++
 1 file changed, 2 insertions(+)
Documentation/devicetree/bindings/iio/imu/invensense,icm42600.yaml +2 -0
index 119e28a833fd..9b2af104f186 100644
@@ -53,6 +53,8 @@ properties:
   drive-open-drain:
     type: boolean
 
+  mount-matrix: true
+
   vdd-supply:
     description: Regulator that provides power to the sensor
 
Signature · 1 line
2.43.0
#2 lore raw

PATCH v16 2/10 dt-bindings: iio: imu: icm42600: Remove interrupts from required

In reply to Chris Morgan

From: Chris Morgan <[email protected]>

Interrupts are almost never required for IIO devices per upstream maintainers. Remove interrupt as a required parameter for the devicetree binding.

---
 .../devicetree/bindings/iio/imu/invensense,icm42600.yaml         | 1 -
 1 file changed, 1 deletion(-)
Documentation/devicetree/bindings/iio/imu/invensense,icm42600.yaml +0 -1
index 9b2af104f186..f6f97ea03038 100644
@@ -67,7 +67,6 @@ properties:
 required:
   - compatible
   - reg
-  - interrupts
 
 allOf:
   - $ref: /schemas/spi/spi-peripheral-props.yaml#
Signature · 1 line
2.43.0
#3 lore raw

Re: [PATCH v16 02/10] dt-bindings: iio: imu: icm42600: Remove interrupts from required

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] The device tree binding removes the `interrupts` requirement, making it optional, but the…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The device tree binding removes the interrupts requirement, making it optional, but the associated kernel driver still unconditionally requires an interrupt to probe successfully. The driver fetches the interrupt via fwnode_irq_get_byname() or fwnode_irq_get() and aborts the probe with dev_err_probe() if none is found. Relaxing the binding allows device trees to omit the interrupt property and pass schema validation, but such configurations will unconditionally fail at runtime because the driver currently lacks support for polling mode. --

--- Patch [2]: [PATCH v16 02/10] dt-bindings: iio: imu: icm42600: Remove interrupts from required --- commit 161a6f84f50962ef8b7d4035dc0e3aa2eb3afb64
Author: Chris Morgan <[email protected]>

dt-bindings: iio: imu: icm42600: Remove interrupts from required

This commit removes the interrupts requirement from the icm42600 device tree binding schema. The commit message notes that interrupts are rarely required for IIO devices.

Documentation/devicetree/bindings/iio/imu/invensense,icm42600.yaml properties: · line 70

Quoted 9 lines
Documentation/devicetree/bindings/iio/imu/invensense,icm42600.yaml +0 -1
index 9b2af104f186d..f6f97ea030389 100644
@@ -67,7 +67,6 @@ properties:
 required:
   - compatible
   - reg
-  - interrupts

[Severity: Medium]
Does this change introduce a mismatch with the driver implementation?

If a device tree omits the interrupts property, it will now pass schema validation, but it appears the driver will still fail to probe.

Looking at inv_icm42600_core_probe() in
drivers/iio/imu/inv_icm42600/inv_icm42600_core.c:

    if (irq < 0)
        return dev_err_probe(dev, irq, "error missing INT1 interrupt\n");

Will the driver need to be updated to support a polling mode, or should the interrupt remain required until the driver can support operating without one?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#4 lore raw

Re: [PATCH v16 02/10] dt-bindings: iio: imu: icm42600: Remove interrupts from required

In reply to Chris Morgan
Quoted 5 lines · Chris Morgan

From: Chris Morgan <[email protected]>

Interrupts are almost never required for IIO devices per upstream maintainers. Remove interrupt as a required parameter for the devicetree binding.

That's an odd statement. We do require interrupts when the hardware requires them. We do not require interrupts, not because we have such policy, but because hardware does not require them.

Plus, we do require interrupts when software implementing ABI requires them.

Above commit msg is simply inaccurate and misleading. Instead, please use actual hardware arguments or how ABI is actually used. You must not introduce changes to ABI just "because" while for example making that ABI conflicting with existing implementation.

Best regards,
Krzysztof

#5 lore raw

Re: [PATCH v16 02/10] dt-bindings: iio: imu: icm42600: Remove interrupts from required

Quoted 11 lines · Krzysztof Kozlowski
Quoted 5 lines · Chris Morgan

From: Chris Morgan <[email protected]>

Interrupts are almost never required for IIO devices per upstream maintainers. Remove interrupt as a required parameter for the devicetree binding.

That's an odd statement. We do require interrupts when the hardware requires them. We do not require interrupts, not because we have such policy, but because hardware does not require them.

Quoted 7 lines

Plus, we do require interrupts when software implementing ABI requires them.

Above commit msg is simply inaccurate and misleading. Instead, please use actual hardware arguments or how ABI is actually used. You must not introduce changes to ABI just "because" while for example making that ABI conflicting with existing implementation.

I will defer then to Jonathan on the specifics of this, but from what I can tell:

1) The icm42600 devices don't need an interrupt for operation other than for buffered mode or wake on movement. One-shot should work without it.

2) The existing icm42600 driver does require an interrupt however, and refuses to bind without it. The driver could in theory be modified to not require an interrupt though and skip using buffered mode and WoM when no interrupt is present; however I don't plan on making these changes at this time.

3) The new icm42607 driver I'm trying to upstream does not use an interrupt, because on my current test device it's not even wired up. On future devices that I have with this chip I may pursue using an interrupt, but it will never be required.

So should I go back to requiring the interrupt for all devices except for the new driver then?

Thank you,
Chris

Quoted 4 lines

Best regards,
Krzysztof

#6 lore raw

Re: [PATCH v16 02/10] dt-bindings: iio: imu: icm42600: Remove interrupts from required

Quoted 33 lines · Chris Morgan
Quoted 11 lines · Krzysztof Kozlowski
Quoted 5 lines · Chris Morgan

From: Chris Morgan <[email protected]>

Interrupts are almost never required for IIO devices per upstream maintainers. Remove interrupt as a required parameter for the devicetree binding.

That's an odd statement. We do require interrupts when the hardware requires them. We do not require interrupts, not because we have such policy, but because hardware does not require them.

Quoted 7 lines

Plus, we do require interrupts when software implementing ABI requires them.

Above commit msg is simply inaccurate and misleading. Instead, please use actual hardware arguments or how ABI is actually used. You must not introduce changes to ABI just "because" while for example making that ABI conflicting with existing implementation.

I will defer then to Jonathan on the specifics of this, but from what I can tell:

1) The icm42600 devices don't need an interrupt for operation other than for buffered mode or wake on movement. One-shot should work without it.

2) The existing icm42600 driver does require an interrupt however, and refuses to bind without it. The driver could in theory be modified to not require an interrupt though and skip using buffered mode and WoM when no interrupt is present; however I don't plan on making these changes at this time.

Quoted 7 lines

3) The new icm42607 driver I'm trying to upstream does not use an interrupt, because on my current test device it's not even wired up. On future devices that I have with this chip I may pursue using an interrupt, but it will never be required.

So should I go back to requiring the interrupt for all devices except for the new driver then?

You mentioned two drivers, I don't know how does this relate to them. In any case your commit msg is inaccurate and not a correct reason to make a change.

Best regards,
Krzysztof

#7 lore raw

Re: [PATCH v16 02/10] dt-bindings: iio: imu: icm42600: Remove interrupts from required

Quoted 42 lines · Krzysztof Kozlowski
Quoted 33 lines · Chris Morgan
Quoted 11 lines · Krzysztof Kozlowski
Quoted 5 lines · Chris Morgan

From: Chris Morgan <[email protected]>

Interrupts are almost never required for IIO devices per upstream maintainers. Remove interrupt as a required parameter for the devicetree binding.

That's an odd statement. We do require interrupts when the hardware requires them. We do not require interrupts, not because we have such policy, but because hardware does not require them.

Quoted 7 lines

Plus, we do require interrupts when software implementing ABI requires them.

Above commit msg is simply inaccurate and misleading. Instead, please use actual hardware arguments or how ABI is actually used. You must not introduce changes to ABI just "because" while for example making that ABI conflicting with existing implementation.

I will defer then to Jonathan on the specifics of this, but from what I can tell:

1) The icm42600 devices don't need an interrupt for operation other than for buffered mode or wake on movement. One-shot should work without it.

2) The existing icm42600 driver does require an interrupt however, and refuses to bind without it. The driver could in theory be modified to not require an interrupt though and skip using buffered mode and WoM when no interrupt is present; however I don't plan on making these changes at this time.

Quoted 7 lines

3) The new icm42607 driver I'm trying to upstream does not use an interrupt, because on my current test device it's not even wired up. On future devices that I have with this chip I may pursue using an interrupt, but it will never be required.

So should I go back to requiring the interrupt for all devices except for the new driver then?

Quoted 6 lines

You mentioned two drivers, I don't know how does this relate to them. In any case your commit msg is inaccurate and not a correct reason to make a change.

Best regards,
Krzysztof

I'm confused, so again should I just go back to the way things were?

This binding is to describe the hardware for devices using two distinct drivers, the inv_icm42600 and the new (that I am trying to finish) inv_icm42607 driver. The hardware requires an interrupt if you want to use features such as wake-on-motion or hardware buffers. The existing driver inv_icm42600 always assumes an interrupt is present and thus fails to probe if one is not (making it a "requirement"). The new driver I'm writing does not use the interrupt, because I don't have one.

I'm thinking I'll just go back to the way it was previously, unless Jonathan disagrees. The interrupt will be listed as required for all devices using the inv_icm42600 driver, and not required for devices using the inv_icm42607 driver.

Thank you.

#8 lore raw

Re: [PATCH v16 02/10] dt-bindings: iio: imu: icm42600: Remove interrupts from required

Quoted 52 lines · On Wed, 15 Jul 2026 15:34:53 -0500 Chris Morgan <[email protected]> wrote:
Quoted 42 lines · Krzysztof Kozlowski
Quoted 33 lines · Chris Morgan
Quoted 11 lines · Krzysztof Kozlowski
Quoted 5 lines · Chris Morgan

From: Chris Morgan <[email protected]>

Interrupts are almost never required for IIO devices per upstream maintainers. Remove interrupt as a required parameter for the devicetree binding.

That's an odd statement. We do require interrupts when the hardware requires them. We do not require interrupts, not because we have such policy, but because hardware does not require them.

Quoted 7 lines

Plus, we do require interrupts when software implementing ABI requires them.

Above commit msg is simply inaccurate and misleading. Instead, please use actual hardware arguments or how ABI is actually used. You must not introduce changes to ABI just "because" while for example making that ABI conflicting with existing implementation.

I will defer then to Jonathan on the specifics of this, but from what I can tell:

1) The icm42600 devices don't need an interrupt for operation other than for buffered mode or wake on movement. One-shot should work without it.

2) The existing icm42600 driver does require an interrupt however, and refuses to bind without it. The driver could in theory be modified to not require an interrupt though and skip using buffered mode and WoM when no interrupt is present; however I don't plan on making these changes at this time.

Quoted 7 lines

3) The new icm42607 driver I'm trying to upstream does not use an interrupt, because on my current test device it's not even wired up. On future devices that I have with this chip I may pursue using an interrupt, but it will never be required.

So should I go back to requiring the interrupt for all devices except for the new driver then?

Quoted 6 lines

You mentioned two drivers, I don't know how does this relate to them. In any case your commit msg is inaccurate and not a correct reason to make a change.

Best regards,
Krzysztof

I'm confused, so again should I just go back to the way things were?

Quoted 8 lines

This binding is to describe the hardware for devices using two distinct drivers, the inv_icm42600 and the new (that I am trying to finish) inv_icm42607 driver. The hardware requires an interrupt if you want to use features such as wake-on-motion or hardware buffers. The existing driver inv_icm42600 always assumes an interrupt is present and thus fails to probe if one is not (making it a "requirement"). The new driver I'm writing does not use the interrupt, because I don't have one.

For dt-bindings, look at it from the question of 'is the hardware useful without this interrupt?' Answer is yes for vast majority of sensors as we can either reduce features but still have some useful ones, or use another approach such as polling a ready flag to replace doing it with an interrupt. It is very common for boards to come out where none of the interrupts are wired.

The only time I've seen that they are actually required for IIO stuff is for very simple devices where the interrupt is the data - e.g. stand alone threshold detectors with no ADC like functionality.

All this is independent of the driver working without the interrupt. It is fully allowed to refuse to probe because it relies on something optional in the DT-binding.

Jonathan

Quoted 8 lines

I'm thinking I'll just go back to the way it was previously, unless Jonathan disagrees. The interrupt will be listed as required for all devices using the inv_icm42600 driver, and not required for devices using the inv_icm42607 driver.

Thank you.

#9 lore raw

Re: [PATCH v16 02/10] dt-bindings: iio: imu: icm42600: Remove interrupts from required

Quoted 75 lines · Jonathan Cameron
Quoted 52 lines · On Wed, 15 Jul 2026 15:34:53 -0500 Chris Morgan <[email protected]> wrote:
Quoted 42 lines · Krzysztof Kozlowski
Quoted 33 lines · Chris Morgan
Quoted 11 lines · Krzysztof Kozlowski
Quoted 5 lines · Chris Morgan

From: Chris Morgan <[email protected]>

Interrupts are almost never required for IIO devices per upstream maintainers. Remove interrupt as a required parameter for the devicetree binding.

That's an odd statement. We do require interrupts when the hardware requires them. We do not require interrupts, not because we have such policy, but because hardware does not require them.

Quoted 7 lines

Plus, we do require interrupts when software implementing ABI requires them.

Above commit msg is simply inaccurate and misleading. Instead, please use actual hardware arguments or how ABI is actually used. You must not introduce changes to ABI just "because" while for example making that ABI conflicting with existing implementation.

I will defer then to Jonathan on the specifics of this, but from what I can tell:

1) The icm42600 devices don't need an interrupt for operation other than for buffered mode or wake on movement. One-shot should work without it.

2) The existing icm42600 driver does require an interrupt however, and refuses to bind without it. The driver could in theory be modified to not require an interrupt though and skip using buffered mode and WoM when no interrupt is present; however I don't plan on making these changes at this time.

Quoted 7 lines

3) The new icm42607 driver I'm trying to upstream does not use an interrupt, because on my current test device it's not even wired up. On future devices that I have with this chip I may pursue using an interrupt, but it will never be required.

So should I go back to requiring the interrupt for all devices except for the new driver then?

Quoted 6 lines

You mentioned two drivers, I don't know how does this relate to them. In any case your commit msg is inaccurate and not a correct reason to make a change.

Best regards,
Krzysztof

I'm confused, so again should I just go back to the way things were?

Quoted 8 lines

This binding is to describe the hardware for devices using two distinct drivers, the inv_icm42600 and the new (that I am trying to finish) inv_icm42607 driver. The hardware requires an interrupt if you want to use features such as wake-on-motion or hardware buffers. The existing driver inv_icm42600 always assumes an interrupt is present and thus fails to probe if one is not (making it a "requirement"). The new driver I'm writing does not use the interrupt, because I don't have one.

For dt-bindings, look at it from the question of 'is the hardware useful without this interrupt?' Answer is yes for vast majority of sensors as we can either reduce features but still have some useful ones, or use another approach such as polling a ready flag to replace doing it with an interrupt. It is very common for boards to come out where none of the interrupts are wired.

The only time I've seen that they are actually required for IIO stuff is for very simple devices where the interrupt is the data - e.g. stand alone threshold detectors with no ADC like functionality.

Quoted 6 lines

All this is independent of the driver working without the interrupt. It is fully allowed to refuse to probe because it relies on something optional in the DT-binding.

Jonathan

At this point (if it's okay with you) I'll just make sure the interrupt is not required for the new chips supported, as the distinction between whether the hardware needs it versus the driver is a bit lost on me; however for now the driver will fail on all the older chips if the interrupt isn't present.

Thank you,
Chris

Quoted 10 lines
Quoted 9 lines

I'm thinking I'll just go back to the way it was previously, unless Jonathan disagrees. The interrupt will be listed as required for all devices using the inv_icm42600 driver, and not required for devices using the inv_icm42607 driver.

Thank you.

maintainer
#10 lore raw

Re: [PATCH v16 02/10] dt-bindings: iio: imu: icm42600: Remove interrupts from required

Quoted 80 lines · On Mon, 20 Jul 2026 12:16:46 -0500 Chris Morgan <[email protected]> wrote:
Quoted 79 lines · Jonathan Cameron
Quoted 52 lines · On Wed, 15 Jul 2026 15:34:53 -0500 Chris Morgan <[email protected]> wrote:
Quoted 42 lines · Krzysztof Kozlowski
Quoted 33 lines · Chris Morgan
Quoted 11 lines · Krzysztof Kozlowski
Quoted 5 lines · Chris Morgan

From: Chris Morgan <[email protected]>

Interrupts are almost never required for IIO devices per upstream maintainers. Remove interrupt as a required parameter for the devicetree binding.

That's an odd statement. We do require interrupts when the hardware requires them. We do not require interrupts, not because we have such policy, but because hardware does not require them.

Quoted 7 lines

Plus, we do require interrupts when software implementing ABI requires them.

Above commit msg is simply inaccurate and misleading. Instead, please use actual hardware arguments or how ABI is actually used. You must not introduce changes to ABI just "because" while for example making that ABI conflicting with existing implementation.

I will defer then to Jonathan on the specifics of this, but from what I can tell:

1) The icm42600 devices don't need an interrupt for operation other than for buffered mode or wake on movement. One-shot should work without it.

2) The existing icm42600 driver does require an interrupt however, and refuses to bind without it. The driver could in theory be modified to not require an interrupt though and skip using buffered mode and WoM when no interrupt is present; however I don't plan on making these changes at this time.

Quoted 7 lines

3) The new icm42607 driver I'm trying to upstream does not use an interrupt, because on my current test device it's not even wired up. On future devices that I have with this chip I may pursue using an interrupt, but it will never be required.

So should I go back to requiring the interrupt for all devices except for the new driver then?

Quoted 6 lines

You mentioned two drivers, I don't know how does this relate to them. In any case your commit msg is inaccurate and not a correct reason to make a change.

Best regards,
Krzysztof

I'm confused, so again should I just go back to the way things were?

Quoted 8 lines

This binding is to describe the hardware for devices using two distinct drivers, the inv_icm42600 and the new (that I am trying to finish) inv_icm42607 driver. The hardware requires an interrupt if you want to use features such as wake-on-motion or hardware buffers. The existing driver inv_icm42600 always assumes an interrupt is present and thus fails to probe if one is not (making it a "requirement"). The new driver I'm writing does not use the interrupt, because I don't have one.

For dt-bindings, look at it from the question of 'is the hardware useful without this interrupt?' Answer is yes for vast majority of sensors as we can either reduce features but still have some useful ones, or use another approach such as polling a ready flag to replace doing it with an interrupt. It is very common for boards to come out where none of the interrupts are wired.

The only time I've seen that they are actually required for IIO stuff is for very simple devices where the interrupt is the data - e.g. stand alone threshold detectors with no ADC like functionality.

All this is independent of the driver working without the interrupt. It is fully allowed to refuse to probe because it relies on something optional in the DT-binding.

Quoted 8 lines
Quoted 2 lines

Jonathan

At this point (if it's okay with you) I'll just make sure the interrupt is not required for the new chips supported, as the distinction between whether the hardware needs it versus the driver is a bit lost on me; however for now the driver will fail on all the older chips if the interrupt isn't present.

Ok. We can leave relaxing the requirement for the older devices for now.

Jonathan

Quoted 15 lines

Thank you,
Chris

Quoted 10 lines
Quoted 9 lines

I'm thinking I'll just go back to the way it was previously, unless Jonathan disagrees. The interrupt will be listed as required for all devices using the inv_icm42600 driver, and not required for devices using the inv_icm42607 driver.

Thank you.

#11 lore raw

PATCH v16 3/10 dt-bindings: iio: imu: icm42600: Add icm42607

In reply to Chris Morgan

From: Chris Morgan <[email protected]>

Add the ICM42607 and ICM42607P inertial measurement unit.

This device is functionally very similar to the icm42600 series with a very different register layout.

---
 .../devicetree/bindings/iio/imu/invensense,icm42600.yaml        | 2 ++
 1 file changed, 2 insertions(+)
Documentation/devicetree/bindings/iio/imu/invensense,icm42600.yaml +2 -0
index f6f97ea03038..d62aa4f285cc 100644
@@ -30,6 +30,8 @@ properties:
       - invensense,icm42600
       - invensense,icm42602
       - invensense,icm42605
+      - invensense,icm42607
+      - invensense,icm42607p
       - invensense,icm42622
       - invensense,icm42631
       - invensense,icm42686
Signature · 1 line
2.43.0
#12 lore raw

PATCH v16 4/10 iio: imu: inv_icm42607: Add inv_icm42607 Core Driver

In reply to Chris Morgan

From: Chris Morgan <[email protected]>

Add the core component of a new inv_icm42607 driver. This includes a few setup functions and the full register definition in the header file, as well as the bits necessary to compile and probe the device when used on an i2c bus.

---
 drivers/iio/imu/Kconfig                       |   1 +
 drivers/iio/imu/Makefile                      |   1 +
 drivers/iio/imu/inv_icm42607/Kconfig          |  18 +
 drivers/iio/imu/inv_icm42607/Makefile         |   7 +
 drivers/iio/imu/inv_icm42607/inv_icm42607.h   | 365 ++++++++++++++++++
 .../iio/imu/inv_icm42607/inv_icm42607_core.c  | 286 ++++++++++++++
 .../iio/imu/inv_icm42607/inv_icm42607_i2c.c   |  96 +++++
 7 files changed, 774 insertions(+)
 create mode 100644 drivers/iio/imu/inv_icm42607/Kconfig
 create mode 100644 drivers/iio/imu/inv_icm42607/Makefile
 create mode 100644 drivers/iio/imu/inv_icm42607/inv_icm42607.h
 create mode 100644 drivers/iio/imu/inv_icm42607/inv_icm42607_core.c
 create mode 100644 drivers/iio/imu/inv_icm42607/inv_icm42607_i2c.c
drivers/iio/imu/Kconfig +1 -0
index 7e0181c27bb6..8bab4616be20 100644
@@ -109,6 +109,7 @@ config KMX61
 	  be called kmx61.
 
 source "drivers/iio/imu/inv_icm42600/Kconfig"
+source "drivers/iio/imu/inv_icm42607/Kconfig"
 source "drivers/iio/imu/inv_icm45600/Kconfig"
 source "drivers/iio/imu/inv_mpu6050/Kconfig"
 
drivers/iio/imu/Makefile +1 -0
index 13fb7846e9c9..3268dc2371ae 100644
@@ -25,6 +25,7 @@ obj-$(CONFIG_FXOS8700_I2C) += fxos8700_i2c.o
 obj-$(CONFIG_FXOS8700_SPI) += fxos8700_spi.o
 
 obj-y += inv_icm42600/
+obj-y += inv_icm42607/
 obj-y += inv_icm45600/
 obj-y += inv_mpu6050/
 
drivers/iio/imu/inv_icm42607/Kconfig new file +18 -0
new file mode 100644
index 000000000000..083c212087ab
@@ -0,0 +1,18 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+config INV_ICM42607
+	tristate
+	select IIO_BUFFER
+	select IIO_INV_SENSORS_TIMESTAMP
+
+config INV_ICM42607_I2C
+	tristate "InvenSense ICM-42607 I2C driver"
+	depends on I2C
+	select INV_ICM42607
+	select REGMAP_I2C
+	help
+	  This driver supports the InvenSense ICM-42607 motion tracking
+	  device over I2C.
+
+	  This driver can be built as a module. The module will be called
+	  inv-icm42607-i2c.
drivers/iio/imu/inv_icm42607/Makefile new file +7 -0
new file mode 100644
index 000000000000..32046e2727d7
@@ -0,0 +1,7 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+obj-$(CONFIG_INV_ICM42607) += inv-icm42607.o
+inv-icm42607-y += inv_icm42607_core.o
+
+obj-$(CONFIG_INV_ICM42607_I2C) += inv-icm42607-i2c.o
+inv-icm42607-i2c-y += inv_icm42607_i2c.o
drivers/iio/imu/inv_icm42607/inv_icm42607.h new file +365 -0

365 lines not on this page · raw message

drivers/iio/imu/inv_icm42607/inv_icm42607_core.c new file +286 -0

286 lines not on this page · raw message

drivers/iio/imu/inv_icm42607/inv_icm42607_i2c.c new file +96 -0

96 lines not on this page · raw message

Signature · 1 line
2.43.0
#13 lore raw

Re: [PATCH v16 04/10] iio: imu: inv_icm42607: Add inv_icm42607 Core Driver

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] Configuration registers `FIFO_CONFIG2` and `FIFO_CONFIG3` are incorrectly marked as volatile…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Configuration registers FIFO_CONFIG2 and FIFO_CONFIG3 are incorrectly marked as volatile, preventing them from being cached and restored by regcache_sync(). --

--- Patch [4]: [PATCH v16 04/10] iio: imu: inv_icm42607: Add inv_icm42607 Core Driver --- commit bb558c6dbdd036d405cccb1f326025519297d967
Author: Chris Morgan <[email protected]>

iio: imu: inv_icm42607: Add inv_icm42607 Core Driver

This commit adds the core component of a new inv_icm42607 driver. It includes setup functions, register definitions, and the initial functionality necessary to compile and probe the device over an i2c bus.

Quoted 4 lines
drivers/iio/imu/inv_icm42607/inv_icm42607_core.c new file +0 -0
new file mode 100644

[ ... ]

drivers/iio/imu/inv_icm42607/inv_icm42607_core.c line 54

Quoted 8 lines
drivers/iio/imu/inv_icm42607/inv_icm42607_core.c new file +8 -0
+static bool inv_icm42607_is_volatile_reg(struct device *dev, unsigned int reg)
+{
+	switch (reg) {
+	case INV_ICM42607_REG_MCLK_RDY:
+	case INV_ICM42607_REG_SIGNAL_PATH_RESET:
+	case INV_ICM42607_REG_TEMP_DATA1 ... INV_ICM42607_REG_APEX_DATA5:
+	case INV_ICM42607_REG_APEX_CONFIG0:
+	case INV_ICM42607_REG_FIFO_CONFIG2 ... INV_ICM42607_REG_FIFO_CONFIG3:

[Severity: Medium]
Should INV_ICM42607_REG_FIFO_CONFIG2 and INV_ICM42607_REG_FIFO_CONFIG3 be marked as volatile here?

These registers hold the FIFO watermark threshold, which is static configuration. Marking them as volatile causes any value written to them to bypass the regmap cache.

If future functionality utilizes these registers, they will not be restored during a regcache_sync() (such as after a soft reset or resume from suspend), which would cause the device to lose its watermark configuration.

Quoted 8 lines
drivers/iio/imu/inv_icm42607/inv_icm42607_core.c new file +8 -0
+	case INV_ICM42607_REG_FIFO_LOST_PKT0 ... INV_ICM42607_REG_APEX_DATA3:
+	case INV_ICM42607_REG_INT_STATUS_DRDY:
+	case INV_ICM42607_REG_INT_STATUS ... INV_ICM42607_REG_FIFO_DATA:
+		return true;
+	}
+
+	return false;
+}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
Reviewed-by on v16 4/10
#14 lore raw

Re: [PATCH v16 04/10] iio: imu: inv_icm42607: Add inv_icm42607 Core Driver

In reply to Chris Morgan
Quoted 4 lines · Chris Morgan

Add the core component of a new inv_icm42607 driver. This includes a few setup functions and the full register definition in the header file, as well as the bits necessary to compile and probe the device when used on an i2c bus.

...

drivers/iio/imu/inv_icm42607/inv_icm42607_core.c line 9

Quoted 7 lines

+++ b/drivers/iio/imu/inv_icm42607/inv_icm42607_core.c

drivers/iio/imu/inv_icm42607/inv_icm42607_core.c new file +4 -0
+#include <linux/bitfield.h>
+#include <linux/delay.h>
+#include <linux/device.h>
 
+#include <linux/device/devres.h>

When device.h is included, this one is not needed. Yeah, device.h is a mess, but here we are now.

Quoted 8 lines
drivers/iio/imu/inv_icm42607/inv_icm42607_core.c new file +8 -0
+#include <linux/err.h>
+#include <linux/iio/iio.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/regmap.h>
+#include <linux/regulator/consumer.h>
+#include <linux/time.h>
+#include <linux/types.h>
Signature · 2 lines
With Best Regards,
Andy Shevchenko
#15 lore raw

Re: [PATCH v16 04/10] iio: imu: inv_icm42607: Add inv_icm42607 Core Driver

In reply to Chris Morgan

Hello,

drivers/iio/imu/inv_icm42607/inv_icm42607_i2c.c line 10

Quoted 2 lines · Chris Morgan
drivers/iio/imu/inv_icm42607/inv_icm42607_i2c.c new file +2 -0
+#include <linux/i2c.h>
+#include <linux/mod_devicetable.h>

Please don't use <linux/mod_devicetable.h>, to get i2c_device_id and of_device_id it's enough to have <linux/i2c.h>.

Quoted 13 lines
drivers/iio/imu/inv_icm42607/inv_icm42607_i2c.c new file +13 -0
+static const struct i2c_device_id inv_icm42607_id[] = {
+	{
+		.name = "icm42607",
+		.driver_data = (kernel_ulong_t)&inv_icm42607_hw_data,
+	}, {
+		.name = "icm42607p",
+		.driver_data = (kernel_ulong_t)&inv_icm42607p_hw_data,
+	},
+	{ }
+};
+MODULE_DEVICE_TABLE(i2c, inv_icm42607_id);
+
+static const struct of_device_id inv_icm42607_of_matches[] = {

drivers/iio/imu/inv_icm42607/inv_icm42607_i2c.c line 81

Quoted 10 lines
drivers/iio/imu/inv_icm42607/inv_icm42607_i2c.c new file +10 -0
+	{
+		.compatible = "invensense,icm42607",
+		.data = &inv_icm42607_hw_data,
+	}, {
+		.compatible = "invensense,icm42607p",
+		.data = &inv_icm42607p_hw_data,
+	},
+	{ }
+};
+MODULE_DEVICE_TABLE(of, inv_icm42607_of_matches);

It would be enough to provide the driver_data pointers in the i2c_device_id array only.

Best regards
Uwe

maintainer
#16 lore raw

Re: [PATCH v16 04/10] iio: imu: inv_icm42607: Add inv_icm42607 Core Driver

Quoted 27 lines · On Tue, 14 Jul 2026 14:18:53 +0200 Uwe Kleine-König…

Hello,

drivers/iio/imu/inv_icm42607/inv_icm42607_i2c.c line 10

Quoted 2 lines · Chris Morgan
drivers/iio/imu/inv_icm42607/inv_icm42607_i2c.c new file +2 -0
+#include <linux/i2c.h>
+#include <linux/mod_devicetable.h>  

Please don't use <linux/mod_devicetable.h>, to get i2c_device_id and of_device_id it's enough to have <linux/i2c.h>.

Quoted 18 lines
drivers/iio/imu/inv_icm42607/inv_icm42607_i2c.c new file +18 -0
+static const struct i2c_device_id inv_icm42607_id[] = {
+	{
+		.name = "icm42607",
+		.driver_data = (kernel_ulong_t)&inv_icm42607_hw_data,
+	}, {
+		.name = "icm42607p",
+		.driver_data = (kernel_ulong_t)&inv_icm42607p_hw_data,
+	},
+	{ }
+};
+MODULE_DEVICE_TABLE(i2c, inv_icm42607_id);
+
+static const struct of_device_id inv_icm42607_of_matches[] = {
+	{
+		.compatible = "invensense,icm42607",
+		.data = &inv_icm42607_hw_data,
+	}, {
+		.compatible = "invensense,icm42607p",
Quoted 8 lines

drivers/iio/imu/inv_icm42607/inv_icm42607_i2c.c line 81

Quoted 5 lines
drivers/iio/imu/inv_icm42607/inv_icm42607_i2c.c new file +5 -0
+		.data = &inv_icm42607p_hw_data,
+	},
+	{ }
+};
+MODULE_DEVICE_TABLE(of, inv_icm42607_of_matches);  

It would be enough to provide the driver_data pointers in the i2c_device_id array only.

I'd prefer to keep them in both.

The match function tries the of_device_id path first and if we should ever get a typo or mismatch we can end up with a driver failing in a way that is annoyingly hard to track down. It has happened :( Now I'd love us to get to the point where we could just have the of_device_id table (and maybe ACPI on occasion) but we aren't there today.

This came up in v17 where I asked why they were missing and Chris mentioned it would be fine to drop them.

Jonathan

Quoted 3 lines

Best regards
Uwe

#17 lore raw

PATCH v16 5/10 iio: imu: inv_icm42607: Add SPI For icm42607

In reply to Chris Morgan

From: Chris Morgan <[email protected]>

Add SPI driver support for InvenSense ICM-42607 devices.

---
 drivers/iio/imu/inv_icm42607/Kconfig          |  12 ++
 drivers/iio/imu/inv_icm42607/Makefile         |   3 +
 .../iio/imu/inv_icm42607/inv_icm42607_spi.c   | 107 ++++++++++++++++++
 3 files changed, 122 insertions(+)
 create mode 100644 drivers/iio/imu/inv_icm42607/inv_icm42607_spi.c
drivers/iio/imu/inv_icm42607/Kconfig +12 -0
index 083c212087ab..23f461f57afc 100644
@@ -16,3 +16,15 @@ config INV_ICM42607_I2C
 
 	  This driver can be built as a module. The module will be called
 	  inv-icm42607-i2c.
+
+config INV_ICM42607_SPI
+	tristate "InvenSense ICM-42607 SPI driver"
+	depends on SPI_MASTER
+	select INV_ICM42607
+	select REGMAP_SPI
+	help
+	  This driver supports the InvenSense ICM-42607 motion tracking
+	  device over SPI.
+
+	  This driver can be built as a module. The module will be called
+	  inv-icm42607-spi.
drivers/iio/imu/inv_icm42607/Makefile +3 -0
index 32046e2727d7..be109102e203 100644
@@ -5,3 +5,6 @@ inv-icm42607-y += inv_icm42607_core.o
 
 obj-$(CONFIG_INV_ICM42607_I2C) += inv-icm42607-i2c.o
 inv-icm42607-i2c-y += inv_icm42607_i2c.o
+
+obj-$(CONFIG_INV_ICM42607_SPI) += inv-icm42607-spi.o
+inv-icm42607-spi-y += inv_icm42607_spi.o
drivers/iio/imu/inv_icm42607/inv_icm42607_spi.c new file +107 -0

107 lines not on this page · raw message

Signature · 1 line
2.43.0
Reviewed-by on v16 5/10
#18 lore raw

Re: [PATCH v16 05/10] iio: imu: inv_icm42607: Add SPI For icm42607

Quoted 1 line · Chris Morgan

Add SPI driver support for InvenSense ICM-42607 devices.

A few nit-picks below, otherwise

...

Quoted 16 lines
drivers/iio/imu/inv_icm42607/inv_icm42607_spi.c new file +16 -0
+static int inv_icm42607_spi_bus_setup(struct inv_icm42607_state *st)
+{
+	unsigned int val;
+	int ret;
+
+	/* Only support 4-wire mode for now. */
+	ret = regmap_set_bits(st->map, INV_ICM42607_REG_DEVICE_CONFIG,
+				      INV_ICM42607_DEVICE_CONFIG_SPI_AP_4WIRE);
+	if (ret)
+		return ret;
+
+	ret = regmap_clear_bits(st->map, INV_ICM42607_REG_INTF_CONFIG1,
+				INV_ICM42607_INTF_CONFIG1_I3C_DDR_EN |
+				INV_ICM42607_INTF_CONFIG1_I3C_SDR_EN);
+	if (ret)
+		return ret;

drivers/iio/imu/inv_icm42607/inv_icm42607_spi.c line 41

Quoted 10 lines
drivers/iio/imu/inv_icm42607/inv_icm42607_spi.c new file +10 -0
+
+	val = FIELD_PREP(INV_ICM42607_DRIVE_CONFIG3_SPI_MASK,
+			 INV_ICM42607_SLEW_RATE_2NS);
+	ret = regmap_update_bits(st->map, INV_ICM42607_REG_DRIVE_CONFIG3,
+				 INV_ICM42607_DRIVE_CONFIG3_SPI_MASK, val);
+	if (ret)
+		return ret;
+
+	val = FIELD_PREP(INV_ICM42607_INTF_CONFIG0_UI_SIFS_CFG_MASK,
+			 INV_ICM42607_INTF_CONFIG0_UI_SIFS_CFG_I2C_DIS);

+ blank line?
(Not sure, this is an interesting case and I have no strong opinion on
either style.)

drivers/iio/imu/inv_icm42607/inv_icm42607_spi.c line 44

Quoted 4 lines
drivers/iio/imu/inv_icm42607/inv_icm42607_spi.c new file +3 -0
+	return regmap_update_bits(st->map, INV_ICM42607_REG_INTF_CONFIG0,
 
+				  INV_ICM42607_INTF_CONFIG0_UI_SIFS_CFG_MASK,
+				  val);

This can be a single (a bit longer) line.

Quoted 1 line

+}

...

drivers/iio/imu/inv_icm42607/inv_icm42607_spi.c line 58

Quoted 12 lines
drivers/iio/imu/inv_icm42607/inv_icm42607_spi.c new file +12 -0
+static int inv_icm42607_probe(struct spi_device *spi)
+{
+	const struct inv_icm42607_hw *hw;
+	struct device *dev = &spi->dev;
+	struct regmap *regmap;
+
+	hw = spi_get_device_match_data(spi);
+	if (!hw)
+		return dev_err_probe(dev, -ENODEV, "Failed to get SPI data\n");
+
+	if (spi->mode & SPI_3WIRE)
+		return dev_err_probe(dev, -ENODEV, "SPI 3-wire mode not supported\n");

Hmm... I would distinguish these two by the error code, perhaps -ENODATA for no match data?

drivers/iio/imu/inv_icm42607/inv_icm42607_spi.c line 66

Quoted 7 lines
drivers/iio/imu/inv_icm42607/inv_icm42607_spi.c new file +6 -0
+	regmap = devm_regmap_init_spi(spi, &inv_icm42607_regmap_config);
+	if (IS_ERR(regmap))
+		return dev_err_probe(dev, PTR_ERR(regmap),
+				     "Failed to register spi regmap\n");
 
+	return inv_icm42607_core_probe(regmap, hw,
+				       inv_icm42607_spi_bus_setup);

This is perfectly a single line.

Quoted 1 line

+}

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#19 lore raw

PATCH v16 6/10 iio: imu: inv_icm42607: Add PM support for icm42607

In reply to Chris Morgan

From: Chris Morgan <[email protected]>

Add power management support for the ICM42607 device driver.

---
 drivers/iio/imu/inv_icm42607/inv_icm42607.h   |  21 +++
 .../iio/imu/inv_icm42607/inv_icm42607_core.c  | 165 ++++++++++++++++++
 .../iio/imu/inv_icm42607/inv_icm42607_i2c.c   |   1 +
 .../iio/imu/inv_icm42607/inv_icm42607_spi.c   |   1 +
 4 files changed, 188 insertions(+)
drivers/iio/imu/inv_icm42607/inv_icm42607.h +21 -0
index 169e848caf2e..cb6369cc1bfc 100644
@@ -9,6 +9,7 @@
 #include <linux/bits.h>
 #include <linux/iio/iio.h>
 #include <linux/mutex.h>
+#include <linux/pm.h>
 #include <linux/regmap.h>
 #include <linux/regulator/consumer.h>
 #include <linux/time.h>
@@ -119,12 +120,19 @@ struct inv_icm42607_hw {
 	u8 whoami;
 };
 
+struct inv_icm42607_suspended {
+	enum inv_icm42607_sensor_mode gyro;
+	enum inv_icm42607_sensor_mode accel;
+};
+
 /**
  *  struct inv_icm42607_state - driver state variables
  *  @hw:		Hardware specific data.
  *  @lock:		lock for serializing multiple registers access.
  *  @map:		regmap pointer.
  *  @vddio_supply:	I/O voltage regulator for the chip.
+ *  @vddio_en:		I/O voltage status for runtime PM.
+ *  @suspended:		suspended sensors configuration.
  *  @conf:		chip sensors configurations.
  *  @orientation:	sensor chip orientation relative to main hardware.
  */
@@ -133,6 +141,8 @@ struct inv_icm42607_state {
 	struct mutex lock;
 	struct regmap *map;
 	struct regulator *vddio_supply;
+	bool vddio_en;
+	struct inv_icm42607_suspended suspended;
 	struct inv_icm42607_conf conf;
 	struct iio_mount_matrix orientation;
 };
@@ -352,11 +362,22 @@ struct inv_icm42607_state {
 #define INV_ICM42607_GYRO_STOP_TIME_US			(45 * USEC_PER_MSEC)
 #define INV_ICM42607_TEMP_STARTUP_TIME_US		77
 
+/*
+ * Suspend delay assumed from other icm42600 series device, not
+ * documented in datasheet.
+ */
+#define INV_ICM42607_SUSPEND_DELAY_MS			(2 * MSEC_PER_SEC)
+
 typedef int (*inv_icm42607_bus_setup)(struct inv_icm42607_state *);
 
 extern const struct regmap_config inv_icm42607_regmap_config;
 extern const struct inv_icm42607_hw inv_icm42607_hw_data;
 extern const struct inv_icm42607_hw inv_icm42607p_hw_data;
+extern const struct dev_pm_ops inv_icm42607_pm_ops;
+
+int inv_icm42607_get_pwr_mgmt0(struct inv_icm42607_state *st,
+			       enum inv_icm42607_sensor_mode *gyro,
+			       enum inv_icm42607_sensor_mode *accel);
 
 int inv_icm42607_core_probe(struct regmap *regmap,
 			    const struct inv_icm42607_hw *hw,
drivers/iio/imu/inv_icm42607/inv_icm42607_core.c +165 -0

222 lines not on this page · raw message

drivers/iio/imu/inv_icm42607/inv_icm42607_i2c.c +1 -0
index 87524e05c3fe..02f4e46caf69 100644
@@ -84,6 +84,7 @@ static struct i2c_driver inv_icm42607_driver = {
 	.driver = {
 		.name = "inv-icm42607-i2c",
 		.of_match_table = inv_icm42607_of_matches,
+		.pm = pm_ptr(&inv_icm42607_pm_ops),
 	},
 	.id_table = inv_icm42607_id,
 	.probe = inv_icm42607_probe,
drivers/iio/imu/inv_icm42607/inv_icm42607_spi.c +1 -0
index 6072ed7adc86..137cd34582d8 100644
@@ -95,6 +95,7 @@ static struct spi_driver inv_icm42607_driver = {
 	.driver = {
 		.name = "inv-icm42607-spi",
 		.of_match_table = inv_icm42607_of_matches,
+		.pm = pm_ptr(&inv_icm42607_pm_ops),
 	},
 	.id_table = inv_icm42607_spi_id_table,
 	.probe = inv_icm42607_probe,
Signature · 1 line
2.43.0
#20 lore raw

Re: [PATCH v16 06/10] iio: imu: inv_icm42607: Add PM support for icm42607

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Low] Bypassing explicit platform workaround for 0-delays - [Low] Incompatible pointer type for enum…

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Low] Bypassing explicit platform workaround for 0-delays
- [Low] Incompatible pointer type for enum parameter
--

--- Patch [6]: [PATCH v16 06/10] iio: imu: inv_icm42607: Add PM support for icm42607 --- commit 2cc6ce210d26cf1a702e03730729ef340784c90f
Author: Chris Morgan <[email protected]>

iio: imu: inv_icm42607: Add PM support for icm42607

Add power management support for the ICM42607 device driver.

Quoted 4 lines
drivers/iio/imu/inv_icm42607/inv_icm42607_core.c +0 -0
index b90e578c3fb2c..303a6a0b1b21e 100644

[ ... ]

Quoted 8 lines
drivers/iio/imu/inv_icm42607/inv_icm42607_core.c +4 -0
@@ -102,6 +106,90 @@ const struct inv_icm42607_hw inv_icm42607p_hw_data = {
 };
 EXPORT_SYMBOL_NS_GPL(inv_icm42607p_hw_data, "IIO_ICM42607");
 
+int inv_icm42607_get_pwr_mgmt0(struct inv_icm42607_state *st,
+			       enum inv_icm42607_sensor_mode *gyro,
+			       enum inv_icm42607_sensor_mode *accel)
+{

[ ... ]

drivers/iio/imu/inv_icm42607/inv_icm42607_core.c const struct inv_icm42607_hw inv_icm42607p_hw_data = { · line 136

Quoted 13 lines
drivers/iio/imu/inv_icm42607/inv_icm42607_core.c +13 -0
+}
+
+static int inv_icm42607_set_pwr_mgmt0(struct inv_icm42607_state *st,
+				      enum inv_icm42607_sensor_mode gyro,
+				      enum inv_icm42607_sensor_mode accel)
+{
+	unsigned int oldaccel, oldgyro;
+	unsigned int sleepval_us;
+	unsigned int val;
+	s64 disable_wait;
+	int ret;
+
+	ret = inv_icm42607_get_pwr_mgmt0(st, &oldgyro, &oldaccel);

[Severity: Low]
Will this cause an incompatible pointer type compiler warning or error? inv_icm42607_get_pwr_mgmt0() expects enum inv_icm42607_sensor_mode pointers, but oldgyro and oldaccel are declared as unsigned int.

Quoted 7 lines
drivers/iio/imu/inv_icm42607/inv_icm42607_core.c +7 -0
+	if (ret)
+		return ret;
+
+	if (gyro == oldgyro && accel == oldaccel)
+		return 0;
+
+	/*

drivers/iio/imu/inv_icm42607/inv_icm42607_core.c const struct inv_icm42607_hw inv_icm42607p_hw_data = { · line 153

Quoted 10 lines
drivers/iio/imu/inv_icm42607/inv_icm42607_core.c +10 -0
+	 * Datasheet on page 14.26 says we need to ensure the gyro sensor is on
+	 * for a minimum of 45ms. So if we transition from an on state to an
+	 * off state make sure at least 45ms have passed before power off and
+	 * wait if it hasn't.
+	 */
+	if (!gyro && oldgyro) {
+		disable_wait = ktime_us_delta(st->conf.gyro_stop, ktime_get());
+		disable_wait = clamp(disable_wait,
+				     0, INV_ICM42607_GYRO_STOP_TIME_US);
+		fsleep(disable_wait);

[Severity: Low]
Can disable_wait evaluate to 0 here and cause issues on certain platforms?

The comment later in this function mentions that some platforms have issues with a 0 delay, but this fsleep() is called unconditionally even if disable_wait is clamped to 0.

Quoted 3 lines
drivers/iio/imu/inv_icm42607/inv_icm42607_core.c +3 -0
+	}
+
+	val = FIELD_PREP(INV_ICM42607_PWR_MGMT0_GYRO_MODE_MASK, gyro) |
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
#21 lore raw

Re: [PATCH v16 06/10] iio: imu: inv_icm42607: Add PM support for icm42607

In reply to Chris Morgan
Quoted 1 line · Chris Morgan

Add power management support for the ICM42607 device driver.

...

Quoted 17 lines
drivers/iio/imu/inv_icm42607/inv_icm42607_core.c +17 -0
+static int inv_icm42607_set_pwr_mgmt0(struct inv_icm42607_state *st,
+				      enum inv_icm42607_sensor_mode gyro,
+				      enum inv_icm42607_sensor_mode accel)
+{
+	unsigned int oldaccel, oldgyro;
+	unsigned int sleepval_us;
+	unsigned int val;
+	s64 disable_wait;
+	int ret;
+
+	ret = inv_icm42607_get_pwr_mgmt0(st, &oldgyro, &oldaccel);
+	if (ret)
+		return ret;
+
+	if (gyro == oldgyro && accel == oldaccel)
+		return 0;
+

drivers/iio/imu/inv_icm42607/inv_icm42607_core.c const struct inv_icm42607_hw inv_icm42607p_hw_data = { · line 152

Quoted 10 lines
drivers/iio/imu/inv_icm42607/inv_icm42607_core.c +10 -0
+	/*
+	 * Datasheet on page 14.26 says we need to ensure the gyro sensor is on
+	 * for a minimum of 45ms. So if we transition from an on state to an
+	 * off state make sure at least 45ms have passed before power off and
+	 * wait if it hasn't.
+	 */
+	if (!gyro && oldgyro) {
+		disable_wait = ktime_us_delta(st->conf.gyro_stop, ktime_get());
+		disable_wait = clamp(disable_wait,
+				     0, INV_ICM42607_GYRO_STOP_TIME_US);

I would go with this slightly longer line

		disable_wait = clamp(ktime_us_delta(st->conf.gyro_stop, ktime_get()),
				     0, INV_ICM42607_GYRO_STOP_TIME_US);
Quoted 24 lines
drivers/iio/imu/inv_icm42607/inv_icm42607_core.c +24 -0
+		fsleep(disable_wait);
+	}
+
+	val = FIELD_PREP(INV_ICM42607_PWR_MGMT0_GYRO_MODE_MASK, gyro) |
+	      FIELD_PREP(INV_ICM42607_PWR_MGMT0_ACCEL_MODE_MASK, accel);
+	ret = regmap_write(st->map, INV_ICM42607_REG_PWR_MGMT0, val);
+	if (ret)
+		return ret;
+
+	/*
+	 * If a state change occurs from off to on, sleep for the startup
+	 * time of the sensor, unless a sleep_ms is specified. Since more
+	 * than one sensor can be transitioned from off to on, select the
+	 * maximum time from each of the sensors changing from off to on.
+	 * The startup time for the temp sensor is considerably smaller
+	 * than the startup time for the other sensors and one or more are
+	 * required to be on for the temp sensor to function, so any start
+	 * delay should be enough.
+	 */
+	sleepval_us = 0;
+	if (accel && !oldaccel)
+		sleepval_us = max(sleepval_us, INV_ICM42607_ACCEL_STARTUP_TIME_US);
+
+	if (gyro && !oldgyro) {

drivers/iio/imu/inv_icm42607/inv_icm42607_core.c const struct inv_icm42607_hw inv_icm42607p_hw_data = { · line 186

Quoted 10 lines
drivers/iio/imu/inv_icm42607/inv_icm42607_core.c +9 -0
+		sleepval_us = max(sleepval_us, INV_ICM42607_GYRO_STARTUP_TIME_US);
+		/* Track the earliest we can turn off the gyroscope. */
+		st->conf.gyro_stop = ktime_add_us(ktime_get(),
+						  INV_ICM42607_GYRO_STOP_TIME_US);
+	}
 
+	/* Only sleep if sleepval_us is greater than 0 in case some
+	 * platforms have issues with a 0 delay. The 0 delay can happen
+	 * if one or both sensors is shut down.
+	 */

/*
* Use the same style for mutli-line comment
* in all comments.
*/

Quoted 5 lines
drivers/iio/imu/inv_icm42607/inv_icm42607_core.c +5 -0
+	if (sleepval_us > 0)
+		fsleep(sleepval_us);
+
+	return 0;
+}

...

drivers/iio/imu/inv_icm42607/inv_icm42607_core.c int inv_icm42607_core_probe(struct regmap *regmap, · line 446

Quoted 6 lines
drivers/iio/imu/inv_icm42607/inv_icm42607_core.c +5 -0
+EXPORT_NS_GPL_DEV_PM_OPS(inv_icm42607_pm_ops, IIO_ICM42607) = {
+	SYSTEM_SLEEP_PM_OPS(inv_icm42607_suspend, inv_icm42607_resume)
 
+	RUNTIME_PM_OPS(inv_icm42607_runtime_suspend,
+		       inv_icm42607_runtime_resume,
+		       NULL)

Hmm... perhaps just a single line as well?

	RUNTIME_PM_OPS(inv_icm42607_runtime_suspend, inv_icm42607_runtime_resume, NULL)
Quoted 1 line

+};

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#22 lore raw

PATCH v16 7/10 iio: imu: inv_icm42607: Add Accelerometer for icm42607

In reply to Chris Morgan

From: Chris Morgan <[email protected]>

Add icm42607 accelerometer sensor for icm42607.

---
 drivers/iio/imu/inv_icm42607/Makefile         |   1 +
 drivers/iio/imu/inv_icm42607/inv_icm42607.h   |  38 +++
 .../iio/imu/inv_icm42607/inv_icm42607_accel.c | 302 ++++++++++++++++++
 .../iio/imu/inv_icm42607/inv_icm42607_core.c  | 187 +++++++++++
 4 files changed, 528 insertions(+)
 create mode 100644 drivers/iio/imu/inv_icm42607/inv_icm42607_accel.c
drivers/iio/imu/inv_icm42607/Makefile +1 -0
index be109102e203..372c6d6bdcec 100644
@@ -2,6 +2,7 @@
 
 obj-$(CONFIG_INV_ICM42607) += inv-icm42607.o
 inv-icm42607-y += inv_icm42607_core.o
+inv-icm42607-y += inv_icm42607_accel.o
 
 obj-$(CONFIG_INV_ICM42607_I2C) += inv-icm42607-i2c.o
 inv-icm42607-i2c-y += inv_icm42607_i2c.o
drivers/iio/imu/inv_icm42607/inv_icm42607.h +38 -0
index cb6369cc1bfc..decd7c7baad8 100644
@@ -88,6 +88,17 @@ enum inv_icm42607_filter_bw {
 	INV_ICM42607_FILTER_BW_NB
 };
 
+/* Low-Power mode sensor data filter (averaging) */
+enum inv_icm42607_filter_avg {
+	INV_ICM42607_FILTER_AVG_2X = 0,
+	INV_ICM42607_FILTER_AVG_4X = 1,
+	INV_ICM42607_FILTER_AVG_8X = 2,
+	INV_ICM42607_FILTER_AVG_16X = 3,
+	INV_ICM42607_FILTER_AVG_32X = 4,
+	INV_ICM42607_FILTER_AVG_64X = 5,
+	/* values 6 and 7 also correspond to 64x. */
+};
+
 /* Temperature sensor data filter (bandwidth) */
 enum inv_icm42607_temp_filter_bw {
 	INV_ICM42607_TEMP_FILTER_BYPASS = 0,
@@ -107,6 +118,7 @@ struct inv_icm42607_sensor_conf {
 	int odr;
 	int filter;
 };
+#define INV_ICM42607_SENSOR_CONF_INIT		{ -1, -1, -1, -1 }
 
 struct inv_icm42607_conf {
 	struct inv_icm42607_sensor_conf gyro;
@@ -130,6 +142,7 @@ struct inv_icm42607_suspended {
  *  @hw:		Hardware specific data.
  *  @lock:		lock for serializing multiple registers access.
  *  @map:		regmap pointer.
+ *  @indio_accel:	accelerometer IIO device.
  *  @vddio_supply:	I/O voltage regulator for the chip.
  *  @vddio_en:		I/O voltage status for runtime PM.
  *  @suspended:		suspended sensors configuration.
@@ -140,6 +153,7 @@ struct inv_icm42607_state {
 	const struct inv_icm42607_hw *hw;
 	struct mutex lock;
 	struct regmap *map;
+	struct iio_dev *indio_accel;
 	struct regulator *vddio_supply;
 	bool vddio_en;
 	struct inv_icm42607_suspended suspended;
@@ -147,6 +161,16 @@ struct inv_icm42607_state {
 	struct iio_mount_matrix orientation;
 };
 
+/**
+ * struct inv_icm42607_sensor_state - sensor state variables
+ * @power_mode:		sensor requested power mode (for common frequencies)
+ * @filter:		sensor filter.
+ */
+struct inv_icm42607_sensor_state {
+	enum inv_icm42607_sensor_mode power_mode;
+	int filter;
+};
+
 /* Virtual register addresses: @bank on MSB (4 upper bits), @address on LSB */
 
 /* Register Map for User Bank 0 */
@@ -375,12 +399,26 @@ extern const struct inv_icm42607_hw inv_icm42607_hw_data;
 extern const struct inv_icm42607_hw inv_icm42607p_hw_data;
 extern const struct dev_pm_ops inv_icm42607_pm_ops;
 
+const struct iio_mount_matrix *
+inv_icm42607_get_mount_matrix(struct iio_dev *indio_dev,
+			      const struct iio_chan_spec *chan);
+
 int inv_icm42607_get_pwr_mgmt0(struct inv_icm42607_state *st,
 			       enum inv_icm42607_sensor_mode *gyro,
 			       enum inv_icm42607_sensor_mode *accel);
 
+int inv_icm42607_set_sensor_conf(struct inv_icm42607_state *st,
+				 struct inv_icm42607_sensor_conf *conf,
+				 enum iio_chan_type chan_type);
+
+int inv_icm42607_read_sensor(struct iio_dev *indio_dev,
+			     struct iio_chan_spec const *chan,
+			     s16 *val);
+
 int inv_icm42607_core_probe(struct regmap *regmap,
 			    const struct inv_icm42607_hw *hw,
 			    inv_icm42607_bus_setup bus_setup);
 
+struct iio_dev *inv_icm42607_accel_init(struct inv_icm42607_state *st);
+
 #endif
drivers/iio/imu/inv_icm42607/inv_icm42607_accel.c new file +302 -0

302 lines not on this page · raw message

drivers/iio/imu/inv_icm42607/inv_icm42607_core.c +187 -0

211 lines not on this page · raw message

Signature · 1 line
2.43.0
#23 lore raw

Re: [PATCH v16 07/10] iio: imu: inv_icm42607: Add Accelerometer for icm42607

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] Missing update of cached sensor state `mode` causes configuration changes to inadvertently power…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Missing update of cached sensor state mode causes configuration changes to inadvertently power off the sensor and breaks suspend/resume state tracking. --

--- Patch [7]: [PATCH v16 07/10] iio: imu: inv_icm42607: Add Accelerometer for icm42607 --- commit 599d6ae3a9166a30d7aae587e26cd1fe820357f4
Author: Chris Morgan <[email protected]>

iio: imu: inv_icm42607: Add Accelerometer for icm42607

Add icm42607 accelerometer sensor for icm42607.

Quoted 4 lines
drivers/iio/imu/inv_icm42607/inv_icm42607_core.c +0 -0
index 303a6a0b1b21e..45e031cefd4ae 100644

[ ... ]

Quoted 6 lines
drivers/iio/imu/inv_icm42607/inv_icm42607_core.c +6 -0
+static void inv_icm42607_update_config(struct inv_icm42607_sensor_conf *conf,
+				       struct inv_icm42607_sensor_conf *oldconf,
+				       bool *config0, bool *config1)
+{
+	if (conf->mode < 0)
+		conf->mode = oldconf->mode;

[ ... ]

Quoted 4 lines
drivers/iio/imu/inv_icm42607/inv_icm42607_core.c +4 -0
+int inv_icm42607_set_sensor_conf(struct inv_icm42607_state *st,
+				 struct inv_icm42607_sensor_conf *conf,
+				 enum iio_chan_type chan_type)
+{

[ ... ]

Quoted 1 line
drivers/iio/imu/inv_icm42607/inv_icm42607_core.c +1 -0
+	if (config0) {

[ ... ]

Quoted 5 lines
drivers/iio/imu/inv_icm42607/inv_icm42607_core.c +5 -0
+		oldconf->fs = conf->fs;
+		oldconf->odr = conf->odr;
+	}
+
+	if (config1) {

[ ... ]

drivers/iio/imu/inv_icm42607/inv_icm42607_core.c static int inv_icm42607_set_pwr_mgmt0(struct inv_icm42607_state *st, · line 309

Quoted 12 lines
drivers/iio/imu/inv_icm42607/inv_icm42607_core.c +12 -0
+		oldconf->filter = conf->filter;
+	}
+
+	switch (chan_type) {
+	case IIO_ACCEL:
+		return inv_icm42607_set_pwr_mgmt0(st, gyro_mode, conf->mode);
+	case IIO_ANGL_VEL:
+		return inv_icm42607_set_pwr_mgmt0(st, conf->mode, accel_mode);
+	default:
+		return -EINVAL;
+	}
+}

[Severity: Medium]
Does this code miss updating the cached mode (e.g., oldconf->mode = conf->mode)?

It looks like fs, odr, and filter are properly cached, but mode is not. If the cached mode is never updated, it could permanently stay OFF.

When a configuration parameter like scale or ODR is written via sysfs, inv_icm42607_update_config() merges the requested change with the cached mode. If the cached mode is incorrectly seen as OFF, it could inadvertently power off the sensor despite an active runtime PM reference. This might also break suspend/resume state tracking which relies on this cache.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
#24 lore raw

Re: [PATCH v16 07/10] iio: imu: inv_icm42607: Add Accelerometer for icm42607

In reply to Chris Morgan
Quoted 1 line · Chris Morgan

Add icm42607 accelerometer sensor for icm42607.

...

drivers/iio/imu/inv_icm42607/inv_icm42607_accel.c line 20

Quoted 3 lines
drivers/iio/imu/inv_icm42607/inv_icm42607_accel.c new file +2 -0
+#define INV_ICM42607_ACCEL_CHAN(_modifier, _index, _ext_info)			\
 
+{										\

You can also make it a compound literal, so it will be possible to use in the assignments at run-time (maybe not needed).

(struct iio_chan_spec) {

But again, it's up to you.

Quoted 17 lines
drivers/iio/imu/inv_icm42607/inv_icm42607_accel.c new file +17 -0
+	.type = IIO_ACCEL,							\
+	.modified = 1,								\
+	.channel2 = _modifier,							\
+	.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),				\
+	.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),			\
+	.info_mask_shared_by_type_available = BIT(IIO_CHAN_INFO_SCALE),		\
+	.info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ),		\
+	.info_mask_shared_by_all_available = BIT(IIO_CHAN_INFO_SAMP_FREQ),	\
+	.scan_index = _index,							\
+	.scan_type = {								\
+		.sign = 's',							\
+		.realbits = 16,							\
+		.storagebits = 16,						\
+		.endianness = IIO_BE,						\
+	},									\
+	.ext_info = _ext_info,							\
+}

...

Quoted 6 lines
drivers/iio/imu/inv_icm42607/inv_icm42607_accel.c new file +6 -0
+static int inv_icm42607_accel_write_scale(struct iio_dev *indio_dev,
+					  int val, int val2)
+{
+	struct inv_icm42607_sensor_conf conf = INV_ICM42607_SENSOR_CONF_INIT;
+	struct inv_icm42607_state *st = iio_device_get_drvdata(indio_dev);
+	size_t scales_len = ARRAY_SIZE(inv_icm42607_accel_scale_nano);

drivers/iio/imu/inv_icm42607/inv_icm42607_accel.c line 96

Quoted 10 lines
drivers/iio/imu/inv_icm42607/inv_icm42607_accel.c new file +10 -0
+	struct device *dev = regmap_get_device(st->map);
+	unsigned int idx;
+	int ret;
+
+	for (idx = 0; idx < scales_len; idx++) {
+		if (val == inv_icm42607_accel_scale_nano[idx][0] &&
+		    val2 == inv_icm42607_accel_scale_nano[idx][1])
+			break;
+	}
+	if (idx >= scales_len)

'==' should suffice, otherwise it will be an interesting case.

Quoted 13 lines
drivers/iio/imu/inv_icm42607/inv_icm42607_accel.c new file +13 -0
+		return -EINVAL;
+
+	conf.fs = idx;
+
+	PM_RUNTIME_ACQUIRE_AUTOSUSPEND(dev, pm);
+	ret = PM_RUNTIME_ACQUIRE_ERR(&pm);
+	if (ret)
+		return ret;
+
+	guard(mutex)(&st->lock);
+
+	return inv_icm42607_set_sensor_conf(st, &conf, IIO_ACCEL);
+}

...

Quoted 6 lines
drivers/iio/imu/inv_icm42607/inv_icm42607_accel.c new file +6 -0
+static int inv_icm42607_accel_read_odr(struct inv_icm42607_state *st,
+				       int *val, int *val2)
+{
+	unsigned int odr;
+	unsigned int i;
+

drivers/iio/imu/inv_icm42607/inv_icm42607_accel.c line 141

Quoted 10 lines
drivers/iio/imu/inv_icm42607/inv_icm42607_accel.c new file +10 -0
+	guard(mutex)(&st->lock);
+
+	odr = st->conf.accel.odr;
+
+	for (i = INV_ICM42607_ODR_1600HZ; i < ARRAY_SIZE(inv_icm42607_accel_odr); i++) {
+		if (i == odr)
+			break;
+	}
+	if (i >= ARRAY_SIZE(inv_icm42607_accel_odr))
+		return -EINVAL;

Ditto. And so on.

Quoted 5 lines
drivers/iio/imu/inv_icm42607/inv_icm42607_accel.c new file +5 -0
+	*val = inv_icm42607_accel_odr[i][0];
+	*val2 = inv_icm42607_accel_odr[i][1];
+
+	return IIO_VAL_INT_PLUS_MICRO;
+}

...

Quoted 8 lines
drivers/iio/imu/inv_icm42607/inv_icm42607_accel.c new file +8 -0
+struct iio_dev *inv_icm42607_accel_init(struct inv_icm42607_state *st)
+{
+	struct device *dev = regmap_get_device(st->map);
+	struct inv_icm42607_sensor_state *accel_st;
+	struct iio_dev *indio_dev;
+	const char *name;
+	int ret;
+

drivers/iio/imu/inv_icm42607/inv_icm42607_accel.c line 286

Quoted 10 lines
drivers/iio/imu/inv_icm42607/inv_icm42607_accel.c new file +9 -0
+	name = devm_kasprintf(dev, GFP_KERNEL, "%s-accel", st->hw->name);
+	if (!name)
+		return ERR_PTR(-ENOMEM);
+
+	indio_dev = devm_iio_device_alloc(dev, sizeof(*accel_st));
+	if (!indio_dev)
+		return ERR_PTR(-ENOMEM);
 
+	accel_st = iio_priv(indio_dev);
+

Move this blank line to be above on the previous assignment.

drivers/iio/imu/inv_icm42607/inv_icm42607_accel.c line 290

Quoted 5 lines
drivers/iio/imu/inv_icm42607/inv_icm42607_accel.c new file +4 -0
+	accel_st->power_mode = INV_ICM42607_SENSOR_MODE_LOW_NOISE;
+	accel_st->filter = INV_ICM42607_FILTER_BW_73HZ;
 
+
+	iio_device_set_drvdata(indio_dev, st);

And here I would rather move this line to be after the all assignments, so we won't have the potential code that might use unfilled data in between.

Quoted 12 lines
drivers/iio/imu/inv_icm42607/inv_icm42607_accel.c new file +12 -0
+	indio_dev->name = name;
+	indio_dev->info = &inv_icm42607_accel_info;
+	indio_dev->modes = INDIO_DIRECT_MODE;
+	indio_dev->channels = inv_icm42607_accel_channels;
+	indio_dev->num_channels = ARRAY_SIZE(inv_icm42607_accel_channels);
+
+	ret = devm_iio_device_register(dev, indio_dev);
+	if (ret)
+		return ERR_PTR(ret);
+
+	return indio_dev;
+}

...

Quoted 7 lines
drivers/iio/imu/inv_icm42607/inv_icm42607_core.c +7 -0
+static void inv_icm42607_update_config(struct inv_icm42607_sensor_conf *conf,
+				       struct inv_icm42607_sensor_conf *oldconf,
+				       bool *config0, bool *config1)
+{
+	if (conf->mode < 0)
+		conf->mode = oldconf->mode;
+	if (conf->fs < 0)

drivers/iio/imu/inv_icm42607/inv_icm42607_core.c static int inv_icm42607_set_pwr_mgmt0(struct inv_icm42607_state *st, · line 223

Quoted 10 lines
drivers/iio/imu/inv_icm42607/inv_icm42607_core.c +9 -0
+		conf->fs = oldconf->fs;
+	if (conf->odr < 0)
+		conf->odr = oldconf->odr;
+	if (conf->filter < 0)
+		conf->filter = oldconf->filter;
 
+	if (conf->fs != oldconf->fs || conf->odr != oldconf->odr)
+		*config0 = true;
+	else
+		*config0 = false;

Can be simply

	*config0 = (conf->fs != oldconf->fs) || (conf->odr != oldconf->odr);

(I added parentheses for better reading of this expression to make it clear
that the recipient is a boolean.)

drivers/iio/imu/inv_icm42607/inv_icm42607_core.c static int inv_icm42607_set_pwr_mgmt0(struct inv_icm42607_state *st, · line 228

Quoted 4 lines
drivers/iio/imu/inv_icm42607/inv_icm42607_core.c +4 -0
+	if (conf->filter != oldconf->filter)
+		*config1 = true;
+	else
+		*config1 = false;

In the similar way.

Quoted 1 line

+}

...

drivers/iio/imu/inv_icm42607/inv_icm42607_core.c static int inv_icm42607_set_pwr_mgmt0(struct inv_icm42607_state *st, · line 320

Quoted 11 lines
drivers/iio/imu/inv_icm42607/inv_icm42607_core.c +10 -0
+int inv_icm42607_read_sensor(struct iio_dev *indio_dev,
+			     struct iio_chan_spec const *chan,
+			     s16 *val)
+{
+	struct inv_icm42607_sensor_conf conf = INV_ICM42607_SENSOR_CONF_INIT;
+	struct inv_icm42607_state *st = iio_device_get_drvdata(indio_dev);
+	struct inv_icm42607_sensor_state *sensor_st = iio_priv(indio_dev);
+	struct device *dev = regmap_get_device(st->map);
+	unsigned int reg;
 
+	u8 data[2];

Define using the correct type. AFAICS it should be __be16 data;

Quoted 53 lines
drivers/iio/imu/inv_icm42607/inv_icm42607_core.c +53 -0
+	int ret;
+
+	if ((chan->type != IIO_ANGL_VEL) && (chan->type != IIO_ACCEL))
+		return -EINVAL;
+
+	switch (chan->channel2) {
+	case IIO_MOD_X:
+		if (chan->type == IIO_ANGL_VEL)
+			reg = INV_ICM42607_REG_GYRO_DATA_X1;
+		else
+			reg = INV_ICM42607_REG_ACCEL_DATA_X1;
+		break;
+	case IIO_MOD_Y:
+		if (chan->type == IIO_ANGL_VEL)
+			reg = INV_ICM42607_REG_GYRO_DATA_Y1;
+		else
+			reg = INV_ICM42607_REG_ACCEL_DATA_Y1;
+		break;
+	case IIO_MOD_Z:
+		if (chan->type == IIO_ANGL_VEL)
+			reg = INV_ICM42607_REG_GYRO_DATA_Z1;
+		else
+			reg = INV_ICM42607_REG_ACCEL_DATA_Z1;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	PM_RUNTIME_ACQUIRE_AUTOSUSPEND(dev, pm);
+	ret = PM_RUNTIME_ACQUIRE_ERR(&pm);
+	if (ret)
+		return ret;
+
+	guard(mutex)(&st->lock);
+
+	/* enable sensor */
+	conf.mode = sensor_st->power_mode;
+	conf.filter = sensor_st->filter;
+	ret = inv_icm42607_set_sensor_conf(st, &conf, chan->type);
+	if (ret)
+		return ret;
+
+	/* read sensor register data */
+	ret = regmap_bulk_read(st->map, reg, data, sizeof(data));
+	if (ret)
+		return ret;
+
+	*val = get_unaligned_be16(data);
+	if (*val == INV_ICM42607_DATA_INVALID)
+		return -EINVAL;
+
+	return 0;
+}
Signature · 2 lines
With Best Regards,
Andy Shevchenko
#25 lore raw

Re: [PATCH v16 07/10] iio: imu: inv_icm42607: Add Accelerometer for icm42607

Quoted 1 line · Andy Shevchenko

On Mon, Jul 13, 2026 at 04:58:37PM -0500, Chris Morgan wrote:

...

Quoted 61 lines

drivers/iio/imu/inv_icm42607/inv_icm42607_core.c static int inv_icm42607_set_pwr_mgmt0(struct inv_icm42607_state *st, · line 320

Quoted 11 lines
drivers/iio/imu/inv_icm42607/inv_icm42607_core.c +10 -0
+int inv_icm42607_read_sensor(struct iio_dev *indio_dev,
+			     struct iio_chan_spec const *chan,
+			     s16 *val)
+{
+	struct inv_icm42607_sensor_conf conf = INV_ICM42607_SENSOR_CONF_INIT;
+	struct inv_icm42607_state *st = iio_device_get_drvdata(indio_dev);
+	struct inv_icm42607_sensor_state *sensor_st = iio_priv(indio_dev);
+	struct device *dev = regmap_get_device(st->map);
+	unsigned int reg;
 
+	u8 data[2];

Define using the correct type. AFAICS it should be __be16 data;

Quoted 46 lines
drivers/iio/imu/inv_icm42607/inv_icm42607_core.c +46 -0
+	int ret;
+
+	if ((chan->type != IIO_ANGL_VEL) && (chan->type != IIO_ACCEL))
+		return -EINVAL;
+
+	switch (chan->channel2) {
+	case IIO_MOD_X:
+		if (chan->type == IIO_ANGL_VEL)
+			reg = INV_ICM42607_REG_GYRO_DATA_X1;
+		else
+			reg = INV_ICM42607_REG_ACCEL_DATA_X1;
+		break;
+	case IIO_MOD_Y:
+		if (chan->type == IIO_ANGL_VEL)
+			reg = INV_ICM42607_REG_GYRO_DATA_Y1;
+		else
+			reg = INV_ICM42607_REG_ACCEL_DATA_Y1;
+		break;
+	case IIO_MOD_Z:
+		if (chan->type == IIO_ANGL_VEL)
+			reg = INV_ICM42607_REG_GYRO_DATA_Z1;
+		else
+			reg = INV_ICM42607_REG_ACCEL_DATA_Z1;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	PM_RUNTIME_ACQUIRE_AUTOSUSPEND(dev, pm);
+	ret = PM_RUNTIME_ACQUIRE_ERR(&pm);
+	if (ret)
+		return ret;
+
+	guard(mutex)(&st->lock);
+
+	/* enable sensor */
+	conf.mode = sensor_st->power_mode;
+	conf.filter = sensor_st->filter;
+	ret = inv_icm42607_set_sensor_conf(st, &conf, chan->type);
+	if (ret)
+		return ret;
+
+	/* read sensor register data */
+	ret = regmap_bulk_read(st->map, reg, data, sizeof(data));
+	if (ret)
+		return ret;
Quoted 1 line

drivers/iio/imu/inv_icm42607/inv_icm42607_core.c static int inv_icm42607_set_pwr_mgmt0(struct inv_icm42607_state *st, · line 368

Quoted 1 line
drivers/iio/imu/inv_icm42607/inv_icm42607_core.c +1 -0
+	*val = get_unaligned_be16(data);

In this case it will be be16_to_cpu() instead (from asm/byteorder.h).

Quoted 5 lines
Quoted 5 lines
drivers/iio/imu/inv_icm42607/inv_icm42607_core.c +5 -0
+	if (*val == INV_ICM42607_DATA_INVALID)
+		return -EINVAL;
+
+	return 0;
+}
Signature · 2 lines
With Best Regards,
Andy Shevchenko
#26 lore raw

PATCH v16 8/10 iio: imu: inv_icm42607: Add Gyroscope to icm42607

In reply to Chris Morgan

From: Chris Morgan <[email protected]>

Add gyroscope functions to the icm42607 driver.

---
 drivers/iio/imu/inv_icm42607/Makefile         |   1 +
 drivers/iio/imu/inv_icm42607/inv_icm42607.h   |   4 +
 .../iio/imu/inv_icm42607/inv_icm42607_core.c  |   5 +
 .../iio/imu/inv_icm42607/inv_icm42607_gyro.c  | 299 ++++++++++++++++++
 4 files changed, 309 insertions(+)
 create mode 100644 drivers/iio/imu/inv_icm42607/inv_icm42607_gyro.c
drivers/iio/imu/inv_icm42607/Makefile +1 -0
index 372c6d6bdcec..8e73385c8f4b 100644
@@ -2,6 +2,7 @@
 
 obj-$(CONFIG_INV_ICM42607) += inv-icm42607.o
 inv-icm42607-y += inv_icm42607_core.o
+inv-icm42607-y += inv_icm42607_gyro.o
 inv-icm42607-y += inv_icm42607_accel.o
 
 obj-$(CONFIG_INV_ICM42607_I2C) += inv-icm42607-i2c.o
drivers/iio/imu/inv_icm42607/inv_icm42607.h +4 -0
index decd7c7baad8..f3e05d9c468c 100644
@@ -143,6 +143,7 @@ struct inv_icm42607_suspended {
  *  @lock:		lock for serializing multiple registers access.
  *  @map:		regmap pointer.
  *  @indio_accel:	accelerometer IIO device.
+ *  @indio_gyro:	gyroscope IIO device.
  *  @vddio_supply:	I/O voltage regulator for the chip.
  *  @vddio_en:		I/O voltage status for runtime PM.
  *  @suspended:		suspended sensors configuration.
@@ -154,6 +155,7 @@ struct inv_icm42607_state {
 	struct mutex lock;
 	struct regmap *map;
 	struct iio_dev *indio_accel;
+	struct iio_dev *indio_gyro;
 	struct regulator *vddio_supply;
 	bool vddio_en;
 	struct inv_icm42607_suspended suspended;
@@ -419,6 +421,8 @@ int inv_icm42607_core_probe(struct regmap *regmap,
 			    const struct inv_icm42607_hw *hw,
 			    inv_icm42607_bus_setup bus_setup);
 
+struct iio_dev *inv_icm42607_gyro_init(struct inv_icm42607_state *st);
+
 struct iio_dev *inv_icm42607_accel_init(struct inv_icm42607_state *st);
 
 #endif
drivers/iio/imu/inv_icm42607/inv_icm42607_core.c +5 -0
index 45e031cefd4a..1712af58d8a3 100644
@@ -571,6 +571,11 @@ int inv_icm42607_core_probe(struct regmap *regmap,
 	if (IS_ERR(st->indio_accel))
 		return PTR_ERR(st->indio_accel);
 
+	/* Initialize IIO device for Gyro */
+	st->indio_gyro = inv_icm42607_gyro_init(st);
+	if (IS_ERR(st->indio_gyro))
+		return PTR_ERR(st->indio_gyro);
+
 	return 0;
 }
 EXPORT_SYMBOL_NS_GPL(inv_icm42607_core_probe, "IIO_ICM42607");
drivers/iio/imu/inv_icm42607/inv_icm42607_gyro.c new file +299 -0

299 lines not on this page · raw message

Signature · 1 line
2.43.0
#27 lore raw

PATCH v16 9/10 iio: imu: inv_icm42607: Add Temp Support in icm42607

In reply to Chris Morgan

From: Chris Morgan <[email protected]>

Add functions for reading temperature sensor data.

---
 drivers/iio/imu/inv_icm42607/Makefile         |  1 +
 .../iio/imu/inv_icm42607/inv_icm42607_accel.c |  6 ++
 .../iio/imu/inv_icm42607/inv_icm42607_gyro.c  |  6 ++
 .../iio/imu/inv_icm42607/inv_icm42607_temp.c  | 98 +++++++++++++++++++
 .../iio/imu/inv_icm42607/inv_icm42607_temp.h  | 38 +++++++
 5 files changed, 149 insertions(+)
 create mode 100644 drivers/iio/imu/inv_icm42607/inv_icm42607_temp.c
 create mode 100644 drivers/iio/imu/inv_icm42607/inv_icm42607_temp.h
drivers/iio/imu/inv_icm42607/Makefile +1 -0
index 8e73385c8f4b..7b907e019601 100644
@@ -4,6 +4,7 @@ obj-$(CONFIG_INV_ICM42607) += inv-icm42607.o
 inv-icm42607-y += inv_icm42607_core.o
 inv-icm42607-y += inv_icm42607_gyro.o
 inv-icm42607-y += inv_icm42607_accel.o
+inv-icm42607-y += inv_icm42607_temp.o
 
 obj-$(CONFIG_INV_ICM42607_I2C) += inv-icm42607-i2c.o
 inv-icm42607-i2c-y += inv_icm42607_i2c.o
drivers/iio/imu/inv_icm42607/inv_icm42607_accel.c +6 -0
index 7a0c419c0f06..a6cd3aebadaa 100644
@@ -15,6 +15,7 @@
 #include <linux/types.h>
 
 #include "inv_icm42607.h"
+#include "inv_icm42607_temp.h"
 
 #define INV_ICM42607_ACCEL_CHAN(_modifier, _index, _ext_info)			\
 {										\
@@ -40,6 +41,7 @@ enum inv_icm42607_accel_scan {
 	INV_ICM42607_ACCEL_SCAN_X,
 	INV_ICM42607_ACCEL_SCAN_Y,
 	INV_ICM42607_ACCEL_SCAN_Z,
+	INV_ICM42607_ACCEL_SCAN_TEMP,
 };
 
 static const struct iio_chan_spec_ext_info inv_icm42607_accel_ext_infos[] = {
@@ -54,6 +56,7 @@ static const struct iio_chan_spec inv_icm42607_accel_channels[] = {
 				inv_icm42607_accel_ext_infos),
 	INV_ICM42607_ACCEL_CHAN(IIO_MOD_Z, INV_ICM42607_ACCEL_SCAN_Z,
 				inv_icm42607_accel_ext_infos),
+	INV_ICM42607_TEMP_CHAN(INV_ICM42607_ACCEL_SCAN_TEMP),
 };
 
 static const int inv_icm42607_accel_scale_nano[][2] = {
@@ -186,6 +189,9 @@ static int inv_icm42607_accel_read_raw(struct iio_dev *indio_dev,
 
 	switch (mask) {
 	case IIO_CHAN_INFO_RAW:
+		if (chan->type == IIO_TEMP)
+			return inv_icm42607_temp_read_raw(indio_dev, chan,
+							  val, val2, mask);
 		ret = inv_icm42607_read_sensor(indio_dev, chan, &data);
 		if (ret)
 			return ret;
drivers/iio/imu/inv_icm42607/inv_icm42607_gyro.c +6 -0
index e4b674070ed9..897cdbf987bf 100644
@@ -15,6 +15,7 @@
 #include <linux/types.h>
 
 #include "inv_icm42607.h"
+#include "inv_icm42607_temp.h"
 
 #define INV_ICM42607_GYRO_CHAN(_modifier, _index, _ext_info)			\
 {										\
@@ -40,6 +41,7 @@ enum inv_icm42607_gyro_scan {
 	INV_ICM42607_GYRO_SCAN_X,
 	INV_ICM42607_GYRO_SCAN_Y,
 	INV_ICM42607_GYRO_SCAN_Z,
+	INV_ICM42607_GYRO_SCAN_TEMP,
 };
 
 static const struct iio_chan_spec_ext_info inv_icm42607_gyro_ext_infos[] = {
@@ -54,6 +56,7 @@ static const struct iio_chan_spec inv_icm42607_gyro_channels[] = {
 			       inv_icm42607_gyro_ext_infos),
 	INV_ICM42607_GYRO_CHAN(IIO_MOD_Z, INV_ICM42607_GYRO_SCAN_Z,
 			       inv_icm42607_gyro_ext_infos),
+	INV_ICM42607_TEMP_CHAN(INV_ICM42607_GYRO_SCAN_TEMP),
 };
 
 static const int inv_icm42607_gyro_scale_nano[][2] = {
@@ -183,6 +186,9 @@ static int inv_icm42607_gyro_read_raw(struct iio_dev *indio_dev,
 
 	switch (mask) {
 	case IIO_CHAN_INFO_RAW:
+		if (chan->type == IIO_TEMP)
+			return inv_icm42607_temp_read_raw(indio_dev, chan,
+							  val, val2, mask);
 		ret = inv_icm42607_read_sensor(indio_dev, chan, &data);
 		if (ret)
 			return ret;
drivers/iio/imu/inv_icm42607/inv_icm42607_temp.c new file +98 -0

98 lines not on this page · raw message

drivers/iio/imu/inv_icm42607/inv_icm42607_temp.h new file +38 -0
new file mode 100644
index 000000000000..18499b4d0b94
@@ -0,0 +1,38 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (C) 2026 InvenSense, Inc.
+ */
+
+#ifndef INV_ICM42607_TEMP_H_
+#define INV_ICM42607_TEMP_H_
+
+#include <linux/bitops.h>
+
+struct iio_dev;
+struct iio_chan_spec;
+
+#define INV_ICM42607_TEMP_CHAN(_index)				\
+{								\
+	.type = IIO_TEMP,					\
+	.info_mask_separate =					\
+		BIT(IIO_CHAN_INFO_RAW) |			\
+		BIT(IIO_CHAN_INFO_OFFSET) |			\
+		BIT(IIO_CHAN_INFO_SCALE),			\
+	.info_mask_shared_by_all =				\
+		BIT(IIO_CHAN_INFO_SAMP_FREQ),			\
+	.info_mask_shared_by_all_available =			\
+		BIT(IIO_CHAN_INFO_SAMP_FREQ),			\
+	.scan_index = _index,					\
+	.scan_type = {						\
+		.sign = 's',					\
+		.realbits = 16,					\
+		.storagebits = 16,				\
+		.endianness = IIO_BE,				\
+	},							\
+}
+
+int inv_icm42607_temp_read_raw(struct iio_dev *indio_dev,
+			       struct iio_chan_spec const *chan,
+			       int *val, int *val2, long mask);
+
+#endif
Signature · 1 line
2.43.0
#28 lore raw

Re: [PATCH v16 09/10] iio: imu: inv_icm42607: Add Temp Support in icm42607

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] The temperature scale and offset sysfs attributes always return -EINVAL. --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The temperature scale and offset sysfs attributes always return -EINVAL. --

--- Patch [9]: [PATCH v16 09/10] iio: imu: inv_icm42607: Add Temp Support in icm42607 --- commit 5c22145efbd1dae68fedacdc2fc8522da3f2f320
Author: Chris Morgan <[email protected]>

iio: imu: inv_icm42607: Add Temp Support in icm42607

This commit adds functions for reading temperature sensor data to the inv_icm42607 driver.

Quoted 3 lines
drivers/iio/imu/inv_icm42607/inv_icm42607_accel.c +0 -0

[ ... ]

drivers/iio/imu/inv_icm42607/inv_icm42607_accel.c static int inv_icm42607_accel_read_raw(struct iio_dev *indio_dev, · line 194

Quoted 7 lines
drivers/iio/imu/inv_icm42607/inv_icm42607_accel.c +3 -0
@@ -186,6 +189,9 @@ static int inv_icm42607_accel_read_raw(struct iio_dev *indio_dev,
 
 	switch (mask) {
 	case IIO_CHAN_INFO_RAW:
+		if (chan->type == IIO_TEMP)
+			return inv_icm42607_temp_read_raw(indio_dev, chan,
+							  val, val2, mask);

[Severity: Medium]
Since this check is nested inside case IIO_CHAN_INFO_RAW:, how are requests for IIO_CHAN_INFO_SCALE and IIO_CHAN_INFO_OFFSET handled for the temperature channel?

Won't those masks bypass this check, fall through to the accelerometer-specific cases below, and ultimately return -EINVAL?

[ ... ]

Quoted 3 lines
drivers/iio/imu/inv_icm42607/inv_icm42607_gyro.c +0 -0

[ ... ]

drivers/iio/imu/inv_icm42607/inv_icm42607_gyro.c static int inv_icm42607_gyro_read_raw(struct iio_dev *indio_dev, · line 191

Quoted 7 lines
drivers/iio/imu/inv_icm42607/inv_icm42607_gyro.c +3 -0
@@ -183,6 +186,9 @@ static int inv_icm42607_gyro_read_raw(struct iio_dev *indio_dev,
 
 	switch (mask) {
 	case IIO_CHAN_INFO_RAW:
+		if (chan->type == IIO_TEMP)
+			return inv_icm42607_temp_read_raw(indio_dev, chan,
+							  val, val2, mask);

[Severity: Medium]
Does this have the same routing issue as the accelerometer handler above?

It appears that requests for the temperature channel's scale and offset will also fail with -EINVAL here, making the IIO_CHAN_INFO_SCALE and IIO_CHAN_INFO_OFFSET cases in inv_icm42607_temp_read_raw() unreachable.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=9
#29 lore raw

PATCH v16 10/10 arm64: dts: rockchip: Add icm42607p IMU for RG-DS

In reply to Chris Morgan

From: Chris Morgan <[email protected]>

Add the Invensense ICM42607P IMU for the Anbernic RG-DS. Mount-matrix was tested with iio-sensor-proxy and reports correct orientation.

---
 arch/arm64/boot/dts/rockchip/rk3568-anbernic-rg-ds.dts | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
arch/arm64/boot/dts/rockchip/rk3568-anbernic-rg-ds.dts +7 -1
index 8d906ab02c5f..b770bfd5268d 100644
@@ -871,7 +871,13 @@ aw87391_pa_r: audio-codec@5b {
 		sound-name-prefix = "Right Amp";
 	};
 
-	/* invensense,icm42607p at 0x68 */
+	icm42607p: imu@68 {
+		compatible = "invensense,icm42607p";
+		reg = <0x68>;
+		mount-matrix = "-1", "0", "0",
+			       "0", "1", "0",
+			       "0", "0", "-1";
+	};
 };
 
 &i2c3 {
Signature · 1 line
2.43.0