* [PATCH 0/4] rework st_lsm6dsx driver to support more devices
@ 2017-09-27 19:29 Lorenzo Bianconi
2017-09-27 19:29 ` [PATCH 1/4] iio: imu: st_lsm6dsx: convert max_fifo_size in fifo words Lorenzo Bianconi
` (3 more replies)
0 siblings, 4 replies; 12+ messages in thread
From: Lorenzo Bianconi @ 2017-09-27 19:29 UTC (permalink / raw)
To: jic23; +Cc: linux-iio, lorenzo.bianconi
This is the first patchset that reworks st_lsm6dsx driver to properly
support more devices
Lorenzo Bianconi (4):
iio: imu: st_lsm6dsx: convert max_fifo_size in fifo words
iio: imu: st_lsm6dsx: split fifo mode and fifo odr configuration
iio: imu: st_lsm6dsx: move decimator info in
st_lsm6dsx_sensor_settings
iio: imu: st_lsm6dsx: add FIFO ops data structure
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h | 33 +++++++++--
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c | 72 ++++++++++++------------
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 78 ++++++++++++++++++++++----
3 files changed, 133 insertions(+), 50 deletions(-)
--
2.14.1
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 1/4] iio: imu: st_lsm6dsx: convert max_fifo_size in fifo words
2017-09-27 19:29 [PATCH 0/4] rework st_lsm6dsx driver to support more devices Lorenzo Bianconi
@ 2017-09-27 19:29 ` Lorenzo Bianconi
2017-10-01 10:40 ` Jonathan Cameron
2017-09-27 19:29 ` [PATCH 2/4] iio: imu: st_lsm6dsx: split fifo mode and fifo odr configuration Lorenzo Bianconi
` (2 subsequent siblings)
3 siblings, 1 reply; 12+ messages in thread
From: Lorenzo Bianconi @ 2017-09-27 19:29 UTC (permalink / raw)
To: jic23; +Cc: linux-iio, lorenzo.bianconi
Express max fifo depth in fifo words instead of in bytes.
That change will be necessary to properly support more devices
in st_lsm6dsx driver
Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@st.com>
---
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
index debf4064f474..e6e0363cd1c2 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
@@ -156,21 +156,21 @@ static const struct st_lsm6dsx_fs_table_entry st_lsm6dsx_fs_table[] = {
static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
{
.wai = 0x69,
- .max_fifo_size = 8192,
+ .max_fifo_size = 1365,
.id = {
[0] = ST_LSM6DS3_ID,
},
},
{
.wai = 0x69,
- .max_fifo_size = 4096,
+ .max_fifo_size = 682,
.id = {
[0] = ST_LSM6DS3H_ID,
},
},
{
.wai = 0x6a,
- .max_fifo_size = 4096,
+ .max_fifo_size = 682,
.id = {
[0] = ST_LSM6DSL_ID,
[1] = ST_LSM6DSM_ID,
@@ -462,10 +462,9 @@ static int st_lsm6dsx_set_watermark(struct iio_dev *iio_dev, unsigned int val)
{
struct st_lsm6dsx_sensor *sensor = iio_priv(iio_dev);
struct st_lsm6dsx_hw *hw = sensor->hw;
- int err, max_fifo_len;
+ int err;
- max_fifo_len = hw->settings->max_fifo_size / ST_LSM6DSX_SAMPLE_SIZE;
- if (val < 1 || val > max_fifo_len)
+ if (val < 1 || val > hw->settings->max_fifo_size)
return -EINVAL;
err = st_lsm6dsx_update_watermark(sensor, val);
--
2.14.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 2/4] iio: imu: st_lsm6dsx: split fifo mode and fifo odr configuration
2017-09-27 19:29 [PATCH 0/4] rework st_lsm6dsx driver to support more devices Lorenzo Bianconi
2017-09-27 19:29 ` [PATCH 1/4] iio: imu: st_lsm6dsx: convert max_fifo_size in fifo words Lorenzo Bianconi
@ 2017-09-27 19:29 ` Lorenzo Bianconi
2017-10-01 10:42 ` Jonathan Cameron
2017-09-27 19:29 ` [PATCH 3/4] iio: imu: st_lsm6dsx: move decimator info in st_lsm6dsx_sensor_settings Lorenzo Bianconi
2017-09-27 19:29 ` [PATCH 4/4] iio: imu: st_lsm6dsx: add FIFO ops data structure Lorenzo Bianconi
3 siblings, 1 reply; 12+ messages in thread
From: Lorenzo Bianconi @ 2017-09-27 19:29 UTC (permalink / raw)
To: jic23; +Cc: linux-iio, lorenzo.bianconi
Separate fifo mode and max fifo sample rate configuration.
That change will be necessary to reuse st_lsm6dsx_set_fifo_mode()
routine and to support more devices in st_lsm6dsx driver
Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@st.com>
---
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c | 32 ++++++++++++++------------
1 file changed, 17 insertions(+), 15 deletions(-)
diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c
index e2737dc71b67..26fb970aed15 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c
@@ -139,23 +139,10 @@ static int st_lsm6dsx_update_decimators(struct st_lsm6dsx_hw *hw)
int st_lsm6dsx_set_fifo_mode(struct st_lsm6dsx_hw *hw,
enum st_lsm6dsx_fifo_mode fifo_mode)
{
- u8 data;
int err;
- switch (fifo_mode) {
- case ST_LSM6DSX_FIFO_BYPASS:
- data = fifo_mode;
- break;
- case ST_LSM6DSX_FIFO_CONT:
- data = (ST_LSM6DSX_MAX_FIFO_ODR_VAL <<
- __ffs(ST_LSM6DSX_FIFO_ODR_MASK)) | fifo_mode;
- break;
- default:
- return -EINVAL;
- }
-
- err = hw->tf->write(hw->dev, ST_LSM6DSX_REG_FIFO_MODE_ADDR,
- sizeof(data), &data);
+ err = st_lsm6dsx_write_with_mask(hw, ST_LSM6DSX_REG_FIFO_MODE_ADDR,
+ ST_LSM6DSX_FIFO_MODE_MASK, fifo_mode);
if (err < 0)
return err;
@@ -164,6 +151,17 @@ int st_lsm6dsx_set_fifo_mode(struct st_lsm6dsx_hw *hw,
return 0;
}
+static int st_lsm6dsx_set_fifo_odr(struct st_lsm6dsx_sensor *sensor,
+ bool enable)
+{
+ struct st_lsm6dsx_hw *hw = sensor->hw;
+ u8 data;
+
+ data = hw->enable_mask ? ST_LSM6DSX_MAX_FIFO_ODR_VAL : 0;
+ return st_lsm6dsx_write_with_mask(hw, ST_LSM6DSX_REG_FIFO_MODE_ADDR,
+ ST_LSM6DSX_FIFO_ODR_MASK, data);
+}
+
int st_lsm6dsx_update_watermark(struct st_lsm6dsx_sensor *sensor, u16 watermark)
{
u16 fifo_watermark = ~0, cur_watermark, sip = 0;
@@ -345,6 +343,10 @@ static int st_lsm6dsx_update_fifo(struct iio_dev *iio_dev, bool enable)
return err;
}
+ err = st_lsm6dsx_set_fifo_odr(sensor, enable);
+ if (err < 0)
+ return err;
+
err = st_lsm6dsx_update_decimators(hw);
if (err < 0)
return err;
--
2.14.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 3/4] iio: imu: st_lsm6dsx: move decimator info in st_lsm6dsx_sensor_settings
2017-09-27 19:29 [PATCH 0/4] rework st_lsm6dsx driver to support more devices Lorenzo Bianconi
2017-09-27 19:29 ` [PATCH 1/4] iio: imu: st_lsm6dsx: convert max_fifo_size in fifo words Lorenzo Bianconi
2017-09-27 19:29 ` [PATCH 2/4] iio: imu: st_lsm6dsx: split fifo mode and fifo odr configuration Lorenzo Bianconi
@ 2017-09-27 19:29 ` Lorenzo Bianconi
2017-10-01 10:44 ` Jonathan Cameron
2017-09-27 19:29 ` [PATCH 4/4] iio: imu: st_lsm6dsx: add FIFO ops data structure Lorenzo Bianconi
3 siblings, 1 reply; 12+ messages in thread
From: Lorenzo Bianconi @ 2017-09-27 19:29 UTC (permalink / raw)
To: jic23; +Cc: linux-iio, lorenzo.bianconi
Move FIFO decimator info in st_lsm6dsx_sensor_settings list since
decimator registers are exported in register map just in
lsm6ds3/lsm6ds3h/lsm6dsl/lsm6dsm sensors and not in other compliant
devices
Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@st.com>
---
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h | 10 ++++++--
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c | 17 +++++++------
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 34 +++++++++++++++++++++++---
3 files changed, 47 insertions(+), 14 deletions(-)
diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
index 46352c7bff43..052db1fbb46e 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
@@ -52,10 +52,18 @@ struct st_lsm6dsx_reg {
u8 mask;
};
+/**
+ * struct st_lsm6dsx_settings - ST IMU sensor settings
+ * @wai: Sensor WhoAmI default value.
+ * @max_fifo_size: Sensor max fifo length in FIFO words.
+ * @id: List of hw id supported by the driver configuration.
+ * @decimator: List of decimator register info (addr + mask).
+ */
struct st_lsm6dsx_settings {
u8 wai;
u16 max_fifo_size;
enum st_lsm6dsx_hw_id id[ST_LSM6DSX_MAX_ID];
+ struct st_lsm6dsx_reg decimator[ST_LSM6DSX_MAX_ID];
};
enum st_lsm6dsx_sensor_id {
@@ -79,7 +87,6 @@ enum st_lsm6dsx_fifo_mode {
* @watermark: Sensor watermark level.
* @sip: Number of samples in a given pattern.
* @decimator: FIFO decimation factor.
- * @decimator_mask: Sensor mask for decimation register.
* @delta_ts: Delta time between two consecutive interrupts.
* @ts: Latest timestamp from the interrupt handler.
*/
@@ -94,7 +101,6 @@ struct st_lsm6dsx_sensor {
u16 watermark;
u8 sip;
u8 decimator;
- u8 decimator_mask;
s64 delta_ts;
s64 ts;
diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c
index 26fb970aed15..cb4f8558a98f 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c
@@ -38,7 +38,6 @@
#define ST_LSM6DSX_REG_FIFO_THL_ADDR 0x06
#define ST_LSM6DSX_REG_FIFO_THH_ADDR 0x07
#define ST_LSM6DSX_FIFO_TH_MASK GENMASK(11, 0)
-#define ST_LSM6DSX_REG_FIFO_DEC_GXL_ADDR 0x08
#define ST_LSM6DSX_REG_HLACTIVE_ADDR 0x12
#define ST_LSM6DSX_REG_HLACTIVE_MASK BIT(5)
#define ST_LSM6DSX_REG_PP_OD_ADDR 0x12
@@ -110,8 +109,9 @@ static int st_lsm6dsx_update_decimators(struct st_lsm6dsx_hw *hw)
st_lsm6dsx_get_max_min_odr(hw, &max_odr, &min_odr);
for (i = 0; i < ST_LSM6DSX_ID_MAX; i++) {
- sensor = iio_priv(hw->iio_devs[i]);
+ const struct st_lsm6dsx_reg *dec_reg;
+ sensor = iio_priv(hw->iio_devs[i]);
/* update fifo decimators and sample in pattern */
if (hw->enable_mask & BIT(sensor->id)) {
sensor->sip = sensor->odr / min_odr;
@@ -123,12 +123,13 @@ static int st_lsm6dsx_update_decimators(struct st_lsm6dsx_hw *hw)
data = 0;
}
- err = st_lsm6dsx_write_with_mask(hw,
- ST_LSM6DSX_REG_FIFO_DEC_GXL_ADDR,
- sensor->decimator_mask, data);
- if (err < 0)
- return err;
-
+ dec_reg = &hw->settings->decimator[sensor->id];
+ if (dec_reg->addr) {
+ err = st_lsm6dsx_write_with_mask(hw, dec_reg->addr,
+ dec_reg->mask, data);
+ if (err < 0)
+ return err;
+ }
sip += sensor->sip;
}
hw->sip = sip;
diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
index e6e0363cd1c2..4532671df1be 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
@@ -42,8 +42,6 @@
#include "st_lsm6dsx.h"
-#define ST_LSM6DSX_REG_ACC_DEC_MASK GENMASK(2, 0)
-#define ST_LSM6DSX_REG_GYRO_DEC_MASK GENMASK(5, 3)
#define ST_LSM6DSX_REG_INT1_ADDR 0x0d
#define ST_LSM6DSX_REG_INT2_ADDR 0x0e
#define ST_LSM6DSX_REG_FIFO_FTH_IRQ_MASK BIT(3)
@@ -160,6 +158,16 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
.id = {
[0] = ST_LSM6DS3_ID,
},
+ .decimator = {
+ [ST_LSM6DSX_ID_ACC] = {
+ .addr = 0x08,
+ .mask = GENMASK(2, 0),
+ },
+ [ST_LSM6DSX_ID_GYRO] = {
+ .addr = 0x08,
+ .mask = GENMASK(5, 3),
+ },
+ },
},
{
.wai = 0x69,
@@ -167,6 +175,16 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
.id = {
[0] = ST_LSM6DS3H_ID,
},
+ .decimator = {
+ [ST_LSM6DSX_ID_ACC] = {
+ .addr = 0x08,
+ .mask = GENMASK(2, 0),
+ },
+ [ST_LSM6DSX_ID_GYRO] = {
+ .addr = 0x08,
+ .mask = GENMASK(5, 3),
+ },
+ },
},
{
.wai = 0x6a,
@@ -175,6 +193,16 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
[0] = ST_LSM6DSL_ID,
[1] = ST_LSM6DSM_ID,
},
+ .decimator = {
+ [ST_LSM6DSX_ID_ACC] = {
+ .addr = 0x08,
+ .mask = GENMASK(2, 0),
+ },
+ [ST_LSM6DSX_ID_GYRO] = {
+ .addr = 0x08,
+ .mask = GENMASK(5, 3),
+ },
+ },
},
};
@@ -645,7 +673,6 @@ static struct iio_dev *st_lsm6dsx_alloc_iiodev(struct st_lsm6dsx_hw *hw,
iio_dev->num_channels = ARRAY_SIZE(st_lsm6dsx_acc_channels);
iio_dev->info = &st_lsm6dsx_acc_info;
- sensor->decimator_mask = ST_LSM6DSX_REG_ACC_DEC_MASK;
scnprintf(sensor->name, sizeof(sensor->name), "%s_accel",
name);
break;
@@ -654,7 +681,6 @@ static struct iio_dev *st_lsm6dsx_alloc_iiodev(struct st_lsm6dsx_hw *hw,
iio_dev->num_channels = ARRAY_SIZE(st_lsm6dsx_gyro_channels);
iio_dev->info = &st_lsm6dsx_gyro_info;
- sensor->decimator_mask = ST_LSM6DSX_REG_GYRO_DEC_MASK;
scnprintf(sensor->name, sizeof(sensor->name), "%s_gyro",
name);
break;
--
2.14.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 4/4] iio: imu: st_lsm6dsx: add FIFO ops data structure
2017-09-27 19:29 [PATCH 0/4] rework st_lsm6dsx driver to support more devices Lorenzo Bianconi
` (2 preceding siblings ...)
2017-09-27 19:29 ` [PATCH 3/4] iio: imu: st_lsm6dsx: move decimator info in st_lsm6dsx_sensor_settings Lorenzo Bianconi
@ 2017-09-27 19:29 ` Lorenzo Bianconi
2017-10-01 10:48 ` Jonathan Cameron
3 siblings, 1 reply; 12+ messages in thread
From: Lorenzo Bianconi @ 2017-09-27 19:29 UTC (permalink / raw)
To: jic23; +Cc: linux-iio, lorenzo.bianconi
Introduce FIFO ops data structure to contain FIFO related parameter
in order to properly support more devices in st_lsm6dsx driver
Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@st.com>
---
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h | 23 ++++++++++++++++--
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c | 23 ++++++++----------
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 33 ++++++++++++++++++++++++++
3 files changed, 64 insertions(+), 15 deletions(-)
diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
index 052db1fbb46e..57c7e8e1f915 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
@@ -29,8 +29,6 @@ enum st_lsm6dsx_hw_id {
#define ST_LSM6DSX_CHAN_SIZE 2
#define ST_LSM6DSX_SAMPLE_SIZE 6
-#define ST_LSM6DSX_SAMPLE_DEPTH (ST_LSM6DSX_SAMPLE_SIZE / \
- ST_LSM6DSX_CHAN_SIZE)
#if defined(CONFIG_SPI_MASTER)
#define ST_LSM6DSX_RX_MAX_LENGTH 256
@@ -52,18 +50,39 @@ struct st_lsm6dsx_reg {
u8 mask;
};
+/**
+ * struct st_lsm6dsx_fifo_ops - ST IMU FIFO settings
+ * @fifo_th: FIFO threshold register info (addr + mask).
+ * @fifo_diff: FIFO diff status register info (addr + mask).
+ * @th_wl: FIFO threshold word length.
+ *
+ */
+struct st_lsm6dsx_fifo_ops {
+ struct {
+ u8 addr;
+ u16 mask;
+ } fifo_th;
+ struct {
+ u8 addr;
+ u16 mask;
+ } fifo_diff;
+ u8 th_wl;
+};
+
/**
* struct st_lsm6dsx_settings - ST IMU sensor settings
* @wai: Sensor WhoAmI default value.
* @max_fifo_size: Sensor max fifo length in FIFO words.
* @id: List of hw id supported by the driver configuration.
* @decimator: List of decimator register info (addr + mask).
+ * @fifo_ops: Sensor hw FIFO parameters.
*/
struct st_lsm6dsx_settings {
u8 wai;
u16 max_fifo_size;
enum st_lsm6dsx_hw_id id[ST_LSM6DSX_MAX_ID];
struct st_lsm6dsx_reg decimator[ST_LSM6DSX_MAX_ID];
+ struct st_lsm6dsx_fifo_ops fifo_ops;
};
enum st_lsm6dsx_sensor_id {
diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c
index cb4f8558a98f..755c472e8a05 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c
@@ -35,9 +35,6 @@
#include "st_lsm6dsx.h"
-#define ST_LSM6DSX_REG_FIFO_THL_ADDR 0x06
-#define ST_LSM6DSX_REG_FIFO_THH_ADDR 0x07
-#define ST_LSM6DSX_FIFO_TH_MASK GENMASK(11, 0)
#define ST_LSM6DSX_REG_HLACTIVE_ADDR 0x12
#define ST_LSM6DSX_REG_HLACTIVE_MASK BIT(5)
#define ST_LSM6DSX_REG_PP_OD_ADDR 0x12
@@ -45,8 +42,6 @@
#define ST_LSM6DSX_REG_FIFO_MODE_ADDR 0x0a
#define ST_LSM6DSX_FIFO_MODE_MASK GENMASK(2, 0)
#define ST_LSM6DSX_FIFO_ODR_MASK GENMASK(6, 3)
-#define ST_LSM6DSX_REG_FIFO_DIFFL_ADDR 0x3a
-#define ST_LSM6DSX_FIFO_DIFF_MASK GENMASK(11, 0)
#define ST_LSM6DSX_FIFO_EMPTY_MASK BIT(12)
#define ST_LSM6DSX_REG_FIFO_OUTL_ADDR 0x3e
@@ -165,7 +160,7 @@ static int st_lsm6dsx_set_fifo_odr(struct st_lsm6dsx_sensor *sensor,
int st_lsm6dsx_update_watermark(struct st_lsm6dsx_sensor *sensor, u16 watermark)
{
- u16 fifo_watermark = ~0, cur_watermark, sip = 0;
+ u16 fifo_watermark = ~0, cur_watermark, sip = 0, fifo_th_mask;
struct st_lsm6dsx_hw *hw = sensor->hw;
struct st_lsm6dsx_sensor *cur_sensor;
__le16 wdata;
@@ -190,20 +185,21 @@ int st_lsm6dsx_update_watermark(struct st_lsm6dsx_sensor *sensor, u16 watermark)
fifo_watermark = max_t(u16, fifo_watermark, sip);
fifo_watermark = (fifo_watermark / sip) * sip;
- fifo_watermark = fifo_watermark * ST_LSM6DSX_SAMPLE_DEPTH;
+ fifo_watermark = fifo_watermark * hw->settings->fifo_ops.th_wl;
mutex_lock(&hw->lock);
- err = hw->tf->read(hw->dev, ST_LSM6DSX_REG_FIFO_THH_ADDR,
+ err = hw->tf->read(hw->dev, hw->settings->fifo_ops.fifo_th.addr + 1,
sizeof(data), &data);
if (err < 0)
goto out;
- fifo_watermark = ((data << 8) & ~ST_LSM6DSX_FIFO_TH_MASK) |
- (fifo_watermark & ST_LSM6DSX_FIFO_TH_MASK);
+ fifo_th_mask = hw->settings->fifo_ops.fifo_th.mask;
+ fifo_watermark = ((data << 8) & ~fifo_th_mask) |
+ (fifo_watermark & fifo_th_mask);
wdata = cpu_to_le16(fifo_watermark);
- err = hw->tf->write(hw->dev, ST_LSM6DSX_REG_FIFO_THL_ADDR,
+ err = hw->tf->write(hw->dev, hw->settings->fifo_ops.fifo_th.addr,
sizeof(wdata), (u8 *)&wdata);
out:
mutex_unlock(&hw->lock);
@@ -222,6 +218,7 @@ int st_lsm6dsx_update_watermark(struct st_lsm6dsx_sensor *sensor, u16 watermark)
static int st_lsm6dsx_read_fifo(struct st_lsm6dsx_hw *hw)
{
u16 fifo_len, pattern_len = hw->sip * ST_LSM6DSX_SAMPLE_SIZE;
+ u16 fifo_diff_mask = hw->settings->fifo_ops.fifo_diff.mask;
int err, acc_sip, gyro_sip, read_len, samples, offset;
struct st_lsm6dsx_sensor *acc_sensor, *gyro_sensor;
s64 acc_ts, acc_delta_ts, gyro_ts, gyro_delta_ts;
@@ -229,7 +226,7 @@ static int st_lsm6dsx_read_fifo(struct st_lsm6dsx_hw *hw)
u8 buff[pattern_len];
__le16 fifo_status;
- err = hw->tf->read(hw->dev, ST_LSM6DSX_REG_FIFO_DIFFL_ADDR,
+ err = hw->tf->read(hw->dev, hw->settings->fifo_ops.fifo_diff.addr,
sizeof(fifo_status), (u8 *)&fifo_status);
if (err < 0)
return err;
@@ -237,7 +234,7 @@ static int st_lsm6dsx_read_fifo(struct st_lsm6dsx_hw *hw)
if (fifo_status & cpu_to_le16(ST_LSM6DSX_FIFO_EMPTY_MASK))
return 0;
- fifo_len = (le16_to_cpu(fifo_status) & ST_LSM6DSX_FIFO_DIFF_MASK) *
+ fifo_len = (le16_to_cpu(fifo_status) & fifo_diff_mask) *
ST_LSM6DSX_CHAN_SIZE;
samples = fifo_len / ST_LSM6DSX_SAMPLE_SIZE;
fifo_len = (fifo_len / pattern_len) * pattern_len;
diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
index 4532671df1be..239c735242be 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
@@ -168,6 +168,17 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
.mask = GENMASK(5, 3),
},
},
+ .fifo_ops = {
+ .fifo_th = {
+ .addr = 0x06,
+ .mask = GENMASK(11, 0),
+ },
+ .fifo_diff = {
+ .addr = 0x3a,
+ .mask = GENMASK(11, 0),
+ },
+ .th_wl = 3, /* 1LSB = 2B */
+ },
},
{
.wai = 0x69,
@@ -185,6 +196,17 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
.mask = GENMASK(5, 3),
},
},
+ .fifo_ops = {
+ .fifo_th = {
+ .addr = 0x06,
+ .mask = GENMASK(11, 0),
+ },
+ .fifo_diff = {
+ .addr = 0x3a,
+ .mask = GENMASK(11, 0),
+ },
+ .th_wl = 3, /* 1LSB = 2B */
+ },
},
{
.wai = 0x6a,
@@ -203,6 +225,17 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
.mask = GENMASK(5, 3),
},
},
+ .fifo_ops = {
+ .fifo_th = {
+ .addr = 0x06,
+ .mask = GENMASK(11, 0),
+ },
+ .fifo_diff = {
+ .addr = 0x3a,
+ .mask = GENMASK(11, 0),
+ },
+ .th_wl = 3, /* 1LSB = 2B */
+ },
},
};
--
2.14.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH 1/4] iio: imu: st_lsm6dsx: convert max_fifo_size in fifo words
2017-09-27 19:29 ` [PATCH 1/4] iio: imu: st_lsm6dsx: convert max_fifo_size in fifo words Lorenzo Bianconi
@ 2017-10-01 10:40 ` Jonathan Cameron
2017-10-01 13:05 ` Lorenzo Bianconi
0 siblings, 1 reply; 12+ messages in thread
From: Jonathan Cameron @ 2017-10-01 10:40 UTC (permalink / raw)
To: Lorenzo Bianconi; +Cc: linux-iio, lorenzo.bianconi
On Wed, 27 Sep 2017 21:29:25 +0200
Lorenzo Bianconi <lorenzo.bianconi83@gmail.com> wrote:
> Express max fifo depth in fifo words instead of in bytes.
> That change will be necessary to properly support more devices
> in st_lsm6dsx driver
>
> Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@st.com>
I'm not sure the term words really applies here. Fifo entries maybe?
We are talking about a set of sample I think?
Other than terminology the patch is fine.
Jonathan
> ---
> drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 11 +++++------
> 1 file changed, 5 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> index debf4064f474..e6e0363cd1c2 100644
> --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> @@ -156,21 +156,21 @@ static const struct st_lsm6dsx_fs_table_entry st_lsm6dsx_fs_table[] = {
> static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
> {
> .wai = 0x69,
> - .max_fifo_size = 8192,
> + .max_fifo_size = 1365,
> .id = {
> [0] = ST_LSM6DS3_ID,
> },
> },
> {
> .wai = 0x69,
> - .max_fifo_size = 4096,
> + .max_fifo_size = 682,
> .id = {
> [0] = ST_LSM6DS3H_ID,
> },
> },
> {
> .wai = 0x6a,
> - .max_fifo_size = 4096,
> + .max_fifo_size = 682,
> .id = {
> [0] = ST_LSM6DSL_ID,
> [1] = ST_LSM6DSM_ID,
> @@ -462,10 +462,9 @@ static int st_lsm6dsx_set_watermark(struct iio_dev *iio_dev, unsigned int val)
> {
> struct st_lsm6dsx_sensor *sensor = iio_priv(iio_dev);
> struct st_lsm6dsx_hw *hw = sensor->hw;
> - int err, max_fifo_len;
> + int err;
>
> - max_fifo_len = hw->settings->max_fifo_size / ST_LSM6DSX_SAMPLE_SIZE;
> - if (val < 1 || val > max_fifo_len)
> + if (val < 1 || val > hw->settings->max_fifo_size)
> return -EINVAL;
>
> err = st_lsm6dsx_update_watermark(sensor, val);
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 2/4] iio: imu: st_lsm6dsx: split fifo mode and fifo odr configuration
2017-09-27 19:29 ` [PATCH 2/4] iio: imu: st_lsm6dsx: split fifo mode and fifo odr configuration Lorenzo Bianconi
@ 2017-10-01 10:42 ` Jonathan Cameron
0 siblings, 0 replies; 12+ messages in thread
From: Jonathan Cameron @ 2017-10-01 10:42 UTC (permalink / raw)
To: Lorenzo Bianconi; +Cc: linux-iio, lorenzo.bianconi
On Wed, 27 Sep 2017 21:29:26 +0200
Lorenzo Bianconi <lorenzo.bianconi83@gmail.com> wrote:
> Separate fifo mode and max fifo sample rate configuration.
> That change will be necessary to reuse st_lsm6dsx_set_fifo_mode()
> routine and to support more devices in st_lsm6dsx driver
>
> Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@st.com>
Sensible change - I'd prefer to see a change like this made
as part of the series making use of it though... Always nice
to have proof that it is a good change ;)
Jonathan
> ---
> drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c | 32 ++++++++++++++------------
> 1 file changed, 17 insertions(+), 15 deletions(-)
>
> diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c
> index e2737dc71b67..26fb970aed15 100644
> --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c
> +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c
> @@ -139,23 +139,10 @@ static int st_lsm6dsx_update_decimators(struct st_lsm6dsx_hw *hw)
> int st_lsm6dsx_set_fifo_mode(struct st_lsm6dsx_hw *hw,
> enum st_lsm6dsx_fifo_mode fifo_mode)
> {
> - u8 data;
> int err;
>
> - switch (fifo_mode) {
> - case ST_LSM6DSX_FIFO_BYPASS:
> - data = fifo_mode;
> - break;
> - case ST_LSM6DSX_FIFO_CONT:
> - data = (ST_LSM6DSX_MAX_FIFO_ODR_VAL <<
> - __ffs(ST_LSM6DSX_FIFO_ODR_MASK)) | fifo_mode;
> - break;
> - default:
> - return -EINVAL;
> - }
> -
> - err = hw->tf->write(hw->dev, ST_LSM6DSX_REG_FIFO_MODE_ADDR,
> - sizeof(data), &data);
> + err = st_lsm6dsx_write_with_mask(hw, ST_LSM6DSX_REG_FIFO_MODE_ADDR,
> + ST_LSM6DSX_FIFO_MODE_MASK, fifo_mode);
> if (err < 0)
> return err;
>
> @@ -164,6 +151,17 @@ int st_lsm6dsx_set_fifo_mode(struct st_lsm6dsx_hw *hw,
> return 0;
> }
>
> +static int st_lsm6dsx_set_fifo_odr(struct st_lsm6dsx_sensor *sensor,
> + bool enable)
> +{
> + struct st_lsm6dsx_hw *hw = sensor->hw;
> + u8 data;
> +
> + data = hw->enable_mask ? ST_LSM6DSX_MAX_FIFO_ODR_VAL : 0;
> + return st_lsm6dsx_write_with_mask(hw, ST_LSM6DSX_REG_FIFO_MODE_ADDR,
> + ST_LSM6DSX_FIFO_ODR_MASK, data);
> +}
> +
> int st_lsm6dsx_update_watermark(struct st_lsm6dsx_sensor *sensor, u16 watermark)
> {
> u16 fifo_watermark = ~0, cur_watermark, sip = 0;
> @@ -345,6 +343,10 @@ static int st_lsm6dsx_update_fifo(struct iio_dev *iio_dev, bool enable)
> return err;
> }
>
> + err = st_lsm6dsx_set_fifo_odr(sensor, enable);
> + if (err < 0)
> + return err;
> +
> err = st_lsm6dsx_update_decimators(hw);
> if (err < 0)
> return err;
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 3/4] iio: imu: st_lsm6dsx: move decimator info in st_lsm6dsx_sensor_settings
2017-09-27 19:29 ` [PATCH 3/4] iio: imu: st_lsm6dsx: move decimator info in st_lsm6dsx_sensor_settings Lorenzo Bianconi
@ 2017-10-01 10:44 ` Jonathan Cameron
0 siblings, 0 replies; 12+ messages in thread
From: Jonathan Cameron @ 2017-10-01 10:44 UTC (permalink / raw)
To: Lorenzo Bianconi; +Cc: linux-iio, lorenzo.bianconi
On Wed, 27 Sep 2017 21:29:27 +0200
Lorenzo Bianconi <lorenzo.bianconi83@gmail.com> wrote:
> Move FIFO decimator info in st_lsm6dsx_sensor_settings list since
> decimator registers are exported in register map just in
> lsm6ds3/lsm6ds3h/lsm6dsl/lsm6dsm sensors and not in other compliant
> devices
>
> Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@st.com>
Sensible change. I'll pick this up once wording of patch 1 is sorted.
Jonathan
> ---
> drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h | 10 ++++++--
> drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c | 17 +++++++------
> drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 34 +++++++++++++++++++++++---
> 3 files changed, 47 insertions(+), 14 deletions(-)
>
> diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
> index 46352c7bff43..052db1fbb46e 100644
> --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
> +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
> @@ -52,10 +52,18 @@ struct st_lsm6dsx_reg {
> u8 mask;
> };
>
> +/**
> + * struct st_lsm6dsx_settings - ST IMU sensor settings
> + * @wai: Sensor WhoAmI default value.
> + * @max_fifo_size: Sensor max fifo length in FIFO words.
> + * @id: List of hw id supported by the driver configuration.
> + * @decimator: List of decimator register info (addr + mask).
> + */
> struct st_lsm6dsx_settings {
> u8 wai;
> u16 max_fifo_size;
> enum st_lsm6dsx_hw_id id[ST_LSM6DSX_MAX_ID];
> + struct st_lsm6dsx_reg decimator[ST_LSM6DSX_MAX_ID];
> };
>
> enum st_lsm6dsx_sensor_id {
> @@ -79,7 +87,6 @@ enum st_lsm6dsx_fifo_mode {
> * @watermark: Sensor watermark level.
> * @sip: Number of samples in a given pattern.
> * @decimator: FIFO decimation factor.
> - * @decimator_mask: Sensor mask for decimation register.
> * @delta_ts: Delta time between two consecutive interrupts.
> * @ts: Latest timestamp from the interrupt handler.
> */
> @@ -94,7 +101,6 @@ struct st_lsm6dsx_sensor {
> u16 watermark;
> u8 sip;
> u8 decimator;
> - u8 decimator_mask;
>
> s64 delta_ts;
> s64 ts;
> diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c
> index 26fb970aed15..cb4f8558a98f 100644
> --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c
> +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c
> @@ -38,7 +38,6 @@
> #define ST_LSM6DSX_REG_FIFO_THL_ADDR 0x06
> #define ST_LSM6DSX_REG_FIFO_THH_ADDR 0x07
> #define ST_LSM6DSX_FIFO_TH_MASK GENMASK(11, 0)
> -#define ST_LSM6DSX_REG_FIFO_DEC_GXL_ADDR 0x08
> #define ST_LSM6DSX_REG_HLACTIVE_ADDR 0x12
> #define ST_LSM6DSX_REG_HLACTIVE_MASK BIT(5)
> #define ST_LSM6DSX_REG_PP_OD_ADDR 0x12
> @@ -110,8 +109,9 @@ static int st_lsm6dsx_update_decimators(struct st_lsm6dsx_hw *hw)
> st_lsm6dsx_get_max_min_odr(hw, &max_odr, &min_odr);
>
> for (i = 0; i < ST_LSM6DSX_ID_MAX; i++) {
> - sensor = iio_priv(hw->iio_devs[i]);
> + const struct st_lsm6dsx_reg *dec_reg;
>
> + sensor = iio_priv(hw->iio_devs[i]);
> /* update fifo decimators and sample in pattern */
> if (hw->enable_mask & BIT(sensor->id)) {
> sensor->sip = sensor->odr / min_odr;
> @@ -123,12 +123,13 @@ static int st_lsm6dsx_update_decimators(struct st_lsm6dsx_hw *hw)
> data = 0;
> }
>
> - err = st_lsm6dsx_write_with_mask(hw,
> - ST_LSM6DSX_REG_FIFO_DEC_GXL_ADDR,
> - sensor->decimator_mask, data);
> - if (err < 0)
> - return err;
> -
> + dec_reg = &hw->settings->decimator[sensor->id];
> + if (dec_reg->addr) {
> + err = st_lsm6dsx_write_with_mask(hw, dec_reg->addr,
> + dec_reg->mask, data);
> + if (err < 0)
> + return err;
> + }
> sip += sensor->sip;
> }
> hw->sip = sip;
> diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> index e6e0363cd1c2..4532671df1be 100644
> --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> @@ -42,8 +42,6 @@
>
> #include "st_lsm6dsx.h"
>
> -#define ST_LSM6DSX_REG_ACC_DEC_MASK GENMASK(2, 0)
> -#define ST_LSM6DSX_REG_GYRO_DEC_MASK GENMASK(5, 3)
> #define ST_LSM6DSX_REG_INT1_ADDR 0x0d
> #define ST_LSM6DSX_REG_INT2_ADDR 0x0e
> #define ST_LSM6DSX_REG_FIFO_FTH_IRQ_MASK BIT(3)
> @@ -160,6 +158,16 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
> .id = {
> [0] = ST_LSM6DS3_ID,
> },
> + .decimator = {
> + [ST_LSM6DSX_ID_ACC] = {
> + .addr = 0x08,
> + .mask = GENMASK(2, 0),
> + },
> + [ST_LSM6DSX_ID_GYRO] = {
> + .addr = 0x08,
> + .mask = GENMASK(5, 3),
> + },
> + },
> },
> {
> .wai = 0x69,
> @@ -167,6 +175,16 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
> .id = {
> [0] = ST_LSM6DS3H_ID,
> },
> + .decimator = {
> + [ST_LSM6DSX_ID_ACC] = {
> + .addr = 0x08,
> + .mask = GENMASK(2, 0),
> + },
> + [ST_LSM6DSX_ID_GYRO] = {
> + .addr = 0x08,
> + .mask = GENMASK(5, 3),
> + },
> + },
> },
> {
> .wai = 0x6a,
> @@ -175,6 +193,16 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
> [0] = ST_LSM6DSL_ID,
> [1] = ST_LSM6DSM_ID,
> },
> + .decimator = {
> + [ST_LSM6DSX_ID_ACC] = {
> + .addr = 0x08,
> + .mask = GENMASK(2, 0),
> + },
> + [ST_LSM6DSX_ID_GYRO] = {
> + .addr = 0x08,
> + .mask = GENMASK(5, 3),
> + },
> + },
> },
> };
>
> @@ -645,7 +673,6 @@ static struct iio_dev *st_lsm6dsx_alloc_iiodev(struct st_lsm6dsx_hw *hw,
> iio_dev->num_channels = ARRAY_SIZE(st_lsm6dsx_acc_channels);
> iio_dev->info = &st_lsm6dsx_acc_info;
>
> - sensor->decimator_mask = ST_LSM6DSX_REG_ACC_DEC_MASK;
> scnprintf(sensor->name, sizeof(sensor->name), "%s_accel",
> name);
> break;
> @@ -654,7 +681,6 @@ static struct iio_dev *st_lsm6dsx_alloc_iiodev(struct st_lsm6dsx_hw *hw,
> iio_dev->num_channels = ARRAY_SIZE(st_lsm6dsx_gyro_channels);
> iio_dev->info = &st_lsm6dsx_gyro_info;
>
> - sensor->decimator_mask = ST_LSM6DSX_REG_GYRO_DEC_MASK;
> scnprintf(sensor->name, sizeof(sensor->name), "%s_gyro",
> name);
> break;
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 4/4] iio: imu: st_lsm6dsx: add FIFO ops data structure
2017-09-27 19:29 ` [PATCH 4/4] iio: imu: st_lsm6dsx: add FIFO ops data structure Lorenzo Bianconi
@ 2017-10-01 10:48 ` Jonathan Cameron
2017-10-01 13:13 ` Lorenzo Bianconi
0 siblings, 1 reply; 12+ messages in thread
From: Jonathan Cameron @ 2017-10-01 10:48 UTC (permalink / raw)
To: Lorenzo Bianconi; +Cc: linux-iio, lorenzo.bianconi
On Wed, 27 Sep 2017 21:29:28 +0200
Lorenzo Bianconi <lorenzo.bianconi83@gmail.com> wrote:
> Introduce FIFO ops data structure to contain FIFO related parameter
> in order to properly support more devices in st_lsm6dsx driver
>
> Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@st.com>
One nitpick inline.
Normally I'm reluctant to take refactors that are required for new support
until the new support is also posted, but these are straight forward and
it is obvious why they might be made. Plus you deliver when you way
you are going to send new support - so I'll make an exception if you
give me a vague timescale for expected new support and it is fairly short...
Jonathan
> ---
> drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h | 23 ++++++++++++++++--
> drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c | 23 ++++++++----------
> drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 33 ++++++++++++++++++++++++++
> 3 files changed, 64 insertions(+), 15 deletions(-)
>
> diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
> index 052db1fbb46e..57c7e8e1f915 100644
> --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
> +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
> @@ -29,8 +29,6 @@ enum st_lsm6dsx_hw_id {
>
> #define ST_LSM6DSX_CHAN_SIZE 2
> #define ST_LSM6DSX_SAMPLE_SIZE 6
> -#define ST_LSM6DSX_SAMPLE_DEPTH (ST_LSM6DSX_SAMPLE_SIZE / \
> - ST_LSM6DSX_CHAN_SIZE)
>
> #if defined(CONFIG_SPI_MASTER)
> #define ST_LSM6DSX_RX_MAX_LENGTH 256
> @@ -52,18 +50,39 @@ struct st_lsm6dsx_reg {
> u8 mask;
> };
>
> +/**
> + * struct st_lsm6dsx_fifo_ops - ST IMU FIFO settings
> + * @fifo_th: FIFO threshold register info (addr + mask).
> + * @fifo_diff: FIFO diff status register info (addr + mask).
> + * @th_wl: FIFO threshold word length.
> + *
Drop this blank line.. Doesn't add anything useful ;)
> + */
> +struct st_lsm6dsx_fifo_ops {
> + struct {
> + u8 addr;
> + u16 mask;
> + } fifo_th;
> + struct {
> + u8 addr;
> + u16 mask;
> + } fifo_diff;
> + u8 th_wl;
> +};
> +
> /**
> * struct st_lsm6dsx_settings - ST IMU sensor settings
> * @wai: Sensor WhoAmI default value.
> * @max_fifo_size: Sensor max fifo length in FIFO words.
> * @id: List of hw id supported by the driver configuration.
> * @decimator: List of decimator register info (addr + mask).
> + * @fifo_ops: Sensor hw FIFO parameters.
> */
> struct st_lsm6dsx_settings {
> u8 wai;
> u16 max_fifo_size;
> enum st_lsm6dsx_hw_id id[ST_LSM6DSX_MAX_ID];
> struct st_lsm6dsx_reg decimator[ST_LSM6DSX_MAX_ID];
> + struct st_lsm6dsx_fifo_ops fifo_ops;
> };
>
> enum st_lsm6dsx_sensor_id {
> diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c
> index cb4f8558a98f..755c472e8a05 100644
> --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c
> +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c
> @@ -35,9 +35,6 @@
>
> #include "st_lsm6dsx.h"
>
> -#define ST_LSM6DSX_REG_FIFO_THL_ADDR 0x06
> -#define ST_LSM6DSX_REG_FIFO_THH_ADDR 0x07
> -#define ST_LSM6DSX_FIFO_TH_MASK GENMASK(11, 0)
> #define ST_LSM6DSX_REG_HLACTIVE_ADDR 0x12
> #define ST_LSM6DSX_REG_HLACTIVE_MASK BIT(5)
> #define ST_LSM6DSX_REG_PP_OD_ADDR 0x12
> @@ -45,8 +42,6 @@
> #define ST_LSM6DSX_REG_FIFO_MODE_ADDR 0x0a
> #define ST_LSM6DSX_FIFO_MODE_MASK GENMASK(2, 0)
> #define ST_LSM6DSX_FIFO_ODR_MASK GENMASK(6, 3)
> -#define ST_LSM6DSX_REG_FIFO_DIFFL_ADDR 0x3a
> -#define ST_LSM6DSX_FIFO_DIFF_MASK GENMASK(11, 0)
> #define ST_LSM6DSX_FIFO_EMPTY_MASK BIT(12)
> #define ST_LSM6DSX_REG_FIFO_OUTL_ADDR 0x3e
>
> @@ -165,7 +160,7 @@ static int st_lsm6dsx_set_fifo_odr(struct st_lsm6dsx_sensor *sensor,
>
> int st_lsm6dsx_update_watermark(struct st_lsm6dsx_sensor *sensor, u16 watermark)
> {
> - u16 fifo_watermark = ~0, cur_watermark, sip = 0;
> + u16 fifo_watermark = ~0, cur_watermark, sip = 0, fifo_th_mask;
> struct st_lsm6dsx_hw *hw = sensor->hw;
> struct st_lsm6dsx_sensor *cur_sensor;
> __le16 wdata;
> @@ -190,20 +185,21 @@ int st_lsm6dsx_update_watermark(struct st_lsm6dsx_sensor *sensor, u16 watermark)
>
> fifo_watermark = max_t(u16, fifo_watermark, sip);
> fifo_watermark = (fifo_watermark / sip) * sip;
> - fifo_watermark = fifo_watermark * ST_LSM6DSX_SAMPLE_DEPTH;
> + fifo_watermark = fifo_watermark * hw->settings->fifo_ops.th_wl;
>
> mutex_lock(&hw->lock);
>
> - err = hw->tf->read(hw->dev, ST_LSM6DSX_REG_FIFO_THH_ADDR,
> + err = hw->tf->read(hw->dev, hw->settings->fifo_ops.fifo_th.addr + 1,
> sizeof(data), &data);
> if (err < 0)
> goto out;
>
> - fifo_watermark = ((data << 8) & ~ST_LSM6DSX_FIFO_TH_MASK) |
> - (fifo_watermark & ST_LSM6DSX_FIFO_TH_MASK);
> + fifo_th_mask = hw->settings->fifo_ops.fifo_th.mask;
> + fifo_watermark = ((data << 8) & ~fifo_th_mask) |
> + (fifo_watermark & fifo_th_mask);
>
> wdata = cpu_to_le16(fifo_watermark);
> - err = hw->tf->write(hw->dev, ST_LSM6DSX_REG_FIFO_THL_ADDR,
> + err = hw->tf->write(hw->dev, hw->settings->fifo_ops.fifo_th.addr,
> sizeof(wdata), (u8 *)&wdata);
> out:
> mutex_unlock(&hw->lock);
> @@ -222,6 +218,7 @@ int st_lsm6dsx_update_watermark(struct st_lsm6dsx_sensor *sensor, u16 watermark)
> static int st_lsm6dsx_read_fifo(struct st_lsm6dsx_hw *hw)
> {
> u16 fifo_len, pattern_len = hw->sip * ST_LSM6DSX_SAMPLE_SIZE;
> + u16 fifo_diff_mask = hw->settings->fifo_ops.fifo_diff.mask;
> int err, acc_sip, gyro_sip, read_len, samples, offset;
> struct st_lsm6dsx_sensor *acc_sensor, *gyro_sensor;
> s64 acc_ts, acc_delta_ts, gyro_ts, gyro_delta_ts;
> @@ -229,7 +226,7 @@ static int st_lsm6dsx_read_fifo(struct st_lsm6dsx_hw *hw)
> u8 buff[pattern_len];
> __le16 fifo_status;
>
> - err = hw->tf->read(hw->dev, ST_LSM6DSX_REG_FIFO_DIFFL_ADDR,
> + err = hw->tf->read(hw->dev, hw->settings->fifo_ops.fifo_diff.addr,
> sizeof(fifo_status), (u8 *)&fifo_status);
> if (err < 0)
> return err;
> @@ -237,7 +234,7 @@ static int st_lsm6dsx_read_fifo(struct st_lsm6dsx_hw *hw)
> if (fifo_status & cpu_to_le16(ST_LSM6DSX_FIFO_EMPTY_MASK))
> return 0;
>
> - fifo_len = (le16_to_cpu(fifo_status) & ST_LSM6DSX_FIFO_DIFF_MASK) *
> + fifo_len = (le16_to_cpu(fifo_status) & fifo_diff_mask) *
> ST_LSM6DSX_CHAN_SIZE;
> samples = fifo_len / ST_LSM6DSX_SAMPLE_SIZE;
> fifo_len = (fifo_len / pattern_len) * pattern_len;
> diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> index 4532671df1be..239c735242be 100644
> --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> @@ -168,6 +168,17 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
> .mask = GENMASK(5, 3),
> },
> },
> + .fifo_ops = {
> + .fifo_th = {
> + .addr = 0x06,
> + .mask = GENMASK(11, 0),
> + },
> + .fifo_diff = {
> + .addr = 0x3a,
> + .mask = GENMASK(11, 0),
> + },
> + .th_wl = 3, /* 1LSB = 2B */
> + },
> },
> {
> .wai = 0x69,
> @@ -185,6 +196,17 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
> .mask = GENMASK(5, 3),
> },
> },
> + .fifo_ops = {
> + .fifo_th = {
> + .addr = 0x06,
> + .mask = GENMASK(11, 0),
> + },
> + .fifo_diff = {
> + .addr = 0x3a,
> + .mask = GENMASK(11, 0),
> + },
> + .th_wl = 3, /* 1LSB = 2B */
> + },
> },
> {
> .wai = 0x6a,
> @@ -203,6 +225,17 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
> .mask = GENMASK(5, 3),
> },
> },
> + .fifo_ops = {
> + .fifo_th = {
> + .addr = 0x06,
> + .mask = GENMASK(11, 0),
> + },
> + .fifo_diff = {
> + .addr = 0x3a,
> + .mask = GENMASK(11, 0),
> + },
> + .th_wl = 3, /* 1LSB = 2B */
> + },
> },
> };
>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 1/4] iio: imu: st_lsm6dsx: convert max_fifo_size in fifo words
2017-10-01 10:40 ` Jonathan Cameron
@ 2017-10-01 13:05 ` Lorenzo Bianconi
0 siblings, 0 replies; 12+ messages in thread
From: Lorenzo Bianconi @ 2017-10-01 13:05 UTC (permalink / raw)
To: Jonathan Cameron; +Cc: linux-iio, Lorenzo BIANCONI
> On Wed, 27 Sep 2017 21:29:25 +0200
> Lorenzo Bianconi <lorenzo.bianconi83@gmail.com> wrote:
>
>> Express max fifo depth in fifo words instead of in bytes.
>> That change will be necessary to properly support more devices
>> in st_lsm6dsx driver
>>
>> Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@st.com>
>
> I'm not sure the term words really applies here. Fifo entries maybe?
> We are talking about a set of sample I think?
>
> Other than terminology the patch is fine.
>
Yes, we are talking about a set of FIFO samples. For LSM6DS3,
LSM6DS3H, LSM6DSL and LSM6DSM we have at least 6B stored in FIFO (e.g:
Acc_x, Acc_y, Acc_z or Gyro_x, Gyro_y, Gyro_z).
I will modify commit log in v2.
Regards,
Lorenzo
> Jonathan
>
>> ---
>> drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 11 +++++------
>> 1 file changed, 5 insertions(+), 6 deletions(-)
>>
>> diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
>> index debf4064f474..e6e0363cd1c2 100644
>> --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
>> +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
>> @@ -156,21 +156,21 @@ static const struct st_lsm6dsx_fs_table_entry st_lsm6dsx_fs_table[] = {
>> static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>> {
>> .wai = 0x69,
>> - .max_fifo_size = 8192,
>> + .max_fifo_size = 1365,
>> .id = {
>> [0] = ST_LSM6DS3_ID,
>> },
>> },
>> {
>> .wai = 0x69,
>> - .max_fifo_size = 4096,
>> + .max_fifo_size = 682,
>> .id = {
>> [0] = ST_LSM6DS3H_ID,
>> },
>> },
>> {
>> .wai = 0x6a,
>> - .max_fifo_size = 4096,
>> + .max_fifo_size = 682,
>> .id = {
>> [0] = ST_LSM6DSL_ID,
>> [1] = ST_LSM6DSM_ID,
>> @@ -462,10 +462,9 @@ static int st_lsm6dsx_set_watermark(struct iio_dev *iio_dev, unsigned int val)
>> {
>> struct st_lsm6dsx_sensor *sensor = iio_priv(iio_dev);
>> struct st_lsm6dsx_hw *hw = sensor->hw;
>> - int err, max_fifo_len;
>> + int err;
>>
>> - max_fifo_len = hw->settings->max_fifo_size / ST_LSM6DSX_SAMPLE_SIZE;
>> - if (val < 1 || val > max_fifo_len)
>> + if (val < 1 || val > hw->settings->max_fifo_size)
>> return -EINVAL;
>>
>> err = st_lsm6dsx_update_watermark(sensor, val);
>
--
UNIX is Sexy: who | grep -i blonde | talk; cd ~; wine; talk; touch;
unzip; touch; strip; gasp; finger; gasp; mount; fsck; more; yes; gasp;
umount; make clean; sleep
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 4/4] iio: imu: st_lsm6dsx: add FIFO ops data structure
2017-10-01 10:48 ` Jonathan Cameron
@ 2017-10-01 13:13 ` Lorenzo Bianconi
2017-10-02 9:46 ` Jonathan Cameron
0 siblings, 1 reply; 12+ messages in thread
From: Lorenzo Bianconi @ 2017-10-01 13:13 UTC (permalink / raw)
To: Jonathan Cameron; +Cc: linux-iio, Lorenzo BIANCONI
> On Wed, 27 Sep 2017 21:29:28 +0200
> Lorenzo Bianconi <lorenzo.bianconi83@gmail.com> wrote:
>
>> Introduce FIFO ops data structure to contain FIFO related parameter
>> in order to properly support more devices in st_lsm6dsx driver
>>
>> Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@st.com>
>
> One nitpick inline.
Ack, I will fix in v2.
>
> Normally I'm reluctant to take refactors that are required for new support
> until the new support is also posted, but these are straight forward and
> it is obvious why they might be made. Plus you deliver when you way
> you are going to send new support - so I'll make an exception if you
> give me a vague timescale for expected new support and it is fairly short...
>
> Jonathan
>
Honestly I have no an answer at the moment, that patchset is a
preliminary work and it works properly on current supported devices.
Up to you, if you want I can send a v2 now or I can queue it up and
send it later with other patches.
Regards,
Lorenzo
>> ---
>> drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h | 23 ++++++++++++++++--
>> drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c | 23 ++++++++----------
>> drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 33 ++++++++++++++++++++++++++
>> 3 files changed, 64 insertions(+), 15 deletions(-)
>>
>> diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
>> index 052db1fbb46e..57c7e8e1f915 100644
>> --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
>> +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
>> @@ -29,8 +29,6 @@ enum st_lsm6dsx_hw_id {
>>
>> #define ST_LSM6DSX_CHAN_SIZE 2
>> #define ST_LSM6DSX_SAMPLE_SIZE 6
>> -#define ST_LSM6DSX_SAMPLE_DEPTH (ST_LSM6DSX_SAMPLE_SIZE / \
>> - ST_LSM6DSX_CHAN_SIZE)
>>
>> #if defined(CONFIG_SPI_MASTER)
>> #define ST_LSM6DSX_RX_MAX_LENGTH 256
>> @@ -52,18 +50,39 @@ struct st_lsm6dsx_reg {
>> u8 mask;
>> };
>>
>> +/**
>> + * struct st_lsm6dsx_fifo_ops - ST IMU FIFO settings
>> + * @fifo_th: FIFO threshold register info (addr + mask).
>> + * @fifo_diff: FIFO diff status register info (addr + mask).
>> + * @th_wl: FIFO threshold word length.
>> + *
>
> Drop this blank line.. Doesn't add anything useful ;)
>
>> + */
>> +struct st_lsm6dsx_fifo_ops {
>> + struct {
>> + u8 addr;
>> + u16 mask;
>> + } fifo_th;
>> + struct {
>> + u8 addr;
>> + u16 mask;
>> + } fifo_diff;
>> + u8 th_wl;
>> +};
>> +
>> /**
>> * struct st_lsm6dsx_settings - ST IMU sensor settings
>> * @wai: Sensor WhoAmI default value.
>> * @max_fifo_size: Sensor max fifo length in FIFO words.
>> * @id: List of hw id supported by the driver configuration.
>> * @decimator: List of decimator register info (addr + mask).
>> + * @fifo_ops: Sensor hw FIFO parameters.
>> */
>> struct st_lsm6dsx_settings {
>> u8 wai;
>> u16 max_fifo_size;
>> enum st_lsm6dsx_hw_id id[ST_LSM6DSX_MAX_ID];
>> struct st_lsm6dsx_reg decimator[ST_LSM6DSX_MAX_ID];
>> + struct st_lsm6dsx_fifo_ops fifo_ops;
>> };
>>
>> enum st_lsm6dsx_sensor_id {
>> diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c
>> index cb4f8558a98f..755c472e8a05 100644
>> --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c
>> +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c
>> @@ -35,9 +35,6 @@
>>
>> #include "st_lsm6dsx.h"
>>
>> -#define ST_LSM6DSX_REG_FIFO_THL_ADDR 0x06
>> -#define ST_LSM6DSX_REG_FIFO_THH_ADDR 0x07
>> -#define ST_LSM6DSX_FIFO_TH_MASK GENMASK(11, 0)
>> #define ST_LSM6DSX_REG_HLACTIVE_ADDR 0x12
>> #define ST_LSM6DSX_REG_HLACTIVE_MASK BIT(5)
>> #define ST_LSM6DSX_REG_PP_OD_ADDR 0x12
>> @@ -45,8 +42,6 @@
>> #define ST_LSM6DSX_REG_FIFO_MODE_ADDR 0x0a
>> #define ST_LSM6DSX_FIFO_MODE_MASK GENMASK(2, 0)
>> #define ST_LSM6DSX_FIFO_ODR_MASK GENMASK(6, 3)
>> -#define ST_LSM6DSX_REG_FIFO_DIFFL_ADDR 0x3a
>> -#define ST_LSM6DSX_FIFO_DIFF_MASK GENMASK(11, 0)
>> #define ST_LSM6DSX_FIFO_EMPTY_MASK BIT(12)
>> #define ST_LSM6DSX_REG_FIFO_OUTL_ADDR 0x3e
>>
>> @@ -165,7 +160,7 @@ static int st_lsm6dsx_set_fifo_odr(struct st_lsm6dsx_sensor *sensor,
>>
>> int st_lsm6dsx_update_watermark(struct st_lsm6dsx_sensor *sensor, u16 watermark)
>> {
>> - u16 fifo_watermark = ~0, cur_watermark, sip = 0;
>> + u16 fifo_watermark = ~0, cur_watermark, sip = 0, fifo_th_mask;
>> struct st_lsm6dsx_hw *hw = sensor->hw;
>> struct st_lsm6dsx_sensor *cur_sensor;
>> __le16 wdata;
>> @@ -190,20 +185,21 @@ int st_lsm6dsx_update_watermark(struct st_lsm6dsx_sensor *sensor, u16 watermark)
>>
>> fifo_watermark = max_t(u16, fifo_watermark, sip);
>> fifo_watermark = (fifo_watermark / sip) * sip;
>> - fifo_watermark = fifo_watermark * ST_LSM6DSX_SAMPLE_DEPTH;
>> + fifo_watermark = fifo_watermark * hw->settings->fifo_ops.th_wl;
>>
>> mutex_lock(&hw->lock);
>>
>> - err = hw->tf->read(hw->dev, ST_LSM6DSX_REG_FIFO_THH_ADDR,
>> + err = hw->tf->read(hw->dev, hw->settings->fifo_ops.fifo_th.addr + 1,
>> sizeof(data), &data);
>> if (err < 0)
>> goto out;
>>
>> - fifo_watermark = ((data << 8) & ~ST_LSM6DSX_FIFO_TH_MASK) |
>> - (fifo_watermark & ST_LSM6DSX_FIFO_TH_MASK);
>> + fifo_th_mask = hw->settings->fifo_ops.fifo_th.mask;
>> + fifo_watermark = ((data << 8) & ~fifo_th_mask) |
>> + (fifo_watermark & fifo_th_mask);
>>
>> wdata = cpu_to_le16(fifo_watermark);
>> - err = hw->tf->write(hw->dev, ST_LSM6DSX_REG_FIFO_THL_ADDR,
>> + err = hw->tf->write(hw->dev, hw->settings->fifo_ops.fifo_th.addr,
>> sizeof(wdata), (u8 *)&wdata);
>> out:
>> mutex_unlock(&hw->lock);
>> @@ -222,6 +218,7 @@ int st_lsm6dsx_update_watermark(struct st_lsm6dsx_sensor *sensor, u16 watermark)
>> static int st_lsm6dsx_read_fifo(struct st_lsm6dsx_hw *hw)
>> {
>> u16 fifo_len, pattern_len = hw->sip * ST_LSM6DSX_SAMPLE_SIZE;
>> + u16 fifo_diff_mask = hw->settings->fifo_ops.fifo_diff.mask;
>> int err, acc_sip, gyro_sip, read_len, samples, offset;
>> struct st_lsm6dsx_sensor *acc_sensor, *gyro_sensor;
>> s64 acc_ts, acc_delta_ts, gyro_ts, gyro_delta_ts;
>> @@ -229,7 +226,7 @@ static int st_lsm6dsx_read_fifo(struct st_lsm6dsx_hw *hw)
>> u8 buff[pattern_len];
>> __le16 fifo_status;
>>
>> - err = hw->tf->read(hw->dev, ST_LSM6DSX_REG_FIFO_DIFFL_ADDR,
>> + err = hw->tf->read(hw->dev, hw->settings->fifo_ops.fifo_diff.addr,
>> sizeof(fifo_status), (u8 *)&fifo_status);
>> if (err < 0)
>> return err;
>> @@ -237,7 +234,7 @@ static int st_lsm6dsx_read_fifo(struct st_lsm6dsx_hw *hw)
>> if (fifo_status & cpu_to_le16(ST_LSM6DSX_FIFO_EMPTY_MASK))
>> return 0;
>>
>> - fifo_len = (le16_to_cpu(fifo_status) & ST_LSM6DSX_FIFO_DIFF_MASK) *
>> + fifo_len = (le16_to_cpu(fifo_status) & fifo_diff_mask) *
>> ST_LSM6DSX_CHAN_SIZE;
>> samples = fifo_len / ST_LSM6DSX_SAMPLE_SIZE;
>> fifo_len = (fifo_len / pattern_len) * pattern_len;
>> diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
>> index 4532671df1be..239c735242be 100644
>> --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
>> +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
>> @@ -168,6 +168,17 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>> .mask = GENMASK(5, 3),
>> },
>> },
>> + .fifo_ops = {
>> + .fifo_th = {
>> + .addr = 0x06,
>> + .mask = GENMASK(11, 0),
>> + },
>> + .fifo_diff = {
>> + .addr = 0x3a,
>> + .mask = GENMASK(11, 0),
>> + },
>> + .th_wl = 3, /* 1LSB = 2B */
>> + },
>> },
>> {
>> .wai = 0x69,
>> @@ -185,6 +196,17 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>> .mask = GENMASK(5, 3),
>> },
>> },
>> + .fifo_ops = {
>> + .fifo_th = {
>> + .addr = 0x06,
>> + .mask = GENMASK(11, 0),
>> + },
>> + .fifo_diff = {
>> + .addr = 0x3a,
>> + .mask = GENMASK(11, 0),
>> + },
>> + .th_wl = 3, /* 1LSB = 2B */
>> + },
>> },
>> {
>> .wai = 0x6a,
>> @@ -203,6 +225,17 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>> .mask = GENMASK(5, 3),
>> },
>> },
>> + .fifo_ops = {
>> + .fifo_th = {
>> + .addr = 0x06,
>> + .mask = GENMASK(11, 0),
>> + },
>> + .fifo_diff = {
>> + .addr = 0x3a,
>> + .mask = GENMASK(11, 0),
>> + },
>> + .th_wl = 3, /* 1LSB = 2B */
>> + },
>> },
>> };
>>
>
--
UNIX is Sexy: who | grep -i blonde | talk; cd ~; wine; talk; touch;
unzip; touch; strip; gasp; finger; gasp; mount; fsck; more; yes; gasp;
umount; make clean; sleep
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 4/4] iio: imu: st_lsm6dsx: add FIFO ops data structure
2017-10-01 13:13 ` Lorenzo Bianconi
@ 2017-10-02 9:46 ` Jonathan Cameron
0 siblings, 0 replies; 12+ messages in thread
From: Jonathan Cameron @ 2017-10-02 9:46 UTC (permalink / raw)
To: Lorenzo Bianconi, Jonathan Cameron; +Cc: linux-iio, Lorenzo BIANCONI
On 1 October 2017 14:13:25 BST, Lorenzo Bianconi <lorenzo.bianconi83@gmail.com> wrote:
>> On Wed, 27 Sep 2017 21:29:28 +0200
>> Lorenzo Bianconi <lorenzo.bianconi83@gmail.com> wrote:
>>
>>> Introduce FIFO ops data structure to contain FIFO related parameter
>>> in order to properly support more devices in st_lsm6dsx driver
>>>
>>> Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@st.com>
>>
>> One nitpick inline.
>
>Ack, I will fix in v2.
>
>>
>> Normally I'm reluctant to take refactors that are required for new
>support
>> until the new support is also posted, but these are straight forward
>and
>> it is obvious why they might be made. Plus you deliver when you way
>> you are going to send new support - so I'll make an exception if you
>> give me a vague timescale for expected new support and it is fairly
>short...
>>
>> Jonathan
>>
>
>Honestly I have no an answer at the moment, that patchset is a
>preliminary work and it works properly on current supported devices.
>Up to you, if you want I can send a v2 now or I can queue it up and
>send it later with other patches.
>
Meh. This set is harmless so V2 now is fine with me..
Jonathan
>Regards,
>Lorenzo
>
>>> ---
>>> drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h | 23
>++++++++++++++++--
>>> drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c | 23
>++++++++----------
>>> drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 33
>++++++++++++++++++++++++++
>>> 3 files changed, 64 insertions(+), 15 deletions(-)
>>>
>>> diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
>b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
>>> index 052db1fbb46e..57c7e8e1f915 100644
>>> --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
>>> +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
>>> @@ -29,8 +29,6 @@ enum st_lsm6dsx_hw_id {
>>>
>>> #define ST_LSM6DSX_CHAN_SIZE 2
>>> #define ST_LSM6DSX_SAMPLE_SIZE 6
>>> -#define ST_LSM6DSX_SAMPLE_DEPTH
>(ST_LSM6DSX_SAMPLE_SIZE / \
>>> - ST_LSM6DSX_CHAN_SIZE)
>>>
>>> #if defined(CONFIG_SPI_MASTER)
>>> #define ST_LSM6DSX_RX_MAX_LENGTH 256
>>> @@ -52,18 +50,39 @@ struct st_lsm6dsx_reg {
>>> u8 mask;
>>> };
>>>
>>> +/**
>>> + * struct st_lsm6dsx_fifo_ops - ST IMU FIFO settings
>>> + * @fifo_th: FIFO threshold register info (addr + mask).
>>> + * @fifo_diff: FIFO diff status register info (addr + mask).
>>> + * @th_wl: FIFO threshold word length.
>>> + *
>>
>> Drop this blank line.. Doesn't add anything useful ;)
>>
>>> + */
>>> +struct st_lsm6dsx_fifo_ops {
>>> + struct {
>>> + u8 addr;
>>> + u16 mask;
>>> + } fifo_th;
>>> + struct {
>>> + u8 addr;
>>> + u16 mask;
>>> + } fifo_diff;
>>> + u8 th_wl;
>>> +};
>>> +
>>> /**
>>> * struct st_lsm6dsx_settings - ST IMU sensor settings
>>> * @wai: Sensor WhoAmI default value.
>>> * @max_fifo_size: Sensor max fifo length in FIFO words.
>>> * @id: List of hw id supported by the driver configuration.
>>> * @decimator: List of decimator register info (addr + mask).
>>> + * @fifo_ops: Sensor hw FIFO parameters.
>>> */
>>> struct st_lsm6dsx_settings {
>>> u8 wai;
>>> u16 max_fifo_size;
>>> enum st_lsm6dsx_hw_id id[ST_LSM6DSX_MAX_ID];
>>> struct st_lsm6dsx_reg decimator[ST_LSM6DSX_MAX_ID];
>>> + struct st_lsm6dsx_fifo_ops fifo_ops;
>>> };
>>>
>>> enum st_lsm6dsx_sensor_id {
>>> diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c
>b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c
>>> index cb4f8558a98f..755c472e8a05 100644
>>> --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c
>>> +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c
>>> @@ -35,9 +35,6 @@
>>>
>>> #include "st_lsm6dsx.h"
>>>
>>> -#define ST_LSM6DSX_REG_FIFO_THL_ADDR 0x06
>>> -#define ST_LSM6DSX_REG_FIFO_THH_ADDR 0x07
>>> -#define ST_LSM6DSX_FIFO_TH_MASK GENMASK(11, 0)
>>> #define ST_LSM6DSX_REG_HLACTIVE_ADDR 0x12
>>> #define ST_LSM6DSX_REG_HLACTIVE_MASK BIT(5)
>>> #define ST_LSM6DSX_REG_PP_OD_ADDR 0x12
>>> @@ -45,8 +42,6 @@
>>> #define ST_LSM6DSX_REG_FIFO_MODE_ADDR 0x0a
>>> #define ST_LSM6DSX_FIFO_MODE_MASK GENMASK(2, 0)
>>> #define ST_LSM6DSX_FIFO_ODR_MASK GENMASK(6, 3)
>>> -#define ST_LSM6DSX_REG_FIFO_DIFFL_ADDR 0x3a
>>> -#define ST_LSM6DSX_FIFO_DIFF_MASK GENMASK(11, 0)
>>> #define ST_LSM6DSX_FIFO_EMPTY_MASK BIT(12)
>>> #define ST_LSM6DSX_REG_FIFO_OUTL_ADDR 0x3e
>>>
>>> @@ -165,7 +160,7 @@ static int st_lsm6dsx_set_fifo_odr(struct
>st_lsm6dsx_sensor *sensor,
>>>
>>> int st_lsm6dsx_update_watermark(struct st_lsm6dsx_sensor *sensor,
>u16 watermark)
>>> {
>>> - u16 fifo_watermark = ~0, cur_watermark, sip = 0;
>>> + u16 fifo_watermark = ~0, cur_watermark, sip = 0, fifo_th_mask;
>>> struct st_lsm6dsx_hw *hw = sensor->hw;
>>> struct st_lsm6dsx_sensor *cur_sensor;
>>> __le16 wdata;
>>> @@ -190,20 +185,21 @@ int st_lsm6dsx_update_watermark(struct
>st_lsm6dsx_sensor *sensor, u16 watermark)
>>>
>>> fifo_watermark = max_t(u16, fifo_watermark, sip);
>>> fifo_watermark = (fifo_watermark / sip) * sip;
>>> - fifo_watermark = fifo_watermark * ST_LSM6DSX_SAMPLE_DEPTH;
>>> + fifo_watermark = fifo_watermark *
>hw->settings->fifo_ops.th_wl;
>>>
>>> mutex_lock(&hw->lock);
>>>
>>> - err = hw->tf->read(hw->dev, ST_LSM6DSX_REG_FIFO_THH_ADDR,
>>> + err = hw->tf->read(hw->dev,
>hw->settings->fifo_ops.fifo_th.addr + 1,
>>> sizeof(data), &data);
>>> if (err < 0)
>>> goto out;
>>>
>>> - fifo_watermark = ((data << 8) & ~ST_LSM6DSX_FIFO_TH_MASK) |
>>> - (fifo_watermark & ST_LSM6DSX_FIFO_TH_MASK);
>>> + fifo_th_mask = hw->settings->fifo_ops.fifo_th.mask;
>>> + fifo_watermark = ((data << 8) & ~fifo_th_mask) |
>>> + (fifo_watermark & fifo_th_mask);
>>>
>>> wdata = cpu_to_le16(fifo_watermark);
>>> - err = hw->tf->write(hw->dev, ST_LSM6DSX_REG_FIFO_THL_ADDR,
>>> + err = hw->tf->write(hw->dev,
>hw->settings->fifo_ops.fifo_th.addr,
>>> sizeof(wdata), (u8 *)&wdata);
>>> out:
>>> mutex_unlock(&hw->lock);
>>> @@ -222,6 +218,7 @@ int st_lsm6dsx_update_watermark(struct
>st_lsm6dsx_sensor *sensor, u16 watermark)
>>> static int st_lsm6dsx_read_fifo(struct st_lsm6dsx_hw *hw)
>>> {
>>> u16 fifo_len, pattern_len = hw->sip * ST_LSM6DSX_SAMPLE_SIZE;
>>> + u16 fifo_diff_mask = hw->settings->fifo_ops.fifo_diff.mask;
>>> int err, acc_sip, gyro_sip, read_len, samples, offset;
>>> struct st_lsm6dsx_sensor *acc_sensor, *gyro_sensor;
>>> s64 acc_ts, acc_delta_ts, gyro_ts, gyro_delta_ts;
>>> @@ -229,7 +226,7 @@ static int st_lsm6dsx_read_fifo(struct
>st_lsm6dsx_hw *hw)
>>> u8 buff[pattern_len];
>>> __le16 fifo_status;
>>>
>>> - err = hw->tf->read(hw->dev, ST_LSM6DSX_REG_FIFO_DIFFL_ADDR,
>>> + err = hw->tf->read(hw->dev,
>hw->settings->fifo_ops.fifo_diff.addr,
>>> sizeof(fifo_status), (u8 *)&fifo_status);
>>> if (err < 0)
>>> return err;
>>> @@ -237,7 +234,7 @@ static int st_lsm6dsx_read_fifo(struct
>st_lsm6dsx_hw *hw)
>>> if (fifo_status & cpu_to_le16(ST_LSM6DSX_FIFO_EMPTY_MASK))
>>> return 0;
>>>
>>> - fifo_len = (le16_to_cpu(fifo_status) &
>ST_LSM6DSX_FIFO_DIFF_MASK) *
>>> + fifo_len = (le16_to_cpu(fifo_status) & fifo_diff_mask) *
>>> ST_LSM6DSX_CHAN_SIZE;
>>> samples = fifo_len / ST_LSM6DSX_SAMPLE_SIZE;
>>> fifo_len = (fifo_len / pattern_len) * pattern_len;
>>> diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
>b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
>>> index 4532671df1be..239c735242be 100644
>>> --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
>>> +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
>>> @@ -168,6 +168,17 @@ static const struct st_lsm6dsx_settings
>st_lsm6dsx_sensor_settings[] = {
>>> .mask = GENMASK(5, 3),
>>> },
>>> },
>>> + .fifo_ops = {
>>> + .fifo_th = {
>>> + .addr = 0x06,
>>> + .mask = GENMASK(11, 0),
>>> + },
>>> + .fifo_diff = {
>>> + .addr = 0x3a,
>>> + .mask = GENMASK(11, 0),
>>> + },
>>> + .th_wl = 3, /* 1LSB = 2B */
>>> + },
>>> },
>>> {
>>> .wai = 0x69,
>>> @@ -185,6 +196,17 @@ static const struct st_lsm6dsx_settings
>st_lsm6dsx_sensor_settings[] = {
>>> .mask = GENMASK(5, 3),
>>> },
>>> },
>>> + .fifo_ops = {
>>> + .fifo_th = {
>>> + .addr = 0x06,
>>> + .mask = GENMASK(11, 0),
>>> + },
>>> + .fifo_diff = {
>>> + .addr = 0x3a,
>>> + .mask = GENMASK(11, 0),
>>> + },
>>> + .th_wl = 3, /* 1LSB = 2B */
>>> + },
>>> },
>>> {
>>> .wai = 0x6a,
>>> @@ -203,6 +225,17 @@ static const struct st_lsm6dsx_settings
>st_lsm6dsx_sensor_settings[] = {
>>> .mask = GENMASK(5, 3),
>>> },
>>> },
>>> + .fifo_ops = {
>>> + .fifo_th = {
>>> + .addr = 0x06,
>>> + .mask = GENMASK(11, 0),
>>> + },
>>> + .fifo_diff = {
>>> + .addr = 0x3a,
>>> + .mask = GENMASK(11, 0),
>>> + },
>>> + .th_wl = 3, /* 1LSB = 2B */
>>> + },
>>> },
>>> };
>>>
>>
--
Sent from my Android device with K-9 Mail. Please excuse my brevity.
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2017-10-02 9:46 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-09-27 19:29 [PATCH 0/4] rework st_lsm6dsx driver to support more devices Lorenzo Bianconi
2017-09-27 19:29 ` [PATCH 1/4] iio: imu: st_lsm6dsx: convert max_fifo_size in fifo words Lorenzo Bianconi
2017-10-01 10:40 ` Jonathan Cameron
2017-10-01 13:05 ` Lorenzo Bianconi
2017-09-27 19:29 ` [PATCH 2/4] iio: imu: st_lsm6dsx: split fifo mode and fifo odr configuration Lorenzo Bianconi
2017-10-01 10:42 ` Jonathan Cameron
2017-09-27 19:29 ` [PATCH 3/4] iio: imu: st_lsm6dsx: move decimator info in st_lsm6dsx_sensor_settings Lorenzo Bianconi
2017-10-01 10:44 ` Jonathan Cameron
2017-09-27 19:29 ` [PATCH 4/4] iio: imu: st_lsm6dsx: add FIFO ops data structure Lorenzo Bianconi
2017-10-01 10:48 ` Jonathan Cameron
2017-10-01 13:13 ` Lorenzo Bianconi
2017-10-02 9:46 ` Jonathan Cameron
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox