Skip to contentSkip to conversation

JH7110 PMU Support

PATCH Superseded Walker Chen 5 participants 11 messages Jan 16, 2023 – Jan 18, 2023

Subsystems (4)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
author maintainer
#7 lore raw

PATCH v3 3/3 riscv: dts: starfive: add pmu controller node

In reply to Walker Chen

Add the pmu controller node for the Starfive JH7110 SoC. The PMU needs to be used by other modules such as VPU, ISP, etc.

---
 arch/riscv/boot/dts/starfive/jh7110.dtsi | 7 +++++++
 1 file changed, 7 insertions(+)
arch/riscv/boot/dts/starfive/jh7110.dtsi +7 -0
index 64d260ea1f29..d0d95ef7aa1a 100644
@@ -407,5 +407,12 @@
 			gpio-controller;
 			#gpio-cells = <2>;
 		};
+
+		pwrc: power-controller@17030000 {
+			compatible = "starfive,jh7110-pmu";
+			reg = <0x0 0x17030000 0x0 0x10000>;
+			interrupts = <111>;
+			#power-domain-cells = <1>;
+		};
 	};
 };
Signature · 1 line
2.17.1
author maintainer
#4 lore raw

PATCH v3 2/3 soc: starfive: Add StarFive JH71XX pmu driver

In reply to Walker Chen

Add pmu driver for the StarFive JH71XX SoC.

As the power domains provider, the Power Management Unit (PMU) is designed for including multiple PM domains that can be used for power gating of selected IP blocks for power saving by reduced leakage current. It accepts software encourage command to switch the power mode of SoC.

---
 MAINTAINERS                       |  14 ++
 drivers/soc/Kconfig               |   1 +
 drivers/soc/Makefile              |   1 +
 drivers/soc/starfive/Kconfig      |  12 +
 drivers/soc/starfive/Makefile     |   3 +
 drivers/soc/starfive/jh71xx_pmu.c | 384 ++++++++++++++++++++++++++++++
 6 files changed, 415 insertions(+)
 create mode 100644 drivers/soc/starfive/Kconfig
 create mode 100644 drivers/soc/starfive/Makefile
 create mode 100644 drivers/soc/starfive/jh71xx_pmu.c
MAINTAINERS +14 -0
index 85e8f83161d7..84fd7054cb6e 100644
@@ -19659,6 +19659,20 @@ F:	Documentation/devicetree/bindings/reset/starfive,jh7100-reset.yaml
 F:	drivers/reset/starfive/reset-starfive-jh71*
 F:	include/dt-bindings/reset/starfive?jh71*.h
 
+STARFIVE SOC DRIVER
+M:	Conor Dooley <[email protected]>
+S:	Maintained
+T:	git https://git.kernel.org/pub/scm/linux/kernel/git/conor/linux.git/
+F:	drivers/soc/starfive/
+F:	include/soc/starfive/
+
+STARFIVE JH71XX PMU CONTROLLER DRIVER
+M:	Walker Chen <[email protected]>
+S:	Supported
+F:	Documentation/devicetree/bindings/power/starfive*
+F:	drivers/soc/starfive/jh71xx_pmu.c
+F:	include/dt-bindings/power/starfive,jh7110-pmu.h
+
 STATIC BRANCH/CALL
 M:	Peter Zijlstra <[email protected]>
 M:	Josh Poimboeuf <[email protected]>
drivers/soc/Kconfig +1 -0
index e461c071189b..628fda4d5ed9 100644
@@ -21,6 +21,7 @@ source "drivers/soc/renesas/Kconfig"
 source "drivers/soc/rockchip/Kconfig"
 source "drivers/soc/samsung/Kconfig"
 source "drivers/soc/sifive/Kconfig"
+source "drivers/soc/starfive/Kconfig"
 source "drivers/soc/sunxi/Kconfig"
 source "drivers/soc/tegra/Kconfig"
 source "drivers/soc/ti/Kconfig"
drivers/soc/Makefile +1 -0
index 534669840858..cbe076f42068 100644
@@ -27,6 +27,7 @@ obj-y				+= renesas/
 obj-y				+= rockchip/
 obj-$(CONFIG_SOC_SAMSUNG)	+= samsung/
 obj-y				+= sifive/
+obj-y				+= starfive/
 obj-y				+= sunxi/
 obj-$(CONFIG_ARCH_TEGRA)	+= tegra/
 obj-y				+= ti/
