linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Mario Tesi <martepisa@gmail.com>
Cc: lorenzo.bianconi83@gmail.com, knaack.h@gmx.de, lars@metafoo.de,
	pmeerw@pmeerw.net, linux-iio@vger.kernel.org,
	linux-kernel@vger.kernel.org, mario.tesi@st.com
Subject: Re: [PATCH] iio: imu: st_lsm6dsx: Scaling factor type set to IIO_VAL_INT_PLUS_NANO
Date: Sat, 19 Sep 2020 14:30:20 +0100	[thread overview]
Message-ID: <20200919143020.53df1f3f@archlinux> (raw)
In-Reply-To: <1600361236-2285-1-git-send-email-martepisa@gmail.com>

On Thu, 17 Sep 2020 18:47:16 +0200
Mario Tesi <martepisa@gmail.com> wrote:

> From: Mario Tesi <mario.tesi@st.com>
> 
> 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@st.com>
Is this v2?  If so where is the change log?
Thankfully wasn't too hard to spot the difference and you were fixing what
Lorenzo was pointing out in v1.

Also, should have picked up Lorenzo's tag from v1 as you have fixed
what he asked you to fix before applying it.

Anyhow, stuff to get right next time.

Applied to the togreg branch of iio.git and pushed out as testing for
the autobuilders to play with it.

Thanks,

Jonathan


	

