Skip to contentSkip to conversation

Fixes for new SCPSYS power domains controller driver

PATCH In review Weiyi Lu 2 participants 4 messages Jan 4, 2021 – Jan 11, 2021 Arm MediaTek

lore
Share & tools
lore

Weiyi Lu

author
#0 lore raw

cover Fixes for new SCPSYS power domains controller driver

This patch is base on v5.10-rc1 and
series "Add new driver for SCPSYS power domains controller"[1]

[1] https://patchwork.kernel.org/project/linux-mediatek/list/?series=374013

Weiyi Lu (2):
soc: mediatek: Add regulator control for MT8192 MFG power domain
soc: mediatek: Fix the clock prepared issue

 drivers/soc/mediatek/mt8192-pm-domains.h |  1 +
 drivers/soc/mediatek/mtk-pm-domains.c    | 73 ++++++++++++++++--------
 drivers/soc/mediatek/mtk-pm-domains.h    |  2 +
 3 files changed, 51 insertions(+), 25 deletions(-)
author
#1 lore raw

PATCH 1/2 soc: mediatek: Add regulator control for MT8192 MFG power domain

Add regulator control support and specific power domain name of MT8192 MFG power domain for regulator lookup.
Also power domain name can fix the debugfs warning. (e.g. debugfs: Directory 'power-domain' with parent 'pm_genpd' already present!)
However, not every domain with name need to get the regulator, if we just want to fix the debugfs warning log by adding names to power domains. Considering this case, lookup regulator by regulator_get_optional() instead of getting a dummy regulator from regulator_get() to operate.

---
 drivers/soc/mediatek/mt8192-pm-domains.h |  1 +
 drivers/soc/mediatek/mtk-pm-domains.c    | 42 ++++++++++++++++++++++++++++++--
 drivers/soc/mediatek/mtk-pm-domains.h    |  2 ++
 3 files changed, 43 insertions(+), 2 deletions(-)
drivers/soc/mediatek/mt8192-pm-domains.h +1 -0
index 0fdf6dc..7db0ad3 100644
@@ -49,6 +49,7 @@
 		.ctl_offs = 0x0308,
 		.sram_pdn_bits = GENMASK(8, 8),
 		.sram_pdn_ack_bits = GENMASK(12, 12),
