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 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, }; diff --git a/drivers/phy/apple/t6040-usb2.c b/drivers/phy/apple/t6040-usb2.c index 50d82116aac2d..3387319144a04 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,37 @@ 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_default); + want = t6040_usb2_sig_tunable(want, tphy->tunable_usb2_host); return want & T6040_USB2_SIG_INIT; } @@ -369,7 +408,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 +429,33 @@ 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). + */ + 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); + 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. + * 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); + } msleep(10); @@ -430,7 +489,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 +501,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 +510,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 +573,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, @@ -2327,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); @@ -2399,6 +2471,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 +2505,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 +2519,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)) diff --git a/drivers/usb/dwc3/dwc3-apple.c b/drivers/usb/dwc3/dwc3-apple.c index 4d9b4ac0d8346..0eb29df7003fb 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,26 @@ 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) +{ + 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"); +} + /* 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 +953,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 @@ -940,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 @@ -964,24 +995,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 +1029,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 +1869,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 +1889,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 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/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; } ''' 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)