All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/6] Add support of similar chips
@ 2020-02-06 10:30 Jean-Baptiste Maneyrol
  2020-02-06 10:31 ` [PATCH v2 1/6] iio: imu: inv_mpu6050: cleanup of/acpi support Jean-Baptiste Maneyrol
                   ` (5 more replies)
  0 siblings, 6 replies; 14+ messages in thread
From: Jean-Baptiste Maneyrol @ 2020-02-06 10:30 UTC (permalink / raw)
  To: Jonathan Cameron, linux-iio, devicetree
  Cc: Rob Herring, Mark Rutland, Jean-Baptiste Maneyrol

This series add support of new chips that are similar to the ones already
supported.

Add correct OF support for spi and modify low-pass filter settings to
support correctly all the chips.

Changelog:
- v2
    * Rework of/acpi support for spi and i2c using device_get_match_data
    * Merge all dt-bindings patches in 1
    * Change the LPF bandwith setting patch description since it is not
      a fix (required only with the addition of the new chips)

Jean-Baptiste Maneyrol (6):
  iio: imu: inv_mpu6050: cleanup of/acpi support
  iio: imu: inv_mpu6050: add support of ICM20609 & ICM20689
  iio: imu: inv_mpu6050: add support of IAM20680
  iio: imu: inv_mpu6050: add support of ICM20690
  iio: imu: inv_mpu6050: update LPF bandwidth settings
  dt-bindings: add description for new supported chips

 .../bindings/iio/imu/inv_mpu6050.txt          |   5 +
 drivers/iio/imu/inv_mpu6050/Kconfig           |  12 +--
 drivers/iio/imu/inv_mpu6050/inv_mpu_core.c    | 100 ++++++++++++++----
 drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c     |  49 +++++----
 drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h     |  20 +++-
 drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c     |  64 ++++++++++-
 6 files changed, 192 insertions(+), 58 deletions(-)

-- 
2.17.1


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH v2 1/6] iio: imu: inv_mpu6050: cleanup of/acpi support
  2020-02-06 10:30 [PATCH v2 0/6] Add support of similar chips Jean-Baptiste Maneyrol
@ 2020-02-06 10:31 ` Jean-Baptiste Maneyrol
  2020-02-06 11:51   ` Jonathan Cameron
  2020-02-06 10:31 ` [PATCH v2 2/6] iio: imu: inv_mpu6050: add support of ICM20609 & ICM20689 Jean-Baptiste Maneyrol
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 14+ messages in thread
From: Jean-Baptiste Maneyrol @ 2020-02-06 10:31 UTC (permalink / raw)
  To: Jonathan Cameron, linux-iio, devicetree
  Cc: Rob Herring, Mark Rutland, Jean-Baptiste Maneyrol

Use device_get_match_data for using of and acpi tables.
In spi support add missing mpu6515 and of match table.
Reorganize Kconfig to display chips grouped by generations.

Signed-off-by: Jean-Baptiste Maneyrol <jmaneyrol@invensense.com>
---
 drivers/iio/imu/inv_mpu6050/Kconfig       |  8 ++---
 drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c | 26 +++-----------
 drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c | 44 +++++++++++++++++++++--
 3 files changed, 50 insertions(+), 28 deletions(-)

diff --git a/drivers/iio/imu/inv_mpu6050/Kconfig b/drivers/iio/imu/inv_mpu6050/Kconfig
index 017bc0fcc365..003134734646 100644
--- a/drivers/iio/imu/inv_mpu6050/Kconfig
+++ b/drivers/iio/imu/inv_mpu6050/Kconfig
@@ -15,8 +15,8 @@ config INV_MPU6050_I2C
 	select INV_MPU6050_IIO
 	select REGMAP_I2C
 	help
-	  This driver supports the Invensense MPU6050/6500/6515,
-	  MPU9150/9250/9255 and ICM20608/20602 motion tracking devices
+	  This driver supports the Invensense MPU6050/9150,
+	  MPU6500/6515/9250/9255, ICM20608 and ICM20602 motion tracking devices
 	  over I2C.
 	  This driver can be built as a module. The module will be called
 	  inv-mpu6050-i2c.
@@ -27,8 +27,8 @@ config INV_MPU6050_SPI
 	select INV_MPU6050_IIO
 	select REGMAP_SPI
 	help
-	  This driver supports the Invensense MPU6000/6500/6515,
-	  MPU9250/9255 and ICM20608/20602 motion tracking devices
+	  This driver supports the Invensense MPU6000,
+	  MPU6500/6515/9250/9255, ICM20608 and ICM20602 motion tracking devices
 	  over SPI.
 	  This driver can be built as a module. The module will be called
 	  inv-mpu6050-spi.
diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c
index f47a28b4be23..49e9aa777ba4 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c
@@ -10,6 +10,7 @@
 #include <linux/iio/iio.h>
 #include <linux/module.h>
 #include <linux/of_device.h>
+#include <linux/property.h>
 #include "inv_mpu_iio.h"
 
 static const struct regmap_config inv_mpu_regmap_config = {
@@ -54,20 +55,6 @@ static int inv_mpu6050_deselect_bypass(struct i2c_mux_core *muxc, u32 chan_id)
 	return 0;
 }
 
-static const char *inv_mpu_match_acpi_device(struct device *dev,
-					     enum inv_devices *chip_id)
-{
-	const struct acpi_device_id *id;
-
-	id = acpi_match_device(dev->driver->acpi_match_table, dev);
-	if (!id)
-		return NULL;
-
-	*chip_id = (int)id->driver_data;
-
-	return dev_name(dev);
-}
-
 static bool inv_mpu_i2c_aux_bus(struct device *dev)
 {
 	struct inv_mpu6050_state *st = iio_priv(dev_get_drvdata(dev));
@@ -130,6 +117,7 @@ static int inv_mpu_magn_disable(struct iio_dev *indio_dev)
 static int inv_mpu_probe(struct i2c_client *client,
 			 const struct i2c_device_id *id)
 {
+	const void *match;
 	struct inv_mpu6050_state *st;
 	int result;
 	enum inv_devices chip_type;
@@ -140,18 +128,14 @@ static int inv_mpu_probe(struct i2c_client *client,
 				     I2C_FUNC_SMBUS_I2C_BLOCK))
 		return -EOPNOTSUPP;
 
-	if (client->dev.of_node) {
-		chip_type = (enum inv_devices)
-			of_device_get_match_data(&client->dev);
+	match = device_get_match_data(&client->dev);
+	if (match) {
+		chip_type = (enum inv_devices)match;
 		name = client->name;
 	} else if (id) {
 		chip_type = (enum inv_devices)
 			id->driver_data;
 		name = id->name;
-	} else if (ACPI_HANDLE(&client->dev)) {
-		name = inv_mpu_match_acpi_device(&client->dev, &chip_type);
-		if (!name)
-			return -ENODEV;
 	} else {
 		return -ENOSYS;
 	}
diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c
index ec102d5a5c77..834bfa8e8684 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c
@@ -4,6 +4,8 @@
 */
 #include <linux/module.h>
 #include <linux/acpi.h>
+#include <linux/of.h>
+#include <linux/property.h>
 #include <linux/spi/spi.h>
 #include <linux/regmap.h>
 #include <linux/iio/iio.h>
@@ -41,17 +43,18 @@ static int inv_mpu_i2c_disable(struct iio_dev *indio_dev)
 
 static int inv_mpu_probe(struct spi_device *spi)
 {
+	const void *match;
 	struct regmap *regmap;
 	const struct spi_device_id *spi_id;
-	const struct acpi_device_id *acpi_id;
 	const char *name = NULL;
 	enum inv_devices chip_type;
 
 	if ((spi_id = spi_get_device_id(spi))) {
 		chip_type = (enum inv_devices)spi_id->driver_data;
 		name = spi_id->name;
-	} else if ((acpi_id = acpi_match_device(spi->dev.driver->acpi_match_table, &spi->dev))) {
-		chip_type = (enum inv_devices)acpi_id->driver_data;
+	} else if ((match = device_get_match_data(&spi->dev))) {
+		chip_type = (enum inv_devices)match;
+		name = dev_name(&spi->dev);
 	} else {
 		return -ENODEV;
 	}
@@ -74,6 +77,7 @@ static int inv_mpu_probe(struct spi_device *spi)
 static const struct spi_device_id inv_mpu_id[] = {
 	{"mpu6000", INV_MPU6000},
 	{"mpu6500", INV_MPU6500},
+	{"mpu6515", INV_MPU6515},
 	{"mpu9250", INV_MPU9250},
 	{"mpu9255", INV_MPU9255},
 	{"icm20608", INV_ICM20608},
@@ -83,6 +87,39 @@ static const struct spi_device_id inv_mpu_id[] = {
 
 MODULE_DEVICE_TABLE(spi, inv_mpu_id);
 
+static const struct of_device_id inv_of_match[] = {
+	{
+		.compatible = "invensense,mpu6000",
+		.data = (void *)INV_MPU6000
+	},
+	{
+		.compatible = "invensense,mpu6500",
+		.data = (void *)INV_MPU6500
+	},
+	{
+		.compatible = "invensense,mpu6515",
+		.data = (void *)INV_MPU6515
+	},
+	{
+		.compatible = "invensense,mpu9250",
+		.data = (void *)INV_MPU9250
+	},
+	{
+		.compatible = "invensense,mpu9255",
+		.data = (void *)INV_MPU9255
+	},
+	{
+		.compatible = "invensense,icm20608",
+		.data = (void *)INV_ICM20608
+	},
+	{
+		.compatible = "invensense,icm20602",
+		.data = (void *)INV_ICM20602
+	},
+	{ }
+};
+MODULE_DEVICE_TABLE(of, inv_of_match);
+
 static const struct acpi_device_id inv_acpi_match[] = {
 	{"INVN6000", INV_MPU6000},
 	{ },
@@ -93,6 +130,7 @@ static struct spi_driver inv_mpu_driver = {
 	.probe		=	inv_mpu_probe,
 	.id_table	=	inv_mpu_id,
 	.driver = {
+		.of_match_table = inv_of_match,
 		.acpi_match_table = ACPI_PTR(inv_acpi_match),
 		.name	=	"inv-mpu6000-spi",
 		.pm     =       &inv_mpu_pmops,
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH v2 2/6] iio: imu: inv_mpu6050: add support of ICM20609 & ICM20689
  2020-02-06 10:30 [PATCH v2 0/6] Add support of similar chips Jean-Baptiste Maneyrol
  2020-02-06 10:31 ` [PATCH v2 1/6] iio: imu: inv_mpu6050: cleanup of/acpi support Jean-Baptiste Maneyrol
