Skip to contentSkip to conversation

PM: spacemit: Add power domain support

PATCH Superseded Yixun Lan 3 participants 8 messages Nov 8 – Nov 10

Subsystems (4)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Yixun Lan

author maintainer
#0 lore raw

v3 cover PM: spacemit: Add power domain support

In this series, we try to add a Power Domain driver support for SpacemiT K1/K3 SoCs, the driver implement the power-switch functionaly which support power on/off, and it's based on Linux Generic PM Domain framework and similiar to vendor K1's implementation, but unlike the K3's vendor version which is more complicated.

The DT documentation for Power Domain already exist in below file,
and APMU already has #power-domain-cells property. Documentation/devicetree/bindings/soc/spacemit/spacemit,k1-syscon.yaml

The previous DTS patch is obsolete, so I dropped it. For devices required
PM feature, it need to add a "power-domains" property, and should send in a separate patch.

In order to test this series, a prerequisite CCU patches are needed,
which can be found here [1].

---
Changes in v3:
- collect tags
- rename spacemit_pm_is_off_state()
- implement a remove() function
- use proper type in struct spacemit_pm_domain_param
- refactor struct spacemit_pmu
- Link to v2: https://patch.msgid.link/[email protected]

Changes in v2:
- convert to auxilary driver
- no need dt-binding doc, drop it
- drop dts patch
- support to build as module
- set always on for K3 audio pm
- no global variable for struct spacemit_pmu
- no force to do power-off in spacemit_pd_power_on()
- check return value of pm_genpd_init()
- adjust license header format
- Link to v1: https://patch.msgid.link/[email protected]

---
Yixun Lan (2):
dt-bindings: power: spacemit: Add power domain controller IDs
pmdomain: spacemit: Add power domain driver

 drivers/pmdomain/Kconfig                        |   1 +
 drivers/pmdomain/Makefile                       |   1 +
 drivers/pmdomain/spacemit/Kconfig               |  21 ++
 drivers/pmdomain/spacemit/Makefile              |   1 +
 drivers/pmdomain/spacemit/spacemit-pm-domains.c | 431 ++++++++++++++++++++++++
 include/dt-bindings/power/spacemit,k1-power.h   |  14 +
 include/dt-bindings/power/spacemit,k3-power.h   |  12 +
 7 files changed, 481 insertions(+)

---
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
change-id: 20260909-04-k3-pm-support-0bef40e87fd7

Best regards,

Signature · 1 line
Yixun Lan <[email protected]>
author maintainer
#1 lore raw

PATCH v3 1/2 dt-bindings: power: spacemit: Add power domain controller IDs

Add initial power domain driver support for SpacemiT K1/K3 SoC, The Power Domain Controller is SoC internal module which is part of APMU (Advanced Power Management Unit), it is responsible for managing power across multi power domains, which includes power on/off, isolation, power-on sequence.

The DT documentation for the power domains already exists in file of spacemit,k1-syscon.yaml.

---
 include/dt-bindings/power/spacemit,k1-power.h | 14 ++++++++++++++
 include/dt-bindings/power/spacemit,k3-power.h | 12 ++++++++++++
 2 files changed, 26 insertions(+)
include/dt-bindings/power/spacemit,k1-power.h new file +14 -0
new file mode 100644
index 000000000000..41ef540b5c44
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */
+
+#ifndef _DT_BINDINGS_SPACEMIT_K1_POWER_H_
+#define _DT_BINDINGS_SPACEMIT_K1_POWER_H_
+
+#define K1_PMDOMAIN_VPU		0
+#define K1_PMDOMAIN_GPU		1
+#define K1_PMDOMAIN_LCD		2
+#define K1_PMDOMAIN_ISP		3
+#define K1_PMDOMAIN_AUDIO	4
+#define K1_PMDOMAIN_GNSS	5
+#define K1_PMDOMAIN_HDMI	6
+
+#endif
include/dt-bindings/power/spacemit,k3-power.h new file +12 -0
new file mode 100644
index 000000000000..519fbf946312
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */
+
+#ifndef _DT_BINDINGS_SPACEMIT_K3_POWER_H_
+#define _DT_BINDINGS_SPACEMIT_K3_POWER_H_
+
+#define K3_PMDOMAIN_VPU		0
+#define K3_PMDOMAIN_GPU		1
+#define K3_PMDOMAIN_AUDIO	2
+#define K3_PMDOMAIN_LCD0	3
+#define K3_PMDOMAIN_LCD1	4
+
+#endif
Signature · 1 line
2.56.0
author maintainer
#3 lore raw