drivers/soc/starfive/Kconfig new file +12 -0
new file mode 100644
index 000000000000..bdb96dc4c989
@@ -0,0 +1,12 @@
+# SPDX-License-Identifier: GPL-2.0
+
+config JH71XX_PMU
+	bool "Support PMU for StarFive JH71XX Soc"
+	depends on PM
+	depends on SOC_STARFIVE || COMPILE_TEST
+	default SOC_STARFIVE
+	select PM_GENERIC_DOMAINS
+	help
+	  Say 'y' here to enable support power domain support.
+	  In order to meet low power requirements, a Power Management Unit (PMU)
+	  is designed for controlling power resources in StarFive JH71XX SoCs.
drivers/soc/starfive/Makefile new file +3 -0
new file mode 100644
index 000000000000..13b589d6b5f3
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+obj-$(CONFIG_JH71XX_PMU)	+= jh71xx_pmu.o
drivers/soc/starfive/jh71xx_pmu.c new file +384 -0

384 lines not on this page · raw message

Signature · 1 line
2.17.1
author maintainer
#1 lore raw

PATCH v3 1/3 dt-bindings: power: Add starfive,jh7110-pmu

In reply to Walker Chen

Add bindings for the Power Management Unit on the StarFive JH7110 SoC.

---
 .../bindings/power/starfive,jh7110-pmu.yaml   | 45 +++++++++++++++++++
 .../dt-bindings/power/starfive,jh7110-pmu.h   | 17 +++++++
 2 files changed, 62 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/power/starfive,jh7110-pmu.yaml
 create mode 100644 include/dt-bindings/power/starfive,jh7110-pmu.h
Documentation/devicetree/bindings/power/starfive,jh7110-pmu.yaml new file +45 -0
new file mode 100644
index 000000000000..98eb8b4110e7
@@ -0,0 +1,45 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/power/starfive,jh7110-pmu.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: StarFive JH7110 Power Management Unit
+
+maintainers:
+  - Walker Chen <[email protected]>
+
+description: |
+  StarFive JH7110 SoC includes support for multiple power domains which can be
+  powered on/off by software based on different application scenes to save power.
+
+properties:
+  compatible:
+    enum:
+      - starfive,jh7110-pmu
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  "#power-domain-cells":
+    const: 1
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - "#power-domain-cells"
+
+additionalProperties: false
+
+examples:
+  - |
+    pwrc: power-controller@17030000 {
+        compatible = "starfive,jh7110-pmu";
+        reg = <0x17030000 0x10000>;
+        interrupts = <111>;
+        #power-domain-cells = <1>;
+    };
include/dt-bindings/power/starfive,jh7110-pmu.h new file +17 -0
new file mode 100644
index 000000000000..132bfe401fc8
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */
+/*
+ * Copyright (C) 2022 StarFive Technology Co., Ltd.
+ * Author: Walker Chen <[email protected]>
+ */
+#ifndef __DT_BINDINGS_POWER_JH7110_POWER_H__
+#define __DT_BINDINGS_POWER_JH7110_POWER_H__
+
+#define JH7110_PD_SYSTOP	0
+#define JH7110_PD_CPU		1
+#define JH7110_PD_GPUA		2
+#define JH7110_PD_VDEC		3
+#define JH7110_PD_VOUT		4
+#define JH7110_PD_ISP		5
+#define JH7110_PD_VENC		6
+
+#endif
Signature · 1 line
2.17.1

Walker Chen

author maintainer
#0 lore raw

v3 cover JH7110 PMU Support

Hello,

This patchset adds PMU (Power Management Unit) controller driver for the StarFive JH7110 SoC. In order to meet low power requirements, PMU is designed for including multiple PM domains that can be used for power gating of selected IP blocks for power saving by reduced leakage current. The first patch adds device tree binding for PM domain provider and consumer. The second patch adds pmu driver and support JH7110 SoC. The last patch adds device node about pmu to JH7110 dts.

The series has been tested on the VisionFive 2 boards which equip with JH7110 SoC and works normally.

The last patch should be applied after the following patchset:
https://lore.kernel.org/all/[email protected]/

Changes in v3:
- Rebased on tag v6.1.
- Renamed the dt-bindings 'starfive,jh71xx-power.yaml' to 'starfive,jh7110-pmu.yaml' which is matching compatible.
- Fixed wrong indentation and error when running 'make dt_binding_check' in dt-bindings.
- Changed the license of the dt-bindings header to be same with dt-bindings.
- Changed a little bit on dependency conditions in Kconfig of driver.
- Dropped some macros that are temporarily useless.
- Simplified the definition of macro 'JH71XX_PMU_INT_ALL_MASK'.
- Changed the sorting of structure members, such as 'struct jh71xx_domain_info', 'struct jh71xx_pmu', etc.
- Modified detailed comment about controlling power domain.
- Dropped useless comment when running 'platform_get_irq'.

