Linux-IIO Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH 0/2] support rational ODRs in st_lsm6dsx
@ 2019-10-27 19:21 Lorenzo Bianconi
  2019-10-27 19:21 ` [PATCH 1/2] iio: imu: st_lsm6dsx: explicitly define odr table size Lorenzo Bianconi
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Lorenzo Bianconi @ 2019-10-27 19:21 UTC (permalink / raw)
  To: jic23; +Cc: lorenzo.bianconi, linux-iio

Express ODRs in HZ / 10 in order to support rational ODRs (e.g. 12.5Hz).
This series will fix an Android CTS failure.
Explicitly define odr table size.
This series is based on 'iio: imu: st_lsm6dsx: fix ODR check in
st_lsm6dsx_write_raw'
https://patchwork.kernel.org/patch/11214281/

Lorenzo Bianconi (2):
  iio: imu: st_lsm6dsx: explicitly define odr table size
  iio: imu: st_lsm6dsx: express odr in HZ / 10

 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h      |   4 +-
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 206 ++++++++++---------
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c |  33 +--
 3 files changed, 133 insertions(+), 110 deletions(-)

-- 
2.21.0


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

* [PATCH 1/2] iio: imu: st_lsm6dsx: explicitly define odr table size
  2019-10-27 19:21 [PATCH 0/2] support rational ODRs in st_lsm6dsx Lorenzo Bianconi
@ 2019-10-27 19:21 ` Lorenzo Bianconi
  2019-10-27 19:21 ` [PATCH 2/2] iio: imu: st_lsm6dsx: express odr in HZ / 10 Lorenzo Bianconi
  2019-10-31 14:43 ` [PATCH 0/2] support rational ODRs in st_lsm6dsx Mario TESI
  2 siblings, 0 replies; 6+ messages in thread
From: Lorenzo Bianconi @ 2019-10-27 19:21 UTC (permalink / raw)
  To: jic23; +Cc: lorenzo.bianconi, linux-iio

Introduce odr_len in st_lsm6dsx_odr_table_entry data structure in order
to explicitly define odr table size and support devices with different
odr table map

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 | 27 +++++++++++++++-----
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c | 12 ++++-----
 3 files changed, 29 insertions(+), 12 deletions(-)

diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
index 37e499fe6bcf..9ffc8e06f73d 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
@@ -113,7 +113,9 @@ struct st_lsm6dsx_odr {
 #define ST_LSM6DSX_ODR_LIST_SIZE	6
 struct st_lsm6dsx_odr_table_entry {
 	struct st_lsm6dsx_reg reg;
+
 	struct st_lsm6dsx_odr odr_avl[ST_LSM6DSX_ODR_LIST_SIZE];
+	int odr_len;
 };
 
 struct st_lsm6dsx_fs {
diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
index c53c03ec2423..2f9396745bc8 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
@@ -133,6 +133,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 				.odr_avl[3] = { 238, 0x04 },
 				.odr_avl[4] = { 476, 0x05 },
 				.odr_avl[5] = { 952, 0x06 },
+				.odr_len = 6,
 			},
 			[ST_LSM6DSX_ID_GYRO] = {
 				.reg = {
@@ -145,6 +146,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 				.odr_avl[3] = { 238, 0x04 },
 				.odr_avl[4] = { 476, 0x05 },
 				.odr_avl[5] = { 952, 0x06 },
+				.odr_len = 6,
 			},
 		},
 		.fs_table = {
@@ -233,6 +235,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 				.odr_avl[3] = { 104, 0x04 },
 				.odr_avl[4] = { 208, 0x05 },
 				.odr_avl[5] = { 416, 0x06 },
+				.odr_len = 6,
 			},
 			[ST_LSM6DSX_ID_GYRO] = {
 				.reg = {
@@ -245,6 +248,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 				.odr_avl[3] = { 104, 0x04 },
 				.odr_avl[4] = { 208, 0x05 },
 				.odr_avl[5] = { 416, 0x06 },
+				.odr_len = 6,
 			},
 		},
 		.fs_table = {
@@ -397,6 +401,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 				.odr_avl[3] = { 104, 0x04 },
 				.odr_avl[4] = { 208, 0x05 },
 				.odr_avl[5] = { 416, 0x06 },
+				.odr_len = 6,
 			},
 			[ST_LSM6DSX_ID_GYRO] = {
 				.reg = {
@@ -409,6 +414,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 				.odr_avl[3] = { 104, 0x04 },
 				.odr_avl[4] = { 208, 0x05 },
 				.odr_avl[5] = { 416, 0x06 },
+				.odr_len = 6,
 			},
 		},
 		.fs_table = {
@@ -570,6 +576,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 				.odr_avl[3] = { 104, 0x04 },
 				.odr_avl[4] = { 208, 0x05 },
 				.odr_avl[5] = { 416, 0x06 },
+				.odr_len = 6,
 			},
 			[ST_LSM6DSX_ID_GYRO] = {
 				.reg = {
@@ -582,6 +589,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 				.odr_avl[3] = { 104, 0x04 },
 				.odr_avl[4] = { 208, 0x05 },
 				.odr_avl[5] = { 416, 0x06 },
+				.odr_len = 6,
 			},
 		},
 		.fs_table = {
@@ -745,6 +753,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 				.odr_avl[3] = { 104, 0x04 },
 				.odr_avl[4] = { 208, 0x05 },
 				.odr_avl[5] = { 416, 0x06 },
+				.odr_len = 6,
 			},
 			[ST_LSM6DSX_ID_GYRO] = {
 				.reg = {
@@ -757,6 +766,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 				.odr_avl[3] = { 104, 0x04 },
 				.odr_avl[4] = { 208, 0x05 },
 				.odr_avl[5] = { 416, 0x06 },
+				.odr_len = 6,
 			},
 		},
 		.fs_table = {
@@ -940,6 +950,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 				.odr_avl[3] = { 104, 0x04 },
 				.odr_avl[4] = { 208, 0x05 },
 				.odr_avl[5] = { 416, 0x06 },
+				.odr_len = 6,
 			},
 			[ST_LSM6DSX_ID_GYRO] = {
 				.reg = {
@@ -952,6 +963,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 				.odr_avl[3] = { 104, 0x04 },
 				.odr_avl[4] = { 208, 0x05 },
 				.odr_avl[5] = { 416, 0x06 },
+				.odr_len = 6,
 			},
 		},
 		.fs_table = {
@@ -1115,6 +1127,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 				.odr_avl[3] = { 104, 0x04 },
 				.odr_avl[4] = { 208, 0x05 },
 				.odr_avl[5] = { 416, 0x06 },
+				.odr_len = 6,
 			},
 			[ST_LSM6DSX_ID_GYRO] = {
 				.reg = {
@@ -1127,6 +1140,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 				.odr_avl[3] = { 104, 0x04 },
 				.odr_avl[4] = { 208, 0x05 },
 				.odr_avl[5] = { 416, 0x06 },
+				.odr_len = 6,
 			},
 		},
 		.fs_table = {
@@ -1350,15 +1364,16 @@ int st_lsm6dsx_check_odr(struct st_lsm6dsx_sensor *sensor, u16 odr, u8 *val)
 	int i;
 
 	odr_table = &sensor->hw->settings->odr_table[sensor->id];
-	for (i = 0; i < ST_LSM6DSX_ODR_LIST_SIZE; i++)
+	for (i = 0; i < odr_table->odr_len; i++) {
 		/*
 		 * ext devices can run at different odr respect to
 		 * accel sensor
 		 */
 		if (odr_table->odr_avl[i].hz >= odr)
 			break;
+	}
 
-	if (i == ST_LSM6DSX_ODR_LIST_SIZE)
+	if (i == odr_table->odr_len)
 		return -EINVAL;
 
 	*val = odr_table->odr_avl[i].val;
@@ -1710,13 +1725,13 @@ st_lsm6dsx_sysfs_sampling_frequency_avail(struct device *dev,
 					  char *buf)
 {
 	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;
+	const struct st_lsm6dsx_odr_table_entry *odr_table;
 	int i, len = 0;
 
-	for (i = 0; i < ST_LSM6DSX_ODR_LIST_SIZE; i++)
+	odr_table = &sensor->hw->settings->odr_table[sensor->id];
+	for (i = 0; i < odr_table->odr_len; i++)
 		len += scnprintf(buf + len, PAGE_SIZE - len, "%d ",
-				 hw->settings->odr_table[id].odr_avl[i].hz);
+				 odr_table->odr_avl[i].hz);
 	buf[len - 1] = '\n';
 
 	return len;
diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c
index ea472cf6db7b..e029cc05a17f 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c
@@ -55,6 +55,7 @@ static const struct st_lsm6dsx_ext_dev_settings st_lsm6dsx_ext_dev_table[] = {
 			.odr_avl[1] = {  20, 0x1 },
 			.odr_avl[2] = {  50, 0x2 },
 			.odr_avl[3] = { 100, 0x3 },
+			.odr_len = 4,
 		},
 		.fs_table = {
 			.fs_avl[0] = {
@@ -323,11 +324,12 @@ st_lsm6dsx_shub_get_odr_val(struct st_lsm6dsx_sensor *sensor,
 	int i;
 
 	settings = sensor->ext_info.settings;
-	for (i = 0; i < ST_LSM6DSX_ODR_LIST_SIZE; i++)
+	for (i = 0; i < settings->odr_table.odr_len; i++) {
 		if (settings->odr_table.odr_avl[i].hz == odr)
 			break;
+	}
 
-	if (i == ST_LSM6DSX_ODR_LIST_SIZE)
+	if (i == settings->odr_table.odr_len)
 		return -EINVAL;
 
 	*val = settings->odr_table.odr_avl[i].val;
@@ -537,12 +539,10 @@ st_lsm6dsx_shub_sampling_freq_avail(struct device *dev,
 	int i, len = 0;
 
 	settings = sensor->ext_info.settings;
-	for (i = 0; i < ST_LSM6DSX_ODR_LIST_SIZE; i++) {
+	for (i = 0; i < settings->odr_table.odr_len; i++) {
 		u16 val = settings->odr_table.odr_avl[i].hz;
 
-		if (val > 0)
-			len += scnprintf(buf + len, PAGE_SIZE - len, "%d ",
-					 val);
+		len += scnprintf(buf + len, PAGE_SIZE - len, "%d ", val);
 	}
 	buf[len - 1] = '\n';
 
-- 
2.21.0


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

* [PATCH 2/2] iio: imu: st_lsm6dsx: express odr in HZ / 10
  2019-10-27 19:21 [PATCH 0/2] support rational ODRs in st_lsm6dsx Lorenzo Bianconi
  2019-10-27 19:21 ` [PATCH 1/2] iio: imu: st_lsm6dsx: explicitly define odr table size Lorenzo Bianconi
@ 2019-10-27 19:21 ` Lorenzo Bianconi
  2019-11-03 10:13   ` Jonathan Cameron
  2019-10-31 14:43 ` [PATCH 0/2] support rational ODRs in st_lsm6dsx Mario TESI
  2 siblings, 1 reply; 6+ messages in thread
From: Lorenzo Bianconi @ 2019-10-27 19:21 UTC (permalink / raw)
  To: jic23; +Cc: lorenzo.bianconi, linux-iio

Express available frequencies in HZ / 10 in order to support even
rational ODRs. This patch is need to fix an Android CTS failure

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 | 181 ++++++++++---------
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c |  23 ++-
 3 files changed, 106 insertions(+), 100 deletions(-)

diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
index 9ffc8e06f73d..b32c6389f47b 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
@@ -106,7 +106,7 @@ struct st_lsm6dsx_sensor;
 struct st_lsm6dsx_hw;
 
 struct st_lsm6dsx_odr {
-	u16 hz;
+	u16 hz; /* expressed in HZ / 10 */
 	u8 val;
 };
 
diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
index 2f9396745bc8..63e113725499 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
@@ -127,12 +127,12 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 					.addr = 0x20,
 					.mask = GENMASK(7, 5),
 				},
-				.odr_avl[0] = {  10, 0x01 },
-				.odr_avl[1] = {  50, 0x02 },
-				.odr_avl[2] = { 119, 0x03 },
-				.odr_avl[3] = { 238, 0x04 },
-				.odr_avl[4] = { 476, 0x05 },
-				.odr_avl[5] = { 952, 0x06 },
+				.odr_avl[0] = {  100, 0x01 },
+				.odr_avl[1] = {  500, 0x02 },
+				.odr_avl[2] = { 1190, 0x03 },
+				.odr_avl[3] = { 2380, 0x04 },
+				.odr_avl[4] = { 4760, 0x05 },
+				.odr_avl[5] = { 9520, 0x06 },
 				.odr_len = 6,
 			},
 			[ST_LSM6DSX_ID_GYRO] = {
@@ -140,12 +140,12 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 					.addr = 0x10,
 					.mask = GENMASK(7, 5),
 				},
-				.odr_avl[0] = {  15, 0x01 },
-				.odr_avl[1] = {  60, 0x02 },
-				.odr_avl[2] = { 119, 0x03 },
-				.odr_avl[3] = { 238, 0x04 },
-				.odr_avl[4] = { 476, 0x05 },
-				.odr_avl[5] = { 952, 0x06 },
+				.odr_avl[0] = {  149, 0x01 },
+				.odr_avl[1] = {  595, 0x02 },
+				.odr_avl[2] = { 1190, 0x03 },
+				.odr_avl[3] = { 2380, 0x04 },
+				.odr_avl[4] = { 4760, 0x05 },
+				.odr_avl[5] = { 9520, 0x06 },
 				.odr_len = 6,
 			},
 		},
@@ -229,12 +229,12 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 					.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 },
+				.odr_avl[0] = {  125, 0x01 },
+				.odr_avl[1] = {  260, 0x02 },
+				.odr_avl[2] = {  520, 0x03 },
+				.odr_avl[3] = { 1040, 0x04 },
+				.odr_avl[4] = { 2080, 0x05 },
+				.odr_avl[5] = { 4160, 0x06 },
 				.odr_len = 6,
 			},
 			[ST_LSM6DSX_ID_GYRO] = {
@@ -242,12 +242,12 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 					.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 },
+				.odr_avl[0] = {  125, 0x01 },
+				.odr_avl[1] = {  260, 0x02 },
+				.odr_avl[2] = {  520, 0x03 },
+				.odr_avl[3] = { 1040, 0x04 },
+				.odr_avl[4] = { 2080, 0x05 },
+				.odr_avl[5] = { 4160, 0x06 },
 				.odr_len = 6,
 			},
 		},
