From 5f055547933bd7bf90047bae99592cf8ca6d6f90 Mon Sep 17 00:00:00 2001 From: Sean Dolbec Date: Thu, 19 Nov 2026 08:49:46 -0500 Subject: [PATCH] usb: dwc3: apple: keep a T8132 device role on USB2 without SuperSpeed device mode The T8132 ATC PHY refuses USB device mode with -EOPNOTSUPP once it is in a USB3 mode, which it is whenever the boot loader supplied its SuperSpeed calibration. dwc3-apple treats every USB3 PHY error on apple,t8132-dwc3 as fatal, so a port where the machine is the USB device fails its role ("USB3 PHY setup failed, err=-95"), where with a USB2-only PHY it ran as a USB2 device. On apple,t8132-dwc3, take -EOPNOTSUPP for the device role as the PHY having no SuperSpeed device mode: start the role on USB2, with the gadget limited to high speed, and say so. The controller compatible is how this file already selects per-SoC behaviour, and it is needed here: other ATC PHYs return the same error for other reasons (an M1 PHY that is off or has no SuperSpeed tunables), and their handling is unchanged. Every other error on T8132 stays fatal. The host role is not touched; the speed limit is removed when the session ends. If the role is selected before the Type-C mux update has put the PHY into a USB3 mode, the PHY accepts the device role and nothing here runs; that ordering was not changed. Assisted-by: LLM Signed-off-by: Sean Dolbec --- drivers/usb/dwc3/dwc3-apple.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/drivers/usb/dwc3/dwc3-apple.c b/drivers/usb/dwc3/dwc3-apple.c index 4d9b4ac0d8346..c7748fce58a01 100644 --- a/drivers/usb/dwc3/dwc3-apple.c +++ b/drivers/usb/dwc3/dwc3-apple.c @@ -147,6 +147,8 @@ * @rpm_held: The glue holds a runtime PM reference for the running core * @pre_core_rpm: Runtime PM is the glue's own until the first core bring-up * @dt_dis_u3_susphy: The device tree keeps USB3 PHY suspend off itself + * @usb2_device_speed: The core's maximum speed before a T8132 device role was limited to USB2 + * (USB_SPEED_UNKNOWN: not limited); restored before the next session starts * @sleep_ddr: The host votes for DRAM in a sleep while it runs (apple,sleep-ddr) * @drd_regs: The controller's optional blocks outside dwc3-core (drd-cfg, drd-bulk, drd-ausbc), * mapped for their tunables @@ -189,6 +191,7 @@ struct dwc3_apple { bool rpm_held; bool pre_core_rpm; bool dt_dis_u3_susphy; + enum usb_device_speed usb2_device_speed; bool sleep_ddr; struct notifier_block pm_nb; /* Kept through a deep sleep, with the PHY's hibernation, and the GUID it had. */ @@ -940,7 +943,19 @@ static int dwc3_apple_set_role(struct dwc3_apple *appledwc, enum dwc3_apple_stat appledwc->dwc.dis_u3_susphy_quirk = appledwc->dt_dis_u3_susphy; dwc3_enable_susphy(&appledwc->dwc, true); ret = phy_set_mode(appledwc->usb3_phy, host ? PHY_MODE_USB_HOST : PHY_MODE_USB_DEVICE); - if (ret) { + if (ret == -EOPNOTSUPP && !host && + of_device_is_compatible(appledwc->dev->of_node, "apple,t8132-dwc3")) { + /* + * The T8132 PHY has no SuperSpeed device mode once it is in a USB3 mode: the + * device role runs on USB2, and the gadget must not offer more. Other PHYs + * return this error for other reasons and are handled below, as before. + */ + dev_info(appledwc->dev, "USB3 PHY has no SuperSpeed device mode, USB2 only\n"); + if (appledwc->dwc.maximum_speed > USB_SPEED_HIGH) { + appledwc->usb2_device_speed = appledwc->dwc.maximum_speed; + appledwc->dwc.maximum_speed = USB_SPEED_HIGH; + } + } else if (ret) { /* * A failed T8132 BIST or PIPE handoff must not start xHCI. Neither must a failed * T6050 one: that PHY reports a port left on USB2 (four DisplayPort lanes) as @@ -998,6 +1013,11 @@ static int dwc3_apple_init(struct dwc3_apple *appledwc, enum dwc3_apple_state st if (state == DWC3_APPLE_HOST && appledwc->host_only) appledwc->dwc.current_dr_role = DWC3_GCTL_PRTCAP_HOST; + /* A previous session's USB2-only device role limits nothing after it. */ + if (appledwc->usb2_device_speed != USB_SPEED_UNKNOWN) { + appledwc->dwc.maximum_speed = appledwc->usb2_device_speed; + appledwc->usb2_device_speed = USB_SPEED_UNKNOWN; + } ret = dwc3_apple_core_start(appledwc, state); if (ret) return ret;