v2 - https://lore.kernel.org/all/[email protected]/

Changes in v2:
- Squashed 1st patch (dt-bindings header) into 2nd which is related to dt-bindings stuff.
- Renamed the dt-bindings header 'jh7110-power.h' to 'starfive,jh7110-pmu.h' and used dual license for it.
- Renamed the dt-bindings 'starfive,jh71xx-power.yaml' to 'starfive,jh71xx-pmu.yaml', dropped items from properties.
- Change of MAINTAINERS: added the entry of 'starfive soc drivers'; changed status to 'Supported' for the entry of
'STARFIVE JH71XX PMU CONTROLLER DRIVER' and sorted the lines alphabetically.
- Dropped the header file 'include/soc/starfive/pm_domains.h'.
- Dropped starfive_pmu_hw_event_turn_on() and starfive_pmu_hw_event_turn_off().
- Added 'default SOC_STARFIVE' and expanded help text in the Kconfig.
- Added a JH71XX_PMU_ prefix to those macro definitions in driver.
- Replaced the data type 'uint8_t / uint32_t' with 'u8 / u32'.
- Fixed some complains by using checkpatch.pl
- Added spinlock to jh71xx_pmu_int_enable().
- Dropped spinlock from jh71xx_pmu_interrupt().
- Used jh71xx_pmu_ as prefix to all functions.
- Replaced io accessors '__raw_readl / __raw_writel' with 'readl / writel'.
- Added jh71xx_pmu_get_state() to the beginning of jh71xx_pmu_set_state().
- Added more detailed comment about controlling power domain.
- Simplified the usage of loop when performing pm_genpd_init() to register power domain.
- Added more detailed description about the features of power domain hardware to commit message in 2nd patch.
- Replaced dev_info() with dev_dbg() in jh71xx_pmu_set_state().
- Decreased the timeout numbers of polling power status when switching power mode.

v1 - https://lore.kernel.org/all/[email protected]/

Best regards,
Walker

Walker Chen (3):
dt-bindings: power: Add starfive,jh7110-pmu
soc: starfive: Add StarFive JH71XX pmu driver
riscv: dts: starfive: add pmu controller node

 .../bindings/power/starfive,jh7110-pmu.yaml   |  45 ++
 MAINTAINERS                                   |  14 +
 arch/riscv/boot/dts/starfive/jh7110.dtsi      |   7 +
 drivers/soc/Kconfig                           |   1 +
 drivers/soc/Makefile                          |   1 +
 drivers/soc/starfive/Kconfig                  |  12 +
 drivers/soc/starfive/Makefile                 |   3 +
 drivers/soc/starfive/jh71xx_pmu.c             | 384 ++++++++++++++++++
 .../dt-bindings/power/starfive,jh7110-pmu.h   |  17 +
 9 files changed, 484 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/power/starfive,jh7110-pmu.yaml
 create mode 100644 drivers/soc/starfive/Kconfig
 create mode 100644 drivers/soc/starfive/Makefile
 create mode 100644 drivers/soc/starfive/jh71xx_pmu.c
 create mode 100644 include/dt-bindings/power/starfive,jh7110-pmu.h

base-commit: 830b3c68c1fb1e9176028d02ef86f3cf76aa2476
prerequisite-patch-id: 54ce870d6ea747466474b5d4105cfbc05e1b01ab
prerequisite-patch-id: e8dd8258a4c4062eee2cf07c4607d52baea71f3a
prerequisite-patch-id: 057fa35870d8d7d22a57c13362588ffb9e9df316
prerequisite-patch-id: 102368a6ff799c4cb639aed513deff09c1839161
prerequisite-patch-id: 7c1a50a37919fedbbd336ca5dec295ac63c2a89d
prerequisite-patch-id: a5d9e0f7d4f8163f566678894cf693015119f2d9
prerequisite-patch-id: 87cb528acd9a7f1ffe7475d7261553f6a4de5753
prerequisite-patch-id: 417736eb958e1158c60a5ed74bc2350394321a80
prerequisite-patch-id: a137312ca162b5712e28719f77d0da78e9fdd778
prerequisite-patch-id: f7c548b4619f491ce27f319242c4e3685c76173b
prerequisite-patch-id: 4d90febab2fb7928f50a73104e7454312b9ce6c8
prerequisite-patch-id: 645a807d50e0e56593ffdc6c3b50ea54a230827a
prerequisite-patch-id: 165f8cd740ae60585d22c95b99a0689084d468e3
prerequisite-patch-id: 480d910deccadc2947b3318c3c13dfa0882c8e0d
prerequisite-patch-id: 1d1cb90ec12dfc9312e448759c7cab89f2bc6394
prerequisite-patch-id: 5f539ac7c96023b36489c6da7c70c31eaf64a25b
prerequisite-patch-id: 6bb9a780c62af3bcc2368dfd20303c7b1bc91e23
prerequisite-patch-id: 258ea5f9b8bf41b6981345dcc81795f25865d38f
prerequisite-patch-id: 8b6f2c9660c0ac0ee4e73e4c21aca8e6b75e81b9
prerequisite-patch-id: e3b986b9c60b2b93b7812ec174c9e1b4cfb14c97
prerequisite-patch-id: 2e03eeb766aefd5d38f132d091618e9fa19a37b6
prerequisite-patch-id: e0ba7af0f8d3d41844da9fbcba14b548cbc18f55
prerequisite-patch-id: c1f8603e58c64828d0f36deac9b93c24289d8e05

