* [PATCH v3] i2c: cadence: Add shutdown handler
@ 2025-07-30 12:29 Ajay Neeli
2025-09-25 12:30 ` Neeli, Ajay
0 siblings, 1 reply; 2+ messages in thread
From: Ajay Neeli @ 2025-07-30 12:29 UTC (permalink / raw)
To: git, andi.shyti, linux-arm-kernel, linux-i2c, linux-kernel
Cc: michal.simek, srinivas.goud, radhey.shyam.pandey, Ajay Neeli
Implement shutdown function for Cadence I2C driver to suspend the bus
during system "reboot" or "shutdown".
Interrupts are disabled in the handler to avoid spurious events when the
driver is in slave mode.
Signed-off-by: Ajay Neeli <ajay.neeli@amd.com>
---
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 | 34 +++++++++++++++++++++++++++-------
1 file changed, 27 insertions(+), 7 deletions(-)
diff --git a/drivers/i2c/busses/i2c-cadence.c b/drivers/i2c/busses/i2c-cadence.c
index 8df63aa..4f033a6 100644
--- a/drivers/i2c/busses/i2c-cadence.c
+++ b/drivers/i2c/busses/i2c-cadence.c
@@ -192,6 +192,7 @@ enum cdns_i2c_slave_state {
* @transfer_size: The maximum number of bytes in one transfer
* @atomic: Mode of transfer
* @err_status_atomic: Error status in atomic mode
+ * @irq: IRQ Number
*/
struct cdns_i2c {
struct device *dev;
@@ -224,6 +225,7 @@ struct cdns_i2c {
unsigned int transfer_size;
bool atomic;
int err_status_atomic;
+ int irq;
};
struct cdns_platform_data {
@@ -1495,7 +1497,7 @@ static int cdns_i2c_probe(struct platform_device *pdev)
{
struct resource *r_mem;
struct cdns_i2c *id;
- int ret, irq;
+ int ret;
const struct of_device_id *match;
id = devm_kzalloc(&pdev->dev, sizeof(*id), GFP_KERNEL);
@@ -1526,9 +1528,9 @@ static int cdns_i2c_probe(struct platform_device *pdev)
if (IS_ERR(id->membase))
return PTR_ERR(id->membase);
- irq = platform_get_irq(pdev, 0);
- if (irq < 0)
- return irq;
+ id->irq = platform_get_irq(pdev, 0);
+ if (id->irq < 0)
+ return id->irq;
id->adap.owner = THIS_MODULE;
id->adap.dev.of_node = pdev->dev.of_node;
@@ -1590,10 +1592,10 @@ static int cdns_i2c_probe(struct platform_device *pdev)
goto err_clk_notifier_unregister;
}
- ret = devm_request_irq(&pdev->dev, irq, cdns_i2c_isr, 0,
+ ret = devm_request_irq(&pdev->dev, id->irq, cdns_i2c_isr, 0,
DRIVER_NAME, id);
if (ret) {
- dev_err(&pdev->dev, "cannot get irq %d\n", irq);
+ dev_err(&pdev->dev, "cannot get irq %d\n", id->irq);
goto err_clk_notifier_unregister;
}
cdns_i2c_init(id);
@@ -1603,7 +1605,7 @@ static int cdns_i2c_probe(struct platform_device *pdev)
goto err_clk_notifier_unregister;
dev_info(&pdev->dev, "%u kHz mmio %08lx irq %d\n",
- id->i2c_clk / 1000, (unsigned long)r_mem->start, irq);
+ id->i2c_clk / 1000, (unsigned long)r_mem->start, id->irq);
return 0;
@@ -1636,6 +1638,23 @@ static void cdns_i2c_remove(struct platform_device *pdev)
reset_control_assert(id->reset);
}
+/**
+ * cdns_i2c_shutdown - Shutdown the i2c device
+ * @pdev: Handle to the platform device structure
+ *
+ * This function handles shutdown sequence
+ */
+static void cdns_i2c_shutdown(struct platform_device *pdev)
+{
+ struct cdns_i2c *id = platform_get_drvdata(pdev);
+
+ /* Disable interrupts */
+ disable_irq(id->irq);
+
+ /* Initiate failure of client i2c transfers */
+ i2c_mark_adapter_suspended(&id->adap);
+}
+
static struct platform_driver cdns_i2c_drv = {
.driver = {
.name = DRIVER_NAME,
@@ -1644,6 +1663,7 @@ static void cdns_i2c_remove(struct platform_device *pdev)
},
.probe = cdns_i2c_probe,
.remove = cdns_i2c_remove,
+ .shutdown = cdns_i2c_shutdown,
};
module_platform_driver(cdns_i2c_drv);
--
1.8.3.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* RE: [PATCH v3] i2c: cadence: Add shutdown handler
2025-07-30 12:29 [PATCH v3] i2c: cadence: Add shutdown handler Ajay Neeli
@ 2025-09-25 12:30 ` Neeli, Ajay
0 siblings, 0 replies; 2+ messages in thread
From: Neeli, Ajay @ 2025-09-25 12:30 UTC (permalink / raw)
To: andi.shyti, Simek, Michal
Cc: Goud, Srinivas, Pandey, Radhey Shyam, Neeli, Ajay,
git (AMD-Xilinx),
linux-arm-kernel, linux-kernel, linux-i2c
[Public]
Ping!
> -----Original Message-----
> From: Ajay Neeli <ajay.neeli@amd.com>
> Sent: Wednesday, July 30, 2025 5:59 PM
> To: git (AMD-Xilinx) <git@amd.com>; andi.shyti@kernel.org; linux-arm-kernel@lists.infradead.org; linux-i2c@vger.kernel.org;
> linux-kernel@vger.kernel.org
> Cc: Simek, Michal <michal.simek@amd.com>; Goud, Srinivas <srinivas.goud@amd.com>; Pandey, Radhey Shyam
> <radhey.shyam.pandey@amd.com>; Neeli, Ajay <Ajay.Neeli@amd.com>
> Subject: [PATCH v3] i2c: cadence: Add shutdown handler
>
> Implement shutdown function for Cadence I2C driver to suspend the bus
> during system "reboot" or "shutdown".
>
> Interrupts are disabled in the handler to avoid spurious events when the
> driver is in slave mode.
>
> Signed-off-by: Ajay Neeli <ajay.neeli@amd.com>
> ---
> 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 | 34 +++++++++++++++++++++++++++-------
> 1 file changed, 27 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/i2c/busses/i2c-cadence.c b/drivers/i2c/busses/i2c-cadence.c
> index 8df63aa..4f033a6 100644
> --- a/drivers/i2c/busses/i2c-cadence.c
> +++ b/drivers/i2c/busses/i2c-cadence.c
> @@ -192,6 +192,7 @@ enum cdns_i2c_slave_state {
> * @transfer_size: The maximum number of bytes in one transfer
> * @atomic: Mode of transfer
> * @err_status_atomic: Error status in atomic mode
> + * @irq: IRQ Number
> */
> struct cdns_i2c {
> struct device *dev;
> @@ -224,6 +225,7 @@ struct cdns_i2c {
> unsigned int transfer_size;
> bool atomic;
> int err_status_atomic;
> + int irq;
> };
>
> struct cdns_platform_data {
> @@ -1495,7 +1497,7 @@ static int cdns_i2c_probe(struct platform_device *pdev)
> {
> struct resource *r_mem;
> struct cdns_i2c *id;
> - int ret, irq;
> + int ret;
> const struct of_device_id *match;
>
> id = devm_kzalloc(&pdev->dev, sizeof(*id), GFP_KERNEL);
> @@ -1526,9 +1528,9 @@ static int cdns_i2c_probe(struct platform_device *pdev)
> if (IS_ERR(id->membase))
> return PTR_ERR(id->membase);
>
> - irq = platform_get_irq(pdev, 0);
> - if (irq < 0)
> - return irq;
> + id->irq = platform_get_irq(pdev, 0);
> + if (id->irq < 0)
> + return id->irq;
>
> id->adap.owner = THIS_MODULE;
> id->adap.dev.of_node = pdev->dev.of_node;
> @@ -1590,10 +1592,10 @@ static int cdns_i2c_probe(struct platform_device *pdev)
> goto err_clk_notifier_unregister;
> }
>
> - ret = devm_request_irq(&pdev->dev, irq, cdns_i2c_isr, 0,
> + ret = devm_request_irq(&pdev->dev, id->irq, cdns_i2c_isr, 0,
> DRIVER_NAME, id);
> if (ret) {
> - dev_err(&pdev->dev, "cannot get irq %d\n", irq);
> + dev_err(&pdev->dev, "cannot get irq %d\n", id->irq);
> goto err_clk_notifier_unregister;
> }
> cdns_i2c_init(id);
> @@ -1603,7 +1605,7 @@ static int cdns_i2c_probe(struct platform_device *pdev)
> goto err_clk_notifier_unregister;
>
> dev_info(&pdev->dev, "%u kHz mmio %08lx irq %d\n",
> - id->i2c_clk / 1000, (unsigned long)r_mem->start, irq);
> + id->i2c_clk / 1000, (unsigned long)r_mem->start, id->irq);
>
> return 0;
>
> @@ -1636,6 +1638,23 @@ static void cdns_i2c_remove(struct platform_device *pdev)
> reset_control_assert(id->reset);
> }
>
> +/**
> + * cdns_i2c_shutdown - Shutdown the i2c device
> + * @pdev: Handle to the platform device structure
> + *
> + * This function handles shutdown sequence
> + */
> +static void cdns_i2c_shutdown(struct platform_device *pdev)
> +{
> + struct cdns_i2c *id = platform_get_drvdata(pdev);
> +
> + /* Disable interrupts */
> + disable_irq(id->irq);
> +
> + /* Initiate failure of client i2c transfers */
> + i2c_mark_adapter_suspended(&id->adap);
> +}
> +
> static struct platform_driver cdns_i2c_drv = {
> .driver = {
> .name = DRIVER_NAME,
> @@ -1644,6 +1663,7 @@ static void cdns_i2c_remove(struct platform_device *pdev)
> },
> .probe = cdns_i2c_probe,
> .remove = cdns_i2c_remove,
> + .shutdown = cdns_i2c_shutdown,
> };
>
> module_platform_driver(cdns_i2c_drv);
> --
> 1.8.3.1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-09-25 12:31 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-07-30 12:29 [PATCH v3] i2c: cadence: Add shutdown handler Ajay Neeli
2025-09-25 12:30 ` Neeli, Ajay
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®