Skip to content

T6050: USB2 device mode on the Type-C combo PHY (on #2334) - #2423

Draft
RyanTheTide wants to merge 2 commits into
usbgadget/t6040-device-modefrom
community/t6050-combo-usb2-device
Draft

RyanTheTide wants to merge 2 commits into
usbgadget/t6040-device-modefrom
community/t6050-combo-usb2-device

Conversation

@RyanTheTide

Copy link
Copy Markdown
Contributor

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 .validate and 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).

  1. 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, CTL and MISCTUNE exactly as atc.c does. The ADT's atc-phy tunable-host and tunable-device are the same two tuples on T8103, T6040, T6041 and T6050: USB2PHY_SIG bits 14:12 set for host and cleared for device. atc.c picks 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.
    • Every USB2 start applies the role right after the host tunable step.
    • A running PHY switches in place: device clears the host signature and forces VBUS valid; host re-applies the host tunable.
    • The controller's power-off puts the role back to host.
    • .validate reports both roles.

    The USB3 side still refuses device mode with -EOPNOTSUPP, before it touches the PIPE.

  2. usb: dwc3: apple: high-speed gadget on a T6050 port. A device-mode -EOPNOTSUPP from the USB3 PHY already meant "PIPE left on its dummy producer, gadget at high speed" (T6040, from T6040: USB device mode on the USB-C ports (USB2), host-only decided by the PHY #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

  • Hardware: none. No T6050 in our lab. This is a draft until an owner runs the rows below.
  • Built atc-t6050-dp.o, phy-apple-atc.o and dwc3-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_ncm as modules. USB-C cable to any host (a Mac or a Linux PC).

  1. configfs NCM gadget: modprobe libcomposite usb_f_ncm, create g1 with an ncm.usb0 function, echo $(ls /sys/class/udc | head -1) > UDC. Then report cat /sys/class/udc/*/current_speed (high-speed expected), dmesg | grep -iE 'dwc3|t6050|gadget' (expect "No USB3 device PHY: gadget at high speed") and the host's view (macOS: System Information USB, or lsusb -v on Linux).
  2. Throughput: iperf3 -s on one side, iperf3 -c <peer> -t 20 and -R over the NCM link. Report both numbers.
  3. Unplug and replug x3. The gadget must come back each time. Then plug a USB device into the same port: host mode must still work (lsusb -t).
  4. 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-phy0 tunable-host = [0x0000000800000000, 0x0000700000007000] and tunable-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).
  • In this tree, 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) and apple_t6050_usb2_stop are atc_usb2_power_on/_off register for register.
  • VBUS forcing (SIG bits 0 to 3) is what atc.c does for both roles on every generation. T6040: USB device mode on the USB-C ports (USB2), host-only decided by the PHY #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
  • The host tunable (apple,tunable-usb2-host, the ADT's tunable_USB2PHY_HOST exported 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 T6040: USB device mode on the USB-C ports (USB2), host-only decided by the PHY #2334 did for T6040) would be the next step. That would need an ADT value from an owner, read with ioreg -l -p IODeviceTree -n atc-phy0.
  • The role switches in place on a running PHY, as atc.c does. If the T6050 PHY needs a stop/start around the switch, row 1 will show no connection on the host side.

Assisted-by: LLM (Claude:Opus 5.5)

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant