diff mbox series

[05/11] soc: imx: gpcv2: add runtime PM support for power-domains

Message ID 20200930155006.535712-6-l.stach@pengutronix.de (mailing list archive)
State New, archived
Headers show
Series i.MX8MM power domain support | expand

Commit Message

Lucas Stach Sept. 30, 2020, 3:50 p.m. UTC
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

Marek Vasut Sept. 30, 2020, 4:14 p.m. UTC | #1
On 9/30/20 5:50 PM, Lucas Stach wrote:
[...]
> @@ -143,11 +144,17 @@ static int imx_pgc_power_up(struct generic_pm_domain *genpd)
>  	u32 reg_val;
>  	int i, 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;
>  		}
>  	}
>  
> @@ -205,6 +212,8 @@ static int imx_pgc_power_up(struct generic_pm_domain *genpd)
>  		clk_disable_unprepare(domain->clk[i]);
>  	if (!IS_ERR(domain->regulator))
>  		regulator_disable(domain->regulator);
> +out_put_pm:
> +	pm_runtime_put(domain->dev);
>  
>  	return ret;
>  }
Shouldn't this be pm_runtime_put_sync() ?
Lucas Stach Sept. 30, 2020, 4:20 p.m. UTC | #2
On Mi, 2020-09-30 at 18:14 +0200, Marek Vasut wrote:
> On 9/30/20 5:50 PM, Lucas Stach wrote:
> [...]
> > @@ -143,11 +144,17 @@ static int imx_pgc_power_up(struct generic_pm_domain *genpd)
> >  	u32 reg_val;
> >  	int i, 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;
> >  		}
> >  	}
> >  
> > @@ -205,6 +212,8 @@ static int imx_pgc_power_up(struct generic_pm_domain *genpd)
> >  		clk_disable_unprepare(domain->clk[i]);
> >  	if (!IS_ERR(domain->regulator))
> >  		regulator_disable(domain->regulator);
> > +out_put_pm:
> > +	pm_runtime_put(domain->dev);
> >  
> >  	return ret;
> >  }
> Shouldn't this be pm_runtime_put_sync() ?

We don't really care when the parent domains powers down, we just care
about it happening sometime, so I guess the code is fine as is, no?

Regards,
Lucas
diff mbox series

Patch

diff --git a/drivers/soc/imx/gpcv2.c b/drivers/soc/imx/gpcv2.c
index 3cfb8b51c23e..5bb7b1cc7c10 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>
@@ -143,11 +144,17 @@  static int imx_pgc_power_up(struct generic_pm_domain *genpd)
 	u32 reg_val;
 	int i, 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;
 		}
 	}
 
@@ -205,6 +212,8 @@  static int imx_pgc_power_up(struct generic_pm_domain *genpd)
 		clk_disable_unprepare(domain->clk[i]);
 	if (!IS_ERR(domain->regulator))
 		regulator_disable(domain->regulator);
+out_put_pm:
+	pm_runtime_put(domain->dev);
 
 	return ret;
 }
@@ -270,6 +279,8 @@  static int imx_pgc_power_down(struct generic_pm_domain *genpd)
 		}
 	}
 
+	pm_runtime_put(domain->dev);
+
 	return 0;
 
 out_clk_disable:
@@ -567,6 +578,8 @@  static int imx_pgc_domain_probe(struct platform_device *pdev)
 		return ret;
 	}
 
+	pm_runtime_enable(domain->dev);
+
 	regmap_update_bits(domain->regmap, GPC_PGC_CPU_MAPPING,
 			   domain->bits.map, domain->bits.map);
 
@@ -590,6 +603,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);
 	imx_pgc_put_clocks(domain);
 
 	return ret;
@@ -605,6 +619,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);
+
 	imx_pgc_put_clocks(domain);
 
 	return 0;