public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] iio: imu: lsm6dsx: Add shutdown callback support for I3C interface
@ 2025-07-21 11:07 Manikanta Guntupalli
  2025-07-21 11:38 ` Andy Shevchenko
  0 siblings, 1 reply; 15+ messages in thread
From: Manikanta Guntupalli @ 2025-07-21 11:07 UTC (permalink / raw)
  To: git, michal.simek, lorenzo, jic23, dlechner, nuno.sa, andy,
	linux-iio, linux-kernel
  Cc: radhey.shyam.pandey, srinivas.goud, manion05gk,
	Manikanta Guntupalli

Add a shutdown handler for the ST LSM6DSx I3C driver to perform a hardware
reset during system shutdown. This ensures the sensor is placed in a
well-defined reset state, preventing issues during subsequent reboots,
such as kexec, where the device may fail to respond correctly during
enumeration.

To support this, the previously static st_lsm6dsx_reset_device() function
is now exported via EXPORT_SYMBOL_NS() under the IIO_LSM6DSX namespace,
allowing it to be invoked from the I3C-specific driver.

Signed-off-by: Manikanta Guntupalli <manikanta.guntupalli@amd.com>
---
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h      |  1 +
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c |  3 ++-
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i3c.c  | 14 ++++++++++++++
 3 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
index c225b246c8a5..42c0dcfbad49 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
@@ -466,6 +466,7 @@ extern const struct dev_pm_ops st_lsm6dsx_pm_ops;
 
 int st_lsm6dsx_probe(struct device *dev, int irq, int hw_id,
 		     struct regmap *regmap);
+int st_lsm6dsx_reset_device(struct st_lsm6dsx_hw *hw);
 int st_lsm6dsx_sensor_set_enable(struct st_lsm6dsx_sensor *sensor,
 				 bool enable);
 int st_lsm6dsx_fifo_setup(struct st_lsm6dsx_hw *hw);
diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
index c65ad49829e7..929b30985d41 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
@@ -2267,7 +2267,7 @@ static int st_lsm6dsx_init_hw_timer(struct st_lsm6dsx_hw *hw)
 	return 0;
 }
 
-static int st_lsm6dsx_reset_device(struct st_lsm6dsx_hw *hw)
+int st_lsm6dsx_reset_device(struct st_lsm6dsx_hw *hw)
 {
 	const struct st_lsm6dsx_reg *reg;
 	int err;
@@ -2302,6 +2302,7 @@ static int st_lsm6dsx_reset_device(struct st_lsm6dsx_hw *hw)
 
 	return 0;
 }
+EXPORT_SYMBOL_NS(st_lsm6dsx_reset_device, "IIO_LSM6DSX");
 
 static int st_lsm6dsx_init_device(struct st_lsm6dsx_hw *hw)
 {
diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i3c.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i3c.c
index cb5c5d7e1f3d..f3d9cdd5a743 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i3c.c
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i3c.c
@@ -41,10 +41,24 @@ static int st_lsm6dsx_i3c_probe(struct i3c_device *i3cdev)
 	return st_lsm6dsx_probe(dev, 0, (uintptr_t)id->data, regmap);
 }
 
+static void st_lsm6dsx_i3c_shutdown(struct device *dev)
+{
+	struct st_lsm6dsx_hw *hw = dev_get_drvdata(dev);
+
+	/*
+	 * Perform device reset to ensure the sensor is in a known
+	 * good state for subsequent re-initialization or power cycles.
+	 * This addresses issues where the sensor might not enumerate
+	 * correctly after a warm reboot (e.g., kexec).
+	 */
+	st_lsm6dsx_reset_device(hw);
+}
+
 static struct i3c_driver st_lsm6dsx_driver = {
 	.driver = {
 		.name = "st_lsm6dsx_i3c",
 		.pm = pm_sleep_ptr(&st_lsm6dsx_pm_ops),
+		.shutdown = st_lsm6dsx_i3c_shutdown,
 	},
 	.probe = st_lsm6dsx_i3c_probe,
 	.id_table = st_lsm6dsx_i3c_ids,
-- 
2.34.1


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

end of thread, other threads:[~2025-09-19 11:18 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-21 11:07 [PATCH] iio: imu: lsm6dsx: Add shutdown callback support for I3C interface Manikanta Guntupalli
2025-07-21 11:38 ` Andy Shevchenko
2025-07-21 11:39   ` Andy Shevchenko
2025-07-22  7:19     ` Guntupalli, Manikanta
2025-09-19 11:10       ` Nuno Sá
2025-07-21 21:01   ` David Lechner
2025-07-22  7:32     ` Guntupalli, Manikanta
2025-07-22  7:56       ` Jorge Marques
2025-07-29 12:02         ` Guntupalli, Manikanta
2025-07-29 12:49           ` Jorge Marques
2025-07-30  6:27             ` Guntupalli, Manikanta
2025-09-05  5:29               ` Guntupalli, Manikanta
2025-09-18  7:22                 ` Mario TESI
2025-09-19  9:22                   ` Guntupalli, Manikanta
2025-09-19 11:18           ` Nuno Sá

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