Re: [PATCH 2/2] soc: imx: gpc: Power off PU domain in suspend/resume on 6qp
From: Lucas Stach
Date: Mon Jul 02 2018 - 08:06:01 EST
Am Montag, den 02.07.2018, 14:52 +0300 schrieb Leonard Crestez:
> On imx6qp power gating on the PU domain is disabled because of errata
> ERR009619. However power gating on suspend/resume can still work.
>
> Enable this by calling the on/off functions directly from suspend code in
> mach-imx.
Sorry, but no. Please keep those two parts split. We don't want them to
interact.
What keeps you from using standard system suspend PM ops in the GPC
driver? The domain drivers within the GPC power management code are all
standard platform devices, so can implement PM ops themselves. There is
no need for any of this reaching between different drivers.
Regards,
Lucas
> Signed-off-by: Leonard Crestez <leonard.crestez@xxxxxxx>
>
> ---
> Âarch/arm/mach-imx/gpc.c | 10 +++++++
> Âdrivers/soc/imx/gpc.cÂÂÂ| 58 ++++++++++++++++++++++++++++++-----------
> Â2 files changed, 53 insertions(+), 15 deletions(-)
>
> diff --git a/arch/arm/mach-imx/gpc.c b/arch/arm/mach-imx/gpc.c
> index de535cb679b3..e99258238210 100644
> --- a/arch/arm/mach-imx/gpc.c
> +++ b/arch/arm/mach-imx/gpc.c
> @@ -32,10 +32,14 @@
> Â
> Âstatic void __iomem *gpc_base;
> Âstatic u32 gpc_wake_irqs[IMR_NUM];
> Âstatic u32 gpc_saved_imrs[IMR_NUM];
> Â
> +/* implemented in drivers/soc/imx/gpc.c */
> +extern void _imx6_pm_pu_power_off(void);
> +extern void _imx6_pm_pu_power_on(void);
> +
> Âvoid imx_gpc_set_arm_power_up_timing(u32 sw2iso, u32 sw)
> Â{
> > Â writel_relaxed((sw2iso << GPC_PGC_SW2ISO_SHIFT) |
> > Â (sw << GPC_PGC_SW_SHIFT), gpc_base + GPC_PGC_CPU_PUPSCR);
> Â}
> @@ -54,10 +58,13 @@ void imx_gpc_set_arm_power_in_lpm(bool power_off)
> Âvoid imx_gpc_pre_suspend(bool arm_power_off)
> Â{
> > Â void __iomem *reg_imr1 = gpc_base + GPC_IMR1;
> > Â int i;
> Â
> > + if (cpu_is_imx6q() && imx_get_soc_revision() >= IMX_CHIP_REVISION_2_0)
> > + _imx6_pm_pu_power_off();
> +
> > Â /* Tell GPC to power off ARM core when suspend */
> > Â if (arm_power_off)
> > Â imx_gpc_set_arm_power_in_lpm(arm_power_off);
> Â
> > Â for (i = 0; i < IMR_NUM; i++) {
> @@ -69,10 +76,13 @@ void imx_gpc_pre_suspend(bool arm_power_off)
> Âvoid imx_gpc_post_resume(void)
> Â{
> > Â void __iomem *reg_imr1 = gpc_base + GPC_IMR1;
> > Â int i;
> Â
> > + if (cpu_is_imx6q() && imx_get_soc_revision() >= IMX_CHIP_REVISION_2_0)
> > + _imx6_pm_pu_power_on();
> +
> > Â /* Keep ARM core powered on for other low-power modes */
> > Â imx_gpc_set_arm_power_in_lpm(false);
> Â
> > Â for (i = 0; i < IMR_NUM; i++)
> > Â writel_relaxed(gpc_saved_imrs[i], reg_imr1 + i * 4);
> diff --git a/drivers/soc/imx/gpc.c b/drivers/soc/imx/gpc.c
> index 83cb275592e9..dddc2469eaac 100644
> --- a/drivers/soc/imx/gpc.c
> +++ b/drivers/soc/imx/gpc.c
> @@ -54,19 +54,16 @@ static inline struct imx_pm_domain *
> Âto_imx_pm_domain(struct generic_pm_domain *genpd)
> Â{
> > Â return container_of(genpd, struct imx_pm_domain, base);
> Â}
> Â
> -static int imx6_pm_domain_power_off(struct generic_pm_domain *genpd)
> +static void _imx6_pm_domain_power_off(struct generic_pm_domain *genpd)
> Â{
> > Â struct imx_pm_domain *pd = to_imx_pm_domain(genpd);
> > Â int iso, iso2sw;
> > Â u32 val;
> Â
> > - if (pd->flags & PGC_DOMAIN_FLAG_NO_PD)
> > - return -EBUSY;
> -
> > Â /* Read ISO and ISO2SW power down delays */
> > Â regmap_read(pd->regmap, pd->reg_offs + GPC_PGC_PUPSCR_OFFS, &val);
> > Â iso = val & 0x3f;
> > Â iso2sw = (val >> 8) & 0x3f;
> Â
> @@ -78,32 +75,33 @@ static int imx6_pm_domain_power_off(struct generic_pm_domain *genpd)
> > Â val = BIT(pd->cntr_pdn_bit);
> > Â regmap_update_bits(pd->regmap, GPC_CNTR, val, val);
> Â
> > Â /* Wait ISO + ISO2SW IPG clock cycles */
> > Â udelay(DIV_ROUND_UP(iso + iso2sw, pd->ipg_rate_mhz));
> +}
> +
> +static int imx6_pm_domain_power_off(struct generic_pm_domain *genpd)
> +{
> > + struct imx_pm_domain *pd = to_imx_pm_domain(genpd);
> +
> > + if (to_imx_pm_domain(genpd)->flags & PGC_DOMAIN_FLAG_NO_PD)
> > + return -EBUSY;
> +
> > + _imx6_pm_domain_power_off(genpd);
> Â
> > Â if (pd->supply)
> > Â regulator_disable(pd->supply);
> Â
> > Â return 0;
> Â}
> Â
> -static int imx6_pm_domain_power_on(struct generic_pm_domain *genpd)
> +static void _imx6_pm_domain_power_on(struct generic_pm_domain *genpd)
> Â{
> > Â struct imx_pm_domain *pd = to_imx_pm_domain(genpd);
> > - int i, ret, sw, sw2iso;
> > + int i, sw, sw2iso;
> > Â u32 val;
> Â
> > - if (pd->supply) {
> > - ret = regulator_enable(pd->supply);
> > - if (ret) {
> > - pr_err("%s: failed to enable regulator: %d\n",
> > - ÂÂÂÂÂÂÂ__func__, ret);
> > - return ret;
> > - }
> > - }
> -
> > Â /* Enable reset clocks for all devices in the domain */
> > Â for (i = 0; i < pd->num_clks; i++)
> > Â clk_prepare_enable(pd->clk[i]);
> Â
> > Â /* Gate off domain when powered down */
> @@ -123,10 +121,27 @@ static int imx6_pm_domain_power_on(struct generic_pm_domain *genpd)
> > Â udelay(DIV_ROUND_UP(sw + sw2iso, pd->ipg_rate_mhz));
> Â
> > Â /* Disable reset clocks for all devices in the domain */
> > Â for (i = 0; i < pd->num_clks; i++)
> > Â clk_disable_unprepare(pd->clk[i]);
> +}
> +
> +static int imx6_pm_domain_power_on(struct generic_pm_domain *genpd)
> +{
> > + struct imx_pm_domain *pd = to_imx_pm_domain(genpd);
> > + int ret;
> +
> > + if (pd->supply) {
> > + ret = regulator_enable(pd->supply);
> > + if (ret) {
> > + pr_err("%s: failed to enable regulator: %d\n",
> > + ÂÂÂÂÂÂÂ__func__, ret);
> > + return ret;
> > + }
> > + }
> +
> > + _imx6_pm_domain_power_on(genpd);
> Â
> > Â return 0;
> Â}
> Â
> Âstatic int imx_pgc_get_clocks(struct device *dev, struct imx_pm_domain *domain)
> @@ -337,10 +352,23 @@ static const struct regmap_config imx_gpc_regmap_config = {
> > Â .val_bits = 32,
> > Â .reg_stride = 4,
> > Â .max_register = 0x2ac,
> Â};
> Â
> +/* exported for suspend/resume code in arch/arm/mach-imx/gpc.c */
> +void _imx6_pm_pu_power_off(void)
> +{
> > + _imx6_pm_domain_power_off(&imx_gpc_domains[GPC_PGC_DOMAIN_PU].base);
> +}
> +EXPORT_SYMBOL_GPL(_imx6_pm_pu_power_off);
> +
> +void _imx6_pm_pu_power_on(void)
> +{
> > + _imx6_pm_domain_power_on(&imx_gpc_domains[GPC_PGC_DOMAIN_PU].base);
> +}
> +EXPORT_SYMBOL_GPL(_imx6_pm_pu_power_on);
> +
> Âstatic struct generic_pm_domain *imx_gpc_onecell_domains[] = {
> > Â &imx_gpc_domains[0].base,
> > Â &imx_gpc_domains[1].base,
> Â};
> Â