* [PATCH] iio: imu: st_lsm6dsx: do not power-off accel if events are enabled
@ 2019-11-29 9:37 Lorenzo Bianconi
2019-12-01 21:01 ` Jonathan Cameron
0 siblings, 1 reply; 4+ messages in thread
From: Lorenzo Bianconi @ 2019-11-29 9:37 UTC (permalink / raw)
To: jic23; +Cc: lorenzo.bianconi, linux-iio, sean
Do not power-off accel unconditionally if wake-up events are enabled
powering off the hw FIFO. At the same time do not power-off the accel
sensor if it is 'batched' in the hw FIFO disabling sensor events
Fixes: b5969abfa8b8 ("iio: imu: st_lsm6dsx: add motion events")
Tested-by: Sean Nyekjaer <sean@geanix.com>
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
---
This patch is based on https://patchwork.kernel.org/patch/11266301/
---
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 30 +++++++++++++++++---
1 file changed, 26 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 13590c041d22..990643da9f4e 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
@@ -1447,8 +1447,9 @@ st_lsm6dsx_set_odr(struct st_lsm6dsx_sensor *sensor, u32 req_odr)
return st_lsm6dsx_update_bits_locked(hw, reg->addr, reg->mask, data);
}
-int st_lsm6dsx_sensor_set_enable(struct st_lsm6dsx_sensor *sensor,
- bool enable)
+static int
+__st_lsm6dsx_sensor_set_enable(struct st_lsm6dsx_sensor *sensor,
+ bool enable)
{
struct st_lsm6dsx_hw *hw = sensor->hw;
u32 odr = enable ? sensor->odr : 0;
@@ -1466,6 +1467,26 @@ int st_lsm6dsx_sensor_set_enable(struct st_lsm6dsx_sensor *sensor,
return 0;
}
+static int
+st_lsm6dsx_check_events(struct st_lsm6dsx_sensor *sensor, bool enable)
+{
+ struct st_lsm6dsx_hw *hw = sensor->hw;
+
+ if (sensor->id == ST_LSM6DSX_ID_GYRO || enable)
+ return 0;
+
+ return hw->enable_event;
+}
+
+int st_lsm6dsx_sensor_set_enable(struct st_lsm6dsx_sensor *sensor,
+ bool enable)
+{
+ if (st_lsm6dsx_check_events(sensor, enable))
+ return 0;
+
+ return __st_lsm6dsx_sensor_set_enable(sensor, enable);
+}
+
static int st_lsm6dsx_read_oneshot(struct st_lsm6dsx_sensor *sensor,
u8 addr, int *val)
{
@@ -1662,7 +1683,7 @@ st_lsm6dsx_write_event_config(struct iio_dev *iio_dev,
struct st_lsm6dsx_sensor *sensor = iio_priv(iio_dev);
struct st_lsm6dsx_hw *hw = sensor->hw;
u8 enable_event;
- int err = 0;
+ int err;
if (type != IIO_EV_TYPE_THRESH)
return -EINVAL;
@@ -1690,7 +1711,8 @@ st_lsm6dsx_write_event_config(struct iio_dev *iio_dev,
return err;
mutex_lock(&hw->conf_lock);
- err = st_lsm6dsx_sensor_set_enable(sensor, state);
+ if (enable_event || !(hw->fifo_mask & BIT(sensor->id)))
+ err = __st_lsm6dsx_sensor_set_enable(sensor, state);
mutex_unlock(&hw->conf_lock);
if (err < 0)
return err;
--
2.21.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] iio: imu: st_lsm6dsx: do not power-off accel if events are enabled
2019-11-29 9:37 [PATCH] iio: imu: st_lsm6dsx: do not power-off accel if events are enabled Lorenzo Bianconi
@ 2019-12-01 21:01 ` Jonathan Cameron
2019-12-01 21:07 ` Lorenzo Bianconi
0 siblings, 1 reply; 4+ messages in thread
From: Jonathan Cameron @ 2019-12-01 21:01 UTC (permalink / raw)
To: Lorenzo Bianconi; +Cc: lorenzo.bianconi, linux-iio, sean
On Fri, 29 Nov 2019 11:37:24 +0200
Lorenzo Bianconi <lorenzo@kernel.org> wrote:
> Do not power-off accel unconditionally if wake-up events are enabled
> powering off the hw FIFO. At the same time do not power-off the accel
> sensor if it is 'batched' in the hw FIFO disabling sensor events
>
> Fixes: b5969abfa8b8 ("iio: imu: st_lsm6dsx: add motion events")
> Tested-by: Sean Nyekjaer <sean@geanix.com>
> Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Not applied as this seems to be dependent on one of the earlier patches.
Please put them in a series and resend.
Thanks,
Jonathan
> ---
> This patch is based on https://patchwork.kernel.org/patch/11266301/
> ---
> drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 30 +++++++++++++++++---
> 1 file changed, 26 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 13590c041d22..990643da9f4e 100644
> --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> @@ -1447,8 +1447,9 @@ st_lsm6dsx_set_odr(struct st_lsm6dsx_sensor *sensor, u32 req_odr)
> return st_lsm6dsx_update_bits_locked(hw, reg->addr, reg->mask, data);
> }
>
> -int st_lsm6dsx_sensor_set_enable(struct st_lsm6dsx_sensor *sensor,
> - bool enable)
> +static int
> +__st_lsm6dsx_sensor_set_enable(struct st_lsm6dsx_sensor *sensor,
> + bool enable)
> {
> struct st_lsm6dsx_hw *hw = sensor->hw;
> u32 odr = enable ? sensor->odr : 0;
> @@ -1466,6 +1467,26 @@ int st_lsm6dsx_sensor_set_enable(struct st_lsm6dsx_sensor *sensor,
> return 0;
> }
>
> +static int
> +st_lsm6dsx_check_events(struct st_lsm6dsx_sensor *sensor, bool enable)
> +{
> + struct st_lsm6dsx_hw *hw = sensor->hw;
> +
> + if (sensor->id == ST_LSM6DSX_ID_GYRO || enable)
> + return 0;
> +
> + return hw->enable_event;
> +}
> +
> +int st_lsm6dsx_sensor_set_enable(struct st_lsm6dsx_sensor *sensor,
> + bool enable)
> +{
> + if (st_lsm6dsx_check_events(sensor, enable))
> + return 0;
> +
> + return __st_lsm6dsx_sensor_set_enable(sensor, enable);
> +}
> +
> static int st_lsm6dsx_read_oneshot(struct st_lsm6dsx_sensor *sensor,
> u8 addr, int *val)
> {
> @@ -1662,7 +1683,7 @@ st_lsm6dsx_write_event_config(struct iio_dev *iio_dev,
> struct st_lsm6dsx_sensor *sensor = iio_priv(iio_dev);
> struct st_lsm6dsx_hw *hw = sensor->hw;
> u8 enable_event;
> - int err = 0;
> + int err;
>
> if (type != IIO_EV_TYPE_THRESH)
> return -EINVAL;
> @@ -1690,7 +1711,8 @@ st_lsm6dsx_write_event_config(struct iio_dev *iio_dev,
> return err;
>
> mutex_lock(&hw->conf_lock);
> - err = st_lsm6dsx_sensor_set_enable(sensor, state);
> + if (enable_event || !(hw->fifo_mask & BIT(sensor->id)))
> + err = __st_lsm6dsx_sensor_set_enable(sensor, state);
> mutex_unlock(&hw->conf_lock);
> if (err < 0)
> return err;
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] iio: imu: st_lsm6dsx: do not power-off accel if events are enabled
2019-12-01 21:01 ` Jonathan Cameron
@ 2019-12-01 21:07 ` Lorenzo Bianconi
2019-12-01 21:20 ` Jonathan Cameron
0 siblings, 1 reply; 4+ messages in thread
From: Lorenzo Bianconi @ 2019-12-01 21:07 UTC (permalink / raw)
To: Jonathan Cameron; +Cc: lorenzo.bianconi, linux-iio, sean
[-- Attachment #1: Type: text/plain, Size: 3312 bytes --]
> On Fri, 29 Nov 2019 11:37:24 +0200
> Lorenzo Bianconi <lorenzo@kernel.org> wrote:
>
> > Do not power-off accel unconditionally if wake-up events are enabled
> > powering off the hw FIFO. At the same time do not power-off the accel
> > sensor if it is 'batched' in the hw FIFO disabling sensor events
> >
> > Fixes: b5969abfa8b8 ("iio: imu: st_lsm6dsx: add motion events")
> > Tested-by: Sean Nyekjaer <sean@geanix.com>
> > Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
> Not applied as this seems to be dependent on one of the earlier patches.
> Please put them in a series and resend.
Hi Jonathan,
Sorry for the noise, but I discovered the issue after I have already sent
the other patch out. I will post them together in v2.
Regards,
Lorenzo
>
> Thanks,
>
> Jonathan
> > ---
> > This patch is based on https://patchwork.kernel.org/patch/11266301/
> > ---
> > drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 30 +++++++++++++++++---
> > 1 file changed, 26 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 13590c041d22..990643da9f4e 100644
> > --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> > +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> > @@ -1447,8 +1447,9 @@ st_lsm6dsx_set_odr(struct st_lsm6dsx_sensor *sensor, u32 req_odr)
> > return st_lsm6dsx_update_bits_locked(hw, reg->addr, reg->mask, data);
> > }
> >
> > -int st_lsm6dsx_sensor_set_enable(struct st_lsm6dsx_sensor *sensor,
> > - bool enable)
> > +static int
> > +__st_lsm6dsx_sensor_set_enable(struct st_lsm6dsx_sensor *sensor,
> > + bool enable)
> > {
> > struct st_lsm6dsx_hw *hw = sensor->hw;
> > u32 odr = enable ? sensor->odr : 0;
> > @@ -1466,6 +1467,26 @@ int st_lsm6dsx_sensor_set_enable(struct st_lsm6dsx_sensor *sensor,
> > return 0;
> > }
> >
> > +static int
> > +st_lsm6dsx_check_events(struct st_lsm6dsx_sensor *sensor, bool enable)
> > +{
> > + struct st_lsm6dsx_hw *hw = sensor->hw;
> > +
> > + if (sensor->id == ST_LSM6DSX_ID_GYRO || enable)
> > + return 0;
> > +
> > + return hw->enable_event;
> > +}
> > +
> > +int st_lsm6dsx_sensor_set_enable(struct st_lsm6dsx_sensor *sensor,
> > + bool enable)
> > +{
> > + if (st_lsm6dsx_check_events(sensor, enable))
> > + return 0;
> > +
> > + return __st_lsm6dsx_sensor_set_enable(sensor, enable);
> > +}
> > +
> > static int st_lsm6dsx_read_oneshot(struct st_lsm6dsx_sensor *sensor,
> > u8 addr, int *val)
> > {
> > @@ -1662,7 +1683,7 @@ st_lsm6dsx_write_event_config(struct iio_dev *iio_dev,
> > struct st_lsm6dsx_sensor *sensor = iio_priv(iio_dev);
> > struct st_lsm6dsx_hw *hw = sensor->hw;
> > u8 enable_event;
> > - int err = 0;
> > + int err;
> >
> > if (type != IIO_EV_TYPE_THRESH)
> > return -EINVAL;
> > @@ -1690,7 +1711,8 @@ st_lsm6dsx_write_event_config(struct iio_dev *iio_dev,
> > return err;
> >
> > mutex_lock(&hw->conf_lock);
> > - err = st_lsm6dsx_sensor_set_enable(sensor, state);
> > + if (enable_event || !(hw->fifo_mask & BIT(sensor->id)))
> > + err = __st_lsm6dsx_sensor_set_enable(sensor, state);
> > mutex_unlock(&hw->conf_lock);
> > if (err < 0)
> > return err;
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] iio: imu: st_lsm6dsx: do not power-off accel if events are enabled
2019-12-01 21:07 ` Lorenzo Bianconi
@ 2019-12-01 21:20 ` Jonathan Cameron
0 siblings, 0 replies; 4+ messages in thread
From: Jonathan Cameron @ 2019-12-01 21:20 UTC (permalink / raw)
To: Lorenzo Bianconi; +Cc: lorenzo.bianconi, linux-iio, sean
On Sun, 1 Dec 2019 23:07:27 +0200
Lorenzo Bianconi <lorenzo@kernel.org> wrote:
> > On Fri, 29 Nov 2019 11:37:24 +0200
> > Lorenzo Bianconi <lorenzo@kernel.org> wrote:
> >
> > > Do not power-off accel unconditionally if wake-up events are enabled
> > > powering off the hw FIFO. At the same time do not power-off the accel
> > > sensor if it is 'batched' in the hw FIFO disabling sensor events
> > >
> > > Fixes: b5969abfa8b8 ("iio: imu: st_lsm6dsx: add motion events")
> > > Tested-by: Sean Nyekjaer <sean@geanix.com>
> > > Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
> > Not applied as this seems to be dependent on one of the earlier patches.
> > Please put them in a series and resend.
>
> Hi Jonathan,
>
> Sorry for the noise, but I discovered the issue after I have already sent
> the other patch out. I will post them together in v2.
I've picked it up given I now have the other one anyway.
Applied to the fixes-togreg branch of iio.git
Thanks,
Jonathan
>
> Regards,
> Lorenzo
>
> >
> > Thanks,
> >
> > Jonathan
> > > ---
> > > This patch is based on https://patchwork.kernel.org/patch/11266301/
> > > ---
> > > drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 30 +++++++++++++++++---
> > > 1 file changed, 26 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 13590c041d22..990643da9f4e 100644
> > > --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> > > +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> > > @@ -1447,8 +1447,9 @@ st_lsm6dsx_set_odr(struct st_lsm6dsx_sensor *sensor, u32 req_odr)
> > > return st_lsm6dsx_update_bits_locked(hw, reg->addr, reg->mask, data);
> > > }
> > >
> > > -int st_lsm6dsx_sensor_set_enable(struct st_lsm6dsx_sensor *sensor,
> > > - bool enable)
> > > +static int
> > > +__st_lsm6dsx_sensor_set_enable(struct st_lsm6dsx_sensor *sensor,
> > > + bool enable)
> > > {
> > > struct st_lsm6dsx_hw *hw = sensor->hw;
> > > u32 odr = enable ? sensor->odr : 0;
> > > @@ -1466,6 +1467,26 @@ int st_lsm6dsx_sensor_set_enable(struct st_lsm6dsx_sensor *sensor,
> > > return 0;
> > > }
> > >
> > > +static int
> > > +st_lsm6dsx_check_events(struct st_lsm6dsx_sensor *sensor, bool enable)
> > > +{
> > > + struct st_lsm6dsx_hw *hw = sensor->hw;
> > > +
> > > + if (sensor->id == ST_LSM6DSX_ID_GYRO || enable)
> > > + return 0;
> > > +
> > > + return hw->enable_event;
> > > +}
> > > +
> > > +int st_lsm6dsx_sensor_set_enable(struct st_lsm6dsx_sensor *sensor,
> > > + bool enable)
> > > +{
> > > + if (st_lsm6dsx_check_events(sensor, enable))
> > > + return 0;
> > > +
> > > + return __st_lsm6dsx_sensor_set_enable(sensor, enable);
> > > +}
> > > +
> > > static int st_lsm6dsx_read_oneshot(struct st_lsm6dsx_sensor *sensor,
> > > u8 addr, int *val)
> > > {
> > > @@ -1662,7 +1683,7 @@ st_lsm6dsx_write_event_config(struct iio_dev *iio_dev,
> > > struct st_lsm6dsx_sensor *sensor = iio_priv(iio_dev);
> > > struct st_lsm6dsx_hw *hw = sensor->hw;
> > > u8 enable_event;
> > > - int err = 0;
> > > + int err;
> > >
> > > if (type != IIO_EV_TYPE_THRESH)
> > > return -EINVAL;
> > > @@ -1690,7 +1711,8 @@ st_lsm6dsx_write_event_config(struct iio_dev *iio_dev,
> > > return err;
> > >
> > > mutex_lock(&hw->conf_lock);
> > > - err = st_lsm6dsx_sensor_set_enable(sensor, state);
> > > + if (enable_event || !(hw->fifo_mask & BIT(sensor->id)))
> > > + err = __st_lsm6dsx_sensor_set_enable(sensor, state);
> > > mutex_unlock(&hw->conf_lock);
> > > if (err < 0)
> > > return err;
> >
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2019-12-01 21:20 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-29 9:37 [PATCH] iio: imu: st_lsm6dsx: do not power-off accel if events are enabled Lorenzo Bianconi
2019-12-01 21:01 ` Jonathan Cameron
2019-12-01 21:07 ` Lorenzo Bianconi
2019-12-01 21:20 ` 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).