@@ -395,12 +395,12 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 					.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 },
+				.odr_avl[0] = {  125, 0x01 },
+				.odr_avl[1] = {  260, 0x02 },
+				.odr_avl[2] = {  520, 0x03 },
+				.odr_avl[3] = { 1040, 0x04 },
+				.odr_avl[4] = { 2080, 0x05 },
+				.odr_avl[5] = { 4160, 0x06 },
 				.odr_len = 6,
 			},
 			[ST_LSM6DSX_ID_GYRO] = {
@@ -408,12 +408,12 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 					.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 },
+				.odr_avl[0] = {  125, 0x01 },
+				.odr_avl[1] = {  260, 0x02 },
+				.odr_avl[2] = {  520, 0x03 },
+				.odr_avl[3] = { 1040, 0x04 },
+				.odr_avl[4] = { 2080, 0x05 },
+				.odr_avl[5] = { 4160, 0x06 },
 				.odr_len = 6,
 			},
 		},
@@ -570,12 +570,12 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 					.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 },
+				.odr_avl[0] = {  125, 0x01 },
+				.odr_avl[1] = {  260, 0x02 },
+				.odr_avl[2] = {  520, 0x03 },
+				.odr_avl[3] = { 1040, 0x04 },
+				.odr_avl[4] = { 2080, 0x05 },
+				.odr_avl[5] = { 4160, 0x06 },
 				.odr_len = 6,
 			},
 			[ST_LSM6DSX_ID_GYRO] = {
@@ -583,12 +583,12 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 					.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 },
+				.odr_avl[0] = {  125, 0x01 },
+				.odr_avl[1] = {  260, 0x02 },
+				.odr_avl[2] = {  520, 0x03 },
+				.odr_avl[3] = { 1040, 0x04 },
+				.odr_avl[4] = { 2080, 0x05 },
+				.odr_avl[5] = { 4160, 0x06 },
 				.odr_len = 6,
 			},
 		},
@@ -747,12 +747,12 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 					.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 },
+				.odr_avl[0] = {  125, 0x01 },
+				.odr_avl[1] = {  260, 0x02 },
+				.odr_avl[2] = {  520, 0x03 },
+				.odr_avl[3] = { 1040, 0x04 },
+				.odr_avl[4] = { 2080, 0x05 },
+				.odr_avl[5] = { 4160, 0x06 },
 				.odr_len = 6,
 			},
 			[ST_LSM6DSX_ID_GYRO] = {
@@ -760,12 +760,12 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 					.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 },
+				.odr_avl[0] = {  125, 0x01 },
+				.odr_avl[1] = {  260, 0x02 },
+				.odr_avl[2] = {  520, 0x03 },
+				.odr_avl[3] = { 1040, 0x04 },
+				.odr_avl[4] = { 2080, 0x05 },
+				.odr_avl[5] = { 4160, 0x06 },
 				.odr_len = 6,
 			},
 		},
@@ -944,12 +944,12 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 					.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 },
+				.odr_avl[0] = {  125, 0x01 },
+				.odr_avl[1] = {  260, 0x02 },
+				.odr_avl[2] = {  520, 0x03 },
+				.odr_avl[3] = { 1040, 0x04 },
+				.odr_avl[4] = { 2080, 0x05 },
+				.odr_avl[5] = { 4160, 0x06 },
 				.odr_len = 6,
 			},
 			[ST_LSM6DSX_ID_GYRO] = {
@@ -957,12 +957,12 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 					.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 },
+				.odr_avl[0] = {  125, 0x01 },
+				.odr_avl[1] = {  260, 0x02 },
+				.odr_avl[2] = {  520, 0x03 },
+				.odr_avl[3] = { 1040, 0x04 },
+				.odr_avl[4] = { 2080, 0x05 },
+				.odr_avl[5] = { 4160, 0x06 },
 				.odr_len = 6,
 			},
 		},
@@ -1121,12 +1121,12 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 					.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 },
+				.odr_avl[0] = {  125, 0x01 },
+				.odr_avl[1] = {  260, 0x02 },
+				.odr_avl[2] = {  520, 0x03 },
+				.odr_avl[3] = { 1040, 0x04 },
+				.odr_avl[4] = { 2080, 0x05 },
+				.odr_avl[5] = { 4160, 0x06 },
 				.odr_len = 6,
 			},
 			[ST_LSM6DSX_ID_GYRO] = {
@@ -1134,12 +1134,12 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 					.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 },
+				.odr_avl[0] = {  125, 0x01 },
+				.odr_avl[1] = {  260, 0x02 },
+				.odr_avl[2] = {  520, 0x03 },
+				.odr_avl[3] = { 1040, 0x04 },
+				.odr_avl[4] = { 2080, 0x05 },
+				.odr_avl[5] = { 4160, 0x06 },
 				.odr_len = 6,
 			},
 		},
