Skip to content

USB device mode: T6040 USB2 device sequence; device role keyed on the PHYs (host-only and SuperSpeed) - #2632

Open
RyanTheTide wants to merge 16 commits into
integration/aurorafrom
usbgadget/t6040-device-mode-rebase-20261121
Open

RyanTheTide wants to merge 16 commits into
integration/aurorafrom
usbgadget/t6040-device-mode-rebase-20261121

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Replaces #2334, rebased onto current integration/aurora (conflicts in tools/testing/selftests/drivers/apple/atc-t8132-usb3.py: kept the base's syscore and USB3-suspend checks with this series' high-speed device fallback; that harness now runs in run-host-tests.py, so one added commit models the maximum_speed save, phy_validate() and the high-speed limit there).

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 only when the boot loader passed apple,tunable-usb2-device (7fb68b5; without it the port stays a host, which is every J616s until aura#340 ships), 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.
  • USB3 PHYs without a SuperSpeed device mode: one mechanism in two layers.
    • The PHY decides. Its USB3 .validate refuses PHY_MODE_USB_DEVICE when it has no SuperSpeed device mode. That's T6040, and in ATC it's a capability in the match data (no_ss_device, T8132 only), not a SoC check. set_mode(DEVICE) routes the lanes for the role. On T8132 that means Dj's phy: apple: atc: serve a T8132 device role on USB2 #2434: while the device role holds, the lanes run USB2 next to any four-lane DisplayPort. It's carried here unchanged, with Dj's authorship. On T6040 the PIPE stays parked.
    • dwc3-apple applies the decision. It sets the core up as a high-speed device when the USB3 PHY does not validate the device role. Both layers are needed because the device speed and the USB2 clock for the USB3 logic are controller settings, and no PHY can set them. A device-role -EOPNOTSUPP from set_mode still means high speed on every SoC (a T8103 port whose lanes are all DisplayPort). That check now runs ahead of the T8132/T6050 check that keeps a failed host handoff from starting xHCI.
    • This fixes the T8132 port that lost its USB as a device once its USB3 calibration landed. It replaces phy: apple: atc: serve a T8132 device role on USB2 #2434 (carried) and usb: dwc3: apple: keep a T8132 device role on USB2 without SuperSpeed device mode #2420 (techmore, whose J773g row showed the high-speed gadget working).
  • Binding: two optional tunable properties. The boot loader side (copy them from the ADT) is a separate aura change.

Testing

  • Rebased head (on c3d01cb), arm64 defconfig + asahi.config, LLVM=1 W=1: drivers/phy/apple/ and dwc3-apple.o build with no warnings in the changed files (one existing kernel-doc note on enum dwc3_apple_sleep_phase). tools/asahi/run-host-tests.py --only atc 6/6, --only neo-stability 11/11, --only apple-dcp 1/1 pass. The T8132 role harness fails if dwc3_apple_init() stops restoring the saved maximum speed or if the .validate check is removed.

  • 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 ATC USB3 harness and the apple-dcp PHY, quiesce and dwc3 models compile atc.c functions against their own structs. They stopped building on phy: apple: atc: serve a T8132 device role on USB2 #2434's commit, and that PR's own CI shows it. The tools: commit fixes them and checks the T8132 device-role mux mapping. The ATC KUnit suite isn't run by CI (its kunit job runs the SEP suite only); it passes 52/52 under qemu arm64, including phy: apple: atc: serve a T8132 device role on USB2 #2434's case and a new .validate case. The CI DWC3/ATC compile profiles pass 3/3 locally.

  • 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 (at 055fed8 and at this head).

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

  • J616s, second session at this head (fleet75 one-shot, Left Back to the Mac mini): the UDC registers at boot. The high-speed setup now comes from the USB3 PHY's .validate ("No USB3 device PHY: gadget at high speed"; set_mode no longer fails). The host port still routes its USB3 PIPE. The gadget runs at high speed. Over NCM a 1 GiB file copies at 40.8 MB/s out and 35.2 MB/s in, sha256 identical, with ping 20/20 at 1.0 ms. A fixed-disk image mounts on the Mac and reads at 40.8 MB/s. 0 kernel warnings. The same modules also ran another lane's 16 s2idle cycles with a gadget netconsole to the Mac.

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)

