Commit 7ca3ac9e authored by Lorenzo Bianconi's avatar Lorenzo Bianconi Committed by Jonathan Cameron

iio: imu: st_lsm6dsx: move decimator info in st_lsm6dsx_sensor_settings

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: default avatarLorenzo Bianconi <lorenzo.bianconi@st.com>
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent ff81a933
...@@ -52,10 +52,18 @@ struct st_lsm6dsx_reg { ...@@ -52,10 +52,18 @@ struct st_lsm6dsx_reg {
u8 mask; 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 { struct st_lsm6dsx_settings {
u8 wai; u8 wai;
u16 max_fifo_size; u16 max_fifo_size;
enum st_lsm6dsx_hw_id id[ST_LSM6DSX_MAX_ID]; enum st_lsm6dsx_hw_id id[ST_LSM6DSX_MAX_ID];
struct st_lsm6dsx_reg decimator[ST_LSM6DSX_MAX_ID];
}; };
enum st_lsm6dsx_sensor_id { enum st_lsm6dsx_sensor_id {
...@@ -79,7 +87,6 @@ enum st_lsm6dsx_fifo_mode { ...@@ -79,7 +87,6 @@ enum st_lsm6dsx_fifo_mode {
* @watermark: Sensor watermark level. * @watermark: Sensor watermark level.
* @sip: Number of samples in a given pattern. * @sip: Number of samples in a given pattern.
* @decimator: FIFO decimation factor. * @decimator: FIFO decimation factor.
* @decimator_mask: Sensor mask for decimation register.
* @delta_ts: Delta time between two consecutive interrupts. * @delta_ts: Delta time between two consecutive interrupts.
* @ts: Latest timestamp from the interrupt handler. * @ts: Latest timestamp from the interrupt handler.
*/ */
...@@ -94,7 +101,6 @@ struct st_lsm6dsx_sensor { ...@@ -94,7 +101,6 @@ struct st_lsm6dsx_sensor {
u16 watermark; u16 watermark;
u8 sip; u8 sip;
u8 decimator; u8 decimator;
u8 decimator_mask;
s64 delta_ts; s64 delta_ts;
s64 ts; s64 ts;
......
...@@ -38,7 +38,6 @@ ...@@ -38,7 +38,6 @@
#define ST_LSM6DSX_REG_FIFO_THL_ADDR 0x06 #define ST_LSM6DSX_REG_FIFO_THL_ADDR 0x06
#define ST_LSM6DSX_REG_FIFO_THH_ADDR 0x07 #define ST_LSM6DSX_REG_FIFO_THH_ADDR 0x07
#define ST_LSM6DSX_FIFO_TH_MASK GENMASK(11, 0) #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_ADDR 0x12
#define ST_LSM6DSX_REG_HLACTIVE_MASK BIT(5) #define ST_LSM6DSX_REG_HLACTIVE_MASK BIT(5)
#define ST_LSM6DSX_REG_PP_OD_ADDR 0x12 #define ST_LSM6DSX_REG_PP_OD_ADDR 0x12
...@@ -110,8 +109,9 @@ static int st_lsm6dsx_update_decimators(struct st_lsm6dsx_hw *hw) ...@@ -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); st_lsm6dsx_get_max_min_odr(hw, &max_odr, &min_odr);
for (i = 0; i < ST_LSM6DSX_ID_MAX; i++) { 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 */ /* update fifo decimators and sample in pattern */
if (hw->enable_mask & BIT(sensor->id)) { if (hw->enable_mask & BIT(sensor->id)) {
sensor->sip = sensor->odr / min_odr; sensor->sip = sensor->odr / min_odr;
...@@ -123,12 +123,13 @@ static int st_lsm6dsx_update_decimators(struct st_lsm6dsx_hw *hw) ...@@ -123,12 +123,13 @@ static int st_lsm6dsx_update_decimators(struct st_lsm6dsx_hw *hw)
data = 0; data = 0;
} }
err = st_lsm6dsx_write_with_mask(hw, dec_reg = &hw->settings->decimator[sensor->id];
ST_LSM6DSX_REG_FIFO_DEC_GXL_ADDR, if (dec_reg->addr) {
sensor->decimator_mask, data); err = st_lsm6dsx_write_with_mask(hw, dec_reg->addr,
if (err < 0) dec_reg->mask, data);
return err; if (err < 0)
return err;
}
sip += sensor->sip; sip += sensor->sip;
} }
hw->sip = sip; hw->sip = sip;
......
...@@ -42,8 +42,6 @@ ...@@ -42,8 +42,6 @@
#include "st_lsm6dsx.h" #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_INT1_ADDR 0x0d
#define ST_LSM6DSX_REG_INT2_ADDR 0x0e #define ST_LSM6DSX_REG_INT2_ADDR 0x0e
#define ST_LSM6DSX_REG_FIFO_FTH_IRQ_MASK BIT(3) #define ST_LSM6DSX_REG_FIFO_FTH_IRQ_MASK BIT(3)
...@@ -160,6 +158,16 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = { ...@@ -160,6 +158,16 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
.id = { .id = {
[0] = ST_LSM6DS3_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, .wai = 0x69,
...@@ -167,6 +175,16 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = { ...@@ -167,6 +175,16 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
.id = { .id = {
[0] = ST_LSM6DS3H_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, .wai = 0x6a,
...@@ -175,6 +193,16 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = { ...@@ -175,6 +193,16 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
[0] = ST_LSM6DSL_ID, [0] = ST_LSM6DSL_ID,
[1] = ST_LSM6DSM_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, ...@@ -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->num_channels = ARRAY_SIZE(st_lsm6dsx_acc_channels);
iio_dev->info = &st_lsm6dsx_acc_info; iio_dev->info = &st_lsm6dsx_acc_info;
sensor->decimator_mask = ST_LSM6DSX_REG_ACC_DEC_MASK;
scnprintf(sensor->name, sizeof(sensor->name), "%s_accel", scnprintf(sensor->name, sizeof(sensor->name), "%s_accel",
name); name);
break; break;
...@@ -654,7 +681,6 @@ static struct iio_dev *st_lsm6dsx_alloc_iiodev(struct st_lsm6dsx_hw *hw, ...@@ -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->num_channels = ARRAY_SIZE(st_lsm6dsx_gyro_channels);
iio_dev->info = &st_lsm6dsx_gyro_info; iio_dev->info = &st_lsm6dsx_gyro_info;
sensor->decimator_mask = ST_LSM6DSX_REG_GYRO_DEC_MASK;
scnprintf(sensor->name, sizeof(sensor->name), "%s_gyro", scnprintf(sensor->name, sizeof(sensor->name), "%s_gyro",
name); name);
break; break;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment