Skip to content

Commit eefe4aa

Browse files
committed
usb: dwc3: apple: Ignore USB role switches to the active role
Ignore USB role switches if dwc3-apple is already in the desired state. The USB-C port controller on M2 and M1/M2 Pro/Max/Ultra devices issues additional interrupts which result in USB role switches to the already active role. Ignore these USB role switches to ensure the USB-C port controller and dwc3-apple are always in a consistent state. This matches the behaviour in __dwc3_set_mode() in core.c. Fixes detecting USB 2.0 and 3.x devices on the affected systems. The reset caused by the additional role switch appears to leave the USB devices in a state which prevents detection when the phy and dwc3 is brought back up again. Fixes: 0ec946d ("usb: dwc3: Add Apple Silicon DWC3 glue layer driver") Cc: stable@vger.kernel.org Signed-off-by: Janne Grunau <j@jannau.net>
1 parent ca76e69 commit eefe4aa

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

drivers/usb/dwc3/dwc3-apple.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,22 @@ static int dwc3_usb_role_switch_set(struct usb_role_switch *sw, enum usb_role ro
357357

358358
guard(mutex)(&appledwc->lock);
359359

360+
/*
361+
* Skip role switches if appledwc is already in the desired state. The
362+
* USB-C port controller on M2 and M1/M2 Pro/Max/Ultra devices issues
363+
* additional interrupts which results in usb_role_switch_set_role()
364+
* calls with the current role.
365+
* Ignore those calls here to ensure the USB-C port controller and
366+
* appledwc are in a consistent state.
367+
* This matches the behaviour in __dwc3_set_mode().
368+
* Do no handle USB_ROLE_NONE for DWC3_APPLE_NO_CABLE and
369+
* DWC3_APPLE_PROBE_PENDING since that is no-op anyway.
370+
*/
371+
if (appledwc->state == DWC3_APPLE_HOST && role == USB_ROLE_HOST)
372+
return 0;
373+
if (appledwc->state == DWC3_APPLE_DEVICE && role == USB_ROLE_DEVICE)
374+
return 0;
375+
360376
/*
361377
* We need to tear all of dwc3 down and re-initialize it every time a cable is
362378
* connected or disconnected or when the mode changes. See the documentation for enum

0 commit comments

Comments
 (0)