@ 2020-02-06 10:31 ` Jean-Baptiste Maneyrol
  2020-02-06 11:53   ` Jonathan Cameron
  2020-02-06 10:31 ` [PATCH v2 3/6] iio: imu: inv_mpu6050: add support of IAM20680 Jean-Baptiste Maneyrol
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 14+ messages in thread
From: Jean-Baptiste Maneyrol @ 2020-02-06 10:31 UTC (permalink / raw)
  To: Jonathan Cameron, linux-iio, devicetree
  Cc: Rob Herring, Mark Rutland, Jean-Baptiste Maneyrol

They are similar to ICM20608 chip.

Signed-off-by: Jean-Baptiste Maneyrol <jmaneyrol@invensense.com>
---
 drivers/iio/imu/inv_mpu6050/Kconfig        |  8 +++----
 drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 26 ++++++++++++++++++----
 drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c  | 12 ++++++++++
 drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h  |  5 +++++
 drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c  | 10 +++++++++
 5 files changed, 53 insertions(+), 8 deletions(-)

diff --git a/drivers/iio/imu/inv_mpu6050/Kconfig b/drivers/iio/imu/inv_mpu6050/Kconfig
index 003134734646..e933db3a5a89 100644
--- a/drivers/iio/imu/inv_mpu6050/Kconfig
+++ b/drivers/iio/imu/inv_mpu6050/Kconfig
@@ -16,8 +16,8 @@ config INV_MPU6050_I2C
 	select REGMAP_I2C
 	help
 	  This driver supports the Invensense MPU6050/9150,
-	  MPU6500/6515/9250/9255, ICM20608 and ICM20602 motion tracking devices
-	  over I2C.
+	  MPU6500/6515/9250/9255, ICM20608/20609/20689 and ICM20602
+	  motion tracking devices over I2C.
 	  This driver can be built as a module. The module will be called
 	  inv-mpu6050-i2c.
 
@@ -28,7 +28,7 @@ config INV_MPU6050_SPI
 	select REGMAP_SPI
 	help
 	  This driver supports the Invensense MPU6000,
-	  MPU6500/6515/9250/9255, ICM20608 and ICM20602 motion tracking devices
-	  over SPI.
+	  MPU6500/6515/9250/9255, ICM20608/20609/20689 and ICM20602
+	  motion tracking devices over SPI.
 	  This driver can be built as a module. The module will be called
 	  inv-mpu6050-spi.
diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
index 5096fc49012d..5fd57a1bee90 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
@@ -176,6 +176,22 @@ static const struct inv_mpu6050_hw hw_info[] = {
 		.fifo_size = 512,
 		.temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE},
 	},
+	{
+		.whoami = INV_ICM20609_WHOAMI_VALUE,
+		.name = "ICM20609",
+		.reg = &reg_set_6500,
+		.config = &chip_config_6050,
+		.fifo_size = 4 * 1024,
+		.temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE},
+	},
+	{
+		.whoami = INV_ICM20689_WHOAMI_VALUE,
+		.name = "ICM20689",
+		.reg = &reg_set_6500,
+		.config = &chip_config_6050,
+		.fifo_size = 4 * 1024,
+		.temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE},
+	},
 	{
 		.whoami = INV_ICM20602_WHOAMI_VALUE,
 		.name = "ICM20602",
@@ -286,20 +302,22 @@ static int inv_mpu6050_set_lpf_regs(struct inv_mpu6050_state *st,
 	if (result)
 		return result;
 
+	/* set accel lpf */
 	switch (st->chip_type) {
 	case INV_MPU6050:
 	case INV_MPU6000:
 	case INV_MPU9150:
 		/* old chips, nothing to do */
-		result = 0;
+		return 0;
+	case INV_ICM20689:
+		/* set FIFO size to maximum value */
+		val |= INV_ICM20689_BITS_FIFO_SIZE_MAX;
 		break;
 	default:
-		/* set accel lpf */
-		result = regmap_write(st->map, st->reg->accel_lpf, val);
 		break;
 	}
 
-	return result;
+	return regmap_write(st->map, st->reg->accel_lpf, val);
 }
 
 /**
diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c
index 49e9aa777ba4..dd054e21216a 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c
@@ -61,6 +61,8 @@ static bool inv_mpu_i2c_aux_bus(struct device *dev)
 
 	switch (st->chip_type) {
 	case INV_ICM20608:
+	case INV_ICM20609:
+	case INV_ICM20689:
 	case INV_ICM20602:
 		/* no i2c auxiliary bus on the chip */
 		return false;
@@ -202,6 +204,8 @@ static const struct i2c_device_id inv_mpu_id[] = {
 	{"mpu9250", INV_MPU9250},
 	{"mpu9255", INV_MPU9255},
 	{"icm20608", INV_ICM20608},
+	{"icm20609", INV_ICM20609},
+	{"icm20689", INV_ICM20689},
 	{"icm20602", INV_ICM20602},
 	{}
 };
@@ -237,6 +241,14 @@ static const struct of_device_id inv_of_match[] = {
 		.compatible = "invensense,icm20608",
 		.data = (void *)INV_ICM20608
 	},
+	{
+		.compatible = "invensense,icm20609",
+		.data = (void *)INV_ICM20609
+	},
+	{
+		.compatible = "invensense,icm20689",
+		.data = (void *)INV_ICM20689
+	},
 	{
 		.compatible = "invensense,icm20602",
 		.data = (void *)INV_ICM20602
diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
index 6158fca7f70e..75b8903450eb 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
@@ -75,6 +75,8 @@ enum inv_devices {
 	INV_MPU9250,
 	INV_MPU9255,
 	INV_ICM20608,
+	INV_ICM20609,
+	INV_ICM20689,
 	INV_ICM20602,
 	INV_NUM_PARTS
 };
@@ -276,6 +278,7 @@ struct inv_mpu6050_state {
 
 /* mpu6500 registers */
 #define INV_MPU6500_REG_ACCEL_CONFIG_2      0x1D
+#define INV_ICM20689_BITS_FIFO_SIZE_MAX     0xC0
 #define INV_MPU6500_REG_ACCEL_OFFSET        0x77
 
 /* delay time in milliseconds */
@@ -340,6 +343,8 @@ struct inv_mpu6050_state {
 #define INV_MPU9255_WHOAMI_VALUE		0x73
 #define INV_MPU6515_WHOAMI_VALUE		0x74
 #define INV_ICM20608_WHOAMI_VALUE		0xAF
+#define INV_ICM20609_WHOAMI_VALUE		0xA6
+#define INV_ICM20689_WHOAMI_VALUE		0x98
 #define INV_ICM20602_WHOAMI_VALUE		0x12
 
 /* scan element definition for generic MPU6xxx devices */
diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c
index 834bfa8e8684..3803c40e7b24 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c
@@ -81,6 +81,8 @@ static const struct spi_device_id inv_mpu_id[] = {
 	{"mpu9250", INV_MPU9250},
 	{"mpu9255", INV_MPU9255},
 	{"icm20608", INV_ICM20608},
+	{"icm20609", INV_ICM20609},
+	{"icm20689", INV_ICM20689},
 	{"icm20602", INV_ICM20602},
 	{}
 };
@@ -112,6 +114,14 @@ static const struct of_device_id inv_of_match[] = {
 		.compatible = "invensense,icm20608",
 		.data = (void *)INV_ICM20608
 	},
+	{
+		.compatible = "invensense,icm20609",
+		.data = (void *)INV_ICM20609
+	},
+	{
+		.compatible = "invensense,icm20689",
+		.data = (void *)INV_ICM20689
+	},
 	{
 		.compatible = "invensense,icm20602",
 		.data = (void *)INV_ICM20602
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH v2 3/6] iio: imu: inv_mpu6050: add support of IAM20680
  2020-02-06 10:30 [PATCH v2 0/6] Add support of similar chips Jean-Baptiste Maneyrol
  2020-02-06 10:31 ` [PATCH v2 1/6] iio: imu: inv_mpu6050: cleanup of/acpi support Jean-Baptiste Maneyrol
  2020-02-06 10:31 ` [PATCH v2 2/6] iio: imu: inv_mpu6050: add support of ICM20609 & ICM20689 Jean-Baptiste Maneyrol
@ 2020-02-06 10:31 ` Jean-Baptiste Maneyrol
  2020-02-06 12:09   ` Jonathan Cameron
  2020-02-06 10:31 ` [PATCH v2 4/6] iio: imu: inv_mpu6050: add support of ICM20690 Jean-Baptiste Maneyrol
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 14+ messages in thread
From: Jean-Baptiste Maneyrol @ 2020-02-06 10:31 UTC (permalink / raw)
  To: Jonathan Cameron, linux-iio, devicetree
  Cc: Rob Herring, Mark Rutland, Jean-Baptiste Maneyrol

Automotive certified IMU, similar to ICM20608.

Signed-off-by: Jean-Baptiste Maneyrol <jmaneyrol@invensense.com>
---
 drivers/iio/imu/inv_mpu6050/Kconfig        | 4 ++--
 drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 8 ++++++++
 drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c  | 6 ++++++
 drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h  | 2 ++
 drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c  | 5 +++++
 5 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/imu/inv_mpu6050/Kconfig b/drivers/iio/imu/inv_mpu6050/Kconfig
index e933db3a5a89..e65474a64675 100644
--- a/drivers/iio/imu/inv_mpu6050/Kconfig
+++ b/drivers/iio/imu/inv_mpu6050/Kconfig
@@ -16,7 +16,7 @@ config INV_MPU6050_I2C
 	select REGMAP_I2C
 	help
 	  This driver supports the Invensense MPU6050/9150,
-	  MPU6500/6515/9250/9255, ICM20608/20609/20689 and ICM20602
+	  MPU6500/6515/9250/9255, ICM20608/20609/20689, ICM20602 and IAM20680
 	  motion tracking devices over I2C.
 	  This driver can be built as a module. The module will be called
 	  inv-mpu6050-i2c.
@@ -28,7 +28,7 @@ config INV_MPU6050_SPI
 	select REGMAP_SPI
 	help
 	  This driver supports the Invensense MPU6000,
-	  MPU6500/6515/9250/9255, ICM20608/20609/20689 and ICM20602
+	  MPU6500/6515/9250/9255, ICM20608/20609/20689, ICM20602 and IAM20680
 	  motion tracking devices over SPI.
 	  This driver can be built as a module. The module will be called
 	  inv-mpu6050-spi.
diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
index 5fd57a1bee90..e8e6beef3f04 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
@@ -200,6 +200,14 @@ static const struct inv_mpu6050_hw hw_info[] = {
 		.fifo_size = 1008,
 		.temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE},
 	},
+	{
+		.whoami = INV_IAM20680_WHOAMI_VALUE,
+		.name = "IAM20680",
+		.reg = &reg_set_6500,
+		.config = &chip_config_6050,
+		.fifo_size = 512,
+		.temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE},
+	},
 };
 
 int inv_mpu6050_switch_engine(struct inv_mpu6050_state *st, bool en, u32 mask)
diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c
index dd054e21216a..cd0eeb5dc7f6 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c
@@ -64,6 +64,7 @@ static bool inv_mpu_i2c_aux_bus(struct device *dev)
 	case INV_ICM20609:
 	case INV_ICM20689:
 	case INV_ICM20602:
+	case INV_IAM20680:
 		/* no i2c auxiliary bus on the chip */
 		return false;
 	case INV_MPU9150:
@@ -207,6 +208,7 @@ static const struct i2c_device_id inv_mpu_id[] = {
 	{"icm20609", INV_ICM20609},
 	{"icm20689", INV_ICM20689},
 	{"icm20602", INV_ICM20602},
+	{"iam20680", INV_IAM20680},
 	{}
 };
 
@@ -253,6 +255,10 @@ static const struct of_device_id inv_of_match[] = {
 		.compatible = "invensense,icm20602",
 		.data = (void *)INV_ICM20602
 	},
+	{
+		.compatible = "invensense,iam20680",
+		.data = (void *)INV_IAM20680
+	},
 	{ }
 };
 MODULE_DEVICE_TABLE(of, inv_of_match);
diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
index 75b8903450eb..404c289f8c84 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
@@ -78,6 +78,7 @@ enum inv_devices {
 	INV_ICM20609,
 	INV_ICM20689,
 	INV_ICM20602,
+	INV_IAM20680,
 	INV_NUM_PARTS
 };
 
