Linux IIO development
 help / color / mirror / Atom feed
* [PATCH v2] iio: imu: st_lsm6dsx: deselect shub page before reading whoami
@ 2026-07-02 10:41 Andreas Kempe
  2026-07-02 12:09 ` Lorenzo Bianconi
  0 siblings, 1 reply; 3+ messages in thread
From: Andreas Kempe @ 2026-07-02 10:41 UTC (permalink / raw)
  To: Lorenzo Bianconi, Jonathan Cameron
  Cc: David Lechner, Nuno Sá, Andy Shevchenko,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
	Andreas Kempe

As part of driver initialization, e.g. st_lsm6dsx_init_shub() selects
the shub register page using st_lsm6dsx_set_page(). Selecting the shub
register page shadows the regular register space so whoami, among other
registers, is no longer accessible.

In applications where the IMU is permanently powered separately from the
processor, there is a window where a reset of the CPU leaves the IMU in
the shub register page. Once this occurs, any subsequent probe attempt
fails because of the register shadowing.

Using the ism330dlc, the error typically looks like

    st_lsm6dsx_i2c 3-006a: unsupported whoami [10]

with the unknown whoami read from a reserved register in the shub page.

The reset register is also shadowed by the page select, preventing a
reset from recovering the chip.

Unconditionally clear the shub page before the whoami readout to ensure
normal register access and allow the initialization to proceed.

Place the fix in st_lsm6dsx_check_whoami() before the whoami check
because hw->settings, which st_lsm6dsx_set_page() relies on, is first
assigned in that function.

Placing the fix in a more logical place than the whoami check would
require a bigger restructuring of the code.

Signed-off-by: Andreas Kempe <andreas.kempe@actia.se>
---

 Changes in v2:
   - Drop st_lsm6dsx_get_page() and unconditionally clear the shub page.
   - Make the code comment clearer.
   - Document the placement rationale in the commit message.
   - Link to v1: https://lore.kernel.org/linux-iio/20260604132646.1099072-1-andreas.kempe@actia.se/

 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 21 +++++++++++++++++++-
 1 file changed, 20 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 630e2cae6f19..f4edcb73ec8c 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
@@ -1712,6 +1712,26 @@ static int st_lsm6dsx_check_whoami(struct st_lsm6dsx_hw *hw, int id,
 		return -ENODEV;
 	}
 
+	hw->settings = &st_lsm6dsx_sensor_settings[i];
+
+	if (hw->settings->shub_settings.page_mux.addr) {
+		/*
+		 * If the IMU has the shub page selected on init, for example
+		 * after a CPU watchdog reset while the page is selected, the
+		 * regular register space is shadowed. While the regular
+		 * register space is shadowed, the registers needed for
+		 * initializing the IMU are not available.
+		 *
+		 * Unconditionally clear the shub page selection to ensure
+		 * normal register access.
+		 */
+		err = st_lsm6dsx_set_page(hw, false);
+		if (err < 0) {
+			dev_err(hw->dev, "failed to clear shub page\n");
+			return err;
+		}
+	}
+
 	err = regmap_read(hw->regmap, ST_LSM6DSX_REG_WHOAMI_ADDR, &data);
 	if (err < 0) {
 		dev_err(hw->dev, "failed to read whoami register\n");
@@ -1724,7 +1744,6 @@ static int st_lsm6dsx_check_whoami(struct st_lsm6dsx_hw *hw, int id,
 	}
 
 	*name = st_lsm6dsx_sensor_settings[i].id[j].name;
-	hw->settings = &st_lsm6dsx_sensor_settings[i];
 
 	return 0;
 }
-- 
2.53.0

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

* Re: [PATCH v2] iio: imu: st_lsm6dsx: deselect shub page before reading whoami
  2026-07-02 10:41 [PATCH v2] iio: imu: st_lsm6dsx: deselect shub page before reading whoami Andreas Kempe
@ 2026-07-02 12:09 ` Lorenzo Bianconi
  2026-07-02 17:04   ` Jonathan Cameron
  0 siblings, 1 reply; 3+ messages in thread
From: Lorenzo Bianconi @ 2026-07-02 12:09 UTC (permalink / raw)
  To: Andreas Kempe
  Cc: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org

[-- Attachment #1: Type: text/plain, Size: 3349 bytes --]

> As part of driver initialization, e.g. st_lsm6dsx_init_shub() selects
> the shub register page using st_lsm6dsx_set_page(). Selecting the shub
> register page shadows the regular register space so whoami, among other
> registers, is no longer accessible.
> 
> In applications where the IMU is permanently powered separately from the
> processor, there is a window where a reset of the CPU leaves the IMU in
> the shub register page. Once this occurs, any subsequent probe attempt
> fails because of the register shadowing.
> 
> Using the ism330dlc, the error typically looks like
> 
>     st_lsm6dsx_i2c 3-006a: unsupported whoami [10]
> 
> with the unknown whoami read from a reserved register in the shub page.
> 
> The reset register is also shadowed by the page select, preventing a
> reset from recovering the chip.
> 
> Unconditionally clear the shub page before the whoami readout to ensure
> normal register access and allow the initialization to proceed.
> 
> Place the fix in st_lsm6dsx_check_whoami() before the whoami check
> because hw->settings, which st_lsm6dsx_set_page() relies on, is first
> assigned in that function.
> 
> Placing the fix in a more logical place than the whoami check would
> require a bigger restructuring of the code.
> 
> Signed-off-by: Andreas Kempe <andreas.kempe@actia.se>
> ---
> 
>  Changes in v2:
>    - Drop st_lsm6dsx_get_page() and unconditionally clear the shub page.
>    - Make the code comment clearer.
>    - Document the placement rationale in the commit message.
>    - Link to v1: https://lore.kernel.org/linux-iio/20260604132646.1099072-1-andreas.kempe@actia.se/
> 
>  drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 21 +++++++++++++++++++-
>  1 file changed, 20 insertions(+), 1 deletion(-)

Acked-by: Lorenzo Bianconi <lorenzo@kernel.org>

> 
> diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> index 630e2cae6f19..f4edcb73ec8c 100644
> --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> @@ -1712,6 +1712,26 @@ static int st_lsm6dsx_check_whoami(struct st_lsm6dsx_hw *hw, int id,
>  		return -ENODEV;
>  	}
>  
> +	hw->settings = &st_lsm6dsx_sensor_settings[i];
> +
> +	if (hw->settings->shub_settings.page_mux.addr) {
> +		/*
> +		 * If the IMU has the shub page selected on init, for example
> +		 * after a CPU watchdog reset while the page is selected, the
> +		 * regular register space is shadowed. While the regular
> +		 * register space is shadowed, the registers needed for
> +		 * initializing the IMU are not available.
> +		 *
> +		 * Unconditionally clear the shub page selection to ensure
> +		 * normal register access.
> +		 */
> +		err = st_lsm6dsx_set_page(hw, false);
> +		if (err < 0) {
> +			dev_err(hw->dev, "failed to clear shub page\n");
> +			return err;
> +		}
> +	}
> +
>  	err = regmap_read(hw->regmap, ST_LSM6DSX_REG_WHOAMI_ADDR, &data);
>  	if (err < 0) {
>  		dev_err(hw->dev, "failed to read whoami register\n");
> @@ -1724,7 +1744,6 @@ static int st_lsm6dsx_check_whoami(struct st_lsm6dsx_hw *hw, int id,
>  	}
>  
>  	*name = st_lsm6dsx_sensor_settings[i].id[j].name;
> -	hw->settings = &st_lsm6dsx_sensor_settings[i];
>  
>  	return 0;
>  }
> -- 
> 2.53.0

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

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

* Re: [PATCH v2] iio: imu: st_lsm6dsx: deselect shub page before reading whoami
  2026-07-02 12:09 ` Lorenzo Bianconi