@@ -1475,7 +1475,7 @@ static int st_lsm6dsx_read_oneshot(struct st_lsm6dsx_sensor *sensor,
 	if (err < 0)
 		return err;
 
-	delay = 1000000 / sensor->odr;
+	delay = 10000000 / sensor->odr;
 	usleep_range(delay, 2 * delay);
 
 	err = st_lsm6dsx_read_locked(hw, addr, &data, sizeof(data));
@@ -1507,8 +1507,9 @@ static int st_lsm6dsx_read_raw(struct iio_dev *iio_dev,
 		iio_device_release_direct_mode(iio_dev);
 		break;
 	case IIO_CHAN_INFO_SAMP_FREQ:
-		*val = sensor->odr;
-		ret = IIO_VAL_INT;
+		*val = sensor->odr / 10;
+		*val2 = (sensor->odr % 10) * 100000;
+		ret = IIO_VAL_INT_PLUS_MICRO;
 		break;
 	case IIO_CHAN_INFO_SCALE:
 		*val = 0;
@@ -1541,6 +1542,7 @@ static int st_lsm6dsx_write_raw(struct iio_dev *iio_dev,
 	case IIO_CHAN_INFO_SAMP_FREQ: {
 		u8 data;
 
+		val = val * 10 + val2 / 100000;
 		val = st_lsm6dsx_check_odr(sensor, val, &data);
 		if (val < 0)
 			err = val;
@@ -1730,8 +1732,9 @@ st_lsm6dsx_sysfs_sampling_frequency_avail(struct device *dev,
 
 	odr_table = &sensor->hw->settings->odr_table[sensor->id];
 	for (i = 0; i < odr_table->odr_len; i++)
-		len += scnprintf(buf + len, PAGE_SIZE - len, "%d ",
-				 odr_table->odr_avl[i].hz);
+		len += scnprintf(buf + len, PAGE_SIZE - len, "%d.%d ",
+				 odr_table->odr_avl[i].hz / 10,
+				 odr_table->odr_avl[i].hz % 10);
 	buf[len - 1] = '\n';
 
 	return len;
diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c
index e029cc05a17f..c3b124a73815 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c
@@ -51,10 +51,10 @@ static const struct st_lsm6dsx_ext_dev_settings st_lsm6dsx_ext_dev_table[] = {
 				.addr = 0x60,
 				.mask = GENMASK(3, 2),
 			},
-			.odr_avl[0] = {  10, 0x0 },
-			.odr_avl[1] = {  20, 0x1 },
-			.odr_avl[2] = {  50, 0x2 },
-			.odr_avl[3] = { 100, 0x3 },
+			.odr_avl[0] = {  100, 0x0 },
+			.odr_avl[1] = {  200, 0x1 },
+			.odr_avl[2] = {  500, 0x2 },
+			.odr_avl[3] = { 1000, 0x3 },
 			.odr_len = 4,
 		},
 		.fs_table = {
@@ -97,8 +97,8 @@ static void st_lsm6dsx_shub_wait_complete(struct st_lsm6dsx_hw *hw)
 	u16 odr;
 
 	sensor = iio_priv(hw->iio_devs[ST_LSM6DSX_ID_ACC]);
-	odr = (hw->enable_mask & BIT(ST_LSM6DSX_ID_ACC)) ? sensor->odr : 13;
-	msleep((2000U / odr) + 1);
+	odr = (hw->enable_mask & BIT(ST_LSM6DSX_ID_ACC)) ? sensor->odr : 125;
+	msleep((20000U / odr) + 1);
 }
 
 /**
@@ -442,7 +442,7 @@ st_lsm6dsx_shub_read_oneshot(struct st_lsm6dsx_sensor *sensor,
 	if (err < 0)
 		return err;
 
-	delay = 1000000 / sensor->odr;
+	delay = 10000000 / sensor->odr;
 	usleep_range(delay, 2 * delay);
 
 	len = min_t(int, sizeof(data), ch->scan_type.realbits >> 3);
@@ -482,8 +482,9 @@ st_lsm6dsx_shub_read_raw(struct iio_dev *iio_dev,
 		iio_device_release_direct_mode(iio_dev);
 		break;
 	case IIO_CHAN_INFO_SAMP_FREQ:
-		*val = sensor->odr;
-		ret = IIO_VAL_INT;
+		*val = sensor->odr / 10;
+		*val2 = (sensor->odr % 10) * 100000;
+		ret = IIO_VAL_INT_PLUS_MICRO;
 		break;
 	case IIO_CHAN_INFO_SCALE:
 		*val = 0;
@@ -514,6 +515,7 @@ st_lsm6dsx_shub_write_raw(struct iio_dev *iio_dev,
 	case IIO_CHAN_INFO_SAMP_FREQ: {
 		u16 data;
 
+		val = val * 10 + val2 / 100000;
 		err = st_lsm6dsx_shub_get_odr_val(sensor, val, &data);
 		if (!err)
 			sensor->odr = val;
@@ -542,7 +544,8 @@ st_lsm6dsx_shub_sampling_freq_avail(struct device *dev,
 	for (i = 0; i < settings->odr_table.odr_len; i++) {
 		u16 val = settings->odr_table.odr_avl[i].hz;
 
-		len += scnprintf(buf + len, PAGE_SIZE - len, "%d ", val);
+		len += scnprintf(buf + len, PAGE_SIZE - len, "%d.%d ",
+				 val / 10, val % 10);
 	}
 	buf[len - 1] = '\n';
 
-- 
2.21.0


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

* Re: [PATCH 0/2] support rational ODRs in st_lsm6dsx
  2019-10-27 19:21 [PATCH 0/2] support rational ODRs in st_lsm6dsx Lorenzo Bianconi
  2019-10-27 19:21 ` [PATCH 1/2] iio: imu: st_lsm6dsx: explicitly define odr table size Lorenzo Bianconi
  2019-10-27 19:21 ` [PATCH 2/2] iio: imu: st_lsm6dsx: express odr in HZ / 10 Lorenzo Bianconi
@ 2019-10-31 14:43 ` Mario TESI
  2 siblings, 0 replies; 6+ messages in thread
From: Mario TESI @ 2019-10-31 14:43 UTC (permalink / raw)
  To: Lorenzo Bianconi, jic23; +Cc: lorenzo.bianconi, linux-iio

Tested-by: Mario Tesi <mario.tesi@st.com>


On 10/27/19 8:21 PM, Lorenzo Bianconi wrote:
> Express ODRs in HZ / 10 in order to support rational ODRs (e.g. 12.5Hz).
> This series will fix an Android CTS failure.
> Explicitly define odr table size.
> This series is based on 'iio: imu: st_lsm6dsx: fix ODR check in
> st_lsm6dsx_write_raw'
> https://patchwork.kernel.org/patch/11214281/
>
> Lorenzo Bianconi (2):
>    iio: imu: st_lsm6dsx: explicitly define odr table size
>    iio: imu: st_lsm6dsx: express odr in HZ / 10
>
>   drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h      |   4 +-
>   drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 206 ++++++++++---------
>   drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c |  33 +--
>   3 files changed, 133 insertions(+), 110 deletions(-)
>

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

* Re: [PATCH 2/2] iio: imu: st_lsm6dsx: express odr in HZ / 10
  2019-10-27 19:21 ` [PATCH 2/2] iio: imu: st_lsm6dsx: express odr in HZ / 10 Lorenzo Bianconi
@ 2019-11-03 10:13   ` Jonathan Cameron
  2019-11-03 13:06     ` Lorenzo Bianconi
  0 siblings, 1 reply; 6+ messages in thread
From: Jonathan Cameron @ 2019-11-03 10:13 UTC (permalink / raw)
  To: Lorenzo Bianconi; +Cc: lorenzo.bianconi, linux-iio

On Sun, 27 Oct 2019 20:21:24 +0100
Lorenzo Bianconi <lorenzo@kernel.org> wrote:

> Express available frequencies in HZ / 10 in order to support even
> rational ODRs. This patch is need to fix an Android CTS failure
> 
> 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 | 181 ++++++++++---------
>  drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c |  23 ++-
>  3 files changed, 106 insertions(+), 100 deletions(-)
> 
> diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
> index 9ffc8e06f73d..b32c6389f47b 100644
> --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
> +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
> @@ -106,7 +106,7 @@ struct st_lsm6dsx_sensor;
>  struct st_lsm6dsx_hw;
>  
>  struct st_lsm6dsx_odr {
> -	u16 hz;
> +	u16 hz; /* expressed in HZ / 10 */

That is in the non obvious category.  Maybe best bet
is to switch to millihz and make the type bigger if needed?

Thanks,

Jonathan

>  	u8 val;
>  };
>  
> diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> index 2f9396745bc8..63e113725499 100644
> --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> @@ -127,12 +127,12 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>  					.addr = 0x20,
>  					.mask = GENMASK(7, 5),
>  				},
> -				.odr_avl[0] = {  10, 0x01 },
> -				.odr_avl[1] = {  50, 0x02 },
> -				.odr_avl[2] = { 119, 0x03 },
> -				.odr_avl[3] = { 238, 0x04 },
> -				.odr_avl[4] = { 476, 0x05 },
> -				.odr_avl[5] = { 952, 0x06 },
> +				.odr_avl[0] = {  100, 0x01 },
> +				.odr_avl[1] = {  500, 0x02 },
> +				.odr_avl[2] = { 1190, 0x03 },
> +				.odr_avl[3] = { 2380, 0x04 },
> +				.odr_avl[4] = { 4760, 0x05 },
> +				.odr_avl[5] = { 9520, 0x06 },
>  				.odr_len = 6,
>  			},
>  			[ST_LSM6DSX_ID_GYRO] = {
> @@ -140,12 +140,12 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>  					.addr = 0x10,
>  					.mask = GENMASK(7, 5),
>  				},
> -				.odr_avl[0] = {  15, 0x01 },
> -				.odr_avl[1] = {  60, 0x02 },
> -				.odr_avl[2] = { 119, 0x03 },
> -				.odr_avl[3] = { 238, 0x04 },
> -				.odr_avl[4] = { 476, 0x05 },
> -				.odr_avl[5] = { 952, 0x06 },
> +				.odr_avl[0] = {  149, 0x01 },
> +				.odr_avl[1] = {  595, 0x02 },
> +				.odr_avl[2] = { 1190, 0x03 },
> +				.odr_avl[3] = { 2380, 0x04 },
> +				.odr_avl[4] = { 4760, 0x05 },
> +				.odr_avl[5] = { 9520, 0x06 },
>  				.odr_len = 6,
>  			},
>  		},
> @@ -229,12 +229,12 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>  					.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 },
> +				.odr_avl[0] = {  125, 0x01 },
> +				.odr_avl[1] = {  260, 0x02 },
> +				.odr_avl[2] = {  520, 0x03 },
> +				.odr_avl[3] = { 1040, 0x04 },
> +				.odr_avl[4] = { 2080, 0x05 },
> +				.odr_avl[5] = { 4160, 0x06 },
>  				.odr_len = 6,
>  			},
>  			[ST_LSM6DSX_ID_GYRO] = {
> @@ -242,12 +242,12 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>  					.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 },
> +				.odr_avl[0] = {  125, 0x01 },
> +				.odr_avl[1] = {  260, 0x02 },
> +				.odr_avl[2] = {  520, 0x03 },
> +				.odr_avl[3] = { 1040, 0x04 },
> +				.odr_avl[4] = { 2080, 0x05 },
> +				.odr_avl[5] = { 4160, 0x06 },
>  				.odr_len = 6,
>  			},
>  		},
> @@ -395,12 +395,12 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>  					.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 },
> +				.odr_avl[0] = {  125, 0x01 },
> +				.odr_avl[1] = {  260, 0x02 },
> +				.odr_avl[2] = {  520, 0x03 },
> +				.odr_avl[3] = { 1040, 0x04 },
> +				.odr_avl[4] = { 2080, 0x05 },
> +				.odr_avl[5] = { 4160, 0x06 },
>  				.odr_len = 6,
>  			},
>  			[ST_LSM6DSX_ID_GYRO] = {
> @@ -408,12 +408,12 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>  					.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 },
> +				.odr_avl[0] = {  125, 0x01 },
> +				.odr_avl[1] = {  260, 0x02 },
> +				.odr_avl[2] = {  520, 0x03 },
> +				.odr_avl[3] = { 1040, 0x04 },
> +				.odr_avl[4] = { 2080, 0x05 },
> +				.odr_avl[5] = { 4160, 0x06 },
>  				.odr_len = 6,
>  			},
>  		},
> @@ -570,12 +570,12 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>  					.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 },
> +				.odr_avl[0] = {  125, 0x01 },
> +				.odr_avl[1] = {  260, 0x02 },
> +				.odr_avl[2] = {  520, 0x03 },
> +				.odr_avl[3] = { 1040, 0x04 },
> +				.odr_avl[4] = { 2080, 0x05 },
> +				.odr_avl[5] = { 4160, 0x06 },
>  				.odr_len = 6,
>  			},
>  			[ST_LSM6DSX_ID_GYRO] = {
> @@ -583,12 +583,12 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>  					.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 },
> +				.odr_avl[0] = {  125, 0x01 },
> +				.odr_avl[1] = {  260, 0x02 },
> +				.odr_avl[2] = {  520, 0x03 },
> +				.odr_avl[3] = { 1040, 0x04 },
> +				.odr_avl[4] = { 2080, 0x05 },
> +				.odr_avl[5] = { 4160, 0x06 },
>  				.odr_len = 6,
>  			},
>  		},
> @@ -747,12 +747,12 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>  					.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 },
> +				.odr_avl[0] = {  125, 0x01 },
> +				.odr_avl[1] = {  260, 0x02 },
> +				.odr_avl[2] = {  520, 0x03 },
> +				.odr_avl[3] = { 1040, 0x04 },
> +				.odr_avl[4] = { 2080, 0x05 },
> +				.odr_avl[5] = { 4160, 0x06 },
>  				.odr_len = 6,
>  			},
>  			[ST_LSM6DSX_ID_GYRO] = {
> @@ -760,12 +760,12 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>  					.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 },
> +				.odr_avl[0] = {  125, 0x01 },
> +				.odr_avl[1] = {  260, 0x02 },
> +				.odr_avl[2] = {  520, 0x03 },
> +				.odr_avl[3] = { 1040, 0x04 },
> +				.odr_avl[4] = { 2080, 0x05 },
> +				.odr_avl[5] = { 4160, 0x06 },
>  				.odr_len = 6,
>  			},
>  		},
> @@ -944,12 +944,12 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>  					.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 },
> +				.odr_avl[0] = {  125, 0x01 },
> +				.odr_avl[1] = {  260, 0x02 },
> +				.odr_avl[2] = {  520, 0x03 },
> +				.odr_avl[3] = { 1040, 0x04 },
> +				.odr_avl[4] = { 2080, 0x05 },
> +				.odr_avl[5] = { 4160, 0x06 },
>  				.odr_len = 6,
>  			},
>  			[ST_LSM6DSX_ID_GYRO] = {
> @@ -957,12 +957,12 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>  					.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 },
> +				.odr_avl[0] = {  125, 0x01 },
> +				.odr_avl[1] = {  260, 0x02 },
> +				.odr_avl[2] = {  520, 0x03 },
> +				.odr_avl[3] = { 1040, 0x04 },
> +				.odr_avl[4] = { 2080, 0x05 },
> +				.odr_avl[5] = { 4160, 0x06 },
>  				.odr_len = 6,
>  			},
>  		},
> @@ -1121,12 +1121,12 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>  					.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 },
> +				.odr_avl[0] = {  125, 0x01 },
> +				.odr_avl[1] = {  260, 0x02 },
> +				.odr_avl[2] = {  520, 0x03 },
> +				.odr_avl[3] = { 1040, 0x04 },
> +				.odr_avl[4] = { 2080, 0x05 },
> +				.odr_avl[5] = { 4160, 0x06 },
>  				.odr_len = 6,
>  			},
>  			[ST_LSM6DSX_ID_GYRO] = {
> @@ -1134,12 +1134,12 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>  					.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 },
> +				.odr_avl[0] = {  125, 0x01 },
> +				.odr_avl[1] = {  260, 0x02 },
> +				.odr_avl[2] = {  520, 0x03 },
> +				.odr_avl[3] = { 1040, 0x04 },
> +				.odr_avl[4] = { 2080, 0x05 },
> +				.odr_avl[5] = { 4160, 0x06 },
>  				.odr_len = 6,
>  			},
>  		},
> @@ -1475,7 +1475,7 @@ static int st_lsm6dsx_read_oneshot(struct st_lsm6dsx_sensor *sensor,
>  	if (err < 0)
>  		return err;
>  
> -	delay = 1000000 / sensor->odr;
> +	delay = 10000000 / sensor->odr;
>  	usleep_range(delay, 2 * delay);
>  
>  	err = st_lsm6dsx_read_locked(hw, addr, &data, sizeof(data));
> @@ -1507,8 +1507,9 @@ static int st_lsm6dsx_read_raw(struct iio_dev *iio_dev,
>  		iio_device_release_direct_mode(iio_dev);
>  		break;
>  	case IIO_CHAN_INFO_SAMP_FREQ:
> -		*val = sensor->odr;
> -		ret = IIO_VAL_INT;
> +		*val = sensor->odr / 10;
> +		*val2 = (sensor->odr % 10) * 100000;
> +		ret = IIO_VAL_INT_PLUS_MICRO;
>  		break;
>  	case IIO_CHAN_INFO_SCALE:
>  		*val = 0;
> @@ -1541,6 +1542,7 @@ static int st_lsm6dsx_write_raw(struct iio_dev *iio_dev,
>  	case IIO_CHAN_INFO_SAMP_FREQ: {
>  		u8 data;
>  
> +		val = val * 10 + val2 / 100000;
>  		val = st_lsm6dsx_check_odr(sensor, val, &data);
>  		if (val < 0)
>  			err = val;
> @@ -1730,8 +1732,9 @@ st_lsm6dsx_sysfs_sampling_frequency_avail(struct device *dev,
>  
>  	odr_table = &sensor->hw->settings->odr_table[sensor->id];
>  	for (i = 0; i < odr_table->odr_len; i++)
> -		len += scnprintf(buf + len, PAGE_SIZE - len, "%d ",
> -				 odr_table->odr_avl[i].hz);
> +		len += scnprintf(buf + len, PAGE_SIZE - len, "%d.%d ",
> +				 odr_table->odr_avl[i].hz / 10,
> +				 odr_table->odr_avl[i].hz % 10);
>  	buf[len - 1] = '\n';
>  
>  	return len;
> diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c
> index e029cc05a17f..c3b124a73815 100644
> --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c
> +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c
> @@ -51,10 +51,10 @@ static const struct st_lsm6dsx_ext_dev_settings st_lsm6dsx_ext_dev_table[] = {
>  				.addr = 0x60,
>  				.mask = GENMASK(3, 2),
>  			},
> -			.odr_avl[0] = {  10, 0x0 },
> -			.odr_avl[1] = {  20, 0x1 },
> -			.odr_avl[2] = {  50, 0x2 },
> -			.odr_avl[3] = { 100, 0x3 },
> +			.odr_avl[0] = {  100, 0x0 },
> +			.odr_avl[1] = {  200, 0x1 },
> +			.odr_avl[2] = {  500, 0x2 },
> +			.odr_avl[3] = { 1000, 0x3 },
>  			.odr_len = 4,
>  		},
>  		.fs_table = {
> @@ -97,8 +97,8 @@ static void st_lsm6dsx_shub_wait_complete(struct st_lsm6dsx_hw *hw)
>  	u16 odr;
>  
>  	sensor = iio_priv(hw->iio_devs[ST_LSM6DSX_ID_ACC]);
> -	odr = (hw->enable_mask & BIT(ST_LSM6DSX_ID_ACC)) ? sensor->odr : 13;
> -	msleep((2000U / odr) + 1);
> +	odr = (hw->enable_mask & BIT(ST_LSM6DSX_ID_ACC)) ? sensor->odr : 125;
> +	msleep((20000U / odr) + 1);
>  }
>  
>  /**
> @@ -442,7 +442,7 @@ st_lsm6dsx_shub_read_oneshot(struct st_lsm6dsx_sensor *sensor,
>  	if (err < 0)
>  		return err;
>  
> -	delay = 1000000 / sensor->odr;
> +	delay = 10000000 / sensor->odr;
>  	usleep_range(delay, 2 * delay);
>  
>  	len = min_t(int, sizeof(data), ch->scan_type.realbits >> 3);
> @@ -482,8 +482,9 @@ st_lsm6dsx_shub_read_raw(struct iio_dev *iio_dev,
>  		iio_device_release_direct_mode(iio_dev);
>  		break;
>  	case IIO_CHAN_INFO_SAMP_FREQ:
> -		*val = sensor->odr;
> -		ret = IIO_VAL_INT;
> +		*val = sensor->odr / 10;
> +		*val2 = (sensor->odr % 10) * 100000;
> +		ret = IIO_VAL_INT_PLUS_MICRO;
>  		break;
>  	case IIO_CHAN_INFO_SCALE:
>  		*val = 0;
> @@ -514,6 +515,7 @@ st_lsm6dsx_shub_write_raw(struct iio_dev *iio_dev,
>  	case IIO_CHAN_INFO_SAMP_FREQ: {
>  		u16 data;
>  
> +		val = val * 10 + val2 / 100000;
>  		err = st_lsm6dsx_shub_get_odr_val(sensor, val, &data);
>  		if (!err)
>  			sensor->odr = val;
> @@ -542,7 +544,8 @@ st_lsm6dsx_shub_sampling_freq_avail(struct device *dev,
>  	for (i = 0; i < settings->odr_table.odr_len; i++) {
>  		u16 val = settings->odr_table.odr_avl[i].hz;
>  
> -		len += scnprintf(buf + len, PAGE_SIZE - len, "%d ", val);
> +		len += scnprintf(buf + len, PAGE_SIZE - len, "%d.%d ",
> +				 val / 10, val % 10);
>  	}
>  	buf[len - 1] = '\n';
>  


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

* Re: [PATCH 2/2] iio: imu: st_lsm6dsx: express odr in HZ / 10
  2019-11-03 10:13   ` Jonathan Cameron
@ 2019-11-03 13:06     ` Lorenzo Bianconi
  0 siblings, 0 replies; 6+ messages in thread
From: Lorenzo Bianconi @ 2019-11-03 13:06 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: Lorenzo Bianconi, linux-iio

[-- Attachment #1: Type: text/plain, Size: 15611 bytes --]

On Nov 03, Jonathan Cameron wrote:
> On Sun, 27 Oct 2019 20:21:24 +0100
> Lorenzo Bianconi <lorenzo@kernel.org> wrote:
> 
> > Express available frequencies in HZ / 10 in order to support even
> > rational ODRs. This patch is need to fix an Android CTS failure
> > 
> > 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 | 181 ++++++++++---------
> >  drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c |  23 ++-
> >  3 files changed, 106 insertions(+), 100 deletions(-)
> > 
> > diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
> > index 9ffc8e06f73d..b32c6389f47b 100644
> > --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
> > +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
> > @@ -106,7 +106,7 @@ struct st_lsm6dsx_sensor;
> >  struct st_lsm6dsx_hw;
> >  
> >  struct st_lsm6dsx_odr {
> > -	u16 hz;
> > +	u16 hz; /* expressed in HZ / 10 */
> 
> That is in the non obvious category.  Maybe best bet
> is to switch to millihz and make the type bigger if needed?

Hi Jonathan,

ack, I will post a v2.

Regards,
Lorenzo

> 
> Thanks,
> 
> Jonathan
> 
> >  	u8 val;
> >  };
> >  
> > diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> > index 2f9396745bc8..63e113725499 100644
> > --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> > +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> > @@ -127,12 +127,12 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
> >  					.addr = 0x20,
> >  					.mask = GENMASK(7, 5),
> >  				},
> > -				.odr_avl[0] = {  10, 0x01 },
> > -				.odr_avl[1] = {  50, 0x02 },
> > -				.odr_avl[2] = { 119, 0x03 },
> > -				.odr_avl[3] = { 238, 0x04 },
> > -				.odr_avl[4] = { 476, 0x05 },
> > -				.odr_avl[5] = { 952, 0x06 },
> > +				.odr_avl[0] = {  100, 0x01 },
> > +				.odr_avl[1] = {  500, 0x02 },
> > +				.odr_avl[2] = { 1190, 0x03 },
> > +				.odr_avl[3] = { 2380, 0x04 },
> > +				.odr_avl[4] = { 4760, 0x05 },
> > +				.odr_avl[5] = { 9520, 0x06 },
> >  				.odr_len = 6,
> >  			},
> >  			[ST_LSM6DSX_ID_GYRO] = {
> > @@ -140,12 +140,12 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
> >  					.addr = 0x10,
> >  					.mask = GENMASK(7, 5),
> >  				},
> > -				.odr_avl[0] = {  15, 0x01 },
> > -				.odr_avl[1] = {  60, 0x02 },
> > -				.odr_avl[2] = { 119, 0x03 },
> > -				.odr_avl[3] = { 238, 0x04 },
> > -				.odr_avl[4] = { 476, 0x05 },
> > -				.odr_avl[5] = { 952, 0x06 },
> > +				.odr_avl[0] = {  149, 0x01 },
> > +				.odr_avl[1] = {  595, 0x02 },
> > +				.odr_avl[2] = { 1190, 0x03 },
> > +				.odr_avl[3] = { 2380, 0x04 },
> > +				.odr_avl[4] = { 4760, 0x05 },
> > +				.odr_avl[5] = { 9520, 0x06 },
> >  				.odr_len = 6,
> >  			},
> >  		},
> > @@ -229,12 +229,12 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
> >  					.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 },
> > +				.odr_avl[0] = {  125, 0x01 },
> > +				.odr_avl[1] = {  260, 0x02 },
> > +				.odr_avl[2] = {  520, 0x03 },
> > +				.odr_avl[3] = { 1040, 0x04 },
> > +				.odr_avl[4] = { 2080, 0x05 },
> > +				.odr_avl[5] = { 4160, 0x06 },
> >  				.odr_len = 6,
> >  			},
> >  			[ST_LSM6DSX_ID_GYRO] = {
> > @@ -242,12 +242,12 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
> >  					.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 },
> > +				.odr_avl[0] = {  125, 0x01 },
> > +				.odr_avl[1] = {  260, 0x02 },
> > +				.odr_avl[2] = {  520, 0x03 },
> > +				.odr_avl[3] = { 1040, 0x04 },
> > +				.odr_avl[4] = { 2080, 0x05 },
> > +				.odr_avl[5] = { 4160, 0x06 },
> >  				.odr_len = 6,
> >  			},
> >  		},
> > @@ -395,12 +395,12 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
> >  					.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 },
> > +				.odr_avl[0] = {  125, 0x01 },
> > +				.odr_avl[1] = {  260, 0x02 },
> > +				.odr_avl[2] = {  520, 0x03 },
> > +				.odr_avl[3] = { 1040, 0x04 },
> > +				.odr_avl[4] = { 2080, 0x05 },
> > +				.odr_avl[5] = { 4160, 0x06 },
> >  				.odr_len = 6,
> >  			},
> >  			[ST_LSM6DSX_ID_GYRO] = {
> > @@ -408,12 +408,12 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
> >  					.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 },
> > +				.odr_avl[0] = {  125, 0x01 },
> > +				.odr_avl[1] = {  260, 0x02 },
> > +				.odr_avl[2] = {  520, 0x03 },
> > +				.odr_avl[3] = { 1040, 0x04 },
> > +				.odr_avl[4] = { 2080, 0x05 },
> > +				.odr_avl[5] = { 4160, 0x06 },
> >  				.odr_len = 6,
> >  			},
> >  		},
> > @@ -570,12 +570,12 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
> >  					.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 },
> > +				.odr_avl[0] = {  125, 0x01 },
> > +				.odr_avl[1] = {  260, 0x02 },
> > +				.odr_avl[2] = {  520, 0x03 },
> > +				.odr_avl[3] = { 1040, 0x04 },
> > +				.odr_avl[4] = { 2080, 0x05 },
> > +				.odr_avl[5] = { 4160, 0x06 },
> >  				.odr_len = 6,
> >  			},
> >  			[ST_LSM6DSX_ID_GYRO] = {
> > @@ -583,12 +583,12 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
> >  					.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 },
> > +				.odr_avl[0] = {  125, 0x01 },
> > +				.odr_avl[1] = {  260, 0x02 },
> > +				.odr_avl[2] = {  520, 0x03 },
> > +				.odr_avl[3] = { 1040, 0x04 },
> > +				.odr_avl[4] = { 2080, 0x05 },
> > +				.odr_avl[5] = { 4160, 0x06 },
> >  				.odr_len = 6,
> >  			},
> >  		},
> > @@ -747,12 +747,12 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
> >  					.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 },
> > +				.odr_avl[0] = {  125, 0x01 },
> > +				.odr_avl[1] = {  260, 0x02 },
> > +				.odr_avl[2] = {  520, 0x03 },
> > +				.odr_avl[3] = { 1040, 0x04 },
> > +				.odr_avl[4] = { 2080, 0x05 },
> > +				.odr_avl[5] = { 4160, 0x06 },
> >  				.odr_len = 6,
> >  			},
> >  			[ST_LSM6DSX_ID_GYRO] = {
> > @@ -760,12 +760,12 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
> >  					.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 },
> > +				.odr_avl[0] = {  125, 0x01 },
> > +				.odr_avl[1] = {  260, 0x02 },
> > +				.odr_avl[2] = {  520, 0x03 },
> > +				.odr_avl[3] = { 1040, 0x04 },
> > +				.odr_avl[4] = { 2080, 0x05 },
> > +				.odr_avl[5] = { 4160, 0x06 },
> >  				.odr_len = 6,
> >  			},
> >  		},
> > @@ -944,12 +944,12 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
> >  					.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 },
> > +				.odr_avl[0] = {  125, 0x01 },
> > +				.odr_avl[1] = {  260, 0x02 },
> > +				.odr_avl[2] = {  520, 0x03 },
> > +				.odr_avl[3] = { 1040, 0x04 },
> > +				.odr_avl[4] = { 2080, 0x05 },
> > +				.odr_avl[5] = { 4160, 0x06 },
> >  				.odr_len = 6,
> >  			},
> >  			[ST_LSM6DSX_ID_GYRO] = {
> > @@ -957,12 +957,12 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
> >  					.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 },
> > +				.odr_avl[0] = {  125, 0x01 },
> > +				.odr_avl[1] = {  260, 0x02 },
> > +				.odr_avl[2] = {  520, 0x03 },
> > +				.odr_avl[3] = { 1040, 0x04 },
> > +				.odr_avl[4] = { 2080, 0x05 },
> > +				.odr_avl[5] = { 4160, 0x06 },
> >  				.odr_len = 6,
> >  			},
> >  		},
> > @@ -1121,12 +1121,12 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
> >  					.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 },
> > +				.odr_avl[0] = {  125, 0x01 },
> > +				.odr_avl[1] = {  260, 0x02 },
> > +				.odr_avl[2] = {  520, 0x03 },
> > +				.odr_avl[3] = { 1040, 0x04 },
> > +				.odr_avl[4] = { 2080, 0x05 },
> > +				.odr_avl[5] = { 4160, 0x06 },
> >  				.odr_len = 6,
> >  			},
> >  			[ST_LSM6DSX_ID_GYRO] = {
> > @@ -1134,12 +1134,12 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
> >  					.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 },
> > +				.odr_avl[0] = {  125, 0x01 },
> > +				.odr_avl[1] = {  260, 0x02 },
> > +				.odr_avl[2] = {  520, 0x03 },
> > +				.odr_avl[3] = { 1040, 0x04 },
> > +				.odr_avl[4] = { 2080, 0x05 },
> > +				.odr_avl[5] = { 4160, 0x06 },
> >  				.odr_len = 6,
> >  			},
> >  		},
> > @@ -1475,7 +1475,7 @@ static int st_lsm6dsx_read_oneshot(struct st_lsm6dsx_sensor *sensor,
> >  	if (err < 0)
> >  		return err;
> >  
> > -	delay = 1000000 / sensor->odr;
> > +	delay = 10000000 / sensor->odr;
> >  	usleep_range(delay, 2 * delay);
> >  
> >  	err = st_lsm6dsx_read_locked(hw, addr, &data, sizeof(data));
> > @@ -1507,8 +1507,9 @@ static int st_lsm6dsx_read_raw(struct iio_dev *iio_dev,
> >  		iio_device_release_direct_mode(iio_dev);
> >  		break;
> >  	case IIO_CHAN_INFO_SAMP_FREQ:
> > -		*val = sensor->odr;
> > -		ret = IIO_VAL_INT;
> > +		*val = sensor->odr / 10;
> > +		*val2 = (sensor->odr % 10) * 100000;
> > +		ret = IIO_VAL_INT_PLUS_MICRO;
> >  		break;
> >  	case IIO_CHAN_INFO_SCALE:
> >  		*val = 0;
> > @@ -1541,6 +1542,7 @@ static int st_lsm6dsx_write_raw(struct iio_dev *iio_dev,
> >  	case IIO_CHAN_INFO_SAMP_FREQ: {
> >  		u8 data;
> >  
> > +		val = val * 10 + val2 / 100000;
> >  		val = st_lsm6dsx_check_odr(sensor, val, &data);
> >  		if (val < 0)
> >  			err = val;
> > @@ -1730,8 +1732,9 @@ st_lsm6dsx_sysfs_sampling_frequency_avail(struct device *dev,
> >  
> >  	odr_table = &sensor->hw->settings->odr_table[sensor->id];
> >  	for (i = 0; i < odr_table->odr_len; i++)
> > -		len += scnprintf(buf + len, PAGE_SIZE - len, "%d ",
> > -				 odr_table->odr_avl[i].hz);
> > +		len += scnprintf(buf + len, PAGE_SIZE - len, "%d.%d ",
> > +				 odr_table->odr_avl[i].hz / 10,
> > +				 odr_table->odr_avl[i].hz % 10);
> >  	buf[len - 1] = '\n';
> >  
> >  	return len;
> > diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c
> > index e029cc05a17f..c3b124a73815 100644
> > --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c
> > +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c
> > @@ -51,10 +51,10 @@ static const struct st_lsm6dsx_ext_dev_settings st_lsm6dsx_ext_dev_table[] = {
> >  				.addr = 0x60,
> >  				.mask = GENMASK(3, 2),
> >  			},
> > -			.odr_avl[0] = {  10, 0x0 },
> > -			.odr_avl[1] = {  20, 0x1 },
> > -			.odr_avl[2] = {  50, 0x2 },
> > -			.odr_avl[3] = { 100, 0x3 },
> > +			.odr_avl[0] = {  100, 0x0 },
> > +			.odr_avl[1] = {  200, 0x1 },
> > +			.odr_avl[2] = {  500, 0x2 },
> > +			.odr_avl[3] = { 1000, 0x3 },
> >  			.odr_len = 4,
> >  		},
> >  		.fs_table = {
> > @@ -97,8 +97,8 @@ static void st_lsm6dsx_shub_wait_complete(struct st_lsm6dsx_hw *hw)
> >  	u16 odr;
> >  
> >  	sensor = iio_priv(hw->iio_devs[ST_LSM6DSX_ID_ACC]);
> > -	odr = (hw->enable_mask & BIT(ST_LSM6DSX_ID_ACC)) ? sensor->odr : 13;
> > -	msleep((2000U / odr) + 1);
> > +	odr = (hw->enable_mask & BIT(ST_LSM6DSX_ID_ACC)) ? sensor->odr : 125;
> > +	msleep((20000U / odr) + 1);
> >  }
> >  
> >  /**
> > @@ -442,7 +442,7 @@ st_lsm6dsx_shub_read_oneshot(struct st_lsm6dsx_sensor *sensor,
> >  	if (err < 0)
> >  		return err;
> >  
> > -	delay = 1000000 / sensor->odr;
> > +	delay = 10000000 / sensor->odr;
> >  	usleep_range(delay, 2 * delay);
> >  
> >  	len = min_t(int, sizeof(data), ch->scan_type.realbits >> 3);
> > @@ -482,8 +482,9 @@ st_lsm6dsx_shub_read_raw(struct iio_dev *iio_dev,
> >  		iio_device_release_direct_mode(iio_dev);
> >  		break;
> >  	case IIO_CHAN_INFO_SAMP_FREQ:
> > -		*val = sensor->odr;
> > -		ret = IIO_VAL_INT;
> > +		*val = sensor->odr / 10;
> > +		*val2 = (sensor->odr % 10) * 100000;
> > +		ret = IIO_VAL_INT_PLUS_MICRO;
> >  		break;
> >  	case IIO_CHAN_INFO_SCALE:
> >  		*val = 0;
> > @@ -514,6 +515,7 @@ st_lsm6dsx_shub_write_raw(struct iio_dev *iio_dev,
> >  	case IIO_CHAN_INFO_SAMP_FREQ: {
> >  		u16 data;
> >  
> > +		val = val * 10 + val2 / 100000;
> >  		err = st_lsm6dsx_shub_get_odr_val(sensor, val, &data);
> >  		if (!err)
> >  			sensor->odr = val;
> > @@ -542,7 +544,8 @@ st_lsm6dsx_shub_sampling_freq_avail(struct device *dev,
> >  	for (i = 0; i < settings->odr_table.odr_len; i++) {
> >  		u16 val = settings->odr_table.odr_avl[i].hz;
> >  
> > -		len += scnprintf(buf + len, PAGE_SIZE - len, "%d ", val);
> > +		len += scnprintf(buf + len, PAGE_SIZE - len, "%d.%d ",
> > +				 val / 10, val % 10);
> >  	}
> >  	buf[len - 1] = '\n';
> >  
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

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

end of thread, back to index

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-27 19:21 [PATCH 0/2] support rational ODRs in st_lsm6dsx Lorenzo Bianconi
2019-10-27 19:21 ` [PATCH 1/2] iio: imu: st_lsm6dsx: explicitly define odr table size Lorenzo Bianconi
2019-10-27 19:21 ` [PATCH 2/2] iio: imu: st_lsm6dsx: express odr in HZ / 10 Lorenzo Bianconi
2019-11-03 10:13   ` Jonathan Cameron
2019-11-03 13:06     ` Lorenzo Bianconi
2019-10-31 14:43 ` [PATCH 0/2] support rational ODRs in st_lsm6dsx Mario TESI

Linux-IIO Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-iio/0 linux-iio/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-iio linux-iio/ https://lore.kernel.org/linux-iio \
		linux-iio@vger.kernel.org
	public-inbox-index linux-iio

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-iio


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git