iio: imu: st_lsm6dsx: explicitly define odr table size

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>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
This commit is contained in:
Lorenzo Bianconi 2019-11-03 20:47:17 +01:00 committed by Jonathan Cameron
parent cb7e1b50e4
commit 59af4e2063
3 changed files with 29 additions and 12 deletions

View File

@ -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 {

View File

@ -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;
@ -1709,13 +1724,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;

View File

@ -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';