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-test.c b/drivers/phy/apple/atc-test.c index 09eec7f9d6185..00249d849feab 100644 --- a/drivers/phy/apple/atc-test.c +++ b/drivers/phy/apple/atc-test.c @@ -104,6 +104,54 @@ 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->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_usb2_device_mode(atcphy, APPLE_ATCPHY_MODE_USB3_DP), + APPLE_ATCPHY_MODE_USB2); + atcphy->t8132_dp_alt = true; + KUNIT_EXPECT_EQ(test, atcphy_usb2_device_mode(atcphy, APPLE_ATCPHY_MODE_USB3_DP), + 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_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); @@ -1391,6 +1439,8 @@ 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_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 34d3aa12b8f4c..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 { @@ -881,6 +886,12 @@ struct apple_atcphy { const struct atcphy_hw *hw; /* T8132 keeps USB2 support when its optional SuperSpeed banks are absent. */ bool t8132_ss; + /* + * 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 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. */ @@ -3620,6 +3631,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 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_usb2_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 @@ -4612,9 +4638,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, }; @@ -4714,6 +4748,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); @@ -4725,10 +4761,26 @@ 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->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 (usb2_device). Without + * the T8132 SuperSpeed banks the lanes never leave USB2. + */ + 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); + 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->usb2_device = false; + } switch (mode) { case PHY_MODE_USB_HOST: @@ -4810,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, @@ -5787,6 +5857,8 @@ static enum atcphy_mode atcphy_typec_target_mode(struct apple_atcphy *atcphy, target_mode = usb_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 @@ -5910,6 +5982,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->usb2_device = false; if (atcphy->t8103_dummy_pending) { ret = atcphy_park_live_t8103_pipehandler(atcphy); if (ret) @@ -7947,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, diff --git a/drivers/phy/apple/t6040-usb2.c b/drivers/phy/apple/t6040-usb2.c index 50d82116aac2d..886574809923e 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, @@ -1177,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; @@ -1198,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, @@ -2327,6 +2408,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 +2483,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 +2517,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 +2531,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..9634b6ac4fde1 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,27 @@ static void dwc3_apple_usb3_pipe_reset(struct dwc3_apple *appledwc) msleep(100); } +/* + * 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) +{ + 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 +954,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 @@ -939,8 +964,25 @@ 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 (ret) { + if (!host && ret == -EOPNOTSUPP) { + /* + * 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) { /* * 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 @@ -961,27 +1003,27 @@ 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); } 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 +1039,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 +1879,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 +1899,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/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/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/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 2461f130fa7f1..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; @@ -76,12 +78,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 +123,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) 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;