Repository navigation
T6040: USB device mode on the USB-C ports (USB2), host-only decided by the PHY - #2334
Open
RyanTheTide wants to merge 8 commits into
Open
RyanTheTide wants to merge 8 commits into
RyanTheTide wants to merge 8 commits into
Conversation
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 <ryan@aurorasilicon.org>
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 <ryan@aurorasilicon.org>
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 <ryan@aurorasilicon.org>
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 <ryan@aurorasilicon.org>
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 <ryan@aurorasilicon.org>
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 <ryan@aurorasilicon.org>
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 <ryan@aurorasilicon.org>
…ce 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: #2420 Link: #2434 Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On the M4 Pro (T6040) every USB-C controller is forced to stay a host, so a J616s cabled to another computer never appears on it as a USB device: no USB networking, no mass storage, no serial gadget. The gate was a compatible list (
apple,t6040-dwc3,apple,t6050-dwc3) indwc3_apple_host_only(), standing in for "this USB2 PHY has no device sequence".Change
phy-apple-t6040-usb2gets a USB2 device sequence: the same eUSB2 power-on with the default + device tunables in place of the host one,SIG[14:12]cleared and VBUS forced valid. These three facts come from the boot loader's USB2 device bring-up on a J616s cabled to a Mac (aura#245). It validatesPHY_MODE_USB_HOSTandPHY_MODE_USB_DEVICEand returns to host mode at power-off so a host session after a device session still starts.phy-apple-atcreports both USB2 modes through.validate(it already served both).dwc3-appledecides host-only from the USB2 PHY:phy_validate(usb2_phy, PHY_MODE_USB_DEVICE). The T6050 combo PHY has no device sequence and stays host-only for that reason; T8103 to T8142 keep their device role. Without a USB3 device PHY (T6040) the gadget is offered at high speed.-EOPNOTSUPPfrom the USB3 PHY (no SuperSpeed device mode) gives a high-speed gadget on every SoC, ahead of the T8132/T6050 check that keeps a failed host handoff from starting xHCI. That fixes the T8132 port that lost its USB as a device once its USB3 calibration landed. It is the generic form of usb: dwc3: apple: keep a T8132 device role on USB2 without SuperSpeed device mode #2420 (techmore, J773g row), and it can land together with phy: apple: atc: serve a T8132 device role on USB2 #2434 (Dj, PHY side).Testing
.textto the production modules). The new code was live (its symbols in/proc/kallsyms). Boot warnings matched the production boot plus only the out-of-tree taint line. SELinux enforcing, 0 failed units, 0 AVC, Type-C roles and port-controller registers unchanged, s2idle 1/1 with an RTC wake. This Mac has no USB device attached, so only probe and sleep ran.dwc3_apple_init()against their own structs, so they broke on the newmaximum_speedfield (the first CI run's host-tests failure). The last commit adds the field to both and checks that a saved maximum comes back at the next core init. The whole host suite passes locally, 427/427 (also at 055fed8).dwc3_core_init()would give it.Still to run
Rule and hardware property
Old gate:
of_device_is_compatible(dev->of_node, "apple,t6040-dwc3") || ... "apple,t6050-dwc3".New gate: the USB2 PHY's own
validateanswer forPHY_MODE_USB_DEVICE. A PHY without.validategets-EOPNOTSUPPfrom the PHY core and keeps the controller a host, which is the safe default.Per generation:
fixed_hub, unchanged.phy-apple-t6040-usb2): device role new, USB2 only (high speed).Why the PHY returns to host mode at power-off
dwc3-apple selects
PHY_MODE_USB_DEVICEbefore releasing the controller reset for a device session. For a host session it leaves the mode to xHCI, which asks forPHY_MODE_USB_HOSTonly afterdwc3_core_init()powered the PHY on. Without the reset to host mode at power-off, the first host session after a device session would power the PHY on as a device andset_mode(HOST)would then return-EBUSY.Assisted-by: LLM (Claude:Opus 5.5)