Skip to content

phy: apple: t6050: USB2 device mode on the Type-C combo PHY - #2423

Draft
RyanTheTide wants to merge 9 commits into
mainfrom
community/t6050-combo-usb2-device
Draft

RyanTheTide wants to merge 9 commits into
mainfrom
community/t6050-combo-usb2-device

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

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 targets main with 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 .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 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

  • 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. 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
  • 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 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 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.

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>
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

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:

  1. Set up a configfs NCM gadget on one USB-C port and connect it to any host (a Mac or a Linux box).
  2. cat /sys/class/udc/*/current_speed. We expect high-speed, and dmesg should say No USB3 device PHY: gadget at high speed.
  3. iperf3 in both directions over the NCM link.
  4. Unplug and replug 3 times, then check that host mode still works on that port (a USB stick is enough).
  5. One s2idle with the gadget bound, then iperf3 again.

If nothing enumerates, the ADT atc-phy0 node values (aura proxy print(u.adt["/arm-io/atc-phy0"]), or macOS ioreg -l -p IODeviceTree -n atc-phy0) would show what the PHY expects. Posting results here is perfect. Thank you.

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Still needed: retarget this onto #2632 (which replaced #2334) or onto integration/aurora once #2632 lands, and a T6050 gadget row (NCM at high speed, iperf3 both ways, 3 replugs, one s2idle).

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

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: usb: dwc3: apple: high-speed gadget on a T6050 port (ac88372) and phy: apple: t6050: USB2 device mode on the Type-C combo PHY (c160e6f). Next step: a fresh branch with just those two on main, plus a K114s (T6050) device-mode row.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
@RyanTheTide RyanTheTide changed the title T6050: USB2 device mode on the Type-C combo PHY (on #2334) phy: apple: t6050: USB2 device mode on the Type-C combo PHY Dec 5, 2026
@RyanTheTide
RyanTheTide changed the base branch from usbgadget/t6040-device-mode to main December 5, 2026 01:41
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Retargeted to main and forward-merged main 7b10eb1 as 0e679b1. The base's commits are all on main (#2632), and main's dwc3_apple_route_usb3() already takes the high-speed gadget path for a USB3 PHY that refuses device mode with -EOPNOTSUPP, so the merge keeps main's dwc3-apple.c and t6040-usb2.c; the PR diff is now only the T6050 combo PHY's USB2 device mode (atc-t6050-combo.h, atc-t6050-dp.c). Local: arm64 LLVM W=1 atc-t6050-dp.o and dwc3-apple.o build, no new warnings.

Still needed: a T6050 gadget row. Our K114s can run it: configfs NCM gadget on one USB-C port, current_speed = high-speed with the 'No USB3 device PHY: gadget at high speed' line, iperf3 both ways, 3 replugs, host mode still works after, one s2idle.

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Hardware row at exact head 0e679b18bd92 on the K114s: PARTIAL (no host on the other end of a cable).

  • dwc3-apple 2a2280000.usb: No USB3 device PHY: gadget at high speed; /sys/class/udc/2a2280000.usb registered (the saved kernel has no UDC).
  • Side effect to check: xhci root hubs went from 6 (saved kernel) to 4 on this boot, i.e. that controller sits in device role with nothing attached (port3 data_role [device], no partner).
  • Not run: the NCM gadget to another host, iperf3, replugs, host mode with a stick on the same port, s2idle.

How: one combined test kernel, not this PR alone. Kernel 7.3.0+ = main d0684a06 + merge commits of linux#2422 d259e636, #2423 0e679b18, #3568 1aa4169b, #4059 b94d8922, #2465 47b668b4 (all merged clean, test commit 2afc7246, fleet config, cloud build https://github.com/aurora-silicon/cloud-build/actions/runs/47498815145). #4059 is in the kernel but its row is run separately. Booted as a one-shot on the lab K114s (M5 Max, T6050, 27.2 stub) with this kernel's own t6050-k114s.dtb in a trial Stage 2 (live aura 1.0.0b19 + U-Boot, only the DTB swapped), default cmdline, silent. No sleep rows on this Mac (its RTC can't wake s2idle). Health: 0 AVC, 0 failed units, no new error-level kernel lines vs the saved kernel. Saved default restored after.

This branch has not been deployed

No deployments
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