]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
i2c: cadence: Add shutdown handler
authorAjay Neeli <ajay.neeli@amd.com>
Thu, 30 Apr 2026 05:30:50 +0000 (11:00 +0530)
committerAndi Shyti <andi.shyti@kernel.org>
Tue, 9 Jun 2026 06:30:47 +0000 (08:30 +0200)
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.

Signed-off-by: Ajay Neeli <ajay.neeli@amd.com>
Acked-by: Michal Simek <michal.simek@amd.com>
Reviewed-by: Radhey Shyam Pandey <radhey.shyam.pandey@amd.com>
Signed-off-by: Andi Shyti <andi.shyti@kernel.org>
Link: https://lore.kernel.org/r/20260430053050.3590173-1-ajay.neeli@amd.com
drivers/i2c/busses/i2c-cadence.c

index 0fb728ade92e4ebdfbfa39bc9c0f1cc74173ee50..da8770182a18624647b9400ad060e811567764f2 100644 (file)
@@ -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);