Signature · 1 line
2.17.1
maintainer Reviewed-by on the v3 series
#8 lore raw

Hey Walker,

Quoted 10 lines · Walker Chen

Hello,

This patchset adds PMU (Power Management Unit) controller driver for the StarFive JH7110 SoC. In order to meet low power requirements, PMU is designed for including multiple PM domains that can be used for power gating of selected IP blocks for power saving by reduced leakage current. The first patch adds device tree binding for PM domain provider and consumer. The second patch adds pmu driver and support JH7110 SoC. The last patch adds device node about pmu to JH7110 dts.

Quoted 2 lines

The series has been tested on the VisionFive 2 boards which equip with JH7110 SoC and works normally.

For the series:

I'm hoping that someone with knowledge of the power APIs will take a look now that the driver looks to be in a pretty good state (to my naive eyes at least).

Quoted 2 lines

Changes in v3:
- Rebased on tag v6.1.

FYI, please pick something more recent than that.
Ideally, the last -rc1, which in this case is v6.2-rc1.
It's helpful to do this, as when I went to apply your patch, there were some conflicts that needed to be sorted out. Because of your prerequisite patches, the usual b4 commands would not usable. E.g.

b4 am -3 [email protected] Analyzing 4 messages in the thread
Checking attestation on all messages, may take a moment...
---
[PATCH v3 1/3] dt-bindings: power: Add starfive,jh7110-pmu [PATCH v3 2/3] soc: starfive: Add StarFive JH71XX pmu driver [PATCH v3 3/3] riscv: dts: starfive: add pmu controller node
---
Total patches: 3
Preparing fake-am for v3: JH7110 PMU Support
ERROR: Could not find matching blob for MAINTAINERS (85e8f83161d7)
If you know on which tree this patchset is based, add it as a remote and perform "git remote update" in order to fetch the missing objects.

Fortunately, this is just a driver addition so despite b4 not helping it was easy to resolve but for other patches in the future, this may not be the case.

Assuming the dt maintainers are happy with the binding, ping me in 2 weeks if no-one else has commented and I'll apply patches 1 & 2.

Thanks,
Conor.

Quoted 24 lines

base-commit: 830b3c68c1fb1e9176028d02ef86f3cf76aa2476
prerequisite-patch-id: 54ce870d6ea747466474b5d4105cfbc05e1b01ab
prerequisite-patch-id: e8dd8258a4c4062eee2cf07c4607d52baea71f3a
prerequisite-patch-id: 057fa35870d8d7d22a57c13362588ffb9e9df316
prerequisite-patch-id: 102368a6ff799c4cb639aed513deff09c1839161
prerequisite-patch-id: 7c1a50a37919fedbbd336ca5dec295ac63c2a89d
prerequisite-patch-id: a5d9e0f7d4f8163f566678894cf693015119f2d9
prerequisite-patch-id: 87cb528acd9a7f1ffe7475d7261553f6a4de5753
prerequisite-patch-id: 417736eb958e1158c60a5ed74bc2350394321a80
prerequisite-patch-id: a137312ca162b5712e28719f77d0da78e9fdd778
prerequisite-patch-id: f7c548b4619f491ce27f319242c4e3685c76173b
prerequisite-patch-id: 4d90febab2fb7928f50a73104e7454312b9ce6c8
prerequisite-patch-id: 645a807d50e0e56593ffdc6c3b50ea54a230827a
prerequisite-patch-id: 165f8cd740ae60585d22c95b99a0689084d468e3
prerequisite-patch-id: 480d910deccadc2947b3318c3c13dfa0882c8e0d
prerequisite-patch-id: 1d1cb90ec12dfc9312e448759c7cab89f2bc6394
prerequisite-patch-id: 5f539ac7c96023b36489c6da7c70c31eaf64a25b
prerequisite-patch-id: 6bb9a780c62af3bcc2368dfd20303c7b1bc91e23
prerequisite-patch-id: 258ea5f9b8bf41b6981345dcc81795f25865d38f
prerequisite-patch-id: 8b6f2c9660c0ac0ee4e73e4c21aca8e6b75e81b9
prerequisite-patch-id: e3b986b9c60b2b93b7812ec174c9e1b4cfb14c97
prerequisite-patch-id: 2e03eeb766aefd5d38f132d091618e9fa19a37b6
prerequisite-patch-id: e0ba7af0f8d3d41844da9fbcba14b548cbc18f55
prerequisite-patch-id: c1f8603e58c64828d0f36deac9b93c24289d8e05

