From 39aefe24b61eb19583710e96a988f77595ca2db6 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Fri, 20 Nov 2026 00:29:42 +1100 Subject: [PATCH 01/13] 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 02/13] 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 03/13] 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 04/13] 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 05/13] 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 06/13] 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 07/13] 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 08/13] 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; } ''' From 161cf31f320fb1e7d4726a94fb46ba8f89b93256 Mon Sep 17 00:00:00 2001 From: Diljit Singh Date: Thu, 19 Nov 2026 10:53:37 -0500 Subject: [PATCH 09/13] phy: apple: atc: serve a T8132 device role on USB2 T8132 has no SuperSpeed device mode, and atcphy refuses a device role on a port whose lanes run USB3: atcphy_usb3_set_mode() returns -EOPNOTSUPP, dwc3-apple fails the role ("USB3 PHY setup failed, err=-95") and the port controller's revalidation gives up. Before the boot loader passed the T8132 USB3 calibration these ports ran USB2 only, and the same device role worked there. So a Mac mini (J773g) rear port that a host connects to as a device lost its USB when the calibration arrived. Serve the device role on USB2 instead: when the controller asks for the device role on a calibrated T8132 port, switch its lanes to the USB2 mode (four-lane DisplayPort keeps its own USB2 wires) and keep them there for later mux updates while the device role holds. The host role, and the partner leaving (safe state), lift that again. Signed-off-by: Diljit Singh --- drivers/phy/apple/atc-test.c | 31 ++++++++++++++++++++++ drivers/phy/apple/atc.c | 51 +++++++++++++++++++++++++++++++++--- 2 files changed, 78 insertions(+), 4 deletions(-) diff --git a/drivers/phy/apple/atc-test.c b/drivers/phy/apple/atc-test.c index 09eec7f9d6185..3f32a314171ff 100644 --- a/drivers/phy/apple/atc-test.c +++ b/drivers/phy/apple/atc-test.c @@ -104,6 +104,36 @@ static void atcphy_test_target_mode_t8132(struct kunit *test) KUNIT_EXPECT_EQ(test, atcphy_typec_target_mode(atcphy, &state), APPLE_ATCPHY_MODE_OFF); } +/* T8132 has no SuperSpeed device mode: a device role keeps the lanes on USB2. */ +static void atcphy_test_t8132_device_role_usb2(struct kunit *test) +{ + struct typec_altmode dp = { .svid = USB_TYPEC_DP_SID }; + struct typec_mux_state state = { .mode = TYPEC_STATE_USB }; + struct apple_atcphy *atcphy = atcphy_test_alloc_dev(test, false); + + atcphy->hw = &atcphy_hw_t8132; + atcphy->t8132_ss = true; + atcphy->ss_tunables = true; + KUNIT_EXPECT_EQ(test, atcphy_typec_target_mode(atcphy, &state), APPLE_ATCPHY_MODE_USB3); + atcphy->t8132_device = true; + KUNIT_EXPECT_EQ(test, atcphy_typec_target_mode(atcphy, &state), APPLE_ATCPHY_MODE_USB2); + state.alt = &dp; + state.mode = TYPEC_DP_STATE_D; + KUNIT_EXPECT_EQ(test, atcphy_typec_target_mode(atcphy, &state), APPLE_ATCPHY_MODE_USB2); + KUNIT_EXPECT_EQ(test, atcphy_t8132_device_mode(atcphy, APPLE_ATCPHY_MODE_USB3_DP), + APPLE_ATCPHY_MODE_USB2); + atcphy->t8132_dp_alt = true; + KUNIT_EXPECT_EQ(test, atcphy_t8132_device_mode(atcphy, APPLE_ATCPHY_MODE_USB3_DP), + APPLE_ATCPHY_MODE_DP); + KUNIT_EXPECT_EQ(test, atcphy_t8132_device_mode(atcphy, APPLE_ATCPHY_MODE_DP), + APPLE_ATCPHY_MODE_DP); + KUNIT_EXPECT_EQ(test, atcphy_t8132_device_mode(atcphy, APPLE_ATCPHY_MODE_OFF), + APPLE_ATCPHY_MODE_OFF); + state.alt = NULL; + state.mode = TYPEC_STATE_SAFE; + KUNIT_EXPECT_EQ(test, atcphy_typec_target_mode(atcphy, &state), APPLE_ATCPHY_MODE_OFF); +} + static void atcphy_test_noop_same_mode(struct kunit *test) { struct apple_atcphy *atcphy = atcphy_test_alloc(test, true); @@ -1391,6 +1421,7 @@ static struct kunit_case atcphy_mux_test_cases[] = { KUNIT_CASE(atcphy_test_target_mode), KUNIT_CASE(atcphy_test_target_mode_fixed_hub), KUNIT_CASE(atcphy_test_target_mode_t8132), + KUNIT_CASE(atcphy_test_t8132_device_role_usb2), KUNIT_CASE(atcphy_test_noop_same_mode), KUNIT_CASE(atcphy_test_noop_needs_work), KUNIT_CASE(atcphy_test_usb3_port_ready), diff --git a/drivers/phy/apple/atc.c b/drivers/phy/apple/atc.c index 820e7f3eca6f6..fe0ab3c83ef5a 100644 --- a/drivers/phy/apple/atc.c +++ b/drivers/phy/apple/atc.c @@ -881,6 +881,12 @@ struct apple_atcphy { const struct atcphy_hw *hw; /* T8132 keeps USB2 support when its optional SuperSpeed banks are absent. */ bool t8132_ss; + /* + * T8132 has no SuperSpeed device mode: while the controller holds the + * device role, the lanes run the USB2 mode the partner's USB3 mode + * would otherwise take. Cleared by the host role and the safe state. + */ + bool t8132_device; /* Only this driver's admitted common-power epoch may be stopped. */ bool t8132_common_owned; /* A touched failure has no qualified partial rollback or retry. */ @@ -3620,6 +3626,21 @@ static bool atcphy_t8132_dp_on(const struct apple_atcphy *atcphy) return atcphy->hw->gen == ATCPHY_GENERATION_T8132 && atcphy->t8132_dp_alt; } +/* + * The mode a T8132 port runs in while its controller is a USB device: the + * same lanes without SuperSpeed. USB2 stays on its own wires next to + * four-lane DisplayPort. + */ +static enum atcphy_mode atcphy_t8132_device_mode(const struct apple_atcphy *atcphy, + enum atcphy_mode mode) +{ + if (mode == APPLE_ATCPHY_MODE_USB3) + return APPLE_ATCPHY_MODE_USB2; + if (mode == APPLE_ATCPHY_MODE_USB3_DP) + return atcphy_t8132_dp_on(atcphy) ? APPLE_ATCPHY_MODE_DP : APPLE_ATCPHY_MODE_USB2; + return mode; +} + /* * The T8132 lane start differs from the T8122 one: both blocks start at swing * 0 / pre-emphasis 0, the RX block's VREF filter is held until both DTVREG @@ -4722,6 +4743,8 @@ static int atcphy_usb3_route(struct apple_atcphy *atcphy, bool host) return atcphy_configure_pipehandler(atcphy, host); } +static int atcphy_mux_switch(struct apple_atcphy *atcphy, enum atcphy_mode target_mode); + static int atcphy_usb3_set_mode(struct phy *phy, enum phy_mode mode, int submode) { struct apple_atcphy *atcphy = phy_get_drvdata(phy); @@ -4733,10 +4756,25 @@ static int atcphy_usb3_set_mode(struct phy *phy, enum phy_mode mode, int submode if (atcphy->usb_off_pending) return -EBUSY; - if (atcphy->t8132_ss && - (atcphy->mode == APPLE_ATCPHY_MODE_USB3 || atcphy->mode == APPLE_ATCPHY_MODE_USB3_DP) && - mode == PHY_MODE_USB_DEVICE) - return -EOPNOTSUPP; + if (atcphy->t8132_ss && mode == PHY_MODE_USB_DEVICE) { + enum atcphy_mode usb2 = atcphy_t8132_device_mode(atcphy, atcphy->mode); + + /* + * No SuperSpeed device mode: serve the device role on USB2, as + * the port did without its USB3 calibration, instead of failing + * the role. Later mux updates keep USB2 (t8132_device). + */ + atcphy->t8132_device = true; + if (usb2 != atcphy->mode) { + dev_info(atcphy->dev, "USB device role: no SuperSpeed device mode, using USB2\n"); + ret = atcphy_mux_switch(atcphy, usb2); + if (ret) + return ret; + } + } else if (mode == PHY_MODE_USB_HOST) { + /* The lanes regain USB3 with the next mux update (a data role swap). */ + atcphy->t8132_device = false; + } switch (mode) { case PHY_MODE_USB_HOST: @@ -5794,6 +5832,8 @@ static enum atcphy_mode atcphy_typec_target_mode(struct apple_atcphy *atcphy, "DisplayPort is not available on this port: serving its USB only\n"); target_mode = usb_mode; } + if (atcphy->t8132_device) + target_mode = atcphy_t8132_device_mode(atcphy, target_mode); } /* @@ -5918,6 +5958,9 @@ static int atcphy_mux_switch(struct apple_atcphy *atcphy, enum atcphy_mode targe int ret; lockdep_assert_held(&atcphy->lock); + /* The partner is gone: the next one starts without the device-role USB2 limit. */ + if (target_mode == APPLE_ATCPHY_MODE_OFF) + atcphy->t8132_device = false; if (atcphy->t8103_dummy_pending) { ret = atcphy_park_live_t8103_pipehandler(atcphy); if (ret) From 96c77e9d9cccd25002efe7b46f5cc168bd2430ab Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Fri, 20 Nov 2026 08:11:23 +1100 Subject: [PATCH 10/13] phy: apple: atc: key the USB2 device role on a no-SuperSpeed-device capability The previous commit serves a T8132 device role on USB2 because that PHY has no SuperSpeed device mode. Describe that as what it is, a property of the PHY in its match data (no_ss_device), instead of the T8132 banks: the device-role USB2 limit (now usb2_device) applies to any ATC PHY with the flag, and the mux update keeps it outside the T8132 block. Also let the USB3 PHY answer .validate: host always, device unless the PHY has no SuperSpeed device mode. That is how dwc3-apple learns that it has to run as a high-speed device: its device speed and the USB2 clock for its USB3 logic are controller settings no PHY can make. Only T8132 sets the flag; every other ATC generation keeps its SuperSpeed device. Signed-off-by: Ryan Murray --- drivers/phy/apple/atc-test.c | 29 ++++++++++++++---- drivers/phy/apple/atc.c | 57 ++++++++++++++++++++++++++---------- 2 files changed, 65 insertions(+), 21 deletions(-) diff --git a/drivers/phy/apple/atc-test.c b/drivers/phy/apple/atc-test.c index 3f32a314171ff..00249d849feab 100644 --- a/drivers/phy/apple/atc-test.c +++ b/drivers/phy/apple/atc-test.c @@ -115,25 +115,43 @@ static void atcphy_test_t8132_device_role_usb2(struct kunit *test) atcphy->t8132_ss = true; atcphy->ss_tunables = true; KUNIT_EXPECT_EQ(test, atcphy_typec_target_mode(atcphy, &state), APPLE_ATCPHY_MODE_USB3); - atcphy->t8132_device = true; + atcphy->usb2_device = true; KUNIT_EXPECT_EQ(test, atcphy_typec_target_mode(atcphy, &state), APPLE_ATCPHY_MODE_USB2); state.alt = &dp; state.mode = TYPEC_DP_STATE_D; KUNIT_EXPECT_EQ(test, atcphy_typec_target_mode(atcphy, &state), APPLE_ATCPHY_MODE_USB2); - KUNIT_EXPECT_EQ(test, atcphy_t8132_device_mode(atcphy, APPLE_ATCPHY_MODE_USB3_DP), + KUNIT_EXPECT_EQ(test, atcphy_usb2_device_mode(atcphy, APPLE_ATCPHY_MODE_USB3_DP), APPLE_ATCPHY_MODE_USB2); atcphy->t8132_dp_alt = true; - KUNIT_EXPECT_EQ(test, atcphy_t8132_device_mode(atcphy, APPLE_ATCPHY_MODE_USB3_DP), + KUNIT_EXPECT_EQ(test, atcphy_usb2_device_mode(atcphy, APPLE_ATCPHY_MODE_USB3_DP), APPLE_ATCPHY_MODE_DP); - KUNIT_EXPECT_EQ(test, atcphy_t8132_device_mode(atcphy, APPLE_ATCPHY_MODE_DP), + KUNIT_EXPECT_EQ(test, atcphy_usb2_device_mode(atcphy, APPLE_ATCPHY_MODE_DP), APPLE_ATCPHY_MODE_DP); - KUNIT_EXPECT_EQ(test, atcphy_t8132_device_mode(atcphy, APPLE_ATCPHY_MODE_OFF), + KUNIT_EXPECT_EQ(test, atcphy_usb2_device_mode(atcphy, APPLE_ATCPHY_MODE_OFF), APPLE_ATCPHY_MODE_OFF); state.alt = NULL; state.mode = TYPEC_STATE_SAFE; KUNIT_EXPECT_EQ(test, atcphy_typec_target_mode(atcphy, &state), APPLE_ATCPHY_MODE_OFF); } +/* .validate tells dwc3-apple whether the USB3 PHY can carry a SuperSpeed device. */ +static void atcphy_test_usb3_validate_device(struct kunit *test) +{ + struct apple_atcphy *atcphy = atcphy_test_alloc_dev(test, false); + struct phy *phy = kunit_kzalloc(test, sizeof(*phy), GFP_KERNEL); + + KUNIT_ASSERT_NOT_NULL(test, phy); + dev_set_drvdata(&phy->dev, atcphy); + atcphy->hw = &atcphy_hw_t8132; + KUNIT_EXPECT_EQ(test, atcphy_usb3_validate(phy, PHY_MODE_USB_HOST, 0, NULL), 0); + KUNIT_EXPECT_EQ(test, atcphy_usb3_validate(phy, PHY_MODE_USB_DEVICE, 0, NULL), -EOPNOTSUPP); + atcphy->hw = &atcphy_hw_t8122; + KUNIT_EXPECT_EQ(test, atcphy_usb3_validate(phy, PHY_MODE_USB_DEVICE, 0, NULL), 0); + atcphy->hw = &atcphy_hw_t8103; + KUNIT_EXPECT_EQ(test, atcphy_usb3_validate(phy, PHY_MODE_USB_DEVICE, 0, NULL), 0); + KUNIT_EXPECT_EQ(test, atcphy_usb3_validate(phy, PHY_MODE_DP, 0, NULL), -EOPNOTSUPP); +} + static void atcphy_test_noop_same_mode(struct kunit *test) { struct apple_atcphy *atcphy = atcphy_test_alloc(test, true); @@ -1422,6 +1440,7 @@ static struct kunit_case atcphy_mux_test_cases[] = { KUNIT_CASE(atcphy_test_target_mode_fixed_hub), KUNIT_CASE(atcphy_test_target_mode_t8132), KUNIT_CASE(atcphy_test_t8132_device_role_usb2), + KUNIT_CASE(atcphy_test_usb3_validate_device), KUNIT_CASE(atcphy_test_noop_same_mode), KUNIT_CASE(atcphy_test_noop_needs_work), KUNIT_CASE(atcphy_test_usb3_port_ready), diff --git a/drivers/phy/apple/atc.c b/drivers/phy/apple/atc.c index fe0ab3c83ef5a..3d2c65272d8a7 100644 --- a/drivers/phy/apple/atc.c +++ b/drivers/phy/apple/atc.c @@ -704,6 +704,10 @@ struct apple_atcphy; * can also drop while the system runs, see atcphy_rpm_get(). * Only for PHYs without DisplayPort, whose phy ops and tunnel * calls take no runtime PM reference + * @no_ss_device: No SuperSpeed device mode. .validate refuses PHY_MODE_USB_DEVICE + * on the USB3 PHY, so that the controller sets itself up as a + * high-speed device, and a device role keeps the lanes off USB3 + * (usb2_device in struct apple_atcphy) */ struct atcphy_hw { void (*configure_post_tunable)(struct apple_atcphy *, enum atcphy_mode); @@ -725,6 +729,7 @@ struct atcphy_hw { bool clear_boot_hold; bool restore_after_pd_off; bool idle_power_off; + bool no_ss_device; }; enum atcphy_t8132_bank { @@ -882,11 +887,11 @@ struct apple_atcphy { /* T8132 keeps USB2 support when its optional SuperSpeed banks are absent. */ bool t8132_ss; /* - * T8132 has no SuperSpeed device mode: while the controller holds the - * device role, the lanes run the USB2 mode the partner's USB3 mode - * would otherwise take. Cleared by the host role and the safe state. + * No SuperSpeed device mode (hw->no_ss_device): while the controller + * holds the device role, the lanes run the USB2 mode the partner's USB3 + * mode would otherwise take. Cleared by the host role and the safe state. */ - bool t8132_device; + bool usb2_device; /* Only this driver's admitted common-power epoch may be stopped. */ bool t8132_common_owned; /* A touched failure has no qualified partial rollback or retry. */ @@ -3627,11 +3632,11 @@ static bool atcphy_t8132_dp_on(const struct apple_atcphy *atcphy) } /* - * The mode a T8132 port runs in while its controller is a USB device: the - * same lanes without SuperSpeed. USB2 stays on its own wires next to - * four-lane DisplayPort. + * The mode a port without SuperSpeed device mode runs in while its controller + * is a USB device: the same lanes without SuperSpeed. USB2 stays on its own + * wires next to four-lane DisplayPort. */ -static enum atcphy_mode atcphy_t8132_device_mode(const struct apple_atcphy *atcphy, +static enum atcphy_mode atcphy_usb2_device_mode(const struct apple_atcphy *atcphy, enum atcphy_mode mode) { if (mode == APPLE_ATCPHY_MODE_USB3) @@ -4756,15 +4761,16 @@ static int atcphy_usb3_set_mode(struct phy *phy, enum phy_mode mode, int submode if (atcphy->usb_off_pending) return -EBUSY; - if (atcphy->t8132_ss && mode == PHY_MODE_USB_DEVICE) { - enum atcphy_mode usb2 = atcphy_t8132_device_mode(atcphy, atcphy->mode); + if (atcphy->hw->no_ss_device && mode == PHY_MODE_USB_DEVICE) { + enum atcphy_mode usb2 = atcphy_usb2_device_mode(atcphy, atcphy->mode); /* * No SuperSpeed device mode: serve the device role on USB2, as * the port did without its USB3 calibration, instead of failing - * the role. Later mux updates keep USB2 (t8132_device). + * the role. Later mux updates keep USB2 (usb2_device). Without + * the T8132 SuperSpeed banks the lanes never leave USB2. */ - atcphy->t8132_device = true; + atcphy->usb2_device = true; if (usb2 != atcphy->mode) { dev_info(atcphy->dev, "USB device role: no SuperSpeed device mode, using USB2\n"); ret = atcphy_mux_switch(atcphy, usb2); @@ -4773,7 +4779,7 @@ static int atcphy_usb3_set_mode(struct phy *phy, enum phy_mode mode, int submode } } else if (mode == PHY_MODE_USB_HOST) { /* The lanes regain USB3 with the next mux update (a data role swap). */ - atcphy->t8132_device = false; + atcphy->usb2_device = false; } switch (mode) { @@ -4856,8 +4862,26 @@ static int atcphy_rpm_usb3_set_mode(struct phy *phy, enum phy_mode mode, int sub return ret; } +/* + * Both roles, except a device role on a PHY without SuperSpeed device mode: + * atcphy_usb3_set_mode() serves that one on USB2, and the controller must run + * as a high-speed device. + */ +static int atcphy_usb3_validate(struct phy *phy, enum phy_mode mode, int submode, + union phy_configure_opts *opts) +{ + struct apple_atcphy *atcphy = phy_get_drvdata(phy); + + if (mode == PHY_MODE_USB_HOST) + return 0; + if (mode == PHY_MODE_USB_DEVICE) + return atcphy->hw->no_ss_device ? -EOPNOTSUPP : 0; + return -EOPNOTSUPP; +} + static const struct phy_ops apple_atc_usb3_phy_ops = { .owner = THIS_MODULE, + .validate = atcphy_usb3_validate, .exit = atcphy_usb3_exit, .power_off = atcphy_rpm_usb3_power_off, .set_mode = atcphy_rpm_usb3_set_mode, @@ -5832,9 +5856,9 @@ static enum atcphy_mode atcphy_typec_target_mode(struct apple_atcphy *atcphy, "DisplayPort is not available on this port: serving its USB only\n"); target_mode = usb_mode; } - if (atcphy->t8132_device) - target_mode = atcphy_t8132_device_mode(atcphy, target_mode); } + if (atcphy->usb2_device) + target_mode = atcphy_usb2_device_mode(atcphy, target_mode); /* * T8142 runs DisplayPort only with the boot loader's LIOA and common @@ -5960,7 +5984,7 @@ static int atcphy_mux_switch(struct apple_atcphy *atcphy, enum atcphy_mode targe lockdep_assert_held(&atcphy->lock); /* The partner is gone: the next one starts without the device-role USB2 limit. */ if (target_mode == APPLE_ATCPHY_MODE_OFF) - atcphy->t8132_device = false; + atcphy->usb2_device = false; if (atcphy->t8103_dummy_pending) { ret = atcphy_park_live_t8103_pipehandler(atcphy); if (ret) @@ -7998,6 +8022,7 @@ static const struct atcphy_hw atcphy_hw_t8122 = { static const struct atcphy_hw atcphy_hw_t8132 = { .gen = ATCPHY_GENERATION_T8132, .usb2_only = true, + .no_ss_device = true, .usb2phy_sig_host = USB2PHY_SIG_HOST_T8132, .pipe_mux_clk = PIPEHANDLER_MUX_CTRL_CLK_T8103, .pipe_mux_data = PIPEHANDLER_MUX_CTRL_DATA_T8103, From de483e181d9e949ea7f66e3217ccd605a8f5d835 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Fri, 20 Nov 2026 08:11:35 +1100 Subject: [PATCH 11/13] phy: apple: t6040-usb2: say there is no SuperSpeed device mode in .validate The USB3 PHY has no device sequence, which it reported by failing set_mode for a device role. Report it through .validate instead, as the ATC PHYs now do, and accept the device role in set_mode: it runs on USB2, with the PIPE left parked on its dummy producer where power_off put it. dwc3-apple then sets up the high-speed device from the capability rather than from an error. Signed-off-by: Ryan Murray --- drivers/phy/apple/t6040-usb2.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/drivers/phy/apple/t6040-usb2.c b/drivers/phy/apple/t6040-usb2.c index 3387319144a04..886574809923e 100644 --- a/drivers/phy/apple/t6040-usb2.c +++ b/drivers/phy/apple/t6040-usb2.c @@ -1246,14 +1246,18 @@ static int t6040_usb3_power_off(struct phy *phy) } /* - * Host only. dwc3-apple calls this after the core init and before xHCI + * dwc3-apple calls this after the core init and before xHCI or the gadget * starts; the xHCI root hub calls it again as it starts, also for a port - * that stays at USB2, which must not fail. + * that stays at USB2, which must not fail. There is no SuperSpeed device + * sequence (t6040_usb3_validate()): a device role runs on USB2 and leaves + * the PIPE parked on its dummy producer, where power_off put it. */ static int t6040_usb3_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_DEVICE) + return 0; if (mode != PHY_MODE_USB_HOST && mode != PHY_MODE_USB_HOST_SS) return -EOPNOTSUPP; @@ -1267,8 +1271,16 @@ static int t6040_usb3_set_mode(struct phy *phy, enum phy_mode mode, int submode) return 0; } +/* SuperSpeed host only: dwc3-apple runs a device role as a high-speed device. */ +static int t6040_usb3_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_HOST_SS ? 0 : -EOPNOTSUPP; +} + static const struct phy_ops t6040_usb3_phy_ops = { .owner = THIS_MODULE, + .validate = t6040_usb3_validate, .set_mode = t6040_usb3_set_mode, .power_on = t6040_usb3_power_on, .power_off = t6040_usb3_power_off, From bcf197a39ddeba45b1d48dc593229611248ac593 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Fri, 20 Nov 2026 08:16:17 +1100 Subject: [PATCH 12/13] usb: dwc3: apple: high-speed gadget from the USB3 PHY's device capability The USB3 PHYs now say in .validate whether they can carry a SuperSpeed device (T8132 and T6040 cannot), and route their lanes for a device role on USB2 when they cannot. Set the high-speed gadget up from that answer, before phy_set_mode(), instead of from a set_mode error. This stays in the glue because the device speed and the USB2 clock for the USB3 logic are controller settings no PHY can make; the PHY decides, the glue applies it. No USB3 PHY at all is the same case. A set_mode -EOPNOTSUPP for a device role still means high speed: an ATC port can lack SuperSpeed on one connection (a T8103 port whose lanes are all DisplayPort, or without SuperSpeed tunables). The T6040 PIPE reset stays with the host role; a device role leaves the PIPE parked. Signed-off-by: Ryan Murray --- drivers/usb/dwc3/dwc3-apple.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/drivers/usb/dwc3/dwc3-apple.c b/drivers/usb/dwc3/dwc3-apple.c index 0eb29df7003fb..9634b6ac4fde1 100644 --- a/drivers/usb/dwc3/dwc3-apple.c +++ b/drivers/usb/dwc3/dwc3-apple.c @@ -924,8 +924,9 @@ static void dwc3_apple_usb3_pipe_reset(struct dwc3_apple *appledwc) } /* - * 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. + * Without a USB3 PHY that runs as a device (no USB3 PHY, or one that does not validate + * PHY_MODE_USB_DEVICE) 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) { @@ -963,12 +964,22 @@ 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); + /* + * Two layers, one decision: the USB3 PHY says whether it can carry a SuperSpeed device + * (.validate; T8132 and T6040 cannot) and routes its lanes for the role in phy_set_mode(), + * on USB2 when it cannot. The core then has to run as a high-speed device, because its + * device speed and the USB2 clock for its USB3 logic are controller settings that no PHY + * can make. No USB3 PHY at all is the same case. + */ + if (!host && (!appledwc->usb3_phy || + phy_validate(appledwc->usb3_phy, PHY_MODE_USB_DEVICE, 0, NULL))) + dwc3_apple_gadget_high_speed(appledwc); ret = phy_set_mode(appledwc->usb3_phy, host ? PHY_MODE_USB_HOST : PHY_MODE_USB_DEVICE); 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. + * The PHY cannot carry a SuperSpeed device on this connection (a T8103 port whose + * lanes are all DisplayPort or that has no SuperSpeed tunables) and has left the + * PIPE alone: high speed as well, whatever the SoC. */ dwc3_apple_gadget_high_speed(appledwc); } else if (ret) { @@ -992,11 +1003,10 @@ static int dwc3_apple_set_role(struct dwc3_apple *appledwc, enum dwc3_apple_stat */ appledwc->dwc.dis_u3_susphy_quirk = true; dwc3_enable_susphy(&appledwc->dwc, true); - } else if (appledwc->usb3_phy && + } else if (host && appledwc->usb3_phy && of_device_is_compatible(appledwc->dev->of_node, "apple,t6040-dwc3")) { + /* A device role leaves the PIPE parked: nothing moved, nothing to reset. */ dwc3_apple_usb3_pipe_reset(appledwc); - } else if (!host && !appledwc->usb3_phy) { - dwc3_apple_gadget_high_speed(appledwc); } return 0; } From 477075d63514c1c86855cd1ea659fde0ee6e49ae Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Fri, 20 Nov 2026 08:37:13 +1100 Subject: [PATCH 13/13] tools: host models for the ATC device-role USB2 limit The ATC USB3 harness and the apple-dcp PHY, quiesce and dwc3 models compile atc.c functions against their own structs. The device role on a PHY without SuperSpeed device mode added a struct member (usb2_device), a helper (atcphy_usb2_device_mode()), a forward declaration of atcphy_mux_switch() and a dev_info() call, so they stopped building, including on linux#2434 alone. Add the member, extract the helper, emit the prototype and stub dev_info as the harnesses do for their neighbours, and check in the USB3 harness that a T8132 device role maps a USB partner to USB2 (and back to USB3 once the role is gone) while four-lane DisplayPort stays DisplayPort. Signed-off-by: Ryan Murray --- tools/asahi/atc-usb3-tests.py | 16 +++++++++++++++- .../selftests/drivers/gpu/apple-dcp/common.py | 14 ++++++++++++-- .../selftests/drivers/gpu/apple-dcp/dwc3/mocks.c | 2 ++ .../drivers/gpu/apple-dcp/dwc3/prefix.c | 1 + .../selftests/drivers/gpu/apple-dcp/phy.py | 11 +++++++++++ .../selftests/drivers/gpu/apple-dcp/quiesce.py | 1 + 6 files changed, 42 insertions(+), 3 deletions(-) diff --git a/tools/asahi/atc-usb3-tests.py b/tools/asahi/atc-usb3-tests.py index 3a7955197c9f9..8b67ddb432f97 100644 --- a/tools/asahi/atc-usb3-tests.py +++ b/tools/asahi/atc-usb3-tests.py @@ -63,6 +63,7 @@ def block(source, marker): #define dev_warn(...) ((void)reports++) #define dev_err(...) ((void)reports++) #define dev_dbg(...) ((void)0) +#define dev_info(...) ((void)0) #define lockdep_assert_held(...) ((void)0) #define guard(which) (void) #define IS_ENABLED(x) 0 @@ -78,7 +79,7 @@ def block(source, marker): STUBS = r''' struct atcphy_hw { enum atcphy_generation gen; bool has_t8140_dp, dp_t8122, has_usb4, park_pipe_unlocked, park_dummy_phy, usb2_only; - bool clear_boot_hold, dp_banked_tunables; }; + bool clear_boot_hold, dp_banked_tunables, no_ss_device; }; struct device_node { const char *const *compatible; unsigned int count; }; static bool of_device_is_compatible(const struct device_node *root, const char *compatible) { if (!root) return false; @@ -101,6 +102,8 @@ def block(source, marker): bool host_active, usb3_port_off, dp_only, ss_tunables, fixed_usb2, t8140_dp_tunables, dp_tunables; /* T8132 ownership is tested without entering its lane-setup backend. */ bool t8132_ss, t8132_common_owned, t8132_failed, cio_tunables, t8132_dp_alt; + /* Device role on a PHY without SuperSpeed device mode (hw->no_ss_device). */ + bool usb2_device; struct { void *usb3_dp; } tunables; }; struct phy { struct apple_atcphy *data; }; @@ -432,6 +435,14 @@ def block(source, marker): /* T8132: 4-lane DP stays DP only on a port marked apple,dp-alt-mode. */ hw.gen=ATCPHY_GENERATION_T8132;assert(atcphy_typec_target_mode(&p,&state)==APPLE_ATCPHY_MODE_USB2); p.t8132_dp_alt=true;assert(atcphy_typec_target_mode(&p,&state)==APPLE_ATCPHY_MODE_DP); + /* T8132 device role (no SuperSpeed device mode): USB3 lanes run USB2, 4-lane DP stays. */ + hw.no_ss_device=true;p.usb2_device=true;p.tunables.usb3_dp=&p; + assert(atcphy_typec_target_mode(&p,&state)==APPLE_ATCPHY_MODE_DP);state.mode=TYPEC_DP_STATE_D; + assert(atcphy_typec_target_mode(&p,&state)==APPLE_ATCPHY_MODE_DP);p.t8132_dp_alt=false; + assert(atcphy_typec_target_mode(&p,&state)==APPLE_ATCPHY_MODE_USB2); + state.mode=TYPEC_STATE_USB;state.alt=NULL;assert(atcphy_typec_target_mode(&p,&state)==APPLE_ATCPHY_MODE_USB2); + p.usb2_device=false;assert(atcphy_typec_target_mode(&p,&state)==APPLE_ATCPHY_MODE_USB3); + hw.no_ss_device=false;p.tunables.usb3_dp=NULL;state.alt=&alt;state.mode=TYPEC_DP_STATE_C; hw.gen=ATCPHY_GENERATION_T8103;p.t8132_dp_alt=false; p.mode=APPLE_ATCPHY_MODE_USB3;p.mode_dirty=true;assert(atcphy_usb3_route(&p,true)==-EBUSY);assert(!muxes&&!configure_calls); p.mode_dirty=false;p.usb_off_pending=true;assert(atcphy_usb3_set_mode(&phy,PHY_MODE_USB_HOST,0)==-EBUSY); @@ -717,6 +728,9 @@ def harness(source): # The PIPE backend of a mode, which T8132 CIO keeps on the dummy one. helpers = [block(source, "static bool atcphy_mode_is_cio("), block(source, "static bool atcphy_t8132_dp_on("), + block(source, "static enum atcphy_mode atcphy_usb2_device_mode("), + # atcphy_usb3_set_mode() calls atcphy_mux_switch() before its definition. + "static int atcphy_mux_switch(struct apple_atcphy *atcphy, enum atcphy_mode target_mode);", block(source, "static enum atcphy_pipehandler_state\natcphy_pipe_state_for(")] functions = "\n".join(helpers + [block(source, "static " + kind + " " + name + "(") for kind, name in function_specs]) diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/common.py b/tools/testing/selftests/drivers/gpu/apple-dcp/common.py index 980a7a8773b97..ae06ce8ef97f6 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/common.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/common.py @@ -177,20 +177,30 @@ def atc_function(source, name): def atc_cio_helpers(source): """The PIPE backend of a mode, which T8132 CIO keeps on the dummy one, and - whether a T8132 port is wired for DP alt mode. + whether a T8132 port is wired for DP alt mode, and the USB2 mode of a device + role without SuperSpeed device mode. The mux and PIPE functions call these; older sources have none: ''. """ result = '' for name in ('atcphy_mode_is_cio', 'atcphy_pipe_state_for', - 'atcphy_usb2_sig_host', 'atcphy_t8132_dp_on'): + 'atcphy_usb2_sig_host', 'atcphy_t8132_dp_on', 'atcphy_usb2_device_mode'): marker = re.search(r'^static [^;{}()]+\b' + name + r'\([^;{}]*\)\s*\{', source, re.M) if marker: helper = block(source, marker.start()) if name == 'atcphy_usb2_sig_host': helper = helper.replace('static u32', 'static __attribute__((unused)) u32', 1) + if name == 'atcphy_usb2_device_mode': + # Only units with the mux mapping or the USB3 set_mode call it. + helper = helper.replace('static enum', + 'static __attribute__((unused)) enum', 1) result += helper + '\n' + # atcphy_usb3_set_mode() serves a no-SuperSpeed-device role on USB2 through + # atcphy_mux_switch(), which the source defines further down. + prototype = re.search(r'^static int atcphy_mux_switch\([^;{}]*\);', source, re.M) + if prototype: + result += prototype.group() + '\n' return result 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 96ba1169f4840..cc1b1ec8f91c2 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/dwc3/mocks.c +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/dwc3/mocks.c @@ -4,6 +4,8 @@ struct apple_atcphy { /* T8132-only paths are covered by drivers/apple/atc-t8132-usb3.py. */ bool t8132_ss, t8132_common_owned, t8132_failed, cio_tunables, t8132_dp_alt; + /* A device role without SuperSpeed device mode runs on USB2 (hw->no_ss_device). */ + bool usb2_device; /* A CIO sleep is T8132's too, covered by tools/asahi/atc-cio-sleep-tests.py. */ struct { bool prepared; diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/dwc3/prefix.c b/tools/testing/selftests/drivers/gpu/apple-dcp/dwc3/prefix.c index 8c0bfb426e8a0..36b5272fc4f3f 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/dwc3/prefix.c +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/dwc3/prefix.c @@ -30,6 +30,7 @@ static void warning(const char *message) #define dev_warn(d, message, ...) warning(message) #define dev_err(...) ((void)0) #define dev_dbg(...) ((void)0) +#define dev_info(...) ((void)0) #define lockdep_assert_held(p) assert(*(p)) #define WARN_ON_ONCE(v) assert(!(v)) static void mutex_lock(int *m) diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/phy.py b/tools/testing/selftests/drivers/gpu/apple-dcp/phy.py index 26c0f62dabb25..cc98625d65cd0 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/phy.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/phy.py @@ -35,6 +35,8 @@ def function(source, name): struct apple_atcphy { /* T8132-only paths are covered by drivers/apple/atc-t8132-usb3.py. */ bool t8132_ss, t8132_common_owned, t8132_failed, cio_tunables, t8132_dp_alt; + /* A device role without SuperSpeed device mode runs on USB2 (hw->no_ss_device). */ + bool usb2_device; /* A CIO sleep is T8132's too, covered by tools/asahi/atc-cio-sleep-tests.py. */ struct { bool prepared; } cio_sleep; struct { void *usb3_dp, *dp_lioa, *dp_common_config; } tunables; @@ -224,6 +226,7 @@ def function(source, name): #define hweight32(v) __builtin_popcount(v) #define dev_info_once(...) ((void)0) #define dev_dbg(...) ((void)0) +#define dev_info(...) ((void)0) #define dev_warn(...) ((void)0) static void report(void *dev, const char *fmt, ...) { (void)dev; (void)fmt; } #define dev_err report @@ -1937,6 +1940,8 @@ def function(name): struct apple_atcphy { /* T8132-only paths are covered by drivers/apple/atc-t8132-usb3.py. */ bool t8132_ss, t8132_common_owned, t8132_failed, cio_tunables, t8132_dp_alt; + /* A device role without SuperSpeed device mode runs on USB2 (hw->no_ss_device). */ + bool usb2_device; /* A CIO sleep is T8132's too, covered by tools/asahi/atc-cio-sleep-tests.py. */ struct { bool prepared; } cio_sleep; struct { void *usb3_dp, *dp_lioa, *dp_common_config; } tunables; @@ -2047,6 +2052,7 @@ def function(name): #define FIELD_GET(m, v) (((v) & (m)) >> __builtin_ctz(m)) #define field_prep FIELD_PREP #define dev_dbg(...) ((void)0) +#define dev_info(...) ((void)0) #define dev_warn(...) ((void)0) #define dev_err(...) ((void)0) #define lockdep_assert_held(...) ((void)0) @@ -2337,6 +2343,8 @@ def function(source, name): struct apple_atcphy { /* T8132-only paths are covered by drivers/apple/atc-t8132-usb3.py. */ bool t8132_ss, t8132_common_owned, t8132_failed, cio_tunables, t8132_dp_alt; + /* A device role without SuperSpeed device mode runs on USB2 (hw->no_ss_device). */ + bool usb2_device; /* A CIO sleep is T8132's too, covered by tools/asahi/atc-cio-sleep-tests.py. */ struct { bool prepared; } cio_sleep; struct { void *usb3_dp, *dp_lioa, *dp_common_config; } tunables; @@ -2467,6 +2475,7 @@ def function(source, name): #define hweight32(v) __builtin_popcount(v) #define dev_info_once(...) ((void)0) #define dev_dbg(...) ((void)0) +#define dev_info(...) ((void)0) #define dev_warn(...) ((void)0) static void report(void *dev, const char *fmt, ...) { (void)dev; (void)fmt; } #define dev_err report @@ -2662,6 +2671,8 @@ def aux(root): struct apple_atcphy { /* T8132-only paths are covered by drivers/apple/atc-t8132-usb3.py. */ bool t8132_ss, t8132_common_owned, t8132_failed, cio_tunables, t8132_dp_alt; + /* A device role without SuperSpeed device mode runs on USB2 (hw->no_ss_device). */ + bool usb2_device; /* A CIO sleep is T8132's too, covered by tools/asahi/atc-cio-sleep-tests.py. */ struct { bool prepared; } cio_sleep; struct { void *usb3_dp, *dp_lioa, *dp_common_config; } tunables; diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/quiesce.py b/tools/testing/selftests/drivers/gpu/apple-dcp/quiesce.py index 46c5bf457d02f..ddc3b46585a74 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/quiesce.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/quiesce.py @@ -157,6 +157,7 @@ def make_unit(source, parent=False, reference=None): const struct atcphy_hw *hw; struct { void *usb2phy; } regs; bool fixed_usb2,host_active,mode_dirty,pipe_pending,usb_off_pending,ss_tunables,dp_tunables,cio_tunables,t8132_dp_alt; + bool usb2_device; bool usb3_port_off,park_owed,dp_only,pd_was_off; bool t8103_dummy_pending,t8103_usb3_retry,t8103_usb3_workaround; enum atcphy_mode mode,typec_mode;