All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
To: Sebastian Reichel <sebastian.reichel@collabora.com>
Cc: Thinh Nguyen <Thinh.Nguyen@synopsys.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Heiko Stuebner <heiko@sntech.de>, Vinod Koul <vkoul@kernel.org>,
	Neil Armstrong <neil.armstrong@linaro.org>,
	Manivannan Sadhasivam <mani@kernel.org>,
	Manivannan Sadhasivam <manivannan.sadhasivam@oss.qualcomm.com>,
	Krishna Kurapati <krishna.kurapati@oss.qualcomm.com>,
	Chaoyi Chen <chaoyi.chen@rock-chips.com>,
	Igor Paunovic <royalnet026@gmail.com>,
	Alexey Charkov <alchark@flipper.net>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
	"linux-arm-kernel@lists.infradead.org"
	<linux-arm-kernel@lists.infradead.org>,
	"linux-rockchip@lists.infradead.org"
	<linux-rockchip@lists.infradead.org>,
	"linux-phy@lists.infradead.org" <linux-phy@lists.infradead.org>,
	"kernel@collabora.com" <kernel@collabora.com>
Subject: Re: [PATCH v19 6/6] usb: dwc3: rockchip: add USBDP PHY reset quirk
Date: Fri, 4 Dec 2026 18:52:57 +0000	[thread overview]
Message-ID: <axMHmj2a3X0lkRAs@vbox> (raw)
In-Reply-To: <20261114-b4-rockchip-dwc3-rockchip-glue-v19-6-b79fb5f4b42a@collabora.com>

