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 c160e6fcfa9930a9fa7f74ad54384798b3525fb2 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Fri, 20 Nov 2026 02:13:17 +1100 Subject: [PATCH 7/8] 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 8/8] 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) {