linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/4] st_lsm6dsx: move {odr,fs}_table in
@ 2019-07-29 19:22 Lorenzo Bianconi
  2019-07-29 19:22 ` [PATCH v2 1/4] iio: imu: st_lsm6dsx: move odr_table in st_lsm6dsx_sensor_settings Lorenzo Bianconi
                   ` (3 more replies)
  0 siblings, 4 replies; 11+ messages in thread
From: Lorenzo Bianconi @ 2019-07-29 19:22 UTC (permalink / raw)
  To: jic23; +Cc: lorenzo.bianconi, linux-iio, martin.kepplinger

Move odr and gain table in st_lsm6dsx_sensor_settings maps in order to support
devices with different odr/fs definitions. Moreover move iio channel
definitions in st_lsm6dsx_sensor_settings.
This is a preliminary series to add support for LSM9DS1 and irq wake up support.

Changes since v1:
- rebase ontop of linux-iio testing branch
- move iio channel definitions in st_lsm6dsx_sensor_settings

Lorenzo Bianconi (4):
  iio: imu: st_lsm6dsx: move odr_table in st_lsm6dsx_sensor_settings
  iio: imu: st_lsm6dsx: move fs_table in st_lsm6dsx_sensor_settings
  iio: imu: st_lsm6dsx: inline output acc/gyro output regs
  iio: imu: st_lsm6dsx: move iio chan definitions in
    st_lsm6dsx_sensor_settings

 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h      |   9 +
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 473 +++++++++++++++----
 2 files changed, 387 insertions(+), 95 deletions(-)

-- 
2.21.0


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

* [PATCH v2 1/4] iio: imu: st_lsm6dsx: move odr_table in st_lsm6dsx_sensor_settings
  2019-07-29 19:22 [PATCH v2 0/4] st_lsm6dsx: move {odr,fs}_table in Lorenzo Bianconi
@ 2019-07-29 19:22 ` Lorenzo Bianconi
  2019-08-05 14:17   ` Jonathan Cameron
  2019-07-29 19:22 ` [PATCH v2 2/4] iio: imu: st_lsm6dsx: move fs_table " Lorenzo Bianconi
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 11+ messages in thread
From: Lorenzo Bianconi @ 2019-07-29 19:22 UTC (permalink / raw)
  To: jic23; +Cc: lorenzo.bianconi, linux-iio, martin.kepplinger

Move sensor odr table in st_lsm6dsx_sensor_settings in order to support
sensors with different odr maps. This is a preliminary patch to add
support for LSM9DS1 sensor to st_lsm6dsx driver

Tested-by: Martin Kepplinger <martin.kepplinger@puri.sm>
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
---
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h      |   2 +
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 196 ++++++++++++++++---
 2 files changed, 166 insertions(+), 32 deletions(-)

diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
index af379a5429ed..3a89f3f6e2c7 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
@@ -200,6 +200,7 @@ struct st_lsm6dsx_ext_dev_settings {
  * @wai: Sensor WhoAmI default value.
  * @max_fifo_size: Sensor max fifo length in FIFO words.
  * @id: List of hw id/device name supported by the driver configuration.
+ * @odr_table: Hw sensors odr table (Hz + val).
  * @decimator: List of decimator register info (addr + mask).
  * @batch: List of FIFO batching register info (addr + mask).
  * @fifo_ops: Sensor hw FIFO parameters.
@@ -213,6 +214,7 @@ struct st_lsm6dsx_settings {
 		enum st_lsm6dsx_hw_id hw_id;
 		const char *name;
 	} id[ST_LSM6DSX_MAX_ID];
+	struct st_lsm6dsx_odr_table_entry odr_table[2];
 	struct st_lsm6dsx_reg decimator[ST_LSM6DSX_MAX_ID];
 	struct st_lsm6dsx_reg batch[ST_LSM6DSX_MAX_ID];
 	struct st_lsm6dsx_fifo_ops fifo_ops;
diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
index d8c4417cf4eb..b3c6c9792913 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
@@ -69,33 +69,6 @@
 #define ST_LSM6DSX_REG_GYRO_OUT_Y_L_ADDR	0x24
 #define ST_LSM6DSX_REG_GYRO_OUT_Z_L_ADDR	0x26
 
-static const struct st_lsm6dsx_odr_table_entry st_lsm6dsx_odr_table[] = {
-	[ST_LSM6DSX_ID_ACC] = {
-		.reg = {
-			.addr = 0x10,
-			.mask = GENMASK(7, 4),
-		},
-		.odr_avl[0] = {  13, 0x01 },
-		.odr_avl[1] = {  26, 0x02 },
-		.odr_avl[2] = {  52, 0x03 },
-		.odr_avl[3] = { 104, 0x04 },
-		.odr_avl[4] = { 208, 0x05 },
-		.odr_avl[5] = { 416, 0x06 },
-	},
-	[ST_LSM6DSX_ID_GYRO] = {
-		.reg = {
-			.addr = 0x11,
-			.mask = GENMASK(7, 4),
-		},
-		.odr_avl[0] = {  13, 0x01 },
-		.odr_avl[1] = {  26, 0x02 },
-		.odr_avl[2] = {  52, 0x03 },
-		.odr_avl[3] = { 104, 0x04 },
-		.odr_avl[4] = { 208, 0x05 },
-		.odr_avl[5] = { 416, 0x06 },
-	}
-};
-
 static const struct st_lsm6dsx_fs_table_entry st_lsm6dsx_fs_table[] = {
 	[ST_LSM6DSX_ID_ACC] = {
 		.reg = {
@@ -129,6 +102,32 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 				.name = ST_LSM6DS3_DEV_NAME,
 			},
 		},
+		.odr_table = {
+			[ST_LSM6DSX_ID_ACC] = {
+				.reg = {
+					.addr = 0x10,
+					.mask = GENMASK(7, 4),
+				},
+				.odr_avl[0] = {  13, 0x01 },
+				.odr_avl[1] = {  26, 0x02 },
+				.odr_avl[2] = {  52, 0x03 },
+				.odr_avl[3] = { 104, 0x04 },
+				.odr_avl[4] = { 208, 0x05 },
+				.odr_avl[5] = { 416, 0x06 },
+			},
+			[ST_LSM6DSX_ID_GYRO] = {
+				.reg = {
+					.addr = 0x11,
+					.mask = GENMASK(7, 4),
+				},
+				.odr_avl[0] = {  13, 0x01 },
+				.odr_avl[1] = {  26, 0x02 },
+				.odr_avl[2] = {  52, 0x03 },
+				.odr_avl[3] = { 104, 0x04 },
+				.odr_avl[4] = { 208, 0x05 },
+				.odr_avl[5] = { 416, 0x06 },
+			},
+		},
 		.decimator = {
 			[ST_LSM6DSX_ID_ACC] = {
 				.addr = 0x08,
@@ -179,6 +178,32 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 				.name = ST_LSM6DS3H_DEV_NAME,
 			},
 		},
+		.odr_table = {
+			[ST_LSM6DSX_ID_ACC] = {
+				.reg = {
+					.addr = 0x10,
+					.mask = GENMASK(7, 4),
+				},
+				.odr_avl[0] = {  13, 0x01 },
+				.odr_avl[1] = {  26, 0x02 },
+				.odr_avl[2] = {  52, 0x03 },
+				.odr_avl[3] = { 104, 0x04 },
+				.odr_avl[4] = { 208, 0x05 },
+				.odr_avl[5] = { 416, 0x06 },
+			},
+			[ST_LSM6DSX_ID_GYRO] = {
+				.reg = {
+					.addr = 0x11,
+					.mask = GENMASK(7, 4),
+				},
+				.odr_avl[0] = {  13, 0x01 },
+				.odr_avl[1] = {  26, 0x02 },
+				.odr_avl[2] = {  52, 0x03 },
+				.odr_avl[3] = { 104, 0x04 },
+				.odr_avl[4] = { 208, 0x05 },
+				.odr_avl[5] = { 416, 0x06 },
+			},
+		},
 		.decimator = {
 			[ST_LSM6DSX_ID_ACC] = {
 				.addr = 0x08,
@@ -238,6 +263,32 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 				.name = ST_LSM6DS3TRC_DEV_NAME,
 			},
 		},
+		.odr_table = {
+			[ST_LSM6DSX_ID_ACC] = {
+				.reg = {
+					.addr = 0x10,
+					.mask = GENMASK(7, 4),
+				},
+				.odr_avl[0] = {  13, 0x01 },
+				.odr_avl[1] = {  26, 0x02 },
+				.odr_avl[2] = {  52, 0x03 },
+				.odr_avl[3] = { 104, 0x04 },
+				.odr_avl[4] = { 208, 0x05 },
+				.odr_avl[5] = { 416, 0x06 },
+			},
+			[ST_LSM6DSX_ID_GYRO] = {
+				.reg = {
+					.addr = 0x11,
+					.mask = GENMASK(7, 4),
+				},
+				.odr_avl[0] = {  13, 0x01 },
+				.odr_avl[1] = {  26, 0x02 },
+				.odr_avl[2] = {  52, 0x03 },
+				.odr_avl[3] = { 104, 0x04 },
+				.odr_avl[4] = { 208, 0x05 },
+				.odr_avl[5] = { 416, 0x06 },
+			},
+		},
 		.decimator = {
 			[ST_LSM6DSX_ID_ACC] = {
 				.addr = 0x08,
@@ -291,6 +342,32 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 				.name = ST_LSM6DSOX_DEV_NAME,
 			},
 		},
+		.odr_table = {
+			[ST_LSM6DSX_ID_ACC] = {
+				.reg = {
+					.addr = 0x10,
+					.mask = GENMASK(7, 4),
+				},
+				.odr_avl[0] = {  13, 0x01 },
+				.odr_avl[1] = {  26, 0x02 },
+				.odr_avl[2] = {  52, 0x03 },
+				.odr_avl[3] = { 104, 0x04 },
+				.odr_avl[4] = { 208, 0x05 },
+				.odr_avl[5] = { 416, 0x06 },
+			},
+			[ST_LSM6DSX_ID_GYRO] = {
+				.reg = {
+					.addr = 0x11,
+					.mask = GENMASK(7, 4),
+				},
+				.odr_avl[0] = {  13, 0x01 },
+				.odr_avl[1] = {  26, 0x02 },
+				.odr_avl[2] = {  52, 0x03 },
+				.odr_avl[3] = { 104, 0x04 },
+				.odr_avl[4] = { 208, 0x05 },
+				.odr_avl[5] = { 416, 0x06 },
+			},
+		},
 		.batch = {
 			[ST_LSM6DSX_ID_ACC] = {
 				.addr = 0x09,
@@ -359,6 +436,32 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 				.name = ST_ASM330LHH_DEV_NAME,
 			},
 		},
+		.odr_table = {
+			[ST_LSM6DSX_ID_ACC] = {
+				.reg = {
+					.addr = 0x10,
+					.mask = GENMASK(7, 4),
+				},
+				.odr_avl[0] = {  13, 0x01 },
+				.odr_avl[1] = {  26, 0x02 },
+				.odr_avl[2] = {  52, 0x03 },
+				.odr_avl[3] = { 104, 0x04 },
+				.odr_avl[4] = { 208, 0x05 },
+				.odr_avl[5] = { 416, 0x06 },
+			},
+			[ST_LSM6DSX_ID_GYRO] = {
+				.reg = {
+					.addr = 0x11,
+					.mask = GENMASK(7, 4),
+				},
+				.odr_avl[0] = {  13, 0x01 },
+				.odr_avl[1] = {  26, 0x02 },
+				.odr_avl[2] = {  52, 0x03 },
+				.odr_avl[3] = { 104, 0x04 },
+				.odr_avl[4] = { 208, 0x05 },
+				.odr_avl[5] = { 416, 0x06 },
+			},
+		},
 		.batch = {
 			[ST_LSM6DSX_ID_ACC] = {
 				.addr = 0x09,
@@ -401,6 +504,32 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 				.name = ST_LSM6DSR_DEV_NAME,
 			},
 		},
+		.odr_table = {
+			[ST_LSM6DSX_ID_ACC] = {
+				.reg = {
+					.addr = 0x10,
+					.mask = GENMASK(7, 4),
+				},
+				.odr_avl[0] = {  13, 0x01 },
+				.odr_avl[1] = {  26, 0x02 },
+				.odr_avl[2] = {  52, 0x03 },
+				.odr_avl[3] = { 104, 0x04 },
+				.odr_avl[4] = { 208, 0x05 },
+				.odr_avl[5] = { 416, 0x06 },
+			},
+			[ST_LSM6DSX_ID_GYRO] = {
+				.reg = {
+					.addr = 0x11,
+					.mask = GENMASK(7, 4),
+				},
+				.odr_avl[0] = {  13, 0x01 },
+				.odr_avl[1] = {  26, 0x02 },
+				.odr_avl[2] = {  52, 0x03 },
+				.odr_avl[3] = { 104, 0x04 },
+				.odr_avl[4] = { 208, 0x05 },
+				.odr_avl[5] = { 416, 0x06 },
+			},
+		},
 		.batch = {
 			[ST_LSM6DSX_ID_ACC] = {
 				.addr = 0x09,
@@ -563,20 +692,22 @@ static int st_lsm6dsx_set_full_scale(struct st_lsm6dsx_sensor *sensor,
 
 int st_lsm6dsx_check_odr(struct st_lsm6dsx_sensor *sensor, u16 odr, u8 *val)
 {
+	const struct st_lsm6dsx_odr_table_entry *odr_table;
 	int i;
 
+	odr_table = &sensor->hw->settings->odr_table[sensor->id];
 	for (i = 0; i < ST_LSM6DSX_ODR_LIST_SIZE; i++)
 		/*
 		 * ext devices can run at different odr respect to
 		 * accel sensor
 		 */
-		if (st_lsm6dsx_odr_table[sensor->id].odr_avl[i].hz >= odr)
+		if (odr_table->odr_avl[i].hz >= odr)
 			break;
 
 	if (i == ST_LSM6DSX_ODR_LIST_SIZE)
 		return -EINVAL;
 
-	*val = st_lsm6dsx_odr_table[sensor->id].odr_avl[i].val;
+	*val = odr_table->odr_avl[i].val;
 
 	return 0;
 }
@@ -641,7 +772,7 @@ static int st_lsm6dsx_set_odr(struct st_lsm6dsx_sensor *sensor, u16 req_odr)
 			return err;
 	}
 
-	reg = &st_lsm6dsx_odr_table[ref_sensor->id].reg;
+	reg = &hw->settings->odr_table[ref_sensor->id].reg;
 	data = ST_LSM6DSX_SHIFT_VAL(val, reg->mask);
 	return st_lsm6dsx_update_bits_locked(hw, reg->addr, reg->mask, data);
 }
@@ -786,11 +917,12 @@ st_lsm6dsx_sysfs_sampling_frequency_avail(struct device *dev,
 {
 	struct st_lsm6dsx_sensor *sensor = iio_priv(dev_get_drvdata(dev));
 	enum st_lsm6dsx_sensor_id id = sensor->id;
+	struct st_lsm6dsx_hw *hw = sensor->hw;
 	int i, len = 0;
 
 	for (i = 0; i < ST_LSM6DSX_ODR_LIST_SIZE; i++)
 		len += scnprintf(buf + len, PAGE_SIZE - len, "%d ",
-				 st_lsm6dsx_odr_table[id].odr_avl[i].hz);
+				 hw->settings->odr_table[id].odr_avl[i].hz);
 	buf[len - 1] = '\n';
 
 	return len;
@@ -1040,7 +1172,7 @@ static struct iio_dev *st_lsm6dsx_alloc_iiodev(struct st_lsm6dsx_hw *hw,
 	sensor = iio_priv(iio_dev);
 	sensor->id = id;
 	sensor->hw = hw;
-	sensor->odr = st_lsm6dsx_odr_table[id].odr_avl[0].hz;
+	sensor->odr = hw->settings->odr_table[id].odr_avl[0].hz;
 	sensor->gain = st_lsm6dsx_fs_table[id].fs_avl[0].gain;
 	sensor->watermark = 1;
 
-- 
2.21.0


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

* [PATCH v2 2/4] iio: imu: st_lsm6dsx: move fs_table in st_lsm6dsx_sensor_settings
  2019-07-29 19:22 [PATCH v2 0/4] st_lsm6dsx: move {odr,fs}_table in Lorenzo Bianconi
  2019-07-29 19:22 ` [PATCH v2 1/4] iio: imu: st_lsm6dsx: move odr_table in st_lsm6dsx_sensor_settings Lorenzo Bianconi
