From: "Stefan Dösinger" <stefandoesinger@gmail.com>
To: "Rob Herring" <robh@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>,
"Stefan Dösinger" <stefandoesinger@gmail.com>,
"Philipp Zabel" <p.zabel@pengutronix.de>,
"Lee Jones" <lee@kernel.org>, "Ulf Hansson" <ulfh@kernel.org>,
"Vinod Koul" <vkoul@kernel.org>,
"Neil Armstrong" <neil.armstrong@linaro.org>,
"Manivannan Sadhasivam" <mani@kernel.org>,
"Agustin Santiago Isasmendi" <isasmendi.agus@gmail.com>,
"Navid Ghahremani" <ghahramani.navid@gmail.com>
Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org, mfd@lists.linux.dev,
linux-pm@vger.kernel.org, linux-phy@lists.infradead.org
Subject: [PATCH 3/6] pmdomain: zte: Add a zx297520v3 power domain driver
Date: Fri, 20 Nov 2026 22:20:52 +0300 [thread overview]
Message-ID: <20261120-zx29usb-v1-3-b0433258e51b@gmail.com> (raw)
In-Reply-To: <20261120-zx29usb-v1-0-b0433258e51b@gmail.com>
This controller has bits for USB, HSIC, EDCP (a cryptographic engine)
and GSM. Not all of them work the way one might expect (see comments in
the code), but they are there and can be set.
Signed-off-by: Stefan Dösinger <stefandoesinger@gmail.com>
---
For now this driver can only enable and disable the USB controller. I
expect more LTE related power switches will be added later, but I don't
want to commit to how I expose GSM and EDCP in the bindings just yet.
---
MAINTAINERS | 1 +
drivers/pmdomain/Kconfig | 1 +
drivers/pmdomain/Makefile | 1 +
drivers/pmdomain/zte/Kconfig | 15 ++
drivers/pmdomain/zte/Makefile | 2 +
drivers/pmdomain/zte/zx297520v3-pm-domain.c | 286 ++++++++++++++++++++++++++++
6 files changed, 306 insertions(+)
diff --git a/MAINTAINERS b/MAINTAINERS
index ab8797b8d0a5..e394e0044f1f 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -4038,6 +4038,7 @@ F: arch/arm/boot/dts/zte/
F: arch/arm/mach-zte/
F: drivers/clk/zte/
F: drivers/mfd/zte-zx297520v3-crm.c
+F: drivers/pmdomain/zte/
F: include/dt-bindings/clock/zte,zx297520v3-clk.h
F: include/dt-bindings/phy/zte,zx297520v3-topcrm.h
F: include/dt-bindings/reset/zte,zx297520v3-reset.h
diff --git a/drivers/pmdomain/Kconfig b/drivers/pmdomain/Kconfig
index 5341dff669be..d5050c22f064 100644
--- a/drivers/pmdomain/Kconfig
+++ b/drivers/pmdomain/Kconfig
@@ -21,5 +21,6 @@ source "drivers/pmdomain/tegra/Kconfig"
source "drivers/pmdomain/thead/Kconfig"
source "drivers/pmdomain/ti/Kconfig"
source "drivers/pmdomain/xilinx/Kconfig"
+source "drivers/pmdomain/zte/Kconfig"
endmenu
diff --git a/drivers/pmdomain/Makefile b/drivers/pmdomain/Makefile
index d7aee13ae571..cc3cc7b3d1c2 100644
--- a/drivers/pmdomain/Makefile
+++ b/drivers/pmdomain/Makefile
@@ -19,4 +19,5 @@ obj-y += tegra/
obj-y += thead/
obj-y += ti/
obj-y += xilinx/
+obj-y += zte/
obj-y += core.o governor.o
diff --git a/drivers/pmdomain/zte/Kconfig b/drivers/pmdomain/zte/Kconfig
new file mode 100644
index 000000000000..cc329d085e5a
--- /dev/null
+++ b/drivers/pmdomain/zte/Kconfig
@@ -0,0 +1,15 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+config ZTE_ZX297520V3_PM_DOMAIN
+ tristate "ZTE zx297520v3 pm domain"
+ depends on HAS_IOMEM
+ depends on PM
+ depends on MFD_ZTE_ZX297520V3_CRM || COMPILE_TEST
+ default SOC_ZX297520V3
+ select PM_GENERIC_DOMAINS
+ select MFD_SYSCON
+ help
+ Say y to enable the power domain driver for ZTE zx297520v3 boards.
+ This driver is necessary to enable the USB hardware found on this
+ board. Say y or m if you are building a kernel for a zx297520v3 based
+ device and plan to use its USB capabilities.
diff --git a/drivers/pmdomain/zte/Makefile b/drivers/pmdomain/zte/Makefile
new file mode 100644
index 000000000000..8a4185f48ff3
--- /dev/null
+++ b/drivers/pmdomain/zte/Makefile
@@ -0,0 +1,2 @@
+# SPDX-License-Identifier: GPL-2.0-only
+obj-$(CONFIG_ZTE_ZX297520V3_PM_DOMAIN) += zx297520v3-pm-domain.o
diff --git a/drivers/pmdomain/zte/zx297520v3-pm-domain.c b/drivers/pmdomain/zte/zx297520v3-pm-domain.c
new file mode 100644
index 000000000000..3df4cd5f1b22
--- /dev/null
+++ b/drivers/pmdomain/zte/zx297520v3-pm-domain.c
@@ -0,0 +1,286 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2026 Stefan Dösinger
+ *
+ * This driver controls power domain registers found on the ZTE zx297520v3 board. The USB and GSM
+ * controllers are controlled from here.
+ */
+
+#include <linux/delay.h>
+#include <linux/mfd/syscon.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/pm_domain.h>
+#include <linux/regmap.h>
+
+static const struct {
+ const char *name;
+ u32 reg;
+ u32 mask;
+} power_domains[] = {
+ /* ZTE's kernel defines the following power controls in 0x10c-0x114:
+ *
+ * Name Bit
+ * GSM_RAM 0
+ * GSM_DSP 1
+ * EDCP 4
+ * USB_CTRL 8
+ * USB_HSIC 9
+ *
+ * But the names are wrong/misleading.
+ *
+ * For USB, bit 9 appears to control both HSIC and USB, except for the isolation register,
+ * where setting either bit 8 or bit 9 zeroes both of their address space. So we expose
+ * one power domain that controls both bits.
+ *
+ * Bit 1 isolates and resets the mmio area from 0xf4000000-0xf7000000. The device behind it
+ * is an Infineon PMB887x GSM controller derivate. The power bit doesn't appear to turn it
+ * off, and it remains unset by the stock firmware. The reset works and the driver for this
+ * hardware needs to assert and deassert it to wake it up on boot. The isolation bit 1
+ * works, but only once the GSM hardware is properly booted - if the GSM chip doesn't
+ * respond, and isolation is enabled, attempts to access this area nevertheless stall the
+ * bus.
+ *
+ * Bit 0 controls the TeakLite DSP on the PMB887x.
+ *
+ * The functionality of bit 4 is not understood yet. The "EDCP" hardware seems to be a
+ * cryptographic engine implementing PDCP and some hash functions.
+ */
+
+ {"usb", 0x10c, BIT(8) | BIT(9)},
+
+ /* There is a separate set of registers in 0x180 - 0x188 that accepts 4 bits (0, 1, 6, 7)
+ * and is controlled by the cpko.ko blob in the same way as 0x10c-0x114 is controlled by
+ * the USB driver: LTE on: Set *0x188=0xc3 and the others to 0. LTE off: Set 0x188 to 0 and
+ * the others to 0xc3. It is therefore likely that up to 4 more devices can be powered on
+ * and off in these registers.
+ */
+};
+
+struct zx29_pm_domain {
+ struct generic_pm_domain gpd;
+ struct regmap *map;
+ unsigned int domain;
+};
+
+#define REG_RST 0x0
+#define REG_ISO 0x4
+#define REG_PWR 0x8
+
+static inline struct zx29_pm_domain *to_zte_pm_domain(struct generic_pm_domain *domain)
+{
+ return container_of(domain, struct zx29_pm_domain, gpd);
+}
+
+static int zx29_pd_on(struct generic_pm_domain *domain)
+{
+ const struct zx29_pm_domain *zx29_pd = to_zte_pm_domain(domain);
+ u32 mask = power_domains[zx29_pd->domain].mask;
+ u32 reg = power_domains[zx29_pd->domain].reg;
+ int res;
+
+ dev_dbg(&domain->dev, "Power on\n");
+
+ res = regmap_set_bits(zx29_pd->map, reg + REG_PWR, mask);
+ if (res)
+ goto error;
+
+ /* The 10 microsecond delay is from ZTE's dwc2 USB driver integration */
+ udelay(10);
+
+ res = regmap_clear_bits(zx29_pd->map, reg + REG_RST, mask);
+ if (res)
+ goto error;
+
+ udelay(10);
+
+ res = regmap_clear_bits(zx29_pd->map, reg + REG_ISO, mask);
+ if (res)
+ goto error;
+
+ return 0;
+
+error:
+ /* Power the device off and isolate it from the bus (reads from an unpowered, unisolated
+ * device can stall the CPU), but don't forcefully reset it.
+ */
+ dev_err(&domain->dev, "%s: Power on failed: %d\n", domain->name, res);
+ regmap_set_bits(zx29_pd->map, reg + REG_ISO, mask);
+ regmap_clear_bits(zx29_pd->map, reg + REG_PWR, mask);
+ return res;
+}
+
+static int zx29_pd_off(struct generic_pm_domain *domain)
+{
+ const struct zx29_pm_domain *zx29_pd = to_zte_pm_domain(domain);
+ u32 mask = power_domains[zx29_pd->domain].mask;
+ u32 reg = power_domains[zx29_pd->domain].reg;
+ int res;
+
+ dev_dbg(&domain->dev, "Power off\n");
+
+ /* If isolation fails, abort. The device should still be operational as far as the pmdomain
+ * settings are concerned. If isolation failed, asserting reset or powering it down leaves
+ * the mmio space in a dangerous state: Attempting to access it will stall the CPU forever.
+ *
+ * If later steps fail, consider the device off. It won't work without removing isolation.
+ */
+ res = regmap_set_bits(zx29_pd->map, reg + REG_ISO, mask);
+ if (res) {
+ dev_err(&domain->dev, "Bus isolation failed: %d\n", res);
+ return res;
+ }
+
+ res = regmap_set_bits(zx29_pd->map, reg + REG_RST, mask);
+ if (res)
+ dev_err(&domain->dev, "Device reset failed: %d\n", res);
+
+ res = regmap_clear_bits(zx29_pd->map, reg + REG_PWR, mask);
+ if (res)
+ dev_err(&domain->dev, "Power off failed: %d\n", res);
+
+ return 0;
+}
+
+static int zx29_pd_attach_dev(struct generic_pm_domain *domain, struct device *dev)
+{
+ /* The DT link to the consumer targets the (MFD) parent, which doesn't prevent unbinding the
+ * this driver or removing the module. Either would leave the consumer with a dangling
+ * reference.
+ */
+ if (!device_link_add(dev, &domain->dev, DL_FLAG_AUTOREMOVE_CONSUMER))
+ return -ENOMEM;
+
+ return 0;
+}
+
+static int zx29_pd_is_on(const struct zx29_pm_domain *zx29_pd)
+{
+ u32 mask = power_domains[zx29_pd->domain].mask;
+ u32 reg = power_domains[zx29_pd->domain].reg;
+ int res;
+ unsigned int val;
+
+ /* To consider a domain on, PWR must be set and RST and ISO cleared */
+ res = regmap_test_bits(zx29_pd->map, reg + REG_PWR, mask);
+ if (res < 0)
+ return res;
+ if (!res)
+ return 0;
+
+ res = regmap_read(zx29_pd->map, reg + REG_ISO, &val);
+ if (res < 0)
+ return res;
+ if (val & mask)
+ return 0;
+
+ res = regmap_read(zx29_pd->map, reg + REG_RST, &val);
+ if (res < 0)
+ return res;
+ if (val & mask)
+ return 0;
+
+ return 1;
+}
+
+static void zx29_pd_release_provider(void *data)
+{
+ struct device_node *of_node = data;
+
+ of_genpd_del_provider(of_node);
+}
+
+static void zx29_pd_remove_domain(void *data)
+{
+ struct generic_pm_domain *genpd = data;
+
+ pm_genpd_remove(genpd);
+}
+
+static int zx29_pd_probe(struct platform_device *pdev)
+{
+ struct device *dev = &pdev->dev;
+ struct device_node *of_node = dev->parent->of_node;
+ struct genpd_onecell_data *zx29_pd_data;
+ struct generic_pm_domain **domains;
+ struct zx29_pm_domain *zx29_pd;
+ struct regmap *map;
+ unsigned int i;
+ int res;
+
+ map = device_node_to_regmap(of_node);
+ if (IS_ERR(map))
+ return dev_err_probe(dev, PTR_ERR(map), "Cannot get parent syscon regmap\n");
+
+ zx29_pd = devm_kcalloc(dev, ARRAY_SIZE(power_domains), sizeof(*zx29_pd), GFP_KERNEL);
+ if (!zx29_pd)
+ return -ENOMEM;
+
+ domains = devm_kcalloc(dev, ARRAY_SIZE(power_domains), sizeof(*domains), GFP_KERNEL);
+ if (!domains)
+ return -ENOMEM;
+
+ zx29_pd_data = devm_kzalloc(dev, sizeof(*zx29_pd_data), GFP_KERNEL);
+ if (!zx29_pd_data)
+ return -ENOMEM;
+
+ for (i = 0; i < ARRAY_SIZE(power_domains); i++) {
+ zx29_pd[i].gpd.name = power_domains[i].name;
+ zx29_pd[i].gpd.power_off = zx29_pd_off;
+ zx29_pd[i].gpd.power_on = zx29_pd_on;
+ zx29_pd[i].gpd.attach_dev = zx29_pd_attach_dev;
+
+ zx29_pd[i].map = map;
+ zx29_pd[i].domain = i;
+
+ domains[i] = &zx29_pd[i].gpd;
+
+ res = zx29_pd_is_on(&zx29_pd[i]);
+ if (res < 0)
+ return dev_err_probe(dev, res, "failed to read initial pmdomain state\n");
+
+ dev_dbg(dev, "%s: %s\n", power_domains[i].name, res ? "on" : "off");
+
+ res = pm_genpd_init(&zx29_pd[i].gpd, NULL, !res);
+ if (res)
+ return dev_err_probe(dev, res, "failed to init power domain\n");
+ res = devm_add_action_or_reset(dev, zx29_pd_remove_domain, &zx29_pd[i].gpd);
+ if (res)
+ return dev_err_probe(dev, res, "failed to add pm_genpd release callback\n");
+ }
+
+ zx29_pd_data->domains = domains;
+ zx29_pd_data->num_domains = ARRAY_SIZE(power_domains);
+
+ res = of_genpd_add_provider_onecell(of_node, zx29_pd_data);
+ if (res)
+ return dev_err_probe(dev, res, "Cannot register power domains\n");
+
+ device_link_add(dev, dev->parent, DL_FLAG_AUTOREMOVE_CONSUMER);
+
+ dev_dbg(dev, "zx297520v3 power domain initialized.\n");
+
+ return devm_add_action_or_reset(dev, zx29_pd_release_provider, of_node);
+}
+
+static const struct platform_device_id pmdomain_zx297520v3_ids[] = {
+ {
+ .name = "zx297520v3-socsys-power",
+ },
+ { }
+};
+MODULE_DEVICE_TABLE(platform, pmdomain_zx297520v3_ids);
+
+static struct platform_driver zx297520_pd = {
+ .probe = zx29_pd_probe,
+ .driver = {
+ .name = "zx297520v3-power-domain",
+ },
+ .id_table = pmdomain_zx297520v3_ids,
+};
+module_platform_driver(zx297520_pd);
+
+MODULE_AUTHOR("Stefan Dösinger <stefandoesinger@gmail.com>");
+MODULE_DESCRIPTION("ZTE zx297520v3 power domain driver");
+MODULE_LICENSE("GPL");
--
2.56.1
--
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy
next prev parent reply other threads:[~2026-11-20 19:22 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-20 19:20 [PATCH 0/6] ZTE zx297520v3 USB support Stefan Dösinger
2026-11-20 19:20 ` [PATCH 1/6] dt-bindings: soc: zte: Document zx297520v3 socsys controller Stefan Dösinger
2026-11-20 19:38 ` sashiko-bot
2026-11-20 19:20 ` [PATCH 2/6] mfd: zx297520v3: Add socsys to the mfd host driver Stefan Dösinger
2026-11-20 19:20 ` Stefan Dösinger [this message]
2026-11-20 19:51 ` [PATCH 3/6] pmdomain: zte: Add a zx297520v3 power domain driver sashiko-bot
2026-11-20 19:20 ` [PATCH 4/6] phy: zte: Add a zx29 USB PHY driver Stefan Dösinger
2026-11-20 19:47 ` sashiko-bot
2026-11-20 19:20 ` [PATCH 5/6] ARM: dts: zte: Declare nodes to enable the board's dwc2 controller Stefan Dösinger
2026-11-20 19:20 ` [PATCH 6/6] ARM: dts: zte: Declare the HSIC controller node Stefan Dösinger
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=20261120-zx29usb-v1-3-b0433258e51b@gmail.com \
--to=stefandoesinger@gmail.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=ghahramani.navid@gmail.com \
--cc=isasmendi.agus@gmail.com \
--cc=krzk+dt@kernel.org \
--cc=lee@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-phy@lists.infradead.org \
--cc=linux-pm@vger.kernel.org \
--cc=mani@kernel.org \
--cc=mfd@lists.linux.dev \
--cc=neil.armstrong@linaro.org \
--cc=p.zabel@pengutronix.de \
--cc=robh@kernel.org \
--cc=ulfh@kernel.org \
--cc=vkoul@kernel.org \
/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).