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 4/6] phy: zte: Add a zx29 USB PHY driver.
Date: Fri, 20 Nov 2026 22:20:53 +0300 [thread overview]
Message-ID: <20261120-zx29usb-v1-4-b0433258e51b@gmail.com> (raw)
In-Reply-To: <20261120-zx29usb-v1-0-b0433258e51b@gmail.com>
This driver's responsibility is the correct reset sequencing of the USB
and HSIC PHYs. Before the ready flag is set in topcrm+0x84, the dwc2
controller mmio space reads zeroes. Waiting for them is therefore
necessary to avoid race conditions on boot.
Signed-off-by: Stefan Dösinger <stefandoesinger@gmail.com>
---
Possible future features are host mode support and adjusting the USB PHY
to mpll over/underclocking. But both are unlikely to have productive use
on this platform. None of the zx29 boards I have seen so far can provide
power on VBUS.
The PHY driver reuses the topcrm node for the MFD child device because
the PHY subsystem enforces that the device either matches the of_node or
is a parent of the of_node (__of_phy_provider_register). Krzysztof
rejected a PHY child node [0] for the purpose of satisfying the check.
One issue - and that's possibly the reason for the PHY subsystem's
behavior - is that nothing prevents the phy driver from being unbound
because the DT producer-consumer relationship targets the MFD parent. I
have set suppress_bind_attrs = true, but that feels ugly and only solves
half the problem. The module can still be unloaded without first
releasing the USB consumer.
0:
https://lore.kernel.org/linux-arm-kernel/20260717-uncovered-feathered-groundhog-eab16e@quoll/
---
MAINTAINERS | 1 +
drivers/phy/Kconfig | 11 +++
drivers/phy/Makefile | 1 +
drivers/phy/phy-zx29-usb.c | 183 +++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 196 insertions(+)
diff --git a/MAINTAINERS b/MAINTAINERS
index e394e0044f1f..1d47080b2290 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/phy/phy-zx29-usb.c
F: drivers/pmdomain/zte/
F: include/dt-bindings/clock/zte,zx297520v3-clk.h
F: include/dt-bindings/phy/zte,zx297520v3-topcrm.h
diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
index d151c05297d7..c4829038bfeb 100644
--- a/drivers/phy/Kconfig
+++ b/drivers/phy/Kconfig
@@ -169,6 +169,17 @@ config PHY_XGENE
help
This option enables support for APM X-Gene SoC multi-purpose PHY.
+config PHY_ZTE_ZX29_USB
+ tristate "ZTE zx29 USB phy"
+ depends on MFD_SYSCON && OF && (ARCH_ZTE || COMPILE_TEST)
+ select GENERIC_PHY
+ help
+ This option enables support for ZTE zx29 USB PHYs. You will need this
+ if you have a ZTE zx29 board and want to use its external USB
+ connector for data transfer. This driver is not required purely for
+ providing power to the board. If M is selected, the module will be
+ called phy-zx29-usb.
+
source "drivers/phy/allwinner/Kconfig"
source "drivers/phy/amlogic/Kconfig"
source "drivers/phy/apple/Kconfig"
diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile
index c6dd02003bbe..e135e96b4930 100644
--- a/drivers/phy/Makefile
+++ b/drivers/phy/Makefile
@@ -19,6 +19,7 @@ obj-$(CONFIG_PHY_NXP_TJA1145) += phy-nxp-tja1145.o
obj-$(CONFIG_PHY_PISTACHIO_USB) += phy-pistachio-usb.o
obj-$(CONFIG_PHY_SNPS_EUSB2) += phy-snps-eusb2.o
obj-$(CONFIG_PHY_XGENE) += phy-xgene.o
+obj-$(CONFIG_PHY_ZTE_ZX29_USB) += phy-zx29-usb.o
obj-$(CONFIG_GENERIC_PHY) += allwinner/ \
amlogic/ \
diff --git a/drivers/phy/phy-zx29-usb.c b/drivers/phy/phy-zx29-usb.c
new file mode 100644
index 000000000000..8dfbcb468c26
--- /dev/null
+++ b/drivers/phy/phy-zx29-usb.c
@@ -0,0 +1,183 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * ZTE zx29 USB2 PHY driver
+ *
+ * Copyright (C) 2026 Stefan Dösinger <stefandoesinger@gmail.com>
+ */
+
+#include <dt-bindings/phy/zte,zx297520v3-topcrm.h>
+#include <linux/err.h>
+#include <linux/iopoll.h>
+#include <linux/mfd/syscon.h>
+#include <linux/module.h>
+#include <linux/phy/phy.h>
+#include <linux/platform_device.h>
+#include <linux/regmap.h>
+
+/* This driver controls the PHY reset bits found in zx297520v3-topcrm register 0x80 and waits for
+ * the ready bits in 0x84.
+ *
+ * More USB related controls can be found in zx297520v3-socsys+0x20 and 0x24:
+ *
+ * Bit 0: Limits the PHY to USB 1
+ * Bit 1: Unknown
+ * Bit 2: DWC2 controller endianness
+ * Bit 3: DWC2 DMA endianness
+ * Bits 7:4: PHY clock adjustments. Adjusting these is necessary if mpll is changed from its default
+ * 624 MHz.
+ * Bits 9:8: PHY electrical configuration. Setting them both to 1 allows operating in host mode.
+ *
+ * They are a fairly useless curiosity though. So far no zx297520v3 based device has a working 5v
+ * VBUS supply, so host mode only works when injecting power externally. The clock bits are too
+ * coarse to be of much use. The default value is 2 (0b0010). Setting it to 1 allows lowering mpll
+ * from 624 to about 530 MHz. The next higher setting might be around mpll=718 MHz, but the SoC is
+ * not able to operate stably at that frequency anyway.
+ */
+
+struct phy_zx29_drv_priv;
+
+struct phy_zx29_phy_priv {
+ struct phy_zx29_drv_priv *drv;
+ struct phy *phy;
+ u32 resetflag;
+ u32 waitflag;
+};
+
+struct phy_zx29_drv_priv {
+ struct regmap *regmap;
+ struct phy_zx29_phy_priv phy[2];
+};
+
+static const struct {
+ const char *name;
+ u32 resetflag;
+ u32 waitflag;
+} phy_data[] = {
+ {"usb", 0x8, 0x2},
+ {"hsic", 0x1, 0x1},
+};
+
+#define PHY_ADDR_ZX297520V3 0x80
+
+static int phy_zx29_init(struct phy *phy)
+{
+ struct phy_zx29_phy_priv *phypriv = phy_get_drvdata(phy);
+ struct phy_zx29_drv_priv *priv = phypriv->drv;
+ int res;
+ u32 val;
+
+ dev_dbg(&phy->dev, "Initializing, reset 0x%x, wait 0x%x\n",
+ phypriv->resetflag, phypriv->waitflag);
+
+ /* If the bootloader used the USB device it sometimes fails to re-initialize without a
+ * reset.
+ */
+ res = regmap_clear_bits(priv->regmap, PHY_ADDR_ZX297520V3, phypriv->resetflag);
+ if (res)
+ return res;
+
+ fsleep(10);
+
+ res = regmap_set_bits(priv->regmap, PHY_ADDR_ZX297520V3, phypriv->resetflag);
+ if (res)
+ return res;
+
+ /* The wait time is usually in the single digit microsecond range, but it can be
+ * considerably longer in some situations. The upper ceiling isn't clear though - 50 us is
+ * not reliably enough, but every time I add timing, the usb wakeup time goes back below 10
+ * us.
+ */
+ res = regmap_read_poll_timeout(priv->regmap, PHY_ADDR_ZX297520V3 + 0x4, val,
+ val & phypriv->waitflag, 10, 500);
+ if (res) {
+ dev_err(&phy->dev, "PHY reset failed: %d\n", res);
+ regmap_clear_bits(priv->regmap, PHY_ADDR_ZX297520V3, phypriv->resetflag);
+ }
+
+ return res;
+}
+
+static int phy_zx29_exit(struct phy *phy)
+{
+ struct phy_zx29_phy_priv *phypriv = phy_get_drvdata(phy);
+ struct phy_zx29_drv_priv *priv = phypriv->drv;
+
+ return regmap_clear_bits(priv->regmap, PHY_ADDR_ZX297520V3, phypriv->resetflag);
+}
+
+static const struct phy_ops phy_zx29_ops = {
+ .init = phy_zx29_init,
+ .exit = phy_zx29_exit,
+ .owner = THIS_MODULE,
+};
+
+static struct phy *phy_zx29_xlate(struct device *dev,
+ const struct of_phandle_args *args)
+{
+ struct phy_zx29_drv_priv *priv = dev_get_drvdata(dev);
+
+ if (args->args_count != 1)
+ return ERR_PTR(-EINVAL);
+ if (args->args[0] >= ARRAY_SIZE(priv->phy))
+ return ERR_PTR(-EINVAL);
+
+ return priv->phy[args->args[0]].phy;
+}
+
+static int phy_zx29_probe(struct platform_device *pdev)
+{
+ struct phy_provider *phy_provider;
+ struct device *dev = &pdev->dev;
+ struct phy_zx29_drv_priv *priv;
+ unsigned int i;
+
+ device_set_of_node_from_dev(dev, dev->parent);
+ priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
+ if (!priv)
+ return -ENOMEM;
+ platform_set_drvdata(pdev, priv);
+
+ priv->regmap = syscon_node_to_regmap(dev->of_node);
+ if (IS_ERR(priv->regmap)) {
+ return dev_err_probe(dev, PTR_ERR(priv->regmap),
+ "Failed to get regmap\n");
+ }
+
+ for (i = 0; i < ARRAY_SIZE(phy_data); ++i) {
+ priv->phy[i].drv = priv;
+ priv->phy[i].waitflag = phy_data[i].waitflag;
+ priv->phy[i].resetflag = phy_data[i].resetflag;
+
+ priv->phy[i].phy = devm_phy_create(dev, NULL, &phy_zx29_ops);
+ if (IS_ERR(priv->phy[i].phy))
+ return dev_err_probe(dev, PTR_ERR(priv->phy[i].phy),
+ "failed to create %s PHY\n", phy_data[i].name);
+
+ phy_set_drvdata(priv->phy[i].phy, &priv->phy[i]);
+ }
+
+ phy_provider = devm_of_phy_provider_register(dev, phy_zx29_xlate);
+ return PTR_ERR_OR_ZERO(phy_provider);
+}
+
+static const struct platform_device_id phy_zx29_ids[] = {
+ {
+ .name = "zx297520v3-usb-phy",
+ },
+ { }
+};
+MODULE_DEVICE_TABLE(platform, phy_zx29_ids);
+
+static struct platform_driver phy_zx29_driver = {
+ .probe = phy_zx29_probe,
+ .driver = {
+ .name = "zx297520v3-usb-phy",
+ .suppress_bind_attrs = true,
+ },
+ .id_table = phy_zx29_ids,
+};
+module_platform_driver(phy_zx29_driver);
+
+MODULE_AUTHOR("Stefan Dösinger <stefandoesinger@gmail.com>");
+MODULE_DESCRIPTION("ZTE zx29 USB2 PHY driver");
+MODULE_LICENSE("GPL");
--
2.56.1
next prev parent reply other threads:[~2026-11-20 19:21 UTC|newest]
Thread overview: 7+ 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:20 ` [PATCH 2/6] mfd: zx297520v3: Add socsys to the mfd host driver Stefan Dösinger
2026-11-20 19:20 ` [PATCH 3/6] pmdomain: zte: Add a zx297520v3 power domain driver Stefan Dösinger
2026-11-20 19:20 ` Stefan Dösinger [this message]
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-4-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
all inboxes | Powered by JetHome®