@ 2019-07-29 19:22 ` Lorenzo Bianconi
  2019-08-05 14:18   ` Jonathan Cameron
  2019-07-29 19:22 ` [PATCH v2 3/4] iio: imu: st_lsm6dsx: inline output acc/gyro output regs Lorenzo Bianconi
  2019-07-29 19:22 ` [PATCH v2 4/4] iio: imu: st_lsm6dsx: move iio chan definitions in st_lsm6dsx_sensor_settings Lorenzo Bianconi
  3 siblings, 1 reply; 11+ messages in thread
From: Lorenzo Bianconi @ 2019-07-29 19:22 UTC (permalink / raw)
  To: jic23; +Cc: lorenzo.bianconi, linux-iio, martin.kepplinger

Move fs_table in st_lsm6dsx_sensor_settings in order to support
sensors with different gain maps. This is a preliminary patch to add
support for LSM9DS1 sensor to st_lsm6dsx driver

Tested-by: Martin Kepplinger <martin.kepplinger@puri.sm>
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
---
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h      |   2 +
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 175 +++++++++++++++----
 2 files changed, 144 insertions(+), 33 deletions(-)

diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
index 3a89f3f6e2c7..ab1c66615d67 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
@@ -201,6 +201,7 @@ struct st_lsm6dsx_ext_dev_settings {
  * @max_fifo_size: Sensor max fifo length in FIFO words.
  * @id: List of hw id/device name supported by the driver configuration.
  * @odr_table: Hw sensors odr table (Hz + val).
+ * @fs_table: Hw sensors gain table (gain + val).
  * @decimator: List of decimator register info (addr + mask).
  * @batch: List of FIFO batching register info (addr + mask).
  * @fifo_ops: Sensor hw FIFO parameters.
@@ -215,6 +216,7 @@ struct st_lsm6dsx_settings {
 		const char *name;
 	} id[ST_LSM6DSX_MAX_ID];
 	struct st_lsm6dsx_odr_table_entry odr_table[2];
+	struct st_lsm6dsx_fs_table_entry fs_table[2];
 	struct st_lsm6dsx_reg decimator[ST_LSM6DSX_MAX_ID];
 	struct st_lsm6dsx_reg batch[ST_LSM6DSX_MAX_ID];
 	struct st_lsm6dsx_fifo_ops fifo_ops;
diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
index b3c6c9792913..9aa109428a52 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
@@ -69,29 +69,6 @@
 #define ST_LSM6DSX_REG_GYRO_OUT_Y_L_ADDR	0x24
 #define ST_LSM6DSX_REG_GYRO_OUT_Z_L_ADDR	0x26
 
-static const struct st_lsm6dsx_fs_table_entry st_lsm6dsx_fs_table[] = {
-	[ST_LSM6DSX_ID_ACC] = {
-		.reg = {
-			.addr = 0x10,
-			.mask = GENMASK(3, 2),
-		},
-		.fs_avl[0] = {  IIO_G_TO_M_S_2(61), 0x0 },
-		.fs_avl[1] = { IIO_G_TO_M_S_2(122), 0x2 },
-		.fs_avl[2] = { IIO_G_TO_M_S_2(244), 0x3 },
-		.fs_avl[3] = { IIO_G_TO_M_S_2(488), 0x1 },
-	},
-	[ST_LSM6DSX_ID_GYRO] = {
-		.reg = {
-			.addr = 0x11,
-			.mask = GENMASK(3, 2),
-		},
-		.fs_avl[0] = {  IIO_DEGREE_TO_RAD(8750), 0x0 },
-		.fs_avl[1] = { IIO_DEGREE_TO_RAD(17500), 0x1 },
-		.fs_avl[2] = { IIO_DEGREE_TO_RAD(35000), 0x2 },
-		.fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 },
-	}
-};
-
 static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 	{
 		.wai = 0x69,
@@ -128,6 +105,28 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 				.odr_avl[5] = { 416, 0x06 },
 			},
 		},
