Skip to content

j616s: USB-C with USB3 (T6040 Type-C PHY, dwc3, ports) - #403

Merged
RyanTheTide merged 23 commits into
integration/aurorafrom
j616s/usb-20261023
Oct 23, 2026
Merged

RyanTheTide merged 23 commits into
integration/aurorafrom
j616s/usb-20261023

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

USB-C on the M4 Pro (T6040, J616s): the two PD controller buses, the three Type-C ports, the T6040 Type-C PHY with USB3 through its coprocessor, and dwc3-apple support for T6040.

What's here:

  • bindings for the T6040 Type-C PHY and the T6040 dwc3 (dt_binding_check passes)
  • Jonathan Goyvaerts' T6040 PHY and dwc3 series and his two RTKit resume commits, cherry-picked with authorship and "cherry picked from" lines kept. CJ Damsleth's USB2 slice is the start of the PHY driver. Two conflicts with the T8132 dwc3-apple code from arm64: apple: T8132/J713 (M4 MacBook Air) support and native graphics (replaces #366, #367) #400 were resolved with [ryan: ...] notes.
  • the T6040 USB DT (ports, PMGR domains, both PD buses) and the J616s USB3 tunables, the tunables credited to Jonathan with Originally-by
  • the PHY driver enabled in asahi.config

No Gravity-derived code: gravity-m4 has no T6040 USB code.

Tested on Ryan's J616s (native tether boot, integration/aurora + this branch + #402 + local tether DT commits), with a USB3 hub on the left-front port (ATC1):

  • sn201202x binds both PD controllers; typec port0 gets a partner and goes to host/source
  • the PHY coprocessor starts and tunes the lane ("USB3 PHY tuned: lane 1"), the USB3 PIPE switches to the PHY
  • xHCI registers usb1 (480) and usb2 (10000); the hub enumerates as 2-1 at 5000 (SuperSpeed)
  • m4test usb passes

USB2 (added after review): the last commit applies the ADT's per-port tunable_USB2PHY_HOST (SIG mask 0x7003, value 0x3) after the PHY's signal setup. Without it the PHY kept the device-mode signal values and the USB2 port never saw a connect. With it, on the same hub: PORTSC CCS at high speed, the hub's USB2 half as 1-1 at 480, and the 2.4 GHz dongle under it as a full-speed HID keyboard and mouse.

The USB3 PLL tunables come from Jonathan's machine and should be replaced by per-unit values from the loader later.

🤖 Generated with Claude Code

RyanTheTide and others added 22 commits October 23, 2026 23:17
The T6040 (M4 Pro) Type-C PHY is driven by phy-apple-t6040-usb2: USB2
host, and USB3 host through a PHY coprocessor that runs RTKit firmware
behind an ASC mailbox. It has a different register layout from the ATC
PHYs in apple,atcphy.yaml. Describe its eleven regions, the mailbox, the
DWC3 reset, the orientation switch and the per-device USB3 calibration
tables.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
Add the T6040 (M4 Pro) controller, its optional configuration block
("drd-cfg") and the controller tables dwc3-apple applies after every core
reset.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
apple_rtkit_idle() puts a co-processor into the IDLE power state and
keeps its RTKit session, but there is no way back other than
apple_rtkit_wake(), which expects the firmware to say HELLO and map its
endpoints again. Add the counterpart: set the IOP and then the AP power
state back to ON in the same session.

The T6040 Type-C PHY coprocessor needs it: it answers neither a restart
nor a wake from RTKit sleep, and it tunes the PHY only when it is
powered up.

Signed-off-by: Jonathan Goyvaerts <[email protected]>
Assisted-by: LLM
(cherry picked from commit b14e33a)
apple_rtkit_idle() moves the AP power state to idle first and then the
IOP's. apple_rtkit_resume_idle() asked the IOP to run again while the AP
state was still idle; the T6040 ATC PHY coprocessor never answered that
request (-ETIME on all three ports). Do the reverse of apple_rtkit_idle():
the AP state first, then the IOP's, as apple_rtkit_wake_early_ap() does
for helpers that need AP readiness before they acknowledge IOP power.

Signed-off-by: Jonathan Goyvaerts <[email protected]>
Assisted-by: LLM
(cherry picked from commit 7c9f08b)
v2 (2026-08-04, ticket 108): default the provider to PHY_MODE_USB_HOST at
probe. dwc3 powers on its phys from dwc3_core_init() inside
dwc3_core_probe(), before any consumer set_mode can reach the phy;
dwc3-apple's early phy_set_mode() runs on a still-NULL
dwc.usb2_generic_phy[0] and is a silent no-op, so the v1
PHY_MODE_INVALID default made power_on return -EINVAL and dwc3-apple
probe fail ('failed to initialize core' / err=-22) on every boot of the
usb2-native-right DT. The provider is host-only by construction and
set_mode still rejects every non-host request; the enabling DT node
remains the review boundary.

Signed-off-by: CJ Damsleth <[email protected]>

Link: https://github.com/damsleth/wallace/blob/93478ce8df6460b90d0027506433e4372bef9d42/patches/0001-phy-apple-add-experimental-T6040-USB2-only-slice.patch
Origin: linux-m4 170d124d6 (CJ Damsleth part)
Provenance: carry-author (wallace patches/0001, as he wrote it)
(cherry picked from commit 00a84a9)
The T6040 USB2 PHY driver could only power the PHY on, so the node had
to stay disabled. Complete it:

- power_off puts the port in reset for 5 ms, sets USBCTL mode 4,
  asserts SIDDQ and the PHY reset and gates the APB and reference
  clocks, then reads the fields back. The host controller must be
  stopped first; dwc3-apple does that on every role change.
- power_on reads back the programmed control, signal, tune, mode and
  event fields before the core can start the host. A power sequence
  that did not land latches a failure and refuses further cycles with
  -EIO.
- The pipehandler register bank provides a reset controller for the
  DWC3 reset and clamp in the pipehandler AON general register (offset
  0x1c: bit 0 is the VCC reset, cleared = asserted; bit 4 forces the
  clamp), with the same assert and release order as atc.c uses on
  T8103/T8122.

This builds on CJ Damsleth's host-only T6040 USB2 PHY slice.

Signed-off-by: Jonathan Goyvaerts <[email protected]>
Assisted-by: LLM
(cherry picked from commit f1d2ffc)
The T6040 (M4 Pro) Type-C ports are driven through the USB2-only PHY
provider phy-apple-t6040-usb2, which implements host mode only, and
have no USB3 PHY in the device tree:

- Look the USB3 PHY up as optional. A NULL PHY makes the USB3 mode
  switch a no-op, and the core finds no USB3 PHY of its own either.
- Never enter device mode on such a controller, or on any controller
  of a kernel built without gadget support, where dwc3_gadget_init()
  is a stub that succeeds. A USB_ROLE_DEVICE request (a charger or a
  host on the other end) leaves the controller off and get() reports
  USB_ROLE_NONE, so the port controller does not retry.
- Mark a host-only controller's role before the core comes up, so that
  dwc3_core_soft_reset() leaves the unused gadget side alone.

Signed-off-by: Jonathan Goyvaerts <[email protected]>
Assisted-by: LLM
(cherry picked from commit 249860c)

[ryan: keep the existing T8132 optional usb3-phy lookup alongside T6040]
Signed-off-by: Ryan Murray <[email protected]>
The driver had no runtime PM, so genpd counted the PHY as always busy:
once bound, it kept the port's whole PHY power chain on, even with
nothing plugged in.

Enable runtime PM before the PHY is created, so the PHY core holds the
device active from power_on to power_off. dwc3-apple drives the DWC3
reset through this driver outside that window, and the controller runs
on the pipehandler's PIPE clock while it is out of reset: take a
reference for every register access in the reset ops, and hold one from
deassert to assert.

With the port idle, the PHY's common_dp power state can now drop, and
its parent phymxwrap with it unless the PHY coprocessor's mailbox holds
it. power_on runs the full macOS sequence from reset, so it does not
depend on the PHY registers keeping state.

Signed-off-by: Jonathan Goyvaerts <[email protected]>
Assisted-by: LLM
(cherry picked from commit 6238cae)
dwc3_core_probe() enables runtime PM and forbids it, for the dwc3
platform driver's own runtime callbacks. This glue registers none and
drives the core itself, so after the first cable the controller stayed
runtime-active for good, and with it its power domain, its DARTs and,
through the device link of its phys, the USB2 PHY: on J616s an idle
port's PHY suspended only until that port's first use.

Hold a runtime PM reference from just before the reset deassert to the
end of the shutdown (taken in dwc3_apple_core_probe() on the first
bring-up, when runtime PM gets enabled), and on T6040 allow runtime PM so
that this reference alone decides. With no cable the controller then
autosuspends after dwc3's 5 s delay: the power domain can drop, the
DARTs save and restore their state through their runtime PM callbacks,
and the PHY follows. A running host keeps the controller active through
its xHCI child as before.

Other SoCs keep the forbid: their PHY and domain behaviour across a
runtime suspend is untested here.

Signed-off-by: Jonathan Goyvaerts <[email protected]>
Assisted-by: LLM
(cherry picked from commit bd6ec04)
Implement the USB3 side of the T6040 Type-C PHY: the USB3 host attach
(mode 4) that macOS's AppleT6040TypeCPhy runs, as a second PHY
(PHY_TYPE_USB3) next to the USB2 one, plus a Type-C orientation switch.

- The orientation switch records the plug orientation tipd reports.
- power_on, which dwc3 calls from its core init: wake the PHY
  (ATCPHY_CFG power requests and their acks), apply the per-port ADT
  tunables from the device tree and the fixed dptx writes, set the
  crossbar and release the overrides of the plug's lane, then start the
  PHY coprocessor (MXWrap RUN and an RTKit boot on its "phy-cpu"
  mailbox; a wake-up on later attaches), wait until it has tuned the
  PHY (UC_TNBL_DONE) and release the PHY reset. The coprocessor places
  its buffers in its own __DATA SRAM ("cpu-data").
- set_mode(host), which dwc3-apple calls after the core init and before
  xHCI starts: move the controller's PIPE from the dummy PHY to this
  PHY inside macOS's BIST bracket. The PIPE lock is never acknowledged
  on T6040 and the switch works without it.
- power_off: park the PIPE on the dummy PHY again, send the coprocessor
  the Power Down message and put it to sleep, as macOS does on detach.

Without a plug orientation, without the device-tree parts, or when the
coprocessor does not come up, the PIPE stays on the dummy PHY and the
port keeps working at USB2; power_on never fails the core init.

Tested with an out-of-tree module running the same sequence on the
left-back port of a J616s: a SanDisk 3.2 Gen 1 stick enumerated at
5 Gb/s and read 256 MiB at 352 MB/s.

Signed-off-by: Jonathan Goyvaerts <[email protected]>
Assisted-by: LLM
(cherry picked from commit b45b086)
… PIPE

macOS applies the usb-drd tunables of the ADT after every controller
reset (applyAllTunables): DRD_USB31_GBL_DEFAULT and _GBL_HOST in the
core's global registers, the LINK_REGS and DBG blocks behind the Apple
registers and DRD_USB31_CFG_HOST in the controller's configuration block
(usb-drd reg[1]). Take them from optional apple,tunable-* properties and
apply them after every core init, since the core's soft reset undoes
them. The configuration block is an optional "drd-cfg" region.

On T6040 the core comes up against the dummy PHY. Once the USB3 PHY has
moved the PIPE, pulse GUSB3PIPECTL.PHYSOFTRST before xHCI starts, as in
the bring-up that reached 5 Gb/s. USB2 is not affected.

Signed-off-by: Jonathan Goyvaerts <[email protected]>
Assisted-by: LLM
(cherry picked from commit d04deff)

[ryan: keep the T8132 CIO-setup condition and the T8132 BIST error return]
Signed-off-by: Ryan Murray <[email protected]>
dwc3_readl() and dwc3_writel() are inline in io.h and fire the
dwc3_readl/dwc3_writel tracepoints. dwc3-apple uses them for the T6040
USB3 PIPE reset, so with CONFIG_TRACING a modular dwc3-apple fails
modpost:

  ERROR: modpost: "__tracepoint_dwc3_readl" [drivers/usb/dwc3/dwc3-apple.ko] undefined!

Export both tracepoints from the core.

Signed-off-by: Jonathan Goyvaerts <[email protected]>
Assisted-by: LLM
(cherry picked from commit c506653)
The first attach of every port reached 5 Gb/s, but every later one fell
back to USB2: after Power Down and an RTKit sleep on detach, the
coprocessor never answered the RTKit wake-up ("endpoint discovery
failed: -62").

macOS does not put it to sleep. RTBuddy(ACIOPHYn) logs "Resuming..." once
per boot, on a port's first attach, and its endpoint services stay
unchanged across unplug, flip and replug. On detach macOS only sends
Power Down. Do the same: keep RTKit running and, on the next attach, wait
for the running firmware to tune the PHY again.

A coprocessor that is not running under a live RTKit session (an earlier
driver instance, a crash), or one that does not tune the PHY, is
restarted: AppleMxWrap's stop request (~RUN), a clean RTKit state, RUN
and an RTKit boot.

Signed-off-by: Jonathan Goyvaerts <[email protected]>
Assisted-by: LLM
(cherry picked from commit 1455432)
With the coprocessor kept running, every replug on m4.21 found it
running, switched the PIPE, and the stick enumerated at USB2 only: the
firmware does not tune the PHY again for the new attach. It tunes as it
starts, for the lane in CFG_S2R_USB_LN_SWAP. When UC_TNBL_DONE is still
set from the last attach, restart the coprocessor (stop request, RUN,
RTKit boot), as already done when it does not tune at all.

Log one line per attach with the lane, whether the coprocessor was
started, restarted or found running, and UC_CTRL before and after, so a
replug can be read from the kernel log without touching the hardware.

Signed-off-by: Jonathan Goyvaerts <[email protected]>
Assisted-by: LLM
(cherry picked from commit 25a1663)
m4.22 showed that the PHY coprocessor can be neither restarted (stop
request, RUN, RTKit boot) nor woken from an RTKit sleep: it never
answers again. It has to keep running from its first start. Every replug
nonetheless found UC_TNBL_DONE still set from the last attach, while
macOS reads it as 0 before every PHY power-on: our detach never put the
PHY itself to sleep.

On detach, after Power Down, run the reverse of the power-up and the PHY
reset release, back to the state before the first attach (CFG ctrl 0x4,
AHB clock not requested). On attach, wait for the running coprocessor to
tune the PHY again, and drop the restart, which cannot work.

Log the PHY state at detach and the coprocessor state when it does not
tune, so a replug can be read from the kernel log.

Signed-off-by: Jonathan Goyvaerts <[email protected]>
Assisted-by: LLM
(cherry picked from commit 5195c7f)
m4.23 put the PHY to sleep on detach (UC_TNBL_DONE back to 0, CFG back
to 0x4/0x100), but the coprocessor, left running, did not tune the PHY
again on the next attach: every replug timed out after 1 s and stayed
at USB2.

macOS powers the embedded CPU down on detach ("couldn't power down
embedded CPU") and up again on attach (runFirmware's RTBuddy call).
Do the same in the RTKit session: apple_rtkit_idle() after Power Down,
apple_rtkit_resume_idle() on the next attach, then wait for the tune.

Signed-off-by: Jonathan Goyvaerts <[email protected]>
Assisted-by: LLM
(cherry picked from commit 2979fde)
Print the MXWrap run, idle control and status words with the error, so a
failed resume shows whether the coprocessor still runs and sits idle.

Signed-off-by: Jonathan Goyvaerts <[email protected]>
Assisted-by: LLM
(cherry picked from commit c230e57)
The Type-C switch was registered only after every USB3 resource had
been found. The DT names this node as the port's orientation switch, so
when one of them was missing or malformed the driver bound without a
switch and tipd's typec_switch_get() deferred forever: the port lost
USB2, role switching and PD too, not just USB3.

Register the switch as soon as the node is an orientation switch. Its
set callback only records the orientation; usb3_ok still gates USB3.

Fixes: 2eb691bb4 ("phy: apple: t6040: add the USB3 host attach")
Signed-off-by: Jonathan Goyvaerts <[email protected]>
Assisted-by: LLM
(cherry picked from commit 8bee5f6)
When the PHY woke but its coprocessor did not tune it in time,
power_on fell back to USB2 with usb3_up still false, so power_off
skipped the firmware power-down and the PHY sleep. The coprocessor kept
running and the PHY stayed awake, and since a running coprocessor never
retunes, every later attach of that port stayed at USB2 until reboot.

Power the firmware down (a no-op when RTKit is not running) and put the
PHY back to sleep on the fallback path.

Fixes: a34449ab6 ("phy: apple: t6040: idle the PHY coprocessor between attaches")
Signed-off-by: Jonathan Goyvaerts <[email protected]>
Assisted-by: LLM
(cherry picked from commit 2997b26)
Add the three Type-C ports of the J616s for the T6040 Type-C PHY driver
(phy-apple-t6040-usb2) and dwc3-apple:

- the PD controllers on nub-spmi-a0 (hpm0, hpm1) and nub-spmi-a1 (hpm2);
- per port the PHY with its coprocessor mailbox, the controller and its
  two DARTs;
- the PMGR domains they need: ATCn_COMMON, ATCn_USB_AON, ATCn_USB,
  ATCn_PHYMXWRAP, ATCn_COMMON_DP and NUB_SPMI_A0/A1.

Addresses, interrupts and PMGR offsets come from the T6040 ADTs (atc-phyN,
usb-drdN, dart-usbN, acio-phy-cpuN, nub-spmi-a0/a1 and the pmgr device
list), cross-checked against Jonathan Goyvaerts' J616s device tree, which
also gives the PHY region layout his driver expects. The ADT lists the
event, sleep and wake interrupts of each PD controller; select is event + 2
as in that tree.

Link: https://github.com/jgoyvaerts/linux/blob/23ecd7ba77f1a2ca06bb2ea0b895773bb5486ea1/arch/arm64/boot/dts/apple/t6040.dtsi
Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
The T6040 Type-C PHY applies the atc-phyN calibration tables at every
USB3 power-on, and dwc3-apple applies the usb-drdN controller tables after
every core reset. m1n1 does not hand these over on T6040 yet, so carry
them in the board tree.

The file is Jonathan Goyvaerts' t6040-j616s-usb3.dtsi, unchanged. Its
values come from his J616s ADT (macOS 26.6.2); the per-port PLL entries may
differ slightly between machines until m1n1 provides them.

Originally-by: Jonathan Goyvaerts <[email protected]>
Link: https://github.com/jgoyvaerts/linux/blob/23ecd7ba77f1a2ca06bb2ea0b895773bb5486ea1/arch/arm64/boot/dts/apple/t6040-j616s-usb3.dtsi
Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
Build phy-apple-t6040-usb2 as a module for the M4 Pro's USB-C ports.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
The USB2 port on the J616s Type-C ports never saw a connect: PORTSC
stayed in RxDetect with no CCS, so nothing enumerated on USB2, not even
the USB2 half of a USB3 hub, while SuperSpeed worked.

The init sequence sets SIG[14:12] and the two VBUS detect force bits.
The ADT then has a per-port tunable_USB2PHY_HOST for the same register
(offset 0x8, mask 0x7003, value 0x3) that clears SIG[14:12] again; its
device-mode twin, tunable_USB2PHY_DEV, sets them. Without the host
tunable, the PHY was left with the device-mode signal values.

Take the tunable from the device tree as apple,tunable-usb2-host,
relative to USB2 bank 0, and apply it right after the signal setup.
The post-sequence check now expects the signal bits as the tunable
leaves them. Add it to the J616s tunables for all three ports.

Tested on a J616s with a USB3 hub with a 2.4 GHz keyboard/mouse dongle on
the left-front port: the USB2 port links at high speed (PORTSC CCS,
speed 3), the hub's USB2 half enumerates as 1-1 at 480 Mb/s and the
dongle under it as a full-speed HID keyboard and mouse. SuperSpeed (2-1
at 5 Gb/s) is unchanged.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
@RyanTheTide
RyanTheTide merged commit 1aa2857 into integration/aurora Oct 23, 2026
@RyanTheTide
RyanTheTide deleted the j616s/usb-20261023 branch October 23, 2026 15:42
jgoyvaerts added a commit to jgoyvaerts/linux that referenced this pull request Oct 23, 2026
Bring in the J616s USB-C ports (aurora-silicon#403). Its Type-C nodes and this
series' GPU nodes were added at the same place in t6040-j616s.dts;
both are kept.

Signed-off-by: Jonathan Goyvaerts <[email protected]>
Assisted-by: LLM
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.

3 participants