]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
iio: imu: inv_icm45600: add I3C driver for inv_icm45600 driver
authorRemi Buisson <remi.buisson@tdk.com>
Tue, 7 Oct 2025 07:20:09 +0000 (07:20 +0000)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Sun, 19 Oct 2025 10:59:21 +0000 (11:59 +0100)
Add I3C driver for InvenSense ICM-45600 devices.

Signed-off-by: Remi Buisson <remi.buisson@tdk.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/imu/inv_icm45600/Kconfig
drivers/iio/imu/inv_icm45600/Makefile
drivers/iio/imu/inv_icm45600/inv_icm45600_i3c.c [new file with mode: 0644]

index 01399d136a7ea3aa92a3a18ea455c95c0a6578b3..dc133402f6d75f8c050100e8475404e00993818b 100644 (file)
@@ -47,3 +47,24 @@ config INV_ICM45600_SPI
 
          This driver can be built as a module. The module will be called
          inv-icm45600-spi.
+
+config INV_ICM45600_I3C
+       tristate "InvenSense ICM-456xx I3C driver"
+       depends on I3C
+       select INV_ICM45600
+       select REGMAP_I3C
+       help
+         This driver supports the InvenSense ICM-456xx motion tracking
+         devices over I3C.
+         Supported devices:
+         - ICM-45605
+         - ICM-45606
+         - ICM-45608
+         - ICM-45634
+         - ICM-45686
+         - ICM-45687
+         - ICM-45688-P
+         - ICM-45689
+
+         This driver can be built as a module. The module will be called
+         inv-icm45600-i3c.
index 3692636d393a109a0ad68e955e1cad59005e9128..c98b8365b467de6abe9873e7ba3c0aca77f464e3 100644 (file)
@@ -11,3 +11,6 @@ inv-icm45600-i2c-y += inv_icm45600_i2c.o
 
 obj-$(CONFIG_INV_ICM45600_SPI) += inv-icm45600-spi.o
 inv-icm45600-spi-y += inv_icm45600_spi.o
+
+obj-$(CONFIG_INV_ICM45600_I3C) += inv-icm45600-i3c.o
+inv-icm45600-i3c-y += inv_icm45600_i3c.o
diff --git a/drivers/iio/imu/inv_icm45600/inv_icm45600_i3c.c b/drivers/iio/imu/inv_icm45600/inv_icm45600_i3c.c
new file mode 100644 (file)
index 0000000..b5df06b
--- /dev/null
@@ -0,0 +1,78 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/* Copyright (C) 2025 InvenSense, Inc. */
+
+#include <linux/err.h>
+#include <linux/mod_devicetable.h>
+#include <linux/module.h>
+#include <linux/regmap.h>
+
+#include <linux/i3c/device.h>
+#include <linux/i3c/master.h>
+
+#include "inv_icm45600.h"
+
+static const struct regmap_config inv_icm45600_regmap_config = {
+       .reg_bits = 8,
+       .val_bits = 8,
+};
+
+static const struct i3c_device_id inv_icm45600_i3c_ids[] = {
+       I3C_DEVICE_EXTRA_INFO(0x0235, 0x0000, 0x0011, (void *)NULL),
+       I3C_DEVICE_EXTRA_INFO(0x0235, 0x0000, 0x0084, (void *)NULL),
+       { /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(i3c, inv_icm45600_i3c_ids);
+
+static const struct inv_icm45600_chip_info *i3c_chip_info[] = {
+       &inv_icm45605_chip_info,
+       &inv_icm45606_chip_info,
+       &inv_icm45608_chip_info,
+       &inv_icm45634_chip_info,
+       &inv_icm45686_chip_info,
+       &inv_icm45687_chip_info,
+       &inv_icm45688p_chip_info,
+       &inv_icm45689_chip_info,
+};
+
+static int inv_icm45600_i3c_probe(struct i3c_device *i3cdev)
+{
+       int ret;
+       unsigned int whoami;
+       struct regmap *regmap;
+       const int nb_chip = ARRAY_SIZE(i3c_chip_info);
+       int chip;
+
+       regmap = devm_regmap_init_i3c(i3cdev, &inv_icm45600_regmap_config);
+       if (IS_ERR(regmap))
+               return dev_err_probe(&i3cdev->dev, PTR_ERR(regmap),
+                                       "Failed to register i3c regmap %ld\n", PTR_ERR(regmap));
+
+       ret = regmap_read(regmap, INV_ICM45600_REG_WHOAMI, &whoami);
+       if (ret)
+               return dev_err_probe(&i3cdev->dev, ret, "Failed to read part id %d\n", whoami);
+
+       for (chip = 0; chip < nb_chip; chip++) {
+               if (whoami == i3c_chip_info[chip]->whoami)
+                       break;
+       }
+
+       if (chip == nb_chip)
+               dev_err_probe(&i3cdev->dev, -ENODEV, "Failed to match part id %d\n", whoami);
+
+       return inv_icm45600_core_probe(regmap, i3c_chip_info[chip], false, NULL);
+}
+
+static struct i3c_driver inv_icm45600_driver = {
+       .driver = {
+               .name = "inv_icm45600_i3c",
+               .pm = pm_sleep_ptr(&inv_icm45600_pm_ops),
+       },
+       .probe = inv_icm45600_i3c_probe,
+       .id_table = inv_icm45600_i3c_ids,
+};
+module_i3c_driver(inv_icm45600_driver);
+
+MODULE_AUTHOR("Remi Buisson <remi.buisson@tdk.com>");
+MODULE_DESCRIPTION("InvenSense ICM-456xx i3c driver");
+MODULE_LICENSE("GPL");
+MODULE_IMPORT_NS("IIO_ICM45600");