diff mbox series

[06/16] soc: imx: gpcv2: add runtime PM support for power-domains

Message ID 20210429073050.21039-7-peng.fan@oss.nxp.com
State Superseded
Headers show
Series soc: imx: gpcv2: support i.MX8MM | expand

Commit Message

Peng Fan (OSS) April 29, 2021, 7:30 a.m. UTC
From: Lucas Stach <l.stach@pengutronix.de>

This allows to nest domains into other power domains and have the
parent domain powered up/down as required by the child domains.

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

Comments

Frieder Schrempf May 3, 2021, 2:18 p.m. UTC | #1
On 29.04.21 09:30, Peng Fan (OSS) wrote:
> From: Lucas Stach <l.stach@pengutronix.de>

> 

> This allows to nest domains into other power domains and have the

> parent domain powered up/down as required by the child domains.

> 

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


With the fix from patch 13/16 squashed:

Reviewed-by: Frieder Schrempf <frieder.schrempf@kontron.de>


> ---

>   drivers/soc/imx/gpcv2.c | 18 +++++++++++++++++-

>   1 file changed, 17 insertions(+), 1 deletion(-)

> 

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

> index d27025e37a9e..87165619a689 100644

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

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

> @@ -12,6 +12,7 @@

>   #include <linux/of_device.h>

>   #include <linux/platform_device.h>

>   #include <linux/pm_domain.h>

> +#include <linux/pm_runtime.h>

>   #include <linux/regmap.h>

>   #include <linux/regulator/consumer.h>

>   #include <linux/sizes.h>

> @@ -141,11 +142,17 @@ static int imx_pgc_power_up(struct generic_pm_domain *genpd)

>   	u32 reg_val;

>   	int ret;

>   

> +	ret = pm_runtime_get_sync(domain->dev);

> +	if (ret) {

> +		pm_runtime_put_noidle(domain->dev);

> +		return ret;

> +	}

> +

>   	if (!IS_ERR(domain->regulator)) {

>   		ret = regulator_enable(domain->regulator);

>   		if (ret) {

>   			dev_err(domain->dev, "failed to enable regulator\n");

> -			return ret;

> +			goto out_put_pm;

>   		}

>   	}

>   

> @@ -200,6 +207,8 @@ static int imx_pgc_power_up(struct generic_pm_domain *genpd)

>   out_regulator_disable:

>   	if (!IS_ERR(domain->regulator))

>   		regulator_disable(domain->regulator);

> +out_put_pm:

> +	pm_runtime_put(domain->dev);

>   

>   	return ret;

>   }

> @@ -262,6 +271,8 @@ static int imx_pgc_power_down(struct generic_pm_domain *genpd)

>   		}

>   	}

>   

> +	pm_runtime_put(domain->dev);

> +

>   	return 0;

>   

>   out_clk_disable:

> @@ -519,6 +530,8 @@ static int imx_pgc_domain_probe(struct platform_device *pdev)

>   		return dev_err_probe(domain->dev, domain->num_clks,

>   				     "Failed to get domain's clocks\n");

>   

> +	pm_runtime_enable(domain->dev);

> +

>   	regmap_update_bits(domain->regmap, GPC_PGC_CPU_MAPPING,

>   			   domain->bits.map, domain->bits.map);

>   

> @@ -542,6 +555,7 @@ static int imx_pgc_domain_probe(struct platform_device *pdev)

>   out_domain_unmap:

>   	regmap_update_bits(domain->regmap, GPC_PGC_CPU_MAPPING,

>   			   domain->bits.map, 0);

> +	pm_runtime_disable(domain->dev);

>   

>   	return ret;

>   }

> @@ -556,6 +570,8 @@ static int imx_pgc_domain_remove(struct platform_device *pdev)

>   	regmap_update_bits(domain->regmap, GPC_PGC_CPU_MAPPING,

>   			   domain->bits.map, 0);

>   

> +	pm_runtime_disable(domain->dev);

> +

>   	return 0;

>   }

>   

>
diff mbox series

Patch

diff --git a/drivers/soc/imx/gpcv2.c b/drivers/soc/imx/gpcv2.c
index d27025e37a9e..87165619a689 100644
--- a/drivers/soc/imx/gpcv2.c
+++ b/drivers/soc/imx/gpcv2.c
@@ -12,6 +12,7 @@ 
 #include <linux/of_device.h>
 #include <linux/platform_device.h>
 #include <linux/pm_domain.h>
+#include <linux/pm_runtime.h>
 #include <linux/regmap.h>
 #include <linux/regulator/consumer.h>
 #include <linux/sizes.h>
@@ -141,11 +142,17 @@  static int imx_pgc_power_up(struct generic_pm_domain *genpd)
 	u32 reg_val;
 	int ret;
 
+	ret = pm_runtime_get_sync(domain->dev);
+	if (ret) {
+		pm_runtime_put_noidle(domain->dev);
+		return ret;
+	}
+
 	if (!IS_ERR(domain->regulator)) {
 		ret = regulator_enable(domain->regulator);
 		if (ret) {
 			dev_err(domain->dev, "failed to enable regulator\n");
-			return ret;
+			goto out_put_pm;
 		}
 	}
 
@@ -200,6 +207,8 @@  static int imx_pgc_power_up(struct generic_pm_domain *genpd)
 out_regulator_disable:
 	if (!IS_ERR(domain->regulator))
 		regulator_disable(domain->regulator);
+out_put_pm:
+	pm_runtime_put(domain->dev);
 
 	return ret;
 }
@@ -262,6 +271,8 @@  static int imx_pgc_power_down(struct generic_pm_domain *genpd)
 		}
 	}
 
+	pm_runtime_put(domain->dev);
+
 	return 0;
 
 out_clk_disable:
@@ -519,6 +530,8 @@  static int imx_pgc_domain_probe(struct platform_device *pdev)
 		return dev_err_probe(domain->dev, domain->num_clks,
 				     "Failed to get domain's clocks\n");
 
+	pm_runtime_enable(domain->dev);
+
 	regmap_update_bits(domain->regmap, GPC_PGC_CPU_MAPPING,
 			   domain->bits.map, domain->bits.map);
 
@@ -542,6 +555,7 @@  static int imx_pgc_domain_probe(struct platform_device *pdev)
 out_domain_unmap:
 	regmap_update_bits(domain->regmap, GPC_PGC_CPU_MAPPING,
 			   domain->bits.map, 0);
+	pm_runtime_disable(domain->dev);
 
 	return ret;
 }
@@ -556,6 +570,8 @@  static int imx_pgc_domain_remove(struct platform_device *pdev)
 	regmap_update_bits(domain->regmap, GPC_PGC_CPU_MAPPING,
 			   domain->bits.map, 0);
 
+	pm_runtime_disable(domain->dev);
+
 	return 0;
 }