Commit 85ae3aee authored by Lorenzo Bianconi's avatar Lorenzo Bianconi Committed by Jonathan Cameron

iio: imu: st_lsm6dsx: forbid 0 sensor sensitivity

Do not allow configuring null sensor gain since it will force to 0
device outputs

Fixes: c8d4066c7246 ("iio: imu: st_lsm6dsx: remove invalid gain value for LSM9DS1")
Signed-off-by: default avatarLorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent de10ac47
...@@ -99,7 +99,9 @@ struct st_lsm6dsx_fs { ...@@ -99,7 +99,9 @@ struct st_lsm6dsx_fs {
#define ST_LSM6DSX_FS_LIST_SIZE 4 #define ST_LSM6DSX_FS_LIST_SIZE 4
struct st_lsm6dsx_fs_table_entry { struct st_lsm6dsx_fs_table_entry {
struct st_lsm6dsx_reg reg; struct st_lsm6dsx_reg reg;
struct st_lsm6dsx_fs fs_avl[ST_LSM6DSX_FS_LIST_SIZE]; struct st_lsm6dsx_fs fs_avl[ST_LSM6DSX_FS_LIST_SIZE];
int fs_len;
}; };
/** /**
......
...@@ -145,6 +145,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = { ...@@ -145,6 +145,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
.fs_avl[1] = { IIO_G_TO_M_S_2(122), 0x2 }, .fs_avl[1] = { IIO_G_TO_M_S_2(122), 0x2 },
.fs_avl[2] = { IIO_G_TO_M_S_2(244), 0x3 }, .fs_avl[2] = { IIO_G_TO_M_S_2(244), 0x3 },
.fs_avl[3] = { IIO_G_TO_M_S_2(732), 0x1 }, .fs_avl[3] = { IIO_G_TO_M_S_2(732), 0x1 },
.fs_len = 4,
}, },
[ST_LSM6DSX_ID_GYRO] = { [ST_LSM6DSX_ID_GYRO] = {
.reg = { .reg = {
...@@ -154,6 +155,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = { ...@@ -154,6 +155,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
.fs_avl[0] = { IIO_DEGREE_TO_RAD(245), 0x0 }, .fs_avl[0] = { IIO_DEGREE_TO_RAD(245), 0x0 },
.fs_avl[1] = { IIO_DEGREE_TO_RAD(500), 0x1 }, .fs_avl[1] = { IIO_DEGREE_TO_RAD(500), 0x1 },
.fs_avl[2] = { IIO_DEGREE_TO_RAD(2000), 0x3 }, .fs_avl[2] = { IIO_DEGREE_TO_RAD(2000), 0x3 },
.fs_len = 3,
}, },
}, },
}, },
...@@ -215,6 +217,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = { ...@@ -215,6 +217,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
.fs_avl[1] = { IIO_G_TO_M_S_2(122), 0x2 }, .fs_avl[1] = { IIO_G_TO_M_S_2(122), 0x2 },
.fs_avl[2] = { IIO_G_TO_M_S_2(244), 0x3 }, .fs_avl[2] = { IIO_G_TO_M_S_2(244), 0x3 },
.fs_avl[3] = { IIO_G_TO_M_S_2(488), 0x1 }, .fs_avl[3] = { IIO_G_TO_M_S_2(488), 0x1 },
.fs_len = 4,
}, },
[ST_LSM6DSX_ID_GYRO] = { [ST_LSM6DSX_ID_GYRO] = {
.reg = { .reg = {
...@@ -225,6 +228,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = { ...@@ -225,6 +228,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
.fs_avl[1] = { IIO_DEGREE_TO_RAD(17500), 0x1 }, .fs_avl[1] = { IIO_DEGREE_TO_RAD(17500), 0x1 },
.fs_avl[2] = { IIO_DEGREE_TO_RAD(35000), 0x2 }, .fs_avl[2] = { IIO_DEGREE_TO_RAD(35000), 0x2 },
.fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 }, .fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 },
.fs_len = 4,
}, },
}, },
.decimator = { .decimator = {
...@@ -327,6 +331,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = { ...@@ -327,6 +331,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
.fs_avl[1] = { IIO_G_TO_M_S_2(122), 0x2 }, .fs_avl[1] = { IIO_G_TO_M_S_2(122), 0x2 },
.fs_avl[2] = { IIO_G_TO_M_S_2(244), 0x3 }, .fs_avl[2] = { IIO_G_TO_M_S_2(244), 0x3 },
.fs_avl[3] = { IIO_G_TO_M_S_2(488), 0x1 }, .fs_avl[3] = { IIO_G_TO_M_S_2(488), 0x1 },
.fs_len = 4,
}, },
[ST_LSM6DSX_ID_GYRO] = { [ST_LSM6DSX_ID_GYRO] = {
.reg = { .reg = {
...@@ -337,6 +342,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = { ...@@ -337,6 +342,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
.fs_avl[1] = { IIO_DEGREE_TO_RAD(17500), 0x1 }, .fs_avl[1] = { IIO_DEGREE_TO_RAD(17500), 0x1 },
.fs_avl[2] = { IIO_DEGREE_TO_RAD(35000), 0x2 }, .fs_avl[2] = { IIO_DEGREE_TO_RAD(35000), 0x2 },
.fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 }, .fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 },
.fs_len = 4,
}, },
}, },
.decimator = { .decimator = {
...@@ -448,6 +454,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = { ...@@ -448,6 +454,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
.fs_avl[1] = { IIO_G_TO_M_S_2(122), 0x2 }, .fs_avl[1] = { IIO_G_TO_M_S_2(122), 0x2 },
.fs_avl[2] = { IIO_G_TO_M_S_2(244), 0x3 }, .fs_avl[2] = { IIO_G_TO_M_S_2(244), 0x3 },
.fs_avl[3] = { IIO_G_TO_M_S_2(488), 0x1 }, .fs_avl[3] = { IIO_G_TO_M_S_2(488), 0x1 },
.fs_len = 4,
}, },
[ST_LSM6DSX_ID_GYRO] = { [ST_LSM6DSX_ID_GYRO] = {
.reg = { .reg = {
...@@ -458,6 +465,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = { ...@@ -458,6 +465,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
.fs_avl[1] = { IIO_DEGREE_TO_RAD(17500), 0x1 }, .fs_avl[1] = { IIO_DEGREE_TO_RAD(17500), 0x1 },
.fs_avl[2] = { IIO_DEGREE_TO_RAD(35000), 0x2 }, .fs_avl[2] = { IIO_DEGREE_TO_RAD(35000), 0x2 },
.fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 }, .fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 },
.fs_len = 4,
}, },
}, },
.decimator = { .decimator = {
...@@ -563,6 +571,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = { ...@@ -563,6 +571,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
.fs_avl[1] = { IIO_G_TO_M_S_2(122), 0x2 }, .fs_avl[1] = { IIO_G_TO_M_S_2(122), 0x2 },
.fs_avl[2] = { IIO_G_TO_M_S_2(244), 0x3 }, .fs_avl[2] = { IIO_G_TO_M_S_2(244), 0x3 },
.fs_avl[3] = { IIO_G_TO_M_S_2(488), 0x1 }, .fs_avl[3] = { IIO_G_TO_M_S_2(488), 0x1 },
.fs_len = 4,
}, },
[ST_LSM6DSX_ID_GYRO] = { [ST_LSM6DSX_ID_GYRO] = {
.reg = { .reg = {
...@@ -573,6 +582,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = { ...@@ -573,6 +582,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
.fs_avl[1] = { IIO_DEGREE_TO_RAD(17500), 0x1 }, .fs_avl[1] = { IIO_DEGREE_TO_RAD(17500), 0x1 },
.fs_avl[2] = { IIO_DEGREE_TO_RAD(35000), 0x2 }, .fs_avl[2] = { IIO_DEGREE_TO_RAD(35000), 0x2 },
.fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 }, .fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 },
.fs_len = 4,
}, },
}, },
.batch = { .batch = {
...@@ -693,6 +703,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = { ...@@ -693,6 +703,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
.fs_avl[1] = { IIO_G_TO_M_S_2(122), 0x2 }, .fs_avl[1] = { IIO_G_TO_M_S_2(122), 0x2 },
.fs_avl[2] = { IIO_G_TO_M_S_2(244), 0x3 }, .fs_avl[2] = { IIO_G_TO_M_S_2(244), 0x3 },
.fs_avl[3] = { IIO_G_TO_M_S_2(488), 0x1 }, .fs_avl[3] = { IIO_G_TO_M_S_2(488), 0x1 },
.fs_len = 4,
}, },
[ST_LSM6DSX_ID_GYRO] = { [ST_LSM6DSX_ID_GYRO] = {
.reg = { .reg = {
...@@ -703,6 +714,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = { ...@@ -703,6 +714,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
.fs_avl[1] = { IIO_DEGREE_TO_RAD(17500), 0x1 }, .fs_avl[1] = { IIO_DEGREE_TO_RAD(17500), 0x1 },
.fs_avl[2] = { IIO_DEGREE_TO_RAD(35000), 0x2 }, .fs_avl[2] = { IIO_DEGREE_TO_RAD(35000), 0x2 },
.fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 }, .fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 },
.fs_len = 4,
}, },
}, },
.batch = { .batch = {
...@@ -800,6 +812,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = { ...@@ -800,6 +812,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
.fs_avl[1] = { IIO_G_TO_M_S_2(122), 0x2 }, .fs_avl[1] = { IIO_G_TO_M_S_2(122), 0x2 },
.fs_avl[2] = { IIO_G_TO_M_S_2(244), 0x3 }, .fs_avl[2] = { IIO_G_TO_M_S_2(244), 0x3 },
.fs_avl[3] = { IIO_G_TO_M_S_2(488), 0x1 }, .fs_avl[3] = { IIO_G_TO_M_S_2(488), 0x1 },
.fs_len = 4,
}, },
[ST_LSM6DSX_ID_GYRO] = { [ST_LSM6DSX_ID_GYRO] = {
.reg = { .reg = {
...@@ -810,6 +823,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = { ...@@ -810,6 +823,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
.fs_avl[1] = { IIO_DEGREE_TO_RAD(17500), 0x1 }, .fs_avl[1] = { IIO_DEGREE_TO_RAD(17500), 0x1 },
.fs_avl[2] = { IIO_DEGREE_TO_RAD(35000), 0x2 }, .fs_avl[2] = { IIO_DEGREE_TO_RAD(35000), 0x2 },
.fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 }, .fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 },
.fs_len = 4,
}, },
}, },
.batch = { .batch = {
...@@ -933,11 +947,12 @@ static int st_lsm6dsx_set_full_scale(struct st_lsm6dsx_sensor *sensor, ...@@ -933,11 +947,12 @@ static int st_lsm6dsx_set_full_scale(struct st_lsm6dsx_sensor *sensor,
int i, err; int i, err;
fs_table = &sensor->hw->settings->fs_table[sensor->id]; fs_table = &sensor->hw->settings->fs_table[sensor->id];
for (i = 0; i < ST_LSM6DSX_FS_LIST_SIZE; i++) for (i = 0; i < fs_table->fs_len; i++) {
if (fs_table->fs_avl[i].gain == gain) if (fs_table->fs_avl[i].gain == gain)
break; break;
}
if (i == ST_LSM6DSX_FS_LIST_SIZE) if (i == fs_table->fs_len)
return -EINVAL; return -EINVAL;
data = ST_LSM6DSX_SHIFT_VAL(fs_table->fs_avl[i].val, data = ST_LSM6DSX_SHIFT_VAL(fs_table->fs_avl[i].val,
...@@ -1196,18 +1211,13 @@ static ssize_t st_lsm6dsx_sysfs_scale_avail(struct device *dev, ...@@ -1196,18 +1211,13 @@ static ssize_t st_lsm6dsx_sysfs_scale_avail(struct device *dev,
{ {
struct st_lsm6dsx_sensor *sensor = iio_priv(dev_get_drvdata(dev)); struct st_lsm6dsx_sensor *sensor = iio_priv(dev_get_drvdata(dev));
const struct st_lsm6dsx_fs_table_entry *fs_table; const struct st_lsm6dsx_fs_table_entry *fs_table;
enum st_lsm6dsx_sensor_id id = sensor->id;
struct st_lsm6dsx_hw *hw = sensor->hw; struct st_lsm6dsx_hw *hw = sensor->hw;
int i, len = 0; int i, len = 0;
fs_table = &hw->settings->fs_table[id]; fs_table = &hw->settings->fs_table[sensor->id];
for (i = 0; i < ST_LSM6DSX_FS_LIST_SIZE; i++) { for (i = 0; i < fs_table->fs_len; i++)
if (!fs_table->fs_avl[i].gain)
break;
len += scnprintf(buf + len, PAGE_SIZE - len, "0.%06u ", len += scnprintf(buf + len, PAGE_SIZE - len, "0.%06u ",
fs_table->fs_avl[i].gain); fs_table->fs_avl[i].gain);
}
buf[len - 1] = '\n'; buf[len - 1] = '\n';
return len; return len;
......
...@@ -61,6 +61,7 @@ static const struct st_lsm6dsx_ext_dev_settings st_lsm6dsx_ext_dev_table[] = { ...@@ -61,6 +61,7 @@ static const struct st_lsm6dsx_ext_dev_settings st_lsm6dsx_ext_dev_table[] = {
.gain = 1500, .gain = 1500,
.val = 0x0, .val = 0x0,
}, /* 1500 uG/LSB */ }, /* 1500 uG/LSB */
.fs_len = 1,
}, },
.temp_comp = { .temp_comp = {
.addr = 0x60, .addr = 0x60,
...@@ -555,13 +556,9 @@ static ssize_t st_lsm6dsx_shub_scale_avail(struct device *dev, ...@@ -555,13 +556,9 @@ static ssize_t st_lsm6dsx_shub_scale_avail(struct device *dev,
int i, len = 0; int i, len = 0;
settings = sensor->ext_info.settings; settings = sensor->ext_info.settings;
for (i = 0; i < ST_LSM6DSX_FS_LIST_SIZE; i++) { for (i = 0; i < settings->fs_table.fs_len; i++)
u16 val = settings->fs_table.fs_avl[i].gain;
if (val > 0)
len += scnprintf(buf + len, PAGE_SIZE - len, "0.%06u ", len += scnprintf(buf + len, PAGE_SIZE - len, "0.%06u ",
val); settings->fs_table.fs_avl[i].gain);
}
buf[len - 1] = '\n'; buf[len - 1] = '\n';
return len; return len;
......
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