diff mbox series

iio: imu: st_lsm6dsx: flush hw FIFO before resetting the device

Message ID e9beff6b3a32ddf0de20821e50cf3ed562e36b48.1584122527.git.lorenzo@kernel.org (mailing list archive)
State New, archived
Headers show
Series iio: imu: st_lsm6dsx: flush hw FIFO before resetting the device | expand

Commit Message

Lorenzo Bianconi March 13, 2020, 6:06 p.m. UTC
flush hw FIFO before device reset in order to avoid possible races
on interrupt line 1. If the first interrupt line is asserted during
hw reset the device will work in I3C-only mode (if it is supported)

Fixes: 801a6e0af0c6 ("iio: imu: st_lsm6dsx: add support to LSM6DSO")
Fixes: 43901008fde0 ("iio: imu: st_lsm6dsx: add support to LSM6DSR")
Reported-by: Mario Tesi <mario.tesi@st.com>
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
---
This is a new version of: "iio: imu: st_lsm6dsx: disable I3C support during
device reset"
https://patchwork.kernel.org/patch/11425389/
---
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 24 +++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

Comments

Vitor Soares March 17, 2020, 1:08 p.m. UTC | #1
Hi Lorenzo,

From: Lorenzo Bianconi <lorenzo@kernel.org>
Date: Fri, Mar 13, 2020 at 18:06:00

