mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Changhuang Liang <changhuang.liang@starfivetech.com>
To: Rob Herring <robh+dt@kernel.org>,
	Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
	Emil Renner Berthing <kernel@esmil.dk>,
	Conor Dooley <conor@kernel.org>,
	Paul Walmsley <paul.walmsley@sifive.com>,
	Palmer Dabbelt <palmer@dabbelt.com>,
	Albert Ou <aou@eecs.berkeley.edu>
Cc: Walker Chen <walker.chen@starfivetech.com>,
	Changhuang Liang <changhuang.liang@starfivetech.com>,
	<devicetree@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<linux-riscv@lists.infradead.org>
Subject: [PATCH v1 6/7] soc: starfive: Add dphy pmu support
Date: Mon, 10 Apr 2023 23:47:42 -0700	[thread overview]
Message-ID: <20230411064743.273388-7-changhuang.liang@starfivetech.com> (raw)
In-Reply-To: <20230411064743.273388-1-changhuang.liang@starfivetech.com>

Add dphy pmu to turn on/off the dphy power switch.

Signed-off-by: Changhuang Liang <changhuang.liang@starfivetech.com>
---
 MAINTAINERS                       |  1 +
 drivers/soc/starfive/jh71xx_pmu.c | 65 +++++++++++++++++++++++++++++++
 2 files changed, 66 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 0b2170e1e4ff..4d958f02403e 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -19944,6 +19944,7 @@ F:	include/dt-bindings/reset/starfive?jh71*.h
 
 STARFIVE JH71XX PMU CONTROLLER DRIVER
 M:	Walker Chen <walker.chen@starfivetech.com>
+M:	Changhuang Liang <changhuang.liang@starfivetech.com>
 S:	Supported
 F:	Documentation/devicetree/bindings/power/starfive*
 F:	drivers/soc/starfive/jh71xx_pmu.c
diff --git a/drivers/soc/starfive/jh71xx_pmu.c b/drivers/soc/starfive/jh71xx_pmu.c
index 990db6735c48..d4092ca4dccf 100644
--- a/drivers/soc/starfive/jh71xx_pmu.c
+++ b/drivers/soc/starfive/jh71xx_pmu.c
@@ -24,6 +24,9 @@
 #define JH71XX_PMU_EVENT_STATUS		0x88
 #define JH71XX_PMU_INT_STATUS		0x8C
 
+/* DPHY pmu register offset */
+#define JH71XX_PMU_DPHY_SWITCH		0x00
+
 /* sw encourage cfg */
 #define JH71XX_PMU_SW_ENCOURAGE_EN_LO	0x05
 #define JH71XX_PMU_SW_ENCOURAGE_EN_HI	0x50