+		.name = "mfg",
 	},
 	[MT8192_POWER_DOMAIN_MFG1] = {
 		.sta_mask = BIT(3),
drivers/soc/mediatek/mtk-pm-domains.c +40 -2

92 lines not on this page · raw message

drivers/soc/mediatek/mtk-pm-domains.h +2 -0
index a2f4d8f..58d72fb 100644
@@ -81,6 +81,7 @@ struct scpsys_bus_prot_data {
  * @caps: The flag for active wake-up action.
  * @bp_infracfg: bus protection for infracfg subsystem
  * @bp_smi: bus protection for smi subsystem
+ * @name: specific power domain name for regulator lookup and debugfs
  */
 struct scpsys_domain_data {
 	u32 sta_mask;
@@ -90,6 +91,7 @@ struct scpsys_domain_data {
 	u8 caps;
 	const struct scpsys_bus_prot_data bp_infracfg[SPM_MAX_BUS_PROT_DATA];
 	const struct scpsys_bus_prot_data bp_smi[SPM_MAX_BUS_PROT_DATA];
+	char *name;
 };
 
 struct scpsys_soc_data {
Signature · 1 line
1.8.1.1.dirty
#2 lore raw

Re: [PATCH 1/2] soc: mediatek: Add regulator control for MT8192 MFG power domain

Quoted 12 lines · Weiyi Lu

Add regulator control support and specific power domain name of MT8192 MFG power domain for regulator lookup.
Also power domain name can fix the debugfs warning. (e.g. debugfs: Directory 'power-domain' with parent 'pm_genpd' already present!)
However, not every domain with name need to get the regulator, if we just want to fix the debugfs warning log by adding names to power domains. Considering this case, lookup regulator by regulator_get_optional() instead of getting a dummy regulator from regulator_get() to operate.

Hi,

sorry I didn't notice this patch before. I sent out a similar patch for this problem here:
https://patchwork.kernel.org/project/linux-mediatek/cover/[email protected]/

The difference is that
1) we store the requirement for quirks in caps instead of name.
2) regulators are under power-domain nodes instead of mfg devices in dts.

Quoted 136 lines
---
 drivers/soc/mediatek/mt8192-pm-domains.h |  1 +
 drivers/soc/mediatek/mtk-pm-domains.c    | 42 ++++++++++++++++++++++++++++++--
 drivers/soc/mediatek/mtk-pm-domains.h    |  2 ++
 3 files changed, 43 insertions(+), 2 deletions(-)
drivers/soc/mediatek/mt8192-pm-domains.h +1 -0
index 0fdf6dc..7db0ad3 100644
@@ -49,6 +49,7 @@
                .ctl_offs = 0x0308,
                .sram_pdn_bits = GENMASK(8, 8),
                .sram_pdn_ack_bits = GENMASK(12, 12),
+               .name = "mfg",
        },
        [MT8192_POWER_DOMAIN_MFG1] = {
                .sta_mask = BIT(3),
drivers/soc/mediatek/mtk-pm-domains.c +40 -2
index fb70cb3..a160800 100644
@@ -13,6 +13,7 @@
 #include <linux/platform_device.h>
 #include <linux/pm_domain.h>
 #include <linux/regmap.h>
+#include <linux/regulator/consumer.h>
 #include <linux/soc/mediatek/infracfg.h>
 
 #include "mt8173-pm-domains.h"
@@ -40,6 +41,7 @@ struct scpsys_domain {
        struct clk_bulk_data *subsys_clks;
        struct regmap *infracfg;
        struct regmap *smi;
+       struct regulator *supply;
 };
 
 struct scpsys {
@@ -187,6 +189,22 @@ static int scpsys_bus_protect_disable(struct scpsys_domain *pd)
        return _scpsys_bus_protect_disable(pd->data->bp_infracfg, pd->infracfg);
 }
 
+static int scpsys_regulator_enable(struct scpsys_domain *pd)
+{
+       if (!pd->supply)
+               return 0;
+
+       return regulator_enable(pd->supply);
+}
+
+static int scpsys_regulator_disable(struct scpsys_domain *pd)
+{
+       if (!pd->supply)
+               return 0;
+
+       return regulator_disable(pd->supply);
+}
+
 static int scpsys_power_on(struct generic_pm_domain *genpd)
 {
        struct scpsys_domain *pd = container_of(genpd, struct scpsys_domain, genpd);
@@ -194,9 +212,13 @@ static int scpsys_power_on(struct generic_pm_domain *genpd)
        bool tmp;
        int ret;
 
+       ret = scpsys_regulator_enable(pd);
+       if (ret < 0)
+               return ret;
+
        ret = clk_bulk_enable(pd->num_clks, pd->clks);
        if (ret)
-               return ret;
+               goto err_disable_regulator;
 
        /* subsys power on */
        regmap_set_bits(scpsys->base, pd->data->ctl_offs, PWR_ON_BIT);
@@ -232,6 +254,8 @@ static int scpsys_power_on(struct generic_pm_domain *genpd)
        clk_bulk_disable(pd->num_subsys_clks, pd->subsys_clks);
 err_pwr_ack:
        clk_bulk_disable(pd->num_clks, pd->clks);
+err_disable_regulator:
+       scpsys_regulator_disable(pd);
        return ret;
 }
 
@@ -267,6 +291,10 @@ static int scpsys_power_off(struct generic_pm_domain *genpd)
 
        clk_bulk_disable(pd->num_clks, pd->clks);
 
+       ret = scpsys_regulator_disable(pd);
+       if (ret < 0)
+               return ret;
+
        return 0;
 }
 
@@ -315,6 +343,16 @@ generic_pm_domain *scpsys_add_one_domain(struct scpsys *scpsys, struct device_no
        if (IS_ERR(pd->smi))
                return ERR_CAST(pd->smi);
 
+       if (pd->data->name) {
+               pd->supply = devm_regulator_get_optional(scpsys->dev, pd->data->name);
+               if (IS_ERR(pd->supply)) {
+                       if (PTR_ERR(pd->supply) == -ENODEV)
+                               pd->supply = NULL;
+                       else
+                               return ERR_CAST(pd->supply);
+               }
+       }
+
        num_clks = of_clk_get_parent_count(node);
        if (num_clks > 0) {
                /* Calculate number of subsys_clks */
@@ -397,7 +435,7 @@ generic_pm_domain *scpsys_add_one_domain(struct scpsys *scpsys, struct device_no
                goto err_unprepare_subsys_clocks;
        }
 
-       pd->genpd.name = node->name;
+       pd->genpd.name = pd->data->name ?: node->name;
        pd->genpd.power_off = scpsys_power_off;
        pd->genpd.power_on = scpsys_power_on;
 
drivers/soc/mediatek/mtk-pm-domains.h +1 -0
index a2f4d8f..58d72fb 100644
@@ -81,6 +81,7 @@ struct scpsys_bus_prot_data {
  * @caps: The flag for active wake-up action.
  * @bp_infracfg: bus protection for infracfg subsystem
  * @bp_smi: bus protection for smi subsystem
+ * @name: specific power domain name for regulator lookup and debugfs
  */
 struct scpsys_domain_data {
        u32 sta_mask;

drivers/soc/mediatek/mtk-pm-domains.h struct scpsys_domain_data { · line 97

Quoted 7 lines
drivers/soc/mediatek/mtk-pm-domains.h +1 -0
@@ -90,6 +91,7 @@ struct scpsys_domain_data {
        u8 caps;
        const struct scpsys_bus_prot_data bp_infracfg[SPM_MAX_BUS_PROT_DATA];
        const struct scpsys_bus_prot_data bp_smi[SPM_MAX_BUS_PROT_DATA];
+       char *name;
 };
 
 struct scpsys_soc_data {

_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek

author
#3 lore raw

PATCH 2/2 soc: mediatek: Fix the clock prepared issue

In reply to Weiyi Lu

In this new power domain driver, when adding one power domain it will prepare the depenedent clocks at the same.
So we only do clk_bulk_enable/disable control during power ON/OFF. When system suspend, the pm runtime framework will forcely power off power domains. However, the dependent clocks are disabled but kept preapred.

In MediaTek clock drivers, PLL would be turned ON when we do clk_bulk_prepare control.

Clock hierarchy:
PLL -->
DIV_CK -->
CLK_MUX
(may be dependent clocks)
-->
SUBSYS_CG
(may be dependent clocks)

It will lead some unexpected clock states during system suspend. This patch will fix by doing prepare_enable/disable_unprepare on dependent clocks at the same time while we are going to power on/off any power domain.

---
 drivers/soc/mediatek/mtk-pm-domains.c | 31 ++++++++-----------------------
 1 file changed, 8 insertions(+), 23 deletions(-)
drivers/soc/mediatek/mtk-pm-domains.c +8 -23
index a160800..f0bcc84 100644
@@ -216,7 +216,7 @@ static int scpsys_power_on(struct generic_pm_domain *genpd)
 	if (ret < 0)
 		return ret;
 
-	ret = clk_bulk_enable(pd->num_clks, pd->clks);
+	ret = clk_bulk_prepare_enable(pd->num_clks, pd->clks);
 	if (ret)
 		goto err_disable_regulator;
 
@@ -234,7 +234,7 @@ static int scpsys_power_on(struct generic_pm_domain *genpd)
 	regmap_clear_bits(scpsys->base, pd->data->ctl_offs, PWR_ISO_BIT);
 	regmap_set_bits(scpsys->base, pd->data->ctl_offs, PWR_RST_B_BIT);
 
-	ret = clk_bulk_enable(pd->num_subsys_clks, pd->subsys_clks);
+	ret = clk_bulk_prepare_enable(pd->num_subsys_clks, pd->subsys_clks);
 	if (ret)
 		goto err_pwr_ack;
 
@@ -251,9 +251,9 @@ static int scpsys_power_on(struct generic_pm_domain *genpd)
 err_disable_sram:
 	scpsys_sram_disable(pd);
 err_disable_subsys_clks:
-	clk_bulk_disable(pd->num_subsys_clks, pd->subsys_clks);
+	clk_bulk_disable_unprepare(pd->num_subsys_clks, pd->subsys_clks);
 err_pwr_ack:
-	clk_bulk_disable(pd->num_clks, pd->clks);
+	clk_bulk_disable_unprepare(pd->num_clks, pd->clks);
 err_disable_regulator:
 	scpsys_regulator_disable(pd);
 	return ret;
@@ -274,7 +274,7 @@ static int scpsys_power_off(struct generic_pm_domain *genpd)
 	if (ret < 0)
 		return ret;
 
-	clk_bulk_disable(pd->num_subsys_clks, pd->subsys_clks);
+	clk_bulk_disable_unprepare(pd->num_subsys_clks, pd->subsys_clks);
 
 	/* subsys power off */
 	regmap_clear_bits(scpsys->base, pd->data->ctl_offs, PWR_RST_B_BIT);
@@ -289,7 +289,7 @@ static int scpsys_power_off(struct generic_pm_domain *genpd)
 	if (ret < 0)
 		return ret;
 
-	clk_bulk_disable(pd->num_clks, pd->clks);
+	clk_bulk_disable_unprepare(pd->num_clks, pd->clks);
 
 	ret = scpsys_regulator_disable(pd);
 	if (ret < 0)
@@ -402,14 +402,6 @@ generic_pm_domain *scpsys_add_one_domain(struct scpsys *scpsys, struct device_no
 		pd->subsys_clks[i].clk = clk;
 	}
 
-	ret = clk_bulk_prepare(pd->num_clks, pd->clks);
-	if (ret)
-		goto err_put_subsys_clocks;
-
-	ret = clk_bulk_prepare(pd->num_subsys_clks, pd->subsys_clks);
-	if (ret)
-		goto err_unprepare_clocks;
-
 	/*
 	 * Initially turn on all domains to make the domains usable
 	 * with !CONFIG_PM and to get the hardware in sync with the
@@ -424,7 +416,7 @@ generic_pm_domain *scpsys_add_one_domain(struct scpsys *scpsys, struct device_no
 		ret = scpsys_power_on(&pd->genpd);
 		if (ret < 0) {
 			dev_err(scpsys->dev, "%pOF: failed to power on domain: %d\n", node, ret);
-			goto err_unprepare_clocks;
+			goto err_put_subsys_clocks;
 		}
 	}
 
@@ -432,7 +424,7 @@ generic_pm_domain *scpsys_add_one_domain(struct scpsys *scpsys, struct device_no
 		ret = -EINVAL;
 		dev_err(scpsys->dev,
 			"power domain with id %d already exists, check your device-tree\n", id);
-		goto err_unprepare_subsys_clocks;
+		goto err_put_subsys_clocks;
 	}
 
 	pd->genpd.name = pd->data->name ?: node->name;
@@ -448,10 +440,6 @@ generic_pm_domain *scpsys_add_one_domain(struct scpsys *scpsys, struct device_no
 
 	return scpsys->pd_data.domains[id];
 
-err_unprepare_subsys_clocks:
-	clk_bulk_unprepare(pd->num_subsys_clks, pd->subsys_clks);
-err_unprepare_clocks:
-	clk_bulk_unprepare(pd->num_clks, pd->clks);
 err_put_subsys_clocks:
 	clk_bulk_put(pd->num_subsys_clks, pd->subsys_clks);
 err_put_clocks:
@@ -529,10 +517,7 @@ static void scpsys_remove_one_domain(struct scpsys_domain *pd)
 			"failed to remove domain '%s' : %d - state may be inconsistent\n",
 			pd->genpd.name, ret);
 
-	clk_bulk_unprepare(pd->num_clks, pd->clks);
 	clk_bulk_put(pd->num_clks, pd->clks);
-
-	clk_bulk_unprepare(pd->num_subsys_clks, pd->subsys_clks);
 	clk_bulk_put(pd->num_subsys_clks, pd->subsys_clks);
 }
 
Signature · 1 line
1.8.1.1.dirty