> ---
>  drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 134 +++++++++++++++------------
>  1 file changed, 77 insertions(+), 57 deletions(-)
> 
> diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> index 346c242..42f4856 100644
> --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> @@ -157,10 +157,10 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>  					.addr = 0x20,
>  					.mask = GENMASK(4, 3),
>  				},
> -				.fs_avl[0] = {  IIO_G_TO_M_S_2(61), 0x0 },
> -				.fs_avl[1] = { IIO_G_TO_M_S_2(122), 0x2 },
> -				.fs_avl[2] = { IIO_G_TO_M_S_2(244), 0x3 },
> -				.fs_avl[3] = { IIO_G_TO_M_S_2(732), 0x1 },
> +				.fs_avl[0] = {  IIO_G_TO_M_S_2(61000), 0x0 },
> +				.fs_avl[1] = { IIO_G_TO_M_S_2(122000), 0x2 },
> +				.fs_avl[2] = { IIO_G_TO_M_S_2(244000), 0x3 },
> +				.fs_avl[3] = { IIO_G_TO_M_S_2(732000), 0x1 },
>  				.fs_len = 4,
>  			},
>  			[ST_LSM6DSX_ID_GYRO] = {
> @@ -169,9 +169,9 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>  					.mask = GENMASK(4, 3),
>  				},
>  
> -				.fs_avl[0] = {  IIO_DEGREE_TO_RAD(8750), 0x0 },
> -				.fs_avl[1] = { IIO_DEGREE_TO_RAD(17500), 0x1 },
> -				.fs_avl[2] = { IIO_DEGREE_TO_RAD(70000), 0x3 },
> +				.fs_avl[0] = {  IIO_DEGREE_TO_RAD(8750000), 0x0 },
> +				.fs_avl[1] = { IIO_DEGREE_TO_RAD(17500000), 0x1 },
> +				.fs_avl[2] = { IIO_DEGREE_TO_RAD(70000000), 0x3 },
>  				.fs_len = 3,
>  			},
>  		},
> @@ -259,10 +259,10 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>  					.addr = 0x10,
>  					.mask = GENMASK(3, 2),
>  				},
> -				.fs_avl[0] = {  IIO_G_TO_M_S_2(61), 0x0 },
> -				.fs_avl[1] = { IIO_G_TO_M_S_2(122), 0x2 },
> -				.fs_avl[2] = { IIO_G_TO_M_S_2(244), 0x3 },
> -				.fs_avl[3] = { IIO_G_TO_M_S_2(488), 0x1 },
> +				.fs_avl[0] = {  IIO_G_TO_M_S_2(61000), 0x0 },
> +				.fs_avl[1] = { IIO_G_TO_M_S_2(122000), 0x2 },
> +				.fs_avl[2] = { IIO_G_TO_M_S_2(244000), 0x3 },
> +				.fs_avl[3] = { IIO_G_TO_M_S_2(488000), 0x1 },
>  				.fs_len = 4,
>  			},
>  			[ST_LSM6DSX_ID_GYRO] = {
> @@ -270,10 +270,10 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>  					.addr = 0x11,
>  					.mask = GENMASK(3, 2),
>  				},
> -				.fs_avl[0] = {  IIO_DEGREE_TO_RAD(8750), 0x0 },
> -				.fs_avl[1] = { IIO_DEGREE_TO_RAD(17500), 0x1 },
> -				.fs_avl[2] = { IIO_DEGREE_TO_RAD(35000), 0x2 },
> -				.fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 },
> +				.fs_avl[0] = {  IIO_DEGREE_TO_RAD(8750000), 0x0 },
> +				.fs_avl[1] = { IIO_DEGREE_TO_RAD(17500000), 0x1 },
> +				.fs_avl[2] = { IIO_DEGREE_TO_RAD(35000000), 0x2 },
> +				.fs_avl[3] = { IIO_DEGREE_TO_RAD(70000000), 0x3 },
>  				.fs_len = 4,
>  			},
>  		},
> @@ -425,10 +425,10 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>  					.addr = 0x10,
>  					.mask = GENMASK(3, 2),
>  				},
> -				.fs_avl[0] = {  IIO_G_TO_M_S_2(61), 0x0 },
> -				.fs_avl[1] = { IIO_G_TO_M_S_2(122), 0x2 },
> -				.fs_avl[2] = { IIO_G_TO_M_S_2(244), 0x3 },
> -				.fs_avl[3] = { IIO_G_TO_M_S_2(488), 0x1 },
> +				.fs_avl[0] = {  IIO_G_TO_M_S_2(61000), 0x0 },
> +				.fs_avl[1] = { IIO_G_TO_M_S_2(122000), 0x2 },
> +				.fs_avl[2] = { IIO_G_TO_M_S_2(244000), 0x3 },
> +				.fs_avl[3] = { IIO_G_TO_M_S_2(488000), 0x1 },
>  				.fs_len = 4,
>  			},
>  			[ST_LSM6DSX_ID_GYRO] = {
> @@ -436,10 +436,10 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>  					.addr = 0x11,
>  					.mask = GENMASK(3, 2),
>  				},
> -				.fs_avl[0] = {  IIO_DEGREE_TO_RAD(8750), 0x0 },
> -				.fs_avl[1] = { IIO_DEGREE_TO_RAD(17500), 0x1 },
> -				.fs_avl[2] = { IIO_DEGREE_TO_RAD(35000), 0x2 },
> -				.fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 },
> +				.fs_avl[0] = {  IIO_DEGREE_TO_RAD(8750000), 0x0 },
> +				.fs_avl[1] = { IIO_DEGREE_TO_RAD(17500000), 0x1 },
> +				.fs_avl[2] = { IIO_DEGREE_TO_RAD(35000000), 0x2 },
> +				.fs_avl[3] = { IIO_DEGREE_TO_RAD(70000000), 0x3 },
>  				.fs_len = 4,
>  			},
>  		},
> @@ -600,10 +600,10 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>  					.addr = 0x10,
>  					.mask = GENMASK(3, 2),
>  				},
> -				.fs_avl[0] = {  IIO_G_TO_M_S_2(61), 0x0 },
> -				.fs_avl[1] = { IIO_G_TO_M_S_2(122), 0x2 },
> -				.fs_avl[2] = { IIO_G_TO_M_S_2(244), 0x3 },
> -				.fs_avl[3] = { IIO_G_TO_M_S_2(488), 0x1 },
> +				.fs_avl[0] = {  IIO_G_TO_M_S_2(61000), 0x0 },
> +				.fs_avl[1] = { IIO_G_TO_M_S_2(122000), 0x2 },
> +				.fs_avl[2] = { IIO_G_TO_M_S_2(244000), 0x3 },
> +				.fs_avl[3] = { IIO_G_TO_M_S_2(488000), 0x1 },
>  				.fs_len = 4,
>  			},
>  			[ST_LSM6DSX_ID_GYRO] = {
> @@ -611,10 +611,10 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>  					.addr = 0x11,
>  					.mask = GENMASK(3, 2),
>  				},
> -				.fs_avl[0] = {  IIO_DEGREE_TO_RAD(8750), 0x0 },
> -				.fs_avl[1] = { IIO_DEGREE_TO_RAD(17500), 0x1 },
> -				.fs_avl[2] = { IIO_DEGREE_TO_RAD(35000), 0x2 },
> -				.fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 },
> +				.fs_avl[0] = {  IIO_DEGREE_TO_RAD(8750000), 0x0 },
> +				.fs_avl[1] = { IIO_DEGREE_TO_RAD(17500000), 0x1 },
> +				.fs_avl[2] = { IIO_DEGREE_TO_RAD(35000000), 0x2 },
> +				.fs_avl[3] = { IIO_DEGREE_TO_RAD(70000000), 0x3 },
>  				.fs_len = 4,
>  			},
>  		},
> @@ -816,10 +816,10 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>  					.addr = 0x10,
>  					.mask = GENMASK(3, 2),
>  				},
> -				.fs_avl[0] = {  IIO_G_TO_M_S_2(61), 0x0 },
> -				.fs_avl[1] = { IIO_G_TO_M_S_2(122), 0x2 },
> -				.fs_avl[2] = { IIO_G_TO_M_S_2(244), 0x3 },
> -				.fs_avl[3] = { IIO_G_TO_M_S_2(488), 0x1 },
> +				.fs_avl[0] = {  IIO_G_TO_M_S_2(61000), 0x0 },
> +				.fs_avl[1] = { IIO_G_TO_M_S_2(122000), 0x2 },
> +				.fs_avl[2] = { IIO_G_TO_M_S_2(244000), 0x3 },
> +				.fs_avl[3] = { IIO_G_TO_M_S_2(488000), 0x1 },
>  				.fs_len = 4,
>  			},
>  			[ST_LSM6DSX_ID_GYRO] = {
> @@ -827,10 +827,10 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>  					.addr = 0x11,
>  					.mask = GENMASK(3, 2),
>  				},
> -				.fs_avl[0] = {  IIO_DEGREE_TO_RAD(8750), 0x0 },
> -				.fs_avl[1] = { IIO_DEGREE_TO_RAD(17500), 0x1 },
> -				.fs_avl[2] = { IIO_DEGREE_TO_RAD(35000), 0x2 },
> -				.fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 },
> +				.fs_avl[0] = {  IIO_DEGREE_TO_RAD(8750000), 0x0 },
> +				.fs_avl[1] = { IIO_DEGREE_TO_RAD(17500000), 0x1 },
> +				.fs_avl[2] = { IIO_DEGREE_TO_RAD(35000000), 0x2 },
> +				.fs_avl[3] = { IIO_DEGREE_TO_RAD(70000000), 0x3 },
>  				.fs_len = 4,
>  			},
>  		},
> @@ -1021,10 +1021,10 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>  					.addr = 0x10,
>  					.mask = GENMASK(3, 2),
>  				},
> -				.fs_avl[0] = {  IIO_G_TO_M_S_2(61), 0x0 },
> -				.fs_avl[1] = { IIO_G_TO_M_S_2(122), 0x2 },
> -				.fs_avl[2] = { IIO_G_TO_M_S_2(244), 0x3 },
> -				.fs_avl[3] = { IIO_G_TO_M_S_2(488), 0x1 },
> +				.fs_avl[0] = {  IIO_G_TO_M_S_2(61000), 0x0 },
> +				.fs_avl[1] = { IIO_G_TO_M_S_2(122000), 0x2 },
> +				.fs_avl[2] = { IIO_G_TO_M_S_2(244000), 0x3 },
> +				.fs_avl[3] = { IIO_G_TO_M_S_2(488000), 0x1 },
>  				.fs_len = 4,
>  			},
>  			[ST_LSM6DSX_ID_GYRO] = {
> @@ -1032,10 +1032,10 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>  					.addr = 0x11,
>  					.mask = GENMASK(3, 2),
>  				},
> -				.fs_avl[0] = {  IIO_DEGREE_TO_RAD(8750), 0x0 },
> -				.fs_avl[1] = { IIO_DEGREE_TO_RAD(17500), 0x1 },
> -				.fs_avl[2] = { IIO_DEGREE_TO_RAD(35000), 0x2 },
> -				.fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 },
> +				.fs_avl[0] = {  IIO_DEGREE_TO_RAD(8750000), 0x0 },
> +				.fs_avl[1] = { IIO_DEGREE_TO_RAD(17500000), 0x1 },
> +				.fs_avl[2] = { IIO_DEGREE_TO_RAD(35000000), 0x2 },
> +				.fs_avl[3] = { IIO_DEGREE_TO_RAD(70000000), 0x3 },
>  				.fs_len = 4,
>  			},
>  		},
> @@ -1200,10 +1200,10 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>  					.addr = 0x10,
>  					.mask = GENMASK(3, 2),
>  				},
> -				.fs_avl[0] = {  IIO_G_TO_M_S_2(61), 0x0 },
> -				.fs_avl[1] = { IIO_G_TO_M_S_2(122), 0x2 },
> -				.fs_avl[2] = { IIO_G_TO_M_S_2(244), 0x3 },
> -				.fs_avl[3] = { IIO_G_TO_M_S_2(488), 0x1 },
> +				.fs_avl[0] = {  IIO_G_TO_M_S_2(61000), 0x0 },
> +				.fs_avl[1] = { IIO_G_TO_M_S_2(122000), 0x2 },
> +				.fs_avl[2] = { IIO_G_TO_M_S_2(244000), 0x3 },
> +				.fs_avl[3] = { IIO_G_TO_M_S_2(488000), 0x1 },
>  				.fs_len = 4,
>  			},
>  			[ST_LSM6DSX_ID_GYRO] = {
> @@ -1211,10 +1211,10 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>  					.addr = 0x11,
>  					.mask = GENMASK(3, 2),
>  				},
> -				.fs_avl[0] = {  IIO_DEGREE_TO_RAD(8750), 0x0 },
> -				.fs_avl[1] = { IIO_DEGREE_TO_RAD(17500), 0x1 },
> -				.fs_avl[2] = { IIO_DEGREE_TO_RAD(35000), 0x2 },
> -				.fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 },
> +				.fs_avl[0] = {  IIO_DEGREE_TO_RAD(8750000), 0x0 },
> +				.fs_avl[1] = { IIO_DEGREE_TO_RAD(17500000), 0x1 },
> +				.fs_avl[2] = { IIO_DEGREE_TO_RAD(35000000), 0x2 },
> +				.fs_avl[3] = { IIO_DEGREE_TO_RAD(70000000), 0x3 },
>  				.fs_len = 4,
>  			},
>  		},
> @@ -1598,7 +1598,7 @@ static int st_lsm6dsx_read_raw(struct iio_dev *iio_dev,
>  	case IIO_CHAN_INFO_SCALE:
>  		*val = 0;
>  		*val2 = sensor->gain;
> -		ret = IIO_VAL_INT_PLUS_MICRO;
> +		ret = IIO_VAL_INT_PLUS_NANO;
>  		break;
>  	default:
>  		ret = -EINVAL;
> @@ -1836,13 +1836,31 @@ static ssize_t st_lsm6dsx_sysfs_scale_avail(struct device *dev,
>  
>  	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;
> +	}
> +}
> +
>  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 +1886,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 +1904,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)


  reply	other threads:[~2020-09-19 13:30 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-17 16:47 [PATCH] iio: imu: st_lsm6dsx: Scaling factor type set to IIO_VAL_INT_PLUS_NANO Mario Tesi
2020-09-19 13:30 ` Jonathan Cameron [this message]
  -- strict thread matches above, loose matches on Subject: below --
2020-09-16 16:44 Mario Tesi
2020-09-17  8:06 ` Lorenzo Bianconi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200919143020.53df1f3f@archlinux \
    --to=jic23@kernel.org \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lorenzo.bianconi83@gmail.com \
    --cc=mario.tesi@st.com \
    --cc=martepisa@gmail.com \
    --cc=pmeerw@pmeerw.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).