RyanTheTide and others added 14 commits November 21, 2026 11:05
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>
T8132 has no SuperSpeed device mode, and atcphy refuses a device role on
a port whose lanes run USB3: atcphy_usb3_set_mode() returns -EOPNOTSUPP,
dwc3-apple fails the role ("USB3 PHY setup failed, err=-95") and the
port controller's revalidation gives up. Before the boot loader passed
the T8132 USB3 calibration these ports ran USB2 only, and the same device
role worked there. So a Mac mini (J773g) rear port that a host connects
to as a device lost its USB when the calibration arrived.

Serve the device role on USB2 instead: when the controller asks for the
device role on a calibrated T8132 port, switch its lanes to the USB2 mode
(four-lane DisplayPort keeps its own USB2 wires) and keep them there for
later mux updates while the device role holds. The host role, and the
partner leaving (safe state), lift that again.

Signed-off-by: Diljit Singh <hey@djdev.me>
…apability

The previous commit serves a T8132 device role on USB2 because that PHY
has no SuperSpeed device mode. Describe that as what it is, a property
of the PHY in its match data (no_ss_device), instead of the T8132
banks: the device-role USB2 limit (now usb2_device) applies to any ATC
PHY with the flag, and the mux update keeps it outside the T8132 block.

Also let the USB3 PHY answer .validate: host always, device unless the
PHY has no SuperSpeed device mode. That is how dwc3-apple learns that it
has to run as a high-speed device: its device speed and the USB2 clock
for its USB3 logic are controller settings no PHY can make. Only T8132
sets the flag; every other ATC generation keeps its SuperSpeed device.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
…lidate

The USB3 PHY has no device sequence, which it reported by failing
set_mode for a device role. Report it through .validate instead, as the
ATC PHYs now do, and accept the device role in set_mode: it runs on
USB2, with the PIPE left parked on its dummy producer where power_off
put it. dwc3-apple then sets up the high-speed device from the
capability rather than from an error.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
…lity

The USB3 PHYs now say in .validate whether they can carry a SuperSpeed
device (T8132 and T6040 cannot), and route their lanes for a device
role on USB2 when they cannot. Set the high-speed gadget up from that
answer, before phy_set_mode(), instead of from a set_mode error. This
stays in the glue because the device speed and the USB2 clock for the
USB3 logic are controller settings no PHY can make; the PHY decides,
the glue applies it. No USB3 PHY at all is the same case.

A set_mode -EOPNOTSUPP for a device role still means high speed: an ATC
port can lack SuperSpeed on one connection (a T8103 port whose lanes
are all DisplayPort, or without SuperSpeed tunables). The T6040 PIPE
reset stays with the host role; a device role leaves the PIPE parked.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
The ATC USB3 harness and the apple-dcp PHY, quiesce and dwc3 models
compile atc.c functions against their own structs. The device role on a
PHY without SuperSpeed device mode added a struct member (usb2_device),
a helper (atcphy_usb2_device_mode()), a forward declaration of
atcphy_mux_switch() and a dev_info() call, so they stopped building,
including on linux#2434 alone. Add the member, extract the helper,
emit the prototype and stub dev_info as the harnesses do for their
neighbours, and check in the USB3 harness that a T8132 device role maps
a USB partner to USB2 (and back to USB3 once the role is gone) while
four-lane DisplayPort stays DisplayPort.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
The T8132 role harness compiles dwc3_apple_set_role() and
dwc3_apple_init() against its own structs. On integration/aurora it now
runs in tools/asahi/run-host-tests.py, and it stopped building with this
series: dwc3_apple_init() restores a saved maximum_speed, and the role
code asks the USB3 PHY's .validate whether it can carry a device and
calls dwc3_apple_gadget_high_speed().

