Repository navigation
phy: apple: t6050: USB2 device mode on the Type-C combo PHY - #2423
RyanTheTide wants to merge 9 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 combo PHY refused every USB2 mode but host and had no .validate, so dwc3-apple, which now takes the device role only from a USB2 PHY that validates PHY_MODE_USB_DEVICE, kept every T6050 Type-C port host-only. The T6050 USB2 PHY is the USB2 block of the older ATC PHYs: its host start and stop sequences drive USBCTL, CTL and MISCTUNE bit for bit as atc.c does, and the ADT's atc-phy tunable-host and tunable-device are the same two tuples as on T8103, T6040 and T6041: USB2PHY_SIG bits 14:12 set for host and clear for device. atc.c selects the role with exactly those bits and, on every generation, forces VBUS detect and VBUS valid, since VBUS belongs to the port controller. Do the same here. combo_usb2_mode() accepts PHY_MODE_USB_DEVICE and latches the role. A USB2 start (the port's mode or the controller's power-up) applies the role right after the host tunable step, and a running PHY switches in place: device clears the host signature and forces VBUS valid, host re-applies the host tunable and sets it again. The controller's power-off returns the role to host, so a start without a controller session is the host start it was. .validate reports both roles. The USB3 side keeps refusing device mode with -EOPNOTSUPP before it touches the PIPE. Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
A USB3 PHY that refuses PHY_MODE_USB_DEVICE with -EOPNOTSUPP leaves the PIPE on its dummy producer, and the gadget is offered at high speed. The T6050 Type-C PHY refuses device mode that way, before it touches the PIPE, but its errors were all treated as a failed PIPE handoff, so a device session on it failed. Take the high-speed path first for any such refusal. T8132 keeps failing: it refuses device mode while its SuperSpeed lanes are routed, which is not a PIPE left on its dummy producer. Host starts and every other error are handled as before. Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
|
Row request for M5 Pro/Max owners (@erikwb J716c, @Isaac-Duarte J714s, @satchlj J775c, @joshuaswarren K114c), whenever it suits you. We have no T6050 Mac in our lab, so this PR is compile- and review-checked only. With #2334 and this PR applied:
If nothing enumerates, the ADT |
|
Status against main a81a12c: the 6 commits of the base (#2334, closed) have all landed on main another way (39eac98, 3c92bc4, cea9e76, eef170d, 3d8120b, 16f9903 by subject). Only this PR's own 2 commits are left: |
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
|
Retargeted to main and forward-merged main 7b10eb1 as 0e679b1. The base's commits are all on main (#2632), and main's Still needed: a T6050 gadget row. Our K114s can run it: configfs NCM gadget on one USB-C port, |
|
Hardware row at exact head
How: one combined test kernel, not this PR alone. Kernel |
Update 12-05: the base (#2334, then #2632) has landed on main, and main's dwc3-apple (
dwc3_apple_route_usb3()) already offers the gadget at high speed when the USB3 PHY refuses device mode with-EOPNOTSUPP, on every SoC. So the dwc3 commit below is superseded and this PR now targetsmainwith the PHY commit only (item 1). Item 2 is kept below for history.Problem
With #2334, dwc3-apple takes the device role only when the USB2 PHY validates
PHY_MODE_USB_DEVICE. The T6050 Type-C combo PHY (drivers/phy/apple/atc-t6050-combo.h) has no.validateand refuses every USB2 mode except host. That leaves every M5 Pro/Max USB-C port (J714s, J716s, K114, K116 and the rest) host-only. A Mac on the other end of the cable cannot use the port as a USB gadget (NCM, ACM, mass storage).Change
Stacked on #2334 (base
usbgadget/t6040-device-mode).phy: apple: t6050: USB2 device mode on the Type-C combo PHY. The T6050 USB2 PHY is the USB2 block of the older ATC PHYs. Its host start and stop sequences drive
USBCTL,CTLandMISCTUNEexactly asatc.cdoes. The ADT'satc-phytunable-hostandtunable-deviceare the same two tuples on T8103, T6040, T6041 and T6050:USB2PHY_SIGbits 14:12 set for host and cleared for device.atc.cpicks the role with those bits and forces VBUS detect/valid on every generation. This PR does the same here:set_mode(DEVICE)latches the role..validatereports both roles.The USB3 side still refuses device mode with
-EOPNOTSUPP, before it touches the PIPE.usb: dwc3: apple: high-speed gadget on a T6050 port. A device-mode
-EOPNOTSUPPfrom the USB3 PHY already meant "PIPE left on its dummy producer, gadget at high speed" (T6040, from USB device mode: T6040 USB2 device sequence; device role keyed on the PHYs (host-only and SuperSpeed) #2334). On T6050 every USB3 PHY error was instead treated as a failed PIPE handoff, which would fail the device start. The high-speed path now comes first. T8132 keeps failing, because its refusal means its SuperSpeed lanes are routed. Host starts are unchanged.A host session on T6050 does exactly what it did before: the role starts as host and the signature code is not run.
Testing
atc-t6050-dp.o,phy-apple-atc.oanddwc3-apple.o(clang 22, arm64, W=1) against a prepared kernel tree with this branch's sources and headers: 0 warnings, 0 errors, before and after. The modpost link step was not checked: the prepared tree is an older fleet kernel, and it fails identically before and after.checkpatch.pl --strict: clean.Still to run (owner of a J714s, J716s, K114 or K116, or any T6050)
Kernel with #2334 and this PR,
CONFIG_USB_DWC3_DUAL_ROLE=y, gadget configfs +f_ncmas modules. USB-C cable to any host (a Mac or a Linux PC).modprobe libcomposite usb_f_ncm, createg1with anncm.usb0function,echo $(ls /sys/class/udc | head -1) > UDC. Then reportcat /sys/class/udc/*/current_speed(high-speedexpected),dmesg | grep -iE 'dwc3|t6050|gadget'(expect "No USB3 device PHY: gadget at high speed") and the host's view (macOS: System Information USB, orlsusb -von Linux).iperf3 -son one side,iperf3 -c <peer> -t 20and-Rover the NCM link. Report both numbers.lsusb -t).echo freeze > /sys/power/state(s2idle) once with the gadget bound, then wake. The link must come back, and iperf3 must run again.Facts used (all public)
atc-phy0tunable-host = [0x0000000800000000, 0x0000700000007000]andtunable-device = [0x0000000800000000, 0x0000000000007000](reg 0 = USB2 PHY, offset 0x8, mask 0x7000, value 0x7000 or 0). The values are identical in the GravityLinux adt-collection dumps for J313 (T8103), J773s (T6040), J616c (T6041) and J873s (T6050).apple_t6050_usb2_host(CTL bit 3 SIDDQ cleared, bits 0 and 1 resets released, bit 2 APB_RESET_N set, MISCTUNE bits 29 and 30 cleared, USBCTL = 2 RUN) andapple_t6050_usb2_stopareatc_usb2_power_on/_offregister for register.atc.cdoes for both roles on every generation. USB device mode: T6040 USB2 device sequence; device role keyed on the PHYs (host-only and SuperSpeed) #2334 found the same was needed for the T6040 device role. Here it is applied in the device role only, so host stays as it is.Risks for the reviewer
apple,tunable-usb2-host, the ADT'stunable_USB2PHY_HOSTexported by aura) is applied in device mode too, before the signature is cleared. If iBoot's tunable carries host-only fields beyond SIG, a device-specific tunable (tunable_USB2PHY_DEV, as USB device mode: T6040 USB2 device sequence; device role keyed on the PHYs (host-only and SuperSpeed) #2334 did for T6040) would be the next step. That would need an ADT value from an owner, read withioreg -l -p IODeviceTree -n atc-phy0.atc.cdoes. If the T6050 PHY needs a stop/start around the switch, row 1 will show no connection on the host side.