@@ -346,6 +347,7 @@ struct inv_mpu6050_state {
 #define INV_ICM20609_WHOAMI_VALUE		0xA6
 #define INV_ICM20689_WHOAMI_VALUE		0x98
 #define INV_ICM20602_WHOAMI_VALUE		0x12
+#define INV_IAM20680_WHOAMI_VALUE		0xA9
 
 /* scan element definition for generic MPU6xxx devices */
 enum inv_mpu6050_scan {
diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c
index 3803c40e7b24..393cec555be6 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c
@@ -84,6 +84,7 @@ static const struct spi_device_id inv_mpu_id[] = {
 	{"icm20609", INV_ICM20609},
 	{"icm20689", INV_ICM20689},
 	{"icm20602", INV_ICM20602},
+	{"iam20680", INV_IAM20680},
 	{}
 };
 
@@ -126,6 +127,10 @@ static const struct of_device_id inv_of_match[] = {
 		.compatible = "invensense,icm20602",
 		.data = (void *)INV_ICM20602
 	},
+	{
+		.compatible = "invensense,iam20680",
+		.data = (void *)INV_IAM20680
+	},
 	{ }
 };
 MODULE_DEVICE_TABLE(of, inv_of_match);
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH v2 4/6] iio: imu: inv_mpu6050: add support of ICM20690
  2020-02-06 10:30 [PATCH v2 0/6] Add support of similar chips Jean-Baptiste Maneyrol
                   ` (2 preceding siblings ...)
  2020-02-06 10:31 ` [PATCH v2 3/6] iio: imu: inv_mpu6050: add support of IAM20680 Jean-Baptiste Maneyrol
@ 2020-02-06 10:31 ` Jean-Baptiste Maneyrol
  2020-02-06 12:15   ` Jonathan Cameron
  2020-02-06 10:31 ` [PATCH v2 5/6] iio: imu: inv_mpu6050: update LPF bandwidth settings Jean-Baptiste Maneyrol
  2020-02-06 10:31 ` [PATCH v2 6/6] dt-bindings: add description for new supported chips Jean-Baptiste Maneyrol
  5 siblings, 1 reply; 14+ messages in thread
From: Jean-Baptiste Maneyrol @ 2020-02-06 10:31 UTC (permalink / raw)
  To: Jonathan Cameron, linux-iio, devicetree
  Cc: Rob Herring, Mark Rutland, Jean-Baptiste Maneyrol

Same generation as ICM20602 but different registers.

Signed-off-by: Jean-Baptiste Maneyrol <jmaneyrol@invensense.com>
---
 drivers/iio/imu/inv_mpu6050/Kconfig        |  8 ++---
 drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 36 +++++++++++++++++++---
 drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c  |  5 +++
 drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h  |  3 ++
 drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c  |  5 +++
 5 files changed, 48 insertions(+), 9 deletions(-)

diff --git a/drivers/iio/imu/inv_mpu6050/Kconfig b/drivers/iio/imu/inv_mpu6050/Kconfig
index e65474a64675..7137ea6f25db 100644
--- a/drivers/iio/imu/inv_mpu6050/Kconfig
+++ b/drivers/iio/imu/inv_mpu6050/Kconfig
@@ -16,8 +16,8 @@ config INV_MPU6050_I2C
 	select REGMAP_I2C
 	help
 	  This driver supports the Invensense MPU6050/9150,
-	  MPU6500/6515/9250/9255, ICM20608/20609/20689, ICM20602 and IAM20680
-	  motion tracking devices over I2C.
+	  MPU6500/6515/9250/9255, ICM20608/20609/20689, ICM20602/ICM20690 and
+	  IAM20680 motion tracking devices over I2C.
 	  This driver can be built as a module. The module will be called
 	  inv-mpu6050-i2c.
 
@@ -28,7 +28,7 @@ config INV_MPU6050_SPI
 	select REGMAP_SPI
 	help
 	  This driver supports the Invensense MPU6000,
-	  MPU6500/6515/9250/9255, ICM20608/20609/20689, ICM20602 and IAM20680
-	  motion tracking devices over SPI.
+	  MPU6500/6515/9250/9255, ICM20608/20609/20689, ICM20602/ICM20690 and
+	  IAM20680 motion tracking devices over SPI.
 	  This driver can be built as a module. The module will be called
 	  inv-mpu6050-spi.
diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
index e8e6beef3f04..9ecc667debbe 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
@@ -200,6 +200,14 @@ static const struct inv_mpu6050_hw hw_info[] = {
 		.fifo_size = 1008,
 		.temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE},
 	},
+	{
+		.whoami = INV_ICM20690_WHOAMI_VALUE,
+		.name = "ICM20690",
+		.reg = &reg_set_icm20602,
+		.config = &chip_config_6050,
+		.fifo_size = 1024,
+		.temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE},
+	},
 	{
 		.whoami = INV_IAM20680_WHOAMI_VALUE,
 		.name = "IAM20680",
@@ -295,6 +303,25 @@ int inv_mpu6050_set_power_itg(struct inv_mpu6050_state *st, bool power_on)
 }
 EXPORT_SYMBOL_GPL(inv_mpu6050_set_power_itg);
 
+static int inv_mpu6050_set_gyro_fsr(struct inv_mpu6050_state *st,
+				    enum inv_mpu6050_fsr_e val)
+{
+	unsigned int gyro_shift;
+	u8 data;
+
+	switch (st->chip_type) {
+	case INV_ICM20690:
+		gyro_shift = INV_ICM20690_GYRO_CONFIG_FSR_SHIFT;
+		break;
+	default:
+		gyro_shift = INV_MPU6050_GYRO_CONFIG_FSR_SHIFT;
+		break;
+	}
+
+	data = val << gyro_shift;
+	return regmap_write(st->map, st->reg->gyro_config, data);
+}
+
 /**
  *  inv_mpu6050_set_lpf_regs() - set low pass filter registers, chip dependent
  *
@@ -318,6 +345,7 @@ static int inv_mpu6050_set_lpf_regs(struct inv_mpu6050_state *st,
 		/* old chips, nothing to do */
 		return 0;
 	case INV_ICM20689:
+	case INV_ICM20690:
 		/* set FIFO size to maximum value */
 		val |= INV_ICM20689_BITS_FIFO_SIZE_MAX;
 		break;
@@ -346,8 +374,8 @@ static int inv_mpu6050_init_config(struct iio_dev *indio_dev)
 	result = inv_mpu6050_set_power_itg(st, true);
 	if (result)
 		return result;
-	d = (INV_MPU6050_FSR_2000DPS << INV_MPU6050_GYRO_CONFIG_FSR_SHIFT);
-	result = regmap_write(st->map, st->reg->gyro_config, d);
+
+	result = inv_mpu6050_set_gyro_fsr(st, INV_MPU6050_FSR_2000DPS);
 	if (result)
 		goto error_power_off;
 
