mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Joey Lu <a0987203069@gmail.com>
To: Manivannan Sadhasivam <mani@kernel.org>
Cc: 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>, Arnd Bergmann <arnd@arndb.de>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Jacky Huang <ychuang3@nuvoton.com>,
	Shan-Chun Hung <schung@nuvoton.com>,
	Hui-Ping Chen <hpchen0nvt@gmail.com>, Joey Lu <yclu4@nuvoton.com>,
	linux-phy@lists.infradead.org, devicetree@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v9 4/4] phy: nuvoton: phy-ma35d1-usb2: extend to dual-port with OTG support
Date: Mon, 30 Nov 2026 10:01:56 +0800	[thread overview]
Message-ID: <fc0f61f4-cad1-464b-9bea-b520e9cf7e2c@gmail.com> (raw)
In-Reply-To: <179578192017.13164.17032072234431650540.b4-reply@b4>


On 11/27/2026 8:18 PM, Manivannan Sadhasivam wrote:
> On 2026-11-11 15:31 +0800, Joey Lu wrote:
>> 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_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.
>>
>> Signed-off-by: Joey Lu <a0987203069@gmail.com>
>> ---
>>   drivers/phy/nuvoton/Kconfig           |   2 +
>>   drivers/phy/nuvoton/phy-ma35d1-usb2.c | 312 ++++++++++++++++++++------
>>   2 files changed, 241 insertions(+), 73 deletions(-)
>>
>> diff --git a/drivers/phy/nuvoton/Kconfig b/drivers/phy/nuvoton/Kconfig
>> index d02cae2db315..573acd03e6c5 100644
>> --- a/drivers/phy/nuvoton/Kconfig
>> +++ b/drivers/phy/nuvoton/Kconfig
>> @@ -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.
>> diff --git a/drivers/phy/nuvoton/phy-ma35d1-usb2.c b/drivers/phy/nuvoton/phy-ma35d1-usb2.c
>> index 0b9976fb15c1..bc706356c434 100644
>> --- a/drivers/phy/nuvoton/phy-ma35d1-usb2.c
>> +++ b/drivers/phy/nuvoton/phy-ma35d1-usb2.c
>> @@ -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).
Sorry about that. I'll restore the original line and keep it unchanged.
>>    */
>>   #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) */
>> +#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.
>> +};
>>   
>>   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;
>>   };
>>   
>> -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.
>>   {
>> -	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;
>>   
>> -	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.
I'll use plain dev_err() with the error code and return ret in init().
>>   
>> -	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;
>>   }
>>   
>>   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 =
I'll use a single space before = .
>>   };
>>   
> [...]
>
>> +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.
>>   };
>>   MODULE_DEVICE_TABLE(of, ma35_usb_phy_of_match);
>>   
>>   static struct platform_driver ma35_usb_phy_driver = {
>>   	.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 =.
I'll use a single space before =
Thanks.
> - Mani

      reply	other threads:[~2026-11-30  2:02 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-11  7:31 [PATCH v9 0/4] phy: nuvoton: extend MA35D1 USB2 PHY driver for dual-port " Joey Lu
2026-11-11  7:31 ` [PATCH v9 1/4] dt-bindings: phy: nuvoton,ma35d1-usb2-phy: extend for dual-port and OTG Joey Lu
2026-11-11  7:31 ` [PATCH v9 2/4] arm64: dts: nuvoton: ma35d1: add USB controllers and dual-port PHY node Joey Lu
2026-11-11  7:31 ` [PATCH v9 3/4] phy: nuvoton: phy-ma35d1-usb2: remove unused linux/io.h include Joey Lu
2026-11-11  7:31 ` [PATCH v9 4/4] phy: nuvoton: phy-ma35d1-usb2: extend to dual-port with OTG support Joey Lu
2026-11-27 12:18   ` Manivannan Sadhasivam
2026-11-30  2:01     ` Joey Lu [this message]

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=fc0f61f4-cad1-464b-9bea-b520e9cf7e2c@gmail.com \
    --to=a0987203069@gmail.com \
    --cc=arnd@arndb.de \
    --cc=catalin.marinas@arm.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=hpchen0nvt@gmail.com \
    --cc=krzk+dt@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-phy@lists.infradead.org \
    --cc=mani@kernel.org \
    --cc=neil.armstrong@linaro.org \
    --cc=robh@kernel.org \
    --cc=schung@nuvoton.com \
    --cc=vkoul@kernel.org \
    --cc=ychuang3@nuvoton.com \
    --cc=yclu4@nuvoton.com \
    /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®