Give the model's structs the maximum_speed fields and stub phy_validate()
and the high-speed limit (without the GUCTL1 clock write, which is the
controller's). The device-role -EOPNOTSUPP case now also checks that the
limit is applied and that the next session starts from the saved
maximum, and two new cases cover a PHY that does not validate a device
role and a controller without a USB3 PHY.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Blockers: 2.

  1. drivers/phy/apple/t6040-usb2.c:341: t6040_usb2_validate() reports PHY_MODE_USB_DEVICE even when the boot loader passed no apple,tunable-usb2-device. In that case power_on (line 442) only logs at dbg level and runs device mode on the PHY's reset defaults. Right now that is every J616s, because aura#340 has not landed; the J616s rows above ran without the tunables. Until the boot loader provides them, the fallback should be today's behaviour (host-only), not an untuned device mode. Return -EOPNOTSUPP for PHY_MODE_USB_DEVICE when tphy->tunable_usb2_device is NULL. dwc3-apple then keeps the controller a host through dwc3_apple_host_only() without any other change. Once aura#340 ships, re-run the J616s gadget row with the tunables applied.
  2. drivers/phy/apple/t6040-usb2.c:8 and :450: the PR rewrites both comments, so clean them up while they are being touched. The file header still says the sequence was decoded from the macOS PHY driver and names that driver. The host-mode comment quotes the host tunable's mask and value from the platform's device tree. Neither belongs in public code. Describe the sequence by what it does (which SIG fields the host tunable clears) and drop the provenance and the numbers.

Also checked, no issue: phy_validate() returns -EOPNOTSUPP for a PHY without .validate (drivers/phy/phy-core.c:598). The T6050 combo USB2 ops (atc-t6050-combo.h:575) have no .validate, so T6050 stays host-only as the body says. The mode reset in t6040_usb2_reset_assert() runs under tphy->lock and only when the PHY is unpowered, so a failed device start cannot leave device mode behind. maximum_speed is saved before the first clamp and restored in dwc3_apple_init() before core init.

HW row: J773g (T8132) on a calibrated port as a gadget to a USB 3 host, on this branch's default command line: the host lists it at 480 Mb/s, NCM iperf3 both ways, then the same port as a host to a USB 3 drive at 5 Gb/s. On the J616s, also a host session after a device session on the same controller once a dual-role far end is available. Regression: 0 AVC, 0 failed units, 0 new kernel errors.

Assisted-by: LLM (Claude:Opus 5.5)

t6040_usb2_validate() accepted PHY_MODE_USB_DEVICE whether or not the
boot loader passed apple,tunable-usb2-device, and power_on then ran
device mode on the PHY's reset defaults with only a debug line. Until
the loader provides the tunables, that is every J616s. Refuse device
mode without them, so dwc3-apple keeps the controller a host as before
this series; set_mode() already goes through validate.

Also describe the host-mode SIG sequence by what it does instead of
quoting the tunable's mask and value, and drop the driver provenance
from the file header.

A KUnit case covers validate and set_mode with and without the device
tunables.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Both points are in 7fb68b5.

  1. t6040_usb2_validate() accepts PHY_MODE_USB_DEVICE only when apple,tunable-usb2-device was passed. Without it the call returns -EOPNOTSUPP, so set_mode() refuses too and dwc3-apple keeps the controller a host. The now-unreachable debug line in power_on is gone. A KUnit case (phy-apple-t6040-usb2-mode) covers validate and set_mode with and without the device tunables. It fails if validate accepts device mode again.
  2. The file header no longer names the macOS driver, and the host-mode comment says what the host tunable does (it clears SIG[14:12] again) without the mask and value.

Checks: arm64 KUnit phy-apple-t6040* 4/4, apple-dcp host suite 90/90, W=1 and checkpatch --strict clean. The hardware rows from your comment (J773g gadget then host on one port, and a J616s gadget row once aura#340 provides the tunables) are still to run.

Assisted-by: LLM (Claude:Opus 5.5)

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pre-PR checklist review (§1–§6) at 7fb68b57e16e: REQUEST_CHANGES (3 code bugs + missing §5 hardware rows on the live head).

Blockers (Code)

  1. Failed device start still leaves T6040 USB2 PHY stuck in PHY_MODE_USB_DEVICE (drivers/usb/dwc3/dwc3-apple.c:855-901, drivers/phy/apple/t6040-usb2.c:2420-2422):

    • Commit 3c92bc49 resets tphy->mode = PHY_MODE_USB_HOST inside t6040_usb2_reset_assert(), stating that every failed start asserts controller reset on its way out.
    • In dwc3_apple_core_start(), phy_set_mode(appledwc->usb2_phy, PHY_MODE_USB_DEVICE) runs at line 856 before:
      • pm_runtime_resume_and_get(appledwc->dev) at lines 869 and 882 — both failure paths return ret directly without calling dwc3_apple_core_stop() or reset_control_assert();
      • reset_control_deassert(appledwc->reset) at line 888 — on failure, appledwc->reset_pending is still false (it is only set at line 901), so dwc3_apple_core_stop() at line 895 skips reset_control_assert() (dwc3-apple.c:799).
    • Failure mode: On either a runtime PM resume failure or a reset deassert failure during a device start, t6040_usb2_reset_assert() never runs and tphy->mode stays PHY_MODE_USB_DEVICE. The next host session then powers the PHY on in device mode and fails xHCI's phy_set_mode(PHY_MODE_USB_HOST) with -EBUSY.
    • Fix: Explicitly unwind usb2_phy back to PHY_MODE_USB_HOST on dwc3_apple_core_start() error paths before core_active is set (or only assert device mode once PM/reset setup succeeds if hardware allows).
  2. T6040 host-after-device session leaks T6040_USB2_SIG_VBUSVLDEXT (drivers/phy/apple/t6040-usb2.c:455, 456-467, 513-514):

    • Device mode explicitly sets T6040_USB2_SIG_VBUSVLDEXT (BIT(2) | BIT(3) = VBUSVLDEXT_FORCE_VAL | VBUSVLDEXT_FORCE_EN) at line 455 after applying tunable_usb2_default and tunable_usb2_device.
    • Neither t6040_usb2_power_off() (lines 535–593) nor the host branch of t6040_usb2_power_on() (lines 456–467) clears T6040_USB2_SIG_VBUSVLDEXT, and host-mode verification (t6040_usb2_sig_want() / line 513–514) masks only T6040_USB2_SIG_INIT (BIT(0..1) | BIT(12..14)).
    • Failure mode: On a host session following a device session on the same controller without a power-domain collapse (currently untested per Still to run), forced-valid VBUS bits bleed into host mode unless tunable_usb2_default/tunable_usb2_host happen to clear bits 2–3.
    • Fix: Explicitly clear T6040_USB2_SIG_VBUSVLDEXT in the host path of t6040_usb2_power_on() (or in t6040_usb2_power_off()) and verify T6040_USB2_SIG_CHECKED in both modes.
  3. T8132 same-plug Device → Host data role swap (DR_Swap) stays stuck on USB2 (drivers/phy/apple/atc.c:4780-4783):

    • atcphy_usb3_set_mode() clears atcphy->usb2_device = false on PHY_MODE_USB_HOST with the comment "The lanes regain USB3 with the next mux update (a data role swap)."
    • In drivers/usb/typec/tipd/core.c:1325-1460, a same-plug DR_Swap (was_disconnected == false) executes in this order:
      1. usb_role_switch_set_role(USB_ROLE_NONE) (line 1327) — stops gadget; atcphy->usb2_device remains true.
      2. cd321x_typec_update_mode() (line 1441) → typec_mux_set() runs while atcphy->usb2_device is still true, so atcphy_typec_target_mode() (atc.c:5860) maps APPLE_ATCPHY_MODE_USB3 → APPLE_ATCPHY_MODE_USB2 and leaves the lanes in USB2.
      3. usb_role_switch_set_role(USB_ROLE_HOST) (line 1460) → atcphy_usb3_set_mode(PHY_MODE_USB_HOST) clears atcphy->usb2_device = false, then calls atcphy_usb3_route(atcphy, true) while atcphy->mode is still APPLE_ATCPHY_MODE_USB2 (dummy PIPE). No further mux update follows.
    • Failure mode: After swapping from device to host on the same plug, a calibrated T8132 port stays stuck at USB2 until unplug.
    • Fix: Clear usb2_device when the device role tears down (e.g., on atcphy_usb3_power_off before the next mux update) and/or restore the lanes when usb2_device clears on PHY_MODE_USB_HOST.

Nits

  • drivers/phy/apple/atc.c:4773-4778: atcphy->usb2_device = true is set before atcphy_mux_switch(atcphy, usb2) succeeds; move it after a successful switch so an error does not leave usb2_device latched.
  • drivers/phy/apple/atc.c:3640-3641: atcphy_usb2_device_mode() calls atcphy_t8132_dp_on() (which gates on ATCPHY_GENERATION_T8132), even though commit 33682cbf generalized no_ss_device/usb2_device beyond T8132.

Missing §5 Evidence (at 7fb68b57)

  • Commit 7fb68b57 makes t6040_usb2_validate() refuse PHY_MODE_USB_DEVICE without apple,tunable-usb2-device, so the earlier J616s rows (run without aura#340 tunables) no longer exercise device mode on this head. Still needed:
    • J616s (T6040) with apple,tunable-usb2-device / apple,tunable-usb2-default (aura#340): gadget enumeration + transfer + host session after device session on the same controller;
    • T8132 (e.g., J773g) calibrated port at this head: gadget at 480 Mb/s, then host at 5 Gb/s on the same port;
    • T8142 & T6050 regression rows (confirming T6050 stays host-only, T8142 gadget unchanged), with 0 SELinux denials (AVC), 0 failed units, 0 new kernel errors.

Verified clean

  • §4 Attribution & clean-room: all 13 commits have human author/committer + human Signed-off-by: (with Diljit's commit carried with his authorship), PR body has Assisted-by:, and 7fb68b57 removed the macOS driver name and hardcoded tunable mask/value from t6040-usb2.c.
  • phy_validate() returns -EOPNOTSUPP when .validate is absent (drivers/phy/phy-core.c:598-599), so T6050 (combo_usb2_ops) remains host-only as intended.
  • CI: 8/8 checks green.

Assisted-by: LLM (Gemini 4 Neon)

Undo USB2 device selection when runtime resume or reset deassertion prevents DWC3 from starting. Clear forced VBUS-valid when the T6040 PHY next powers up as host and verify the same signal mask for both roles.

After parking the PIPE on role teardown, drop the USB2-only device restriction before Type-C applies the next mux state. Record the restriction only after a successful device route.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
@RyanTheTide

RyanTheTide commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor Author

At 98157ea51c73a, a failed DWC3 runtime resume or reset release unwinds USB2 device selection. The T6040 host sequence clears the forced VBUS-valid bits and checks them on readback. ATC drops the device-role USB2 restriction after parking the PIPE, before the mux update on a same-plug swap, and records that restriction only after a successful device route.

The three touched arm64 objects compiled, strict checkpatch passed, and arm64 KUnit passed 62 tests with one unrelated skip. The same-controller J616s device-to-host row, calibrated T8132 role swap, and T8142/T6050 regressions remain pending.

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.

2 participants