Re: [PATCH] iio: imu: st_lsm6dsx: Scaling factor type set to IIO_VAL_INT_PLUS_NANO

From: Lorenzo Bianconi
Date: Thu Sep 17 2020 - 04:07:48 EST


> From: Mario Tesi <mario.tesi@xxxxxx>
>
> 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: Mario Tesi <mario.tesi@xxxxxx>

Hi Mario,

just a minor comment inline. Fixing it:

Acked-by: Lorenzo Bianconi <lorenzo@xxxxxxxxxx>

> ---
> drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 136 ++++++++++++++++-----------
> 1 file changed, 79 insertions(+), 57 deletions(-)
>

[...]

> fs_table = &hw->settings->fs_table[sensor->id];
> 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);
> buf[len - 1] = '\n';
>
> 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;
> + }
> +
> + return -EINVAL;

you can remove this

> +}
> +
> static IIO_DEV_ATTR_SAMP_FREQ_AVAIL(st_lsm6dsx_sysfs_sampling_frequency_avail);
> static IIO_DEVICE_ATTR(in_accel_scale_available, 0444,
> st_lsm6dsx_sysfs_scale_avail, NULL, 0);
> @@ -1868,6 +1888,7 @@ static const struct iio_info st_lsm6dsx_acc_info = {
> .read_event_config = st_lsm6dsx_read_event_config,
> .write_event_config = st_lsm6dsx_write_event_config,
> .hwfifo_set_watermark = st_lsm6dsx_set_watermark,
> + .write_raw_get_fmt = st_lsm6dsx_write_raw_get_fmt,
> };
>
> static struct attribute *st_lsm6dsx_gyro_attributes[] = {
> @@ -1885,6 +1906,7 @@ static const struct iio_info st_lsm6dsx_gyro_info = {
> .read_raw = st_lsm6dsx_read_raw,
> .write_raw = st_lsm6dsx_write_raw,
> .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)
> --
> 2.7.4
>

Attachment: signature.asc
Description: PGP signature