linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Weiyi Lu <weiyi.lu@mediatek.com>
To: Enric Balletbo Serra <eballetbo@gmail.com>,
	Matthias Brugger <matthias.bgg@gmail.com>,
	Nicolas Boichat <drinkcat@chromium.org>
Cc: <linux-arm-kernel@lists.infradead.org>,
	<linux-kernel@vger.kernel.org>,
	<linux-mediatek@lists.infradead.org>,
	<srv_heupstream@mediatek.com>,
	<Project_Global_Chrome_Upstream_Group@mediatek.com>,
	Weiyi Lu <weiyi.lu@mediatek.com>
Subject: [PATCH 1/2] soc: mediatek: Add regulator control for MT8192 MFG power domain
Date: Mon, 4 Jan 2021 18:44:52 +0800	[thread overview]
Message-ID: <1609757093-30618-2-git-send-email-weiyi.lu@mediatek.com> (raw)
In-Reply-To: <1609757093-30618-1-git-send-email-weiyi.lu@mediatek.com>

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.

Signed-off-by: Weiyi Lu <weiyi.lu@mediatek.com>
---
 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(-)

diff --git a/drivers/soc/mediatek/mt8192-pm-domains.h b/drivers/soc/mediatek/mt8192-pm-domains.h
index 0fdf6dc..7db0ad3 100644
--- a/drivers/soc/mediatek/mt8192-pm-domains.h
+++ b/drivers/soc/mediatek/mt8192-pm-domains.h
@@ -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),
diff --git a/drivers/soc/mediatek/mtk-pm-domains.c b/drivers/soc/mediatek/mtk-pm-domains.c
index fb70cb3..a160800 100644
--- a/drivers/soc/mediatek/mtk-pm-domains.c
+++ b/drivers/soc/mediatek/mtk-pm-domains.c
@@ -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;
 
diff --git a/drivers/soc/mediatek/mtk-pm-domains.h b/drivers/soc/mediatek/mtk-pm-domains.h
index a2f4d8f..58d72fb 100644
--- a/drivers/soc/mediatek/mtk-pm-domains.h
+++ b/drivers/soc/mediatek/mtk-pm-domains.h
@@ -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 {
-- 
1.8.1.1.dirty


  reply	other threads:[~2021-01-04 10:45 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-04 10:44 [PATCH 0/2] Fixes for new SCPSYS power domains controller driver Weiyi Lu
2021-01-04 10:44 ` Weiyi Lu [this message]
2021-01-11  7:07   ` [PATCH 1/2] soc: mediatek: Add regulator control for MT8192 MFG power domain Hsin-Yi Wang
2021-01-04 10:44 ` [PATCH 2/2] soc: mediatek: Fix the clock prepared issue Weiyi Lu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1609757093-30618-2-git-send-email-weiyi.lu@mediatek.com \
    --to=weiyi.lu@mediatek.com \
    --cc=Project_Global_Chrome_Upstream_Group@mediatek.com \
    --cc=drinkcat@chromium.org \
    --cc=eballetbo@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=matthias.bgg@gmail.com \
    --cc=srv_heupstream@mediatek.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).