author maintainer
#9 lore raw
Quoted 23 lines · Conor Dooley

Hey Walker,

Quoted 10 lines · Walker Chen

Hello,

This patchset adds PMU (Power Management Unit) controller driver for the StarFive JH7110 SoC. In order to meet low power requirements, PMU is designed for including multiple PM domains that can be used for power gating of selected IP blocks for power saving by reduced leakage current. The first patch adds device tree binding for PM domain provider and consumer. The second patch adds pmu driver and support JH7110 SoC. The last patch adds device node about pmu to JH7110 dts.

Quoted 2 lines

The series has been tested on the VisionFive 2 boards which equip with JH7110 SoC and works normally.

For the series:

I'm hoping that someone with knowledge of the power APIs will take a look now that the driver looks to be in a pretty good state (to my naive eyes at least).

Quoted 5 lines
Quoted 2 lines

Changes in v3:
- Rebased on tag v6.1.

FYI, please pick something more recent than that. Ideally, the last -rc1, which in this case is v6.2-rc1.

OK, the next version will be rebased to the latest kernel.

Quoted 19 lines

It's helpful to do this, as when I went to apply your patch, there were some conflicts that needed to be sorted out. Because of your prerequisite patches, the usual b4 commands would not usable. E.g.

b4 am -3 [email protected] Analyzing 4 messages in the thread
Checking attestation on all messages, may take a moment...
---
[PATCH v3 1/3] dt-bindings: power: Add starfive,jh7110-pmu [PATCH v3 2/3] soc: starfive: Add StarFive JH71XX pmu driver [PATCH v3 3/3] riscv: dts: starfive: add pmu controller node
---
Total patches: 3
Preparing fake-am for v3: JH7110 PMU Support
ERROR: Could not find matching blob for MAINTAINERS (85e8f83161d7)
If you know on which tree this patchset is based, add it as a remote and perform "git remote update" in order to fetch the missing objects.

Quoted 6 lines

Fortunately, this is just a driver addition so despite b4 not helping it was easy to resolve but for other patches in the future, this may not be the case.

Assuming the dt maintainers are happy with the binding, ping me in 2 weeks if no-one else has commented and I'll apply patches 1 & 2.

Could I drop patch 3 and rebase patch 1 & 2 on the latest mainline then submit as v4 ?

Best regards,
Walker

#10 lore raw

Hey Walker,

Quoted 21 lines · Walker Chen
Quoted 19 lines · Conor Dooley

It's helpful to do this, as when I went to apply your patch, there were some conflicts that needed to be sorted out. Because of your prerequisite patches, the usual b4 commands would not usable. E.g.

b4 am -3 [email protected] Analyzing 4 messages in the thread
Checking attestation on all messages, may take a moment...
---
[PATCH v3 1/3] dt-bindings: power: Add starfive,jh7110-pmu [PATCH v3 2/3] soc: starfive: Add StarFive JH71XX pmu driver [PATCH v3 3/3] riscv: dts: starfive: add pmu controller node
---
Total patches: 3
Preparing fake-am for v3: JH7110 PMU Support
ERROR: Could not find matching blob for MAINTAINERS (85e8f83161d7)
If you know on which tree this patchset is based, add it as a remote and perform "git remote update" in order to fetch the missing objects.

Quoted 8 lines
Quoted 6 lines

Fortunately, this is just a driver addition so despite b4 not helping it was easy to resolve but for other patches in the future, this may not be the case.

Assuming the dt maintainers are happy with the binding, ping me in 2 weeks if no-one else has commented and I'll apply patches 1 & 2.

Could I drop patch 3 and rebase patch 1 & 2 on the latest mainline then submit as v4 ?

I dunno, if someone has the pre-requisites then they should be okay, but I need to apply 1 & 2 without the pre-requisites.
I dropped patch 3 & did the rebase myself so that the build bots would be able to build the patches:
https://git.kernel.org/pub/scm/linux/kernel/git/conor/linux.git/log/?h=riscv-jh7110_pmu
I got the build success email this morning, so they appear happy with it.