+		.fs_table = {
+			[ST_LSM6DSX_ID_ACC] = {
+				.reg = {
+					.addr = 0x10,
+					.mask = GENMASK(3, 2),
+				},
+				.fs_avl[0] = {  IIO_G_TO_M_S_2(61), 0x0 },
+				.fs_avl[1] = { IIO_G_TO_M_S_2(122), 0x2 },
+				.fs_avl[2] = { IIO_G_TO_M_S_2(244), 0x3 },
+				.fs_avl[3] = { IIO_G_TO_M_S_2(488), 0x1 },
+			},
+			[ST_LSM6DSX_ID_GYRO] = {
+				.reg = {
+					.addr = 0x11,
+					.mask = GENMASK(3, 2),
+				},
+				.fs_avl[0] = {  IIO_DEGREE_TO_RAD(8750), 0x0 },
+				.fs_avl[1] = { IIO_DEGREE_TO_RAD(17500), 0x1 },
+				.fs_avl[2] = { IIO_DEGREE_TO_RAD(35000), 0x2 },
+				.fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 },
+			},
+		},
 		.decimator = {
 			[ST_LSM6DSX_ID_ACC] = {
 				.addr = 0x08,
@@ -204,6 +203,28 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 				.odr_avl[5] = { 416, 0x06 },
 			},
 		},
+		.fs_table = {
+			[ST_LSM6DSX_ID_ACC] = {
+				.reg = {
+					.addr = 0x10,
+					.mask = GENMASK(3, 2),
+				},
+				.fs_avl[0] = {  IIO_G_TO_M_S_2(61), 0x0 },
+				.fs_avl[1] = { IIO_G_TO_M_S_2(122), 0x2 },
+				.fs_avl[2] = { IIO_G_TO_M_S_2(244), 0x3 },
+				.fs_avl[3] = { IIO_G_TO_M_S_2(488), 0x1 },
+			},
+			[ST_LSM6DSX_ID_GYRO] = {
+				.reg = {
+					.addr = 0x11,
+					.mask = GENMASK(3, 2),
+				},
+				.fs_avl[0] = {  IIO_DEGREE_TO_RAD(8750), 0x0 },
+				.fs_avl[1] = { IIO_DEGREE_TO_RAD(17500), 0x1 },
+				.fs_avl[2] = { IIO_DEGREE_TO_RAD(35000), 0x2 },
+				.fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 },
+			},
+		},
 		.decimator = {
 			[ST_LSM6DSX_ID_ACC] = {
 				.addr = 0x08,
@@ -289,6 +310,28 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 				.odr_avl[5] = { 416, 0x06 },
 			},
 		},
+		.fs_table = {
+			[ST_LSM6DSX_ID_ACC] = {
+				.reg = {
+					.addr = 0x10,
+					.mask = GENMASK(3, 2),
+				},
+				.fs_avl[0] = {  IIO_G_TO_M_S_2(61), 0x0 },
+				.fs_avl[1] = { IIO_G_TO_M_S_2(122), 0x2 },
+				.fs_avl[2] = { IIO_G_TO_M_S_2(244), 0x3 },
+				.fs_avl[3] = { IIO_G_TO_M_S_2(488), 0x1 },
+			},
+			[ST_LSM6DSX_ID_GYRO] = {
+				.reg = {
+					.addr = 0x11,
+					.mask = GENMASK(3, 2),
+				},
+				.fs_avl[0] = {  IIO_DEGREE_TO_RAD(8750), 0x0 },
+				.fs_avl[1] = { IIO_DEGREE_TO_RAD(17500), 0x1 },
+				.fs_avl[2] = { IIO_DEGREE_TO_RAD(35000), 0x2 },
+				.fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 },
+			},
+		},
 		.decimator = {
 			[ST_LSM6DSX_ID_ACC] = {
 				.addr = 0x08,
@@ -368,6 +411,28 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 				.odr_avl[5] = { 416, 0x06 },
 			},
 		},
+		.fs_table = {
+			[ST_LSM6DSX_ID_ACC] = {
+				.reg = {
+					.addr = 0x10,
+					.mask = GENMASK(3, 2),
+				},
+				.fs_avl[0] = {  IIO_G_TO_M_S_2(61), 0x0 },
+				.fs_avl[1] = { IIO_G_TO_M_S_2(122), 0x2 },
+				.fs_avl[2] = { IIO_G_TO_M_S_2(244), 0x3 },
+				.fs_avl[3] = { IIO_G_TO_M_S_2(488), 0x1 },
+			},
+			[ST_LSM6DSX_ID_GYRO] = {
+				.reg = {
+					.addr = 0x11,
+					.mask = GENMASK(3, 2),
+				},
+				.fs_avl[0] = {  IIO_DEGREE_TO_RAD(8750), 0x0 },
+				.fs_avl[1] = { IIO_DEGREE_TO_RAD(17500), 0x1 },
+				.fs_avl[2] = { IIO_DEGREE_TO_RAD(35000), 0x2 },
+				.fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 },
+			},
+		},
 		.batch = {
 			[ST_LSM6DSX_ID_ACC] = {
 				.addr = 0x09,
@@ -462,6 +527,28 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 				.odr_avl[5] = { 416, 0x06 },
 			},
 		},
+		.fs_table = {
+			[ST_LSM6DSX_ID_ACC] = {
+				.reg = {
+					.addr = 0x10,
+					.mask = GENMASK(3, 2),
+				},
+				.fs_avl[0] = {  IIO_G_TO_M_S_2(61), 0x0 },
+				.fs_avl[1] = { IIO_G_TO_M_S_2(122), 0x2 },
+				.fs_avl[2] = { IIO_G_TO_M_S_2(244), 0x3 },
+				.fs_avl[3] = { IIO_G_TO_M_S_2(488), 0x1 },
+			},
+			[ST_LSM6DSX_ID_GYRO] = {
+				.reg = {
+					.addr = 0x11,
+					.mask = GENMASK(3, 2),
+				},
+				.fs_avl[0] = {  IIO_DEGREE_TO_RAD(8750), 0x0 },
+				.fs_avl[1] = { IIO_DEGREE_TO_RAD(17500), 0x1 },
+				.fs_avl[2] = { IIO_DEGREE_TO_RAD(35000), 0x2 },
+				.fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 },
+			},
+		},
 		.batch = {
 			[ST_LSM6DSX_ID_ACC] = {
 				.addr = 0x09,
@@ -530,6 +617,28 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 				.odr_avl[5] = { 416, 0x06 },
 			},
 		},