PATCH v3 2/2 pmdomain: spacemit: Add power domain driver

In reply to Yixun Lan

SpacemiT's PMU (Power Management Unit) consist of several power domains
which can be managed independently, depending on different application scenario, each domain can be powered on/off for saving power.

The driver is implemented based on Linux Generic PM Domain framework.
From a hardware perspective, either of two distinct power-on sequences are supported, in software mode (SW mode), the driver is responsible for controlling the states of bits such as sleep1, sleep2, isolation and pwr_state, while in hardware mode (HW mode), the PMU hardware will complete the sequence automatically without requiring software intervention.

---
 drivers/pmdomain/Kconfig                        |   1 +
 drivers/pmdomain/Makefile                       |   1 +
 drivers/pmdomain/spacemit/Kconfig               |  21 ++
 drivers/pmdomain/spacemit/Makefile              |   1 +
 drivers/pmdomain/spacemit/spacemit-pm-domains.c | 431 ++++++++++++++++++++++++
 5 files changed, 455 insertions(+)
drivers/pmdomain/Kconfig +1 -0
index 5341dff669be..20aea5fe94b2 100644
@@ -14,6 +14,7 @@ source "drivers/pmdomain/renesas/Kconfig"
 source "drivers/pmdomain/riscv/Kconfig"
 source "drivers/pmdomain/rockchip/Kconfig"
 source "drivers/pmdomain/samsung/Kconfig"
+source "drivers/pmdomain/spacemit/Kconfig"
 source "drivers/pmdomain/st/Kconfig"
 source "drivers/pmdomain/starfive/Kconfig"
 source "drivers/pmdomain/sunxi/Kconfig"
drivers/pmdomain/Makefile +1 -0
index d7aee13ae571..25238576f8a3 100644
@@ -12,6 +12,7 @@ obj-y					+= renesas/
 obj-y					+= riscv/
 obj-y					+= rockchip/
 obj-y					+= samsung/
+obj-y					+= spacemit/
 obj-y					+= st/
 obj-y					+= starfive/
 obj-y					+= sunxi/
drivers/pmdomain/spacemit/Kconfig new file +21 -0
new file mode 100644
index 000000000000..0dce5eef8da8
@@ -0,0 +1,21 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+menu "SpacemiT PM Domains"
+
+config SPACEMIT_PM_DOMAINS
+	tristate "PM Domain driver for SpacemiT SoC"
+	depends on ARCH_SPACEMIT || COMPILE_TEST
+	depends on PM && OF
+	select PM_GENERIC_DOMAINS
+	select PM_GENERIC_DOMAINS_OF
+	select AUXILIARY_BUS
+	help
+	  This driver enables power domain management for the SpacemiT
+	  SoC. On the SoC there are number of power domains available,
+	  which can be managed independently. For example VPU, GPU, LCD,
+	  and Audio reside in their own power domains which can be
+	  turned on/off.
+
+	  Say y to enable device power management through PM domains.
+
+endmenu
drivers/pmdomain/spacemit/Makefile new file +1 -0
new file mode 100644
index 000000000000..d0bd77a520c0
@@ -0,0 +1 @@
+obj-$(CONFIG_SPACEMIT_PM_DOMAINS)	+= spacemit-pm-domains.o
drivers/pmdomain/spacemit/spacemit-pm-domains.c new file +431 -0

431 lines not on this page · raw message

Signature · 1 line
2.56.0
reviewer
#4 lore raw

Re: [PATCH v3 2/2] pmdomain: spacemit: Add power domain driver

Hi Yixun,

Quoted 2 lines · Yixun Lan
drivers/pmdomain/spacemit/Kconfig new file +2 -0
+config SPACEMIT_PM_DOMAINS
+	tristate "PM Domain driver for SpacemiT SoC"

