Add Invensense ICM42607
Subsystems (4)
v14 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.
Chris Morgan (9):
dt-bindings: iio: imu: icm42600: Add mount-matrix
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 | 20 +- .../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 | 423 ++++++++++++ .../iio/imu/inv_icm42607/inv_icm42607_accel.c | 317 +++++++++ .../iio/imu/inv_icm42607/inv_icm42607_core.c | 606 ++++++++++++++++++ .../iio/imu/inv_icm42607/inv_icm42607_gyro.c | 313 +++++++++ .../iio/imu/inv_icm42607/inv_icm42607_i2c.c | 98 +++ .../iio/imu/inv_icm42607/inv_icm42607_spi.c | 108 ++++ .../iio/imu/inv_icm42607/inv_icm42607_temp.c | 99 +++ .../iio/imu/inv_icm42607/inv_icm42607_temp.h | 37 ++ 14 files changed, 2072 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
PATCH v14 1/9 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
@@ -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
PATCH v14 2/9 dt-bindings: iio: imu: icm42600: Add icm42607
In reply to Chris MorganFrom: 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. The driver does not require an interrupt for these specific chip revisions.
--- .../bindings/iio/imu/invensense,icm42600.yaml | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/iio/imu/invensense,icm42600.yaml +17 -1
@@ -30,6 +30,8 @@ properties: - invensense,icm42600 - invensense,icm42602 - invensense,icm42605 + - invensense,icm42607 + - invensense,icm42607p - invensense,icm42622 - invensense,icm42631 - invensense,icm42686
@@ -67,10 +69,24 @@ properties: required: - compatible - reg - - interrupts allOf: - $ref: /schemas/spi/spi-peripheral-props.yaml# + - if: + properties: + compatible: + contains: + enum: + - invensense,icm42600 + - invensense,icm42602 + - invensense,icm42605 + - invensense,icm42622 + - invensense,icm42631 + - invensense,icm42686 + - invensense,icm42688 + then: + required: + - interrupts unevaluatedProperties: false
Signature · 1 line
2.43.0
PATCH v14 3/9 iio: imu: inv_icm42607: Add inv_icm42607 Core Driver
In reply to Chris MorganFrom: 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 | 364 ++++++++++++++++++ .../iio/imu/inv_icm42607/inv_icm42607_core.c | 286 ++++++++++++++ .../iio/imu/inv_icm42607/inv_icm42607_i2c.c | 97 +++++ 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
@@ -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
@@ -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
@@ -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
@@ -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 +364 -0
364 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 +97 -0
97 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v14 4/9 iio: imu: inv_icm42607: Add SPI For icm42607
In reply to Chris MorganFrom: 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
@@ -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
@@ -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
PATCH v14 5/9 iio: imu: inv_icm42607: Add PM support for icm42607
In reply to Chris MorganFrom: Chris Morgan <[email protected]>
Add power management support for the ICM42607 device driver.
--- drivers/iio/imu/inv_icm42607/inv_icm42607.h | 17 ++ .../iio/imu/inv_icm42607/inv_icm42607_core.c | 146 ++++++++++++++++++ .../iio/imu/inv_icm42607/inv_icm42607_i2c.c | 1 + .../iio/imu/inv_icm42607/inv_icm42607_spi.c | 1 + 4 files changed, 165 insertions(+)
drivers/iio/imu/inv_icm42607/inv_icm42607.h +17 -0
@@ -10,6 +10,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>
@@ -118,12 +119,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. */
@@ -132,6 +140,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; };
@@ -351,11 +361,18 @@ 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 2000 +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_core_probe(struct regmap *regmap, const struct inv_icm42607_hw *hw,
drivers/iio/imu/inv_icm42607/inv_icm42607_core.c +146 -0
203 lines not on this page · raw message
drivers/iio/imu/inv_icm42607/inv_icm42607_i2c.c +1 -0
@@ -85,6 +85,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
@@ -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
PATCH v14 6/9 iio: imu: inv_icm42607: Add Accelerometer for icm42607
In reply to Chris MorganFrom: 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 | 309 ++++++++++++++++++ .../iio/imu/inv_icm42607/inv_icm42607_core.c | 169 ++++++++++ 4 files changed, 517 insertions(+) create mode 100644 drivers/iio/imu/inv_icm42607/inv_icm42607_accel.c
drivers/iio/imu/inv_icm42607/Makefile +1 -0
@@ -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
@@ -87,6 +87,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 ,
@@ -106,6 +117,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;
@@ -129,6 +141,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.
@@ -139,6 +152,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;
@@ -146,6 +160,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 */
@@ -374,8 +398,22 @@ 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_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 +309 -0
309 lines not on this page · raw message
drivers/iio/imu/inv_icm42607/inv_icm42607_core.c +169 -0
193 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v14 7/9 iio: imu: inv_icm42607: Add Gyroscope to icm42607
In reply to Chris MorganFrom: 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 | 305 ++++++++++++++++++ 4 files changed, 315 insertions(+) create mode 100644 drivers/iio/imu/inv_icm42607/inv_icm42607_gyro.c
drivers/iio/imu/inv_icm42607/Makefile +1 -0
@@ -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
@@ -142,6 +142,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.
@@ -153,6 +154,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;
@@ -414,6 +416,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
@@ -534,6 +534,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 +305 -0
305 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v14 8/9 iio: imu: inv_icm42607: Add Temp Support in icm42607
In reply to Chris MorganFrom: 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 | 8 ++ .../iio/imu/inv_icm42607/inv_icm42607_gyro.c | 8 ++ .../iio/imu/inv_icm42607/inv_icm42607_temp.c | 99 +++++++++++++++++++ .../iio/imu/inv_icm42607/inv_icm42607_temp.h | 37 +++++++ 5 files changed, 153 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
@@ -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 +8 -0
@@ -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,11 @@ static int inv_icm42607_accel_read_raw(struct iio_dev *indio_dev,switch (chan->type) {case IIO_ACCEL :break ; +case IIO_TEMP : +if (mask !=IIO_CHAN_INFO_SAMP_FREQ ) +return inv_icm42607_temp_read_raw (indio_dev, chan, + val, val2, mask); +break ;default :return -EINVAL ; }
drivers/iio/imu/inv_icm42607/inv_icm42607_gyro.c +8 -0
@@ -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 ] = {
@@ -182,6 +185,11 @@ static int inv_icm42607_gyro_read_raw(struct iio_dev *indio_dev,switch (chan->type) {case IIO_ANGL_VEL :break ; +case IIO_TEMP : +if (mask !=IIO_CHAN_INFO_SAMP_FREQ ) +return inv_icm42607_temp_read_raw (indio_dev, chan, + val, val2, mask); +break ;default :return -EINVAL ; }
drivers/iio/imu/inv_icm42607/inv_icm42607_temp.c new file +99 -0
99 lines not on this page · raw message
drivers/iio/imu/inv_icm42607/inv_icm42607_temp.h new file +37 -0
@@ -0,0 +1,37 @@ +/* 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, \ + }, \ +} + +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
PATCH v14 9/9 arm64: dts: rockchip: Add icm42607p IMU for RG-DS
In reply to Chris MorganFrom: 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
@@ -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
[email protected]
AI reviewRe: [PATCH V14 2/9] dt-bindings: iio: imu: icm42600: Add icm42607
In reply to Chris MorganThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] The new compatibles 'invensense,icm42607' and 'invensense,icm42607p' are omitted from the…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The new compatibles 'invensense,icm42607' and 'invensense,icm42607p' are omitted from the conditional block requiring the 'interrupts' property, violating Device Tree hardware description rules. --
commit dfee2e713ee93b8822c465d8c4cace6a935bc62d
Author: Chris Morgan <[email protected]>
dt-bindings: iio: imu: icm42600: Add icm42607
This commit adds the icm42607 and icm42607p inertial measurement unit device tree bindings. It also refactors the required properties to make the interrupts property conditional, explicitly omitting the newly added compatibles.
Quoted 3 lines
This device is functionally very similar to the icm42600 series with a very different register layout. The driver does not require an interrupt for these specific chip revisions.
[Severity: Medium]
Is it appropriate to omit the interrupts property based on driver behavior rather than hardware wiring?
Device tree bindings are meant to describe the hardware capabilities rather than specific operating system driver limitations. If the icm42607 hardware physically has an interrupt line, shouldn't it remain a required property regardless of whether the current driver uses it?
Quoted 4 lines
Documentation/devicetree/bindings/iio/imu/invensense,icm42600.yaml +0
-0
[ ... ]
Quoted 13 lines
Documentation/devicetree/bindings/iio/imu/invensense,icm42600.yaml +5
-1@@ -67,10 +69,24 @@ properties: required: - compatible - reg - - interrupts allOf: - $ref: /schemas/spi/spi-peripheral-props.yaml# + - if: + properties: + compatible: + contains: + enum:
Documentation/devicetree/bindings/iio/imu/invensense,icm42600.yaml properties: · line 89
Quoted 10 lines
Documentation/devicetree/bindings/iio/imu/invensense,icm42600.yaml +10
-0+ - invensense,icm42600 + - invensense,icm42602 + - invensense,icm42605 + - invensense,icm42622 + - invensense,icm42631 + - invensense,icm42686 + - invensense,icm42688 + then: + required: + - interrupts
[Severity: Medium]
Does omitting the newly added compatibles from this enum block bypass device tree schema validation for those variants?
If the hardware shares the same interrupt constraints as the previous generations listed here, device trees missing the interrupts property for invensense,icm42607 will now silently pass validation.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
[email protected]
AI reviewRe: [PATCH V14 6/9] iio: imu: inv_icm42607: Add Accelerometer for icm42607
In reply to Chris MorganThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] Missing update of software cache for sensor power mode causes unintended hardware power-downs.…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Missing update of software cache for sensor power mode causes unintended hardware power-downs.
- [Medium] Use of non-monotonic ktime_get_real() for hardware delay tracking.
--
commit 99de30070cdb6e08bed49a3aac077583415f3f84
Author: Chris Morgan <[email protected]>
Subject: iio: imu: inv_icm42607: Add Accelerometer for icm42607
This patch adds accelerometer sensor support for the icm42607 device. It introduces the accelerometer IIO channel configurations and integrates the sensor state management.
Quoted 4 lines
drivers/iio/imu/inv_icm42607/inv_icm42607_core.c +0
-0
[ ... ]
Quoted 1 line
drivers/iio/imu/inv_icm42607/inv_icm42607_core.c +0
-0@@ -106,6 +107,15 @@ const struct inv_icm42607_hw inv_icm42607p_hw_data = {
[ ... ]
Quoted 4 lines
drivers/iio/imu/inv_icm42607/inv_icm42607_core.c +4
-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) +{
[ ... ]
drivers/iio/imu/inv_icm42607/inv_icm42607_core.c
Quoted 3 lines
drivers/iio/imu/inv_icm42607/inv_icm42607_core.c +3
-0+if (!gyro && oldgyro) { + disable_wait =ktime_us_delta (st->conf.gyro_stop, +ktime_get_real ());
[Severity: Medium]
Is ktime_get_real() safe to use here for hardware delay tracking?
Because ktime_get_real() returns wall-clock time, it is susceptible to time jumps, such as an NTP synchronization.
If the clock jumps forwards while the gyroscope is being powered off, could the calculated disable_wait become negative and get clamped to 0, thereby bypassing the 45ms minimum on-time requirement?
Quoted 4 lines
drivers/iio/imu/inv_icm42607/inv_icm42607_core.c +4
-0+ disable_wait =clamp (disable_wait,0 , +INV_ICM42607_GYRO_STOP_TIME_US ); +fsleep (disable_wait); + }
[ ... ]
drivers/iio/imu/inv_icm42607/inv_icm42607_core.c
Quoted 5 lines
drivers/iio/imu/inv_icm42607/inv_icm42607_core.c +5
-0+if (gyro && !oldgyro) { + 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_real (), +INV_ICM42607_GYRO_STOP_TIME_US );
[Severity: Medium]
Would using a monotonic time source like ktime_get() prevent potential issues with time jumps during this delay calculation?
Quoted 6 lines
drivers/iio/imu/inv_icm42607/inv_icm42607_core.c +6
-0+ } + +fsleep (sleepval_us); + +return 0 ; +}
[ ... ]
Quoted 1 line
drivers/iio/imu/inv_icm42607/inv_icm42607_core.c +0
-0@@ -171,6 +181,160 @@ static int inv_icm42607_set_pwr_mgmt0(struct inv_icm42607_state *st,
[ ... ]
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) +{
[ ... ]
drivers/iio/imu/inv_icm42607/inv_icm42607_core.c static int inv_icm42607_set_pwr_mgmt0(struct inv_icm42607_state *st, · line 272
Quoted 5 lines
drivers/iio/imu/inv_icm42607/inv_icm42607_core.c +5
-0+if (chan_type ==IIO_ANGL_VEL ) +return inv_icm42607_set_pwr_mgmt0 (st, conf->mode, st->conf.accel.mode); + +return inv_icm42607_set_pwr_mgmt0 (st, st->conf.gyro.mode, conf->mode); +}
[Severity: High]
Does this code update the software state cache for the sensor mode?
It appears that inv_icm42607_set_sensor_conf() applies the new mode to the hardware by calling inv_icm42607_set_pwr_mgmt0(), but returns without saving conf->mode into oldconf->mode (or st->conf.accel.mode / st->conf.gyro.mode).
If this cache remains at its initial OFF value, could a subsequent configuration of the other sensor read this stale OFF state and erroneously power down the currently active sensor?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
[email protected]
AI reviewRe: [PATCH V14 8/9] iio: imu: inv_icm42607: Add Temp Support in icm42607
In reply to Chris MorganThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Low] Missing endianness initialization in INV_ICM42607_TEMP_CHAN. - [Low] Leftover commented-out…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Low] Missing endianness initialization in INV_ICM42607_TEMP_CHAN.
- [Low] Leftover commented-out developmental code.
--
commit a30ed1de671168873a3fd8263c138bbcda62583a
Author: Chris Morgan <[email protected]>
iio: imu: inv_icm42607: Add Temp Support in icm42607
Add functions for reading temperature sensor data.
Quoted 5 lines
drivers/iio/imu/inv_icm42607/inv_icm42607_temp.c new file +0
-0
[ ... ]
Quoted 2 lines
drivers/iio/imu/inv_icm42607/inv_icm42607_temp.c new file +2
-0+static int inv_icm42607_temp_read (struct inv_icm42607_state *st,s16 *temp) +{
[ ... ]
drivers/iio/imu/inv_icm42607/inv_icm42607_temp.c line 50
Quoted 6 lines
drivers/iio/imu/inv_icm42607/inv_icm42607_temp.c new file +6
-0+ accel_mode =FIELD_GET (INV_ICM42607_PWR_MGMT0_ACCEL_MODE_MASK , val); + gyro_mode =FIELD_GET (INV_ICM42607_PWR_MGMT0_GYRO_MODE_MASK , val); +if (!gyro_mode && !accel_mode) { +/* enable accel sensor */ + conf.mode =INV_ICM42607_SENSOR_MODE_LOW_NOISE ; +// ret = inv_icm42607_set_accel_conf(st, &conf);
[Severity: Low]
This isn't a bug, but should this commented-out line of code be removed from the final patch?
Quoted 4 lines
drivers/iio/imu/inv_icm42607/inv_icm42607_temp.c new file +4
-0+ ret =inv_icm42607_set_sensor_conf (st, &conf,IIO_ACCEL ); +if (ret) +return ret; + }
[ ... ]
Quoted 5 lines
drivers/iio/imu/inv_icm42607/inv_icm42607_temp.h new file +0
-0
[ ... ]
Quoted 7 lines
drivers/iio/imu/inv_icm42607/inv_icm42607_temp.h new file +7
-0+#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), \
drivers/iio/imu/inv_icm42607/inv_icm42607_temp.h line 30
Quoted 10 lines
drivers/iio/imu/inv_icm42607/inv_icm42607_temp.h new file +10
-0+ .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, \ + }, \
[Severity: Low]
Does this scan_type struct need its endianness field initialized to IIO_BE?
Since get_unaligned_be16() is used when reading the sensor data in inv_icm42607_temp_read(), it appears the hardware outputs big-endian data. Omitting the endianness here defaults to IIO_CPU (0), which differs from the gyro and accel channels that explicitly define it. Could this cause issues if IIO buffered reads are implemented later?
Quoted 1 line
+}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=8
[email protected]
AI reviewRe: [PATCH V14 5/9] iio: imu: inv_icm42607: Add PM support for icm42607
In reply to Chris MorganThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] The driver incorrectly uses the non-monotonic `ktime_get_real()` to measure the 45ms gyroscope…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The driver incorrectly uses the non-monotonic ktime_get_real() to measure the 45ms gyroscope power-off delay, risking bypassed hardware waits. --
commit d9cd3cdeff3488026816468ab782366517d43120
Author: Chris Morgan <[email protected]>
Subject: 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
[ ... ]
Quoted 23 lines
drivers/iio/imu/inv_icm42607/inv_icm42607_core.c +19
-0@@ -102,6 +106,71 @@ const struct inv_icm42607_hw inv_icm42607p_hw_data = { };EXPORT_SYMBOL_NS_GPL (inv_icm42607p_hw_data,"IIO_ICM42607" ); +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 =0 ; +unsigned int val; +s64 disable_wait; +int ret; + + ret =regmap_read (st->map,INV_ICM42607_REG_PWR_MGMT0 , &val); +if (ret) +return ret; + + oldaccel =FIELD_GET (INV_ICM42607_PWR_MGMT0_ACCEL_MODE_MASK , val); + oldgyro =FIELD_GET (INV_ICM42607_PWR_MGMT0_GYRO_MODE_MASK , val); + +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 137
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_real ());
[Severity: Medium]
Is it safe to use the non-monotonic ktime_get_real() here to measure the 45ms gyroscope power-off delay?
If the system wall-clock (CLOCK_REALTIME) is stepped forward concurrently (e.g., by an NTP sync), ktime_get_real() will jump forward. The calculated disable_wait could become negative, get clamped to 0, and completely bypass the mandatory wait before powering off the gyroscope, violating the datasheet constraint.
Would it be better to use a monotonic clock like ktime_get() here and when setting st->conf.gyro_stop below to track the elapsed interval reliably?
Quoted 35 lines
drivers/iio/imu/inv_icm42607/inv_icm42607_core.c +35
-0+ disable_wait =clamp (disable_wait,0 , +INV_ICM42607_GYRO_STOP_TIME_US ); +fsleep (disable_wait); + } + + val =FIELD_PREP (INV_ICM42607_PWR_MGMT0_GYRO_MODE_MASK , gyro); + val |=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. +*/ +if (accel && !oldaccel) + sleepval_us =max (sleepval_us,INV_ICM42607_ACCEL_STARTUP_TIME_US ); + +if (gyro && !oldgyro) { + 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_real (), +INV_ICM42607_GYRO_STOP_TIME_US ); + } + +fsleep (sleepval_us); + +return 0 ; +}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
Quoted 175 lines · Chris Morgan
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 existinginv_icm42600driver. 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.
- Usedguard()andPM_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 theMakefile).
- 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 theFIELD_PREPfrom header file to c files to make code easier to read.
- Changed scale values to 2D arrays for Gyro and Accelerometer.
- RemovedIIO_CHAN_INFO_CALIBBIASattribute.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 ofmax()tomin()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 optimizeinv_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.
- AddedFIELD_PREPin 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.
- Removediio_device_claim_direct()calls since it was no longer needed.
- Fixedshared_by_allattributes for temperature sensor.
- Additional miscellanous fixes as requested.Changes Since V12:
- Removed aligned buffer frominv_icm42607_statestruct 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:
- Refactoredinv_icm42607_set_accel_conf()andinv_icm42607_set_gyro_conf()into a single function.
- Refactoredinv_icm42607_accel_read_sensor()andinv_icm42607_gyro_read_sensor()into a single function.
- Mergedinv_icm42607_set_temp_conf()into initial init function since it only really needs to be called once.
- Saved adding temp sensor for last and updatedinv_icm42607_temp_read()to either confirm other sensors are already enabled or enable the accelerometer so it can get a reading.
- Updatedinv_icm42607_set_pwr_mgmt0()so that it does not update the sensor mode and forcibly keep the sensor enabled.
- Addedinv_icm42607_temp_filter_bwenums 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.Chris Morgan (9):
dt-bindings: iio: imu: icm42600: Add mount-matrix
dt-bindings: iio: imu: icm42600: Add icm42607
iio: imu:inv_icm42607: Addinv_icm42607Core 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 | 20 +- .../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 | 423 ++++++++++++ .../iio/imu/inv_icm42607/inv_icm42607_accel.c | 317 +++++++++ .../iio/imu/inv_icm42607/inv_icm42607_core.c | 606 ++++++++++++++++++ .../iio/imu/inv_icm42607/inv_icm42607_gyro.c | 313 +++++++++ .../iio/imu/inv_icm42607/inv_icm42607_i2c.c | 98 +++ .../iio/imu/inv_icm42607/inv_icm42607_spi.c | 108 ++++ .../iio/imu/inv_icm42607/inv_icm42607_temp.c | 99 +++ .../iio/imu/inv_icm42607/inv_icm42607_temp.h | 37 ++ 14 files changed, 2072 insertions(+), 2 deletions(-) create mode 100644 drivers/iio/imu/inv_icm42607/Kconfig create mode 100644 drivers/iio/imu/inv_icm42607/Makefile
Quoted 12 lines
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.hSignature · 1 line
2.43.0
I got sashiko.dev's review, and agree with everything except 2 points.
1) It asks "Is it appropriate to omit the interrupts property based on driver behavior rather than hardware wiring?" I would say no, but in my case the hardware is not wired for an interrupt so it's moot.
2) It asks "Does this code update the software state cache for the sensor mode?" No, it doesn't. The goal is for the device to stay powered up for up to 2 seconds until runtime PM turns it off if it isn't active, but I don't mind something turning around and shutting the hardware down if it's not in use before then. Anything that needs to read the specific sensor in question will be holding the mutex so that there shouldn't be a risk of another thread turning stuff off while I'm trying to use it, I don't think. What I want to avoid is calling to turn the hardware on for a one-shot read and then immediately turning it off once I'm done. I can wait the two seconds for runtime PM to do it when the alternative is to call the shutdown routine every single time for one-shot reads and wait for the startup and in the case of the gyro shutdown times otherwise.
Thoughts?
I can fix the remaining issues it points out and resubmit.
Thank you,
Chris
Jonathan Cameron
maintainerQuoted 59 lines · On Wed, 24 Jun 2026 16:18:23 -0500 Chris Morgan <[email protected]> wrote:
Quoted 46 lines
Changes Since V13:
- Refactoredinv_icm42607_set_accel_conf()andinv_icm42607_set_gyro_conf()into a single function.
- Refactoredinv_icm42607_accel_read_sensor()andinv_icm42607_gyro_read_sensor()into a single function.
- Mergedinv_icm42607_set_temp_conf()into initial init function since it only really needs to be called once.
- Saved adding temp sensor for last and updatedinv_icm42607_temp_read()to either confirm other sensors are already enabled or enable the accelerometer so it can get a reading.
- Updatedinv_icm42607_set_pwr_mgmt0()so that it does not update the sensor mode and forcibly keep the sensor enabled.
- Addedinv_icm42607_temp_filter_bwenums 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.Chris Morgan (9):
dt-bindings: iio: imu: icm42600: Add mount-matrix
dt-bindings: iio: imu: icm42600: Add icm42607
iio: imu:inv_icm42607: Addinv_icm42607Core 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 | 20 +- .../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 | 423 ++++++++++++ .../iio/imu/inv_icm42607/inv_icm42607_accel.c | 317 +++++++++ .../iio/imu/inv_icm42607/inv_icm42607_core.c | 606 ++++++++++++++++++ .../iio/imu/inv_icm42607/inv_icm42607_gyro.c | 313 +++++++++ .../iio/imu/inv_icm42607/inv_icm42607_i2c.c | 98 +++ .../iio/imu/inv_icm42607/inv_icm42607_spi.c | 108 ++++ .../iio/imu/inv_icm42607/inv_icm42607_temp.c | 99 +++ .../iio/imu/inv_icm42607/inv_icm42607_temp.h | 37 ++ 14 files changed, 2072 insertions(+), 2 deletions(-) create mode 100644 drivers/iio/imu/inv_icm42607/Kconfig create mode 100644 drivers/iio/imu/inv_icm42607/MakefileQuoted 12 lines
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.hSignature · 1 line
2.43.0
Quoted 5 lines
I got sashiko.dev's review, and agree with everything except 2 points.
1) It asks "Is it appropriate to omit the interrupts property based on driver behavior rather than hardware wiring?" I would say no, but in my case the hardware is not wired for an interrupt so it's moot.
I think the key thing it gets wrong is 'required'. Obviously an interrupt isn't required if it isn't wired ;) My only question is why is
it required for the other devices? That makes no sense - so I think you can get rid of that change to require it in the binding (I'll reply to v15)
Quoted 15 lines
2) It asks "Does this code update the software state cache for the sensor mode?" No, it doesn't. The goal is for the device to stay powered up for up to 2 seconds until runtime PM turns it off if it isn't active, but I don't mind something turning around and shutting the hardware down if it's not in use before then. Anything that needs to read the specific sensor in question will be holding the mutex so that there shouldn't be a risk of another thread turning stuff off while I'm trying to use it, I don't think. What I want to avoid is calling to turn the hardware on for a one-shot read and then immediately turning it off once I'm done. I can wait the two seconds for runtime PM to do it when the alternative is to call the shutdown routine every single time for one-shot reads and wait for the startup and in the case of the gyro shutdown times otherwise.
Quoted 2 lines
Thoughts?
As long as the locks are doing their jobs, this seems correct.
Jonathan
Quoted 4 lines
I can fix the remaining issues it points out and resubmit.
Thank you,
Chris