I would wait for some comments from the dt maintainers on patch 1 before considering re-sending the series. If they have comments, then please do rebase on v6.2

Thanks,
Conor.

Reviewed-by on v3 2/3
#5 lore raw

Re: [PATCH v3 2/3] soc: starfive: Add StarFive JH71XX pmu driver

In reply to Walker Chen

Hi Walker,

Am Montag, 16. Januar 2023, 08:42:58 CET schrieb Walker Chen:

drivers/soc/starfive/jh71xx_pmu.c line 80

Quoted 6 lines
drivers/soc/starfive/jh71xx_pmu.c new file +6 -0
+static int jh71xx_pmu_get_state(struct jh71xx_pmu_dev *pmd, u32 mask, bool *is_on)
+{
+	struct jh71xx_pmu *pmu = pmd->pmu;
+
+	if (!mask) {
+		*is_on = false;

nit: While it's not necessarily bad, I don't think callers of jh71xx_pmu_get_state() should expect this to be set in error case.

Quoted 7 lines
drivers/soc/starfive/jh71xx_pmu.c new file +7 -0
+		return -EINVAL;
+	}
+
+	*is_on = readl(pmu->base + JH71XX_PMU_CURR_POWER_MODE) & mask;
+
+	return 0;
+}

[...]

Quoted 49 lines
drivers/soc/starfive/jh71xx_pmu.c new file +49 -0
+static int jh71xx_pmu_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct device_node *np = dev->of_node;
+	const struct jh71xx_pmu_match_data *match_data;
+	struct jh71xx_pmu *pmu;
+	unsigned int i;
+	int ret;
+
+	pmu = devm_kzalloc(dev, sizeof(*pmu), GFP_KERNEL);
+	if (!pmu)
+		return -ENOMEM;
+
+	pmu->base = devm_platform_ioremap_resource(pdev, 0);
+	if (IS_ERR(pmu->base))
+		return PTR_ERR(pmu->base);
+
+	pmu->irq = platform_get_irq(pdev, 0);
+	if (pmu->irq < 0)
+		return pmu->irq;
+
+	ret = devm_request_irq(dev, pmu->irq, jh71xx_pmu_interrupt,
+			       0, pdev->name, pmu);
+	if (ret)
+		dev_err(dev, "failed to request irq\n");
+
+	match_data = of_device_get_match_data(dev);
+	if (!match_data)
+		return -EINVAL;
+
+	pmu->genpd = devm_kcalloc(dev, match_data->num_domains,
+				  sizeof(struct generic_pm_domain *),
+				  GFP_KERNEL);
+	if (!pmu->genpd)
+		return -ENOMEM;
+
+	pmu->dev = dev;
+	pmu->match_data = match_data;
+	pmu->genpd_data.domains = pmu->genpd;
+	pmu->genpd_data.num_domains = match_data->num_domains;
+
+	for (i = 0; i < match_data->num_domains; i++) {
+		ret = jh71xx_pmu_init_domain(pmu, i);
+		if (ret) {
+			dev_err(dev, "failed to initialize power domain\n");
+			return ret;
+		}
+	}
+

drivers/soc/starfive/jh71xx_pmu.c line 321

Quoted 10 lines
drivers/soc/starfive/jh71xx_pmu.c new file +10 -0
+	spin_lock_init(&pmu->lock);
+	jh71xx_pmu_int_enable(pmu, JH71XX_PMU_INT_ALL_MASK & ~JH71XX_PMU_INT_PCH_FAIL, true);
+
+	ret = of_genpd_add_provider_onecell(np, &pmu->genpd_data);
+	if (ret) {
+		dev_err(dev, "failed to register genpd driver: %d\n", ret);
+		return ret;
+	}
+
+	dev_info(dev, "registered %u power domains\n", i);

nit: I guess that could be a dev_dbg to not spam the kernel log too much?