[...]

drivers/pmdomain/spacemit/Kconfig line 19

Quoted 1 line
drivers/pmdomain/spacemit/Kconfig new file +1 -0
+	  Say y to enable device power management through PM domains.

This is tristate now, so "Say Y or M".

[...]

drivers/pmdomain/spacemit/spacemit-pm-domains.c line 13

Quoted 6 lines
drivers/pmdomain/spacemit/spacemit-pm-domains.c new file +6 -0
+#include <linux/io.h>
+#include <linux/err.h>
+#include <linux/platform_device.h>
+#include <linux/pm_domain.h>
+#include <linux/regmap.h>
+#include <linux/auxiliary_bus.h>

io.h, err.h and platform_device.h are not used right now.

[...]

Quoted 1 line

+static int spacemit_pd_power_off(struct generic_pm_domain *domain)

[...]

drivers/pmdomain/spacemit/spacemit-pm-domains.c line 95

Quoted 5 lines
drivers/pmdomain/spacemit/spacemit-pm-domains.c new file +5 -0
+	if (ret) {
+		dev_err(&domain->dev, "failed to power off domain %s: %d\n",
+			p->name, pd->pm_index);
+		return -EBUSY;
+	}

-EBUSY drops the -ETIMEDOUT returned by regmap_read_poll_timeout(); why not print ret and return it? Same in spacemit_pd_power_on().

[...]

Quoted 2 lines
drivers/pmdomain/spacemit/spacemit-pm-domains.c new file +2 -0
+static bool spacemit_pm_is_off_state(struct spacemit_pmu *pmu,
+				     struct spacemit_pm_domain *pd)

[...]

drivers/pmdomain/spacemit/spacemit-pm-domains.c line 157

Quoted 1 line
drivers/pmdomain/spacemit/spacemit-pm-domains.c new file +1 -0
+	return (reg & bit) ? false : true;

return !(reg & bit);

[...]

Quoted 16 lines
drivers/pmdomain/spacemit/spacemit-pm-domains.c new file +16 -0
+static void spacemit_pm_domain_cleanup(struct spacemit_pmu *pmu)
+{
+	struct spacemit_pm_domain *pd;
+	int i, ret;
+
+	for (i = 0; i < pmu->genpd_data.num_domains; i++) {
+		if (!pmu->domains[i])
+			continue;
+
+		pd = to_spacemit_pd(pmu->domains[i]);
+		ret = pm_genpd_remove(pmu->domains[i]);
+		if (ret)
+			dev_err(pmu->dev, "failed to remove domain %s: %d - state may be inconsistent\n",
+				pd->param->name, ret);
+	}
+}

[...]

drivers/pmdomain/spacemit/spacemit-pm-domains.c line 258

Quoted 8 lines
drivers/pmdomain/spacemit/spacemit-pm-domains.c new file +8 -0
+static void spacemit_pm_domain_remove(struct auxiliary_device *adev)
+{
+	struct spacemit_pmu *pmu = auxiliary_get_drvdata(adev);
+	struct device *dev = &adev->dev;
+
+	of_genpd_del_provider(dev->of_node);
+	spacemit_pm_domain_cleanup(pmu);
+}

pm_genpd_remove() fails with -EBUSY while a consumer is still attached, but pd is freed by devres anyway. Set suppress_bind_attrs like most pmdomain drivers?

Signature · 1 line
Troy Mitchell
author maintainer
#5 lore raw

Re: [PATCH v3 2/2] pmdomain: spacemit: Add power domain driver

author maintainer
#6 lore raw

Re: [PATCH v3 2/2] pmdomain: spacemit: Add power domain driver

In reply to Troy Mitchell

Hi Troy,

Quoted 9 lines · Troy Mitchell

Hi Yixun,

Quoted 2 lines · Yixun Lan
drivers/pmdomain/spacemit/Kconfig new file +2 -0
+config SPACEMIT_PM_DOMAINS
+	tristate "PM Domain driver for SpacemiT SoC"

[...]

drivers/pmdomain/spacemit/Kconfig line 19