@@ -559,12 +587,10 @@ inv_mpu6050_read_raw(struct iio_dev *indio_dev,
 static int inv_mpu6050_write_gyro_scale(struct inv_mpu6050_state *st, int val)
 {
 	int result, i;
-	u8 d;
 
 	for (i = 0; i < ARRAY_SIZE(gyro_scale_6050); ++i) {
 		if (gyro_scale_6050[i] == val) {
-			d = (i << INV_MPU6050_GYRO_CONFIG_FSR_SHIFT);
-			result = regmap_write(st->map, st->reg->gyro_config, d);
+			result = inv_mpu6050_set_gyro_fsr(st, i);
 			if (result)
 				return result;
 
diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c
index cd0eeb5dc7f6..1363d3776523 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c
@@ -208,6 +208,7 @@ static const struct i2c_device_id inv_mpu_id[] = {
 	{"icm20609", INV_ICM20609},
 	{"icm20689", INV_ICM20689},
 	{"icm20602", INV_ICM20602},
+	{"icm20690", INV_ICM20690},
 	{"iam20680", INV_IAM20680},
 	{}
 };
@@ -255,6 +256,10 @@ static const struct of_device_id inv_of_match[] = {
 		.compatible = "invensense,icm20602",
 		.data = (void *)INV_ICM20602
 	},
+	{
+		.compatible = "invensense,icm20690",
+		.data = (void *)INV_ICM20690
+	},
 	{
 		.compatible = "invensense,iam20680",
 		.data = (void *)INV_IAM20680
diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
index 404c289f8c84..7ae614052210 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
@@ -78,6 +78,7 @@ enum inv_devices {
 	INV_ICM20609,
 	INV_ICM20689,
 	INV_ICM20602,
+	INV_ICM20690,
 	INV_IAM20680,
 	INV_NUM_PARTS
 };
@@ -297,6 +298,7 @@ struct inv_mpu6050_state {
 #define INV_MPU6050_MAX_ACCL_FS_PARAM        3
 #define INV_MPU6050_THREE_AXIS               3
 #define INV_MPU6050_GYRO_CONFIG_FSR_SHIFT    3
+#define INV_ICM20690_GYRO_CONFIG_FSR_SHIFT   2
 #define INV_MPU6050_ACCL_CONFIG_FSR_SHIFT    3
 
 #define INV_MPU6500_TEMP_OFFSET              7011
@@ -347,6 +349,7 @@ struct inv_mpu6050_state {
 #define INV_ICM20609_WHOAMI_VALUE		0xA6
 #define INV_ICM20689_WHOAMI_VALUE		0x98
 #define INV_ICM20602_WHOAMI_VALUE		0x12
+#define INV_ICM20690_WHOAMI_VALUE		0x20
 #define INV_IAM20680_WHOAMI_VALUE		0xA9
 
 /* scan element definition for generic MPU6xxx devices */
diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c
index 393cec555be6..bc351dd58c53 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c
@@ -84,6 +84,7 @@ static const struct spi_device_id inv_mpu_id[] = {
 	{"icm20609", INV_ICM20609},
 	{"icm20689", INV_ICM20689},
 	{"icm20602", INV_ICM20602},
+	{"icm20690", INV_ICM20690},
 	{"iam20680", INV_IAM20680},
 	{}
 };
@@ -127,6 +128,10 @@ static const struct of_device_id inv_of_match[] = {
 		.compatible = "invensense,icm20602",
 		.data = (void *)INV_ICM20602
 	},
+	{
+		.compatible = "invensense,icm20690",
+		.data = (void *)INV_ICM20690
+	},
 	{
 		.compatible = "invensense,iam20680",
 		.data = (void *)INV_IAM20680
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH v2 5/6] iio: imu: inv_mpu6050: update LPF bandwidth settings
  2020-02-06 10:30 [PATCH v2 0/6] Add support of similar chips Jean-Baptiste Maneyrol
                   ` (3 preceding siblings ...)
  2020-02-06 10:31 ` [PATCH v2 4/6] iio: imu: inv_mpu6050: add support of ICM20690 Jean-Baptiste Maneyrol
@ 2020-02-06 10:31 ` Jean-Baptiste Maneyrol
  2020-02-06 12:16   ` Jonathan Cameron
  2020-02-06 10:31 ` [PATCH v2 6/6] dt-bindings: add description for new supported chips Jean-Baptiste Maneyrol
  5 siblings, 1 reply; 14+ messages in thread
From: Jean-Baptiste Maneyrol @ 2020-02-06 10:31 UTC (permalink / raw)
  To: Jonathan Cameron, linux-iio, devicetree
  Cc: Rob Herring, Mark Rutland, Jean-Baptiste Maneyrol

As every chip has some little variant in LPF bandwidth values,
use common values that are working for all chips.
Simplify the LPF setting function.

Signed-off-by: Jean-Baptiste Maneyrol <jmaneyrol@invensense.com>
---
 drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 30 ++++++++++++----------
 drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h  | 10 ++++----
 2 files changed, 21 insertions(+), 19 deletions(-)

diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
index 9ecc667debbe..c4db9086775c 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
@@ -707,30 +707,32 @@ static int inv_mpu6050_write_raw(struct iio_dev *indio_dev,
 /**
  *  inv_mpu6050_set_lpf() - set low pass filer based on fifo rate.
  *
- *                  Based on the Nyquist principle, the sampling rate must
- *                  exceed twice of the bandwidth of the signal, or there
- *                  would be alising. This function basically search for the
- *                  correct low pass parameters based on the fifo rate, e.g,
- *                  sampling frequency.
+ *                  Based on the Nyquist principle, the bandwidth of the low
+ *                  pass filter must not exceed the signal sampling rate divided
+ *                  by 2, or there would be aliasing.
+ *                  This function basically search for the correct low pass
+ *                  parameters based on the fifo rate, e.g, sampling frequency.
  *
  *  lpf is set automatically when setting sampling rate to avoid any aliases.
  */
 static int inv_mpu6050_set_lpf(struct inv_mpu6050_state *st, int rate)
 {
-	static const int hz[] = {188, 98, 42, 20, 10, 5};
+	static const int hz[] = {400, 200, 90, 40, 20, 10};
 	static const int d[] = {
-		INV_MPU6050_FILTER_188HZ, INV_MPU6050_FILTER_98HZ,
-		INV_MPU6050_FILTER_42HZ, INV_MPU6050_FILTER_20HZ,
+		INV_MPU6050_FILTER_200HZ, INV_MPU6050_FILTER_100HZ,
+		INV_MPU6050_FILTER_45HZ, INV_MPU6050_FILTER_20HZ,
 		INV_MPU6050_FILTER_10HZ, INV_MPU6050_FILTER_5HZ
 	};
-	int i, h, result;
+	int i, result;
 	u8 data;
 
-	h = (rate >> 1);
-	i = 0;
-	while ((h < hz[i]) && (i < ARRAY_SIZE(d) - 1))
-		i++;
-	data = d[i];
+	data = INV_MPU6050_FILTER_5HZ;
+	for (i = 0; i < ARRAY_SIZE(hz); ++i) {
+		if (rate >= hz[i]) {
+			data = d[i];
+			break;
+		}
+	}
 	result = inv_mpu6050_set_lpf_regs(st, data);
 	if (result)
 		return result;
diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
index 7ae614052210..9a81098a8b4d 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
@@ -370,14 +370,14 @@ enum inv_mpu6050_scan {
 };
 
 enum inv_mpu6050_filter_e {
-	INV_MPU6050_FILTER_256HZ_NOLPF2 = 0,
-	INV_MPU6050_FILTER_188HZ,
-	INV_MPU6050_FILTER_98HZ,
-	INV_MPU6050_FILTER_42HZ,
+	INV_MPU6050_FILTER_NOLPF2 = 0,
+	INV_MPU6050_FILTER_200HZ,
+	INV_MPU6050_FILTER_100HZ,
+	INV_MPU6050_FILTER_45HZ,
 	INV_MPU6050_FILTER_20HZ,
 	INV_MPU6050_FILTER_10HZ,
 	INV_MPU6050_FILTER_5HZ,
-	INV_MPU6050_FILTER_2100HZ_NOLPF,
+	INV_MPU6050_FILTER_NOLPF,
 	NUM_MPU6050_FILTER
 };
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH v2 6/6] dt-bindings: add description for new supported chips
  2020-02-06 10:30 [PATCH v2 0/6] Add support of similar chips Jean-Baptiste Maneyrol
                   ` (4 preceding siblings ...)
  2020-02-06 10:31 ` [PATCH v2 5/6] iio: imu: inv_mpu6050: update LPF bandwidth settings Jean-Baptiste Maneyrol
@ 2020-02-06 10:31 ` Jean-Baptiste Maneyrol
  2020-02-06 12:16   ` Jonathan Cameron
  5 siblings, 1 reply; 14+ messages in thread
From: Jean-Baptiste Maneyrol @ 2020-02-06 10:31 UTC (permalink / raw)
  To: Jonathan Cameron, linux-iio, devicetree
  Cc: Rob Herring, Mark Rutland, Jean-Baptiste Maneyrol

Add missing mpu6000 and new icm20609, icm20689, icm20690, and
iam20680.

Signed-off-by: Jean-Baptiste Maneyrol <jmaneyrol@invensense.com>
---
 Documentation/devicetree/bindings/iio/imu/inv_mpu6050.txt | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/Documentation/devicetree/bindings/iio/imu/inv_mpu6050.txt b/Documentation/devicetree/bindings/iio/imu/inv_mpu6050.txt
index c5ee8a20af9f..f2f64749e818 100644
--- a/Documentation/devicetree/bindings/iio/imu/inv_mpu6050.txt
+++ b/Documentation/devicetree/bindings/iio/imu/inv_mpu6050.txt
@@ -4,6 +4,7 @@ http://www.invensense.com/mems/gyro/mpu6050.html
 
 Required properties:
  - compatible : should be one of
+		"invensense,mpu6000"
 		"invensense,mpu6050"
  		"invensense,mpu6500"
 		"invensense,mpu6515"
@@ -11,7 +12,11 @@ Required properties:
 		"invensense,mpu9250"
 		"invensense,mpu9255"
 		"invensense,icm20608"
+		"invensense,icm20609"
+		"invensense,icm20689"
 		"invensense,icm20602"
+		"invensense,icm20690"
+		"invensense,iam20680"
  - reg : the I2C address of the sensor
  - interrupts: interrupt mapping for IRQ. It should be configured with flags
    IRQ_TYPE_LEVEL_HIGH, IRQ_TYPE_EDGE_RISING, IRQ_TYPE_LEVEL_LOW or
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* Re: [PATCH v2 1/6] iio: imu: inv_mpu6050: cleanup of/acpi support
  2020-02-06 10:31 ` [PATCH v2 1/6] iio: imu: inv_mpu6050: cleanup of/acpi support Jean-Baptiste Maneyrol
@ 2020-02-06 11:51   ` Jonathan Cameron
  2021-11-08 17:52     ` Jonathan Cameron
  0 siblings, 1 reply; 14+ messages in thread
From: Jonathan Cameron @ 2020-02-06 11:51 UTC (permalink / raw)
  To: Jean-Baptiste Maneyrol; +Cc: linux-iio, devicetree, Rob Herring, Mark Rutland

On Thu,  6 Feb 2020 11:31:00 +0100
Jean-Baptiste Maneyrol <jmaneyrol@invensense.com> wrote:

> Use device_get_match_data for using of and acpi tables.
> In spi support add missing mpu6515 and of match table.
> Reorganize Kconfig to display chips grouped by generations.
> 
> Signed-off-by: Jean-Baptiste Maneyrol <jmaneyrol@invensense.com>
Great.

Applied to the togreg branch of iio.git.  Clearly I took this
one very quickly after posting, but note it's not in a non rebasing
tree so I can still change that if anyone else has comments!

Thanks

Jonathan

> ---
>  drivers/iio/imu/inv_mpu6050/Kconfig       |  8 ++---
>  drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c | 26 +++-----------
>  drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c | 44 +++++++++++++++++++++--
>  3 files changed, 50 insertions(+), 28 deletions(-)
> 
> diff --git a/drivers/iio/imu/inv_mpu6050/Kconfig b/drivers/iio/imu/inv_mpu6050/Kconfig
> index 017bc0fcc365..003134734646 100644
> --- a/drivers/iio/imu/inv_mpu6050/Kconfig
> +++ b/drivers/iio/imu/inv_mpu6050/Kconfig
> @@ -15,8 +15,8 @@ config INV_MPU6050_I2C
>  	select INV_MPU6050_IIO
>  	select REGMAP_I2C
>  	help
> -	  This driver supports the Invensense MPU6050/6500/6515,
> -	  MPU9150/9250/9255 and ICM20608/20602 motion tracking devices
> +	  This driver supports the Invensense MPU6050/9150,
> +	  MPU6500/6515/9250/9255, ICM20608 and ICM20602 motion tracking devices
>  	  over I2C.
>  	  This driver can be built as a module. The module will be called
>  	  inv-mpu6050-i2c.
> @@ -27,8 +27,8 @@ config INV_MPU6050_SPI
>  	select INV_MPU6050_IIO
>  	select REGMAP_SPI
>  	help
> -	  This driver supports the Invensense MPU6000/6500/6515,
> -	  MPU9250/9255 and ICM20608/20602 motion tracking devices
> +	  This driver supports the Invensense MPU6000,
> +	  MPU6500/6515/9250/9255, ICM20608 and ICM20602 motion tracking devices
>  	  over SPI.
>  	  This driver can be built as a module. The module will be called
>  	  inv-mpu6050-spi.
> diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c
> index f47a28b4be23..49e9aa777ba4 100644
> --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c
> +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c
> @@ -10,6 +10,7 @@
>  #include <linux/iio/iio.h>
>  #include <linux/module.h>
>  #include <linux/of_device.h>
> +#include <linux/property.h>
>  #include "inv_mpu_iio.h"
>  
>  static const struct regmap_config inv_mpu_regmap_config = {
> @@ -54,20 +55,6 @@ static int inv_mpu6050_deselect_bypass(struct i2c_mux_core *muxc, u32 chan_id)
>  	return 0;
>  }
>  
> -static const char *inv_mpu_match_acpi_device(struct device *dev,
> -					     enum inv_devices *chip_id)
> -{
> -	const struct acpi_device_id *id;
> -
> -	id = acpi_match_device(dev->driver->acpi_match_table, dev);
> -	if (!id)
> -		return NULL;
> -
> -	*chip_id = (int)id->driver_data;
> -
> -	return dev_name(dev);
> -}
> -
>  static bool inv_mpu_i2c_aux_bus(struct device *dev)
>  {
>  	struct inv_mpu6050_state *st = iio_priv(dev_get_drvdata(dev));
> @@ -130,6 +117,7 @@ static int inv_mpu_magn_disable(struct iio_dev *indio_dev)
>  static int inv_mpu_probe(struct i2c_client *client,
>  			 const struct i2c_device_id *id)
>  {
> +	const void *match;
>  	struct inv_mpu6050_state *st;
>  	int result;
>  	enum inv_devices chip_type;
> @@ -140,18 +128,14 @@ static int inv_mpu_probe(struct i2c_client *client,
>  				     I2C_FUNC_SMBUS_I2C_BLOCK))
>  		return -EOPNOTSUPP;
>  
> -	if (client->dev.of_node) {
> -		chip_type = (enum inv_devices)
> -			of_device_get_match_data(&client->dev);
> +	match = device_get_match_data(&client->dev);
> +	if (match) {
> +		chip_type = (enum inv_devices)match;
>  		name = client->name;
>  	} else if (id) {
>  		chip_type = (enum inv_devices)
>  			id->driver_data;
>  		name = id->name;
> -	} else if (ACPI_HANDLE(&client->dev)) {
> -		name = inv_mpu_match_acpi_device(&client->dev, &chip_type);
> -		if (!name)
> -			return -ENODEV;
>  	} else {
>  		return -ENOSYS;
>  	}
> diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c
> index ec102d5a5c77..834bfa8e8684 100644
> --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c
> +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c
> @@ -4,6 +4,8 @@
>  */
>  #include <linux/module.h>
>  #include <linux/acpi.h>
> +#include <linux/of.h>
> +#include <linux/property.h>
>  #include <linux/spi/spi.h>
>  #include <linux/regmap.h>
>  #include <linux/iio/iio.h>
> @@ -41,17 +43,18 @@ static int inv_mpu_i2c_disable(struct iio_dev *indio_dev)
>  
>  static int inv_mpu_probe(struct spi_device *spi)
>  {
> +	const void *match;
>  	struct regmap *regmap;
>  	const struct spi_device_id *spi_id;
> -	const struct acpi_device_id *acpi_id;
>  	const char *name = NULL;
>  	enum inv_devices chip_type;
>  
>  	if ((spi_id = spi_get_device_id(spi))) {
>  		chip_type = (enum inv_devices)spi_id->driver_data;
>  		name = spi_id->name;
> -	} else if ((acpi_id = acpi_match_device(spi->dev.driver->acpi_match_table, &spi->dev))) {
> -		chip_type = (enum inv_devices)acpi_id->driver_data;
> +	} else if ((match = device_get_match_data(&spi->dev))) {
> +		chip_type = (enum inv_devices)match;
> +		name = dev_name(&spi->dev);
>  	} else {
>  		return -ENODEV;
>  	}
> @@ -74,6 +77,7 @@ static int inv_mpu_probe(struct spi_device *spi)
>  static const struct spi_device_id inv_mpu_id[] = {
>  	{"mpu6000", INV_MPU6000},
>  	{"mpu6500", INV_MPU6500},
> +	{"mpu6515", INV_MPU6515},
>  	{"mpu9250", INV_MPU9250},
>  	{"mpu9255", INV_MPU9255},
>  	{"icm20608", INV_ICM20608},
> @@ -83,6 +87,39 @@ static const struct spi_device_id inv_mpu_id[] = {
>  
>  MODULE_DEVICE_TABLE(spi, inv_mpu_id);
>  
> +static const struct of_device_id inv_of_match[] = {
> +	{
> +		.compatible = "invensense,mpu6000",
> +		.data = (void *)INV_MPU6000
> +	},
> +	{
> +		.compatible = "invensense,mpu6500",
> +		.data = (void *)INV_MPU6500
> +	},
> +	{
> +		.compatible = "invensense,mpu6515",
> +		.data = (void *)INV_MPU6515
> +	},
> +	{
> +		.compatible = "invensense,mpu9250",
> +		.data = (void *)INV_MPU9250
> +	},
> +	{
> +		.compatible = "invensense,mpu9255",
> +		.data = (void *)INV_MPU9255
> +	},
> +	{
> +		.compatible = "invensense,icm20608",
> +		.data = (void *)INV_ICM20608
> +	},
> +	{
> +		.compatible = "invensense,icm20602",
> +		.data = (void *)INV_ICM20602
> +	},
> +	{ }
> +};
> +MODULE_DEVICE_TABLE(of, inv_of_match);
> +
>  static const struct acpi_device_id inv_acpi_match[] = {
>  	{"INVN6000", INV_MPU6000},
>  	{ },
> @@ -93,6 +130,7 @@ static struct spi_driver inv_mpu_driver = {
>  	.probe		=	inv_mpu_probe,
>  	.id_table	=	inv_mpu_id,
>  	.driver = {
> +		.of_match_table = inv_of_match,
>  		.acpi_match_table = ACPI_PTR(inv_acpi_match),
>  		.name	=	"inv-mpu6000-spi",
>  		.pm     =       &inv_mpu_pmops,


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v2 2/6] iio: imu: inv_mpu6050: add support of ICM20609 & ICM20689
  2020-02-06 10:31 ` [PATCH v2 2/6] iio: imu: inv_mpu6050: add support of ICM20609 & ICM20689 Jean-Baptiste Maneyrol
@ 2020-02-06 11:53   ` Jonathan Cameron
  0 siblings, 0 replies; 14+ messages in thread
From: Jonathan Cameron @ 2020-02-06 11:53 UTC (permalink / raw)
  To: Jean-Baptiste Maneyrol; +Cc: linux-iio, devicetree, Rob Herring, Mark Rutland

On Thu,  6 Feb 2020 11:31:01 +0100
Jean-Baptiste Maneyrol <jmaneyrol@invensense.com> wrote:

> They are similar to ICM20608 chip.
> 
> Signed-off-by: Jean-Baptiste Maneyrol <jmaneyrol@invensense.com>

Applied to the togreg branch of iio.git and pushed out as testing for
the autobuilders to play with it.

Thanks,

Jonathan

> ---
>  drivers/iio/imu/inv_mpu6050/Kconfig        |  8 +++----
>  drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 26 ++++++++++++++++++----
>  drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c  | 12 ++++++++++
>  drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h  |  5 +++++
>  drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c  | 10 +++++++++
>  5 files changed, 53 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/iio/imu/inv_mpu6050/Kconfig b/drivers/iio/imu/inv_mpu6050/Kconfig
> index 003134734646..e933db3a5a89 100644
> --- a/drivers/iio/imu/inv_mpu6050/Kconfig
> +++ b/drivers/iio/imu/inv_mpu6050/Kconfig
> @@ -16,8 +16,8 @@ config INV_MPU6050_I2C
>  	select REGMAP_I2C
>  	help
>  	  This driver supports the Invensense MPU6050/9150,
> -	  MPU6500/6515/9250/9255, ICM20608 and ICM20602 motion tracking devices
> -	  over I2C.
> +	  MPU6500/6515/9250/9255, ICM20608/20609/20689 and ICM20602
> +	  motion tracking devices over I2C.
>  	  This driver can be built as a module. The module will be called
>  	  inv-mpu6050-i2c.
>  
> @@ -28,7 +28,7 @@ config INV_MPU6050_SPI
>  	select REGMAP_SPI
>  	help
>  	  This driver supports the Invensense MPU6000,
> -	  MPU6500/6515/9250/9255, ICM20608 and ICM20602 motion tracking devices
> -	  over SPI.
> +	  MPU6500/6515/9250/9255, ICM20608/20609/20689 and ICM20602
> +	  motion tracking devices over SPI.
>  	  This driver can be built as a module. The module will be called
>  	  inv-mpu6050-spi.
> diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
> index 5096fc49012d..5fd57a1bee90 100644
> --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
> +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
> @@ -176,6 +176,22 @@ static const struct inv_mpu6050_hw hw_info[] = {
>  		.fifo_size = 512,
>  		.temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE},
>  	},
> +	{
> +		.whoami = INV_ICM20609_WHOAMI_VALUE,
> +		.name = "ICM20609",
> +		.reg = &reg_set_6500,
> +		.config = &chip_config_6050,
> +		.fifo_size = 4 * 1024,
> +		.temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE},
> +	},
> +	{
> +		.whoami = INV_ICM20689_WHOAMI_VALUE,
> +		.name = "ICM20689",
> +		.reg = &reg_set_6500,
> +		.config = &chip_config_6050,
> +		.fifo_size = 4 * 1024,
> +		.temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE},
> +	},
>  	{
>  		.whoami = INV_ICM20602_WHOAMI_VALUE,
>  		.name = "ICM20602",
> @@ -286,20 +302,22 @@ static int inv_mpu6050_set_lpf_regs(struct inv_mpu6050_state *st,
>  	if (result)
>  		return result;
>  
> +	/* set accel lpf */
>  	switch (st->chip_type) {
>  	case INV_MPU6050:
>  	case INV_MPU6000:
>  	case INV_MPU9150:
>  		/* old chips, nothing to do */
> -		result = 0;
> +		return 0;
> +	case INV_ICM20689:
> +		/* set FIFO size to maximum value */
> +		val |= INV_ICM20689_BITS_FIFO_SIZE_MAX;
>  		break;
>  	default:
> -		/* set accel lpf */
> -		result = regmap_write(st->map, st->reg->accel_lpf, val);
>  		break;
>  	}
>  
> -	return result;
> +	return regmap_write(st->map, st->reg->accel_lpf, val);
>  }
>  
>  /**
> diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c
> index 49e9aa777ba4..dd054e21216a 100644
> --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c
> +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c
> @@ -61,6 +61,8 @@ static bool inv_mpu_i2c_aux_bus(struct device *dev)
>  
>  	switch (st->chip_type) {
>  	case INV_ICM20608:
> +	case INV_ICM20609:
> +	case INV_ICM20689:
>  	case INV_ICM20602:
>  		/* no i2c auxiliary bus on the chip */
>  		return false;
> @@ -202,6 +204,8 @@ static const struct i2c_device_id inv_mpu_id[] = {
>  	{"mpu9250", INV_MPU9250},
>  	{"mpu9255", INV_MPU9255},
>  	{"icm20608", INV_ICM20608},
> +	{"icm20609", INV_ICM20609},
> +	{"icm20689", INV_ICM20689},
>  	{"icm20602", INV_ICM20602},
>  	{}
>  };
> @@ -237,6 +241,14 @@ static const struct of_device_id inv_of_match[] = {
>  		.compatible = "invensense,icm20608",
>  		.data = (void *)INV_ICM20608
>  	},
> +	{
> +		.compatible = "invensense,icm20609",
> +		.data = (void *)INV_ICM20609
> +	},
> +	{
> +		.compatible = "invensense,icm20689",
> +		.data = (void *)INV_ICM20689
> +	},
>  	{
>  		.compatible = "invensense,icm20602",
>  		.data = (void *)INV_ICM20602
> diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
> index 6158fca7f70e..75b8903450eb 100644
> --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
> +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
> @@ -75,6 +75,8 @@ enum inv_devices {
>  	INV_MPU9250,
>  	INV_MPU9255,
>  	INV_ICM20608,
> +	INV_ICM20609,
> +	INV_ICM20689,
>  	INV_ICM20602,
>  	INV_NUM_PARTS
>  };
> @@ -276,6 +278,7 @@ struct inv_mpu6050_state {
>  
>  /* mpu6500 registers */
>  #define INV_MPU6500_REG_ACCEL_CONFIG_2      0x1D
> +#define INV_ICM20689_BITS_FIFO_SIZE_MAX     0xC0
>  #define INV_MPU6500_REG_ACCEL_OFFSET        0x77
>  
>  /* delay time in milliseconds */
> @@ -340,6 +343,8 @@ struct inv_mpu6050_state {
>  #define INV_MPU9255_WHOAMI_VALUE		0x73
>  #define INV_MPU6515_WHOAMI_VALUE		0x74
>  #define INV_ICM20608_WHOAMI_VALUE		0xAF
> +#define INV_ICM20609_WHOAMI_VALUE		0xA6
> +#define INV_ICM20689_WHOAMI_VALUE		0x98
>  #define INV_ICM20602_WHOAMI_VALUE		0x12
>  
>  /* scan element definition for generic MPU6xxx devices */
> diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c
> index 834bfa8e8684..3803c40e7b24 100644
> --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c
> +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c
> @@ -81,6 +81,8 @@ static const struct spi_device_id inv_mpu_id[] = {
>  	{"mpu9250", INV_MPU9250},
>  	{"mpu9255", INV_MPU9255},
>  	{"icm20608", INV_ICM20608},
> +	{"icm20609", INV_ICM20609},
> +	{"icm20689", INV_ICM20689},
>  	{"icm20602", INV_ICM20602},
>  	{}
>  };
> @@ -112,6 +114,14 @@ static const struct of_device_id inv_of_match[] = {
>  		.compatible = "invensense,icm20608",
>  		.data = (void *)INV_ICM20608
>  	},
> +	{
> +		.compatible = "invensense,icm20609",
> +		.data = (void *)INV_ICM20609
> +	},
> +	{
> +		.compatible = "invensense,icm20689",
> +		.data = (void *)INV_ICM20689
> +	},
>  	{
>  		.compatible = "invensense,icm20602",
>  		.data = (void *)INV_ICM20602


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v2 3/6] iio: imu: inv_mpu6050: add support of IAM20680
  2020-02-06 10:31 ` [PATCH v2 3/6] iio: imu: inv_mpu6050: add support of IAM20680 Jean-Baptiste Maneyrol
@ 2020-02-06 12:09   ` Jonathan Cameron
  0 siblings, 0 replies; 14+ messages in thread
From: Jonathan Cameron @ 2020-02-06 12:09 UTC (permalink / raw)
  To: Jean-Baptiste Maneyrol; +Cc: linux-iio, devicetree, Rob Herring, Mark Rutland

On Thu,  6 Feb 2020 11:31:02 +0100
Jean-Baptiste Maneyrol <jmaneyrol@invensense.com> wrote:

> Automotive certified IMU, similar to ICM20608.
> 
> Signed-off-by: Jean-Baptiste Maneyrol <jmaneyrol@invensense.com>
Applied.

Thanks,

Jonathan

> ---
>  drivers/iio/imu/inv_mpu6050/Kconfig        | 4 ++--
>  drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 8 ++++++++
>  drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c  | 6 ++++++
>  drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h  | 2 ++
>  drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c  | 5 +++++
>  5 files changed, 23 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/iio/imu/inv_mpu6050/Kconfig b/drivers/iio/imu/inv_mpu6050/Kconfig
> index e933db3a5a89..e65474a64675 100644
> --- a/drivers/iio/imu/inv_mpu6050/Kconfig
> +++ b/drivers/iio/imu/inv_mpu6050/Kconfig
> @@ -16,7 +16,7 @@ config INV_MPU6050_I2C
>  	select REGMAP_I2C
>  	help
>  	  This driver supports the Invensense MPU6050/9150,
> -	  MPU6500/6515/9250/9255, ICM20608/20609/20689 and ICM20602
> +	  MPU6500/6515/9250/9255, ICM20608/20609/20689, ICM20602 and IAM20680
>  	  motion tracking devices over I2C.
>  	  This driver can be built as a module. The module will be called
>  	  inv-mpu6050-i2c.
> @@ -28,7 +28,7 @@ config INV_MPU6050_SPI
>  	select REGMAP_SPI
>  	help
>  	  This driver supports the Invensense MPU6000,
> -	  MPU6500/6515/9250/9255, ICM20608/20609/20689 and ICM20602
> +	  MPU6500/6515/9250/9255, ICM20608/20609/20689, ICM20602 and IAM20680
>  	  motion tracking devices over SPI.
>  	  This driver can be built as a module. The module will be called
>  	  inv-mpu6050-spi.
> diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
> index 5fd57a1bee90..e8e6beef3f04 100644
> --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
> +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
> @@ -200,6 +200,14 @@ static const struct inv_mpu6050_hw hw_info[] = {
>  		.fifo_size = 1008,
>  		.temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE},
>  	},
> +	{
> +		.whoami = INV_IAM20680_WHOAMI_VALUE,
> +		.name = "IAM20680",
> +		.reg = &reg_set_6500,
> +		.config = &chip_config_6050,
> +		.fifo_size = 512,
> +		.temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE},
> +	},
>  };
>  
>  int inv_mpu6050_switch_engine(struct inv_mpu6050_state *st, bool en, u32 mask)
> diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c
> index dd054e21216a..cd0eeb5dc7f6 100644
> --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c
> +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c
> @@ -64,6 +64,7 @@ static bool inv_mpu_i2c_aux_bus(struct device *dev)
>  	case INV_ICM20609:
>  	case INV_ICM20689:
>  	case INV_ICM20602:
> +	case INV_IAM20680:
>  		/* no i2c auxiliary bus on the chip */
>  		return false;
>  	case INV_MPU9150:
> @@ -207,6 +208,7 @@ static const struct i2c_device_id inv_mpu_id[] = {
>  	{"icm20609", INV_ICM20609},
>  	{"icm20689", INV_ICM20689},
>  	{"icm20602", INV_ICM20602},
> +	{"iam20680", INV_IAM20680},
>  	{}
>  };
>  
> @@ -253,6 +255,10 @@ static const struct of_device_id inv_of_match[] = {
>  		.compatible = "invensense,icm20602",
>  		.data = (void *)INV_ICM20602
>  	},
> +	{
> +		.compatible = "invensense,iam20680",
> +		.data = (void *)INV_IAM20680
> +	},
>  	{ }
>  };
>  MODULE_DEVICE_TABLE(of, inv_of_match);
> diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
> index 75b8903450eb..404c289f8c84 100644
> --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
> +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
> @@ -78,6 +78,7 @@ enum inv_devices {
>  	INV_ICM20609,
>  	INV_ICM20689,
>  	INV_ICM20602,
> +	INV_IAM20680,
>  	INV_NUM_PARTS
>  };
>  
> @@ -346,6 +347,7 @@ struct inv_mpu6050_state {
>  #define INV_ICM20609_WHOAMI_VALUE		0xA6
>  #define INV_ICM20689_WHOAMI_VALUE		0x98
>  #define INV_ICM20602_WHOAMI_VALUE		0x12
> +#define INV_IAM20680_WHOAMI_VALUE		0xA9
>  
>  /* scan element definition for generic MPU6xxx devices */
>  enum inv_mpu6050_scan {
> diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c
> index 3803c40e7b24..393cec555be6 100644
> --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c
> +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c
> @@ -84,6 +84,7 @@ static const struct spi_device_id inv_mpu_id[] = {
>  	{"icm20609", INV_ICM20609},
>  	{"icm20689", INV_ICM20689},
>  	{"icm20602", INV_ICM20602},
> +	{"iam20680", INV_IAM20680},
>  	{}
>  };
>  
> @@ -126,6 +127,10 @@ static const struct of_device_id inv_of_match[] = {
>  		.compatible = "invensense,icm20602",
>  		.data = (void *)INV_ICM20602
>  	},
> +	{
> +		.compatible = "invensense,iam20680",
> +		.data = (void *)INV_IAM20680
> +	},
>  	{ }
>  };
>  MODULE_DEVICE_TABLE(of, inv_of_match);


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v2 4/6] iio: imu: inv_mpu6050: add support of ICM20690
  2020-02-06 10:31 ` [PATCH v2 4/6] iio: imu: inv_mpu6050: add support of ICM20690 Jean-Baptiste Maneyrol
@ 2020-02-06 12:15   ` Jonathan Cameron
  0 siblings, 0 replies; 14+ messages in thread
From: Jonathan Cameron @ 2020-02-06 12:15 UTC (permalink / raw)
  To: Jean-Baptiste Maneyrol; +Cc: linux-iio, devicetree, Rob Herring, Mark Rutland

On Thu,  6 Feb 2020 11:31:03 +0100
Jean-Baptiste Maneyrol <jmaneyrol@invensense.com> wrote:

> Same generation as ICM20602 but different registers.
> 
> Signed-off-by: Jean-Baptiste Maneyrol <jmaneyrol@invensense.com>
Applied.
Thanks.
> ---
>  drivers/iio/imu/inv_mpu6050/Kconfig        |  8 ++---
>  drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 36 +++++++++++++++++++---
>  drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c  |  5 +++
>  drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h  |  3 ++
>  drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c  |  5 +++
>  5 files changed, 48 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/iio/imu/inv_mpu6050/Kconfig b/drivers/iio/imu/inv_mpu6050/Kconfig
> index e65474a64675..7137ea6f25db 100644
> --- a/drivers/iio/imu/inv_mpu6050/Kconfig
> +++ b/drivers/iio/imu/inv_mpu6050/Kconfig
> @@ -16,8 +16,8 @@ config INV_MPU6050_I2C
>  	select REGMAP_I2C
>  	help
>  	  This driver supports the Invensense MPU6050/9150,
> -	  MPU6500/6515/9250/9255, ICM20608/20609/20689, ICM20602 and IAM20680
> -	  motion tracking devices over I2C.
> +	  MPU6500/6515/9250/9255, ICM20608/20609/20689, ICM20602/ICM20690 and
> +	  IAM20680 motion tracking devices over I2C.
>  	  This driver can be built as a module. The module will be called
>  	  inv-mpu6050-i2c.
>  
> @@ -28,7 +28,7 @@ config INV_MPU6050_SPI
>  	select REGMAP_SPI
>  	help
>  	  This driver supports the Invensense MPU6000,
> -	  MPU6500/6515/9250/9255, ICM20608/20609/20689, ICM20602 and IAM20680
> -	  motion tracking devices over SPI.
> +	  MPU6500/6515/9250/9255, ICM20608/20609/20689, ICM20602/ICM20690 and
> +	  IAM20680 motion tracking devices over SPI.
>  	  This driver can be built as a module. The module will be called
>  	  inv-mpu6050-spi.
> diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
> index e8e6beef3f04..9ecc667debbe 100644
> --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
> +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
> @@ -200,6 +200,14 @@ static const struct inv_mpu6050_hw hw_info[] = {
>  		.fifo_size = 1008,
>  		.temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE},
>  	},
> +	{
> +		.whoami = INV_ICM20690_WHOAMI_VALUE,
> +		.name = "ICM20690",
> +		.reg = &reg_set_icm20602,
> +		.config = &chip_config_6050,
> +		.fifo_size = 1024,
> +		.temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE},
> +	},
>  	{
>  		.whoami = INV_IAM20680_WHOAMI_VALUE,
>  		.name = "IAM20680",
> @@ -295,6 +303,25 @@ int inv_mpu6050_set_power_itg(struct inv_mpu6050_state *st, bool power_on)
>  }
>  EXPORT_SYMBOL_GPL(inv_mpu6050_set_power_itg);
>  
> +static int inv_mpu6050_set_gyro_fsr(struct inv_mpu6050_state *st,
> +				    enum inv_mpu6050_fsr_e val)
> +{
> +	unsigned int gyro_shift;
> +	u8 data;
> +
> +	switch (st->chip_type) {
> +	case INV_ICM20690:
> +		gyro_shift = INV_ICM20690_GYRO_CONFIG_FSR_SHIFT;
> +		break;
> +	default:
> +		gyro_shift = INV_MPU6050_GYRO_CONFIG_FSR_SHIFT;
> +		break;
> +	}
> +
> +	data = val << gyro_shift;
> +	return regmap_write(st->map, st->reg->gyro_config, data);
> +}
> +
>  /**
>   *  inv_mpu6050_set_lpf_regs() - set low pass filter registers, chip dependent
>   *
> @@ -318,6 +345,7 @@ static int inv_mpu6050_set_lpf_regs(struct inv_mpu6050_state *st,
>  		/* old chips, nothing to do */
>  		return 0;
>  	case INV_ICM20689:
> +	case INV_ICM20690:
>  		/* set FIFO size to maximum value */
>  		val |= INV_ICM20689_BITS_FIFO_SIZE_MAX;
>  		break;
> @@ -346,8 +374,8 @@ static int inv_mpu6050_init_config(struct iio_dev *indio_dev)
>  	result = inv_mpu6050_set_power_itg(st, true);
>  	if (result)
>  		return result;
> -	d = (INV_MPU6050_FSR_2000DPS << INV_MPU6050_GYRO_CONFIG_FSR_SHIFT);
> -	result = regmap_write(st->map, st->reg->gyro_config, d);
> +
> +	result = inv_mpu6050_set_gyro_fsr(st, INV_MPU6050_FSR_2000DPS);
>  	if (result)
>  		goto error_power_off;
>  
> @@ -559,12 +587,10 @@ inv_mpu6050_read_raw(struct iio_dev *indio_dev,
>  static int inv_mpu6050_write_gyro_scale(struct inv_mpu6050_state *st, int val)
>  {
>  	int result, i;
> -	u8 d;
>  
>  	for (i = 0; i < ARRAY_SIZE(gyro_scale_6050); ++i) {
>  		if (gyro_scale_6050[i] == val) {
> -			d = (i << INV_MPU6050_GYRO_CONFIG_FSR_SHIFT);
> -			result = regmap_write(st->map, st->reg->gyro_config, d);
> +			result = inv_mpu6050_set_gyro_fsr(st, i);
>  			if (result)
>  				return result;
>  
> diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c
> index cd0eeb5dc7f6..1363d3776523 100644
> --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c
> +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c
> @@ -208,6 +208,7 @@ static const struct i2c_device_id inv_mpu_id[] = {
>  	{"icm20609", INV_ICM20609},
>  	{"icm20689", INV_ICM20689},
>  	{"icm20602", INV_ICM20602},
> +	{"icm20690", INV_ICM20690},
>  	{"iam20680", INV_IAM20680},
>  	{}
>  };
> @@ -255,6 +256,10 @@ static const struct of_device_id inv_of_match[] = {
>  		.compatible = "invensense,icm20602",
>  		.data = (void *)INV_ICM20602
>  	},
> +	{
> +		.compatible = "invensense,icm20690",
> +		.data = (void *)INV_ICM20690
> +	},
>  	{
>  		.compatible = "invensense,iam20680",
>  		.data = (void *)INV_IAM20680
> diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
> index 404c289f8c84..7ae614052210 100644
> --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
> +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
> @@ -78,6 +78,7 @@ enum inv_devices {
>  	INV_ICM20609,
>  	INV_ICM20689,
>  	INV_ICM20602,
> +	INV_ICM20690,
>  	INV_IAM20680,
>  	INV_NUM_PARTS
>  };
> @@ -297,6 +298,7 @@ struct inv_mpu6050_state {
>  #define INV_MPU6050_MAX_ACCL_FS_PARAM        3
>  #define INV_MPU6050_THREE_AXIS               3
>  #define INV_MPU6050_GYRO_CONFIG_FSR_SHIFT    3
> +#define INV_ICM20690_GYRO_CONFIG_FSR_SHIFT   2
>  #define INV_MPU6050_ACCL_CONFIG_FSR_SHIFT    3
>  
>  #define INV_MPU6500_TEMP_OFFSET              7011
> @@ -347,6 +349,7 @@ struct inv_mpu6050_state {
>  #define INV_ICM20609_WHOAMI_VALUE		0xA6
>  #define INV_ICM20689_WHOAMI_VALUE		0x98
>  #define INV_ICM20602_WHOAMI_VALUE		0x12
> +#define INV_ICM20690_WHOAMI_VALUE		0x20
>  #define INV_IAM20680_WHOAMI_VALUE		0xA9
>  
>  /* scan element definition for generic MPU6xxx devices */
> diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c
> index 393cec555be6..bc351dd58c53 100644
> --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c
> +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c
> @@ -84,6 +84,7 @@ static const struct spi_device_id inv_mpu_id[] = {
>  	{"icm20609", INV_ICM20609},
>  	{"icm20689", INV_ICM20689},
>  	{"icm20602", INV_ICM20602},
> +	{"icm20690", INV_ICM20690},
>  	{"iam20680", INV_IAM20680},
>  	{}
>  };
> @@ -127,6 +128,10 @@ static const struct of_device_id inv_of_match[] = {
>  		.compatible = "invensense,icm20602",
>  		.data = (void *)INV_ICM20602
>  	},
> +	{
> +		.compatible = "invensense,icm20690",
> +		.data = (void *)INV_ICM20690
> +	},
>  	{
>  		.compatible = "invensense,iam20680",
>  		.data = (void *)INV_IAM20680


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v2 5/6] iio: imu: inv_mpu6050: update LPF bandwidth settings
  2020-02-06 10:31 ` [PATCH v2 5/6] iio: imu: inv_mpu6050: update LPF bandwidth settings Jean-Baptiste Maneyrol
@ 2020-02-06 12:16   ` Jonathan Cameron
  0 siblings, 0 replies; 14+ messages in thread
From: Jonathan Cameron @ 2020-02-06 12:16 UTC (permalink / raw)
  To: Jean-Baptiste Maneyrol; +Cc: linux-iio, devicetree, Rob Herring, Mark Rutland

On Thu,  6 Feb 2020 11:31:04 +0100
Jean-Baptiste Maneyrol <jmaneyrol@invensense.com> wrote:

> As every chip has some little variant in LPF bandwidth values,
> use common values that are working for all chips.
> Simplify the LPF setting function.
> 
> Signed-off-by: Jean-Baptiste Maneyrol <jmaneyrol@invensense.com>
Applied, thanks
> ---
>  drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 30 ++++++++++++----------
>  drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h  | 10 ++++----
>  2 files changed, 21 insertions(+), 19 deletions(-)
> 
> diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
> index 9ecc667debbe..c4db9086775c 100644
> --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
> +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
> @@ -707,30 +707,32 @@ static int inv_mpu6050_write_raw(struct iio_dev *indio_dev,
>  /**
>   *  inv_mpu6050_set_lpf() - set low pass filer based on fifo rate.
>   *
> - *                  Based on the Nyquist principle, the sampling rate must
> - *                  exceed twice of the bandwidth of the signal, or there
> - *                  would be alising. This function basically search for the
> - *                  correct low pass parameters based on the fifo rate, e.g,
> - *                  sampling frequency.
> + *                  Based on the Nyquist principle, the bandwidth of the low
> + *                  pass filter must not exceed the signal sampling rate divided
> + *                  by 2, or there would be aliasing.
> + *                  This function basically search for the correct low pass
> + *                  parameters based on the fifo rate, e.g, sampling frequency.
>   *
>   *  lpf is set automatically when setting sampling rate to avoid any aliases.
>   */
>  static int inv_mpu6050_set_lpf(struct inv_mpu6050_state *st, int rate)
>  {
> -	static const int hz[] = {188, 98, 42, 20, 10, 5};
> +	static const int hz[] = {400, 200, 90, 40, 20, 10};
>  	static const int d[] = {
> -		INV_MPU6050_FILTER_188HZ, INV_MPU6050_FILTER_98HZ,
> -		INV_MPU6050_FILTER_42HZ, INV_MPU6050_FILTER_20HZ,
> +		INV_MPU6050_FILTER_200HZ, INV_MPU6050_FILTER_100HZ,
> +		INV_MPU6050_FILTER_45HZ, INV_MPU6050_FILTER_20HZ,
>  		INV_MPU6050_FILTER_10HZ, INV_MPU6050_FILTER_5HZ
>  	};
> -	int i, h, result;
> +	int i, result;
>  	u8 data;
>  
> -	h = (rate >> 1);
> -	i = 0;
> -	while ((h < hz[i]) && (i < ARRAY_SIZE(d) - 1))
> -		i++;
> -	data = d[i];
> +	data = INV_MPU6050_FILTER_5HZ;
> +	for (i = 0; i < ARRAY_SIZE(hz); ++i) {
> +		if (rate >= hz[i]) {
> +			data = d[i];
> +			break;
> +		}
> +	}
>  	result = inv_mpu6050_set_lpf_regs(st, data);
>  	if (result)
>  		return result;
> diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
> index 7ae614052210..9a81098a8b4d 100644
> --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
> +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
> @@ -370,14 +370,14 @@ enum inv_mpu6050_scan {
>  };
>  
>  enum inv_mpu6050_filter_e {
> -	INV_MPU6050_FILTER_256HZ_NOLPF2 = 0,
> -	INV_MPU6050_FILTER_188HZ,
> -	INV_MPU6050_FILTER_98HZ,
> -	INV_MPU6050_FILTER_42HZ,
> +	INV_MPU6050_FILTER_NOLPF2 = 0,
> +	INV_MPU6050_FILTER_200HZ,
> +	INV_MPU6050_FILTER_100HZ,
> +	INV_MPU6050_FILTER_45HZ,
>  	INV_MPU6050_FILTER_20HZ,
>  	INV_MPU6050_FILTER_10HZ,
>  	INV_MPU6050_FILTER_5HZ,
> -	INV_MPU6050_FILTER_2100HZ_NOLPF,
> +	INV_MPU6050_FILTER_NOLPF,
>  	NUM_MPU6050_FILTER
>  };
>  


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v2 6/6] dt-bindings: add description for new supported chips
  2020-02-06 10:31 ` [PATCH v2 6/6] dt-bindings: add description for new supported chips Jean-Baptiste Maneyrol
@ 2020-02-06 12:16   ` Jonathan Cameron
  0 siblings, 0 replies; 14+ messages in thread
From: Jonathan Cameron @ 2020-02-06 12:16 UTC (permalink / raw)
  To: Jean-Baptiste Maneyrol; +Cc: linux-iio, devicetree, Rob Herring, Mark Rutland

On Thu,  6 Feb 2020 11:31:05 +0100
Jean-Baptiste Maneyrol <jmaneyrol@invensense.com> wrote:

> Add missing mpu6000 and new icm20609, icm20689, icm20690, and
> iam20680.
> 
> Signed-off-by: Jean-Baptiste Maneyrol <jmaneyrol@invensense.com>

Applied.  Thanks,

Jonathan

> ---
>  Documentation/devicetree/bindings/iio/imu/inv_mpu6050.txt | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/Documentation/devicetree/bindings/iio/imu/inv_mpu6050.txt b/Documentation/devicetree/bindings/iio/imu/inv_mpu6050.txt
> index c5ee8a20af9f..f2f64749e818 100644
> --- a/Documentation/devicetree/bindings/iio/imu/inv_mpu6050.txt
> +++ b/Documentation/devicetree/bindings/iio/imu/inv_mpu6050.txt
> @@ -4,6 +4,7 @@ http://www.invensense.com/mems/gyro/mpu6050.html
>  
>  Required properties:
>   - compatible : should be one of
> +		"invensense,mpu6000"
>  		"invensense,mpu6050"
>   		"invensense,mpu6500"
>  		"invensense,mpu6515"
> @@ -11,7 +12,11 @@ Required properties:
>  		"invensense,mpu9250"
>  		"invensense,mpu9255"
>  		"invensense,icm20608"
> +		"invensense,icm20609"
> +		"invensense,icm20689"
>  		"invensense,icm20602"
> +		"invensense,icm20690"
> +		"invensense,iam20680"
>   - reg : the I2C address of the sensor
>   - interrupts: interrupt mapping for IRQ. It should be configured with flags
>     IRQ_TYPE_LEVEL_HIGH, IRQ_TYPE_EDGE_RISING, IRQ_TYPE_LEVEL_LOW or


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v2 1/6] iio: imu: inv_mpu6050: cleanup of/acpi support
  2020-02-06 11:51   ` Jonathan Cameron
@ 2021-11-08 17:52     ` Jonathan Cameron
  0 siblings, 0 replies; 14+ messages in thread
From: Jonathan Cameron @ 2021-11-08 17:52 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Jean-Baptiste Maneyrol, linux-iio, devicetree, Rob Herring, Mark Rutland

On Thu, 6 Feb 2020 11:51:55 +0000
Jonathan Cameron <jic23@kernel.org> wrote:

> On Thu,  6 Feb 2020 11:31:00 +0100
> Jean-Baptiste Maneyrol <jmaneyrol@invensense.com> wrote:
> 
> > Use device_get_match_data for using of and acpi tables.
> > In spi support add missing mpu6515 and of match table.
> > Reorganize Kconfig to display chips grouped by generations.
> > 
> > Signed-off-by: Jean-Baptiste Maneyrol <jmaneyrol@invensense.com>  
> Great.
> 
> Applied to the togreg branch of iio.git.  Clearly I took this
> one very quickly after posting, but note it's not in a non rebasing
> tree so I can still change that if anyone else has comments!
> 

I happened to be looking at the code this affects for an entirely
different reason and realized there is a problem...

> Thanks
> 
> Jonathan
> 
> > ---
> >  drivers/iio/imu/inv_mpu6050/Kconfig       |  8 ++---
> >  drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c | 26 +++-----------
> >  drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c | 44 +++++++++++++++++++++--
> >  3 files changed, 50 insertions(+), 28 deletions(-)
> > 
> > diff --git a/drivers/iio/imu/inv_mpu6050/Kconfig b/drivers/iio/imu/inv_mpu6050/Kconfig
> > index 017bc0fcc365..003134734646 100644
> > --- a/drivers/iio/imu/inv_mpu6050/Kconfig
> > +++ b/drivers/iio/imu/inv_mpu6050/Kconfig
> > @@ -15,8 +15,8 @@ config INV_MPU6050_I2C
> >  	select INV_MPU6050_IIO
> >  	select REGMAP_I2C
> >  	help
> > -	  This driver supports the Invensense MPU6050/6500/6515,
> > -	  MPU9150/9250/9255 and ICM20608/20602 motion tracking devices
> > +	  This driver supports the Invensense MPU6050/9150,
> > +	  MPU6500/6515/9250/9255, ICM20608 and ICM20602 motion tracking devices
> >  	  over I2C.
> >  	  This driver can be built as a module. The module will be called
> >  	  inv-mpu6050-i2c.
> > @@ -27,8 +27,8 @@ config INV_MPU6050_SPI
> >  	select INV_MPU6050_IIO
> >  	select REGMAP_SPI
> >  	help
> > -	  This driver supports the Invensense MPU6000/6500/6515,
> > -	  MPU9250/9255 and ICM20608/20602 motion tracking devices
> > +	  This driver supports the Invensense MPU6000,
> > +	  MPU6500/6515/9250/9255, ICM20608 and ICM20602 motion tracking devices
> >  	  over SPI.
> >  	  This driver can be built as a module. The module will be called
> >  	  inv-mpu6050-spi.
> > diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c
> > index f47a28b4be23..49e9aa777ba4 100644
> > --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c
> > +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c
> > @@ -10,6 +10,7 @@
> >  #include <linux/iio/iio.h>
> >  #include <linux/module.h>
> >  #include <linux/of_device.h>
> > +#include <linux/property.h>
> >  #include "inv_mpu_iio.h"
> >  
> >  static const struct regmap_config inv_mpu_regmap_config = {
> > @@ -54,20 +55,6 @@ static int inv_mpu6050_deselect_bypass(struct i2c_mux_core *muxc, u32 chan_id)
> >  	return 0;
> >  }
> >  
> > -static const char *inv_mpu_match_acpi_device(struct device *dev,
> > -					     enum inv_devices *chip_id)
> > -{
> > -	const struct acpi_device_id *id;
> > -
> > -	id = acpi_match_device(dev->driver->acpi_match_table, dev);
> > -	if (!id)
> > -		return NULL;
> > -
> > -	*chip_id = (int)id->driver_data;
> > -
> > -	return dev_name(dev);
> > -}
> > -
> >  static bool inv_mpu_i2c_aux_bus(struct device *dev)
> >  {
> >  	struct inv_mpu6050_state *st = iio_priv(dev_get_drvdata(dev));
> > @@ -130,6 +117,7 @@ static int inv_mpu_magn_disable(struct iio_dev *indio_dev)
> >  static int inv_mpu_probe(struct i2c_client *client,
> >  			 const struct i2c_device_id *id)
> >  {
> > +	const void *match;
> >  	struct inv_mpu6050_state *st;
> >  	int result;
> >  	enum inv_devices chip_type;
> > @@ -140,18 +128,14 @@ static int inv_mpu_probe(struct i2c_client *client,
> >  				     I2C_FUNC_SMBUS_I2C_BLOCK))
> >  		return -EOPNOTSUPP;
> >  
> > -	if (client->dev.of_node) {
> > -		chip_type = (enum inv_devices)
> > -			of_device_get_match_data(&client->dev);
> > +	match = device_get_match_data(&client->dev);
> > +	if (match) {

Unfortunately, chip_type == 0 and hence match == NULL doesn't 
necessarily mean no match... It might mean the enum value was
0 which is the case for INV_MPU6050

For the of case, we probably get away with it because
id->driver_data will be set anyway but I don't think that was what
was intended.

Fixes are all a bit mess.  Simplest might be to add a check of
dev_fwnode() to verify if there is a firmware node or not and
then use the match value form device_get_match_data without checking
it against 0.

Jonathan
> > +		chip_type = (enum inv_devices)match;
> >  		name = client->name;
> >  	} else if (id) {
> >  		chip_type = (enum inv_devices)
> >  			id->driver_data;
> >  		name = id->name;
> > -	} else if (ACPI_HANDLE(&client->dev)) {
> > -		name = inv_mpu_match_acpi_device(&client->dev, &chip_type);
> > -		if (!name)
> > -			return -ENODEV;
> >  	} else {
> >  		return -ENOSYS;
> >  	}
> > diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c
> > index ec102d5a5c77..834bfa8e8684 100644
> > --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c
> > +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c
> > @@ -4,6 +4,8 @@
> >  */
> >  #include <linux/module.h>
> >  #include <linux/acpi.h>
> > +#include <linux/of.h>
> > +#include <linux/property.h>
> >  #include <linux/spi/spi.h>
> >  #include <linux/regmap.h>
> >  #include <linux/iio/iio.h>
> > @@ -41,17 +43,18 @@ static int inv_mpu_i2c_disable(struct iio_dev *indio_dev)
> >  
> >  static int inv_mpu_probe(struct spi_device *spi)
> >  {
> > +	const void *match;
> >  	struct regmap *regmap;
> >  	const struct spi_device_id *spi_id;
> > -	const struct acpi_device_id *acpi_id;
> >  	const char *name = NULL;
> >  	enum inv_devices chip_type;
> >  
> >  	if ((spi_id = spi_get_device_id(spi))) {
> >  		chip_type = (enum inv_devices)spi_id->driver_data;
> >  		name = spi_id->name;
> > -	} else if ((acpi_id = acpi_match_device(spi->dev.driver->acpi_match_table, &spi->dev))) {
> > -		chip_type = (enum inv_devices)acpi_id->driver_data;
> > +	} else if ((match = device_get_match_data(&spi->dev))) {
> > +		chip_type = (enum inv_devices)match;
> > +		name = dev_name(&spi->dev);
> >  	} else {
> >  		return -ENODEV;
> >  	}
> > @@ -74,6 +77,7 @@ static int inv_mpu_probe(struct spi_device *spi)
> >  static const struct spi_device_id inv_mpu_id[] = {
> >  	{"mpu6000", INV_MPU6000},
> >  	{"mpu6500", INV_MPU6500},
> > +	{"mpu6515", INV_MPU6515},
> >  	{"mpu9250", INV_MPU9250},
> >  	{"mpu9255", INV_MPU9255},
> >  	{"icm20608", INV_ICM20608},
> > @@ -83,6 +87,39 @@ static const struct spi_device_id inv_mpu_id[] = {
> >  
> >  MODULE_DEVICE_TABLE(spi, inv_mpu_id);
> >  
> > +static const struct of_device_id inv_of_match[] = {
> > +	{
> > +		.compatible = "invensense,mpu6000",
> > +		.data = (void *)INV_MPU6000
> > +	},
> > +	{
> > +		.compatible = "invensense,mpu6500",
> > +		.data = (void *)INV_MPU6500
> > +	},
> > +	{
> > +		.compatible = "invensense,mpu6515",
> > +		.data = (void *)INV_MPU6515
> > +	},
> > +	{
> > +		.compatible = "invensense,mpu9250",
> > +		.data = (void *)INV_MPU9250
> > +	},
> > +	{
> > +		.compatible = "invensense,mpu9255",
> > +		.data = (void *)INV_MPU9255
> > +	},
> > +	{
> > +		.compatible = "invensense,icm20608",
> > +		.data = (void *)INV_ICM20608
> > +	},
> > +	{
> > +		.compatible = "invensense,icm20602",
> > +		.data = (void *)INV_ICM20602
> > +	},
> > +	{ }
> > +};
> > +MODULE_DEVICE_TABLE(of, inv_of_match);
> > +
> >  static const struct acpi_device_id inv_acpi_match[] = {
> >  	{"INVN6000", INV_MPU6000},
> >  	{ },
> > @@ -93,6 +130,7 @@ static struct spi_driver inv_mpu_driver = {
> >  	.probe		=	inv_mpu_probe,
> >  	.id_table	=	inv_mpu_id,
> >  	.driver = {
> > +		.of_match_table = inv_of_match,
> >  		.acpi_match_table = ACPI_PTR(inv_acpi_match),
> >  		.name	=	"inv-mpu6000-spi",
> >  		.pm     =       &inv_mpu_pmops,  
> 
> 


^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2021-11-08 17:52 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-06 10:30 [PATCH v2 0/6] Add support of similar chips Jean-Baptiste Maneyrol
2020-02-06 10:31 ` [PATCH v2 1/6] iio: imu: inv_mpu6050: cleanup of/acpi support Jean-Baptiste Maneyrol
2020-02-06 11:51   ` Jonathan Cameron
2021-11-08 17:52     ` Jonathan Cameron
2020-02-06 10:31 ` [PATCH v2 2/6] iio: imu: inv_mpu6050: add support of ICM20609 & ICM20689 Jean-Baptiste Maneyrol
2020-02-06 11:53   ` Jonathan Cameron
2020-02-06 10:31 ` [PATCH v2 3/6] iio: imu: inv_mpu6050: add support of IAM20680 Jean-Baptiste Maneyrol
2020-02-06 12:09   ` Jonathan Cameron
2020-02-06 10:31 ` [PATCH v2 4/6] iio: imu: inv_mpu6050: add support of ICM20690 Jean-Baptiste Maneyrol
2020-02-06 12:15   ` Jonathan Cameron
2020-02-06 10:31 ` [PATCH v2 5/6] iio: imu: inv_mpu6050: update LPF bandwidth settings Jean-Baptiste Maneyrol
2020-02-06 12:16   ` Jonathan Cameron
2020-02-06 10:31 ` [PATCH v2 6/6] dt-bindings: add description for new supported chips Jean-Baptiste Maneyrol
2020-02-06 12:16   ` Jonathan Cameron

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.