On Sat, Nov 14, 2026, Sebastian Reichel wrote:
> On recent Rockchip platforms (at least RK3588 & RK3576), DWC3 IP is used
> with a USBDP PHY providing USB3 and DP. This PHY needs to be reset when
> the mode changes, which may happen when plugging in different USB-C
> devices.
> 
> If the USBDP PHY resets with the DWC3 IP running, its internal state
> corrupts resulting in the USBDP PHY not being able to lock some PLL
> clocks, which effectively renders USB3 unusable.
> 
> To fix the issue this adds a Rockchip USBDP specific quirk, which will
> assert PHYSOFTRST before the actual PHY is disabled and will deassert it
> once the PHY returns.
> 
> The quirk is skipped while DWC3 is suspended, as its registers may be
> inaccessible and the device being suspended is a quirk in itself (the
> vendor BSP enables runtime PM with very short autosuspend as a
> workaround for this issue). Thus the code just ensures the PM state
> does not change while the PHY reset is going on.
> 
> Note, that the same platforms also use DWC3 with a different PHY
> (rockchip-naneng-combphy), so the PHY calls are protected by a
> driver name check.
> 
> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
> ---
>  drivers/usb/dwc3/Kconfig         |   1 +
>  drivers/usb/dwc3/dwc3-rockchip.c | 154 +++++++++++++++++++++++++++++++++++++--
>  drivers/usb/dwc3/trace.c         |   3 +
>  3 files changed, 153 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/usb/dwc3/Kconfig b/drivers/usb/dwc3/Kconfig
> index 3c120ea9746d..c86c1ac293bf 100644
> --- a/drivers/usb/dwc3/Kconfig
> +++ b/drivers/usb/dwc3/Kconfig
> @@ -193,6 +193,7 @@ config USB_DWC3_OCTEON
>  config USB_DWC3_ROCKCHIP
>  	tristate "Rockchip DWC3 Platform Driver"
>  	depends on ARCH_ROCKCHIP || COMPILE_TEST
> +	depends on PHY_ROCKCHIP_USBDP || !PHY_ROCKCHIP_USBDP
>  	depends on OF
>  	default USB_DWC3
>  	help
> diff --git a/drivers/usb/dwc3/dwc3-rockchip.c b/drivers/usb/dwc3/dwc3-rockchip.c
> index 4129aefd6a8b..25bf2794c1fc 100644
> --- a/drivers/usb/dwc3/dwc3-rockchip.c
> +++ b/drivers/usb/dwc3/dwc3-rockchip.c
> @@ -2,11 +2,120 @@
>  /* Copyright (c) 2026, Collabora Ltd. */
>  #include <linux/module.h>
>  #include <linux/platform_device.h>
> +#include <linux/phy/rockchip-usbdp.h>
>  #include <linux/pm_runtime.h>
> +#include <linux/wait.h>
>  #include "glue.h"
> +#include "io.h"
>  
>  struct dwc3_rockchip {
>  	struct dwc3		dwc;
> +	wait_queue_head_t	phy_reset_wq;
> +	u8			phy_reset_active;
> +	bool			pm_suspended;
> +};
> +
> +static inline struct dwc3_rockchip *to_dwc3_rockchip(struct dwc3 *dwc)
> +{
> +	return container_of(dwc, struct dwc3_rockchip, dwc);
> +}
> +
> +static void dwc3_rockchip_set_suspended(struct dwc3_rockchip *dwc_rk, bool suspended)
> +{
> +	struct dwc3 *dwc = &dwc_rk->dwc;
> +
> +	guard(spinlock_irq)(&dwc->lock);
> +
> +	wait_event_lock_irq(dwc_rk->phy_reset_wq, !dwc_rk->phy_reset_active, dwc->lock);
> +	dwc_rk->pm_suspended = suspended;
> +}
> +
> +static void dwc3_rockchip_phy_pre_reset(struct dwc3_rockchip *dwc_rk, int port)
> +{
> +	struct dwc3 *dwc = &dwc_rk->dwc;
> +	u32 reg;
> +
> +	guard(spinlock_irqsave)(&dwc->lock);
> +
> +	dwc_rk->phy_reset_active |= BIT(port);
> +
> +	/* DWC3 being suspended also works as a quirk */
> +	if (dwc_rk->pm_suspended)
> +		return;
> +
> +	/*
> +	 * Assert USB3 PHY soft reset within DWC3 before the external
> +	 * PHY resets. This disconnects the PIPE interface, preventing
> +	 * the DWC3 from interfering with PHY reinitialization and
> +	 * avoiding LCPLL lock failures.
> +	 */
> +	reg = dwc3_readl(dwc, DWC3_GUSB3PIPECTL(port));
> +	reg |= DWC3_GUSB3PIPECTL_PHYSOFTRST;
> +	dwc3_writel(dwc, DWC3_GUSB3PIPECTL(port), reg);
> +}
> +
> +static void dwc3_rockchip_phy_post_reset(struct dwc3_rockchip *dwc_rk, int port)
> +{
> +	struct dwc3 *dwc = &dwc_rk->dwc;
> +	u32 reg;
> +
> +	scoped_guard(spinlock_irqsave, &dwc->lock) {
> +		dwc_rk->phy_reset_active &= ~BIT(port);
> +
> +		if (!dwc_rk->pm_suspended) {
> +			reg = dwc3_readl(dwc, DWC3_GUSB3PIPECTL(port));
> +			reg &= ~DWC3_GUSB3PIPECTL_PHYSOFTRST;
> +			dwc3_writel(dwc, DWC3_GUSB3PIPECTL(port), reg);
> +		}
> +	}
> +
> +	wake_up(&dwc_rk->phy_reset_wq);
> +}
> +
> +static void dwc3_rockchip_phy_reset(void *data, int port, bool pre)
> +{
> +	struct dwc3_rockchip *dwc_rk = data;
> +
> +	if (pre)
> +		dwc3_rockchip_phy_pre_reset(dwc_rk, port);
> +	else
> +		dwc3_rockchip_phy_post_reset(dwc_rk, port);
> +}
> +
> +static void dwc3_rockchip_phy_unregister_reset_handler(void *data)
> +{
> +	struct dwc3_rockchip *dwc_rk = data;
> +	struct dwc3 *dwc = &dwc_rk->dwc;
> +	int i;
> +
> +	for (i = 0; i < dwc->num_usb3_ports; i++) {
> +		struct phy *phy = dwc->usb3_generic_phy[i];
> +
> +		if (phy && !strcmp(dev_driver_string(phy->dev.parent), "rockchip-usbdp-phy"))
> +			rk_udphy_unregister_reset_handler(phy);
> +	}
> +
> +	WARN_ON(dwc_rk->phy_reset_active);
> +}
> +
> +static int dwc3_rockchip_phy_register_reset_handler(struct dwc3 *dwc)
> +{
> +	struct dwc3_rockchip *dwc_rk = to_dwc3_rockchip(dwc);
> +	int i;
> +
> +	for (i = 0; i < dwc->num_usb3_ports; i++) {
> +		struct phy *phy = dwc->usb3_generic_phy[i];
> +
> +		if (phy && !strcmp(dev_driver_string(phy->dev.parent), "rockchip-usbdp-phy"))

Could the phy driver validate this in rk_udphy_register_reset_handler()
instead of having the glue match on the phy driver name? I'd avoid
baked-in knowledge of what phy to use in the glue code. But this can be
a follow-up change.

> +			rk_udphy_register_reset_handler(phy, dwc3_rockchip_phy_reset, dwc_rk, i);
> +	}
> +

Acked-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>

BR,
Thinh
_______________________________________________
Linux-rockchip mailing list
Linux-rockchip@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip

WARNING: multiple messages have this Message-ID (diff)
From: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
To: Sebastian Reichel <sebastian.reichel@collabora.com>
Cc: Thinh Nguyen <Thinh.Nguyen@synopsys.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Heiko Stuebner <heiko@sntech.de>, Vinod Koul <vkoul@kernel.org>,
	Neil Armstrong <neil.armstrong@linaro.org>,
	Manivannan Sadhasivam <mani@kernel.org>,
	Manivannan Sadhasivam <manivannan.sadhasivam@oss.qualcomm.com>,
	Krishna Kurapati <krishna.kurapati@oss.qualcomm.com>,
	Chaoyi Chen <chaoyi.chen@rock-chips.com>,
	Igor Paunovic <royalnet026@gmail.com>,
	Alexey Charkov <alchark@flipper.net>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
	"linux-arm-kernel@lists.infradead.org"
	<linux-arm-kernel@lists.infradead.org>,
	"linux-rockchip@lists.infradead.org"
	<linux-rockchip@lists.infradead.org>,
	"linux-phy@lists.infradead.org" <linux-phy@lists.infradead.org>,
	"kernel@collabora.com" <kernel@collabora.com>
Subject: Re: [PATCH v19 6/6] usb: dwc3: rockchip: add USBDP PHY reset quirk
Date: Fri, 4 Dec 2026 18:52:57 +0000	[thread overview]
Message-ID: <axMHmj2a3X0lkRAs@vbox> (raw)
In-Reply-To: <20261114-b4-rockchip-dwc3-rockchip-glue-v19-6-b79fb5f4b42a@collabora.com>

On Sat, Nov 14, 2026, Sebastian Reichel wrote:
> On recent Rockchip platforms (at least RK3588 & RK3576), DWC3 IP is used
> with a USBDP PHY providing USB3 and DP. This PHY needs to be reset when
> the mode changes, which may happen when plugging in different USB-C
> devices.
> 
> If the USBDP PHY resets with the DWC3 IP running, its internal state
> corrupts resulting in the USBDP PHY not being able to lock some PLL
> clocks, which effectively renders USB3 unusable.
> 
> To fix the issue this adds a Rockchip USBDP specific quirk, which will
> assert PHYSOFTRST before the actual PHY is disabled and will deassert it
> once the PHY returns.
> 
> The quirk is skipped while DWC3 is suspended, as its registers may be
> inaccessible and the device being suspended is a quirk in itself (the
> vendor BSP enables runtime PM with very short autosuspend as a
> workaround for this issue). Thus the code just ensures the PM state
> does not change while the PHY reset is going on.
> 
> Note, that the same platforms also use DWC3 with a different PHY
> (rockchip-naneng-combphy), so the PHY calls are protected by a
> driver name check.
> 
> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
> ---
>  drivers/usb/dwc3/Kconfig         |   1 +
>  drivers/usb/dwc3/dwc3-rockchip.c | 154 +++++++++++++++++++++++++++++++++++++--
>  drivers/usb/dwc3/trace.c         |   3 +
>  3 files changed, 153 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/usb/dwc3/Kconfig b/drivers/usb/dwc3/Kconfig
> index 3c120ea9746d..c86c1ac293bf 100644
> --- a/drivers/usb/dwc3/Kconfig
> +++ b/drivers/usb/dwc3/Kconfig
> @@ -193,6 +193,7 @@ config USB_DWC3_OCTEON
>  config USB_DWC3_ROCKCHIP
>  	tristate "Rockchip DWC3 Platform Driver"
>  	depends on ARCH_ROCKCHIP || COMPILE_TEST
> +	depends on PHY_ROCKCHIP_USBDP || !PHY_ROCKCHIP_USBDP
>  	depends on OF
>  	default USB_DWC3
>  	help
> diff --git a/drivers/usb/dwc3/dwc3-rockchip.c b/drivers/usb/dwc3/dwc3-rockchip.c
> index 4129aefd6a8b..25bf2794c1fc 100644
> --- a/drivers/usb/dwc3/dwc3-rockchip.c
> +++ b/drivers/usb/dwc3/dwc3-rockchip.c
> @@ -2,11 +2,120 @@
>  /* Copyright (c) 2026, Collabora Ltd. */
>  #include <linux/module.h>
>  #include <linux/platform_device.h>
> +#include <linux/phy/rockchip-usbdp.h>
>  #include <linux/pm_runtime.h>
> +#include <linux/wait.h>
>  #include "glue.h"
> +#include "io.h"
>  
>  struct dwc3_rockchip {
>  	struct dwc3		dwc;
> +	wait_queue_head_t	phy_reset_wq;
> +	u8			phy_reset_active;
> +	bool			pm_suspended;
> +};
> +
> +static inline struct dwc3_rockchip *to_dwc3_rockchip(struct dwc3 *dwc)
> +{
> +	return container_of(dwc, struct dwc3_rockchip, dwc);
> +}
> +
> +static void dwc3_rockchip_set_suspended(struct dwc3_rockchip *dwc_rk, bool suspended)
> +{
> +	struct dwc3 *dwc = &dwc_rk->dwc;
> +
> +	guard(spinlock_irq)(&dwc->lock);
> +
> +	wait_event_lock_irq(dwc_rk->phy_reset_wq, !dwc_rk->phy_reset_active, dwc->lock);
> +	dwc_rk->pm_suspended = suspended;
> +}
> +
> +static void dwc3_rockchip_phy_pre_reset(struct dwc3_rockchip *dwc_rk, int port)
> +{
> +	struct dwc3 *dwc = &dwc_rk->dwc;
> +	u32 reg;
> +
> +	guard(spinlock_irqsave)(&dwc->lock);
> +
> +	dwc_rk->phy_reset_active |= BIT(port);
> +
> +	/* DWC3 being suspended also works as a quirk */
> +	if (dwc_rk->pm_suspended)
> +		return;
> +
> +	/*
> +	 * Assert USB3 PHY soft reset within DWC3 before the external
> +	 * PHY resets. This disconnects the PIPE interface, preventing
> +	 * the DWC3 from interfering with PHY reinitialization and
> +	 * avoiding LCPLL lock failures.
> +	 */
> +	reg = dwc3_readl(dwc, DWC3_GUSB3PIPECTL(port));
> +	reg |= DWC3_GUSB3PIPECTL_PHYSOFTRST;
> +	dwc3_writel(dwc, DWC3_GUSB3PIPECTL(port), reg);
> +}
> +
> +static void dwc3_rockchip_phy_post_reset(struct dwc3_rockchip *dwc_rk, int port)
> +{
> +	struct dwc3 *dwc = &dwc_rk->dwc;
> +	u32 reg;
> +
> +	scoped_guard(spinlock_irqsave, &dwc->lock) {
> +		dwc_rk->phy_reset_active &= ~BIT(port);
> +
> +		if (!dwc_rk->pm_suspended) {
> +			reg = dwc3_readl(dwc, DWC3_GUSB3PIPECTL(port));
> +			reg &= ~DWC3_GUSB3PIPECTL_PHYSOFTRST;
> +			dwc3_writel(dwc, DWC3_GUSB3PIPECTL(port), reg);
> +		}
> +	}
> +
> +	wake_up(&dwc_rk->phy_reset_wq);
> +}
> +
> +static void dwc3_rockchip_phy_reset(void *data, int port, bool pre)
> +{
> +	struct dwc3_rockchip *dwc_rk = data;
> +
> +	if (pre)
> +		dwc3_rockchip_phy_pre_reset(dwc_rk, port);
> +	else
> +		dwc3_rockchip_phy_post_reset(dwc_rk, port);
> +}
> +
> +static void dwc3_rockchip_phy_unregister_reset_handler(void *data)
> +{
> +	struct dwc3_rockchip *dwc_rk = data;
> +	struct dwc3 *dwc = &dwc_rk->dwc;
> +	int i;
> +
> +	for (i = 0; i < dwc->num_usb3_ports; i++) {
> +		struct phy *phy = dwc->usb3_generic_phy[i];
> +
> +		if (phy && !strcmp(dev_driver_string(phy->dev.parent), "rockchip-usbdp-phy"))
> +			rk_udphy_unregister_reset_handler(phy);
> +	}
> +
> +	WARN_ON(dwc_rk->phy_reset_active);
> +}
> +
> +static int dwc3_rockchip_phy_register_reset_handler(struct dwc3 *dwc)
> +{
> +	struct dwc3_rockchip *dwc_rk = to_dwc3_rockchip(dwc);
> +	int i;
> +
> +	for (i = 0; i < dwc->num_usb3_ports; i++) {
> +		struct phy *phy = dwc->usb3_generic_phy[i];
> +
> +		if (phy && !strcmp(dev_driver_string(phy->dev.parent), "rockchip-usbdp-phy"))

Could the phy driver validate this in rk_udphy_register_reset_handler()
instead of having the glue match on the phy driver name? I'd avoid
baked-in knowledge of what phy to use in the glue code. But this can be
a follow-up change.

> +			rk_udphy_register_reset_handler(phy, dwc3_rockchip_phy_reset, dwc_rk, i);
> +	}
> +

Acked-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>

BR,
Thinh
-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

WARNING: multiple messages have this Message-ID (diff)
From: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
To: Sebastian Reichel <sebastian.reichel@collabora.com>
Cc: Thinh Nguyen <Thinh.Nguyen@synopsys.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Heiko Stuebner <heiko@sntech.de>, Vinod Koul <vkoul@kernel.org>,
	Neil Armstrong <neil.armstrong@linaro.org>,
	Manivannan Sadhasivam <mani@kernel.org>,
	Manivannan Sadhasivam <manivannan.sadhasivam@oss.qualcomm.com>,
	Krishna Kurapati <krishna.kurapati@oss.qualcomm.com>,
	Chaoyi Chen <chaoyi.chen@rock-chips.com>,
	Igor Paunovic <royalnet026@gmail.com>,
	Alexey Charkov <alchark@flipper.net>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
	"linux-arm-kernel@lists.infradead.org"
	<linux-arm-kernel@lists.infradead.org>,
	"linux-rockchip@lists.infradead.org"
	<linux-rockchip@lists.infradead.org>,
	"linux-phy@lists.infradead.org" <linux-phy@lists.infradead.org>,
	"kernel@collabora.com" <kernel@collabora.com>
Subject: Re: [PATCH v19 6/6] usb: dwc3: rockchip: add USBDP PHY reset quirk
Date: Fri, 4 Dec 2026 18:52:57 +0000	[thread overview]
Message-ID: <axMHmj2a3X0lkRAs@vbox> (raw)
In-Reply-To: <20261114-b4-rockchip-dwc3-rockchip-glue-v19-6-b79fb5f4b42a@collabora.com>

On Sat, Nov 14, 2026, Sebastian Reichel wrote:
> On recent Rockchip platforms (at least RK3588 & RK3576), DWC3 IP is used
> with a USBDP PHY providing USB3 and DP. This PHY needs to be reset when
> the mode changes, which may happen when plugging in different USB-C
> devices.
> 
> If the USBDP PHY resets with the DWC3 IP running, its internal state
> corrupts resulting in the USBDP PHY not being able to lock some PLL
> clocks, which effectively renders USB3 unusable.
> 
> To fix the issue this adds a Rockchip USBDP specific quirk, which will
> assert PHYSOFTRST before the actual PHY is disabled and will deassert it
> once the PHY returns.
> 
> The quirk is skipped while DWC3 is suspended, as its registers may be
> inaccessible and the device being suspended is a quirk in itself (the
> vendor BSP enables runtime PM with very short autosuspend as a
> workaround for this issue). Thus the code just ensures the PM state
> does not change while the PHY reset is going on.
> 
> Note, that the same platforms also use DWC3 with a different PHY
> (rockchip-naneng-combphy), so the PHY calls are protected by a
> driver name check.
> 
> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
> ---
>  drivers/usb/dwc3/Kconfig         |   1 +
>  drivers/usb/dwc3/dwc3-rockchip.c | 154 +++++++++++++++++++++++++++++++++++++--
>  drivers/usb/dwc3/trace.c         |   3 +
>  3 files changed, 153 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/usb/dwc3/Kconfig b/drivers/usb/dwc3/Kconfig
> index 3c120ea9746d..c86c1ac293bf 100644
> --- a/drivers/usb/dwc3/Kconfig
> +++ b/drivers/usb/dwc3/Kconfig
> @@ -193,6 +193,7 @@ config USB_DWC3_OCTEON
>  config USB_DWC3_ROCKCHIP
>  	tristate "Rockchip DWC3 Platform Driver"
>  	depends on ARCH_ROCKCHIP || COMPILE_TEST
> +	depends on PHY_ROCKCHIP_USBDP || !PHY_ROCKCHIP_USBDP
>  	depends on OF
>  	default USB_DWC3
>  	help
> diff --git a/drivers/usb/dwc3/dwc3-rockchip.c b/drivers/usb/dwc3/dwc3-rockchip.c
> index 4129aefd6a8b..25bf2794c1fc 100644
> --- a/drivers/usb/dwc3/dwc3-rockchip.c
> +++ b/drivers/usb/dwc3/dwc3-rockchip.c
> @@ -2,11 +2,120 @@
>  /* Copyright (c) 2026, Collabora Ltd. */
>  #include <linux/module.h>
>  #include <linux/platform_device.h>
> +#include <linux/phy/rockchip-usbdp.h>
>  #include <linux/pm_runtime.h>
> +#include <linux/wait.h>
>  #include "glue.h"
> +#include "io.h"
>  
>  struct dwc3_rockchip {
>  	struct dwc3		dwc;
> +	wait_queue_head_t	phy_reset_wq;
> +	u8			phy_reset_active;
> +	bool			pm_suspended;
> +};
> +
> +static inline struct dwc3_rockchip *to_dwc3_rockchip(struct dwc3 *dwc)
> +{
> +	return container_of(dwc, struct dwc3_rockchip, dwc);
> +}
> +
> +static void dwc3_rockchip_set_suspended(struct dwc3_rockchip *dwc_rk, bool suspended)
> +{
> +	struct dwc3 *dwc = &dwc_rk->dwc;
> +
> +	guard(spinlock_irq)(&dwc->lock);
> +
> +	wait_event_lock_irq(dwc_rk->phy_reset_wq, !dwc_rk->phy_reset_active, dwc->lock);
> +	dwc_rk->pm_suspended = suspended;
> +}
> +
> +static void dwc3_rockchip_phy_pre_reset(struct dwc3_rockchip *dwc_rk, int port)
> +{
> +	struct dwc3 *dwc = &dwc_rk->dwc;
> +	u32 reg;
> +
> +	guard(spinlock_irqsave)(&dwc->lock);
> +
> +	dwc_rk->phy_reset_active |= BIT(port);
> +
> +	/* DWC3 being suspended also works as a quirk */
> +	if (dwc_rk->pm_suspended)
> +		return;
> +
> +	/*
> +	 * Assert USB3 PHY soft reset within DWC3 before the external
> +	 * PHY resets. This disconnects the PIPE interface, preventing
> +	 * the DWC3 from interfering with PHY reinitialization and
> +	 * avoiding LCPLL lock failures.
> +	 */
> +	reg = dwc3_readl(dwc, DWC3_GUSB3PIPECTL(port));
> +	reg |= DWC3_GUSB3PIPECTL_PHYSOFTRST;
> +	dwc3_writel(dwc, DWC3_GUSB3PIPECTL(port), reg);
> +}
> +
> +static void dwc3_rockchip_phy_post_reset(struct dwc3_rockchip *dwc_rk, int port)
> +{
> +	struct dwc3 *dwc = &dwc_rk->dwc;
> +	u32 reg;
> +
> +	scoped_guard(spinlock_irqsave, &dwc->lock) {
> +		dwc_rk->phy_reset_active &= ~BIT(port);
> +
> +		if (!dwc_rk->pm_suspended) {
> +			reg = dwc3_readl(dwc, DWC3_GUSB3PIPECTL(port));
> +			reg &= ~DWC3_GUSB3PIPECTL_PHYSOFTRST;
> +			dwc3_writel(dwc, DWC3_GUSB3PIPECTL(port), reg);
> +		}
> +	}
> +
> +	wake_up(&dwc_rk->phy_reset_wq);
> +}
> +
> +static void dwc3_rockchip_phy_reset(void *data, int port, bool pre)
> +{
> +	struct dwc3_rockchip *dwc_rk = data;
> +
> +	if (pre)
> +		dwc3_rockchip_phy_pre_reset(dwc_rk, port);
> +	else
> +		dwc3_rockchip_phy_post_reset(dwc_rk, port);
> +}
> +
> +static void dwc3_rockchip_phy_unregister_reset_handler(void *data)
> +{
> +	struct dwc3_rockchip *dwc_rk = data;
> +	struct dwc3 *dwc = &dwc_rk->dwc;
> +	int i;
> +
> +	for (i = 0; i < dwc->num_usb3_ports; i++) {
> +		struct phy *phy = dwc->usb3_generic_phy[i];
> +
> +		if (phy && !strcmp(dev_driver_string(phy->dev.parent), "rockchip-usbdp-phy"))
> +			rk_udphy_unregister_reset_handler(phy);
> +	}
> +
> +	WARN_ON(dwc_rk->phy_reset_active);
> +}
> +
> +static int dwc3_rockchip_phy_register_reset_handler(struct dwc3 *dwc)
> +{
> +	struct dwc3_rockchip *dwc_rk = to_dwc3_rockchip(dwc);
> +	int i;
> +
> +	for (i = 0; i < dwc->num_usb3_ports; i++) {
> +		struct phy *phy = dwc->usb3_generic_phy[i];
> +
> +		if (phy && !strcmp(dev_driver_string(phy->dev.parent), "rockchip-usbdp-phy"))

Could the phy driver validate this in rk_udphy_register_reset_handler()
instead of having the glue match on the phy driver name? I'd avoid
baked-in knowledge of what phy to use in the glue code. But this can be
a follow-up change.

> +			rk_udphy_register_reset_handler(phy, dwc3_rockchip_phy_reset, dwc_rk, i);
> +	}
> +

Acked-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>

BR,
Thinh

  parent reply	other threads:[~2026-12-04 18:53 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-14  1:01 [PATCH v19 0/6] usb: dwc3: introduce Rockchip glue driver Sebastian Reichel
2026-11-14  1:01 ` Sebastian Reichel
2026-11-14  1:01 ` Sebastian Reichel
2026-11-14  1:02 ` [PATCH v19 1/6] phy: rockchip: usbdp: Track PHY power state Sebastian Reichel
2026-11-14  1:02   ` Sebastian Reichel
2026-11-14  1:02   ` Sebastian Reichel
2026-11-14  1:15   ` sashiko-bot
2026-11-14  1:02 ` [PATCH v19 2/6] phy: rockchip: usbdp: Add reset hook support for dwc3 Sebastian Reichel
2026-11-14  1:02   ` Sebastian Reichel
2026-11-14  1:02   ` Sebastian Reichel
2026-11-14  1:17   ` sashiko-bot
2026-11-14  1:02 ` [PATCH v19 3/6] usb: dwc3: rockchip: introduce glue driver Sebastian Reichel
2026-11-14  1:02   ` Sebastian Reichel
2026-11-14  1:02   ` Sebastian Reichel
2026-11-14  1:08   ` sashiko-bot
2026-12-04 18:27   ` Thinh Nguyen
2026-12-04 18:27     ` Thinh Nguyen
2026-12-04 18:27     ` Thinh Nguyen
2026-11-14  1:02 ` [PATCH v19 4/6] usb: dwc3: core: add post PHY registration hook for platform glue Sebastian Reichel
2026-11-14  1:02   ` Sebastian Reichel
2026-11-14  1:02   ` Sebastian Reichel
2026-11-14  1:05   ` sashiko-bot
2026-11-14  1:02 ` [PATCH v19 5/6] usb: dwc3: core: only access GUSB3PIPECTL under lock Sebastian Reichel
2026-11-14  1:02   ` Sebastian Reichel
2026-11-14  1:02   ` Sebastian Reichel
2026-11-14  1:09   ` sashiko-bot
2026-12-03 16:48   ` Greg Kroah-Hartman
2026-12-03 16:48     ` Greg Kroah-Hartman
2026-12-03 16:48     ` Greg Kroah-Hartman
2026-12-04 16:59     ` Sebastian Reichel
2026-12-04 16:59       ` Sebastian Reichel
2026-12-04 16:59       ` Sebastian Reichel
2026-12-04 19:04       ` Thinh Nguyen
2026-12-04 19:04         ` Thinh Nguyen
2026-12-04 19:04         ` Thinh Nguyen
2026-12-04 22:45         ` Thinh Nguyen
2026-12-04 22:45           ` Thinh Nguyen
2026-12-04 22:45           ` Thinh Nguyen
2026-11-14  1:02 ` [PATCH v19 6/6] usb: dwc3: rockchip: add USBDP PHY reset quirk Sebastian Reichel
2026-11-14  1:02   ` Sebastian Reichel
2026-11-14  1:02   ` Sebastian Reichel
2026-11-14  1:28   ` sashiko-bot
2026-12-04 18:52   ` Thinh Nguyen [this message]
2026-12-04 18:52     ` Thinh Nguyen
2026-12-04 18:52     ` Thinh Nguyen
2026-11-21 11:37 ` [PATCH v19 0/6] usb: dwc3: introduce Rockchip glue driver Ricardo Pardini
2026-11-21 11:37   ` Ricardo Pardini
2026-11-21 11:37   ` Ricardo Pardini

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=axMHmj2a3X0lkRAs@vbox \
    --to=thinh.nguyen@synopsys.com \
    --cc=alchark@flipper.net \
    --cc=chaoyi.chen@rock-chips.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=heiko@sntech.de \
    --cc=kernel@collabora.com \
    --cc=krishna.kurapati@oss.qualcomm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-phy@lists.infradead.org \
    --cc=linux-rockchip@lists.infradead.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mani@kernel.org \
    --cc=manivannan.sadhasivam@oss.qualcomm.com \
    --cc=neil.armstrong@linaro.org \
    --cc=royalnet026@gmail.com \
    --cc=sebastian.reichel@collabora.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.