Quoted 1 line
drivers/pmdomain/spacemit/Kconfig new file +1 -0
+	  Say y to enable device power management through PM domains.

This is tristate now, so "Say Y or M".

Ok, will update

Quoted 9 lines

[...]

drivers/pmdomain/spacemit/spacemit-pm-domains.c line 13

Quoted 6 lines
drivers/pmdomain/spacemit/spacemit-pm-domains.c new file +6 -0
+#include <linux/io.h>
+#include <linux/err.h>
+#include <linux/platform_device.h>
+#include <linux/pm_domain.h>
+#include <linux/regmap.h>
+#include <linux/auxiliary_bus.h>

io.h, err.h and platform_device.h are not used right now.

Ok, will drop them

Quoted 12 lines

[...]

Quoted 1 line

+static int spacemit_pd_power_off(struct generic_pm_domain *domain)

[...]

drivers/pmdomain/spacemit/spacemit-pm-domains.c line 95

Quoted 5 lines
drivers/pmdomain/spacemit/spacemit-pm-domains.c new file +5 -0
+	if (ret) {
+		dev_err(&domain->dev, "failed to power off domain %s: %d\n",
+			p->name, pd->pm_index);
+		return -EBUSY;
+	}

-EBUSY drops the -ETIMEDOUT returned by regmap_read_poll_timeout(); why not print ret and return it? Same in spacemit_pd_power_on().

Yes, I think it's ok to propogate the err

Quoted 7 lines

[...]

Quoted 2 lines
drivers/pmdomain/spacemit/spacemit-pm-domains.c new file +2 -0
+static bool spacemit_pm_is_off_state(struct spacemit_pmu *pmu,
+				     struct spacemit_pm_domain *pd)

[...]

drivers/pmdomain/spacemit/spacemit-pm-domains.c line 157

Quoted 1 line
drivers/pmdomain/spacemit/spacemit-pm-domains.c new file +1 -0
+	return (reg & bit) ? false : true;

return !(reg & bit);

Actually, there isn't much difference, your version is slightly short

Quoted 18 lines

[...]

Quoted 16 lines
drivers/pmdomain/spacemit/spacemit-pm-domains.c new file +16 -0
+static void spacemit_pm_domain_cleanup(struct spacemit_pmu *pmu)
+{
+	struct spacemit_pm_domain *pd;
+	int i, ret;
+
+	for (i = 0; i < pmu->genpd_data.num_domains; i++) {
+		if (!pmu->domains[i])
+			continue;
+
+		pd = to_spacemit_pd(pmu->domains[i]);
+		ret = pm_genpd_remove(pmu->domains[i]);
+		if (ret)
+			dev_err(pmu->dev, "failed to remove domain %s: %d - state may be inconsistent\n",
+				pd->param->name, ret);
+	}
+}

[...]

Quoted 12 lines

drivers/pmdomain/spacemit/spacemit-pm-domains.c line 258

Quoted 8 lines
drivers/pmdomain/spacemit/spacemit-pm-domains.c new file +8 -0
+static void spacemit_pm_domain_remove(struct auxiliary_device *adev)
+{
+	struct spacemit_pmu *pmu = auxiliary_get_drvdata(adev);
+	struct device *dev = &adev->dev;
+
+	of_genpd_del_provider(dev->of_node);
+	spacemit_pm_domain_cleanup(pmu);
+}

pm_genpd_remove() fails with -EBUSY while a consumer is still attached, but pd is freed by devres anyway. Set suppress_bind_attrs like most pmdomain drivers?

No, I won't add suppress_bind_attrs

As I'm also aware of this problem, but intend to address it in a different way, and should send a patch in another separate thread..

In my opinion, Adding "suppress_bind_attrs = true" will only mitigate the problem, in the case of this driver, it will still trigger a problem while unloading the driver with rmmod command if built as kernel module, consumer side won't get notification with the event. Ideally the device link machanism should solve this, currently I'm working on a patch for this..

Signature · 1 line
Yixun Lan (dlan)
Reviewed-by
#7 lore raw

Re: [PATCH v3 2/2] pmdomain: spacemit: Add power domain driver

Thank you for addressing the feedback. The series looks good now.

