Commit 44a76de8 authored by Mario Tesi's avatar Mario Tesi Committed by Jonathan Cameron

iio: imu: st_lsm6dsx: Scaling factor type set to IIO_VAL_INT_PLUS_NANO

Scaling factor values for Acc lead to an unacceptable rounding of the
full scale (FS) calculated by some SensorHAL on Android devices. For examples
setting FS to 4g the in_accel_x_scale, in_accel_y_scale and in_accel_z_scale
are 0.001196 on 6 decimal digits and the FS is
0.001196 × ((2^15) − 1) ~= 39.1893 m/s^2.

Android CTS R10 SensorParameterRangeTest test expects a value greater than
39.20 m/s^2 so this test fails (ACCELEROMETER_MAX_RANGE = 4 * 9.80).

Using 9 decimal digits the new scale factor is 0.001196411 and the FS now
is 0.001196411 × ((2^15)−1) ~= 39.2028 m/s^2.

This patch extends to IIO_VAL_INT_PLUS_NANO type the scaling factor to all
IMU devices where SensorParameterRangeTest CTS test fails.
Signed-off-by: default avatarMario Tesi <mario.tesi@st.com>
Acked-by: default avatarLorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
Link: https://lore.kernel.org/r/1600361236-2285-1-git-send-email-martepisa@gmail.com
parent e8173161
...@@ -157,10 +157,10 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = { ...@@ -157,10 +157,10 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
.addr = 0x20, .addr = 0x20,
.mask = GENMASK(4, 3), .mask = GENMASK(4, 3),
}, },
.fs_avl[0] = { IIO_G_TO_M_S_2(61), 0x0 }, .fs_avl[0] = { IIO_G_TO_M_S_2(61000), 0x0 },
.fs_avl[1] = { IIO_G_TO_M_S_2(122), 0x2 }, .fs_avl[1] = { IIO_G_TO_M_S_2(122000), 0x2 },
.fs_avl[2] = { IIO_G_TO_M_S_2(244), 0x3 }, .fs_avl[2] = { IIO_G_TO_M_S_2(244000), 0x3 },
.fs_avl[3] = { IIO_G_TO_M_S_2(732), 0x1 }, .fs_avl[3] = { IIO_G_TO_M_S_2(732000), 0x1 },
.fs_len = 4, .fs_len = 4,
}, },
[ST_LSM6DSX_ID_GYRO] = { [ST_LSM6DSX_ID_GYRO] = {
...@@ -169,9 +169,9 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = { ...@@ -169,9 +169,9 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
.mask = GENMASK(4, 3), .mask = GENMASK(4, 3),
}, },
.fs_avl[0] = { IIO_DEGREE_TO_RAD(8750), 0x0 }, .fs_avl[0] = { IIO_DEGREE_TO_RAD(8750000), 0x0 },
.fs_avl[1] = { IIO_DEGREE_TO_RAD(17500), 0x1 }, .fs_avl[1] = { IIO_DEGREE_TO_RAD(17500000), 0x1 },
.fs_avl[2] = { IIO_DEGREE_TO_RAD(70000), 0x3 }, .fs_avl[2] = { IIO_DEGREE_TO_RAD(70000000), 0x3 },
.fs_len = 3, .fs_len = 3,
}, },
}, },
...@@ -259,10 +259,10 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = { ...@@ -259,10 +259,10 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
.addr = 0x10, .addr = 0x10,
.mask = GENMASK(3, 2), .mask = GENMASK(3, 2),
}, },
.fs_avl[0] = { IIO_G_TO_M_S_2(61), 0x0 }, .fs_avl[0] = { IIO_G_TO_M_S_2(61000), 0x0 },
.fs_avl[1] = { IIO_G_TO_M_S_2(122), 0x2 }, .fs_avl[1] = { IIO_G_TO_M_S_2(122000), 0x2 },
.fs_avl[2] = { IIO_G_TO_M_S_2(244), 0x3 }, .fs_avl[2] = { IIO_G_TO_M_S_2(244000), 0x3 },
.fs_avl[3] = { IIO_G_TO_M_S_2(488), 0x1 }, .fs_avl[3] = { IIO_G_TO_M_S_2(488000), 0x1 },
.fs_len = 4, .fs_len = 4,
}, },
[ST_LSM6DSX_ID_GYRO] = { [ST_LSM6DSX_ID_GYRO] = {
...@@ -270,10 +270,10 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = { ...@@ -270,10 +270,10 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
.addr = 0x11, .addr = 0x11,
.mask = GENMASK(3, 2), .mask = GENMASK(3, 2),
}, },
.fs_avl[0] = { IIO_DEGREE_TO_RAD(8750), 0x0 }, .fs_avl[0] = { IIO_DEGREE_TO_RAD(8750000), 0x0 },
.fs_avl[1] = { IIO_DEGREE_TO_RAD(17500), 0x1 }, .fs_avl[1] = { IIO_DEGREE_TO_RAD(17500000), 0x1 },
.fs_avl[2] = { IIO_DEGREE_TO_RAD(35000), 0x2 }, .fs_avl[2] = { IIO_DEGREE_TO_RAD(35000000), 0x2 },
.fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 }, .fs_avl[3] = { IIO_DEGREE_TO_RAD(70000000), 0x3 },
.fs_len = 4, .fs_len = 4,
}, },
}, },
...@@ -425,10 +425,10 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = { ...@@ -425,10 +425,10 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
.addr = 0x10, .addr = 0x10,
.mask = GENMASK(3, 2), .mask = GENMASK(3, 2),
}, },
.fs_avl[0] = { IIO_G_TO_M_S_2(61), 0x0 }, .fs_avl[0] = { IIO_G_TO_M_S_2(61000), 0x0 },
.fs_avl[1] = { IIO_G_TO_M_S_2(122), 0x2 }, .fs_avl[1] = { IIO_G_TO_M_S_2(122000), 0x2 },
.fs_avl[2] = { IIO_G_TO_M_S_2(244), 0x3 }, .fs_avl[2] = { IIO_G_TO_M_S_2(244000), 0x3 },
.fs_avl[3] = { IIO_G_TO_M_S_2(488), 0x1 }, .fs_avl[3] = { IIO_G_TO_M_S_2(488000), 0x1 },
.fs_len = 4, .fs_len = 4,
}, },
[ST_LSM6DSX_ID_GYRO] = { [ST_LSM6DSX_ID_GYRO] = {
...@@ -436,10 +436,10 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = { ...@@ -436,10 +436,10 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
.addr = 0x11, .addr = 0x11,
.mask = GENMASK(3, 2), .mask = GENMASK(3, 2),
}, },
.fs_avl[0] = { IIO_DEGREE_TO_RAD(8750), 0x0 }, .fs_avl[0] = { IIO_DEGREE_TO_RAD(8750000), 0x0 },
.fs_avl[1] = { IIO_DEGREE_TO_RAD(17500), 0x1 }, .fs_avl[1] = { IIO_DEGREE_TO_RAD(17500000), 0x1 },
.fs_avl[2] = { IIO_DEGREE_TO_RAD(35000), 0x2 }, .fs_avl[2] = { IIO_DEGREE_TO_RAD(35000000), 0x2 },
.fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 }, .fs_avl[3] = { IIO_DEGREE_TO_RAD(70000000), 0x3 },
.fs_len = 4, .fs_len = 4,
}, },
}, },
...@@ -600,10 +600,10 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = { ...@@ -600,10 +600,10 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
.addr = 0x10, .addr = 0x10,
.mask = GENMASK(3, 2), .mask = GENMASK(3, 2),
}, },
.fs_avl[0] = { IIO_G_TO_M_S_2(61), 0x0 }, .fs_avl[0] = { IIO_G_TO_M_S_2(61000), 0x0 },
.fs_avl[1] = { IIO_G_TO_M_S_2(122), 0x2 }, .fs_avl[1] = { IIO_G_TO_M_S_2(122000), 0x2 },
.fs_avl[2] = { IIO_G_TO_M_S_2(244), 0x3 }, .fs_avl[2] = { IIO_G_TO_M_S_2(244000), 0x3 },
.fs_avl[3] = { IIO_G_TO_M_S_2(488), 0x1 }, .fs_avl[3] = { IIO_G_TO_M_S_2(488000), 0x1 },
.fs_len = 4, .fs_len = 4,
}, },
[ST_LSM6DSX_ID_GYRO] = { [ST_LSM6DSX_ID_GYRO] = {
...@@ -611,10 +611,10 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = { ...@@ -611,10 +611,10 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
.addr = 0x11, .addr = 0x11,
.mask = GENMASK(3, 2), .mask = GENMASK(3, 2),
}, },
.fs_avl[0] = { IIO_DEGREE_TO_RAD(8750), 0x0 }, .fs_avl[0] = { IIO_DEGREE_TO_RAD(8750000), 0x0 },
.fs_avl[1] = { IIO_DEGREE_TO_RAD(17500), 0x1 }, .fs_avl[1] = { IIO_DEGREE_TO_RAD(17500000), 0x1 },
.fs_avl[2] = { IIO_DEGREE_TO_RAD(35000), 0x2 }, .fs_avl[2] = { IIO_DEGREE_TO_RAD(35000000), 0x2 },
.fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 }, .fs_avl[3] = { IIO_DEGREE_TO_RAD(70000000), 0x3 },
.fs_len = 4, .fs_len = 4,
}, },
}, },
...@@ -816,10 +816,10 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = { ...@@ -816,10 +816,10 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
.addr = 0x10, .addr = 0x10,
.mask = GENMASK(3, 2), .mask = GENMASK(3, 2),
}, },
.fs_avl[0] = { IIO_G_TO_M_S_2(61), 0x0 }, .fs_avl[0] = { IIO_G_TO_M_S_2(61000), 0x0 },
.fs_avl[1] = { IIO_G_TO_M_S_2(122), 0x2 }, .fs_avl[1] = { IIO_G_TO_M_S_2(122000), 0x2 },
.fs_avl[2] = { IIO_G_TO_M_S_2(244), 0x3 }, .fs_avl[2] = { IIO_G_TO_M_S_2(244000), 0x3 },
.fs_avl[3] = { IIO_G_TO_M_S_2(488), 0x1 }, .fs_avl[3] = { IIO_G_TO_M_S_2(488000), 0x1 },
.fs_len = 4, .fs_len = 4,
}, },
[ST_LSM6DSX_ID_GYRO] = { [ST_LSM6DSX_ID_GYRO] = {
...@@ -827,10 +827,10 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = { ...@@ -827,10 +827,10 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
.addr = 0x11, .addr = 0x11,
.mask = GENMASK(3, 2), .mask = GENMASK(3, 2),
}, },
.fs_avl[0] = { IIO_DEGREE_TO_RAD(8750), 0x0 }, .fs_avl[0] = { IIO_DEGREE_TO_RAD(8750000), 0x0 },
.fs_avl[1] = { IIO_DEGREE_TO_RAD(17500), 0x1 }, .fs_avl[1] = { IIO_DEGREE_TO_RAD(17500000), 0x1 },
.fs_avl[2] = { IIO_DEGREE_TO_RAD(35000), 0x2 }, .fs_avl[2] = { IIO_DEGREE_TO_RAD(35000000), 0x2 },
.fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 }, .fs_avl[3] = { IIO_DEGREE_TO_RAD(70000000), 0x3 },
.fs_len = 4, .fs_len = 4,
}, },
}, },
...@@ -1021,10 +1021,10 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = { ...@@ -1021,10 +1021,10 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
.addr = 0x10, .addr = 0x10,
.mask = GENMASK(3, 2), .mask = GENMASK(3, 2),
}, },
.fs_avl[0] = { IIO_G_TO_M_S_2(61), 0x0 }, .fs_avl[0] = { IIO_G_TO_M_S_2(61000), 0x0 },
.fs_avl[1] = { IIO_G_TO_M_S_2(122), 0x2 }, .fs_avl[1] = { IIO_G_TO_M_S_2(122000), 0x2 },
.fs_avl[2] = { IIO_G_TO_M_S_2(244), 0x3 }, .fs_avl[2] = { IIO_G_TO_M_S_2(244000), 0x3 },
.fs_avl[3] = { IIO_G_TO_M_S_2(488), 0x1 }, .fs_avl[3] = { IIO_G_TO_M_S_2(488000), 0x1 },
.fs_len = 4, .fs_len = 4,
}, },
[ST_LSM6DSX_ID_GYRO] = { [ST_LSM6DSX_ID_GYRO] = {
...@@ -1032,10 +1032,10 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = { ...@@ -1032,10 +1032,10 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
.addr = 0x11, .addr = 0x11,
.mask = GENMASK(3, 2), .mask = GENMASK(3, 2),
}, },
.fs_avl[0] = { IIO_DEGREE_TO_RAD(8750), 0x0 }, .fs_avl[0] = { IIO_DEGREE_TO_RAD(8750000), 0x0 },
.fs_avl[1] = { IIO_DEGREE_TO_RAD(17500), 0x1 }, .fs_avl[1] = { IIO_DEGREE_TO_RAD(17500000), 0x1 },
.fs_avl[2] = { IIO_DEGREE_TO_RAD(35000), 0x2 }, .fs_avl[2] = { IIO_DEGREE_TO_RAD(35000000), 0x2 },
.fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 }, .fs_avl[3] = { IIO_DEGREE_TO_RAD(70000000), 0x3 },
.fs_len = 4, .fs_len = 4,
}, },
}, },
...@@ -1200,10 +1200,10 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = { ...@@ -1200,10 +1200,10 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
.addr = 0x10, .addr = 0x10,
.mask = GENMASK(3, 2), .mask = GENMASK(3, 2),
}, },
.fs_avl[0] = { IIO_G_TO_M_S_2(61), 0x0 }, .fs_avl[0] = { IIO_G_TO_M_S_2(61000), 0x0 },
.fs_avl[1] = { IIO_G_TO_M_S_2(122), 0x2 }, .fs_avl[1] = { IIO_G_TO_M_S_2(122000), 0x2 },
.fs_avl[2] = { IIO_G_TO_M_S_2(244), 0x3 }, .fs_avl[2] = { IIO_G_TO_M_S_2(244000), 0x3 },
.fs_avl[3] = { IIO_G_TO_M_S_2(488), 0x1 }, .fs_avl[3] = { IIO_G_TO_M_S_2(488000), 0x1 },
.fs_len = 4, .fs_len = 4,
}, },
[ST_LSM6DSX_ID_GYRO] = { [ST_LSM6DSX_ID_GYRO] = {
...@@ -1211,10 +1211,10 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = { ...@@ -1211,10 +1211,10 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
.addr = 0x11, .addr = 0x11,
.mask = GENMASK(3, 2), .mask = GENMASK(3, 2),
}, },
.fs_avl[0] = { IIO_DEGREE_TO_RAD(8750), 0x0 }, .fs_avl[0] = { IIO_DEGREE_TO_RAD(8750000), 0x0 },
.fs_avl[1] = { IIO_DEGREE_TO_RAD(17500), 0x1 }, .fs_avl[1] = { IIO_DEGREE_TO_RAD(17500000), 0x1 },
.fs_avl[2] = { IIO_DEGREE_TO_RAD(35000), 0x2 }, .fs_avl[2] = { IIO_DEGREE_TO_RAD(35000000), 0x2 },
.fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 }, .fs_avl[3] = { IIO_DEGREE_TO_RAD(70000000), 0x3 },
.fs_len = 4, .fs_len = 4,
}, },
}, },
...@@ -1598,7 +1598,7 @@ static int st_lsm6dsx_read_raw(struct iio_dev *iio_dev, ...@@ -1598,7 +1598,7 @@ static int st_lsm6dsx_read_raw(struct iio_dev *iio_dev,
case IIO_CHAN_INFO_SCALE: case IIO_CHAN_INFO_SCALE:
*val = 0; *val = 0;
*val2 = sensor->gain; *val2 = sensor->gain;
ret = IIO_VAL_INT_PLUS_MICRO; ret = IIO_VAL_INT_PLUS_NANO;
break; break;
default: default:
ret = -EINVAL; ret = -EINVAL;
...@@ -1836,13 +1836,31 @@ static ssize_t st_lsm6dsx_sysfs_scale_avail(struct device *dev, ...@@ -1836,13 +1836,31 @@ static ssize_t st_lsm6dsx_sysfs_scale_avail(struct device *dev,
fs_table = &hw->settings->fs_table[sensor->id]; fs_table = &hw->settings->fs_table[sensor->id];
for (i = 0; i < fs_table->fs_len; i++) for (i = 0; i < fs_table->fs_len; i++)
len += scnprintf(buf + len, PAGE_SIZE - len, "0.%06u ", len += scnprintf(buf + len, PAGE_SIZE - len, "0.%09u ",
fs_table->fs_avl[i].gain); fs_table->fs_avl[i].gain);
buf[len - 1] = '\n'; buf[len - 1] = '\n';
return len; return len;
} }
static int st_lsm6dsx_write_raw_get_fmt(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
long mask)
{
switch (mask) {
case IIO_CHAN_INFO_SCALE:
switch (chan->type) {
case IIO_ANGL_VEL:
case IIO_ACCEL:
return IIO_VAL_INT_PLUS_NANO;
default:
return IIO_VAL_INT_PLUS_MICRO;
}
default:
return IIO_VAL_INT_PLUS_MICRO;
}
}
static IIO_DEV_ATTR_SAMP_FREQ_AVAIL(st_lsm6dsx_sysfs_sampling_frequency_avail); static IIO_DEV_ATTR_SAMP_FREQ_AVAIL(st_lsm6dsx_sysfs_sampling_frequency_avail);
static IIO_DEVICE_ATTR(in_accel_scale_available, 0444, static IIO_DEVICE_ATTR(in_accel_scale_available, 0444,
st_lsm6dsx_sysfs_scale_avail, NULL, 0); st_lsm6dsx_sysfs_scale_avail, NULL, 0);
...@@ -1868,6 +1886,7 @@ static const struct iio_info st_lsm6dsx_acc_info = { ...@@ -1868,6 +1886,7 @@ static const struct iio_info st_lsm6dsx_acc_info = {
.read_event_config = st_lsm6dsx_read_event_config, .read_event_config = st_lsm6dsx_read_event_config,
.write_event_config = st_lsm6dsx_write_event_config, .write_event_config = st_lsm6dsx_write_event_config,
.hwfifo_set_watermark = st_lsm6dsx_set_watermark, .hwfifo_set_watermark = st_lsm6dsx_set_watermark,
.write_raw_get_fmt = st_lsm6dsx_write_raw_get_fmt,
}; };
static struct attribute *st_lsm6dsx_gyro_attributes[] = { static struct attribute *st_lsm6dsx_gyro_attributes[] = {
...@@ -1885,6 +1904,7 @@ static const struct iio_info st_lsm6dsx_gyro_info = { ...@@ -1885,6 +1904,7 @@ static const struct iio_info st_lsm6dsx_gyro_info = {
.read_raw = st_lsm6dsx_read_raw, .read_raw = st_lsm6dsx_read_raw,
.write_raw = st_lsm6dsx_write_raw, .write_raw = st_lsm6dsx_write_raw,
.hwfifo_set_watermark = st_lsm6dsx_set_watermark, .hwfifo_set_watermark = st_lsm6dsx_set_watermark,
.write_raw_get_fmt = st_lsm6dsx_write_raw_get_fmt,
}; };
static int st_lsm6dsx_get_drdy_pin(struct st_lsm6dsx_hw *hw, int *drdy_pin) static int st_lsm6dsx_get_drdy_pin(struct st_lsm6dsx_hw *hw, int *drdy_pin)
......
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