phy: nuvoton: extend MA35D1 USB2 PHY driver for dual-port OTG support
Subsystems (4)
v9 cover phy: nuvoton: extend MA35D1 USB2 PHY driver for dual-port OTG support
The MA35D1 SoC has two USB PHY ports managed by a shared hardware block:
- PHY0 (USB0): OTG port shared between the DWC2 gadget controller and the EHCI0/OHCI0 host controllers. A hardware mux automatically routes USB0 signals to the correct controller based on the USB ID pin state.
- PHY1 (USB1): dedicated host-only port for EHCI1/OHCI1.
This series extends the existing phy-ma35d1-usb2.c driver and its binding to cover both ports and add OTG role-switch support, while keeping full backward compatibility with existing device trees.
Changes since v8:
- dts: set the DWC2 (USB0) register window to 0x40000
(0x4020_0000-0x4024_0000, per the MA35D1 spec) instead of 0x1000, so
that it covers the per-endpoint FIFO region at 0x1000 + n * 0x1000.
The EHCI/OHCI windows were checked against the spec and are
unchanged. - phy: select MFD_SYSCON in PHY_MA35_USB, as the driver depends on syscon_regmap_lookup_by_phandle().
- Patches 1 and 3 are unchanged.
Changes since v7:
- phy: add "depends on USB_ROLE_SWITCH || !USB_ROLE_SWITCH" to PHY_MA35_USB, so a built-in PHY driver cannot be combined with a modular role switch core (link failure on usb_role_switch_register()).
- phy: restore the PHY reset fallback. If the PHY is already in operation mode but its clocks do not become stable, reset it and poll again instead of failing immediately. The reset is still skipped when the already-running PHY reports stable clocks.
- phy: gate the HUSBH0_GATE clock dynamically again. The clock is no longer enabled for the whole lifetime of the driver (devm_clk_get() instead of devm_clk_get_enabled()); .power_on/.power_off enable and disable it, and .init enables it around its register accesses. The gate can therefore close when neither port is powered.
- phy: nuvoton,oc-active-high: keep writing the polarity bit unconditionally, so that an absent property means active-low as documented in the binding, regardless of what the bootloader left in MISCFCR0. The bit only affects the EHCI/OHCI host ports' VBUS switch and is irrelevant to the gadget use of PHY0. This is a new property in this series, and no mainline DT depends on a bootloader-programmed polarity.
- Patches 1-3 are unchanged.
Changes since v6:
- phy: update the copyright notice in the rewritten driver header to "2024-2026" instead of "2026", preserving the original 2024 date rather than dropping it.
- phy: split the unused linux/io.h removal out of patch 4 into its own patch (3/4), since it's unrelated cleanup that predates this series (the driver has never done direct MMIO access; all register access goes through regmap via syscon_regmap_lookup_by_phandle()). Placed immediately before patch 4 since that is the first patch in the series to touch this file.
Joey Lu (4):
dt-bindings: phy: nuvoton,ma35d1-usb2-phy: extend for dual-port and
OTG
arm64: dts: nuvoton: ma35d1: add USB controllers and dual-port PHY
node
phy: nuvoton: phy-ma35d1-usb2: remove unused linux/io.h include
phy: nuvoton: phy-ma35d1-usb2: extend to dual-port with OTG support
.../bindings/phy/nuvoton,ma35d1-usb2-phy.yaml | 44 ++- .../boot/dts/nuvoton/ma35d1-iot-512m.dts | 36 ++ .../boot/dts/nuvoton/ma35d1-som-256m.dts | 36 ++ arch/arm64/boot/dts/nuvoton/ma35d1.dtsi | 65 ++++ drivers/phy/nuvoton/Kconfig | 2 + drivers/phy/nuvoton/phy-ma35d1-usb2.c | 313 +++++++++++++----- 6 files changed, 420 insertions(+), 76 deletions(-)
base-commit: cee9395acd8043be0644b25c34bfa86623f2b935
Signature · 1 line
2.43.0
PATCH v9 1/4 dt-bindings: phy: nuvoton,ma35d1-usb2-phy: extend for dual-port and OTG
The MA35D1 exposes two USB PHY ports (PHY0 and PHY1) managed by the same hardware block (USBPMISCR register in the system-management syscon). PHY0 is shared between the DWC2 gadget controller and EHCI0/OHCI0 through an automatic hardware mux that follows the USB ID pin; PHY1 is dedicated to EHCI1/OHCI1. Because both ports share the same register topology a single binding and driver should cover both.
Changing '#phy-cells' from const: 0 to enum: [0, 1] lets consumers name the port they need while preserving backward compatibility: boards already using '#phy-cells = <0>' continue to validate and function unchanged.
The two new optional properties:
- nuvoton,rcalcode: the resistor calibration trim code is determined at board design time to match the PCB trace impedance. Both PHY0 and PHY1 values must be supplied together when the property is present.
- nuvoton,oc-active-high: the over-current detect polarity depends on the choice of VBUS power switch.
--- .../bindings/phy/nuvoton,ma35d1-usb2-phy.yaml | 44 ++++++++++++++++++- 1 file changed, 42 insertions(+), 2 deletions(-)
Documentation/devicetree/bindings/phy/nuvoton,ma35d1-usb2-phy.yaml +42 -2
@@ -8,6 +8,18 @@ title: Nuvoton MA35D1 USB2 phy maintainers: - Hui-Ping Chen <[email protected]> + - Joey Lu <[email protected]> + +description: + USB 2.0 PHY for the Nuvoton MA35D1 SoC. The PHY node is a standalone + platform device that accesses the USB PHY control registers inside the + system-management syscon block via the nuvoton,sys phandle. + + PHY0 is the OTG port whose signals are routed to either the DWC2 gadget + controller or the EHCI0/OHCI0 host controller by a hardware mux that + follows the USB ID pin automatically. + + PHY1 is a dedicated host-only port used by EHCI1/OHCI1. properties: compatible:
@@ -15,7 +27,12 @@ properties: - nuvoton,ma35d1-usb2-phy "#phy-cells": - const: 0 + enum: [0, 1] + description: + When 0, the node exposes PHY0 only and consumers reference it + with no cell argument. When 1, the single cell selects the port, + with 0 for the OTG port (USB0, shared with DWC2 gadget controller) + and 1 for the host-only port (USB1). clocks: maxItems: 1
@@ -23,7 +40,29 @@ properties: nuvoton,sys: $ref: /schemas/types.yaml#/definitions/phandle description: - phandle to syscon for checking the PHY clock status. + Phandle to the system-management syscon node providing access to the + USB PHY control registers. + + nuvoton,rcalcode: + $ref: /schemas/types.yaml#/definitions/uint32-array + minItems: 2 + maxItems: 2 + items: + minimum: 0 + maximum: 15 + description: + Resistor calibration trim codes for PHY0 and PHY1 respectively. + Each 4-bit value is written to the RCALCODE field in USBPMISCR and + adjusts the PHY's internal termination resistance. Both entries must + be supplied when this property is present; when absent the hardware + reset default is used for each port. + + nuvoton,oc-active-high: + type: boolean + description: + When present, the over-current detect input from the VBUS power switch + is treated as active-high. The default (property absent) is active-low. + This setting is shared by both USB host ports. required: - compatible
@@ -42,4 +81,5 @@ examples: clocks = <&clk USBD_GATE>; nuvoton,sys = <&sys>; #phy-cells = <0>; + nuvoton,rcalcode = <7 7>; };
Signature · 1 line
2.43.0
PATCH v9 2/4 arm64: dts: nuvoton: ma35d1: add USB controllers and dual-port PHY node
In reply to Joey LuAdd the USB subsystem nodes for the MA35D1 SoC and boards:
- usb_phy: standalone PHY node with #phy-cells = <1>, covering both the OTG port (PHY0, index 0) and the host-only port (PHY1, index 1). Uses nuvoton,sys phandle and HUSBH0_GATE clock per the binding.
- usb (DWC2 gadget, USB0): phys = <&usb_phy 0>, dr_mode = peripheral.
- ehci0/ohci0 (USB0 host): phys = <&usb_phy 0>, companion pairing.
- ehci1/ohci1 (USB1 host): phys = <&usb_phy 1>.
Board files (ma35d1-som-256m.dts, ma35d1-iot-512m.dts) add pinctrl for VBUSVLD, PWREN and OVC signals and enable all USB nodes.
--- .../boot/dts/nuvoton/ma35d1-iot-512m.dts | 36 ++++++++++ .../boot/dts/nuvoton/ma35d1-som-256m.dts | 36 ++++++++++ arch/arm64/boot/dts/nuvoton/ma35d1.dtsi | 65 +++++++++++++++++++ 3 files changed, 137 insertions(+)
arch/arm64/boot/dts/nuvoton/ma35d1-iot-512m.dts +36 -0
@@ -97,6 +97,16 @@ pinctrl_uart14: uart14-pins { power-source = <1>; }; }; + + hsusb-grp { + pinctrl_hsusb: hsusb-pins { + nuvoton,pins = <5 15 1>, /* VBUSVLD */ + <11 12 9>, /* PWREN */ + <11 13 9>; /* OVC */ + bias-disable; + power-source = <1>; + }; + }; }; &uart0 {
@@ -151,3 +161,29 @@ eth_phy1: ethernet-phy@1 { reg = <1>; }; }; + +&usb_phy { + pinctrl-names = "default"; + pinctrl-0 = <&pinctrl_hsusb>; + status = "okay"; +}; + +&usb { + status = "okay"; +}; + +&ehci0 { + status = "okay"; +}; + +&ehci1 { + status = "okay"; +}; + +&ohci0 { + status = "okay"; +}; + +&ohci1 { + status = "okay"; +};
arch/arm64/boot/dts/nuvoton/ma35d1-som-256m.dts +36 -0
@@ -100,6 +100,16 @@ pinctrl_uart16: uart16-pins { power-source = <1>; }; }; + + hsusb-grp { + pinctrl_hsusb: hsusb-pins { + nuvoton,pins = <5 15 1>, /* VBUSVLD */ + <11 12 9>, /* PWREN */ + <11 13 9>; /* OVC */ + bias-disable; + power-source = <1>; + }; + }; }; &uart0 {
@@ -153,3 +163,29 @@ eth_phy1: ethernet-phy@1 { reg = <1>; }; }; + +&usb_phy { + pinctrl-names = "default"; + pinctrl-0 = <&pinctrl_hsusb>; + status = "okay"; +}; + +&usb { + status = "okay"; +}; + +&ehci0 { + status = "okay"; +}; + +&ehci1 { + status = "okay"; +}; + +&ohci0 { + status = "okay"; +}; + +&ohci1 { + status = "okay"; +};
arch/arm64/boot/dts/nuvoton/ma35d1.dtsi +65 -0
76 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v9 3/4 phy: nuvoton: phy-ma35d1-usb2: remove unused linux/io.h include
In reply to Joey LuThis driver never performs direct MMIO access (no readl()/writel()/ ioremap()/__iomem); all register access goes through regmap via syscon_regmap_lookup_by_phandle(). linux/io.h has therefore been unused since the driver was first added.
--- drivers/phy/nuvoton/phy-ma35d1-usb2.c | 1 - 1 file changed, 1 deletion(-)
drivers/phy/nuvoton/phy-ma35d1-usb2.c +0 -1
@@ -5,7 +5,6 @@#include <linux/bitfield.h> #include <linux/clk.h> #include <linux/delay.h> -#include <linux/io.h> #include <linux/kernel.h> #include <linux/mfd/syscon.h> #include <linux/module.h>
Signature · 1 line
2.43.0
PATCH v9 4/4 phy: nuvoton: phy-ma35d1-usb2: extend to dual-port with OTG support
In reply to Joey LuPHY0 and PHY1 use the same power-on/reset sequence in USBPMISCR, with PHY1 control bits shifted 16 positions relative to PHY0. A separate driver for PHY1 would duplicate this logic, so the existing driver is extended to manage both ports.
The original driver polled only DEVCKSTB after releasing PHY0 from reset. When USB0 operates in host mode (USB ID pin floating or tied high) only HSTCKSTB and CK12MSTB assert; DEVCKSTB never sets. Polling exclusively for DEVCKSTB in host mode causes a 1 ms timeout on every phy_init() call from the EHCI driver. The init callback is changed to accept either host-mode or device-mode clock stability, whichever asserts first.
The init callback handles PHY reset and clock-stable polling. The power_on and power_off callbacks only gate the HUSBH0_GATE clock shared by both ports, so it stays off when neither port is in use. If a PHY already in operation mode does not report stable clocks, it is reset before failing.
A read-only USB role switch is registered for PHY0 to expose the USB0 role to userspace via the standard role-switch sysfs interface. The .set callback returns -EOPNOTSUPP because the hardware mux is fully automatic with no software override path. When CONFIG_USB_ROLE_SWITCH is not enabled, the registration returns -ENODEV and the driver skips the role switch gracefully without failing probe.
Two new optional device-tree properties are implemented:
- nuvoton,rcalcode: writes per-port 4-bit resistor calibration trim codes to the RCALCODE field in USBPMISCR.
- nuvoton,oc-active-high: sets the UHOVRCURH bit in MISCFCR0 to treat the over-current detect input as active-high. When absent, the bit is cleared (active-low) regardless of the bootloader setting.
--- drivers/phy/nuvoton/Kconfig | 2 + drivers/phy/nuvoton/phy-ma35d1-usb2.c | 312 ++++++++++++++++++++------ 2 files changed, 241 insertions(+), 73 deletions(-)
drivers/phy/nuvoton/Kconfig +2 -0
@@ -6,7 +6,9 @@ config PHY_MA35_USB tristate "Nuvoton MA35 USB2.0 PHY driver" depends on ARCH_MA35 || COMPILE_TEST depends on OF + depends on USB_ROLE_SWITCH || !USB_ROLE_SWITCH select GENERIC_PHY + select MFD_SYSCON help Enable this to support the USB2.0 PHY on the Nuvoton MA35 series SoCs.
drivers/phy/nuvoton/phy-ma35d1-usb2.c +239 -73
376 lines not on this page · raw message
Signature · 1 line
2.43.0
Manivannan Sadhasivam
reviewerRe: [PATCH v9 4/4] phy: nuvoton: phy-ma35d1-usb2: extend to dual-port with OTG support
Quoted 58 lines · Joey Lu
PHY0 and PHY1 use the same power-on/reset sequence in USBPMISCR, with PHY1 control bits shifted 16 positions relative to PHY0. A separate driver for PHY1 would duplicate this logic, so the existing driver is extended to manage both ports.
The original driver polled only DEVCKSTB after releasing PHY0 from reset. When USB0 operates in host mode (USB ID pin floating or tied high) only HSTCKSTB and CK12MSTB assert; DEVCKSTB never sets. Polling exclusively for DEVCKSTB in host mode causes a 1 ms timeout on every
phy_init()call from the EHCI driver. The init callback is changed to accept either host-mode or device-mode clock stability, whichever asserts first.The init callback handles PHY reset and clock-stable polling. The
power_onandpower_offcallbacks only gate theHUSBH0_GATEclock shared by both ports, so it stays off when neither port is in use. If a PHY already in operation mode does not report stable clocks, it is reset before failing.A read-only USB role switch is registered for PHY0 to expose the USB0 role to userspace via the standard role-switch sysfs interface. The .set callback returns
-EOPNOTSUPPbecause the hardware mux is fully automatic with no software override path. WhenCONFIG_USB_ROLE_SWITCHis not enabled, the registration returns-ENODEVand the driver skips the role switch gracefully without failing probe.Two new optional device-tree properties are implemented:
- nuvoton,rcalcode: writes per-port 4-bit resistor calibration trim codes to the RCALCODE field in USBPMISCR.
- nuvoton,oc-active-high: sets the UHOVRCURH bit in MISCFCR0 to treat the over-current detect input as active-high. When absent, the bit is cleared (active-low) regardless of the bootloader setting.Signed-off-by Joey Lu <[email protected]>--- drivers/phy/nuvoton/Kconfig | 2 + drivers/phy/nuvoton/phy-ma35d1-usb2.c | 312 ++++++++++++++++++++------ 2 files changed, 241 insertions(+), 73 deletions(-)drivers/phy/nuvoton/Kconfig +2
-0@@ -6,7 +6,9 @@ config PHY_MA35_USB tristate "Nuvoton MA35 USB2.0 PHY driver" depends on ARCH_MA35 || COMPILE_TEST depends on OF + depends on USB_ROLE_SWITCH || !USB_ROLE_SWITCH select GENERIC_PHY + select MFD_SYSCON help Enable this to support the USB2.0 PHY on the Nuvoton MA35 series SoCs.drivers/phy/nuvoton/phy-ma35d1-usb2.c +0
-0
drivers/phy/nuvoton/phy-ma35d1-usb2.c line 9
Quoted 10 lines
drivers/phy/nuvoton/phy-ma35d1-usb2.c +7
-1@@ -1,6 +1,12 @@// SPDX-License-Identifier: GPL-2.0 /* -* Copyright (C) 2024 Nuvoton Technology Corp. +* Nuvoton MA35D1 USB 2.0 PHY driver +* +* Supports PHY0 (USB0 OTG port, shared between DWC2 gadget and EHCI0/OHCI0) +* and PHY1 (USB1 host-only port, used by EHCI1/OHCI1). The hardware mux on +* PHY0 switches automatically via the USB ID pin. +* +* Copyright (C) 2024-2026 Nuvoton Technology Corp.
Are you affiliated with Nuvoton? Your email doesn't say so. So you do not have the authority to change the copyright (not even extend it).
Quoted 38 lines
drivers/phy/nuvoton/phy-ma35d1-usb2.c +24
-6*/ #include <linux/bitfield.h> #include <linux/clk.h> @@ -12,131 +18,291 @@#include <linux/phy/phy.h> #include <linux/platform_device.h> #include <linux/regmap.h> +#include <linux/usb/role.h> -/* USB PHY Miscellaneous Control Register */ -#define MA35_SYS_REG_USBPMISCR 0x60 -#define PHY0POR BIT(0)/* PHY Power-On Reset Control Bit */ -#define PHY0SUSPEND BIT(1)/* PHY Suspend; 0: suspend, 1: operaion */ -#define PHY0COMN BIT(2)/* PHY Common Block Power-Down Control */ -#define PHY0DEVCKSTB BIT(10)/* PHY 60 MHz UTMI clock stable bit */ +#define MA35_SYS_PWRONOTP 0x04 +#define PWRONOTP_USBP0ID BIT(16) + +#define MA35_SYS_USBPMISCR 0x60 +#define USBPMISCR_PHY_POR (n) BIT(0 + (n) * 16) +#define USBPMISCR_PHY_SUSPEND (n) BIT(1 + (n) * 16) +#define USBPMISCR_PHY_COMN (n) BIT(2 + (n) * 16) +#define USBPMISCR_PHY_HSTCKSTB (n) BIT(8 + (n) * 16) +#define USBPMISCR_PHY_CK12MSTB (n) BIT(9 + (n) * 16) +#define USBPMISCR_PHY_DEVCKSTB (n) BIT(10 + (n) * 16) +/* Mask for control bits (POR, SUSPEND, COMN) */ +#define USBPMISCR_PHY_CTL_MASK (n) (0x7u << ((n) * 16)) +/* Host-mode ready */ +#define USBPMISCR_PHY_HOST_READY (n) (USBPMISCR_PHY_SUSPEND(n) | \ + USBPMISCR_PHY_HSTCKSTB(n) | \ + USBPMISCR_PHY_CK12MSTB(n)) +/* Device-mode ready */ +#define USBPMISCR_PHY_DEV_READY (n) (USBPMISCR_PHY_SUSPEND(n) | \ + USBPMISCR_PHY_DEVCKSTB(n)) +/* RCALCODE: 4-bit resistor trim */ +#define USBPMISCR_RCAL_SHIFT (n) (12 + (n) * 16) +#define USBPMISCR_RCAL_MASK (n) GENMASK(USBPMISCR_RCAL_SHIFT(n) + 3, \ + USBPMISCR_RCAL_SHIFT(n))
drivers/phy/nuvoton/phy-ma35d1-usb2.c line 55
Quoted 10 lines
drivers/phy/nuvoton/phy-ma35d1-usb2.c +10
-0+ +#define MA35_SYS_MISCFCR0 0x70 +/* USB host over-current detect polarity (shared, both ports) */ +#define MISCFCR0_UHOVRCURH BIT(12) + +#define MA35_PHY_NUM 2 + +struct ma35_phy_port { +struct phy *phy; +unsigned int idx;
u32
Quoted 4 lines
drivers/phy/nuvoton/phy-ma35d1-usb2.c +1
-1+};struct ma35_usb_phy { -struct clk *clk;
drivers/phy/nuvoton/phy-ma35d1-usb2.c line 67
Quoted 10 lines
drivers/phy/nuvoton/phy-ma35d1-usb2.c +5
-1struct device *dev;struct regmap *sysreg; +struct clk *clk; +struct ma35_phy_port port[MA35_PHY_NUM ]; +struct usb_role_switch *role_sw; }; -static int ma35_usb_phy_power_on (struct phy *phy) +static int ma35_usb_phy_wait_ready (struct ma35_usb_phy *p,unsigned int n, +unsigned int *val)
u32 instead of 'unsigned int' wherever applicable.
Quoted 24 lines
drivers/phy/nuvoton/phy-ma35d1-usb2.c +21
-1{ -struct ma35_usb_phy *p_phy =phy_get_drvdata (phy); +if (n ==0 ) +return regmap_read_poll_timeout (p->sysreg,MA35_SYS_USBPMISCR , + *val, + ((*val &USBPMISCR_PHY_HOST_READY (0 )) == +USBPMISCR_PHY_HOST_READY (0 )) || + ((*val &USBPMISCR_PHY_DEV_READY (0 )) == +USBPMISCR_PHY_DEV_READY (0 )), +10 ,1000 ); + +return regmap_read_poll_timeout (p->sysreg,MA35_SYS_USBPMISCR , *val, + (*val &USBPMISCR_PHY_HOST_READY (n)) == +USBPMISCR_PHY_HOST_READY (n), +10 ,1000 ); +} + +static int ma35_usb_phy_init (struct phy *phy) +{ +struct ma35_phy_port *port =phy_get_drvdata (phy); +struct ma35_usb_phy *p =container_of (port - port->idx, + struct ma35_usb_phy, port[0]); +unsigned int n = port->idx;unsigned int val;
drivers/phy/nuvoton/phy-ma35d1-usb2.c line 95
Quoted 10 lines
drivers/phy/nuvoton/phy-ma35d1-usb2.c +3
-5int ret; - ret =clk_prepare_enable (p_phy->clk); -if (ret <0 ) { -dev_err (p_phy->dev,"Failed to enable PHY clock: %d\n" , ret); -return ret; - } + ret =clk_prepare_enable (p->clk); +if (ret) +return dev_err_probe (p->dev, ret,"failed to enable clock\n" );
Please do not use dev_err_probe() outside of probe(). It is meant to be used in probe() where the driver probe can fail with probe deferrals.
Quoted 71 lines
drivers/phy/nuvoton/phy-ma35d1-usb2.c +30
-29-regmap_read (p_phy->sysreg,MA35_SYS_REG_USBPMISCR , &val); -if (val &PHY0SUSPEND ) { -/* -* USB PHY0 is in operation mode already -* make sure USB PHY 60 MHz UTMI Interface Clock ready -*/ - ret =regmap_read_poll_timeout (p_phy->sysreg,MA35_SYS_REG_USBPMISCR , val, - val &PHY0DEVCKSTB ,10 ,1000 ); -if (ret ==0 ) -return 0 ; - } +regmap_read (p->sysreg,MA35_SYS_USBPMISCR , &val); -/* -* reset USB PHY0. -* wait until USB PHY0 60 MHz UTMI Interface Clock ready -*/ -regmap_update_bits (p_phy->sysreg,MA35_SYS_REG_USBPMISCR ,0x7 , (PHY0POR |PHY0SUSPEND )); +if ((val &USBPMISCR_PHY_SUSPEND (n)) && + !ma35_usb_phy_wait_ready (p, n, &val)) + goto out; + +regmap_update_bits (p->sysreg,MA35_SYS_USBPMISCR , +USBPMISCR_PHY_CTL_MASK (n), +USBPMISCR_PHY_POR (n) |USBPMISCR_PHY_SUSPEND (n));udelay (20 ); -/* make USB PHY0 enter operation mode */ -regmap_update_bits (p_phy->sysreg,MA35_SYS_REG_USBPMISCR ,0x7 ,PHY0SUSPEND ); +regmap_update_bits (p->sysreg,MA35_SYS_USBPMISCR , +USBPMISCR_PHY_CTL_MASK (n), +USBPMISCR_PHY_SUSPEND (n)); -/* make sure USB PHY 60 MHz UTMI Interface Clock ready */ - ret =regmap_read_poll_timeout (p_phy->sysreg,MA35_SYS_REG_USBPMISCR , val, - val &PHY0DEVCKSTB ,10 ,1000 ); -if (ret == -ETIMEDOUT ) { -dev_err (p_phy->dev,"Check PHY clock, Timeout: %d\n" , ret); -clk_disable_unprepare (p_phy->clk); -return ret; - } + ret =ma35_usb_phy_wait_ready (p, n, &val); +if (ret) +dev_err (p->dev,"USB PHY%u clock not stable (USBPMISCR=0x%08x)\n" , + n, val); +out: +clk_disable_unprepare (p->clk); +return ret; +} -return 0 ; +static int ma35_usb_phy_power_on (struct phy *phy) +{ +struct ma35_phy_port *port =phy_get_drvdata (phy); +struct ma35_usb_phy *p =container_of (port - port->idx, + struct ma35_usb_phy, port[0]); + +return clk_prepare_enable (p->clk); }static int ma35_usb_phy_power_off (struct phy *phy) { -struct ma35_usb_phy *p_phy =phy_get_drvdata (phy); +struct ma35_phy_port *port =phy_get_drvdata (phy); +struct ma35_usb_phy *p =container_of (port - port->idx, + struct ma35_usb_phy, port[0]); -clk_disable_unprepare (p_phy->clk); +clk_disable_unprepare (p->clk);return 0 ;
drivers/phy/nuvoton/phy-ma35d1-usb2.c line 144
Quoted 10 lines
drivers/phy/nuvoton/phy-ma35d1-usb2.c +4
-3}static const struct phy_ops ma35_usb_phy_ops = { - .power_on = ma35_usb_phy_power_on, - .power_off = ma35_usb_phy_power_off, - .owner =THIS_MODULE , + .init = ma35_usb_phy_init, + .power_on = ma35_usb_phy_power_on, + .power_off = ma35_usb_phy_power_off, + .owner =THIS_MODULE ,
Just keep a single space before =
Quoted 2 lines
drivers/phy/nuvoton/phy-ma35d1-usb2.c +0
-0};
[...]
drivers/phy/nuvoton/phy-ma35d1-usb2.c line 291
Quoted 12 lines
drivers/phy/nuvoton/phy-ma35d1-usb2.c +9
-2+static void ma35_usb_phy_remove (struct platform_device *pdev) +{ +struct ma35_usb_phy *p =platform_get_drvdata (pdev); + +ma35_role_switch_exit (p); +} +static const struct of_device_id ma35_usb_phy_of_match[] = { - { .compatible ="nuvoton,ma35d1-usb2-phy" , }, - { }, + { .compatible ="nuvoton,ma35d1-usb2-phy" }, + {/* sentinel */ }
Not necessary.
drivers/phy/nuvoton/phy-ma35d1-usb2.c line 298
Quoted 10 lines
};
MODULE_DEVICE_TABLE(of, ma35_usb_phy_of_match);static struct
platform_driverma35_usb_phy_driver= {drivers/phy/nuvoton/phy-ma35d1-usb2.c +2
-3.probe = ma35_usb_phy_probe, - .driver = { - .name = "ma35d1-usb2-phy", - .of_match_table = ma35_usb_phy_of_match, + .remove = ma35_usb_phy_remove, + .driver = {
I'd argue that you should just leave a single space before =.
- Mani
Re: [PATCH v9 4/4] phy: nuvoton: phy-ma35d1-usb2: extend to dual-port with OTG support
Quoted 63 lines · Manivannan Sadhasivam
Quoted 62 lines · Joey Lu
PHY0 and PHY1 use the same power-on/reset sequence in USBPMISCR, with PHY1 control bits shifted 16 positions relative to PHY0. A separate driver for PHY1 would duplicate this logic, so the existing driver is extended to manage both ports.
The original driver polled only DEVCKSTB after releasing PHY0 from reset. When USB0 operates in host mode (USB ID pin floating or tied high) only HSTCKSTB and CK12MSTB assert; DEVCKSTB never sets. Polling exclusively for DEVCKSTB in host mode causes a 1 ms timeout on every
phy_init()call from the EHCI driver. The init callback is changed to accept either host-mode or device-mode clock stability, whichever asserts first.The init callback handles PHY reset and clock-stable polling. The
power_onandpower_offcallbacks only gate theHUSBH0_GATEclock shared by both ports, so it stays off when neither port is in use. If a PHY already in operation mode does not report stable clocks, it is reset before failing.A read-only USB role switch is registered for PHY0 to expose the USB0 role to userspace via the standard role-switch sysfs interface. The .set callback returns
-EOPNOTSUPPbecause the hardware mux is fully automatic with no software override path. WhenCONFIG_USB_ROLE_SWITCHis not enabled, the registration returns-ENODEVand the driver skips the role switch gracefully without failing probe.Two new optional device-tree properties are implemented:
- nuvoton,rcalcode: writes per-port 4-bit resistor calibration trim codes to the RCALCODE field in USBPMISCR.
- nuvoton,oc-active-high: sets the UHOVRCURH bit in MISCFCR0 to treat the over-current detect input as active-high. When absent, the bit is cleared (active-low) regardless of the bootloader setting.Signed-off-by Joey Lu <[email protected]>--- drivers/phy/nuvoton/Kconfig | 2 + drivers/phy/nuvoton/phy-ma35d1-usb2.c | 312 ++++++++++++++++++++------ 2 files changed, 241 insertions(+), 73 deletions(-)drivers/phy/nuvoton/Kconfig +2
-0@@ -6,7 +6,9 @@ config PHY_MA35_USB tristate "Nuvoton MA35 USB2.0 PHY driver" depends on ARCH_MA35 || COMPILE_TEST depends on OF + depends on USB_ROLE_SWITCH || !USB_ROLE_SWITCH select GENERIC_PHY + select MFD_SYSCON help Enable this to support the USB2.0 PHY on the Nuvoton MA35 series SoCs.drivers/phy/nuvoton/phy-ma35d1-usb2.c +1
-1@@ -1,6 +1,12 @@// SPDX-License-Identifier: GPL-2.0 /* -* Copyright (C) 2024 Nuvoton Technology Corp. +* Nuvoton MA35D1 USB 2.0 PHY driver
Quoted 8 lines
drivers/phy/nuvoton/phy-ma35d1-usb2.c line 9
Quoted 6 lines
drivers/phy/nuvoton/phy-ma35d1-usb2.c +6
-0+* +* Supports PHY0 (USB0 OTG port, shared between DWC2 gadget and EHCI0/OHCI0) +* and PHY1 (USB1 host-only port, used by EHCI1/OHCI1). The hardware mux on +* PHY0 switches automatically via the USB ID pin. +* +* Copyright (C) 2024-2026 Nuvoton Technology Corp. Are you affiliated with Nuvoton? Your email doesn't say so. So you do not have the authority to change the copyright (not even extend it).
Sorry about that. I'll restore the original line and keep it unchanged.
Quoted 41 lines
Quoted 41 lines
drivers/phy/nuvoton/phy-ma35d1-usb2.c +27
-6*/ #include <linux/bitfield.h> #include <linux/clk.h> @@ -12,131 +18,291 @@#include <linux/phy/phy.h> #include <linux/platform_device.h> #include <linux/regmap.h> +#include <linux/usb/role.h> -/* USB PHY Miscellaneous Control Register */ -#define MA35_SYS_REG_USBPMISCR 0x60 -#define PHY0POR BIT(0)/* PHY Power-On Reset Control Bit */ -#define PHY0SUSPEND BIT(1)/* PHY Suspend; 0: suspend, 1: operaion */ -#define PHY0COMN BIT(2)/* PHY Common Block Power-Down Control */ -#define PHY0DEVCKSTB BIT(10)/* PHY 60 MHz UTMI clock stable bit */ +#define MA35_SYS_PWRONOTP 0x04 +#define PWRONOTP_USBP0ID BIT(16) + +#define MA35_SYS_USBPMISCR 0x60 +#define USBPMISCR_PHY_POR (n) BIT(0 + (n) * 16) +#define USBPMISCR_PHY_SUSPEND (n) BIT(1 + (n) * 16) +#define USBPMISCR_PHY_COMN (n) BIT(2 + (n) * 16) +#define USBPMISCR_PHY_HSTCKSTB (n) BIT(8 + (n) * 16) +#define USBPMISCR_PHY_CK12MSTB (n) BIT(9 + (n) * 16) +#define USBPMISCR_PHY_DEVCKSTB (n) BIT(10 + (n) * 16) +/* Mask for control bits (POR, SUSPEND, COMN) */ +#define USBPMISCR_PHY_CTL_MASK (n) (0x7u << ((n) * 16)) +/* Host-mode ready */ +#define USBPMISCR_PHY_HOST_READY (n) (USBPMISCR_PHY_SUSPEND(n) | \ + USBPMISCR_PHY_HSTCKSTB(n) | \ + USBPMISCR_PHY_CK12MSTB(n)) +/* Device-mode ready */ +#define USBPMISCR_PHY_DEV_READY (n) (USBPMISCR_PHY_SUSPEND(n) | \ + USBPMISCR_PHY_DEVCKSTB(n)) +/* RCALCODE: 4-bit resistor trim */ +#define USBPMISCR_RCAL_SHIFT (n) (12 + (n) * 16) +#define USBPMISCR_RCAL_MASK (n) GENMASK(USBPMISCR_RCAL_SHIFT(n) + 3, \ + USBPMISCR_RCAL_SHIFT(n)) + +#define MA35_SYS_MISCFCR0 0x70 +/* USB host over-current detect polarity (shared, both ports) */
Quoted 8 lines
drivers/phy/nuvoton/phy-ma35d1-usb2.c line 55
Quoted 7 lines
drivers/phy/nuvoton/phy-ma35d1-usb2.c +7
-0+#define MISCFCR0_UHOVRCURH BIT(12) + +#define MA35_PHY_NUM 2 + +struct ma35_phy_port { +struct phy *phy; +unsigned int idx;u32
I'll change it to u32.
Quoted 11 lines
Quoted 11 lines
drivers/phy/nuvoton/phy-ma35d1-usb2.c +4
-1+};struct ma35_usb_phy { -struct clk *clk;struct device *dev;struct regmap *sysreg; +struct clk *clk; +struct ma35_phy_port port[MA35_PHY_NUM ]; +struct usb_role_switch *role_sw; };
Quoted 4 lines
drivers/phy/nuvoton/phy-ma35d1-usb2.c line 67
Quoted 3 lines
drivers/phy/nuvoton/phy-ma35d1-usb2.c +2
-1-static int ma35_usb_phy_power_on (struct phy *phy) +static int ma35_usb_phy_wait_ready (struct ma35_usb_phy *p,unsigned int n, +unsigned int *val)u32 instead of 'unsigned int' wherever applicable.
I'll convert all of them to u32.
Quoted 26 lines
Quoted 26 lines
drivers/phy/nuvoton/phy-ma35d1-usb2.c +21
-1{ -struct ma35_usb_phy *p_phy =phy_get_drvdata (phy); +if (n ==0 ) +return regmap_read_poll_timeout (p->sysreg,MA35_SYS_USBPMISCR , + *val, + ((*val &USBPMISCR_PHY_HOST_READY (0 )) == +USBPMISCR_PHY_HOST_READY (0 )) || + ((*val &USBPMISCR_PHY_DEV_READY (0 )) == +USBPMISCR_PHY_DEV_READY (0 )), +10 ,1000 ); + +return regmap_read_poll_timeout (p->sysreg,MA35_SYS_USBPMISCR , *val, + (*val &USBPMISCR_PHY_HOST_READY (n)) == +USBPMISCR_PHY_HOST_READY (n), +10 ,1000 ); +} + +static int ma35_usb_phy_init (struct phy *phy) +{ +struct ma35_phy_port *port =phy_get_drvdata (phy); +struct ma35_usb_phy *p =container_of (port - port->idx, + struct ma35_usb_phy, port[0]); +unsigned int n = port->idx;unsigned int val;int ret;
Quoted 10 lines
drivers/phy/nuvoton/phy-ma35d1-usb2.c line 95
Quoted 8 lines
drivers/phy/nuvoton/phy-ma35d1-usb2.c +3
-5- ret =clk_prepare_enable (p_phy->clk); -if (ret <0 ) { -dev_err (p_phy->dev,"Failed to enable PHY clock: %d\n" , ret); -return ret; - } + ret =clk_prepare_enable (p->clk); +if (ret) +return dev_err_probe (p->dev, ret,"failed to enable clock\n" );Please do not use
dev_err_probe()outside ofprobe(). It is meant to be used inprobe()where the driver probe can fail with probe deferrals.
I'll use plain dev_err() with the error code and return ret in init().
Quoted 73 lines
Quoted 73 lines
drivers/phy/nuvoton/phy-ma35d1-usb2.c +30
-29-regmap_read (p_phy->sysreg,MA35_SYS_REG_USBPMISCR , &val); -if (val &PHY0SUSPEND ) { -/* -* USB PHY0 is in operation mode already -* make sure USB PHY 60 MHz UTMI Interface Clock ready -*/ - ret =regmap_read_poll_timeout (p_phy->sysreg,MA35_SYS_REG_USBPMISCR , val, - val &PHY0DEVCKSTB ,10 ,1000 ); -if (ret ==0 ) -return 0 ; - } +regmap_read (p->sysreg,MA35_SYS_USBPMISCR , &val); -/* -* reset USB PHY0. -* wait until USB PHY0 60 MHz UTMI Interface Clock ready -*/ -regmap_update_bits (p_phy->sysreg,MA35_SYS_REG_USBPMISCR ,0x7 , (PHY0POR |PHY0SUSPEND )); +if ((val &USBPMISCR_PHY_SUSPEND (n)) && + !ma35_usb_phy_wait_ready (p, n, &val)) + goto out; + +regmap_update_bits (p->sysreg,MA35_SYS_USBPMISCR , +USBPMISCR_PHY_CTL_MASK (n), +USBPMISCR_PHY_POR (n) |USBPMISCR_PHY_SUSPEND (n));udelay (20 ); -/* make USB PHY0 enter operation mode */ -regmap_update_bits (p_phy->sysreg,MA35_SYS_REG_USBPMISCR ,0x7 ,PHY0SUSPEND ); +regmap_update_bits (p->sysreg,MA35_SYS_USBPMISCR , +USBPMISCR_PHY_CTL_MASK (n), +USBPMISCR_PHY_SUSPEND (n)); -/* make sure USB PHY 60 MHz UTMI Interface Clock ready */ - ret =regmap_read_poll_timeout (p_phy->sysreg,MA35_SYS_REG_USBPMISCR , val, - val &PHY0DEVCKSTB ,10 ,1000 ); -if (ret == -ETIMEDOUT ) { -dev_err (p_phy->dev,"Check PHY clock, Timeout: %d\n" , ret); -clk_disable_unprepare (p_phy->clk); -return ret; - } + ret =ma35_usb_phy_wait_ready (p, n, &val); +if (ret) +dev_err (p->dev,"USB PHY%u clock not stable (USBPMISCR=0x%08x)\n" , + n, val); +out: +clk_disable_unprepare (p->clk); +return ret; +} -return 0 ; +static int ma35_usb_phy_power_on (struct phy *phy) +{ +struct ma35_phy_port *port =phy_get_drvdata (phy); +struct ma35_usb_phy *p =container_of (port - port->idx, + struct ma35_usb_phy, port[0]); + +return clk_prepare_enable (p->clk); }static int ma35_usb_phy_power_off (struct phy *phy) { -struct ma35_usb_phy *p_phy =phy_get_drvdata (phy); +struct ma35_phy_port *port =phy_get_drvdata (phy); +struct ma35_usb_phy *p =container_of (port - port->idx, + struct ma35_usb_phy, port[0]); -clk_disable_unprepare (p_phy->clk); +clk_disable_unprepare (p->clk);return 0 ; }
Quoted 9 lines
drivers/phy/nuvoton/phy-ma35d1-usb2.c line 144
Quoted 8 lines
drivers/phy/nuvoton/phy-ma35d1-usb2.c +4
-3static const struct phy_ops ma35_usb_phy_ops = { - .power_on = ma35_usb_phy_power_on, - .power_off = ma35_usb_phy_power_off, - .owner =THIS_MODULE , + .init = ma35_usb_phy_init, + .power_on = ma35_usb_phy_power_on, + .power_off = ma35_usb_phy_power_off, + .owner =THIS_MODULE ,Just keep a single space before =
I'll use a single space before = .
Quoted 4 lines
Quoted 2 lines
drivers/phy/nuvoton/phy-ma35d1-usb2.c +0
-0};[...]
Quoted 13 lines
drivers/phy/nuvoton/phy-ma35d1-usb2.c line 291
Quoted 12 lines
drivers/phy/nuvoton/phy-ma35d1-usb2.c +9
-2+static void ma35_usb_phy_remove (struct platform_device *pdev) +{ +struct ma35_usb_phy *p =platform_get_drvdata (pdev); + +ma35_role_switch_exit (p); +} +static const struct of_device_id ma35_usb_phy_of_match[] = { - { .compatible ="nuvoton,ma35d1-usb2-phy" , }, - { }, + { .compatible ="nuvoton,ma35d1-usb2-phy" }, + {/* sentinel */ }Not necessary.
I'll drop it.
Quoted 11 lines
drivers/phy/nuvoton/phy-ma35d1-usb2.c line 298
Quoted 10 lines
}; MODULE_DEVICE_TABLE(of, ma35_usb_phy_of_match); static struct platform_driver ma35_usb_phy_driver = { .probe = ma35_usb_phy_probe,drivers/phy/nuvoton/phy-ma35d1-usb2.c +2
-3- .driver = { - .name = "ma35d1-usb2-phy", - .of_match_table = ma35_usb_phy_of_match, + .remove = ma35_usb_phy_remove, + .driver = {I'd argue that you should just leave a single space before =.
I'll use a single space before =
Thanks.
Quoted 1 line
- Mani
RE: [PATCH v9 4/4] phy: nuvoton: phy-ma35d1-usb2: extend to dual-port with OTG support
-----Original Message-----
From: Joey Lu <[email protected]>
Sent: Monday, November 30, 2026 10:02 AM
To: Manivannan Sadhasivam <[email protected]>
Cc: Vinod Koul <[email protected]>; Neil Armstrong <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Arnd Bergmann <[email protected]>; Catalin Marinas <[email protected]>; MS10 YCHuang3 <[email protected]>; MS10 SCHung <[email protected]>; Hui-Ping Chen <[email protected]>; MS10 YCLu4 <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v9 4/4] phy: nuvoton: phy-ma35d1-usb2: extend to dual-port with OTG support
CAUTION - External Email: Do not click links or open attachments unless you acknowledge the sender and content.
Quoted 6 lines · Manivannan Sadhasivam
Quoted 5 lines · Joey Lu
PHY0 and PHY1 use the same power-on/reset sequence in USBPMISCR, with PHY1 control bits shifted 16 positions relative to PHY0. A separate driver for PHY1 would duplicate this logic, so the existing driver is extended to manage both ports.
--------------8<-----------------
Quoted 12 lines
Quoted 12 lines
drivers/phy/nuvoton/phy-ma35d1-usb2.c +3
-1@@ -1,6 +1,12 @@// SPDX-License-Identifier: GPL-2.0 /* -* Copyright (C) 2024 Nuvoton Technology Corp. +* Nuvoton MA35D1 USB 2.0 PHY driver +* +* Supports PHY0 (USB0 OTG port, shared between DWC2 gadget and
Quoted 8 lines
drivers/phy/nuvoton/phy-ma35d1-usb2.c line 9
Quoted 6 lines
drivers/phy/nuvoton/phy-ma35d1-usb2.c +6
-0+ EHCI0/OHCI0) + * and PHY1 (USB1 host-only port, used by EHCI1/OHCI1). The hardware + mux on + * PHY0 switches automatically via the USB ID pin. + * + * Copyright (C) 2024-2026 Nuvoton Technology Corp.Are you affiliated with Nuvoton? Your email doesn't say so. So you do not have the authority to change the copyright (not even extend it).
Sorry about that. I'll restore the original line and keep it unchanged.
Hi Mani,
Yes, I'm a Nuvoton employee, and this reply is sent from my company address to show that. I submitted the earlier versions from my personal mail only because the company mail setup goes through a proxy, which is unreliable for sending patches.
I'll restore the original "Copyright (C) 2024 Nuvoton Technology Corp." line in v10 and leave the copyright untouched.
Thanks,
Joey Lu
________________________________
________________________________
The privileged confidential information contained in this email is intended for use only by the addressees as indicated by the original sender of this email. If you are not the addressee indicated in this email or are not responsible for delivery of the email to such a person, please kindly reply to the sender indicating this fact and delete all copies of it from your computer and network server immediately. Your cooperation is highly appreciated. It is advised that any unauthorized use of confidential information of Nuvoton is strictly prohibited; and any information in this email irrelevant to the official business of Nuvoton shall be deemed as neither given nor endorsed by Nuvoton.