Quoted 93 lines · Yixun Lan

Hi Troy,

Quoted 9 lines · Troy Mitchell

Hi Yixun,

Quoted 2 lines · Yixun Lan
drivers/pmdomain/spacemit/Kconfig new file +2 -0
+config SPACEMIT_PM_DOMAINS
+   tristate "PM Domain driver for SpacemiT SoC"

[...]

Quoted 1 line

+ Say y to enable device power management through PM domains.

This is tristate now, so "Say Y or M".

Ok, will update

Quoted 9 lines

[...]

drivers/pmdomain/spacemit/spacemit-pm-domains.c line 13

Quoted 6 lines
drivers/pmdomain/spacemit/spacemit-pm-domains.c new file +6 -0
+#include <linux/io.h>
+#include <linux/err.h>
+#include <linux/platform_device.h>
+#include <linux/pm_domain.h>
+#include <linux/regmap.h>
+#include <linux/auxiliary_bus.h>

io.h, err.h and platform_device.h are not used right now.

Ok, will drop them

Quoted 12 lines

[...]

Quoted 1 line

+static int spacemit_pd_power_off(struct generic_pm_domain *domain)

[...]

drivers/pmdomain/spacemit/spacemit-pm-domains.c line 95

Quoted 5 lines
drivers/pmdomain/spacemit/spacemit-pm-domains.c new file +5 -0
+   if (ret) {
+           dev_err(&domain->dev, "failed to power off domain %s: %d\n",
+                   p->name, pd->pm_index);
+           return -EBUSY;
+   }

-EBUSY drops the -ETIMEDOUT returned by regmap_read_poll_timeout(); why not print ret and return it? Same in spacemit_pd_power_on().

Yes, I think it's ok to propogate the err

Quoted 7 lines

[...]

Quoted 2 lines
drivers/pmdomain/spacemit/spacemit-pm-domains.c new file +2 -0
+static bool spacemit_pm_is_off_state(struct spacemit_pmu *pmu,
+                                struct spacemit_pm_domain *pd)

[...]

Quoted 1 line

+ return (reg & bit) ? false : true;

return !(reg & bit);

Actually, there isn't much difference, your version is slightly short

Quoted 18 lines

[...]

Quoted 16 lines
drivers/pmdomain/spacemit/spacemit-pm-domains.c new file +16 -0
+static void spacemit_pm_domain_cleanup(struct spacemit_pmu *pmu)
+{
+   struct spacemit_pm_domain *pd;
+   int i, ret;
+
+   for (i = 0; i < pmu->genpd_data.num_domains; i++) {
+           if (!pmu->domains[i])
+                   continue;
+
+           pd = to_spacemit_pd(pmu->domains[i]);
+           ret = pm_genpd_remove(pmu->domains[i]);
+           if (ret)
+                   dev_err(pmu->dev, "failed to remove domain %s: %d - state may be inconsistent\n",
+                           pd->param->name, ret);
+   }
+}

[...]

Quoted 12 lines

drivers/pmdomain/spacemit/spacemit-pm-domains.c line 258

Quoted 8 lines
drivers/pmdomain/spacemit/spacemit-pm-domains.c new file +8 -0
+static void spacemit_pm_domain_remove(struct auxiliary_device *adev)
+{
+   struct spacemit_pmu *pmu = auxiliary_get_drvdata(adev);
+   struct device *dev = &adev->dev;
+
+   of_genpd_del_provider(dev->of_node);
+   spacemit_pm_domain_cleanup(pmu);
+}

pm_genpd_remove() fails with -EBUSY while a consumer is still attached, but pd is freed by devres anyway. Set suppress_bind_attrs like most pmdomain drivers?

No, I won't add suppress_bind_attrs

As I'm also aware of this problem, but intend to address it in a different way, and should send a patch in another separate thread..

In my opinion, Adding "suppress_bind_attrs = true" will only mitigate the problem, in the case of this driver, it will still trigger a problem while unloading the driver with rmmod command if built as kernel module, consumer side won't get notification with the event. Ideally the device link machanism should solve this, currently I'm working on a patch for this..

--
Yixun Lan (dlan)