Quoted 44 lines
drivers/soc/starfive/jh71xx_pmu.c new file +44 -0
+	return 0;
+}
+
+static const struct jh71xx_domain_info jh7110_power_domains[] = {
+	[JH7110_PD_SYSTOP] = {
+		.name = "SYSTOP",
+		.bit = 0,
+		.flags = GENPD_FLAG_ALWAYS_ON,
+	},
+	[JH7110_PD_CPU] = {
+		.name = "CPU",
+		.bit = 1,
+		.flags = GENPD_FLAG_ALWAYS_ON,
+	},
+	[JH7110_PD_GPUA] = {
+		.name = "GPUA",
+		.bit = 2,
+	},
+	[JH7110_PD_VDEC] = {
+		.name = "VDEC",
+		.bit = 3,
+	},
+	[JH7110_PD_VOUT] = {
+		.name = "VOUT",
+		.bit = 4,
+	},
+	[JH7110_PD_ISP] = {
+		.name = "ISP",
+		.bit = 5,
+	},
+	[JH7110_PD_VENC] = {
+		.name = "VENC",
+		.bit = 6,
+	},
+};
+
+static const struct jh71xx_pmu_match_data jh7110_pmu = {
+	.num_domains = ARRAY_SIZE(jh7110_power_domains),
+	.domain_info = jh7110_power_domains,
+};
+
+static const struct of_device_id jh71xx_pmu_of_match[] = {
+	{
+		.compatible = "starfive,jh7110-pmu",

drivers/soc/starfive/jh71xx_pmu.c line 376

Quoted 10 lines
drivers/soc/starfive/jh71xx_pmu.c new file +10 -0
+		.data = (void *)&jh7110_pmu,
+	}, {
+		/* sentinel */
+	}
+};
+
+static struct platform_driver jh71xx_pmu_driver = {
+	.driver = {
+		.name = "jh71xx-pmu",
+		.of_match_table = jh71xx_pmu_of_match,

In the rockchip pm-domains driver we have

/*
* We can't forcibly eject devices from the power
* domain, so we can't really remove power domains
* once they were added.
*/
.suppress_bind_attrs = true,

here, which might be valid for your pmu driver as well.

Other than that

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

Reviewed-by on v3 1/3
#2 lore raw

Re: [PATCH v3 1/3] dt-bindings: power: Add starfive,jh7110-pmu

In reply to Walker Chen
Quoted 10 lines · Walker Chen

Add bindings for the Power Management Unit on the StarFive JH7110 SoC.

---
 .../bindings/power/starfive,jh7110-pmu.yaml   | 45 +++++++++++++++++++
 .../dt-bindings/power/starfive,jh7110-pmu.h   | 17 +++++++
 2 files changed, 62 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/power/starfive,jh7110-pmu.yaml
 create mode 100644 include/dt-bindings/power/starfive,jh7110-pmu.h

Best regards,
Krzysztof

author maintainer
#6 lore raw

Re: [PATCH v3 2/3] soc: starfive: Add StarFive JH71XX pmu driver

In reply to Heiko Stübner
Quoted 12 lines · Heiko Stübner

Hi Walker,

Am Montag, 16. Januar 2023, 08:42:58 CET schrieb Walker Chen:

drivers/soc/starfive/jh71xx_pmu.c line 80

Quoted 6 lines
drivers/soc/starfive/jh71xx_pmu.c new file +6 -0
+static int jh71xx_pmu_get_state(struct jh71xx_pmu_dev *pmd, u32 mask, bool *is_on)
+{
+	struct jh71xx_pmu *pmu = pmd->pmu;
+
+	if (!mask) {
+		*is_on = false;

nit: While it's not necessarily bad, I don't think callers of jh71xx_pmu_get_state() should expect this to be set in error case.

Maybe setting 'is_on' in this case is redundant operation. Will be dropped.

Quoted 64 lines
Quoted 8 lines
drivers/soc/starfive/jh71xx_pmu.c new file +7 -0
+		return -EINVAL;
+	}
+
+	*is_on = readl(pmu->base + JH71XX_PMU_CURR_POWER_MODE) & mask;
+
+	return 0;
+}

[...]

Quoted 53 lines
drivers/soc/starfive/jh71xx_pmu.c new file +53 -0
+static int jh71xx_pmu_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct device_node *np = dev->of_node;
+	const struct jh71xx_pmu_match_data *match_data;
+	struct jh71xx_pmu *pmu;
+	unsigned int i;
+	int ret;
+
+	pmu = devm_kzalloc(dev, sizeof(*pmu), GFP_KERNEL);
+	if (!pmu)
+		return -ENOMEM;
+
+	pmu->base = devm_platform_ioremap_resource(pdev, 0);
+	if (IS_ERR(pmu->base))
+		return PTR_ERR(pmu->base);
+
+	pmu->irq = platform_get_irq(pdev, 0);
+	if (pmu->irq < 0)
+		return pmu->irq;
+
+	ret = devm_request_irq(dev, pmu->irq, jh71xx_pmu_interrupt,
+			       0, pdev->name, pmu);
+	if (ret)
+		dev_err(dev, "failed to request irq\n");
+
+	match_data = of_device_get_match_data(dev);
+	if (!match_data)
+		return -EINVAL;
+
+	pmu->genpd = devm_kcalloc(dev, match_data->num_domains,
+				  sizeof(struct generic_pm_domain *),
+				  GFP_KERNEL);
+	if (!pmu->genpd)
+		return -ENOMEM;
+
+	pmu->dev = dev;
+	pmu->match_data = match_data;
+	pmu->genpd_data.domains = pmu->genpd;
+	pmu->genpd_data.num_domains = match_data->num_domains;
+
+	for (i = 0; i < match_data->num_domains; i++) {
+		ret = jh71xx_pmu_init_domain(pmu, i);
+		if (ret) {
+			dev_err(dev, "failed to initialize power domain\n");
+			return ret;
+		}
+	}
+
+	spin_lock_init(&pmu->lock);
+	jh71xx_pmu_int_enable(pmu, JH71XX_PMU_INT_ALL_MASK & ~JH71XX_PMU_INT_PCH_FAIL, true);
+
+	ret = of_genpd_add_provider_onecell(np, &pmu->genpd_data);
Quoted 8 lines

drivers/soc/starfive/jh71xx_pmu.c line 321

Quoted 6 lines
drivers/soc/starfive/jh71xx_pmu.c new file +6 -0
+	if (ret) {
+		dev_err(dev, "failed to register genpd driver: %d\n", ret);
+		return ret;
+	}
+
+	dev_info(dev, "registered %u power domains\n", i);

nit: I guess that could be a dev_dbg to not spam the kernel log too much?

OK, will be used with dev_dbg().

Quoted 59 lines
Quoted 46 lines
drivers/soc/starfive/jh71xx_pmu.c new file +44 -0
+	return 0;
+}
+
+static const struct jh71xx_domain_info jh7110_power_domains[] = {
+	[JH7110_PD_SYSTOP] = {
+		.name = "SYSTOP",
+		.bit = 0,
+		.flags = GENPD_FLAG_ALWAYS_ON,
+	},
+	[JH7110_PD_CPU] = {
+		.name = "CPU",
+		.bit = 1,
+		.flags = GENPD_FLAG_ALWAYS_ON,
+	},
+	[JH7110_PD_GPUA] = {
+		.name = "GPUA",
+		.bit = 2,
+	},
+	[JH7110_PD_VDEC] = {
+		.name = "VDEC",
+		.bit = 3,
+	},
+	[JH7110_PD_VOUT] = {
+		.name = "VOUT",
+		.bit = 4,
+	},
+	[JH7110_PD_ISP] = {
+		.name = "ISP",
+		.bit = 5,
+	},
+	[JH7110_PD_VENC] = {
+		.name = "VENC",
+		.bit = 6,
+	},
+};
+
+static const struct jh71xx_pmu_match_data jh7110_pmu = {
+	.num_domains = ARRAY_SIZE(jh7110_power_domains),
+	.domain_info = jh7110_power_domains,
+};
+
+static const struct of_device_id jh71xx_pmu_of_match[] = {
+	{
+		.compatible = "starfive,jh7110-pmu",

drivers/soc/starfive/jh71xx_pmu.c line 376

Quoted 10 lines
drivers/soc/starfive/jh71xx_pmu.c new file +10 -0
+		.data = (void *)&jh7110_pmu,
+	}, {
+		/* sentinel */
+	}
+};
+
+static struct platform_driver jh71xx_pmu_driver = {
+	.driver = {
+		.name = "jh71xx-pmu",
+		.of_match_table = jh71xx_pmu_of_match,

In the rockchip pm-domains driver we have

Quoted 8 lines

/*
* We can't forcibly eject devices from the power
* domain, so we can't really remove power domains
* once they were added.
*/
.suppress_bind_attrs = true,

here, which might be valid for your pmu driver as well.

Okay, this attribute will be added in next version.

Quoted 5 lines

Other than that

Thanks for your review.

Best regards,
Walker Chen

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

author maintainer
#3 lore raw

Re: [PATCH v3 1/3] dt-bindings: power: Add starfive,jh7110-pmu

In reply to Krzysztof Kozlowski
Quoted 12 lines · Krzysztof Kozlowski
Quoted 10 lines · Walker Chen

Add bindings for the Power Management Unit on the StarFive JH7110 SoC.

---
 .../bindings/power/starfive,jh7110-pmu.yaml   | 45 +++++++++++++++++++
 .../dt-bindings/power/starfive,jh7110-pmu.h   | 17 +++++++
 2 files changed, 62 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/power/starfive,jh7110-pmu.yaml
 create mode 100644 include/dt-bindings/power/starfive,jh7110-pmu.h
Quoted 5 lines

Best regards,
Krzysztof

Thanks a lot for your review!

Best regards,
Walker

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