[v3,2/3] iio: imu: mpu6050: add level shifter flag

Message ID 20230927173245.2151083-3-andreas@kemnade.info
State New
Headers
Series ARM: omap: omap4-embt2ws: Add IMU on control unit |

Commit Message

Andreas Kemnade Sept. 27, 2023, 5:32 p.m. UTC
  Some boards fail in magnetometer probe if level shifter flag is not set,
definition was found in the vendor Linux kernel v3.0.

Signed-off-by: Andreas Kemnade <andreas@kemnade.info>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
---
 drivers/iio/imu/inv_mpu6050/inv_mpu_aux.c  | 13 +++++++++++++
 drivers/iio/imu/inv_mpu6050/inv_mpu_core.c |  3 +++
 drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h  |  1 +
 3 files changed, 17 insertions(+)
  

Comments

Jean-Baptiste Maneyrol Sept. 27, 2023, 7:08 p.m. UTC | #1
Hello,

looks good for me.

Acked-by: Jean-Baptiste Maneyrol <jean-baptiste.maneyrol@tdk.com>

Thanks,
JB


From: Andreas Kemnade <andreas@kemnade.info>
Sent: Wednesday, September 27, 2023 19:32
To: jic23@kernel.org <jic23@kernel.org>; lars@metafoo.de <lars@metafoo.de>; robh+dt@kernel.org <robh+dt@kernel.org>; krzysztof.kozlowski+dt@linaro.org <krzysztof.kozlowski+dt@linaro.org>; conor+dt@kernel.org <conor+dt@kernel.org>; bcousson@baylibre.com <bcousson@baylibre.com>; tony@atomide.com <tony@atomide.com>; andreas@kemnade.info <andreas@kemnade.info>; chenhuiz@axis.com <chenhuiz@axis.com>; Jean-Baptiste Maneyrol <Jean-Baptiste.Maneyrol@tdk.com>; andy.shevchenko@gmail.com <andy.shevchenko@gmail.com>; linux-iio@vger.kernel.org <linux-iio@vger.kernel.org>; devicetree@vger.kernel.org <devicetree@vger.kernel.org>; linux-kernel@vger.kernel.org <linux-kernel@vger.kernel.org>; linux-omap@vger.kernel.org <linux-omap@vger.kernel.org>
Subject: [PATCH v3 2/3] iio: imu: mpu6050: add level shifter flag 
 
Some boards fail in magnetometer probe if level shifter flag is not set, definition was found in the vendor Linux kernel v3. 0. Signed-off-by: Andreas Kemnade <andreas@ kemnade. info> Reviewed-by: Andy Shevchenko <andy. shevchenko@ gmail. com> 
ZjQcmQRYFpfptBannerStart
This Message Is From an External Sender 
This message came from outside your organization. 
 
ZjQcmQRYFpfptBannerEnd
Some boards fail in magnetometer probe if level shifter flag is not set,
definition was found in the vendor Linux kernel v3.0.

Signed-off-by: Andreas Kemnade <andreas@kemnade.info>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
---
 drivers/iio/imu/inv_mpu6050/inv_mpu_aux.c  | 13 +++++++++++++
 drivers/iio/imu/inv_mpu6050/inv_mpu_core.c |  3 +++
 drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h  |  1 +
 3 files changed, 17 insertions(+)

diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_aux.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_aux.c
index 7327e5723f961..8a7f2911905af 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_aux.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_aux.c
@@ -71,6 +71,19 @@ int inv_mpu_aux_init(const struct inv_mpu6050_state *st)
 	unsigned int val;
 	int ret;
 
+	/*
+	 * Code based on the vendor Linux kernel v3.0,
+	 * the exact meaning is unknown.
+	 */
+	if (st->chip_type == INV_MPU9150) {
+		unsigned int mask = BIT(7);
+
+		val = st->level_shifter ? mask : 0;
+		ret = regmap_update_bits(st->map, 0x1, mask, val);
+		if (ret)
+			return ret;
+	}
+
 	/* configure i2c master */
 	val = INV_MPU6050_BITS_I2C_MST_CLK_400KHZ |
 			INV_MPU6050_BIT_WAIT_FOR_ES;
diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
index 29f906c884bd8..3fbeef1a70186 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
@@ -17,6 +17,7 @@
 #include <linux/regulator/consumer.h>
 #include <linux/pm.h>
 #include <linux/pm_runtime.h>
+#include <linux/property.h>
 
 #include <linux/iio/common/inv_sensors_timestamp.h>
 #include <linux/iio/iio.h>
@@ -1495,6 +1496,8 @@ int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name,
 	st->irq = irq;
 	st->map = regmap;
 
+	st->level_shifter = device_property_read_bool(dev,
+						      "invensense,level-shifter");
 	pdata = dev_get_platdata(dev);
 	if (!pdata) {
 		result = iio_read_mount_matrix(dev, &st->orientation);
diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
index ed5a96e78df05..7eba1439c8093 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
@@ -203,6 +203,7 @@ struct inv_mpu6050_state {
 	s32 magn_raw_to_gauss[3];
 	struct iio_mount_matrix magn_orient;
 	unsigned int suspended_sensors;
+	bool level_shifter;
 	u8 *data;
 };
  
Jonathan Cameron Sept. 30, 2023, 4:50 p.m. UTC | #2
On Wed, 27 Sep 2023 19:08:31 +0000
Jean-Baptiste Maneyrol <Jean-Baptiste.Maneyrol@tdk.com> wrote:

> Hello,
> 
> looks good for me.
> 
> Acked-by: Jean-Baptiste Maneyrol <jean-baptiste.maneyrol@tdk.com>

Applied patches 1 and 2 to the togreg branch of iio.git which I will
initially push out as testing to let 0-day poke at it,

Thanks,

Jonathan

> 
> Thanks,
> JB
> 
> 
> From: Andreas Kemnade <andreas@kemnade.info>
> Sent: Wednesday, September 27, 2023 19:32
> To: jic23@kernel.org <jic23@kernel.org>; lars@metafoo.de <lars@metafoo.de>; robh+dt@kernel.org <robh+dt@kernel.org>; krzysztof.kozlowski+dt@linaro.org <krzysztof.kozlowski+dt@linaro.org>; conor+dt@kernel.org <conor+dt@kernel.org>; bcousson@baylibre.com <bcousson@baylibre.com>; tony@atomide.com <tony@atomide.com>; andreas@kemnade.info <andreas@kemnade.info>; chenhuiz@axis.com <chenhuiz@axis.com>; Jean-Baptiste Maneyrol <Jean-Baptiste.Maneyrol@tdk.com>; andy.shevchenko@gmail.com <andy.shevchenko@gmail.com>; linux-iio@vger.kernel.org <linux-iio@vger.kernel.org>; devicetree@vger.kernel.org <devicetree@vger.kernel.org>; linux-kernel@vger.kernel.org <linux-kernel@vger.kernel.org>; linux-omap@vger.kernel.org <linux-omap@vger.kernel.org>
> Subject: [PATCH v3 2/3] iio: imu: mpu6050: add level shifter flag 
>  
> Some boards fail in magnetometer probe if level shifter flag is not set, definition was found in the vendor Linux kernel v3. 0. Signed-off-by: Andreas Kemnade <andreas@ kemnade. info> Reviewed-by: Andy Shevchenko <andy. shevchenko@ gmail. com> 
> ZjQcmQRYFpfptBannerStart
> This Message Is From an External Sender 
> This message came from outside your organization. 
>  
> ZjQcmQRYFpfptBannerEnd
> Some boards fail in magnetometer probe if level shifter flag is not set,
> definition was found in the vendor Linux kernel v3.0.
> 
> Signed-off-by: Andreas Kemnade <andreas@kemnade.info>
> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
> ---
>  drivers/iio/imu/inv_mpu6050/inv_mpu_aux.c  | 13 +++++++++++++
>  drivers/iio/imu/inv_mpu6050/inv_mpu_core.c |  3 +++
>  drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h  |  1 +
>  3 files changed, 17 insertions(+)
> 
> diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_aux.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_aux.c
> index 7327e5723f961..8a7f2911905af 100644
> --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_aux.c
> +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_aux.c
> @@ -71,6 +71,19 @@ int inv_mpu_aux_init(const struct inv_mpu6050_state *st)
>  	unsigned int val;
>  	int ret;
>  
> +	/*
> +	 * Code based on the vendor Linux kernel v3.0,
> +	 * the exact meaning is unknown.
> +	 */
> +	if (st->chip_type == INV_MPU9150) {
> +		unsigned int mask = BIT(7);
> +
> +		val = st->level_shifter ? mask : 0;
> +		ret = regmap_update_bits(st->map, 0x1, mask, val);
> +		if (ret)
> +			return ret;
> +	}
> +
>  	/* configure i2c master */
>  	val = INV_MPU6050_BITS_I2C_MST_CLK_400KHZ |
>  			INV_MPU6050_BIT_WAIT_FOR_ES;
> diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
> index 29f906c884bd8..3fbeef1a70186 100644
> --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
> +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
> @@ -17,6 +17,7 @@
>  #include <linux/regulator/consumer.h>
>  #include <linux/pm.h>
>  #include <linux/pm_runtime.h>
> +#include <linux/property.h>
>  
>  #include <linux/iio/common/inv_sensors_timestamp.h>
>  #include <linux/iio/iio.h>
> @@ -1495,6 +1496,8 @@ int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name,
>  	st->irq = irq;
>  	st->map = regmap;
>  
> +	st->level_shifter = device_property_read_bool(dev,
> +						      "invensense,level-shifter");
>  	pdata = dev_get_platdata(dev);
>  	if (!pdata) {
>  		result = iio_read_mount_matrix(dev, &st->orientation);
> diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
> index ed5a96e78df05..7eba1439c8093 100644
> --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
> +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
> @@ -203,6 +203,7 @@ struct inv_mpu6050_state {
>  	s32 magn_raw_to_gauss[3];
>  	struct iio_mount_matrix magn_orient;
>  	unsigned int suspended_sensors;
> +	bool level_shifter;
>  	u8 *data;
>  };
>
  

Patch

diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_aux.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_aux.c
index 7327e5723f961..8a7f2911905af 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_aux.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_aux.c
@@ -71,6 +71,19 @@  int inv_mpu_aux_init(const struct inv_mpu6050_state *st)
 	unsigned int val;
 	int ret;
 
+	/*
+	 * Code based on the vendor Linux kernel v3.0,
+	 * the exact meaning is unknown.
+	 */
+	if (st->chip_type == INV_MPU9150) {
+		unsigned int mask = BIT(7);
+
+		val = st->level_shifter ? mask : 0;
+		ret = regmap_update_bits(st->map, 0x1, mask, val);
+		if (ret)
+			return ret;
+	}
+
 	/* configure i2c master */
 	val = INV_MPU6050_BITS_I2C_MST_CLK_400KHZ |
 			INV_MPU6050_BIT_WAIT_FOR_ES;
diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
index 29f906c884bd8..3fbeef1a70186 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
@@ -17,6 +17,7 @@ 
 #include <linux/regulator/consumer.h>
 #include <linux/pm.h>
 #include <linux/pm_runtime.h>
+#include <linux/property.h>
 
 #include <linux/iio/common/inv_sensors_timestamp.h>
 #include <linux/iio/iio.h>
@@ -1495,6 +1496,8 @@  int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name,
 	st->irq = irq;
 	st->map = regmap;
 
+	st->level_shifter = device_property_read_bool(dev,
+						      "invensense,level-shifter");
 	pdata = dev_get_platdata(dev);
 	if (!pdata) {
 		result = iio_read_mount_matrix(dev, &st->orientation);
diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
index ed5a96e78df05..7eba1439c8093 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
@@ -203,6 +203,7 @@  struct inv_mpu6050_state {
 	s32 magn_raw_to_gauss[3];
 	struct iio_mount_matrix magn_orient;
 	unsigned int suspended_sensors;
+	bool level_shifter;
 	u8 *data;
 };