diff mbox series

[v2,07/18] soc: imx: gpcv2: support system suspend/resume

Message ID 20210721204703.1424034-8-l.stach@pengutronix.de
State Superseded
Headers show
Series i.MX8MM GPC improvements and BLK_CTRL driver | expand

Commit Message

Lucas Stach July 21, 2021, 8:46 p.m. UTC
Our usage of runtime PM to control the hierarchy of power domains is
slightly unusual and means that powering up a domain may fail in early
system resume, as runtime PM is still disallowed at this stage.

However the system suspend/resume path takes care of powering down/up
the power domains in the order defined by the device parent/child and
power-domain provider/consumer hierarachy. So we can just runtime
resume all our power-domain devices to allow the power-up to work
properly in the resume path. System suspend will still disable all
domains as intended.

Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
---
 drivers/soc/imx/gpcv2.c | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

Comments

Peng Fan Aug. 5, 2021, 9:47 a.m. UTC | #1
> Subject: [PATCH v2 07/18] soc: imx: gpcv2: support system suspend/resume

> 

> Our usage of runtime PM to control the hierarchy of power domains is slightly

> unusual and means that powering up a domain may fail in early system

> resume, as runtime PM is still disallowed at this stage.

> 

> However the system suspend/resume path takes care of powering down/up

> the power domains in the order defined by the device parent/child and

> power-domain provider/consumer hierarachy. So we can just runtime resume

> all our power-domain devices to allow the power-up to work properly in the

> resume path. System suspend will still disable all domains as intended.

> 

> Signed-off-by: Lucas Stach <l.stach@pengutronix.de>


Acked-by: Peng Fan <peng.fan@nxp.com>


> ---

>  drivers/soc/imx/gpcv2.c | 31 +++++++++++++++++++++++++++++++

>  1 file changed, 31 insertions(+)

> 

> diff --git a/drivers/soc/imx/gpcv2.c b/drivers/soc/imx/gpcv2.c index

> c48f37f203ab..57ed0a6bfb13 100644

> --- a/drivers/soc/imx/gpcv2.c

> +++ b/drivers/soc/imx/gpcv2.c

> @@ -947,6 +947,36 @@ static int imx_pgc_domain_remove(struct

> platform_device *pdev)

>  	return 0;

>  }

> 

> +#ifdef CONFIG_PM_SLEEP

> +static int imx_pgc_domain_suspend(struct device *dev) {

> +	int ret;

> +

> +	/*

> +	 * This may look strange, but is done so the generic PM_SLEEP code

> +	 * can power down our domain and more importantly power it up again

> +	 * after resume, without tripping over our usage of runtime PM to

> +	 * power up/down the nested domains.

> +	 */

> +	ret = pm_runtime_get_sync(dev);

> +	if (ret < 0) {

> +		pm_runtime_put_noidle(dev);

> +		return ret;

> +	}

> +

> +	return 0;

> +}

> +

> +static int imx_pgc_domain_resume(struct device *dev) {

> +	return pm_runtime_put(dev);

> +}

> +#endif

> +

> +static const struct dev_pm_ops imx_pgc_domain_pm_ops = {

> +	SET_SYSTEM_SLEEP_PM_OPS(imx_pgc_domain_suspend,

> imx_pgc_domain_resume)

> +};

> +

>  static const struct platform_device_id imx_pgc_domain_id[] = {

>  	{ "imx-pgc-domain", },

>  	{ },

> @@ -955,6 +985,7 @@ static const struct platform_device_id

> imx_pgc_domain_id[] = {  static struct platform_driver

> imx_pgc_domain_driver = {

>  	.driver = {

>  		.name = "imx-pgc",

> +		.pm = &imx_pgc_domain_pm_ops,

>  	},

>  	.probe    = imx_pgc_domain_probe,

>  	.remove   = imx_pgc_domain_remove,

> --

> 2.30.2
diff mbox series

Patch

diff --git a/drivers/soc/imx/gpcv2.c b/drivers/soc/imx/gpcv2.c
index c48f37f203ab..57ed0a6bfb13 100644
--- a/drivers/soc/imx/gpcv2.c
+++ b/drivers/soc/imx/gpcv2.c
@@ -947,6 +947,36 @@  static int imx_pgc_domain_remove(struct platform_device *pdev)
 	return 0;
 }
 
+#ifdef CONFIG_PM_SLEEP
+static int imx_pgc_domain_suspend(struct device *dev)
+{
+	int ret;
+
+	/*
+	 * This may look strange, but is done so the generic PM_SLEEP code
+	 * can power down our domain and more importantly power it up again
+	 * after resume, without tripping over our usage of runtime PM to
+	 * power up/down the nested domains.
+	 */
+	ret = pm_runtime_get_sync(dev);
+	if (ret < 0) {
+		pm_runtime_put_noidle(dev);
+		return ret;
+	}
+
+	return 0;
+}
+
+static int imx_pgc_domain_resume(struct device *dev)
+{
+	return pm_runtime_put(dev);
+}
+#endif
+
+static const struct dev_pm_ops imx_pgc_domain_pm_ops = {
+	SET_SYSTEM_SLEEP_PM_OPS(imx_pgc_domain_suspend, imx_pgc_domain_resume)
+};
+
 static const struct platform_device_id imx_pgc_domain_id[] = {
 	{ "imx-pgc-domain", },
 	{ },
@@ -955,6 +985,7 @@  static const struct platform_device_id imx_pgc_domain_id[] = {
 static struct platform_driver imx_pgc_domain_driver = {
 	.driver = {
 		.name = "imx-pgc",
+		.pm = &imx_pgc_domain_pm_ops,
 	},
 	.probe    = imx_pgc_domain_probe,
 	.remove   = imx_pgc_domain_remove,