From c160e6fcfa9930a9fa7f74ad54384798b3525fb2 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Fri, 20 Nov 2026 02:13:17 +1100 Subject: [PATCH 1/2] phy: apple: t6050: USB2 device mode on the Type-C combo PHY The combo PHY refused every USB2 mode but host and had no .validate, so dwc3-apple, which now takes the device role only from a USB2 PHY that validates PHY_MODE_USB_DEVICE, kept every T6050 Type-C port host-only. The T6050 USB2 PHY is the USB2 block of the older ATC PHYs: its host start and stop sequences drive USBCTL, CTL and MISCTUNE bit for bit as atc.c does, and the ADT's atc-phy tunable-host and tunable-device are the same two tuples as on T8103, T6040 and T6041: USB2PHY_SIG bits 14:12 set for host and clear for device. atc.c selects the role with exactly those bits and, on every generation, forces VBUS detect and VBUS valid, since VBUS belongs to the port controller. Do the same here. combo_usb2_mode() accepts PHY_MODE_USB_DEVICE and latches the role. A USB2 start (the port's mode or the controller's power-up) applies the role right after the host tunable step, and a running PHY switches in place: device clears the host signature and forces VBUS valid, host re-applies the host tunable and sets it again. The controller's power-off returns the role to host, so a start without a controller session is the host start it was. .validate reports both roles. The USB3 side keeps refusing device mode with -EOPNOTSUPP before it touches the PIPE. Signed-off-by: Ryan Murray --- drivers/phy/apple/atc-t6050-combo.h | 57 ++++++++++++++++++++++++++++- drivers/phy/apple/atc-t6050-dp.c | 1 + 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/drivers/phy/apple/atc-t6050-combo.h b/drivers/phy/apple/atc-t6050-combo.h index 7dceb224d2556..643f007e6371b 100644 --- a/drivers/phy/apple/atc-t6050-combo.h +++ b/drivers/phy/apple/atc-t6050-combo.h @@ -48,6 +48,32 @@ static int combo_firmware(void *ctx, unsigned int active) { return atc_firmware(ctx, active); } + +/* + * USB2PHY_SIG, bank 0 + 0x8. The USB2 PHY is the block of the older ATC PHYs (atc.c): the host and + * stop sequences use its USBCTL, CTL and MISCTUNE registers bit for bit, and the ADT's atc-phy + * tunable-host and tunable-device are the same two tuples as on T8103, T6040 and T6041: SIG + * bits 14:12 set for host, clear for device. A device session also forces VBUS detect and + * VBUS valid, as atc.c does on every generation: VBUS is the port controller's, not the PHY's. + * The role applies at every USB2 start (the host sequence's HOST tunable step) and in place on a + * running PHY (combo_usb2_mode()). + */ +#define COMBO_USB2_SIG 0x8 +#define COMBO_USB2_SIG_VBUS_FORCE GENMASK(3, 0) +#define COMBO_USB2_SIG_HOST GENMASK(14, 12) + +static void combo_usb2_signature(struct t6050_dp *dp) +{ + void __iomem *sig = dp->banks[0] + COMBO_USB2_SIG; + u32 val = readl(sig); + + if (dp->usb2_device) + val = (val & ~COMBO_USB2_SIG_HOST) | COMBO_USB2_SIG_VBUS_FORCE; + else + val |= COMBO_USB2_SIG_HOST; + writel(val, sig); +} + static int combo_tunable(void *ctx, unsigned int bank, const char *name) { static const struct { u8 bank, index; const char *name; } common[] = { @@ -71,6 +97,8 @@ static int combo_tunable(void *ctx, unsigned int bank, const char *name) } if (bank == 0 && !strcmp(name, "tunable_USB2PHY_HOST")) { apple_tunable_apply(dp->banks[0], dp->usb2_host); + if (dp->usb2_device) + combo_usb2_signature(dp); return 0; } for (unsigned int i = 0; i < ARRAY_SIZE(common); i++) @@ -442,15 +470,36 @@ static int combo_usb2_start(struct t6050_dp *dp) static int combo_usb2_mode(struct phy *phy, enum phy_mode mode, int submode) { struct t6050_dp *dp = phy_get_drvdata(phy); + bool device = mode == PHY_MODE_USB_DEVICE; guard(mutex)(&dp->lock); if (dp->faulted) return -EIO; - if (mode != PHY_MODE_USB_HOST) + if (mode != PHY_MODE_USB_HOST && !device) return -EOPNOTSUPP; + /* + * The port's mode started USB2 before the controller chose its role (dwc3-apple selects + * device mode before the core reset, xHCI host mode as its root hub starts): switch the + * running PHY in place, as atc.c does. Back to host, the host tunable comes first again. + */ + if (device != dp->usb2_device) { + dp->usb2_device = device; + if (dp->usb2_active) { + if (!device) + apple_tunable_apply(dp->banks[0], dp->usb2_host); + combo_usb2_signature(dp); + } + } return combo_usb2_start(dp); } +/* Both roles: combo_usb2_mode() sets or clears the host signature. */ +static int combo_usb2_validate(struct phy *phy, enum phy_mode mode, int submode, + union phy_configure_opts *opts) +{ + return mode == PHY_MODE_USB_HOST || mode == PHY_MODE_USB_DEVICE ? 0 : -EOPNOTSUPP; +} + static int combo_usb2_reset(struct phy *phy) { struct t6050_dp *dp = phy_get_drvdata(phy); @@ -566,6 +615,9 @@ static int combo_usb3_poweroff(struct phy *phy) if (!ret) dp->usb2_active = false; } + /* The controller's next session selects its role again; until then USB2 starts as host. */ + if (!ret) + dp->usb2_device = false; if (ret) { dev_err(dp->dev, "USB3 power-off failed (%d)\n", ret); dp->faulted = true; @@ -573,7 +625,8 @@ static int combo_usb3_poweroff(struct phy *phy) return ret ? -EIO : 0; } static const struct phy_ops combo_usb2_ops = { - .set_mode = combo_usb2_mode, .reset = combo_usb2_reset, .owner = THIS_MODULE, + .set_mode = combo_usb2_mode, .validate = combo_usb2_validate, .reset = combo_usb2_reset, + .owner = THIS_MODULE, }; static const struct phy_ops combo_usb3_ops = { .set_mode = combo_usb3_mode, .power_off = combo_usb3_poweroff, .owner = THIS_MODULE, diff --git a/drivers/phy/apple/atc-t6050-dp.c b/drivers/phy/apple/atc-t6050-dp.c index d266091a78d0f..d25f7ab4a8344 100644 --- a/drivers/phy/apple/atc-t6050-dp.c +++ b/drivers/phy/apple/atc-t6050-dp.c @@ -98,6 +98,7 @@ enum combo_mode { COMBO_SAFE, COMBO_USB, COMBO_DP4, COMBO_DP2, COMBO_CIO }; struct t6050_dp { bool combo, usb_prepared, usb2_active, pipe_active, controller_active, cio_prepared; bool pipe_tunnel; /* the active PIPE is a USB4 router's USB3 tunnel */ + bool usb2_device; /* device mode chosen: USB2 starts without the host signature */ enum combo_mode combo_mode; enum typec_orientation orientation; struct phy *combo_phy[3]; From ac88372ab29044845b9b5625c611ee5bbcc89cb7 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Fri, 20 Nov 2026 02:13:18 +1100 Subject: [PATCH 2/2] usb: dwc3: apple: high-speed gadget on a T6050 port A USB3 PHY that refuses PHY_MODE_USB_DEVICE with -EOPNOTSUPP leaves the PIPE on its dummy producer, and the gadget is offered at high speed. The T6050 Type-C PHY refuses device mode that way, before it touches the PIPE, but its errors were all treated as a failed PIPE handoff, so a device session on it failed. Take the high-speed path first for any such refusal. T8132 keeps failing: it refuses device mode while its SuperSpeed lanes are routed, which is not a PIPE left on its dummy producer. Host starts and every other error are handled as before. Signed-off-by: Ryan Murray --- drivers/usb/dwc3/dwc3-apple.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/drivers/usb/dwc3/dwc3-apple.c b/drivers/usb/dwc3/dwc3-apple.c index 1f7a63b96b97e..ee168f8d60dca 100644 --- a/drivers/usb/dwc3/dwc3-apple.c +++ b/drivers/usb/dwc3/dwc3-apple.c @@ -965,6 +965,17 @@ static int dwc3_apple_set_role(struct dwc3_apple *appledwc, enum dwc3_apple_stat dwc3_enable_susphy(&appledwc->dwc, true); ret = phy_set_mode(appledwc->usb3_phy, host ? PHY_MODE_USB_HOST : PHY_MODE_USB_DEVICE); if (ret) { + /* + * A USB3 PHY without a device sequence (T6040, T6050) refuses the mode before it + * touches the PIPE, which stays on its dummy producer: offer the gadget at high + * speed only. T8132 refuses device mode while its SuperSpeed lanes are routed, + * which is not that case: it keeps failing below. + */ + if (!host && ret == -EOPNOTSUPP && + !of_device_is_compatible(appledwc->dev->of_node, "apple,t8132-dwc3")) { + dwc3_apple_gadget_high_speed(appledwc); + return 0; + } /* * 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 @@ -975,15 +986,7 @@ static int dwc3_apple_set_role(struct dwc3_apple *appledwc, enum dwc3_apple_stat dev_err(appledwc->dev, "USB3 PHY setup failed, err=%d\n", ret); return ret; } - /* - * A USB3 PHY without a device sequence (T6040) leaves the PIPE on its - * dummy producer: offer the gadget at high speed only. - */ - if (!host && ret == -EOPNOTSUPP) { - dwc3_apple_gadget_high_speed(appledwc); - } else { - dev_warn(appledwc->dev, "USB3 PHY setup failed, USB2 only, err=%d\n", ret); - } + dev_warn(appledwc->dev, "USB3 PHY setup failed, USB2 only, err=%d\n", ret); } else if (host && appledwc->usb3_phy && (of_device_is_compatible(appledwc->dev->of_node, "apple,t8132-dwc3") || of_device_is_compatible(appledwc->dev->of_node, "apple,t8142-dwc3"))) { @@ -1003,11 +1006,11 @@ static int dwc3_apple_set_role(struct dwc3_apple *appledwc, enum dwc3_apple_stat } /* - * No device mode: a USB2 PHY that does not validate PHY_MODE_USB_DEVICE (the T6050 Type-C PHY - * implements host mode only), or a kernel built without gadget support, which turns - * dwc3_gadget_init() into a stub that succeeds. Such a controller must not follow a - * USB_ROLE_DEVICE request from the Type-C port controller (a charger or a host on the other end), - * or the core would end up in device mode on top of a PHY powered in host mode. + * No device mode: a USB2 PHY that does not validate PHY_MODE_USB_DEVICE, or a kernel built + * without gadget support, which turns dwc3_gadget_init() into a stub that succeeds. Such a + * controller must not follow a USB_ROLE_DEVICE request from the Type-C port controller (a + * charger or a host on the other end), or the core would end up in device mode on top of a PHY + * powered in host mode. */ static bool dwc3_apple_host_only(struct dwc3_apple *appledwc) {