@ 2026-07-02 17:04   ` Jonathan Cameron
  0 siblings, 0 replies; 3+ messages in thread
From: Jonathan Cameron @ 2026-07-02 17:04 UTC (permalink / raw)
  To: Lorenzo Bianconi
  Cc: Andreas Kempe, David Lechner, Nuno Sá, Andy Shevchenko,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org

On Thu, 2 Jul 2026 14:09:50 +0200
Lorenzo Bianconi <lorenzo@kernel.org> wrote:

> > As part of driver initialization, e.g. st_lsm6dsx_init_shub() selects
> > the shub register page using st_lsm6dsx_set_page(). Selecting the shub
> > register page shadows the regular register space so whoami, among other
> > registers, is no longer accessible.
> > 
> > In applications where the IMU is permanently powered separately from the
> > processor, there is a window where a reset of the CPU leaves the IMU in
> > the shub register page. Once this occurs, any subsequent probe attempt
> > fails because of the register shadowing.
> > 
> > Using the ism330dlc, the error typically looks like
> > 
> >     st_lsm6dsx_i2c 3-006a: unsupported whoami [10]
> > 
> > with the unknown whoami read from a reserved register in the shub page.
> > 
> > The reset register is also shadowed by the page select, preventing a
> > reset from recovering the chip.
> > 
> > Unconditionally clear the shub page before the whoami readout to ensure
> > normal register access and allow the initialization to proceed.
> > 
> > Place the fix in st_lsm6dsx_check_whoami() before the whoami check
> > because hw->settings, which st_lsm6dsx_set_page() relies on, is first
> > assigned in that function.
> > 
> > Placing the fix in a more logical place than the whoami check would
> > require a bigger restructuring of the code.
> > 
> > Signed-off-by: Andreas Kempe <andreas.kempe@actia.se>
> > ---
> > 
> >  Changes in v2:
> >    - Drop st_lsm6dsx_get_page() and unconditionally clear the shub page.
> >    - Make the code comment clearer.
> >    - Document the placement rationale in the commit message.
> >    - Link to v1: https://lore.kernel.org/linux-iio/20260604132646.1099072-1-andreas.kempe@actia.se/
> > 
> >  drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 21 +++++++++++++++++++-
> >  1 file changed, 20 insertions(+), 1 deletion(-)  
> 
> Acked-by: Lorenzo Bianconi <lorenzo@kernel.org>
> 
Given I assume we want to backport this, please send an appropriate
Fixes tag in response to this email.

Thanks,

Jonathan

> > 
> > diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> > index 630e2cae6f19..f4edcb73ec8c 100644
> > --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> > +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> > @@ -1712,6 +1712,26 @@ static int st_lsm6dsx_check_whoami(struct st_lsm6dsx_hw *hw, int id,
> >  		return -ENODEV;
> >  	}
> >  
> > +	hw->settings = &st_lsm6dsx_sensor_settings[i];
> > +
> > +	if (hw->settings->shub_settings.page_mux.addr) {
> > +		/*
> > +		 * If the IMU has the shub page selected on init, for example
> > +		 * after a CPU watchdog reset while the page is selected, the
> > +		 * regular register space is shadowed. While the regular
> > +		 * register space is shadowed, the registers needed for
> > +		 * initializing the IMU are not available.
> > +		 *
> > +		 * Unconditionally clear the shub page selection to ensure
> > +		 * normal register access.
> > +		 */
> > +		err = st_lsm6dsx_set_page(hw, false);
> > +		if (err < 0) {
> > +			dev_err(hw->dev, "failed to clear shub page\n");
> > +			return err;
> > +		}
> > +	}
> > +
> >  	err = regmap_read(hw->regmap, ST_LSM6DSX_REG_WHOAMI_ADDR, &data);
> >  	if (err < 0) {
> >  		dev_err(hw->dev, "failed to read whoami register\n");
> > @@ -1724,7 +1744,6 @@ static int st_lsm6dsx_check_whoami(struct st_lsm6dsx_hw *hw, int id,
> >  	}
> >  
> >  	*name = st_lsm6dsx_sensor_settings[i].id[j].name;
> > -	hw->settings = &st_lsm6dsx_sensor_settings[i];
> >  
> >  	return 0;
> >  }
> > -- 
> > 2.53.0  


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

end of thread, other threads:[~2026-07-02 17:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-02 10:41 [PATCH v2] iio: imu: st_lsm6dsx: deselect shub page before reading whoami Andreas Kempe
2026-07-02 12:09 ` Lorenzo Bianconi
2026-07-02 17:04   ` Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox