2023-12-09 03:11:13

by Ji Sheng Teoh

[permalink] [raw]
Subject: [PATCH v1] i2c: cadence: Add system suspend and resume PM support

Enable device system suspend and resume PM support, and mark the device
state as suspended during system suspend to reject any data transfer.

Signed-off-by: Ji Sheng Teoh <[email protected]>
---
drivers/i2c/busses/i2c-cadence.c | 33 ++++++++++++++++++++++++++++++++
1 file changed, 33 insertions(+)

diff --git a/drivers/i2c/busses/i2c-cadence.c b/drivers/i2c/busses/i2c-cadence.c
index de3f58b60dce..c42d6afded2a 100644
--- a/drivers/i2c/busses/i2c-cadence.c
+++ b/drivers/i2c/busses/i2c-cadence.c
@@ -1176,6 +1176,18 @@ static int __maybe_unused cdns_i2c_runtime_suspend(struct device *dev)
return 0;
}

+static int __maybe_unused cdns_i2c_suspend(struct device *dev)
+{
+ struct cdns_i2c *xi2c = dev_get_drvdata(dev);
+
+ i2c_mark_adapter_suspended(&xi2c->adap);
+
+ if (!pm_runtime_status_suspended(dev))
+ return cdns_i2c_runtime_suspend(dev);
+
+ return 0;
+}
+
/**
* cdns_i2c_init - Controller initialisation
* @id: Device private data structure
@@ -1219,7 +1231,28 @@ static int __maybe_unused cdns_i2c_runtime_resume(struct device *dev)
return 0;
}

+static int __maybe_unused cdns_i2c_resume(struct device *dev)
+{
+ struct cdns_i2c *xi2c = dev_get_drvdata(dev);
+ int err;
+
+ err = cdns_i2c_runtime_resume(dev);
+ if (err)
+ return err;
+
+ if (pm_runtime_status_suspended(dev)) {
+ cdns_i2c_runtime_suspend(dev);
+ if (err)
+ return err;
+ }
+
+ i2c_mark_adapter_resumed(&xi2c->adap);
+
+ return 0;
+}
+
static const struct dev_pm_ops cdns_i2c_dev_pm_ops = {
+ SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(cdns_i2c_suspend, cdns_i2c_resume)
SET_RUNTIME_PM_OPS(cdns_i2c_runtime_suspend,
cdns_i2c_runtime_resume, NULL)
};
--
2.25.1


2023-12-09 13:01:58

by Andi Shyti

[permalink] [raw]
Subject: Re: [PATCH v1] i2c: cadence: Add system suspend and resume PM support

Hi Ji Sheng,

[...]

> +static int __maybe_unused cdns_i2c_resume(struct device *dev)
> +{
> + struct cdns_i2c *xi2c = dev_get_drvdata(dev);
> + int err;
> +
> + err = cdns_i2c_runtime_resume(dev);
> + if (err)
> + return err;
> +
> + if (pm_runtime_status_suspended(dev)) {
> + cdns_i2c_runtime_suspend(dev);
> + if (err)
> + return err;

have you forgotten to assign 'err'?

Andi

> + }

2023-12-09 13:07:52

by Ji Sheng Teoh

[permalink] [raw]
Subject: Re: [PATCH v1] i2c: cadence: Add system suspend and resume PM support

On Sat, 9 Dec 2023 14:01:40 +0100
Andi Shyti <[email protected]> wrote:

> Hi Ji Sheng,
>
> [...]
>
> > +static int __maybe_unused cdns_i2c_resume(struct device *dev)
> > +{
> > + struct cdns_i2c *xi2c = dev_get_drvdata(dev);
> > + int err;
> > +
> > + err = cdns_i2c_runtime_resume(dev);
> > + if (err)
> > + return err;
> > +
> > + if (pm_runtime_status_suspended(dev)) {
> > + cdns_i2c_runtime_suspend(dev);
> > + if (err)
> > + return err;
>
> have you forgotten to assign 'err'?
>
> Andi
>
> > + }

My bad, I will fix it in v2. Thanks Andi.