From 39aefe24b61eb19583710e96a988f77595ca2db6 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Fri, 20 Nov 2026 00:29:42 +1100 Subject: [PATCH 1/8] dt-bindings: phy: apple,t6040-atcphy: USB2 device tunables Describe the two optional tunable lists the T6040 USB2 PHY takes in place of apple,tunable-usb2-host when the port runs as a USB device: apple,tunable-usb2-default, applied first, and apple,tunable-usb2-device. The boot loader copies both from the platform's device tree, as it does for the host list. Signed-off-by: Ryan Murray --- .../devicetree/bindings/phy/apple,t6040-atcphy.yaml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Documentation/devicetree/bindings/phy/apple,t6040-atcphy.yaml b/Documentation/devicetree/bindings/phy/apple,t6040-atcphy.yaml index 3178de1a8b7e4..a5586c0de80c1 100644 --- a/Documentation/devicetree/bindings/phy/apple,t6040-atcphy.yaml +++ b/Documentation/devicetree/bindings/phy/apple,t6040-atcphy.yaml @@ -172,6 +172,16 @@ properties: $ref: "#/$defs/apple,tunable" description: USB2 host tunables, applied to the bank0 region. + apple,tunable-usb2-default: + $ref: "#/$defs/apple,tunable" + description: + USB2 default tunables, applied to the bank0 region before the device + tunables when the port runs as a USB device. + + apple,tunable-usb2-device: + $ref: "#/$defs/apple,tunable" + description: USB2 device tunables, applied to the bank0 region. + required: - compatible - reg From b4099aa5726d7dbcfbb58b38c4a651ad4085bf3a Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Fri, 20 Nov 2026 00:29:46 +1100 Subject: [PATCH 2/8] phy: apple: t6040-usb2: USB2 device mode The T6040 USB2 PHY implemented host mode only, so dwc3-apple had to keep every T6040 controller a host and drop the port controller's USB_ROLE_DEVICE: a J616s cabled to another computer never shows up on it as a USB device. Device mode is the same eUSB2 power-on with three differences, found with the boot loader's USB2 device bring-up on a J616s cabled to a Mac host: - the default and device tunables are applied instead of the host one; - SIG[14:12] are cleared: the device tunables leave them set (SIG reads 0x01c0700f) and with them set the host never sees the device connect. The host tunable clears the same bits for host mode; - VBUS valid is forced: VBUS is seen by the Type-C port controller, not by this PHY, and the controller is only put in device mode after the port controller reported a USB data connection from a host. Accept PHY_MODE_USB_DEVICE in set_mode and power_on, check the device signal bits like the host ones, and add a validate op that reports both modes, so the controller glue can tell from the PHY whether it may follow a device role. power_off returns the PHY to host mode: dwc3-apple selects device mode before each device session, while xHCI asks for host mode only once the PHY runs, so a host session after a device one would otherwise power on as a device and then have xHCI's request refused. The USB3 PHY has no device sequence; a device port runs at high speed with its PIPE on the dummy PHY. Signed-off-by: Ryan Murray --- drivers/phy/apple/t6040-usb2.c | 142 +++++++++++++++++++++++++-------- 1 file changed, 110 insertions(+), 32 deletions(-) diff --git a/drivers/phy/apple/t6040-usb2.c b/drivers/phy/apple/t6040-usb2.c index 50d82116aac2d..152d4cdfc5e82 100644 --- a/drivers/phy/apple/t6040-usb2.c +++ b/drivers/phy/apple/t6040-usb2.c @@ -1,11 +1,18 @@ // SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause /* - * Apple T6040 Type-C PHY -- USB2 and USB3 host + * Apple T6040 Type-C PHY -- USB2 host and device, USB3 host * * This deliberately does not share the T8103/T8122 ATC PHY compatible. T6040 * has CIO4/TB5-era resources and a different event-bank layout. The - * implemented operations are the USB2 host sequence and the USB3 host attach - * (mode 4) decoded from the paired AppleT6040TypeCPhy driver. + * implemented operations are the USB2 host and device sequences and the USB3 + * host attach (mode 4) decoded from the paired AppleT6040TypeCPhy driver. + * + * USB2 device: the same eUSB2 power-on as the host, with the device tunables + * from the boot loader instead of the host one, the role signature cleared and + * VBUS forced valid (the Type-C port controller, not this PHY, sees VBUS: the + * controller only enters device mode once the port controller has reported a + * USB data connection from a host). The USB3 PHY has no device sequence, so a + * device port runs at high speed with its PIPE on the dummy PHY. * * USB3: the Type-C orientation switch records the plug orientation; power_on * of the USB3 PHY wakes the PHY, applies the tunables and the crossbar for @@ -56,7 +63,7 @@ #define T6040_USB2_USBCTL 0x00 #define T6040_USB2_USBCTL_MODE GENMASK(2, 0) -#define T6040_USB2_USBCTL_MODE_HOST 2 +#define T6040_USB2_USBCTL_MODE_HOST 2 /* "run": host and device alike */ #define T6040_USB2_CTL 0x04 #define T6040_USB2_CTL_RESET BIT(0) @@ -67,6 +74,8 @@ #define T6040_USB2_SIG 0x08 #define T6040_USB2_SIG_VBUSDET_FORCE_VAL BIT(0) #define T6040_USB2_SIG_VBUSDET_FORCE_EN BIT(1) +#define T6040_USB2_SIG_VBUSVLDEXT_FORCE_VAL BIT(2) +#define T6040_USB2_SIG_VBUSVLDEXT_FORCE_EN BIT(3) #define T6040_USB2_SIG_HOST_0 BIT(12) #define T6040_USB2_SIG_HOST_1 BIT(13) #define T6040_USB2_SIG_HOST_2 BIT(14) @@ -280,6 +289,9 @@ struct t6040_usb2_phy { struct apple_tunable *tunable_pipehandler; /* ADT tunable_USB2PHY_HOST, applied after the signal setup. */ struct apple_tunable *tunable_usb2_host; + /* ADT tunable_USB2PHY_DFLT and _DEV, applied in their place for device mode. */ + struct apple_tunable *tunable_usb2_default; + struct apple_tunable *tunable_usb2_device; struct apple_rtkit *rtk; struct device *mbox_dev; struct completion app_reply; @@ -326,11 +338,17 @@ static inline void t6040_usb2_clear32(void __iomem *reg, u32 clear) t6040_usb2_mask32(reg, clear, 0); } +static int t6040_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 t6040_usb2_set_mode(struct phy *phy, enum phy_mode mode, int submode) { struct t6040_usb2_phy *tphy = phy_get_drvdata(phy); - if (mode != PHY_MODE_USB_HOST) + if (t6040_usb2_validate(phy, mode, submode, NULL)) return -EOPNOTSUPP; guard(mutex)(&tphy->lock); @@ -347,16 +365,36 @@ static int t6040_usb2_set_mode(struct phy *phy, enum phy_mode mode, int submode) #define T6040_USB2_SIG_INIT (T6040_USB2_SIG_HOST_0 | T6040_USB2_SIG_HOST_1 | \ T6040_USB2_SIG_HOST_2 | T6040_USB2_SIG_VBUSDET_FORCE_VAL | \ T6040_USB2_SIG_VBUSDET_FORCE_EN) +#define T6040_USB2_SIG_ROLE (T6040_USB2_SIG_HOST_0 | T6040_USB2_SIG_HOST_1 | \ + T6040_USB2_SIG_HOST_2) +#define T6040_USB2_SIG_VBUSVLDEXT (T6040_USB2_SIG_VBUSVLDEXT_FORCE_VAL | \ + T6040_USB2_SIG_VBUSVLDEXT_FORCE_EN) +/* The signal bits power_on programs and checks: the init ones, plus VBUS valid in device mode. */ +#define T6040_USB2_SIG_CHECKED (T6040_USB2_SIG_INIT | T6040_USB2_SIG_VBUSVLDEXT) -static u32 t6040_usb2_sig_want(struct t6040_usb2_phy *tphy) +static u32 t6040_usb2_sig_tunable(u32 sig, const struct apple_tunable *t) { - struct apple_tunable *t = tphy->tunable_usb2_host; - u32 want = T6040_USB2_SIG_INIT; size_t i; for (i = 0; t && i < t->sz; i++) if (t->values[i].offset == T6040_USB2_SIG) - want = (want & ~t->values[i].mask) | t->values[i].value; + sig = (sig & ~t->values[i].mask) | t->values[i].value; + return sig; +} + +/* The checked signal bits as power_on leaves them in the current mode. */ +static u32 t6040_usb2_sig_want(struct t6040_usb2_phy *tphy) +{ + u32 want = T6040_USB2_SIG_INIT; + + if (tphy->mode == PHY_MODE_USB_DEVICE) { + want = t6040_usb2_sig_tunable(want, tphy->tunable_usb2_default); + want = t6040_usb2_sig_tunable(want, tphy->tunable_usb2_device); + want = (want & ~T6040_USB2_SIG_ROLE) | T6040_USB2_SIG_VBUSVLDEXT; + return want & T6040_USB2_SIG_CHECKED; + } + + want = t6040_usb2_sig_tunable(want, tphy->tunable_usb2_host); return want & T6040_USB2_SIG_INIT; } @@ -369,7 +407,7 @@ static int t6040_usb2_power_on(struct phy *phy) if (tphy->shutdown_failed) return -EIO; - if (tphy->mode != PHY_MODE_USB_HOST) + if (tphy->mode != PHY_MODE_USB_HOST && tphy->mode != PHY_MODE_USB_DEVICE) return -EINVAL; if (tphy->powered) return 0; @@ -390,13 +428,27 @@ static int t6040_usb2_power_on(struct phy *phy) t6040_usb2_set32(tphy->usb2 + T6040_USB2_SIG, T6040_USB2_SIG_VBUSDET_FORCE_EN); - /* - * The host tunable then sets the signal fields for host mode: on the - * J616s it clears SIG[14:12] again (mask 0x7003, value 0x3). Left at - * their init values, which are the device-mode ones, the USB2 port - * never sees a connect. - */ - apple_tunable_apply(tphy->usb2, tphy->tunable_usb2_host); + if (tphy->mode == PHY_MODE_USB_DEVICE) { + /* + * Device mode takes the default and device tunables instead. On + * the J616s they leave SIG[14:12] set (SIG reads 0x01c0700f), and + * with those set a host never sees the device connect: clear them, + * as the host tunable does for host mode. VBUS is the port + * controller's: force it valid, or the controller sees no session + * (J616s USB2 device row, aura#245, 2026-11-19). + */ + apple_tunable_apply(tphy->usb2, tphy->tunable_usb2_default); + apple_tunable_apply(tphy->usb2, tphy->tunable_usb2_device); + t6040_usb2_clear32(tphy->usb2 + T6040_USB2_SIG, T6040_USB2_SIG_ROLE); + t6040_usb2_set32(tphy->usb2 + T6040_USB2_SIG, T6040_USB2_SIG_VBUSVLDEXT); + } else { + /* + * The host tunable then sets the signal fields for host mode: on + * the J616s it clears SIG[14:12] again (mask 0x7003, value 0x3). + * Left at their init values the USB2 port never sees a connect. + */ + apple_tunable_apply(tphy->usb2, tphy->tunable_usb2_host); + } msleep(10); @@ -430,7 +482,7 @@ static int t6040_usb2_power_on(struct phy *phy) T6040_USB2_USBCTL_MODE, T6040_USB2_USBCTL_MODE_HOST); - /* Confirm the programmed fields before the core can start the host. */ + /* Confirm the programmed fields before the core can start. */ sig_want = t6040_usb2_sig_want(tphy); ctl = readl(tphy->usb2 + T6040_USB2_CTL); sig = readl(tphy->usb2 + T6040_USB2_SIG); @@ -442,7 +494,8 @@ static int t6040_usb2_power_on(struct phy *phy) (ctl & (T6040_USB2_CTL_RESET | T6040_USB2_CTL_PORT_RESET | T6040_USB2_CTL_SIDDQ | T6040_USB2_CTL_APB_RESET_N)) != T6040_USB2_CTL_APB_RESET_N || - (sig & T6040_USB2_SIG_INIT) != sig_want || + (sig & (tphy->mode == PHY_MODE_USB_DEVICE ? T6040_USB2_SIG_CHECKED : + T6040_USB2_SIG_INIT)) != sig_want || (tune & (T6040_USB2_MISCTUNE_APBCLK_GATE_OFF | T6040_USB2_MISCTUNE_REFCLK_GATE_OFF)) || (mode & T6040_USB2_USBCTL_MODE) != T6040_USB2_USBCTL_MODE_HOST || @@ -450,7 +503,8 @@ static int t6040_usb2_power_on(struct phy *phy) goto failed; tphy->powered = true; - dev_info(tphy->dev, "USB2 host sequence complete\n"); + dev_info(tphy->dev, "USB2 %s sequence complete\n", + tphy->mode == PHY_MODE_USB_DEVICE ? "device" : "host"); return 0; failed: tphy->shutdown_failed = true; @@ -512,11 +566,19 @@ static int t6040_usb2_power_off(struct phy *phy) return -EIO; tphy->shutdown_failed = false; tphy->powered = false; + /* + * dwc3-apple selects device mode before each device session; xHCI asks + * for host mode only once the PHY is powered. Start the next session in + * host mode, as at probe, or a host after a device session would power + * on as a device and then fail xHCI's request. + */ + tphy->mode = PHY_MODE_USB_HOST; return 0; } static const struct phy_ops t6040_usb2_phy_ops = { .owner = THIS_MODULE, + .validate = t6040_usb2_validate, .set_mode = t6040_usb2_set_mode, .power_on = t6040_usb2_power_on, .power_off = t6040_usb2_power_off, @@ -2399,6 +2461,22 @@ static struct phy *t6040_usb2_xlate(struct device *dev, } } +/* An optional USB2 tunable from the boot loader, for the bank0 region. */ +static int t6040_usb2_tunable(struct platform_device *pdev, const char *name, + struct apple_tunable **tunable) +{ + struct device *dev = &pdev->dev; + + if (!of_property_present(dev->of_node, name)) + return 0; + *tunable = devm_apple_tunable_parse(dev, dev->of_node, name, + platform_get_resource_byname(pdev, IORESOURCE_MEM, + "bank0")); + if (IS_ERR(*tunable)) + return dev_err_probe(dev, PTR_ERR(*tunable), "invalid %s\n", name); + return 0; +} + static int t6040_usb2_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -2417,9 +2495,9 @@ static int t6040_usb2_probe(struct platform_device *pdev) * to this phy. dwc3-apple's early phy_set_mode() call happens while * dwc.usb2_generic_phy[] is still unpopulated, so it is a silent no-op * on a NULL phy, and a PHY_MODE_INVALID default then fails power_on - * with -EINVAL ("failed to initialize core", ticket 108). This - * provider implements exactly one mode, so start in it; set_mode - * still rejects every request that is not PHY_MODE_USB_HOST. + * with -EINVAL ("failed to initialize core", ticket 108). Start in + * host mode; dwc3-apple selects device mode before a device session, + * and power_off returns to host mode. */ tphy->mode = PHY_MODE_USB_HOST; mutex_init(&tphy->lock); @@ -2431,15 +2509,15 @@ static int t6040_usb2_probe(struct platform_device *pdev) return dev_err_probe(dev, PTR_ERR(tphy->usb2), "failed to map USB2 bank 0\n"); - if (of_property_present(dev->of_node, "apple,tunable-usb2-host")) { - tphy->tunable_usb2_host = - devm_apple_tunable_parse(dev, dev->of_node, "apple,tunable-usb2-host", - platform_get_resource_byname(pdev, IORESOURCE_MEM, - "bank0")); - if (IS_ERR(tphy->tunable_usb2_host)) - return dev_err_probe(dev, PTR_ERR(tphy->tunable_usb2_host), - "invalid apple,tunable-usb2-host\n"); - } + ret = t6040_usb2_tunable(pdev, "apple,tunable-usb2-host", &tphy->tunable_usb2_host); + if (!ret) + ret = t6040_usb2_tunable(pdev, "apple,tunable-usb2-default", + &tphy->tunable_usb2_default); + if (!ret) + ret = t6040_usb2_tunable(pdev, "apple,tunable-usb2-device", + &tphy->tunable_usb2_device); + if (ret) + return ret; tphy->evt = devm_platform_ioremap_resource_byname(pdev, "bank1"); if (IS_ERR(tphy->evt)) From b2486d1dd62cfaeb7f8ec75a48ba5bdb7c80a7a2 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Fri, 20 Nov 2026 00:29:50 +1100 Subject: [PATCH 3/8] phy: apple: atc: report the USB2 host and device modes atcphy_usb2_set_mode() serves both roles by setting or clearing the host signature. Say so through the validate op, so that a controller glue can ask the PHY whether it may run a port as a USB device instead of keeping a list of SoCs. Signed-off-by: Ryan Murray --- drivers/phy/apple/atc.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/phy/apple/atc.c b/drivers/phy/apple/atc.c index 34d3aa12b8f4c..820e7f3eca6f6 100644 --- a/drivers/phy/apple/atc.c +++ b/drivers/phy/apple/atc.c @@ -4612,9 +4612,17 @@ static int atcphy_rpm_usb2_set_mode(struct phy *phy, enum phy_mode mode, int sub return ret; } +/* Both roles: atcphy_usb2_set_mode() sets or clears the host signature. */ +static int atcphy_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 const struct phy_ops apple_atc_usb2_phy_ops = { .owner = THIS_MODULE, .init = atcphy_rpm_usb2_init, + .validate = atcphy_usb2_validate, .set_mode = atcphy_rpm_usb2_set_mode, }; From 7269c79fab18041984e470f2786bc42c0661fbb0 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Fri, 20 Nov 2026 00:29:53 +1100 Subject: [PATCH 4/8] usb: dwc3: apple: take the device role when the USB2 PHY has one dwc3_apple_host_only() kept T6040 and T6050 controllers hosts by compatible, because their USB2 PHYs could not run as a device. Ask the PHY instead: a controller follows USB_ROLE_DEVICE when its USB2 PHY validates PHY_MODE_USB_DEVICE. The T6040 PHY now does; the T6050 combo PHY does not, so those ports stay hosts for the hardware reason the compatible list stood for, and any PHY that gains a device sequence gets device mode without a change here. The ATC PHY validates both modes, so T8103 to T8142 controllers keep their device role. A port whose USB3 PHY has no device sequence (T6040: -EOPNOTSUPP) or that has no USB3 PHY leaves the PIPE on the dummy producer. Offer the gadget at high speed only there, and give the next session the core's own maximum speed back before the core is initialised. Signed-off-by: Ryan Murray --- drivers/usb/dwc3/dwc3-apple.c | 47 +++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/drivers/usb/dwc3/dwc3-apple.c b/drivers/usb/dwc3/dwc3-apple.c index 4d9b4ac0d8346..27ce98ff214a7 100644 --- a/drivers/usb/dwc3/dwc3-apple.c +++ b/drivers/usb/dwc3/dwc3-apple.c @@ -175,6 +175,8 @@ struct dwc3_apple { /* The root port the fixed hub sits on, its node's reg. */ u32 hub_port; bool host_only; + /* The core's maximum speed from its first probe; device sessions may lower it. */ + enum usb_device_speed maximum_speed; struct mutex lock; @@ -921,6 +923,17 @@ static void dwc3_apple_usb3_pipe_reset(struct dwc3_apple *appledwc) msleep(100); } +/* + * Without a USB3 PHY that runs as a device the PIPE stays on its dummy producer: offer the gadget + * at high speed only. dwc3_apple_init() undoes this for the next session. + */ +static void dwc3_apple_gadget_high_speed(struct dwc3_apple *appledwc) +{ + if (appledwc->dwc.maximum_speed > USB_SPEED_HIGH) + appledwc->dwc.maximum_speed = USB_SPEED_HIGH; + dev_info(appledwc->dev, "No USB3 device PHY: gadget at high speed\n"); +} + /* Select the role in the core and route the USB3 PHY, before xhci or the gadget is started */ static int dwc3_apple_set_role(struct dwc3_apple *appledwc, enum dwc3_apple_state state) { @@ -931,6 +944,8 @@ static int dwc3_apple_set_role(struct dwc3_apple *appledwc, enum dwc3_apple_stat appledwc->dwc.dr_mode = host ? USB_DR_MODE_HOST : USB_DR_MODE_PERIPHERAL; dwc3_apple_set_ptrcap(appledwc, host ? DWC3_GCTL_PRTCAP_HOST : DWC3_GCTL_PRTCAP_DEVICE); + if (appledwc->maximum_speed == USB_SPEED_UNKNOWN) + appledwc->maximum_speed = appledwc->dwc.maximum_speed; /* * 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's @@ -951,7 +966,15 @@ 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; } - dev_warn(appledwc->dev, "USB3 PHY setup failed, USB2 only, err=%d\n", 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); + } } 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"))) { @@ -964,24 +987,25 @@ static int dwc3_apple_set_role(struct dwc3_apple *appledwc, enum dwc3_apple_stat } else if (appledwc->usb3_phy && of_device_is_compatible(appledwc->dev->of_node, "apple,t6040-dwc3")) { dwc3_apple_usb3_pipe_reset(appledwc); + } else if (!host && !appledwc->usb3_phy) { + dwc3_apple_gadget_high_speed(appledwc); } return 0; } /* - * No device mode: the T6040 USB2 PHY (phy-apple-t6040-usb2) and the T6050 Type-C PHY implement - * host mode only, and a kernel built without gadget support 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 (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. */ -static bool dwc3_apple_host_only(struct device *dev) +static bool dwc3_apple_host_only(struct dwc3_apple *appledwc) { if (!IS_ENABLED(CONFIG_USB_DWC3_GADGET) && !IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE)) return true; - return of_device_is_compatible(dev->of_node, "apple,t6040-dwc3") || - of_device_is_compatible(dev->of_node, "apple,t6050-dwc3"); + return phy_validate(appledwc->usb2_phy, PHY_MODE_USB_DEVICE, 0, NULL) != 0; } static int dwc3_apple_init(struct dwc3_apple *appledwc, enum dwc3_apple_state state) @@ -997,6 +1021,9 @@ 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; + /* Undo a high-speed limit of an earlier device session before the core init. */ + if (appledwc->maximum_speed != USB_SPEED_UNKNOWN) + appledwc->dwc.maximum_speed = appledwc->maximum_speed; ret = dwc3_apple_core_start(appledwc, state); if (ret) @@ -1834,7 +1861,6 @@ static int dwc3_apple_probe(struct platform_device *pdev) appledwc->dev = &pdev->dev; appledwc->fixed_hub = dwc3_apple_has_fixed_hub(dev, &appledwc->hub_port); - appledwc->host_only = dwc3_apple_host_only(dev); appledwc->dt_dis_u3_susphy = device_property_read_bool(dev, "snps,dis_u3_susphy_quirk"); appledwc->sleep_ddr = device_property_read_bool(dev, "apple,sleep-ddr"); /* The PHY driver and the DARTs follow runtime PM on these SoCs. */ @@ -1855,6 +1881,7 @@ static int dwc3_apple_probe(struct platform_device *pdev) if (IS_ERR(appledwc->usb2_phy)) return dev_err_probe(dev, PTR_ERR(appledwc->usb2_phy), "Failed to get the USB2 PHY\n"); + appledwc->host_only = dwc3_apple_host_only(appledwc); /* * Older T8132 device trees and the T6040 ports without a USB3 PHY From f98d18642ee62729886c4cfe9a4df4fb7178629e Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Fri, 20 Nov 2026 00:44:03 +1100 Subject: [PATCH 5/8] phy: apple: t6040-usb2: leave no device mode behind a failed start dwc3-apple selects device mode before it releases the controller reset. When the start fails before the PHY is powered (the reset, a runtime PM resume or the core probe fails), power_off never runs and the PHY kept device mode: the next host session then powered it on as a device and xHCI's host request was refused. Return to host mode when the controller reset is asserted with the PHY off, which every failed start does on its way out. Also apply the default tunable, when the boot loader provides it, before the host one, as the device sequence does, so that fields only the device tunable writes do not carry over into a host session. Signed-off-by: Ryan Murray --- drivers/phy/apple/t6040-usb2.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/phy/apple/t6040-usb2.c b/drivers/phy/apple/t6040-usb2.c index 152d4cdfc5e82..3387319144a04 100644 --- a/drivers/phy/apple/t6040-usb2.c +++ b/drivers/phy/apple/t6040-usb2.c @@ -394,6 +394,7 @@ static u32 t6040_usb2_sig_want(struct t6040_usb2_phy *tphy) return want & T6040_USB2_SIG_CHECKED; } + want = t6040_usb2_sig_tunable(want, tphy->tunable_usb2_default); want = t6040_usb2_sig_tunable(want, tphy->tunable_usb2_host); return want & T6040_USB2_SIG_INIT; } @@ -437,6 +438,8 @@ static int t6040_usb2_power_on(struct phy *phy) * controller's: force it valid, or the controller sees no session * (J616s USB2 device row, aura#245, 2026-11-19). */ + if (!tphy->tunable_usb2_device) + dev_dbg(tphy->dev, "USB2 device mode without device tunables\n"); apple_tunable_apply(tphy->usb2, tphy->tunable_usb2_default); apple_tunable_apply(tphy->usb2, tphy->tunable_usb2_device); t6040_usb2_clear32(tphy->usb2 + T6040_USB2_SIG, T6040_USB2_SIG_ROLE); @@ -446,7 +449,11 @@ static int t6040_usb2_power_on(struct phy *phy) * The host tunable then sets the signal fields for host mode: on * the J616s it clears SIG[14:12] again (mask 0x7003, value 0x3). * Left at their init values the USB2 port never sees a connect. + * The default tunable, when the boot loader provides it, goes + * first, as for a device: fields only the device tunable writes + * do not carry over from a device session. */ + apple_tunable_apply(tphy->usb2, tphy->tunable_usb2_default); apple_tunable_apply(tphy->usb2, tphy->tunable_usb2_host); } @@ -2389,6 +2396,9 @@ static int t6040_usb2_reset_assert(struct reset_controller_dev *rcdev, T6040_PIPEHANDLER_AON_GEN_DWC3_RESET_N); t6040_usb2_set32(tphy->pipehandler + T6040_PIPEHANDLER_AON_GEN, T6040_PIPEHANDLER_AON_GEN_DWC3_FORCE_CLAMP_EN); + /* A device start that failed before power_on also ends here: back to host mode. */ + if (!tphy->powered) + tphy->mode = PHY_MODE_USB_HOST; if (tphy->dwc3_running) { tphy->dwc3_running = false; pm_runtime_put(tphy->dev); From 465f189aa0cded67528be80026d2364c9962dbec Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Fri, 20 Nov 2026 00:44:09 +1100 Subject: [PATCH 6/8] usb: dwc3: apple: set up a high-speed gadget like dwc3_core_init() dwc3_core_init() picks GUCTL1.DEV_FORCE_20_CLK_FOR_30_CLK from the maximum speed, which the glue lowers to high speed only after the core init, once the USB3 PHY has refused the device role. Set the bit there too, so a gadget limited to high speed runs with the core set up as for one configured that way. Signed-off-by: Ryan Murray --- drivers/usb/dwc3/dwc3-apple.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/usb/dwc3/dwc3-apple.c b/drivers/usb/dwc3/dwc3-apple.c index 27ce98ff214a7..1f7a63b96b97e 100644 --- a/drivers/usb/dwc3/dwc3-apple.c +++ b/drivers/usb/dwc3/dwc3-apple.c @@ -929,8 +929,17 @@ static void dwc3_apple_usb3_pipe_reset(struct dwc3_apple *appledwc) */ static void dwc3_apple_gadget_high_speed(struct dwc3_apple *appledwc) { - if (appledwc->dwc.maximum_speed > USB_SPEED_HIGH) - appledwc->dwc.maximum_speed = USB_SPEED_HIGH; + struct dwc3 *dwc = &appledwc->dwc; + u32 reg; + + if (dwc->maximum_speed <= USB_SPEED_HIGH) + return; + dwc->maximum_speed = USB_SPEED_HIGH; + /* What dwc3_core_init() selects for a core limited to high speed. */ + if (DWC3_VER_IS_WITHIN(DWC3, 290A, ANY)) { + reg = dwc3_readl(dwc, DWC3_GUCTL1); + dwc3_writel(dwc, DWC3_GUCTL1, reg | DWC3_GUCTL1_DEV_FORCE_20_CLK_FOR_30_CLK); + } dev_info(appledwc->dev, "No USB3 device PHY: gadget at high speed\n"); } From 9d73fd7d6235d2247f79c5e80981b3086f7305e9 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Fri, 20 Nov 2026 04:44:21 +1100 Subject: [PATCH 7/8] tools/asahi: model the dwc3-apple maximum_speed save in the host tests The glue now keeps the controller's maximum speed while a gadget runs clamped to high speed and puts it back in dwc3_apple_init(). The Neo stability harness and the apple-dcp dwc3-teardown model compile that function against their own struct dwc3 and struct dwc3_apple, which had no maximum_speed and no enum usb_device_speed, so both stopped building. Add both with the uapi values (USB_SPEED_UNKNOWN is 0, so the zeroed fixtures save nothing), and check in the Neo harness that a saved maximum is restored at the next core init and that nothing is restored before a clamp. Signed-off-by: Ryan Murray --- tools/asahi/neo-stability-tests.py | 12 ++++++++++-- .../selftests/drivers/gpu/apple-dcp/dwc3/mocks.c | 8 ++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/tools/asahi/neo-stability-tests.py b/tools/asahi/neo-stability-tests.py index 3433943659746..892f1379ccd84 100644 --- a/tools/asahi/neo-stability-tests.py +++ b/tools/asahi/neo-stability-tests.py @@ -79,9 +79,10 @@ def function(source, name): assert(h==dockchannel_rx_irq&&t==dockchannel_rx_irq_thread&&!strcmp(n,"apple-dockchannel-rx"));rx_irq_requested=irq;rx_flags=f;return 0;} enum dwc3_apple_state {DWC3_APPLE_PROBE_PENDING,DWC3_APPLE_NO_CABLE,DWC3_APPLE_HOST,DWC3_APPLE_DEVICE,DWC3_APPLE_SUSPENDED}; #define DWC3_GCTL_PRTCAP_HOST 1 -struct dwc3 {int num_usb3_ports,num_usb2_ports;int usb3_generic_phy[2],usb2_generic_phy[2],usb3_phy,usb2_phy;int current_dr_role;bool dis_u3_susphy_quirk;}; +enum usb_device_speed {USB_SPEED_UNKNOWN,USB_SPEED_LOW,USB_SPEED_FULL,USB_SPEED_HIGH,USB_SPEED_WIRELESS,USB_SPEED_SUPER,USB_SPEED_SUPER_PLUS}; +struct dwc3 {int num_usb3_ports,num_usb2_ports;int usb3_generic_phy[2],usb2_generic_phy[2],usb3_phy,usb2_phy;int current_dr_role;bool dis_u3_susphy_quirk;enum usb_device_speed maximum_speed;}; struct dwc3_apple {struct device*dev;struct dwc3 dwc;int lock,reset;enum dwc3_apple_state state;bool fixed_hub,host_only,rpm_held,core_active,core_exit_pending,reset_pending,dt_dis_u3_susphy,sleep_ddr;unsigned usb3_power_off_pending,usb2_power_off_pending;int usb2_phy; - int sleep_pm_lock;enum dwc3_apple_sleep_phase sleep_phase;bool sleep_syscore;}; + int sleep_pm_lock;enum dwc3_apple_sleep_phase sleep_phase;bool sleep_syscore;enum usb_device_speed maximum_speed;}; static void apple_sleep_usb_slp_ddr(bool on){(void)on;} static int core_error,host_error,gadget_error,reset_error,role_error,start_role; static unsigned rpm_puts; @@ -186,6 +187,13 @@ def function(source, name): assert(!dwc3_apple_init(&a,role)&&!d.syscore&&a.sleep_syscore); assert(!dwc3_apple_exit(&a)&&!d.syscore&&!a.sleep_syscore); a.sleep_phase=DWC3_APPLE_SLEEP_IDLE; + /* A gadget clamped to high speed gets the saved controller maximum back at the next + * core init; nothing is saved before the first clamp. */ + assert(!dwc3_apple_init(&a,role)&&a.dwc.maximum_speed==USB_SPEED_UNKNOWN); + assert(!dwc3_apple_exit(&a)); + a.maximum_speed=USB_SPEED_SUPER;a.dwc.maximum_speed=USB_SPEED_HIGH; + assert(!dwc3_apple_init(&a,role)&&a.dwc.maximum_speed==USB_SPEED_SUPER); + assert(!dwc3_apple_exit(&a)); } }else if(!strcmp(argv[1],"regulatory")){ enum {N25=MT7932_CHANNELS_2G+MT7932_CHANNELS_5G,SIX13=N25+3,VLP=N25+5}; diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/dwc3/mocks.c b/tools/testing/selftests/drivers/gpu/apple-dcp/dwc3/mocks.c index 2461f130fa7f1..96ba1169f4840 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/dwc3/mocks.c +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/dwc3/mocks.c @@ -76,12 +76,18 @@ static void regulator_disable(int p) { assert(!p); } +/* include/uapi/linux/usb/ch9.h: UNKNOWN is 0, so zeroed fixtures save no speed. */ +enum usb_device_speed { + USB_SPEED_UNKNOWN, USB_SPEED_LOW, USB_SPEED_FULL, USB_SPEED_HIGH, + USB_SPEED_WIRELESS, USB_SPEED_SUPER, USB_SPEED_SUPER_PLUS, +}; struct dwc3 { struct phy *usb2_generic_phy[3], *usb3_generic_phy[3]; int num_usb2_ports, num_usb3_ports, usb2_phy, usb3_phy; struct reset_controller_dev *reset; int dev, usb_psy, vbus_draw_work, dr_mode, current_dr_role; bool dis_u3_susphy_quirk; + enum usb_device_speed maximum_speed; struct { void *notifier_call; } psy_nb; }; struct dwc3_apple { @@ -115,6 +121,8 @@ struct dwc3_apple { */ bool sleep_tunnel; enum usb_role sleep_tunnel_role; + /* The controller maximum saved by a high-speed gadget clamp; UNKNOWN here. */ + enum usb_device_speed maximum_speed; }; /* The epoch spinlock: taken only when free, released only when held. */ #define spin_lock_irqsave(l, f) do { assert(!*(l)); *(l) = 1; (f) = 0; } while (0) From 055fed8483c486a5c3fed4d334af2d5a0eb669c7 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Fri, 20 Nov 2026 05:11:34 +1100 Subject: [PATCH 8/8] usb: dwc3: apple: high-speed gadget whenever the USB3 PHY has no device mode A USB3 PHY that cannot run a SuperSpeed device answers the device request with -EOPNOTSUPP and leaves the PIPE alone. The glue already offers the gadget at high speed for that (T6040), but on T8132 and T6050 the check for failed host handoffs ran first and failed the role instead. Its reason is xHCI: a failed BIST or PIPE handoff must not start the host. That does not apply to a gadget whose USB2 PHY already runs as a device. The T8132 ATC PHY refuses the device role while its lanes run USB3, so a T8132 port with a USB3 calibration and a host on the other end lost its USB (seen on the J773g, linux#2434). Take the high-speed path for a device-role -EOPNOTSUPP on every SoC, before that check; other USB3 PHY errors are handled as before. T6050 never gets here, its USB2 PHY has no device mode. The ATC PHYs that answer -EOPNOTSUPP for another reason (a T8103 port whose lanes are all DisplayPort or that has no SuperSpeed tunables) cannot carry a SuperSpeed device either, so the high-speed gadget fits them too; they already took this path. The T8132 selftest now expects the high-speed gadget. This is the generic form of the T8132 fallback in linux#2420 by techmore, whose J773g row (a USB 3 host lists the gadget at 480 Mb/s where the role failed before) is the hardware evidence for it. DjDeveloperr reported the failure and serves the T8132 device role from the PHY side in linux#2434; both changes can land. Link: https://github.com/aurora-silicon/linux/pull/2420 Link: https://github.com/aurora-silicon/linux/pull/2434 Signed-off-by: Ryan Murray --- drivers/usb/dwc3/dwc3-apple.c | 19 +++++++++---------- .../selftests/drivers/apple/atc-t8132-usb3.py | 8 +++++--- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/drivers/usb/dwc3/dwc3-apple.c b/drivers/usb/dwc3/dwc3-apple.c index 1f7a63b96b97e..0eb29df7003fb 100644 --- a/drivers/usb/dwc3/dwc3-apple.c +++ b/drivers/usb/dwc3/dwc3-apple.c @@ -964,7 +964,14 @@ 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 (!host && ret == -EOPNOTSUPP) { + /* + * The USB3 PHY has no SuperSpeed device mode (T6040, or a T8132 port whose + * lanes run USB3) and has left the PIPE alone: offer the gadget at high speed, + * whatever the SoC. The USB2 PHY already runs as a device. + */ + dwc3_apple_gadget_high_speed(appledwc); + } 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 @@ -975,15 +982,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"))) { diff --git a/tools/testing/selftests/drivers/apple/atc-t8132-usb3.py b/tools/testing/selftests/drivers/apple/atc-t8132-usb3.py index a4f12c3c601e5..a37fa74653c53 100755 --- a/tools/testing/selftests/drivers/apple/atc-t8132-usb3.py +++ b/tools/testing/selftests/drivers/apple/atc-t8132-usb3.py @@ -358,15 +358,17 @@ def main(): phy_error=-ETIMEDOUT; assert(dwc3_apple_init(&a,DWC3_APPLE_HOST)==-ETIMEDOUT); assert(!host_calls && !gadget_calls && stops==1 && a.state==DWC3_APPLE_NO_CABLE); + /* No SuperSpeed device mode: the gadget starts at high speed instead. */ phy_error=-EOPNOTSUPP; - assert(dwc3_apple_init(&a,DWC3_APPLE_DEVICE)==-EOPNOTSUPP); - assert(!gadget_calls && stops==2); + assert(!dwc3_apple_init(&a,DWC3_APPLE_DEVICE)); + assert(gadget_calls==1 && stops==1 && a.state==DWC3_APPLE_DEVICE); + a.state=DWC3_APPLE_NO_CABLE; phy_error=0; assert(!dwc3_apple_init(&a,DWC3_APPLE_HOST)); assert(host_calls==1 && a.state==DWC3_APPLE_HOST); dev.of_node="apple,t8103-dwc3"; phy_error=-ETIMEDOUT; assert(!dwc3_apple_init(&a,DWC3_APPLE_HOST) && host_calls==2); - puts("ok 7 - T8132 PHY failures stop before xHCI, older fallback preserved"); + puts("ok 7 - T8132 PHY failures stop before xHCI, a device role falls back to high speed, older fallback preserved"); return 0; } '''