[PATCH v2 0/3] Add driver for Invensense ICM42370P accelerometer

Kanak Shilledar posted 3 patches 1 month, 2 weeks ago
.../bindings/iio/accel/invensense,icm42370p.yaml   |   84 ++
MAINTAINERS                                        |    9 +
drivers/iio/accel/Kconfig                          |   18 +
drivers/iio/accel/Makefile                         |    6 +
drivers/iio/accel/inv_icm42370.h                   |  352 +++++
drivers/iio/accel/inv_icm42370_buffer.c            |  496 +++++++
drivers/iio/accel/inv_icm42370_buffer.h            |  100 ++
drivers/iio/accel/inv_icm42370_core.c              | 1502 ++++++++++++++++++++
drivers/iio/accel/inv_icm42370_i2c.c               |   93 ++
9 files changed, 2660 insertions(+)
[PATCH v2 0/3] Add driver for Invensense ICM42370P accelerometer
Posted by Kanak Shilledar 1 month, 2 weeks ago
Invensense ICM42370P is a high performance MEMS MotionTracking 3-axis
accelerometer. It supports I2C, I3C and SPI protocols. It has a 2.25kB
FIFO and two programmable interrupts with support for ultra-low-power
wake-on-motion support. It has a built-in temperature sensor. This
patch series adds basic support for the sensor with functionality of
performing raw reads and writes along with buffered reads via the I2C
interface.

This device contains 4 register banks for configuring the device called
MREG0, MREG1, MREG2 and MREG3. Unlike other devices from the same
vendor, this contains a very different way of accessing the register
banks apart from the default user bank 0 (MREG0). The register bank access
procedure is mentioned in the datasheet [1] Section 13. Due to this
specific reason and that it doesn't have a gyro sensor, it is implemented
as a standalone driver.

This device has 3 formats for the FIFO structure (datasheet [1] Section
6), currently only FIFO packet format 1 is supported, others
formats can be added as part of future work.

The device supports EDGE and LEVEL triggered interrupts, refer the dt-binding
for example of how the devicetree should be setup.

The driver is inspired from iio/imu/inv_icm42600.

Thanks to the reviewers for all the time you spent going through the
code and the comments. The changes for v2 are quite a lot and I hope
that every important change is documented in the changelog. After
implementing the suggested changes, the driver is in a far better state
than v1.

[1] https://uat.invensense.com/en-us/products/3-axis/icm-42370-p

Signed-off-by: Kanak Shilledar <kanak.shilledar@axis.com>
---
Changes in v2:
* Changes across all files
- Update MAINTAINERS with company mailing list
- Sort/Cleanup of includes
- Use `guard(mutex)` and newer `pm_runtime` APIs
- Fix code formatting and add empty lines
- Be consistent in inv_icm42370_data variable name
- Fix MODULE_DESCRIPTION
- Drop secondary state struct and merge it's properties in
  `inv_icm42370_data` struct
- Update mreg_read/write function calls
- Change the compatible and filename to `icm42370p`

* Changes to dt-binding
- Add dependencies property
- Made vdd and vddio supply as required
- Add description to drive-open-drain property
- Add mount-matrix property
- Add interrupt-names property

* Changes to `inv_icm42370.h` and `inv_icm42370_buffer.h`:
- Resturcture the file according to @Marcelo's advice
- Move struct __aligned properties to the end

* Changes to `inv_icm42370_core.c`:
- Fix _accel_scale[] values
- Add IIO_TIMESTAMP to channel spec
- Update mreg_read/write to fix bank access
- Replace usleep_range() with fsleep()
- Use constants from linux/units.h
- Call `_update_fifo_period()` after updating the ODR values
- Fix mathematical error in offset calculation
- Implement handling of mount matrix
- Implement handling of named interrupts
- Use devm_regulator_get_enable for the vdd/vddio regulators
- Use better error handling
- Move iio device registration after performing IRQ init

* Changes to `inv_icm42370_i2c.c`
- Change compatible string as per the binding
- Use named identifiers
- Add `id_table` to the i2c_driver struct

* Changes to `inv_icm42370_buffer.c`
- Update FIFO enable/disable logic
- Update FIFO buffer to match the specification and handle increased
  size dynamically.

- Link to v1: https://patch.msgid.link/20260806-b4-inv_icm42370p-v1-0-670837f5842f@axis.com

To: Kanak Shilledar <kanak.shilledar@axis.com>
To: Henrik Grimler <henrik.grimler@axis.com>
To: Jonathan Cameron <jic23@kernel.org>
To: David Lechner <dlechner@baylibre.com>
To: Nuno Sá <nuno.sa@analog.com>
To: Andy Shevchenko <andy@kernel.org>
To: Rob Herring <robh@kernel.org>
To: Krzysztof Kozlowski <krzk+dt@kernel.org>
To: Conor Dooley <conor+dt@kernel.org>
Cc: kernel@axis.com
Cc: linux-iio@vger.kernel.org
Cc: devicetree@vger.kernel.org
Cc: linux-kernel@vger.kernel.org

