From: Janne Grunau <j@jannau.net>
To: Sven Peter <sven@kernel.org>
Cc: Neal Gompa <neal@gompa.dev>,
Thinh Nguyen <Thinh.Nguyen@synopsys.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
asahi@lists.linux.dev, linux-arm-kernel@lists.infradead.org,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
James Calligeros <jcalligeros99@gmail.com>,
stable@vger.kernel.org
Subject: Re: [PATCH] usb: dwc3: apple: Set USB2 PHY mode before dwc3 init
Date: Fri, 9 Jan 2026 11:23:09 +0100 [thread overview]
Message-ID: <20260109102309.GE4068972@robin.jannau.net> (raw)
In-Reply-To: <20260108-dwc3-apple-usb2phy-fix-v1-1-5dd7bc642040@kernel.org>
On Thu, Jan 08, 2026 at 08:21:45PM +0100, Sven Peter wrote:
> Now that the upstream code has been getting broader test coverage by our
> users we occasionally see issues with USB2 devices plugged in during boot.
> Before Linux is running, the USB2 PHY has usually been running in device
> mode and it turns out that sometimes host->device or device->host
> transitions don't work.
> The root cause: If the role inside the USB2 PHY is re-configured when it
> has already been powered on or when dwc2 has already enabled the ULPI
"dwc3", typo noticed by Mark Kettenis
> interface the new configuration sometimes doesn't take affect until dwc3
> is reset again. Fix this rare issue by configuring the role much earlier.
> Note that the USB3 PHY does not suffer from this issue and actually
> requires dwc3 to be up before the correct role can be configured there.
>
> Reported-by: James Calligeros <jcalligeros99@gmail.com>
> Reported-by: Janne Grunau <j@jannau.net>
> Fixes: 0ec946d32ef7 ("usb: dwc3: Add Apple Silicon DWC3 glue layer driver")
> Cc: stable@vger.kernel.org
> Signed-off-by: Sven Peter <sven@kernel.org>
> ---
> drivers/usb/dwc3/dwc3-apple.c | 48 +++++++++++++++++++++++++++++--------------
> 1 file changed, 33 insertions(+), 15 deletions(-)
>
> diff --git a/drivers/usb/dwc3/dwc3-apple.c b/drivers/usb/dwc3/dwc3-apple.c
> index cc47cad232e397ac4498b09165dfdb5bd215ded7..c2ae8eb21d514e5e493d2927bc12908c308dfe19 100644
> --- a/drivers/usb/dwc3/dwc3-apple.c
> +++ b/drivers/usb/dwc3/dwc3-apple.c
> @@ -218,25 +218,31 @@ static int dwc3_apple_core_init(struct dwc3_apple *appledwc)
> return ret;
> }
>
> -static void dwc3_apple_phy_set_mode(struct dwc3_apple *appledwc, enum phy_mode mode)
> -{
> - lockdep_assert_held(&appledwc->lock);
> -
> - /*
> - * This platform requires SUSPHY to be enabled here already in order to properly configure
> - * the PHY and switch dwc3's PIPE interface to USB3 PHY.
> - */
> - dwc3_enable_susphy(&appledwc->dwc, true);
> - phy_set_mode(appledwc->dwc.usb2_generic_phy[0], mode);
> - phy_set_mode(appledwc->dwc.usb3_generic_phy[0], mode);
> -}
> -
> static int dwc3_apple_init(struct dwc3_apple *appledwc, enum dwc3_apple_state state)
> {
> int ret, ret_reset;
>
> lockdep_assert_held(&appledwc->lock);
>
> + /*
> + * The USB2 PHY on this platform must be configured for host or device mode while it is
> + * still powered off and before dwc3 tries to access it. Otherwise, the new configuration
> + * will sometimes only take affect after the *next* time dwc3 is brought up which causes
> + * the connected device to just not work.
> + * The USB3 PHY must be configured later after dwc3 has already been initialized.
> + */
> + switch (state) {
> + case DWC3_APPLE_HOST:
> + phy_set_mode(appledwc->dwc.usb2_generic_phy[0], PHY_MODE_USB_HOST);
> + break;
> + case DWC3_APPLE_DEVICE:
> + phy_set_mode(appledwc->dwc.usb2_generic_phy[0], PHY_MODE_USB_DEVICE);
> + break;
> + default:
> + /* Unreachable unless there's a bug in this driver */
> + return -EINVAL;
> + }
> +
> ret = reset_control_deassert(appledwc->reset);
> if (ret) {
> dev_err(appledwc->dev, "Failed to deassert reset, err=%d\n", ret);
> @@ -257,7 +263,13 @@ static int dwc3_apple_init(struct dwc3_apple *appledwc, enum dwc3_apple_state st
> case DWC3_APPLE_HOST:
> appledwc->dwc.dr_mode = USB_DR_MODE_HOST;
> dwc3_apple_set_ptrcap(appledwc, DWC3_GCTL_PRTCAP_HOST);
> - dwc3_apple_phy_set_mode(appledwc, PHY_MODE_USB_HOST);
> + /*
> + * This platform requires SUSPHY to be enabled here already in order to properly
> + * configure the PHY and switch dwc3's PIPE interface to USB3 PHY. The USB2 PHY
> + * has already been configured to the correct mode earlier.
> + */
> + dwc3_enable_susphy(&appledwc->dwc, true);
> + phy_set_mode(appledwc->dwc.usb3_generic_phy[0], PHY_MODE_USB_HOST);
> ret = dwc3_host_init(&appledwc->dwc);
> if (ret) {
> dev_err(appledwc->dev, "Failed to initialize host, ret=%d\n", ret);
> @@ -268,7 +280,13 @@ static int dwc3_apple_init(struct dwc3_apple *appledwc, enum dwc3_apple_state st
> case DWC3_APPLE_DEVICE:
> appledwc->dwc.dr_mode = USB_DR_MODE_PERIPHERAL;
> dwc3_apple_set_ptrcap(appledwc, DWC3_GCTL_PRTCAP_DEVICE);
> - dwc3_apple_phy_set_mode(appledwc, PHY_MODE_USB_DEVICE);
> + /*
> + * This platform requires SUSPHY to be enabled here already in order to properly
> + * configure the PHY and switch dwc3's PIPE interface to USB3 PHY. The USB2 PHY
> + * has already been configured to the correct mode earlier.
> + */
> + dwc3_enable_susphy(&appledwc->dwc, true);
> + phy_set_mode(appledwc->dwc.usb3_generic_phy[0], PHY_MODE_USB_DEVICE);
> ret = dwc3_gadget_init(&appledwc->dwc);
> if (ret) {
> dev_err(appledwc->dev, "Failed to initialize gadget, ret=%d\n", ret);
>
Tested-by: Janne Grunau <j@jannau.net>
Reviewed-by: Janne Grunau <j@jannau.net>
Janne
prev parent reply other threads:[~2026-01-09 10:23 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-08 19:21 Sven Peter
2026-01-09 0:51 ` Thinh Nguyen
2026-01-09 10:23 ` Janne Grunau [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=20260109102309.GE4068972@robin.jannau.net \
--to=j@jannau.net \
--cc=Thinh.Nguyen@synopsys.com \
--cc=asahi@lists.linux.dev \
--cc=gregkh@linuxfoundation.org \
--cc=jcalligeros99@gmail.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=neal@gompa.dev \
--cc=stable@vger.kernel.org \
--cc=sven@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®