linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iio: imu: st_lsm6dsx: fix ODR check in st_lsm6dsx_write_raw
@ 2019-10-27 18:02 Lorenzo Bianconi
  2019-11-02 15:58 ` Jonathan Cameron
  0 siblings, 1 reply; 2+ messages in thread
From: Lorenzo Bianconi @ 2019-10-27 18:02 UTC (permalink / raw)
  To: jic23; +Cc: lorenzo.bianconi, linux-iio

Since st_lsm6dsx i2c master controller relies on accel device as trigger
and slave devices can run at different ODRs we must select an accel_odr >=
slave_odr. Report real accel ODR in st_lsm6dsx_check_odr() in order to
properly set sensor frequency in st_lsm6dsx_write_raw and avoid to
report unsupported frequency

Fixes: 6ffb55e5009ff ("iio: imu: st_lsm6dsx: introduce ST_LSM6DSX_ID_EXT sensor ids")
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
---
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
index 1f28a7733fc0..c53c03ec2423 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
@@ -1362,8 +1362,7 @@ int st_lsm6dsx_check_odr(struct st_lsm6dsx_sensor *sensor, u16 odr, u8 *val)
 		return -EINVAL;
 
 	*val = odr_table->odr_avl[i].val;
-
-	return 0;
+	return odr_table->odr_avl[i].hz;
 }
 
 static u16 st_lsm6dsx_check_odr_dependency(struct st_lsm6dsx_hw *hw, u16 odr,
@@ -1527,8 +1526,10 @@ static int st_lsm6dsx_write_raw(struct iio_dev *iio_dev,
 	case IIO_CHAN_INFO_SAMP_FREQ: {
 		u8 data;
 
-		err = st_lsm6dsx_check_odr(sensor, val, &data);
-		if (!err)
+		val = st_lsm6dsx_check_odr(sensor, val, &data);
+		if (val < 0)
+			err = val;
+		else
 			sensor->odr = val;
 		break;
 	}
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] iio: imu: st_lsm6dsx: fix ODR check in st_lsm6dsx_write_raw
  2019-10-27 18:02 [PATCH] iio: imu: st_lsm6dsx: fix ODR check in st_lsm6dsx_write_raw Lorenzo Bianconi
@ 2019-11-02 15:58 ` Jonathan Cameron
  0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Cameron @ 2019-11-02 15:58 UTC (permalink / raw)
  To: Lorenzo Bianconi; +Cc: lorenzo.bianconi, linux-iio

On Sun, 27 Oct 2019 19:02:30 +0100
Lorenzo Bianconi <lorenzo@kernel.org> wrote:

> Since st_lsm6dsx i2c master controller relies on accel device as trigger
> and slave devices can run at different ODRs we must select an accel_odr >=
> slave_odr. Report real accel ODR in st_lsm6dsx_check_odr() in order to
> properly set sensor frequency in st_lsm6dsx_write_raw and avoid to
> report unsupported frequency
> 
> Fixes: 6ffb55e5009ff ("iio: imu: st_lsm6dsx: introduce ST_LSM6DSX_ID_EXT sensor ids")
> Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>

Applied to the fixes-togreg branch of iio.git and marked for stable.
Given time in cycle I 'might' shift this into togreg to go in during the
merge window. 

Thanks,

Jonathan

> ---
>  drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> index 1f28a7733fc0..c53c03ec2423 100644
> --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> @@ -1362,8 +1362,7 @@ int st_lsm6dsx_check_odr(struct st_lsm6dsx_sensor *sensor, u16 odr, u8 *val)
>  		return -EINVAL;
>  
>  	*val = odr_table->odr_avl[i].val;
> -
> -	return 0;
> +	return odr_table->odr_avl[i].hz;
>  }
>  
>  static u16 st_lsm6dsx_check_odr_dependency(struct st_lsm6dsx_hw *hw, u16 odr,
> @@ -1527,8 +1526,10 @@ static int st_lsm6dsx_write_raw(struct iio_dev *iio_dev,
>  	case IIO_CHAN_INFO_SAMP_FREQ: {
>  		u8 data;
>  
> -		err = st_lsm6dsx_check_odr(sensor, val, &data);
> -		if (!err)
> +		val = st_lsm6dsx_check_odr(sensor, val, &data);
> +		if (val < 0)
> +			err = val;
> +		else
>  			sensor->odr = val;
>  		break;
>  	}


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-11-02 15:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-27 18:02 [PATCH] iio: imu: st_lsm6dsx: fix ODR check in st_lsm6dsx_write_raw Lorenzo Bianconi
2019-11-02 15:58 ` Jonathan Cameron

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).