@@ -94,6 +97,8 @@ static int jh71xx_pmu_get_state(struct jh71xx_pmu_dev *pmd, u32 mask, bool *is_o
 
 	if (pmu->match_data->pmu_type == JH71XX_PMU_GENERAL)
 		offset = JH71XX_PMU_CURR_POWER_MODE;
+	else if (pmu->match_data->pmu_type == JH71XX_PMU_DPHY)
+		offset = JH71XX_PMU_DPHY_SWITCH;
 
 	regmap_read(pmu->base, offset, &val);
 
@@ -170,6 +175,23 @@ static int jh71xx_pmu_general_set_state(struct jh71xx_pmu_dev *pmd, u32 mask, bo
 	return 0;
 }
 
+static int jh71xx_pmu_dphy_set_state(struct jh71xx_pmu_dev *pmd, u32 mask, bool on)
+{
+	struct jh71xx_pmu *pmu = pmd->pmu;
+	unsigned long flags;
+
+	spin_lock_irqsave(&pmu->lock, flags);
+
+	if (on)
+		regmap_update_bits(pmu->base, JH71XX_PMU_DPHY_SWITCH, mask, mask);
+	else
+		regmap_update_bits(pmu->base, JH71XX_PMU_DPHY_SWITCH, mask, 0);
+
+	spin_unlock_irqrestore(&pmu->lock, flags);
+
+	return 0;
+}
+
 static int jh71xx_pmu_set_state(struct jh71xx_pmu_dev *pmd, u32 mask, bool on)
 {
 	struct jh71xx_pmu *pmu = pmd->pmu;
@@ -191,6 +213,8 @@ static int jh71xx_pmu_set_state(struct jh71xx_pmu_dev *pmd, u32 mask, bool on)
 
 	if (pmu->match_data->pmu_type == JH71XX_PMU_GENERAL)
 		ret = jh71xx_pmu_general_set_state(pmd, mask, on);
+	else if (pmu->match_data->pmu_type == JH71XX_PMU_DPHY)
+		ret = jh71xx_pmu_dphy_set_state(pmd, mask, on);
 
 	return ret;
 }
@@ -280,6 +304,25 @@ static int jh7110_pmu_general_parse_dt(struct platform_device *pdev,
 	return 0;
 }
 
+static int jh7110_pmu_dphy_parse_dt(struct platform_device *pdev,
+				    struct jh71xx_pmu *pmu)
+{
+	struct device *parent;
+	struct device *dev = &pdev->dev;
+
+	parent = pdev->dev.parent;
+	if (!parent) {
+		dev_err(dev, "No parent for syscon pmu\n");
+		return -ENODEV;
+	}
+
+	pmu->base = syscon_node_to_regmap(parent->of_node);
+	if (IS_ERR(pmu->base))
+		return PTR_ERR(pmu->base);
+
+	return 0;
+}
+
 static int jh71xx_pmu_init_domain(struct jh71xx_pmu *pmu, int index)
 {
 	struct jh71xx_pmu_dev *pmd;
@@ -409,10 +452,31 @@ static const struct jh71xx_pmu_match_data jh7110_pmu = {
 	.pmu_parse_dt = jh7110_pmu_general_parse_dt,
 };
 
+static const struct jh71xx_domain_info jh7110_dphy_power_domains[] = {
+	[JH7110_PD_DPHY_TX] = {
+		.name = "DPHY-TX",
+		.bit = 30,
+	},
+	[JH7110_PD_DPHY_RX] = {
+		.name = "DPHY-RX",
+		.bit = 31,
+	},
+};
+
+static const struct jh71xx_pmu_match_data jh7110_pmu_dphy = {
+	.num_domains = ARRAY_SIZE(jh7110_dphy_power_domains),
+	.domain_info = jh7110_dphy_power_domains,
+	.pmu_type = JH71XX_PMU_DPHY,
+	.pmu_parse_dt = jh7110_pmu_dphy_parse_dt,
+};
+
 static const struct of_device_id jh71xx_pmu_of_match[] = {
 	{
 		.compatible = "starfive,jh7110-pmu",
 		.data = (void *)&jh7110_pmu,
+	}, {
+		.compatible = "starfive,jh7110-pmu-dphy",
+		.data = (void *)&jh7110_pmu_dphy,
 	}, {
 		/* sentinel */
 	}
@@ -429,5 +493,6 @@ static struct platform_driver jh71xx_pmu_driver = {
 builtin_platform_driver(jh71xx_pmu_driver);
 
 MODULE_AUTHOR("Walker Chen <walker.chen@starfivetech.com>");
+MODULE_AUTHOR("Changhuang Liang <changhuang.liang@starfivetech.com>");
 MODULE_DESCRIPTION("StarFive JH71XX PMU Driver");
 MODULE_LICENSE("GPL");
-- 
2.25.1


  parent reply	other threads:[~2023-04-11  6:48 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-11  6:47 [PATCH v1 0/7] Add JH7110 DPHY PMU support Changhuang Liang
2023-04-11  6:47 ` [PATCH v1 1/7] dt-bindings: power: Constrain properties for JH7110 PMU Changhuang Liang
2023-04-11 20:13   ` Conor Dooley
2023-04-12  2:51     ` Changhuang Liang
2023-04-12  8:35   ` Krzysztof Kozlowski
2023-04-12  8:51     ` Changhuang Liang
2023-04-12  9:42       ` Conor Dooley
2023-04-12 11:29         ` Krzysztof Kozlowski
2023-04-13  2:11           ` Changhuang Liang
2023-04-14  2:20           ` Changhuang Liang
2023-04-17 18:55             ` Conor Dooley
2023-04-18  1:38               ` Changhuang Liang
2023-04-14  6:27           ` Conor Dooley
2023-04-11  6:47 ` [PATCH v1 2/7] soc: starfive: Replace SOC_STARFIVE with ARCH_SATRFIVE Changhuang Liang
2023-04-11 20:13   ` Conor Dooley
2023-04-12  2:11   ` Walker Chen
2023-04-12  2:52     ` Changhuang Liang
2023-04-11  6:47 ` [PATCH v1 3/7] soc: starfive: Modify ioremap to regmap Changhuang Liang
2023-04-11 20:26   ` Conor Dooley
2023-04-12  3:03     ` Changhuang Liang
2023-04-11  6:47 ` [PATCH v1 4/7] soc: starfive: Add pmu type operation Changhuang Liang
2023-04-11 20:52   ` Conor Dooley
2023-04-12  6:42     ` Changhuang Liang
2023-04-11  6:47 ` [PATCH v1 5/7] soc: starfive: Use call back to parse device tree resources Changhuang Liang
2023-04-11 21:06   ` Conor Dooley
2023-04-12  7:52     ` Changhuang Liang
2023-04-12  6:07   ` Walker Chen
2023-04-12  6:27     ` Conor Dooley
2023-04-11  6:47 ` Changhuang Liang [this message]
2023-04-11 21:15   ` [PATCH v1 6/7] soc: starfive: Add dphy pmu support Conor Dooley
2023-04-12  7:31     ` Changhuang Liang
2023-04-12  8:19     ` Changhuang Liang
2023-04-11  6:47 ` [PATCH v1 7/7] riscv: dts: starfive: Add dphy rx pmu node Changhuang Liang
2023-04-11 20:09 ` [PATCH v1 0/7] Add JH7110 DPHY PMU support Conor Dooley

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=20230411064743.273388-7-changhuang.liang@starfivetech.com \
    --to=changhuang.liang@starfivetech.com \
    --cc=aou@eecs.berkeley.edu \
    --cc=conor@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=kernel@esmil.dk \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=palmer@dabbelt.com \
    --cc=paul.walmsley@sifive.com \
    --cc=robh+dt@kernel.org \
    --cc=walker.chen@starfivetech.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

all inboxes | Powered by JetHome®