> flush hw FIFO before device reset in order to avoid possible races
> on interrupt line 1. If the first interrupt line is asserted during
> hw reset the device will work in I3C-only mode (if it is supported)
> 
> Fixes: 801a6e0af0c6 ("iio: imu: st_lsm6dsx: add support to LSM6DSO")
> Fixes: 43901008fde0 ("iio: imu: st_lsm6dsx: add support to LSM6DSR")
> Reported-by: Mario Tesi <mario.tesi@st.com>
> Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
> ---
> This is a new version of: "iio: imu: st_lsm6dsx: disable I3C support during
> device reset"
> https://urldefense.proofpoint.com/v2/url?u=https-3A__patchwork.kernel.org_patch_11425389_&d=DwIDAg&c=DPL6_X_6JkXFx7AXWqB0tg&r=qVuU64u9x77Y0Kd0PhDK_lpxFgg6PK9PateHwjb_DY0&m=d7oUzE4fWeY3JqYqqd-uW_v1SJkij_sOpXRvpm3-Thg&s=BEgROrIZoG9oGrwQEENFz0DP88VioXUhpeZP2Y168XI&e= 
> ---
>  drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 24 +++++++++++++++++++-
>  1 file changed, 23 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> index 84d219ae6aee..4426524b59f2 100644
> --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> @@ -2036,11 +2036,21 @@ static int st_lsm6dsx_init_hw_timer(struct st_lsm6dsx_hw *hw)
>  	return 0;
>  }
>  
> -static int st_lsm6dsx_init_device(struct st_lsm6dsx_hw *hw)
> +static int st_lsm6dsx_reset_device(struct st_lsm6dsx_hw *hw)
>  {
>  	const struct st_lsm6dsx_reg *reg;
>  	int err;
>  
> +	/*
> +	 * flush hw FIFO before device reset in order to avoid
> +	 * possible races on interrupt line 1. If the first interrupt
> +	 * line is asserted during hw reset the device will work in
> +	 * I3C-only mode (if it is supported)
> +	 */
> +	err = st_lsm6dsx_flush_fifo(hw);
> +	if (err < 0 && err != -ENOTSUPP)
> +		return err;
> +
>  	/* device sw reset */
>  	reg = &hw->settings->reset;
>  	err = regmap_update_bits(hw->regmap, reg->addr, reg->mask,
> @@ -2059,6 +2069,18 @@ static int st_lsm6dsx_init_device(struct st_lsm6dsx_hw *hw)
>  
>  	msleep(50);
>  
> +	return 0;
> +}
> +
> +static int st_lsm6dsx_init_device(struct st_lsm6dsx_hw *hw)
> +{
> +	const struct st_lsm6dsx_reg *reg;
> +	int err;
> +
> +	err = st_lsm6dsx_reset_device(hw);
> +	if (err < 0)
> +		return err;
> +
>  	/* enable Block Data Update */
>  	reg = &hw->settings->bdu;
>  	err = regmap_update_bits(hw->regmap, reg->addr, reg->mask,
> -- 
> 2.24.1

I tested the patch and the I3C interface is working fine in this version.

Reviewed-by: Vitor Soares <vitor.soares@synopsys.com>
Tested-by: Vitor Soares <vitor.soares@synopsys.com>

Best regards,
Vitor 
Soares
Lorenzo Bianconi April 4, 2020, 4:29 p.m. UTC | #2
>
> Hi Lorenzo,
>
> From: Lorenzo Bianconi <lorenzo@kernel.org>
> Date: Fri, Mar 13, 2020 at 18:06:00
>
> > flush hw FIFO before device reset in order to avoid possible races
> > on interrupt line 1. If the first interrupt line is asserted during
> > hw reset the device will work in I3C-only mode (if it is supported)
> >

Hi Jonathan,

any news about this patch? Maybe I am wrong but I am not able to find
it in your tree.
Thanks in advance.

Regards,
Lorenzo


> > Fixes: 801a6e0af0c6 ("iio: imu: st_lsm6dsx: add support to LSM6DSO")
> > Fixes: 43901008fde0 ("iio: imu: st_lsm6dsx: add support to LSM6DSR")
> > Reported-by: Mario Tesi <mario.tesi@st.com>
> > Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
> > ---
> > This is a new version of: "iio: imu: st_lsm6dsx: disable I3C support during
> > device reset"
> > https://urldefense.proofpoint.com/v2/url?u=https-3A__patchwork.kernel.org_patch_11425389_&d=DwIDAg&c=DPL6_X_6JkXFx7AXWqB0tg&r=qVuU64u9x77Y0Kd0PhDK_lpxFgg6PK9PateHwjb_DY0&m=d7oUzE4fWeY3JqYqqd-uW_v1SJkij_sOpXRvpm3-Thg&s=BEgROrIZoG9oGrwQEENFz0DP88VioXUhpeZP2Y168XI&e=
> > ---
> >  drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 24 +++++++++++++++++++-
> >  1 file changed, 23 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> > index 84d219ae6aee..4426524b59f2 100644
> > --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> > +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> > @@ -2036,11 +2036,21 @@ static int st_lsm6dsx_init_hw_timer(struct st_lsm6dsx_hw *hw)
> >       return 0;
> >  }
> >
> > -static int st_lsm6dsx_init_device(struct st_lsm6dsx_hw *hw)
> > +static int st_lsm6dsx_reset_device(struct st_lsm6dsx_hw *hw)
> >  {
> >       const struct st_lsm6dsx_reg *reg;
> >       int err;
> >
> > +     /*
> > +      * flush hw FIFO before device reset in order to avoid
> > +      * possible races on interrupt line 1. If the first interrupt
> > +      * line is asserted during hw reset the device will work in
> > +      * I3C-only mode (if it is supported)
> > +      */
> > +     err = st_lsm6dsx_flush_fifo(hw);
> > +     if (err < 0 && err != -ENOTSUPP)
> > +             return err;
> > +
> >       /* device sw reset */
> >       reg = &hw->settings->reset;
> >       err = regmap_update_bits(hw->regmap, reg->addr, reg->mask,
> > @@ -2059,6 +2069,18 @@ static int st_lsm6dsx_init_device(struct st_lsm6dsx_hw *hw)
> >
> >       msleep(50);
> >
> > +     return 0;
> > +}
> > +
> > +static int st_lsm6dsx_init_device(struct st_lsm6dsx_hw *hw)
> > +{
> > +     const struct st_lsm6dsx_reg *reg;
> > +     int err;
> > +
> > +     err = st_lsm6dsx_reset_device(hw);
> > +     if (err < 0)
> > +             return err;
> > +
> >       /* enable Block Data Update */
> >       reg = &hw->settings->bdu;
> >       err = regmap_update_bits(hw->regmap, reg->addr, reg->mask,
> > --
> > 2.24.1
>
> I tested the patch and the I3C interface is working fine in this version.
>
> Reviewed-by: Vitor Soares <vitor.soares@synopsys.com>
> Tested-by: Vitor Soares <vitor.soares@synopsys.com>
>
> Best regards,
> Vitor
> Soares
>
>
Jonathan Cameron April 4, 2020, 5:06 p.m. UTC | #3
On Sat, 4 Apr 2020 18:29:25 +0200
Lorenzo Bianconi <lorenzo.bianconi@redhat.com> wrote:

> >
> > Hi Lorenzo,
> >
> > From: Lorenzo Bianconi <lorenzo@kernel.org>
> > Date: Fri, Mar 13, 2020 at 18:06:00
> >  
> > > flush hw FIFO before device reset in order to avoid possible races
> > > on interrupt line 1. If the first interrupt line is asserted during
> > > hw reset the device will work in I3C-only mode (if it is supported)
> > >  
> 
> Hi Jonathan,
> 
> any news about this patch? Maybe I am wrong but I am not able to find
> it in your tree.
> Thanks in advance.

I'm running a bit behind on catching up with fixes after it became obvious
they wouldn't make the merge window.

Applied to the fixes-togreg branch of iio.git and marked for stable.

> 
> Regards,
> Lorenzo
> 
> 
> > > Fixes: 801a6e0af0c6 ("iio: imu: st_lsm6dsx: add support to LSM6DSO")
> > > Fixes: 43901008fde0 ("iio: imu: st_lsm6dsx: add support to LSM6DSR")
> > > Reported-by: Mario Tesi <mario.tesi@st.com>
> > > Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
> > > ---
> > > This is a new version of: "iio: imu: st_lsm6dsx: disable I3C support during
> > > device reset"
> > > https://urldefense.proofpoint.com/v2/url?u=https-3A__patchwork.kernel.org_patch_11425389_&d=DwIDAg&c=DPL6_X_6JkXFx7AXWqB0tg&r=qVuU64u9x77Y0Kd0PhDK_lpxFgg6PK9PateHwjb_DY0&m=d7oUzE4fWeY3JqYqqd-uW_v1SJkij_sOpXRvpm3-Thg&s=BEgROrIZoG9oGrwQEENFz0DP88VioXUhpeZP2Y168XI&e=
> > > ---
> > >  drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 24 +++++++++++++++++++-
> > >  1 file changed, 23 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> > > index 84d219ae6aee..4426524b59f2 100644
> > > --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> > > +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> > > @@ -2036,11 +2036,21 @@ static int st_lsm6dsx_init_hw_timer(struct st_lsm6dsx_hw *hw)
> > >       return 0;
> > >  }
> > >
> > > -static int st_lsm6dsx_init_device(struct st_lsm6dsx_hw *hw)
> > > +static int st_lsm6dsx_reset_device(struct st_lsm6dsx_hw *hw)
> > >  {
> > >       const struct st_lsm6dsx_reg *reg;
> > >       int err;
> > >
> > > +     /*
> > > +      * flush hw FIFO before device reset in order to avoid
> > > +      * possible races on interrupt line 1. If the first interrupt
> > > +      * line is asserted during hw reset the device will work in
> > > +      * I3C-only mode (if it is supported)
> > > +      */
> > > +     err = st_lsm6dsx_flush_fifo(hw);
> > > +     if (err < 0 && err != -ENOTSUPP)
> > > +             return err;
> > > +
> > >       /* device sw reset */
> > >       reg = &hw->settings->reset;
> > >       err = regmap_update_bits(hw->regmap, reg->addr, reg->mask,
> > > @@ -2059,6 +2069,18 @@ static int st_lsm6dsx_init_device(struct st_lsm6dsx_hw *hw)
> > >
> > >       msleep(50);
> > >
> > > +     return 0;
> > > +}
> > > +
> > > +static int st_lsm6dsx_init_device(struct st_lsm6dsx_hw *hw)
> > > +{
> > > +     const struct st_lsm6dsx_reg *reg;
> > > +     int err;
> > > +
> > > +     err = st_lsm6dsx_reset_device(hw);
> > > +     if (err < 0)
> > > +             return err;
> > > +
> > >       /* enable Block Data Update */
> > >       reg = &hw->settings->bdu;
> > >       err = regmap_update_bits(hw->regmap, reg->addr, reg->mask,
> > > --
> > > 2.24.1  
> >
> > I tested the patch and the I3C interface is working fine in this version.
> >
> > Reviewed-by: Vitor Soares <vitor.soares@synopsys.com>
> > Tested-by: Vitor Soares <vitor.soares@synopsys.com>
> >

> > Best regards,
> > Vitor
> > Soares
> >
> >  
>
Lorenzo Bianconi April 4, 2020, 5:09 p.m. UTC | #4
>
> On Sat, 4 Apr 2020 18:29:25 +0200
> Lorenzo Bianconi <lorenzo.bianconi@redhat.com> wrote:
>
> > >
> > > Hi Lorenzo,
> > >
> > > From: Lorenzo Bianconi <lorenzo@kernel.org>
> > > Date: Fri, Mar 13, 2020 at 18:06:00
> > >
> > > > flush hw FIFO before device reset in order to avoid possible races
> > > > on interrupt line 1. If the first interrupt line is asserted during
> > > > hw reset the device will work in I3C-only mode (if it is supported)
> > > >
> >
> > Hi Jonathan,
> >
> > any news about this patch? Maybe I am wrong but I am not able to find
> > it in your tree.
> > Thanks in advance.
>
> I'm running a bit behind on catching up with fixes after it became obvious
> they wouldn't make the merge window.
>
> Applied to the fixes-togreg branch of iio.git and marked for stable.
>

ack, thx...sorry for all the noise around it.

Regards,
Lorenzo

> >
> > Regards,
> > Lorenzo
> >
> >
> > > > Fixes: 801a6e0af0c6 ("iio: imu: st_lsm6dsx: add support to LSM6DSO")
> > > > Fixes: 43901008fde0 ("iio: imu: st_lsm6dsx: add support to LSM6DSR")
> > > > Reported-by: Mario Tesi <mario.tesi@st.com>
> > > > Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
> > > > ---
> > > > This is a new version of: "iio: imu: st_lsm6dsx: disable I3C support during
> > > > device reset"
> > > > https://urldefense.proofpoint.com/v2/url?u=https-3A__patchwork.kernel.org_patch_11425389_&d=DwIDAg&c=DPL6_X_6JkXFx7AXWqB0tg&r=qVuU64u9x77Y0Kd0PhDK_lpxFgg6PK9PateHwjb_DY0&m=d7oUzE4fWeY3JqYqqd-uW_v1SJkij_sOpXRvpm3-Thg&s=BEgROrIZoG9oGrwQEENFz0DP88VioXUhpeZP2Y168XI&e=
> > > > ---
> > > >  drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 24 +++++++++++++++++++-
> > > >  1 file changed, 23 insertions(+), 1 deletion(-)
> > > >
> > > > diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> > > > index 84d219ae6aee..4426524b59f2 100644
> > > > --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> > > > +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> > > > @@ -2036,11 +2036,21 @@ static int st_lsm6dsx_init_hw_timer(struct st_lsm6dsx_hw *hw)
> > > >       return 0;
> > > >  }
> > > >
> > > > -static int st_lsm6dsx_init_device(struct st_lsm6dsx_hw *hw)
> > > > +static int st_lsm6dsx_reset_device(struct st_lsm6dsx_hw *hw)
> > > >  {
> > > >       const struct st_lsm6dsx_reg *reg;
> > > >       int err;
> > > >
> > > > +     /*
> > > > +      * flush hw FIFO before device reset in order to avoid
> > > > +      * possible races on interrupt line 1. If the first interrupt
> > > > +      * line is asserted during hw reset the device will work in
> > > > +      * I3C-only mode (if it is supported)
> > > > +      */
> > > > +     err = st_lsm6dsx_flush_fifo(hw);
> > > > +     if (err < 0 && err != -ENOTSUPP)
> > > > +             return err;
> > > > +
> > > >       /* device sw reset */
> > > >       reg = &hw->settings->reset;
> > > >       err = regmap_update_bits(hw->regmap, reg->addr, reg->mask,
> > > > @@ -2059,6 +2069,18 @@ static int st_lsm6dsx_init_device(struct st_lsm6dsx_hw *hw)
> > > >
> > > >       msleep(50);
> > > >
> > > > +     return 0;
> > > > +}
> > > > +
> > > > +static int st_lsm6dsx_init_device(struct st_lsm6dsx_hw *hw)
> > > > +{
> > > > +     const struct st_lsm6dsx_reg *reg;
> > > > +     int err;
> > > > +
> > > > +     err = st_lsm6dsx_reset_device(hw);
> > > > +     if (err < 0)
> > > > +             return err;
> > > > +
> > > >       /* enable Block Data Update */
> > > >       reg = &hw->settings->bdu;
> > > >       err = regmap_update_bits(hw->regmap, reg->addr, reg->mask,
> > > > --
> > > > 2.24.1
> > >
> > > I tested the patch and the I3C interface is working fine in this version.
> > >
> > > Reviewed-by: Vitor Soares <vitor.soares@synopsys.com>
> > > Tested-by: Vitor Soares <vitor.soares@synopsys.com>
> > >
>
> > > Best regards,
> > > Vitor
> > > Soares
> > >
> > >
> >
>
Jonathan Cameron April 5, 2020, 9:26 a.m. UTC | #5
On Sat, 4 Apr 2020 19:09:18 +0200
Lorenzo Bianconi <lorenzo.bianconi@redhat.com> wrote:

> >
> > On Sat, 4 Apr 2020 18:29:25 +0200
> > Lorenzo Bianconi <lorenzo.bianconi@redhat.com> wrote:
> >  
> > > >
> > > > Hi Lorenzo,
> > > >
> > > > From: Lorenzo Bianconi <lorenzo@kernel.org>
> > > > Date: Fri, Mar 13, 2020 at 18:06:00
> > > >  
> > > > > flush hw FIFO before device reset in order to avoid possible races
> > > > > on interrupt line 1. If the first interrupt line is asserted during
> > > > > hw reset the device will work in I3C-only mode (if it is supported)
> > > > >  
> > >
> > > Hi Jonathan,
> > >
> > > any news about this patch? Maybe I am wrong but I am not able to find
> > > it in your tree.
> > > Thanks in advance.  
> >
> > I'm running a bit behind on catching up with fixes after it became obvious
> > they wouldn't make the merge window.
> >
> > Applied to the fixes-togreg branch of iio.git and marked for stable.
> >  
> 
> ack, thx...sorry for all the noise around it.

No problem - it reminded me to actually do something about this and other
patches in the same position ;)

Jonathan
> 
> Regards,
> Lorenzo
> 
> > >
> > > Regards,
> > > Lorenzo
> > >
> > >  
> > > > > Fixes: 801a6e0af0c6 ("iio: imu: st_lsm6dsx: add support to LSM6DSO")
> > > > > Fixes: 43901008fde0 ("iio: imu: st_lsm6dsx: add support to LSM6DSR")
> > > > > Reported-by: Mario Tesi <mario.tesi@st.com>
> > > > > Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
> > > > > ---
> > > > > This is a new version of: "iio: imu: st_lsm6dsx: disable I3C support during
> > > > > device reset"
> > > > > https://urldefense.proofpoint.com/v2/url?u=https-3A__patchwork.kernel.org_patch_11425389_&d=DwIDAg&c=DPL6_X_6JkXFx7AXWqB0tg&r=qVuU64u9x77Y0Kd0PhDK_lpxFgg6PK9PateHwjb_DY0&m=d7oUzE4fWeY3JqYqqd-uW_v1SJkij_sOpXRvpm3-Thg&s=BEgROrIZoG9oGrwQEENFz0DP88VioXUhpeZP2Y168XI&e=
> > > > > ---
> > > > >  drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 24 +++++++++++++++++++-
> > > > >  1 file changed, 23 insertions(+), 1 deletion(-)
> > > > >
> > > > > diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> > > > > index 84d219ae6aee..4426524b59f2 100644
> > > > > --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> > > > > +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> > > > > @@ -2036,11 +2036,21 @@ static int st_lsm6dsx_init_hw_timer(struct st_lsm6dsx_hw *hw)
> > > > >       return 0;
> > > > >  }
> > > > >
> > > > > -static int st_lsm6dsx_init_device(struct st_lsm6dsx_hw *hw)
> > > > > +static int st_lsm6dsx_reset_device(struct st_lsm6dsx_hw *hw)
> > > > >  {
> > > > >       const struct st_lsm6dsx_reg *reg;
> > > > >       int err;
> > > > >
> > > > > +     /*
> > > > > +      * flush hw FIFO before device reset in order to avoid
> > > > > +      * possible races on interrupt line 1. If the first interrupt
> > > > > +      * line is asserted during hw reset the device will work in
> > > > > +      * I3C-only mode (if it is supported)
> > > > > +      */
> > > > > +     err = st_lsm6dsx_flush_fifo(hw);
> > > > > +     if (err < 0 && err != -ENOTSUPP)
> > > > > +             return err;
> > > > > +
> > > > >       /* device sw reset */
> > > > >       reg = &hw->settings->reset;
> > > > >       err = regmap_update_bits(hw->regmap, reg->addr, reg->mask,
> > > > > @@ -2059,6 +2069,18 @@ static int st_lsm6dsx_init_device(struct st_lsm6dsx_hw *hw)
> > > > >
> > > > >       msleep(50);
> > > > >
> > > > > +     return 0;
> > > > > +}
> > > > > +
> > > > > +static int st_lsm6dsx_init_device(struct st_lsm6dsx_hw *hw)
> > > > > +{
> > > > > +     const struct st_lsm6dsx_reg *reg;
> > > > > +     int err;
> > > > > +
> > > > > +     err = st_lsm6dsx_reset_device(hw);
> > > > > +     if (err < 0)
> > > > > +             return err;
> > > > > +
> > > > >       /* enable Block Data Update */
> > > > >       reg = &hw->settings->bdu;
> > > > >       err = regmap_update_bits(hw->regmap, reg->addr, reg->mask,
> > > > > --
> > > > > 2.24.1  
> > > >
> > > > I tested the patch and the I3C interface is working fine in this version.
> > > >
> > > > Reviewed-by: Vitor Soares <vitor.soares@synopsys.com>
> > > > Tested-by: Vitor Soares <vitor.soares@synopsys.com>
> > > >  
> >  
> > > > Best regards,
> > > > Vitor
> > > > Soares
> > > >
> > > >  
> > >  
> >  
>
diff mbox series

Patch

diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
index 84d219ae6aee..4426524b59f2 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
@@ -2036,11 +2036,21 @@  static int st_lsm6dsx_init_hw_timer(struct st_lsm6dsx_hw *hw)
 	return 0;
 }
 
-static int st_lsm6dsx_init_device(struct st_lsm6dsx_hw *hw)
+static int st_lsm6dsx_reset_device(struct st_lsm6dsx_hw *hw)
 {
 	const struct st_lsm6dsx_reg *reg;
 	int err;
 
+	/*
+	 * flush hw FIFO before device reset in order to avoid
+	 * possible races on interrupt line 1. If the first interrupt
+	 * line is asserted during hw reset the device will work in
+	 * I3C-only mode (if it is supported)
+	 */
+	err = st_lsm6dsx_flush_fifo(hw);
+	if (err < 0 && err != -ENOTSUPP)
+		return err;
+
 	/* device sw reset */
 	reg = &hw->settings->reset;
 	err = regmap_update_bits(hw->regmap, reg->addr, reg->mask,
@@ -2059,6 +2069,18 @@  static int st_lsm6dsx_init_device(struct st_lsm6dsx_hw *hw)
 
 	msleep(50);
 
+	return 0;
+}
+
+static int st_lsm6dsx_init_device(struct st_lsm6dsx_hw *hw)
+{
+	const struct st_lsm6dsx_reg *reg;
+	int err;
+
+	err = st_lsm6dsx_reset_device(hw);
+	if (err < 0)
+		return err;
+
 	/* enable Block Data Update */
 	reg = &hw->settings->bdu;
 	err = regmap_update_bits(hw->regmap, reg->addr, reg->mask,