Skip to contentSkip to conversation

i2c: cadence: Add shutdown handler

PATCH Applied Ajay Neeli 4 participants 4 messages Apr 30 – Jun 9

Subsystems (2)
lore
Share & tools
lore

Ajay Neeli

author
#0 lore raw

PATCH v4 1/1 i2c: cadence: Add shutdown handler

During system reboot or kexec, in-flight I2C transfers can cause spurious interrupts or leave the bus in an undefined state. Add a shutdown handler that marks the adapter suspended and resets the controller, ensuring a clean handoff.

---

Changes v3->v4:
- Replaced disable_irq() with cdns_i2c_master_reset() to avoid potential deadlocks during shutdown
- Added pm_runtime_status_suspended() check to skip register access when clocks are disabled

Changes v2->v3:
Corrected a typo that caused a build error in v2

Changes in v1->v2:
Disable interrupts

---
 drivers/i2c/busses/i2c-cadence.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
drivers/i2c/busses/i2c-cadence.c +20 -0
index 0fb728ade92e..da8770182a18 100644
@@ -1635,6 +1635,25 @@ static void cdns_i2c_remove(struct platform_device *pdev)
 	reset_control_assert(id->reset);
 }
 
+/**
+ * cdns_i2c_shutdown - Prepare I2C controller for system shutdown
+ * @pdev:	Handle to the platform device structure
+ *
+ * Mark the adapter as suspended and reset the controller to ensure a clean
+ * handoff during system reboot or kexec.
+ */
+static void cdns_i2c_shutdown(struct platform_device *pdev)
+{
+	struct cdns_i2c *id = platform_get_drvdata(pdev);
+
+	/* Mark the adapter as suspended to prevent further I2C transfers */
+	i2c_mark_adapter_suspended(&id->adap);
+
+	/* Reset the controller state if active - clocks are disabled when suspended */
+	if (!pm_runtime_status_suspended(&pdev->dev))
+		cdns_i2c_master_reset(&id->adap);
+}
+
 static struct platform_driver cdns_i2c_drv = {
 	.driver = {
 		.name  = DRIVER_NAME,
@@ -1643,6 +1662,7 @@ static struct platform_driver cdns_i2c_drv = {
 	},
 	.probe  = cdns_i2c_probe,
 	.remove = cdns_i2c_remove,
+	.shutdown = cdns_i2c_shutdown,
 };
 
 module_platform_driver(cdns_i2c_drv);
Signature · 1 line
2.43.0
Reviewed-by Radhey Shyam Pandey on v4 1/1
#1 lore raw
Quoted 6 lines

During system reboot or kexec, in-flight I2C transfers can cause spurious interrupts or leave the bus in an undefined state. Add a shutdown handler that marks the adapter suspended and resets the controller, ensuring a clean handoff.

Thanks!

Quoted 56 lines

---

Changes v3->v4:
- Replaced disable_irq() with cdns_i2c_master_reset() to avoid potential deadlocks during shutdown
- Added pm_runtime_status_suspended() check to skip register access when clocks are disabled

Changes v2->v3:
Corrected a typo that caused a build error in v2

Changes in v1->v2:
Disable interrupts

---
  drivers/i2c/busses/i2c-cadence.c | 20 ++++++++++++++++++++
  1 file changed, 20 insertions(+)
drivers/i2c/busses/i2c-cadence.c +20 -0
index 0fb728ade92e..da8770182a18 100644
@@ -1635,6 +1635,25 @@ static void cdns_i2c_remove(struct platform_device *pdev)
  	reset_control_assert(id->reset);
  }
 
+/**
+ * cdns_i2c_shutdown - Prepare I2C controller for system shutdown
+ * @pdev:	Handle to the platform device structure
+ *
+ * Mark the adapter as suspended and reset the controller to ensure a clean
+ * handoff during system reboot or kexec.
+ */
+static void cdns_i2c_shutdown(struct platform_device *pdev)
+{
+	struct cdns_i2c *id = platform_get_drvdata(pdev);
+
+	/* Mark the adapter as suspended to prevent further I2C transfers */
+	i2c_mark_adapter_suspended(&id->adap);
+
+	/* Reset the controller state if active - clocks are disabled when suspended */
+	if (!pm_runtime_status_suspended(&pdev->dev))
+		cdns_i2c_master_reset(&id->adap);
+}
+
  static struct platform_driver cdns_i2c_drv = {
  	.driver = {
  		.name  = DRIVER_NAME,
@@ -1643,6 +1662,7 @@ static struct platform_driver cdns_i2c_drv = {
  	},
  	.probe  = cdns_i2c_probe,
  	.remove = cdns_i2c_remove,
+	.shutdown = cdns_i2c_shutdown,
  };
 
  module_platform_driver(cdns_i2c_drv);
maintainer Applied
#2 lore raw
In reply to Ajay Neeli

Hi Ajay,

Quoted 6 lines · Ajay Neeli

During system reboot or kexec, in-flight I2C transfers can cause spurious interrupts or leave the bus in an undefined state. Add a shutdown handler that marks the adapter suspended and resets the controller, ensuring a clean handoff.

Michal's ack was missing here.

Merged to i2c/i2c-host.

Thanks,
Andi

maintainer
#3 lore raw
Quoted 8 lines · Andi Shyti

Hi Ajay,

Quoted 5 lines · Ajay Neeli

During system reboot or kexec, in-flight I2C transfers can cause spurious interrupts or leave the bus in an undefined state. Add a shutdown handler that marks the adapter suspended and resets the controller, ensuring a clean handoff.

Quoted 5 lines
Quoted 1 line

Michal's ack was missing here.

Merged to i2c/i2c-host.

I have reviewed this patch internally too.
Just checking why I missed it.
Anyway the patch is fine for me.

Thanks,
Michal