+		.fs_table = {
+			[ST_LSM6DSX_ID_ACC] = {
+				.reg = {
+					.addr = 0x10,
+					.mask = GENMASK(3, 2),
+				},
+				.fs_avl[0] = {  IIO_G_TO_M_S_2(61), 0x0 },
+				.fs_avl[1] = { IIO_G_TO_M_S_2(122), 0x2 },
+				.fs_avl[2] = { IIO_G_TO_M_S_2(244), 0x3 },
+				.fs_avl[3] = { IIO_G_TO_M_S_2(488), 0x1 },
+			},
+			[ST_LSM6DSX_ID_GYRO] = {
+				.reg = {
+					.addr = 0x11,
+					.mask = GENMASK(3, 2),
+				},
+				.fs_avl[0] = {  IIO_DEGREE_TO_RAD(8750), 0x0 },
+				.fs_avl[1] = { IIO_DEGREE_TO_RAD(17500), 0x1 },
+				.fs_avl[2] = { IIO_DEGREE_TO_RAD(35000), 0x2 },
+				.fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 },
+			},
+		},
 		.batch = {
 			[ST_LSM6DSX_ID_ACC] = {
 				.addr = 0x09,
@@ -665,23 +774,22 @@ static int st_lsm6dsx_check_whoami(struct st_lsm6dsx_hw *hw, int id,
 static int st_lsm6dsx_set_full_scale(struct st_lsm6dsx_sensor *sensor,
 				     u32 gain)
 {
-	struct st_lsm6dsx_hw *hw = sensor->hw;
-	const struct st_lsm6dsx_reg *reg;
+	const struct st_lsm6dsx_fs_table_entry *fs_table;
 	unsigned int data;
 	int i, err;
-	u8 val;
 
+	fs_table = &sensor->hw->settings->fs_table[sensor->id];
 	for (i = 0; i < ST_LSM6DSX_FS_LIST_SIZE; i++)
-		if (st_lsm6dsx_fs_table[sensor->id].fs_avl[i].gain == gain)
+		if (fs_table->fs_avl[i].gain == gain)
 			break;
 
 	if (i == ST_LSM6DSX_FS_LIST_SIZE)
 		return -EINVAL;
 
-	val = st_lsm6dsx_fs_table[sensor->id].fs_avl[i].val;
-	reg = &st_lsm6dsx_fs_table[sensor->id].reg;
-	data = ST_LSM6DSX_SHIFT_VAL(val, reg->mask);
-	err = st_lsm6dsx_update_bits_locked(hw, reg->addr, reg->mask, data);
+	data = ST_LSM6DSX_SHIFT_VAL(fs_table->fs_avl[i].val,
+				    fs_table->reg.mask);
+	err = st_lsm6dsx_update_bits_locked(sensor->hw, fs_table->reg.addr,
+					    fs_table->reg.mask, data);
 	if (err < 0)
 		return err;
 
@@ -934,11 +1042,12 @@ static ssize_t st_lsm6dsx_sysfs_scale_avail(struct device *dev,
 {
 	struct st_lsm6dsx_sensor *sensor = iio_priv(dev_get_drvdata(dev));
 	enum st_lsm6dsx_sensor_id id = sensor->id;
+	struct st_lsm6dsx_hw *hw = sensor->hw;
 	int i, len = 0;
 
 	for (i = 0; i < ST_LSM6DSX_FS_LIST_SIZE; i++)
 		len += scnprintf(buf + len, PAGE_SIZE - len, "0.%06u ",
-				 st_lsm6dsx_fs_table[id].fs_avl[i].gain);
+				 hw->settings->fs_table[id].fs_avl[i].gain);
 	buf[len - 1] = '\n';
 
 	return len;
@@ -1173,7 +1282,7 @@ static struct iio_dev *st_lsm6dsx_alloc_iiodev(struct st_lsm6dsx_hw *hw,
 	sensor->id = id;
 	sensor->hw = hw;
 	sensor->odr = hw->settings->odr_table[id].odr_avl[0].hz;
-	sensor->gain = st_lsm6dsx_fs_table[id].fs_avl[0].gain;
+	sensor->gain = hw->settings->fs_table[id].fs_avl[0].gain;
 	sensor->watermark = 1;
 
 	switch (id) {
-- 
2.21.0


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

* [PATCH v2 3/4] iio: imu: st_lsm6dsx: inline output acc/gyro output regs
  2019-07-29 19:22 [PATCH v2 0/4] st_lsm6dsx: move {odr,fs}_table in Lorenzo Bianconi
  2019-07-29 19:22 ` [PATCH v2 1/4] iio: imu: st_lsm6dsx: move odr_table in st_lsm6dsx_sensor_settings Lorenzo Bianconi
  2019-07-29 19:22 ` [PATCH v2 2/4] iio: imu: st_lsm6dsx: move fs_table " Lorenzo Bianconi
@ 2019-07-29 19:22 ` Lorenzo Bianconi
  2019-08-02  5:35   ` Martin Kepplinger
  2019-07-29 19:22 ` [PATCH v2 4/4] iio: imu: st_lsm6dsx: move iio chan definitions in st_lsm6dsx_sensor_settings Lorenzo Bianconi
  3 siblings, 1 reply; 11+ messages in thread
From: Lorenzo Bianconi @ 2019-07-29 19:22 UTC (permalink / raw)
  To: jic23; +Cc: lorenzo.bianconi, linux-iio, martin.kepplinger

Remove output register definition and inline register value since
they are used only for iio channel definition. This is a preliminary
patch to add support for LSM9DS1 sensor to st_lsm6dsx driver

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
---
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 26 +++++---------------
 1 file changed, 6 insertions(+), 20 deletions(-)

diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
index 9aa109428a52..0abd5b85b398 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
@@ -61,14 +61,6 @@
 #define ST_LSM6DSX_REG_INT2_ON_INT1_ADDR	0x13
 #define ST_LSM6DSX_REG_INT2_ON_INT1_MASK	BIT(5)
 
-#define ST_LSM6DSX_REG_ACC_OUT_X_L_ADDR		0x28
-#define ST_LSM6DSX_REG_ACC_OUT_Y_L_ADDR		0x2a
-#define ST_LSM6DSX_REG_ACC_OUT_Z_L_ADDR		0x2c
-
-#define ST_LSM6DSX_REG_GYRO_OUT_X_L_ADDR	0x22
-#define ST_LSM6DSX_REG_GYRO_OUT_Y_L_ADDR	0x24
-#define ST_LSM6DSX_REG_GYRO_OUT_Z_L_ADDR	0x26
-
 static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 	{
 		.wai = 0x69,
@@ -701,22 +693,16 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 };
 
 static const struct iio_chan_spec st_lsm6dsx_acc_channels[] = {
-	ST_LSM6DSX_CHANNEL(IIO_ACCEL, ST_LSM6DSX_REG_ACC_OUT_X_L_ADDR,
-			   IIO_MOD_X, 0),
-	ST_LSM6DSX_CHANNEL(IIO_ACCEL, ST_LSM6DSX_REG_ACC_OUT_Y_L_ADDR,
-			   IIO_MOD_Y, 1),
-	ST_LSM6DSX_CHANNEL(IIO_ACCEL, ST_LSM6DSX_REG_ACC_OUT_Z_L_ADDR,
-			   IIO_MOD_Z, 2),
+	ST_LSM6DSX_CHANNEL(IIO_ACCEL, 0x28, IIO_MOD_X, 0),
+	ST_LSM6DSX_CHANNEL(IIO_ACCEL, 0x2a, IIO_MOD_Y, 1),
+	ST_LSM6DSX_CHANNEL(IIO_ACCEL, 0x2c, IIO_MOD_Z, 2),
 	IIO_CHAN_SOFT_TIMESTAMP(3),
 };
 
 static const struct iio_chan_spec st_lsm6dsx_gyro_channels[] = {
-	ST_LSM6DSX_CHANNEL(IIO_ANGL_VEL, ST_LSM6DSX_REG_GYRO_OUT_X_L_ADDR,
-			   IIO_MOD_X, 0),
-	ST_LSM6DSX_CHANNEL(IIO_ANGL_VEL, ST_LSM6DSX_REG_GYRO_OUT_Y_L_ADDR,
-			   IIO_MOD_Y, 1),
-	ST_LSM6DSX_CHANNEL(IIO_ANGL_VEL, ST_LSM6DSX_REG_GYRO_OUT_Z_L_ADDR,
-			   IIO_MOD_Z, 2),
+	ST_LSM6DSX_CHANNEL(IIO_ANGL_VEL, 0x22, IIO_MOD_X, 0),
+	ST_LSM6DSX_CHANNEL(IIO_ANGL_VEL, 0x24, IIO_MOD_Y, 1),
+	ST_LSM6DSX_CHANNEL(IIO_ANGL_VEL, 0x26, IIO_MOD_Z, 2),
 	IIO_CHAN_SOFT_TIMESTAMP(3),
 };
 
-- 
2.21.0


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

* [PATCH v2 4/4] iio: imu: st_lsm6dsx: move iio chan definitions in st_lsm6dsx_sensor_settings
  2019-07-29 19:22 [PATCH v2 0/4] st_lsm6dsx: move {odr,fs}_table in Lorenzo Bianconi
                   ` (2 preceding siblings ...)
  2019-07-29 19:22 ` [PATCH v2 3/4] iio: imu: st_lsm6dsx: inline output acc/gyro output regs Lorenzo Bianconi
@ 2019-07-29 19:22 ` Lorenzo Bianconi
  2019-08-02  5:36   ` Martin Kepplinger
  3 siblings, 1 reply; 11+ messages in thread
From: Lorenzo Bianconi @ 2019-07-29 19:22 UTC (permalink / raw)
  To: jic23; +Cc: lorenzo.bianconi, linux-iio, martin.kepplinger

Move IIO channel definitions in st_lsm6dsx_sensor_settings in order to
support sensors with different channels maps.
This is a preliminary patch to add support for LSM9DS1 sensor to
st_lsm6dsx driver.

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
---
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h      |  5 +
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 96 ++++++++++++++++----
 2 files changed, 81 insertions(+), 20 deletions(-)

diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
index ab1c66615d67..5090f1b3525a 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
@@ -200,6 +200,7 @@ struct st_lsm6dsx_ext_dev_settings {
  * @wai: Sensor WhoAmI default value.
  * @max_fifo_size: Sensor max fifo length in FIFO words.
  * @id: List of hw id/device name supported by the driver configuration.
+ * @channels: IIO channels supported by the device.
  * @odr_table: Hw sensors odr table (Hz + val).
  * @fs_table: Hw sensors gain table (gain + val).
  * @decimator: List of decimator register info (addr + mask).
@@ -215,6 +216,10 @@ struct st_lsm6dsx_settings {
 		enum st_lsm6dsx_hw_id hw_id;
 		const char *name;
 	} id[ST_LSM6DSX_MAX_ID];
+	struct {
+		const struct iio_chan_spec *chan;
+		int len;
+	} channels[2];
 	struct st_lsm6dsx_odr_table_entry odr_table[2];
 	struct st_lsm6dsx_fs_table_entry fs_table[2];
 	struct st_lsm6dsx_reg decimator[ST_LSM6DSX_MAX_ID];
diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
index 0abd5b85b398..fc4d18b58c97 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
@@ -61,6 +61,20 @@
 #define ST_LSM6DSX_REG_INT2_ON_INT1_ADDR	0x13
 #define ST_LSM6DSX_REG_INT2_ON_INT1_MASK	BIT(5)
 
+static const struct iio_chan_spec st_lsm6dsx_acc_channels[] = {
+	ST_LSM6DSX_CHANNEL(IIO_ACCEL, 0x28, IIO_MOD_X, 0),
+	ST_LSM6DSX_CHANNEL(IIO_ACCEL, 0x2a, IIO_MOD_Y, 1),
+	ST_LSM6DSX_CHANNEL(IIO_ACCEL, 0x2c, IIO_MOD_Z, 2),
+	IIO_CHAN_SOFT_TIMESTAMP(3),
+};
+
+static const struct iio_chan_spec st_lsm6dsx_gyro_channels[] = {
+	ST_LSM6DSX_CHANNEL(IIO_ANGL_VEL, 0x22, IIO_MOD_X, 0),
+	ST_LSM6DSX_CHANNEL(IIO_ANGL_VEL, 0x24, IIO_MOD_Y, 1),
+	ST_LSM6DSX_CHANNEL(IIO_ANGL_VEL, 0x26, IIO_MOD_Z, 2),
+	IIO_CHAN_SOFT_TIMESTAMP(3),
+};
+
 static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 	{
 		.wai = 0x69,
@@ -71,6 +85,16 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 				.name = ST_LSM6DS3_DEV_NAME,
 			},
 		},
+		.channels = {
+			[ST_LSM6DSX_ID_ACC] = {
+				.chan = st_lsm6dsx_acc_channels,
+				.len = ARRAY_SIZE(st_lsm6dsx_acc_channels),
+			},
+			[ST_LSM6DSX_ID_GYRO] = {
+				.chan = st_lsm6dsx_gyro_channels,
+				.len = ARRAY_SIZE(st_lsm6dsx_gyro_channels),
+			},
+		},
 		.odr_table = {
 			[ST_LSM6DSX_ID_ACC] = {
 				.reg = {
@@ -169,6 +193,16 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 				.name = ST_LSM6DS3H_DEV_NAME,
 			},
 		},
+		.channels = {
+			[ST_LSM6DSX_ID_ACC] = {
+				.chan = st_lsm6dsx_acc_channels,
+				.len = ARRAY_SIZE(st_lsm6dsx_acc_channels),
+			},
+			[ST_LSM6DSX_ID_GYRO] = {
+				.chan = st_lsm6dsx_gyro_channels,
+				.len = ARRAY_SIZE(st_lsm6dsx_gyro_channels),
+			},
+		},
 		.odr_table = {
 			[ST_LSM6DSX_ID_ACC] = {
 				.reg = {
@@ -276,6 +310,16 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 				.name = ST_LSM6DS3TRC_DEV_NAME,
 			},
 		},
+		.channels = {
+			[ST_LSM6DSX_ID_ACC] = {
+				.chan = st_lsm6dsx_acc_channels,
+				.len = ARRAY_SIZE(st_lsm6dsx_acc_channels),
+			},
+			[ST_LSM6DSX_ID_GYRO] = {
+				.chan = st_lsm6dsx_gyro_channels,
+				.len = ARRAY_SIZE(st_lsm6dsx_gyro_channels),
+			},
+		},
 		.odr_table = {
 			[ST_LSM6DSX_ID_ACC] = {
 				.reg = {
@@ -377,6 +421,16 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 				.name = ST_LSM6DSOX_DEV_NAME,
 			},
 		},
+		.channels = {
+			[ST_LSM6DSX_ID_ACC] = {
+				.chan = st_lsm6dsx_acc_channels,
+				.len = ARRAY_SIZE(st_lsm6dsx_acc_channels),
+			},
+			[ST_LSM6DSX_ID_GYRO] = {
+				.chan = st_lsm6dsx_gyro_channels,
+				.len = ARRAY_SIZE(st_lsm6dsx_gyro_channels),
+			},
+		},
 		.odr_table = {
 			[ST_LSM6DSX_ID_ACC] = {
 				.reg = {
@@ -493,6 +547,16 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 				.name = ST_ASM330LHH_DEV_NAME,
 			},
 		},
+		.channels = {
+			[ST_LSM6DSX_ID_ACC] = {
+				.chan = st_lsm6dsx_acc_channels,
+				.len = ARRAY_SIZE(st_lsm6dsx_acc_channels),
+			},
+			[ST_LSM6DSX_ID_GYRO] = {
+				.chan = st_lsm6dsx_gyro_channels,
+				.len = ARRAY_SIZE(st_lsm6dsx_gyro_channels),
+			},
+		},
 		.odr_table = {
 			[ST_LSM6DSX_ID_ACC] = {
 				.reg = {
@@ -583,6 +647,16 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 				.name = ST_LSM6DSR_DEV_NAME,
 			},
 		},
+		.channels = {
+			[ST_LSM6DSX_ID_ACC] = {
+				.chan = st_lsm6dsx_acc_channels,
+				.len = ARRAY_SIZE(st_lsm6dsx_acc_channels),
+			},
+			[ST_LSM6DSX_ID_GYRO] = {
+				.chan = st_lsm6dsx_gyro_channels,
+				.len = ARRAY_SIZE(st_lsm6dsx_gyro_channels),
+			},
+		},
 		.odr_table = {
 			[ST_LSM6DSX_ID_ACC] = {
 				.reg = {
@@ -692,20 +766,6 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 	},
 };
 
-static const struct iio_chan_spec st_lsm6dsx_acc_channels[] = {
-	ST_LSM6DSX_CHANNEL(IIO_ACCEL, 0x28, IIO_MOD_X, 0),
-	ST_LSM6DSX_CHANNEL(IIO_ACCEL, 0x2a, IIO_MOD_Y, 1),
-	ST_LSM6DSX_CHANNEL(IIO_ACCEL, 0x2c, IIO_MOD_Z, 2),
-	IIO_CHAN_SOFT_TIMESTAMP(3),
-};
-
-static const struct iio_chan_spec st_lsm6dsx_gyro_channels[] = {
-	ST_LSM6DSX_CHANNEL(IIO_ANGL_VEL, 0x22, IIO_MOD_X, 0),
-	ST_LSM6DSX_CHANNEL(IIO_ANGL_VEL, 0x24, IIO_MOD_Y, 1),
-	ST_LSM6DSX_CHANNEL(IIO_ANGL_VEL, 0x26, IIO_MOD_Z, 2),
-	IIO_CHAN_SOFT_TIMESTAMP(3),
-};
-
 int st_lsm6dsx_set_page(struct st_lsm6dsx_hw *hw, bool enable)
 {
 	const struct st_lsm6dsx_shub_settings *hub_settings;
@@ -1263,6 +1323,8 @@ static struct iio_dev *st_lsm6dsx_alloc_iiodev(struct st_lsm6dsx_hw *hw,
 	iio_dev->modes = INDIO_DIRECT_MODE;
 	iio_dev->dev.parent = hw->dev;
 	iio_dev->available_scan_masks = st_lsm6dsx_available_scan_masks;
+	iio_dev->channels = hw->settings->channels[id].chan;
+	iio_dev->num_channels = hw->settings->channels[id].len;
 
 	sensor = iio_priv(iio_dev);
 	sensor->id = id;
@@ -1273,18 +1335,12 @@ static struct iio_dev *st_lsm6dsx_alloc_iiodev(struct st_lsm6dsx_hw *hw,
 
 	switch (id) {
 	case ST_LSM6DSX_ID_ACC:
-		iio_dev->channels = st_lsm6dsx_acc_channels;
-		iio_dev->num_channels = ARRAY_SIZE(st_lsm6dsx_acc_channels);
 		iio_dev->info = &st_lsm6dsx_acc_info;
-
 		scnprintf(sensor->name, sizeof(sensor->name), "%s_accel",
 			  name);
 		break;
 	case ST_LSM6DSX_ID_GYRO:
-		iio_dev->channels = st_lsm6dsx_gyro_channels;
-		iio_dev->num_channels = ARRAY_SIZE(st_lsm6dsx_gyro_channels);
 		iio_dev->info = &st_lsm6dsx_gyro_info;
-
 		scnprintf(sensor->name, sizeof(sensor->name), "%s_gyro",
 			  name);
 		break;
-- 
2.21.0


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

* Re: [PATCH v2 3/4] iio: imu: st_lsm6dsx: inline output acc/gyro output regs
  2019-07-29 19:22 ` [PATCH v2 3/4] iio: imu: st_lsm6dsx: inline output acc/gyro output regs Lorenzo Bianconi
@ 2019-08-02  5:35   ` Martin Kepplinger
  2019-08-05 14:18     ` Jonathan Cameron
  0 siblings, 1 reply; 11+ messages in thread
From: Martin Kepplinger @ 2019-08-02  5:35 UTC (permalink / raw)
  To: Lorenzo Bianconi, jic23; +Cc: lorenzo.bianconi, linux-iio

On 29.07.19 21:22, Lorenzo Bianconi wrote:
> Remove output register definition and inline register value since
> they are used only for iio channel definition. This is a preliminary
> patch to add support for LSM9DS1 sensor to st_lsm6dsx driver
> 
> Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
> ---
>  drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 26 +++++---------------
>  1 file changed, 6 insertions(+), 20 deletions(-)
> 

thanks. I'm running this patchset now and will resend LSM9DS1 patches
after these are merged.

Tested-by: Martin Kepplinger <martin.kepplinger@puri.sm>


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

* Re: [PATCH v2 4/4] iio: imu: st_lsm6dsx: move iio chan definitions in st_lsm6dsx_sensor_settings
  2019-07-29 19:22 ` [PATCH v2 4/4] iio: imu: st_lsm6dsx: move iio chan definitions in st_lsm6dsx_sensor_settings Lorenzo Bianconi
@ 2019-08-02  5:36   ` Martin Kepplinger
  2019-08-05 14:19     ` Jonathan Cameron
  0 siblings, 1 reply; 11+ messages in thread
From: Martin Kepplinger @ 2019-08-02  5:36 UTC (permalink / raw)
  To: Lorenzo Bianconi, jic23; +Cc: lorenzo.bianconi, linux-iio

On 29.07.19 21:22, Lorenzo Bianconi wrote:
> Move IIO channel definitions in st_lsm6dsx_sensor_settings in order to
> support sensors with different channels maps.
> This is a preliminary patch to add support for LSM9DS1 sensor to
> st_lsm6dsx driver.
> 
> Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
> ---
>  drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h      |  5 +
>  drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 96 ++++++++++++++++----
>  2 files changed, 81 insertions(+), 20 deletions(-)


thanks. I'm running this patchset now and will resend LSM9DS1 patches
after these are merged.

Tested-by: Martin Kepplinger <martin.kepplinger@puri.sm>


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

* Re: [PATCH v2 1/4] iio: imu: st_lsm6dsx: move odr_table in st_lsm6dsx_sensor_settings
  2019-07-29 19:22 ` [PATCH v2 1/4] iio: imu: st_lsm6dsx: move odr_table in st_lsm6dsx_sensor_settings Lorenzo Bianconi
@ 2019-08-05 14:17   ` Jonathan Cameron
  0 siblings, 0 replies; 11+ messages in thread
From: Jonathan Cameron @ 2019-08-05 14:17 UTC (permalink / raw)
  To: Lorenzo Bianconi; +Cc: lorenzo.bianconi, linux-iio, martin.kepplinger

On Mon, 29 Jul 2019 21:22:28 +0200
Lorenzo Bianconi <lorenzo@kernel.org> wrote:

> Move sensor odr table in st_lsm6dsx_sensor_settings in order to support
> sensors with different odr maps. This is a preliminary patch to add
> support for LSM9DS1 sensor to st_lsm6dsx driver
> 
> Tested-by: Martin Kepplinger <martin.kepplinger@puri.sm>
> Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>

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/st_lsm6dsx/st_lsm6dsx.h      |   2 +
>  drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 196 ++++++++++++++++---
>  2 files changed, 166 insertions(+), 32 deletions(-)
> 
> diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
> index af379a5429ed..3a89f3f6e2c7 100644
> --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
> +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
> @@ -200,6 +200,7 @@ struct st_lsm6dsx_ext_dev_settings {
>   * @wai: Sensor WhoAmI default value.
>   * @max_fifo_size: Sensor max fifo length in FIFO words.
>   * @id: List of hw id/device name supported by the driver configuration.
> + * @odr_table: Hw sensors odr table (Hz + val).
>   * @decimator: List of decimator register info (addr + mask).
>   * @batch: List of FIFO batching register info (addr + mask).
>   * @fifo_ops: Sensor hw FIFO parameters.
> @@ -213,6 +214,7 @@ struct st_lsm6dsx_settings {
>  		enum st_lsm6dsx_hw_id hw_id;
>  		const char *name;
>  	} id[ST_LSM6DSX_MAX_ID];
> +	struct st_lsm6dsx_odr_table_entry odr_table[2];
>  	struct st_lsm6dsx_reg decimator[ST_LSM6DSX_MAX_ID];
>  	struct st_lsm6dsx_reg batch[ST_LSM6DSX_MAX_ID];
>  	struct st_lsm6dsx_fifo_ops fifo_ops;
> diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> index d8c4417cf4eb..b3c6c9792913 100644
> --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> @@ -69,33 +69,6 @@
>  #define ST_LSM6DSX_REG_GYRO_OUT_Y_L_ADDR	0x24
>  #define ST_LSM6DSX_REG_GYRO_OUT_Z_L_ADDR	0x26
>  
> -static const struct st_lsm6dsx_odr_table_entry st_lsm6dsx_odr_table[] = {
> -	[ST_LSM6DSX_ID_ACC] = {
> -		.reg = {
> -			.addr = 0x10,
> -			.mask = GENMASK(7, 4),
> -		},
> -		.odr_avl[0] = {  13, 0x01 },
> -		.odr_avl[1] = {  26, 0x02 },
> -		.odr_avl[2] = {  52, 0x03 },
> -		.odr_avl[3] = { 104, 0x04 },
> -		.odr_avl[4] = { 208, 0x05 },
> -		.odr_avl[5] = { 416, 0x06 },
> -	},
> -	[ST_LSM6DSX_ID_GYRO] = {
> -		.reg = {
> -			.addr = 0x11,
> -			.mask = GENMASK(7, 4),
> -		},
> -		.odr_avl[0] = {  13, 0x01 },
> -		.odr_avl[1] = {  26, 0x02 },
> -		.odr_avl[2] = {  52, 0x03 },
> -		.odr_avl[3] = { 104, 0x04 },
> -		.odr_avl[4] = { 208, 0x05 },
> -		.odr_avl[5] = { 416, 0x06 },
> -	}
> -};
> -
>  static const struct st_lsm6dsx_fs_table_entry st_lsm6dsx_fs_table[] = {
>  	[ST_LSM6DSX_ID_ACC] = {
>  		.reg = {
> @@ -129,6 +102,32 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>  				.name = ST_LSM6DS3_DEV_NAME,
>  			},
>  		},
> +		.odr_table = {
> +			[ST_LSM6DSX_ID_ACC] = {
> +				.reg = {
> +					.addr = 0x10,
> +					.mask = GENMASK(7, 4),
> +				},
> +				.odr_avl[0] = {  13, 0x01 },
> +				.odr_avl[1] = {  26, 0x02 },
> +				.odr_avl[2] = {  52, 0x03 },
> +				.odr_avl[3] = { 104, 0x04 },
> +				.odr_avl[4] = { 208, 0x05 },
> +				.odr_avl[5] = { 416, 0x06 },
> +			},
> +			[ST_LSM6DSX_ID_GYRO] = {
> +				.reg = {
> +					.addr = 0x11,
> +					.mask = GENMASK(7, 4),
> +				},
> +				.odr_avl[0] = {  13, 0x01 },
> +				.odr_avl[1] = {  26, 0x02 },
> +				.odr_avl[2] = {  52, 0x03 },
> +				.odr_avl[3] = { 104, 0x04 },
> +				.odr_avl[4] = { 208, 0x05 },
> +				.odr_avl[5] = { 416, 0x06 },
> +			},
> +		},
>  		.decimator = {
>  			[ST_LSM6DSX_ID_ACC] = {
>  				.addr = 0x08,
> @@ -179,6 +178,32 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>  				.name = ST_LSM6DS3H_DEV_NAME,
>  			},
>  		},
> +		.odr_table = {
> +			[ST_LSM6DSX_ID_ACC] = {
> +				.reg = {
> +					.addr = 0x10,
> +					.mask = GENMASK(7, 4),
> +				},
> +				.odr_avl[0] = {  13, 0x01 },
> +				.odr_avl[1] = {  26, 0x02 },
> +				.odr_avl[2] = {  52, 0x03 },
> +				.odr_avl[3] = { 104, 0x04 },
> +				.odr_avl[4] = { 208, 0x05 },
> +				.odr_avl[5] = { 416, 0x06 },
> +			},
> +			[ST_LSM6DSX_ID_GYRO] = {
> +				.reg = {
> +					.addr = 0x11,
> +					.mask = GENMASK(7, 4),
> +				},
> +				.odr_avl[0] = {  13, 0x01 },
> +				.odr_avl[1] = {  26, 0x02 },
> +				.odr_avl[2] = {  52, 0x03 },
> +				.odr_avl[3] = { 104, 0x04 },
> +				.odr_avl[4] = { 208, 0x05 },
> +				.odr_avl[5] = { 416, 0x06 },
> +			},
> +		},
>  		.decimator = {
>  			[ST_LSM6DSX_ID_ACC] = {
>  				.addr = 0x08,
> @@ -238,6 +263,32 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>  				.name = ST_LSM6DS3TRC_DEV_NAME,
>  			},
>  		},
> +		.odr_table = {
> +			[ST_LSM6DSX_ID_ACC] = {
> +				.reg = {
> +					.addr = 0x10,
> +					.mask = GENMASK(7, 4),
> +				},
> +				.odr_avl[0] = {  13, 0x01 },
> +				.odr_avl[1] = {  26, 0x02 },
> +				.odr_avl[2] = {  52, 0x03 },
> +				.odr_avl[3] = { 104, 0x04 },
> +				.odr_avl[4] = { 208, 0x05 },
> +				.odr_avl[5] = { 416, 0x06 },
> +			},
> +			[ST_LSM6DSX_ID_GYRO] = {
> +				.reg = {
> +					.addr = 0x11,
> +					.mask = GENMASK(7, 4),
> +				},
> +				.odr_avl[0] = {  13, 0x01 },
> +				.odr_avl[1] = {  26, 0x02 },
> +				.odr_avl[2] = {  52, 0x03 },
> +				.odr_avl[3] = { 104, 0x04 },
> +				.odr_avl[4] = { 208, 0x05 },
> +				.odr_avl[5] = { 416, 0x06 },
> +			},
> +		},
>  		.decimator = {
>  			[ST_LSM6DSX_ID_ACC] = {
>  				.addr = 0x08,
> @@ -291,6 +342,32 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>  				.name = ST_LSM6DSOX_DEV_NAME,
>  			},
>  		},
> +		.odr_table = {
> +			[ST_LSM6DSX_ID_ACC] = {
> +				.reg = {
> +					.addr = 0x10,
> +					.mask = GENMASK(7, 4),
> +				},
> +				.odr_avl[0] = {  13, 0x01 },
> +				.odr_avl[1] = {  26, 0x02 },
> +				.odr_avl[2] = {  52, 0x03 },
> +				.odr_avl[3] = { 104, 0x04 },
> +				.odr_avl[4] = { 208, 0x05 },
> +				.odr_avl[5] = { 416, 0x06 },
> +			},
> +			[ST_LSM6DSX_ID_GYRO] = {
> +				.reg = {
> +					.addr = 0x11,
> +					.mask = GENMASK(7, 4),
> +				},
> +				.odr_avl[0] = {  13, 0x01 },
> +				.odr_avl[1] = {  26, 0x02 },
> +				.odr_avl[2] = {  52, 0x03 },
> +				.odr_avl[3] = { 104, 0x04 },
> +				.odr_avl[4] = { 208, 0x05 },
> +				.odr_avl[5] = { 416, 0x06 },
> +			},
> +		},
>  		.batch = {
>  			[ST_LSM6DSX_ID_ACC] = {
>  				.addr = 0x09,
> @@ -359,6 +436,32 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>  				.name = ST_ASM330LHH_DEV_NAME,
>  			},
>  		},
> +		.odr_table = {
> +			[ST_LSM6DSX_ID_ACC] = {
> +				.reg = {
> +					.addr = 0x10,
> +					.mask = GENMASK(7, 4),
> +				},
> +				.odr_avl[0] = {  13, 0x01 },
> +				.odr_avl[1] = {  26, 0x02 },
> +				.odr_avl[2] = {  52, 0x03 },
> +				.odr_avl[3] = { 104, 0x04 },
> +				.odr_avl[4] = { 208, 0x05 },
> +				.odr_avl[5] = { 416, 0x06 },
> +			},
> +			[ST_LSM6DSX_ID_GYRO] = {
> +				.reg = {
> +					.addr = 0x11,
> +					.mask = GENMASK(7, 4),
> +				},
> +				.odr_avl[0] = {  13, 0x01 },
> +				.odr_avl[1] = {  26, 0x02 },
> +				.odr_avl[2] = {  52, 0x03 },
> +				.odr_avl[3] = { 104, 0x04 },
> +				.odr_avl[4] = { 208, 0x05 },
> +				.odr_avl[5] = { 416, 0x06 },
> +			},
> +		},
>  		.batch = {
>  			[ST_LSM6DSX_ID_ACC] = {
>  				.addr = 0x09,
> @@ -401,6 +504,32 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>  				.name = ST_LSM6DSR_DEV_NAME,
>  			},
>  		},
> +		.odr_table = {
> +			[ST_LSM6DSX_ID_ACC] = {
> +				.reg = {
> +					.addr = 0x10,
> +					.mask = GENMASK(7, 4),
> +				},
> +				.odr_avl[0] = {  13, 0x01 },
> +				.odr_avl[1] = {  26, 0x02 },
> +				.odr_avl[2] = {  52, 0x03 },
> +				.odr_avl[3] = { 104, 0x04 },
> +				.odr_avl[4] = { 208, 0x05 },
> +				.odr_avl[5] = { 416, 0x06 },
> +			},
> +			[ST_LSM6DSX_ID_GYRO] = {
> +				.reg = {
> +					.addr = 0x11,
> +					.mask = GENMASK(7, 4),
> +				},
> +				.odr_avl[0] = {  13, 0x01 },
> +				.odr_avl[1] = {  26, 0x02 },
> +				.odr_avl[2] = {  52, 0x03 },
> +				.odr_avl[3] = { 104, 0x04 },
> +				.odr_avl[4] = { 208, 0x05 },
> +				.odr_avl[5] = { 416, 0x06 },
> +			},
> +		},
>  		.batch = {
>  			[ST_LSM6DSX_ID_ACC] = {
>  				.addr = 0x09,
> @@ -563,20 +692,22 @@ static int st_lsm6dsx_set_full_scale(struct st_lsm6dsx_sensor *sensor,
>  
>  int st_lsm6dsx_check_odr(struct st_lsm6dsx_sensor *sensor, u16 odr, u8 *val)
>  {
> +	const struct st_lsm6dsx_odr_table_entry *odr_table;
>  	int i;
>  
> +	odr_table = &sensor->hw->settings->odr_table[sensor->id];
>  	for (i = 0; i < ST_LSM6DSX_ODR_LIST_SIZE; i++)
>  		/*
>  		 * ext devices can run at different odr respect to
>  		 * accel sensor
>  		 */
> -		if (st_lsm6dsx_odr_table[sensor->id].odr_avl[i].hz >= odr)
> +		if (odr_table->odr_avl[i].hz >= odr)
>  			break;
>  
>  	if (i == ST_LSM6DSX_ODR_LIST_SIZE)
>  		return -EINVAL;
>  
> -	*val = st_lsm6dsx_odr_table[sensor->id].odr_avl[i].val;
> +	*val = odr_table->odr_avl[i].val;
>  
>  	return 0;
>  }
> @@ -641,7 +772,7 @@ static int st_lsm6dsx_set_odr(struct st_lsm6dsx_sensor *sensor, u16 req_odr)
>  			return err;
>  	}
>  
> -	reg = &st_lsm6dsx_odr_table[ref_sensor->id].reg;
> +	reg = &hw->settings->odr_table[ref_sensor->id].reg;
>  	data = ST_LSM6DSX_SHIFT_VAL(val, reg->mask);
>  	return st_lsm6dsx_update_bits_locked(hw, reg->addr, reg->mask, data);
>  }
> @@ -786,11 +917,12 @@ st_lsm6dsx_sysfs_sampling_frequency_avail(struct device *dev,
>  {
>  	struct st_lsm6dsx_sensor *sensor = iio_priv(dev_get_drvdata(dev));
>  	enum st_lsm6dsx_sensor_id id = sensor->id;
> +	struct st_lsm6dsx_hw *hw = sensor->hw;
>  	int i, len = 0;
>  
>  	for (i = 0; i < ST_LSM6DSX_ODR_LIST_SIZE; i++)
>  		len += scnprintf(buf + len, PAGE_SIZE - len, "%d ",
> -				 st_lsm6dsx_odr_table[id].odr_avl[i].hz);
> +				 hw->settings->odr_table[id].odr_avl[i].hz);
>  	buf[len - 1] = '\n';
>  
>  	return len;
> @@ -1040,7 +1172,7 @@ static struct iio_dev *st_lsm6dsx_alloc_iiodev(struct st_lsm6dsx_hw *hw,
>  	sensor = iio_priv(iio_dev);
>  	sensor->id = id;
>  	sensor->hw = hw;
> -	sensor->odr = st_lsm6dsx_odr_table[id].odr_avl[0].hz;
> +	sensor->odr = hw->settings->odr_table[id].odr_avl[0].hz;
>  	sensor->gain = st_lsm6dsx_fs_table[id].fs_avl[0].gain;
>  	sensor->watermark = 1;
>  


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

* Re: [PATCH v2 2/4] iio: imu: st_lsm6dsx: move fs_table in st_lsm6dsx_sensor_settings
  2019-07-29 19:22 ` [PATCH v2 2/4] iio: imu: st_lsm6dsx: move fs_table " Lorenzo Bianconi
@ 2019-08-05 14:18   ` Jonathan Cameron
  0 siblings, 0 replies; 11+ messages in thread
From: Jonathan Cameron @ 2019-08-05 14:18 UTC (permalink / raw)
  To: Lorenzo Bianconi; +Cc: lorenzo.bianconi, linux-iio, martin.kepplinger

On Mon, 29 Jul 2019 21:22:29 +0200
Lorenzo Bianconi <lorenzo@kernel.org> wrote:

> Move fs_table in st_lsm6dsx_sensor_settings in order to support
> sensors with different gain maps. This is a preliminary patch to add
> support for LSM9DS1 sensor to st_lsm6dsx driver
> 
> Tested-by: Martin Kepplinger <martin.kepplinger@puri.sm>
> Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Applied,

Thanks,

Jonathan

> ---
>  drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h      |   2 +
>  drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 175 +++++++++++++++----
>  2 files changed, 144 insertions(+), 33 deletions(-)
> 
> diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
> index 3a89f3f6e2c7..ab1c66615d67 100644
> --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
> +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
> @@ -201,6 +201,7 @@ struct st_lsm6dsx_ext_dev_settings {
>   * @max_fifo_size: Sensor max fifo length in FIFO words.
>   * @id: List of hw id/device name supported by the driver configuration.
>   * @odr_table: Hw sensors odr table (Hz + val).
> + * @fs_table: Hw sensors gain table (gain + val).
>   * @decimator: List of decimator register info (addr + mask).
>   * @batch: List of FIFO batching register info (addr + mask).
>   * @fifo_ops: Sensor hw FIFO parameters.
> @@ -215,6 +216,7 @@ struct st_lsm6dsx_settings {
>  		const char *name;
>  	} id[ST_LSM6DSX_MAX_ID];
>  	struct st_lsm6dsx_odr_table_entry odr_table[2];
> +	struct st_lsm6dsx_fs_table_entry fs_table[2];
>  	struct st_lsm6dsx_reg decimator[ST_LSM6DSX_MAX_ID];
>  	struct st_lsm6dsx_reg batch[ST_LSM6DSX_MAX_ID];
>  	struct st_lsm6dsx_fifo_ops fifo_ops;
> diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> index b3c6c9792913..9aa109428a52 100644
> --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> @@ -69,29 +69,6 @@
>  #define ST_LSM6DSX_REG_GYRO_OUT_Y_L_ADDR	0x24
>  #define ST_LSM6DSX_REG_GYRO_OUT_Z_L_ADDR	0x26
>  
> -static const struct st_lsm6dsx_fs_table_entry st_lsm6dsx_fs_table[] = {
> -	[ST_LSM6DSX_ID_ACC] = {
> -		.reg = {
> -			.addr = 0x10,
> -			.mask = GENMASK(3, 2),
> -		},
> -		.fs_avl[0] = {  IIO_G_TO_M_S_2(61), 0x0 },
> -		.fs_avl[1] = { IIO_G_TO_M_S_2(122), 0x2 },
> -		.fs_avl[2] = { IIO_G_TO_M_S_2(244), 0x3 },
> -		.fs_avl[3] = { IIO_G_TO_M_S_2(488), 0x1 },
> -	},
> -	[ST_LSM6DSX_ID_GYRO] = {
> -		.reg = {
> -			.addr = 0x11,
> -			.mask = GENMASK(3, 2),
> -		},
> -		.fs_avl[0] = {  IIO_DEGREE_TO_RAD(8750), 0x0 },
> -		.fs_avl[1] = { IIO_DEGREE_TO_RAD(17500), 0x1 },
> -		.fs_avl[2] = { IIO_DEGREE_TO_RAD(35000), 0x2 },
> -		.fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 },
> -	}
> -};
> -
>  static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>  	{
>  		.wai = 0x69,
> @@ -128,6 +105,28 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>  				.odr_avl[5] = { 416, 0x06 },
>  			},
>  		},
> +		.fs_table = {
> +			[ST_LSM6DSX_ID_ACC] = {
> +				.reg = {
> +					.addr = 0x10,
> +					.mask = GENMASK(3, 2),
> +				},
> +				.fs_avl[0] = {  IIO_G_TO_M_S_2(61), 0x0 },
> +				.fs_avl[1] = { IIO_G_TO_M_S_2(122), 0x2 },
> +				.fs_avl[2] = { IIO_G_TO_M_S_2(244), 0x3 },
> +				.fs_avl[3] = { IIO_G_TO_M_S_2(488), 0x1 },
> +			},
> +			[ST_LSM6DSX_ID_GYRO] = {
> +				.reg = {
> +					.addr = 0x11,
> +					.mask = GENMASK(3, 2),
> +				},
> +				.fs_avl[0] = {  IIO_DEGREE_TO_RAD(8750), 0x0 },
> +				.fs_avl[1] = { IIO_DEGREE_TO_RAD(17500), 0x1 },
> +				.fs_avl[2] = { IIO_DEGREE_TO_RAD(35000), 0x2 },
> +				.fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 },
> +			},
> +		},
>  		.decimator = {
>  			[ST_LSM6DSX_ID_ACC] = {
>  				.addr = 0x08,
> @@ -204,6 +203,28 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>  				.odr_avl[5] = { 416, 0x06 },
>  			},
>  		},
> +		.fs_table = {
> +			[ST_LSM6DSX_ID_ACC] = {
> +				.reg = {
> +					.addr = 0x10,
> +					.mask = GENMASK(3, 2),
> +				},
> +				.fs_avl[0] = {  IIO_G_TO_M_S_2(61), 0x0 },
> +				.fs_avl[1] = { IIO_G_TO_M_S_2(122), 0x2 },
> +				.fs_avl[2] = { IIO_G_TO_M_S_2(244), 0x3 },
> +				.fs_avl[3] = { IIO_G_TO_M_S_2(488), 0x1 },
> +			},
> +			[ST_LSM6DSX_ID_GYRO] = {
> +				.reg = {
> +					.addr = 0x11,
> +					.mask = GENMASK(3, 2),
> +				},
> +				.fs_avl[0] = {  IIO_DEGREE_TO_RAD(8750), 0x0 },
> +				.fs_avl[1] = { IIO_DEGREE_TO_RAD(17500), 0x1 },
> +				.fs_avl[2] = { IIO_DEGREE_TO_RAD(35000), 0x2 },
> +				.fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 },
> +			},
> +		},
>  		.decimator = {
>  			[ST_LSM6DSX_ID_ACC] = {
>  				.addr = 0x08,
> @@ -289,6 +310,28 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>  				.odr_avl[5] = { 416, 0x06 },
>  			},
>  		},
> +		.fs_table = {
> +			[ST_LSM6DSX_ID_ACC] = {
> +				.reg = {
> +					.addr = 0x10,
> +					.mask = GENMASK(3, 2),
> +				},
> +				.fs_avl[0] = {  IIO_G_TO_M_S_2(61), 0x0 },
> +				.fs_avl[1] = { IIO_G_TO_M_S_2(122), 0x2 },
> +				.fs_avl[2] = { IIO_G_TO_M_S_2(244), 0x3 },
> +				.fs_avl[3] = { IIO_G_TO_M_S_2(488), 0x1 },
> +			},
> +			[ST_LSM6DSX_ID_GYRO] = {
> +				.reg = {
> +					.addr = 0x11,
> +					.mask = GENMASK(3, 2),
> +				},
> +				.fs_avl[0] = {  IIO_DEGREE_TO_RAD(8750), 0x0 },
> +				.fs_avl[1] = { IIO_DEGREE_TO_RAD(17500), 0x1 },
> +				.fs_avl[2] = { IIO_DEGREE_TO_RAD(35000), 0x2 },
> +				.fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 },
> +			},
> +		},
>  		.decimator = {
>  			[ST_LSM6DSX_ID_ACC] = {
>  				.addr = 0x08,
> @@ -368,6 +411,28 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>  				.odr_avl[5] = { 416, 0x06 },
>  			},
>  		},
> +		.fs_table = {
> +			[ST_LSM6DSX_ID_ACC] = {
> +				.reg = {
> +					.addr = 0x10,
> +					.mask = GENMASK(3, 2),
> +				},
> +				.fs_avl[0] = {  IIO_G_TO_M_S_2(61), 0x0 },
> +				.fs_avl[1] = { IIO_G_TO_M_S_2(122), 0x2 },
> +				.fs_avl[2] = { IIO_G_TO_M_S_2(244), 0x3 },
> +				.fs_avl[3] = { IIO_G_TO_M_S_2(488), 0x1 },
> +			},
> +			[ST_LSM6DSX_ID_GYRO] = {
> +				.reg = {
> +					.addr = 0x11,
> +					.mask = GENMASK(3, 2),
> +				},
> +				.fs_avl[0] = {  IIO_DEGREE_TO_RAD(8750), 0x0 },
> +				.fs_avl[1] = { IIO_DEGREE_TO_RAD(17500), 0x1 },
> +				.fs_avl[2] = { IIO_DEGREE_TO_RAD(35000), 0x2 },
> +				.fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 },
> +			},
> +		},
>  		.batch = {
>  			[ST_LSM6DSX_ID_ACC] = {
>  				.addr = 0x09,
> @@ -462,6 +527,28 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>  				.odr_avl[5] = { 416, 0x06 },
>  			},
>  		},
> +		.fs_table = {
> +			[ST_LSM6DSX_ID_ACC] = {
> +				.reg = {
> +					.addr = 0x10,
> +					.mask = GENMASK(3, 2),
> +				},
> +				.fs_avl[0] = {  IIO_G_TO_M_S_2(61), 0x0 },
> +				.fs_avl[1] = { IIO_G_TO_M_S_2(122), 0x2 },
> +				.fs_avl[2] = { IIO_G_TO_M_S_2(244), 0x3 },
> +				.fs_avl[3] = { IIO_G_TO_M_S_2(488), 0x1 },
> +			},
> +			[ST_LSM6DSX_ID_GYRO] = {
> +				.reg = {
> +					.addr = 0x11,
> +					.mask = GENMASK(3, 2),
> +				},
> +				.fs_avl[0] = {  IIO_DEGREE_TO_RAD(8750), 0x0 },
> +				.fs_avl[1] = { IIO_DEGREE_TO_RAD(17500), 0x1 },
> +				.fs_avl[2] = { IIO_DEGREE_TO_RAD(35000), 0x2 },
> +				.fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 },
> +			},
> +		},
>  		.batch = {
>  			[ST_LSM6DSX_ID_ACC] = {
>  				.addr = 0x09,
> @@ -530,6 +617,28 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>  				.odr_avl[5] = { 416, 0x06 },
>  			},
>  		},
> +		.fs_table = {
> +			[ST_LSM6DSX_ID_ACC] = {
> +				.reg = {
> +					.addr = 0x10,
> +					.mask = GENMASK(3, 2),
> +				},
> +				.fs_avl[0] = {  IIO_G_TO_M_S_2(61), 0x0 },
> +				.fs_avl[1] = { IIO_G_TO_M_S_2(122), 0x2 },
> +				.fs_avl[2] = { IIO_G_TO_M_S_2(244), 0x3 },
> +				.fs_avl[3] = { IIO_G_TO_M_S_2(488), 0x1 },
> +			},
> +			[ST_LSM6DSX_ID_GYRO] = {
> +				.reg = {
> +					.addr = 0x11,
> +					.mask = GENMASK(3, 2),
> +				},
> +				.fs_avl[0] = {  IIO_DEGREE_TO_RAD(8750), 0x0 },
> +				.fs_avl[1] = { IIO_DEGREE_TO_RAD(17500), 0x1 },
> +				.fs_avl[2] = { IIO_DEGREE_TO_RAD(35000), 0x2 },
> +				.fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 },
> +			},
> +		},
>  		.batch = {
>  			[ST_LSM6DSX_ID_ACC] = {
>  				.addr = 0x09,
> @@ -665,23 +774,22 @@ static int st_lsm6dsx_check_whoami(struct st_lsm6dsx_hw *hw, int id,
>  static int st_lsm6dsx_set_full_scale(struct st_lsm6dsx_sensor *sensor,
>  				     u32 gain)
>  {
> -	struct st_lsm6dsx_hw *hw = sensor->hw;
> -	const struct st_lsm6dsx_reg *reg;
> +	const struct st_lsm6dsx_fs_table_entry *fs_table;
>  	unsigned int data;
>  	int i, err;
> -	u8 val;
>  
> +	fs_table = &sensor->hw->settings->fs_table[sensor->id];
>  	for (i = 0; i < ST_LSM6DSX_FS_LIST_SIZE; i++)
> -		if (st_lsm6dsx_fs_table[sensor->id].fs_avl[i].gain == gain)
> +		if (fs_table->fs_avl[i].gain == gain)
>  			break;
>  
>  	if (i == ST_LSM6DSX_FS_LIST_SIZE)
>  		return -EINVAL;
>  
> -	val = st_lsm6dsx_fs_table[sensor->id].fs_avl[i].val;
> -	reg = &st_lsm6dsx_fs_table[sensor->id].reg;
> -	data = ST_LSM6DSX_SHIFT_VAL(val, reg->mask);
> -	err = st_lsm6dsx_update_bits_locked(hw, reg->addr, reg->mask, data);
> +	data = ST_LSM6DSX_SHIFT_VAL(fs_table->fs_avl[i].val,
> +				    fs_table->reg.mask);
> +	err = st_lsm6dsx_update_bits_locked(sensor->hw, fs_table->reg.addr,
> +					    fs_table->reg.mask, data);
>  	if (err < 0)
>  		return err;
>  
> @@ -934,11 +1042,12 @@ static ssize_t st_lsm6dsx_sysfs_scale_avail(struct device *dev,
>  {
>  	struct st_lsm6dsx_sensor *sensor = iio_priv(dev_get_drvdata(dev));
>  	enum st_lsm6dsx_sensor_id id = sensor->id;
> +	struct st_lsm6dsx_hw *hw = sensor->hw;
>  	int i, len = 0;
>  
>  	for (i = 0; i < ST_LSM6DSX_FS_LIST_SIZE; i++)
>  		len += scnprintf(buf + len, PAGE_SIZE - len, "0.%06u ",
> -				 st_lsm6dsx_fs_table[id].fs_avl[i].gain);
> +				 hw->settings->fs_table[id].fs_avl[i].gain);
>  	buf[len - 1] = '\n';
>  
>  	return len;
> @@ -1173,7 +1282,7 @@ static struct iio_dev *st_lsm6dsx_alloc_iiodev(struct st_lsm6dsx_hw *hw,
>  	sensor->id = id;
>  	sensor->hw = hw;
>  	sensor->odr = hw->settings->odr_table[id].odr_avl[0].hz;
> -	sensor->gain = st_lsm6dsx_fs_table[id].fs_avl[0].gain;
> +	sensor->gain = hw->settings->fs_table[id].fs_avl[0].gain;
>  	sensor->watermark = 1;
>  
>  	switch (id) {


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

* Re: [PATCH v2 3/4] iio: imu: st_lsm6dsx: inline output acc/gyro output regs
  2019-08-02  5:35   ` Martin Kepplinger
@ 2019-08-05 14:18     ` Jonathan Cameron
  0 siblings, 0 replies; 11+ messages in thread
From: Jonathan Cameron @ 2019-08-05 14:18 UTC (permalink / raw)
  To: Martin Kepplinger; +Cc: Lorenzo Bianconi, lorenzo.bianconi, linux-iio

On Fri, 2 Aug 2019 07:35:46 +0200
Martin Kepplinger <martin.kepplinger@puri.sm> wrote:

> On 29.07.19 21:22, Lorenzo Bianconi wrote:
> > Remove output register definition and inline register value since
> > they are used only for iio channel definition. This is a preliminary
> > patch to add support for LSM9DS1 sensor to st_lsm6dsx driver
> > 
> > Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
> > ---
> >  drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 26 +++++---------------
> >  1 file changed, 6 insertions(+), 20 deletions(-)
> >   
> 
> thanks. I'm running this patchset now and will resend LSM9DS1 patches
> after these are merged.
> 
> Tested-by: Martin Kepplinger <martin.kepplinger@puri.sm>
> 

Nice little tidy up. Applied.

Thanks,

Jonathan

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

* Re: [PATCH v2 4/4] iio: imu: st_lsm6dsx: move iio chan definitions in st_lsm6dsx_sensor_settings
  2019-08-02  5:36   ` Martin Kepplinger
@ 2019-08-05 14:19     ` Jonathan Cameron
  0 siblings, 0 replies; 11+ messages in thread
From: Jonathan Cameron @ 2019-08-05 14:19 UTC (permalink / raw)
  To: Martin Kepplinger; +Cc: Lorenzo Bianconi, lorenzo.bianconi, linux-iio

On Fri, 2 Aug 2019 07:36:03 +0200
Martin Kepplinger <martin.kepplinger@puri.sm> wrote:

> On 29.07.19 21:22, Lorenzo Bianconi wrote:
> > Move IIO channel definitions in st_lsm6dsx_sensor_settings in order to
> > support sensors with different channels maps.
> > This is a preliminary patch to add support for LSM9DS1 sensor to
> > st_lsm6dsx driver.
> > 
> > Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
> > ---
> >  drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h      |  5 +
> >  drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 96 ++++++++++++++++----
> >  2 files changed, 81 insertions(+), 20 deletions(-)  
> 
> 
> thanks. I'm running this patchset now and will resend LSM9DS1 patches
> after these are merged.
> 
> Tested-by: Martin Kepplinger <martin.kepplinger@puri.sm>

Applied and a particular thanks for the tested-by's.

Thanks,

Jonathan

> 


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

end of thread, other threads:[~2019-08-05 14:19 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-29 19:22 [PATCH v2 0/4] st_lsm6dsx: move {odr,fs}_table in Lorenzo Bianconi
2019-07-29 19:22 ` [PATCH v2 1/4] iio: imu: st_lsm6dsx: move odr_table in st_lsm6dsx_sensor_settings Lorenzo Bianconi
2019-08-05 14:17   ` Jonathan Cameron
2019-07-29 19:22 ` [PATCH v2 2/4] iio: imu: st_lsm6dsx: move fs_table " Lorenzo Bianconi
2019-08-05 14:18   ` Jonathan Cameron
2019-07-29 19:22 ` [PATCH v2 3/4] iio: imu: st_lsm6dsx: inline output acc/gyro output regs Lorenzo Bianconi
2019-08-02  5:35   ` Martin Kepplinger
2019-08-05 14:18     ` Jonathan Cameron
2019-07-29 19:22 ` [PATCH v2 4/4] iio: imu: st_lsm6dsx: move iio chan definitions in st_lsm6dsx_sensor_settings Lorenzo Bianconi
2019-08-02  5:36   ` Martin Kepplinger
2019-08-05 14:19     ` Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).