---
Kanak Shilledar (3):
      dt-bindings: Add InvenSense ICM-42370-p accelerometer
      iio: accel: Add support for ICM42370P
      iio: accel: icm42370: Add FIFO buffer functionality

 .../bindings/iio/accel/invensense,icm42370p.yaml   |   84 ++
 MAINTAINERS                                        |    9 +
 drivers/iio/accel/Kconfig                          |   18 +
 drivers/iio/accel/Makefile                         |    6 +
 drivers/iio/accel/inv_icm42370.h                   |  352 +++++
 drivers/iio/accel/inv_icm42370_buffer.c            |  496 +++++++
 drivers/iio/accel/inv_icm42370_buffer.h            |  100 ++
 drivers/iio/accel/inv_icm42370_core.c              | 1502 ++++++++++++++++++++
 drivers/iio/accel/inv_icm42370_i2c.c               |   93 ++
 9 files changed, 2660 insertions(+)
---
base-commit: 350d1fb9204b13c5f95e511e98b8bcb47574d425
change-id: 20260629-b4-inv_icm42370p-ccd671066bcf

Best regards,
--  
Kanak Shilledar <kanak.shilledar@axis.com>

Re: [PATCH v2 0/3] Add driver for Invensense ICM42370P accelerometer
Posted by Andy Shevchenko 1 month, 1 week ago
On Thu, Aug 13, 2026 at 02:26:09PM +0200, Kanak Shilledar wrote:
> Invensense ICM42370P is a high performance MEMS MotionTracking 3-axis
> accelerometer. It supports I2C, I3C and SPI protocols. It has a 2.25kB
> FIFO and two programmable interrupts with support for ultra-low-power
> wake-on-motion support. It has a built-in temperature sensor. This
> patch series adds basic support for the sensor with functionality of
> performing raw reads and writes along with buffered reads via the I2C
> interface.
> 
> This device contains 4 register banks for configuring the device called
> MREG0, MREG1, MREG2 and MREG3. Unlike other devices from the same
> vendor, this contains a very different way of accessing the register
> banks apart from the default user bank 0 (MREG0). The register bank access
> procedure is mentioned in the datasheet [1] Section 13. Due to this
> specific reason and that it doesn't have a gyro sensor, it is implemented
> as a standalone driver.
> 
> This device has 3 formats for the FIFO structure (datasheet [1] Section
> 6), currently only FIFO packet format 1 is supported, others
> formats can be added as part of future work.
> 
> The device supports EDGE and LEVEL triggered interrupts, refer the dt-binding
> for example of how the devicetree should be setup.
> 
> The driver is inspired from iio/imu/inv_icm42600.
> 
> Thanks to the reviewers for all the time you spent going through the
> code and the comments. The changes for v2 are quite a lot and I hope
> that every important change is documented in the changelog. After
> implementing the suggested changes, the driver is in a far better state
> than v1.

> [1] https://uat.invensense.com/en-us/products/3-axis/icm-42370-p

Can be added as a Datasheet tag here (and be spread by `b4` to all patches in
the series, which I think is fine).

Can you split the first patch to be based on the features implemented?
Something like

- patch 0: DT binding
- patch 1: very basic (but working) driver
- patch 2...n: Features 1...(n-1)

-- 
With Best Regards,
Andy Shevchenko
Re: [PATCH v2 0/3] Add driver for Invensense ICM42370P accelerometer
Posted by Kanak Shilledar 1 month, 1 week ago
Hi Andy,
Thanks for the comments.

On Mon, 2026-08-17 at 10:19 +0300, Andy Shevchenko wrote:
> [Some people who received this message don't often get email from
> andriy.shevchenko@intel.com. Learn why this is important at
> https://aka.ms/LearnAboutSenderIdentification ]
> 
> On Thu, Aug 13, 2026 at 02:26:09PM +0200, Kanak Shilledar wrote:
> > Invensense ICM42370P is a high performance MEMS MotionTracking 3-
> > axis
> > accelerometer. It supports I2C, I3C and SPI protocols. It has a
> > 2.25kB
> > 
> > The driver is inspired from iio/imu/inv_icm42600.
> > 
> > Thanks to the reviewers for all the time you spent going through
> > the
> > code and the comments. The changes for v2 are quite a lot and I
> > hope
> > that every important change is documented in the changelog. After
> > implementing the suggested changes, the driver is in a far better
> > state
> > than v1.
> 
> > [1] https://uat.invensense.com/en-us/products/3-axis/icm-42370-p
> 
> Can be added as a Datasheet tag here (and be spread by `b4` to all
> patches in
> the series, which I think is fine).

Thanks, for pointing that out. We will use "Datasheet:" in our next
version.
> 
> Can you split the first patch to be based on the features
> implemented?
> Something like
> 
> - patch 0: DT binding
> - patch 1: very basic (but working) driver
> - patch 2...n: Features 1...(n-1)

As @jonathan said to squash the two files (buffer.c and core.c into
just core.c), I split out the implementation in various commits. Here
is what I plan to split them into, let me know if you think anything
else should be split into multiple commits.

* patch 0: DT binding
* patch 1: basic working driver
* patch 2: implementing temperature sensor
* patch 3: implementation of accelerometer configuration and power
management
* patch 4: implementing user bank switching (mreg_read/write)
* patch 5: implemtation of timestamp related things
* patch 6: implementing advanced accelerometer parts
* patch 7: parsing of mount-matrix
* patch 8: add basic irq handler and parse devicetree interrupts
* patch 9: adding buffer support

The buffer functionality has a lot of dependent changes and thus
splitting them may cause "unused-functions/symbols" warnings. So, it is
better to have them in a single commit.

> --
> With Best Regards,
> Andy Shevchenko

Thanks and Regards,
Kanak Shilledar