From: Alastair D'Silva <alastair@d-silva.org>
To: Vinod Koul <vkoul@kernel.org>,
Neil Armstrong <neil.armstrong@linaro.org>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Chen-Yu Tsai <wens@kernel.org>,
Jernej Skrabec <jernej.skrabec@gmail.com>,
Samuel Holland <samuel@sholland.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Stephen Boyd <sboyd@kernel.org>,
Brian Masney <bmasney+clk@redhat.com>,
Jerome Brunet <jbrunet+clk@baylibre.com>,
Thinh Nguyen <Thinh.Nguyen@synopsys.com>,
Mathias Nyman <mathias.nyman@intel.com>
Cc: linux-phy@lists.infradead.org, devicetree@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-sunxi@lists.linux.dev, linux-usb@vger.kernel.org,
linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org,
Alastair D'Silva <alastair@d-silva.org>
Subject: [PATCH 06/11] phy: allwinner: Add Allwinner A733 USB 2.0 PHY driver
Date: Fri, 27 Nov 2026 18:32:26 +1100 [thread overview]
Message-ID: <20261127073231.1776847-7-alastair@d-silva.org> (raw)
In-Reply-To: <20261127073231.1776847-1-alastair@d-silva.org>
Add USB 2.0 PHY driver for the Allwinner A733 DWC3 controller.
Signed-off-by: Alastair D'Silva <alastair@d-silva.org>
---
drivers/phy/allwinner/Kconfig | 12 ++
drivers/phy/allwinner/Makefile | 1 +
drivers/phy/allwinner/phy-sun60i-u2phy.c | 233 +++++++++++++++++++++++
3 files changed, 246 insertions(+)
create mode 100644 drivers/phy/allwinner/phy-sun60i-u2phy.c
diff --git a/drivers/phy/allwinner/Kconfig b/drivers/phy/allwinner/Kconfig
index 7518c4b5c379..f8dc4931378b 100644
--- a/drivers/phy/allwinner/Kconfig
+++ b/drivers/phy/allwinner/Kconfig
@@ -68,3 +68,15 @@ config PHY_SUN60I_COMBOPHY
help
Enable this to support the SerDes ComboPHY controller on
Allwinner A733 SoCs.
+
+config PHY_SUN60I_U2PHY
+ tristate "Allwinner A733 USB 2.0 PHY driver"
+ depends on ARCH_SUNXI || COMPILE_TEST
+ depends on HAS_IOMEM && COMMON_CLK && OF
+ depends on RESET_CONTROLLER
+ select GENERIC_PHY
+ help
+ Enable this to support the USB 2.0 PHY paired with the DWC3
+ controller on Allwinner A733 SoCs. This driver handles UTMI
+ PHY initialization, tuning, and host/device mode switching.
+ If unsure, say N.
diff --git a/drivers/phy/allwinner/Makefile b/drivers/phy/allwinner/Makefile
index 483e9053bb5f..22793d59c4cd 100644
--- a/drivers/phy/allwinner/Makefile
+++ b/drivers/phy/allwinner/Makefile
@@ -4,3 +4,4 @@ obj-$(CONFIG_PHY_SUN6I_MIPI_DPHY) += phy-sun6i-mipi-dphy.o
obj-$(CONFIG_PHY_SUN9I_USB) += phy-sun9i-usb.o
obj-$(CONFIG_PHY_SUN50I_USB3) += phy-sun50i-usb3.o
obj-$(CONFIG_PHY_SUN60I_COMBOPHY) += phy-sun60i-combophy.o
+obj-$(CONFIG_PHY_SUN60I_U2PHY) += phy-sun60i-u2phy.o
diff --git a/drivers/phy/allwinner/phy-sun60i-u2phy.c b/drivers/phy/allwinner/phy-sun60i-u2phy.c
new file mode 100644
index 000000000000..7788fe55ee56
--- /dev/null
+++ b/drivers/phy/allwinner/phy-sun60i-u2phy.c
@@ -0,0 +1,233 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Allwinner A733 USB 2.0 PHY driver
+ *
+ * Copyright (C) 2026 Alastair D'Silva <alastair@d-silva.org>
+ */
+
+#include <linux/bits.h>
+#include <linux/cleanup.h>
+#include <linux/clk.h>
+#include <linux/io.h>
+#include <linux/mod_devicetable.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/phy/phy.h>
+#include <linux/platform_device.h>
+#include <linux/reset.h>
+
+#define PHY_USB2_ISCR 0x00
+#define FORCE_ID_MASK GENMASK(15, 14)
+#define FORCE_ID_HOST BIT(15)
+#define FORCE_ID_DEVICE GENMASK(15, 14)
+#define FORCE_VBUS_VALID_MASK GENMASK(13, 12)
+#define FORCE_VBUS_VALID_HIGH GENMASK(13, 12)
+
+#define PHY_USB2_PHYCTL 0x10
+#define OTGDISABLE BIT(10)
+#define VBUSVLDEXT BIT(5)
+#define SIDDQ BIT(3)
+
+#define PHY_USB2_PHYTUNE 0x18
+/* Vendor BSP default USB2 PHY tuning value for A733. */
+#define PHYTUNE_A733_DEFAULT 0x143338d6
+
+struct sun60i_u2phy {
+ void __iomem *base;
+ struct clk_bulk_data *clks;
+ int num_clks;
+ struct reset_control *reset;
+ struct mutex lock; /* protects mode and initialized state */
+ enum phy_mode mode;
+ bool initialized;
+};
+
+static const char * const sun60i_u2phy_clks[] = {
+ "bus",
+ "ahb",
+};
+
+static void sun60i_u2phy_apply_mode(struct sun60i_u2phy *u2phy)
+{
+ u32 val;
+
+ val = readl(u2phy->base + PHY_USB2_ISCR);
+ val &= ~(FORCE_ID_MASK | FORCE_VBUS_VALID_MASK);
+
+ switch (u2phy->mode) {
+ case PHY_MODE_USB_HOST:
+ val |= FORCE_ID_HOST | FORCE_VBUS_VALID_HIGH;
+ break;
+ case PHY_MODE_USB_DEVICE:
+ val |= FORCE_ID_DEVICE | FORCE_VBUS_VALID_HIGH;
+ break;
+ case PHY_MODE_USB_OTG:
+ default:
+ break;
+ }
+
+ writel(val, u2phy->base + PHY_USB2_ISCR);
+}
+
+static int sun60i_u2phy_init(struct phy *phy)
+{
+ struct sun60i_u2phy *u2phy = phy_get_drvdata(phy);
+ u32 val;
+ int ret;
+
+ guard(mutex)(&u2phy->lock);
+
+ ret = reset_control_deassert(u2phy->reset);
+ if (ret)
+ return ret;
+
+ ret = clk_bulk_prepare_enable(u2phy->num_clks, u2phy->clks);
+ if (ret) {
+ reset_control_assert(u2phy->reset);
+ return ret;
+ }
+
+ sun60i_u2phy_apply_mode(u2phy);
+
+ val = readl(u2phy->base + PHY_USB2_PHYCTL);
+ val |= OTGDISABLE | VBUSVLDEXT;
+ val &= ~SIDDQ;
+ writel(val, u2phy->base + PHY_USB2_PHYCTL);
+
+ writel(PHYTUNE_A733_DEFAULT, u2phy->base + PHY_USB2_PHYTUNE);
+ u2phy->initialized = true;
+
+ return 0;
+}
+
+static int sun60i_u2phy_exit(struct phy *phy)
+{
+ struct sun60i_u2phy *u2phy = phy_get_drvdata(phy);
+ u32 val;
+
+ guard(mutex)(&u2phy->lock);
+
+ u2phy->initialized = false;
+
+ val = readl(u2phy->base + PHY_USB2_PHYCTL);
+ val &= ~(OTGDISABLE | VBUSVLDEXT);
+ val |= SIDDQ;
+ writel(val, u2phy->base + PHY_USB2_PHYCTL);
+
+ val = readl(u2phy->base + PHY_USB2_ISCR);
+ val &= ~(FORCE_ID_MASK | FORCE_VBUS_VALID_MASK);
+ writel(val, u2phy->base + PHY_USB2_ISCR);
+
+ clk_bulk_disable_unprepare(u2phy->num_clks, u2phy->clks);
+ return reset_control_assert(u2phy->reset);
+}
+
+static int sun60i_u2phy_set_mode(struct phy *phy, enum phy_mode mode,
+ int submode)
+{
+ struct sun60i_u2phy *u2phy = phy_get_drvdata(phy);
+
+ guard(mutex)(&u2phy->lock);
+
+ switch (mode) {
+ case PHY_MODE_USB_HOST:
+ case PHY_MODE_USB_HOST_LS:
+ case PHY_MODE_USB_HOST_FS:
+ case PHY_MODE_USB_HOST_HS:
+ case PHY_MODE_USB_HOST_SS:
+ u2phy->mode = PHY_MODE_USB_HOST;
+ break;
+ case PHY_MODE_USB_DEVICE:
+ case PHY_MODE_USB_DEVICE_LS:
+ case PHY_MODE_USB_DEVICE_FS:
+ case PHY_MODE_USB_DEVICE_HS:
+ case PHY_MODE_USB_DEVICE_SS:
+ u2phy->mode = PHY_MODE_USB_DEVICE;
+ break;
+ case PHY_MODE_USB_OTG:
+ u2phy->mode = PHY_MODE_USB_OTG;
+ break;
+ default:
+ return -EINVAL;
+ }
+
+ if (u2phy->initialized)
+ sun60i_u2phy_apply_mode(u2phy);
+
+ return 0;
+}
+
+static const struct phy_ops sun60i_u2phy_ops = {
+ .init = sun60i_u2phy_init,
+ .exit = sun60i_u2phy_exit,
+ .set_mode = sun60i_u2phy_set_mode,
+ .owner = THIS_MODULE,
+};
+
+static int sun60i_u2phy_probe(struct platform_device *pdev)
+{
+ struct device *dev = &pdev->dev;
+ struct sun60i_u2phy *u2phy;
+ struct phy_provider *phy_provider;
+ struct phy *phy;
+ int i, ret;
+
+ u2phy = devm_kzalloc(dev, sizeof(*u2phy), GFP_KERNEL);
+ if (!u2phy)
+ return -ENOMEM;
+
+ ret = devm_mutex_init(dev, &u2phy->lock);
+ if (ret)
+ return ret;
+ u2phy->mode = PHY_MODE_USB_HOST;
+ u2phy->base = devm_platform_ioremap_resource(pdev, 0);
+ if (IS_ERR(u2phy->base))
+ return PTR_ERR(u2phy->base);
+
+ u2phy->num_clks = ARRAY_SIZE(sun60i_u2phy_clks);
+ u2phy->clks = devm_kcalloc(dev, u2phy->num_clks, sizeof(*u2phy->clks),
+ GFP_KERNEL);
+ if (!u2phy->clks)
+ return -ENOMEM;
+
+ for (i = 0; i < u2phy->num_clks; i++)
+ u2phy->clks[i].id = sun60i_u2phy_clks[i];
+
+ ret = devm_clk_bulk_get(dev, u2phy->num_clks, u2phy->clks);
+ if (ret)
+ return dev_err_probe(dev, ret, "failed to get clocks\n");
+
+ u2phy->reset = devm_reset_control_get_shared(dev, NULL);
+ if (IS_ERR(u2phy->reset))
+ return dev_err_probe(dev, PTR_ERR(u2phy->reset),
+ "failed to get reset\n");
+
+ phy = devm_phy_create(dev, NULL, &sun60i_u2phy_ops);
+ if (IS_ERR(phy))
+ return dev_err_probe(dev, PTR_ERR(phy),
+ "failed to create PHY\n");
+
+ phy_set_drvdata(phy, u2phy);
+
+ phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
+ return PTR_ERR_OR_ZERO(phy_provider);
+}
+
+static const struct of_device_id sun60i_u2phy_of_match[] = {
+ { .compatible = "allwinner,sun60i-a733-u2phy" },
+ { /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, sun60i_u2phy_of_match);
+
+static struct platform_driver sun60i_u2phy_driver = {
+ .probe = sun60i_u2phy_probe,
+ .driver = {
+ .name = "sun60i-u2phy",
+ .of_match_table = sun60i_u2phy_of_match,
+ },
+};
+module_platform_driver(sun60i_u2phy_driver);
+
+MODULE_DESCRIPTION("Allwinner A733 USB 2.0 PHY driver");
+MODULE_AUTHOR("Alastair D'Silva <alastair@d-silva.org>");
+MODULE_LICENSE("GPL");
--
2.53.0
next prev parent reply other threads:[~2026-11-27 7:33 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 7:32 [PATCH 00/11] arm64: dts: allwinner: Add Allwinner A733 USB 3.0 support Alastair D'Silva
2026-11-27 7:32 ` [PATCH 01/11] dt-bindings: phy: allwinner,sun60i-a733-u2phy: Add Allwinner A733 USB 2.0 PHY Alastair D'Silva
2026-11-27 7:32 ` [PATCH 02/11] dt-bindings: phy: allwinner,sun60i-a733-combophy: Add combophy0 USB 3.0 support Alastair D'Silva
2026-11-27 7:32 ` [PATCH 03/11] dt-bindings: clock: sun60i-a733: Add USB2 bus and sys clock IDs Alastair D'Silva
2026-11-27 7:32 ` [PATCH 04/11] clk: sunxi-ng: sun60i-a733: Add USB2 bus and sys clocks Alastair D'Silva
2026-11-27 7:32 ` [PATCH 05/11] dt-bindings: usb: allwinner,sun60i-a733-dwc3: Add Allwinner A733 DWC3 Alastair D'Silva
2026-11-27 7:32 ` Alastair D'Silva [this message]
2026-11-27 7:32 ` [PATCH 07/11] phy: allwinner: sun60i-combophy: Add USB 3.0 PHY mode support Alastair D'Silva
2026-11-27 7:32 ` [PATCH 08/11] usb: dwc3: Add Allwinner A733 DWC3 support Alastair D'Silva
2026-11-27 7:32 ` [PATCH 09/11] usb: host: xhci: Add W1C port change quirk for Allwinner A733 Alastair D'Silva
2026-11-27 7:32 ` [PATCH 10/11] arm64: dts: allwinner: sun60i-a733: Add USB 3.0 controller and PHYs Alastair D'Silva
2026-11-27 7:32 ` [PATCH 11/11] arm64: dts: allwinner: sun60i-a733-orangepi-4-pro: Enable USB 3.0 Alastair D'Silva
2026-11-27 9:56 ` [PATCH 00/11] arm64: dts: allwinner: Add Allwinner A733 USB 3.0 support Andre Przywara
2026-11-27 10:26 ` Alastair D'Silva
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=20261127073231.1776847-7-alastair@d-silva.org \
--to=alastair@d-silva.org \
--cc=Thinh.Nguyen@synopsys.com \
--cc=bmasney+clk@redhat.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=jbrunet+clk@baylibre.com \
--cc=jernej.skrabec@gmail.com \
--cc=krzk+dt@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-clk@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-phy@lists.infradead.org \
--cc=linux-sunxi@lists.linux.dev \
--cc=linux-usb@vger.kernel.org \
--cc=mathias.nyman@intel.com \
--cc=neil.armstrong@linaro.org \
--cc=robh@kernel.org \
--cc=samuel@sholland.org \
--cc=sboyd@kernel.org \
--cc=vkoul@kernel.org \
--cc=wens@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®