Skip to contentSkip to conversation

iio: imu: inv_mpu6050: Add i2c mux for by pass

PATCH Superseded Srinivas Pandruvada 2 participants 5 messages Dec 4, 2014 – Dec 5, 2014 3 messages not in the archive

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 iio: imu: inv_mpu6050: Add i2c mux for by pass

v2
Addressed comments from Wolfram
- Added reference of discussion for adding this mode to commit message to explain the purpose
- Removed static mux variable
- Removed exported interface to add i2c client on the i2c mux comments by Hartmut
- Unregister iio device if there is a failure

Removed ak8975 change from series still this patch is accepted.

v1
Some minor formatting fix mostly suggested by Hartmut fail probe if mux create fails
function parameter type matching i2c struct

v0
base version

Srinivas Pandruvada (1):
iio: imu: inv_mpu6050: Add i2c mux for by pass

 drivers/iio/imu/inv_mpu6050/Kconfig        |   1 +
 drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 135 +++++++++++++++++++++++++++--
 drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h  |   6 ++
 3 files changed, 136 insertions(+), 6 deletions(-)
Signature · 1 line
1.9.3

A message that is not in the archive (sent off-list or not yet received): 1417734625-13739-1-git-send-email-srinivas.pandruvada-VuQAYsv1563Yd54FQh9/[email protected]

#2 lore raw

PATCH v2 1/1 iio: imu: inv_mpu6050: Add i2c mux for by pass

This chip allows some limited number of sensors connected to it as slaves, which can be directly accessed by register interface of this driver.But the current upstream driver doesn't support such mode. To attach such slaves to main processor i2c bus, chip has to be set up in bypass mode. This change adds i2c mux, which will enable/disable this mode for transaction to/from such slave devices.
This was discussed for a while in mailing list, this was the outcome:
Reference:
http://www.spinics.net/lists/linux-iio/msg12126.html
http://comments.gmane.org/gmane.linux.kernel.iio/11470

---
 drivers/iio/imu/inv_mpu6050/Kconfig        |   1 +
 drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 135 +++++++++++++++++++++++++++--
 drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h  |   6 ++
 3 files changed, 136 insertions(+), 6 deletions(-)
drivers/iio/imu/inv_mpu6050/Kconfig +1 -0
index 2d0608b..48fbc0b 100644
@@ -7,6 +7,7 @@ config INV_MPU6050_IIO
 	depends on I2C && SYSFS
 	select IIO_BUFFER
 	select IIO_TRIGGERED_BUFFER
+	select I2C_MUX
 	help
 	  This driver supports the Invensense MPU6050 devices.
 	  This driver can also support MPU6500 in MPU6050 compatibility mode
drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +129 -6

180 lines not on this page · raw message

drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h +6 -0
index e779931..aa837de 100644
@@ -54,6 +54,7 @@ struct inv_mpu6050_reg_map {
 	u8 int_enable;
 	u8 pwr_mgmt_1;
 	u8 pwr_mgmt_2;
+	u8 int_pin_cfg;
 };
 
 /*device enum */
@@ -119,6 +120,8 @@ struct inv_mpu6050_state {
 	enum   inv_devices chip_type;
 	spinlock_t time_stamp_lock;
 	struct i2c_client *client;
+	struct i2c_adapter *mux_adapter;
+	unsigned int powerup_count;
 	struct inv_mpu6050_platform_data plat_data;
 	DECLARE_KFIFO(timestamps, long long, TIMESTAMP_FIFO_SIZE);
 };
@@ -179,6 +182,9 @@ struct inv_mpu6050_state {
 /* 6 + 6 round up and plus 8 */
 #define INV_MPU6050_OUTPUT_DATA_SIZE         24
 
+#define INV_MPU6050_REG_INT_PIN_CFG	0x37
+#define INV_MPU6050_BIT_BYPASS_EN	0x2
+
 /* init parameters */
 #define INV_MPU6050_INIT_FIFO_RATE           50
 #define INV_MPU6050_TIME_STAMP_TOR           5
Signature · 1 line
1.9.3

A message that is not in the archive (sent off-list or not yet received): 1417734625-13739-2-git-send-email-srinivas.pandruvada-VuQAYsv1563Yd54FQh9/[email protected]

Reviewed-by
#4 lore raw
Quoted 11 lines · Srinivas Pandruvada

This chip allows some limited number of sensors connected to it as slaves, which can be directly accessed by register interface of this driver.But the current upstream driver doesn't support such mode. To attach such slaves to main processor i2c bus, chip has to be set up in bypass mode. This change adds i2c mux, which will enable/disable this mode for transaction to/from such slave devices.
This was discussed for a while in mailing list, this was the outcome:
Reference:
http://www.spinics.net/lists/linux-iio/msg12126.html
http://comments.gmane.org/gmane.linux.kernel.iio/11470

Quoted 1 line

Only minor nits, in general:

drivers/iio/imu/inv_mpu6050/inv_mpu_core.c int inv_mpu6050_write_reg(struct inv_mpu6050_state *st, int reg, u8 d) · line 171

Quoted 13 lines
drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +13 -0
+static int inv_mpu6050_create_mux(struct iio_dev *indio_dev)
+{
+	struct inv_mpu6050_state *st = iio_priv(indio_dev);
+	struct i2c_client *client = st->client;
+
+	st->mux_adapter = i2c_add_mux_adapter(client->adapter,
+					      &client->dev,
+					      indio_dev,
+					      0, 0, 0,
+					      inv_mpu6050_select_bypass,
+					      inv_mpu6050_deselect_bypass);
+	if (st->mux_adapter == NULL) {
+		dev_err(&st->client->dev, "Mux create Failed\n");

i2c_add_mux_adapter prints error messages on its own, so this is not needed.

drivers/iio/imu/inv_mpu6050/inv_mpu_core.c int inv_mpu6050_write_reg(struct inv_mpu6050_state *st, int reg, u8 d) · line 184

Quoted 13 lines
drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +13 -0
+		return -ENODEV;
+	}
+
+	return 0;
+}
+
+static void inv_mpu6050_destroy_mux(struct iio_dev *indio_dev)
+{
+	struct inv_mpu6050_state *mpu_st = iio_priv(indio_dev);
+
+	if (mpu_st->mux_adapter)
+		i2c_del_mux_adapter(mpu_st->mux_adapter);
+}

Since those two functions are only called once and don't encapsulate much, I'd rather put the commands directly into the calling functions.

#5 lore raw
Quoted 35 lines · Wolfram Sang
Quoted 11 lines · Srinivas Pandruvada

This chip allows some limited number of sensors connected to it as slaves, which can be directly accessed by register interface of this driver.But the current upstream driver doesn't support such mode. To attach such slaves to main processor i2c bus, chip has to be set up in bypass mode. This change adds i2c mux, which will enable/disable this mode for transaction to/from such slave devices.
This was discussed for a while in mailing list, this was the outcome:
Reference:
http://www.spinics.net/lists/linux-iio/msg12126.html
http://comments.gmane.org/gmane.linux.kernel.iio/11470

Quoted 1 line

Only minor nits, in general:

drivers/iio/imu/inv_mpu6050/inv_mpu_core.c int inv_mpu6050_write_reg(struct inv_mpu6050_state *st, int reg, u8 d) · line 171

Quoted 13 lines
drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +13 -0
+static int inv_mpu6050_create_mux(struct iio_dev *indio_dev)
+{
+	struct inv_mpu6050_state *st = iio_priv(indio_dev);
+	struct i2c_client *client = st->client;
+
+	st->mux_adapter = i2c_add_mux_adapter(client->adapter,
+					      &client->dev,
+					      indio_dev,
+					      0, 0, 0,
+					      inv_mpu6050_select_bypass,
+					      inv_mpu6050_deselect_bypass);
+	if (st->mux_adapter == NULL) {
+		dev_err(&st->client->dev, "Mux create Failed\n");

i2c_add_mux_adapter prints error messages on its own, so this is not needed.

Quoted 16 lines

drivers/iio/imu/inv_mpu6050/inv_mpu_core.c int inv_mpu6050_write_reg(struct inv_mpu6050_state *st, int reg, u8 d) · line 184

Quoted 13 lines
drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +13 -0
+		return -ENODEV;
+	}
+
+	return 0;
+}
+
+static void inv_mpu6050_destroy_mux(struct iio_dev *indio_dev)
+{
+	struct inv_mpu6050_state *mpu_st = iio_priv(indio_dev);
+
+	if (mpu_st->mux_adapter)
+		i2c_del_mux_adapter(mpu_st->mux_adapter);
+}

Since those two functions are only called once and don't encapsulate much, I'd rather put the commands directly into the calling functions.

Agree. I will move them to the caller and submit another version. I hope, I can still use reviewed-by tag, after this change.

Thanks,
Srinivas

Quoted 1 line

A message that is not in the archive (sent off-list or not yet received): 1417795398.1851.17.camel-hINH/TbAiWppyMZ9rn1DP+ejPoqOX1/[email protected]

#7 lore raw
Quoted 5 lines
Quoted 3 lines

Since those two functions are only called once and don't encapsulate much, I'd rather put the commands directly into the calling functions.

Agree. I will move them to the caller and submit another version. I hope, I can still use reviewed-by tag, after this change.

If you only change my comments, then yes!