Skip to content

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
integration/aurorafrom
usbgadget/t6040-device-mode
Open

RyanTheTide wants to merge 8 commits into
integration/aurorafrom
usbgadget/t6040-device-mode

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

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) in dwc3_apple_host_only(), standing in for "this USB2 PHY has no device sequence".

Change

  • phy-apple-t6040-usb2 gets 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 validates PHY_MODE_USB_HOST and PHY_MODE_USB_DEVICE and returns to host mode at power-off so a host session after a device session still starts.
  • phy-apple-atc reports both USB2 modes through .validate (it already served both).
  • dwc3-apple decides 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.
  • A device-role -EOPNOTSUPP from 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).
  • Binding: two optional tunable properties. The boot loader side (copy them from the ADT) is a separate aura change.

Testing

  • Builds clean (no warnings) as modules against the production fleet75 tree; checkpatch clean apart from the binding being its own commit, which it is.
  • M2 (T8112, ATC PHY), no-regression: one-shot of production fleet74 with these three modules built out of tree (a stock rebuild of the same files is byte-identical in .text to 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.
  • Host tests: the Neo stability harness and the apple-dcp dwc3-teardown model compile dwc3_apple_init() against their own structs, so they broke on the new maximum_speed field (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).
  • Review follow-ups are in the commits before it: a failed device start no longer leaves the T6040 PHY in device mode; host sessions apply the default tunable first; a high-speed gadget gets the same GUCTL1 clock setting dwc3_core_init() would give it.
  • J616s (T6040), device mode: one-shot of production fleet75 with these modules, Left Back cabled to a Mac mini (macOS 26) as host. The controller registers its UDC at boot; the Mac enumerates the configfs gadget at 480 Mb/s and binds its own NCM, ACM and mass-storage drivers. Over NCM, iperf3 gives 277 Mbit/s into the J616s and 314 Mbit/s out of it, and ping averages 0.83 ms. ACM serial carries data both ways. One s2idle cycle with the gadget bound: the gadget is still configured after resume and the link comes back (ping 10/10). On the same boot, the host port still routes its USB3 PIPE to the PHY and a USB3 flash drive runs at 5 Gb/s, the same as production.

Still to run

  • J616s with the device tunables from the boot loader (aura#340). The row above ran without them; the PHY used its defaults.
  • A host session after a device session on the same controller. This cable's far end is host-only, so it can't do that.
  • T8132 with this branch: a gadget to a USB 3 host on a calibrated port (usb: dwc3: apple: keep a T8132 device role on USB2 without SuperSpeed device mode #2420's row ran the T8132-only form of the same path).
  • Owner rows on T8142 (already a gadget for some users) and T6050 (stays host-only).
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 validate answer for PHY_MODE_USB_DEVICE. A PHY without .validate gets -EOPNOTSUPP from the PHY core and keeps the controller a host, which is the safe default.

Per generation:

  • T8103/T8112/T6000/T6020/T8122/T603x/T8132/T8142/T8140 (ATC PHY): device role unchanged (validate returns 0 for host and device). T8140 ports sit behind a fixed hub and stay hosts through fixed_hub, unchanged.
  • T6040/T6041 (phy-apple-t6040-usb2): device role new, USB2 only (high speed).
  • T6050 (combo PHY): host-only, unchanged, now because the PHY reports no device mode.
Why the PHY returns to host mode at power-off

dwc3-apple selects PHY_MODE_USB_DEVICE before releasing the controller reset for a device session. For a host session it leaves the mode to xHCI, which asks for PHY_MODE_USB_HOST only after dwc3_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 and set_mode(HOST) would then return -EBUSY.

Assisted-by: LLM (Claude:Opus 5.5)

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