Skip to content

Thunderbolt display on M1 Pro/Max (t600x), stacked on #8 - #64

Closed
cb2206 wants to merge 77 commits into
aurora-silicon:aurora-wipfrom
cb2206:t600x-tb-display
Closed

cb2206 wants to merge 77 commits into
aurora-silicon:aurora-wipfrom
cb2206:t600x-tb-display

Conversation

@cb2206

@cb2206 cb2206 commented Sep 30, 2026

Copy link
Copy Markdown
Contributor

Stacked on #8 (iconidentify:tb-dp-tunnel-t8103 at efafaf1). Its head branch lives in another repository, so this PR is opened against aurora-wip and shows #8's commits too. Only the last five commits are new:

  1. mux: apple-display-crossbar: let a DP IN output be pointed at its source early
  2. phy: apple: atc: run the t8103 tunnel clock sequence on t600x
  3. drm/apple: prepare crossbar and PHY before DCP hears about a tunneled display
  4. thunderbolt: apple: drive DP tunnels on t6000 and t6001
  5. drm/apple: a late clear swap at power-off is not a DCP crash

With them a Thunderbolt 3 display works on the MacBook Pro 14" M1 Pro (j314s). t6001 takes the same path but is untested.

What was wrong

On t600x the DP tunnel hook from #8 is never installed; it is keyed on apple,t8103. With only the compatible checks widened, the DP IN adapter went active, but DCP stayed silent for 5 s after Activate, every DPTX call timed out, and it gave up with link faults 22 and 24 before it ever set a link rate.

The t8103 flow leaves the crossbar's DP IN output at its idle source (dispext0) until DidChangeLinkConfig. On t8103 dispext0 is the only external pipeline. On j314s all three Type-C routes use dcpext1 (apple,typec-mux-indices = <2 2 2>), so the pipeline that was activated never saw the sink.

What this does

Before the DPTX connect, point the DP IN output at the pipeline that will drive it and wake the ATC's DP clock path (sleep overrides, PMA reset release, PCLK enables). On t600x the PHY also runs DPRX_PCLK and PCLK2 with the rate selector, and the crossbar skips the DP IN cycle-slip toggle, as omacom/linux-aurora#9 found on j316c. Both new helpers return -EOPNOTSUPP elsewhere, so t8103 and T602X behave as before.

Power-off fix (commit 5)

iomfb_poweroff() waits 50 ms for the clear swap and sets dcp->crashed on a timeout. On unplug the firmware is busy with its own power-down and answers a little later. Nothing logs it, but afterwards every atomic commit fails with -EINVAL ([CRTC:73] atomic driver check failed), and a replugged display stays dark until reboot. This is not specific to t600x. #46 changes the same lines with the same intent (warn instead of crashed = true); this one also waits 500 ms and carries on with the power-off. Whichever lands second can drop its hunk.

Tested

MacBook Pro 14" M1 Pro (j314s), LG UltraFine 5K, both left ports, thunderbolt_apple.dp_display=1:

  • cold boot with the display attached: 3840x2160@60, 10 bit
  • hotplug, and unplug followed by replug (needs commit 5)
  • suspend-to-idle and resume with the display attached (10 s sleep)
apple-display-crossbar 70304c000.mux: dpin0: source preselected, MUX_CTRL=00002002
phy-apple-atc 703000000.phy: DP tunnel open (CFG0=11833fef SLEEP_CTRL=15570cff TX_DP_CTRL0=0000e00d)
apple-dcp 28cc00000.dcp: display routed to Thunderbolt DP tunnel dpin0
apple-dcp 28cc00000.dcp: DPTXPort: SET_LINK_RATE 0x14
apple-display-crossbar 70304c000.mux: Switched dpin0 to dispext1,0
apple-dcp 28cc00000.dcp: dcp_hotplug() connected:1 valid_mode:0 nr_modes:5

The runtime tests ran on the 11.12 release tree (iconidentify/aurora-linux c0e90dc), where these files differ from #8's head only in the dp_display default. On #8's head the four modules were compile-tested only. checkpatch is clean.

Not covered

  • The display's second DP tunnel (dpin1) is still refused with port already routed (-16), so it runs as one 4K stream, not as two 2560x2880 tiles.
  • PCIe-C on t600x. I have a port of J416c: dual dock DP streams, DP connector type, and PCIe-C for Thunderbolt 3 docks (stacked on #46) #50's kernel cold-init running on this machine (the display's USB hub, audio, camera and brightness HID work), but it still uses DART tunables copied from T602x, so it is not part of this PR.
  • Not tested: t6001, the right-hand port, long suspends.

🤖 Generated with Claude Code

chriskearney and others added 30 commits September 23, 2026 01:40
A DP tunnel from the host router's DP IN adapter needs a pixel clock
from the ATC's AUSPLL. Type-C DP alt mode sets it up together with the
lanes; a tunnel has no lanes to set up, and the PHY stays in
Thunderbolt/USB4 mode.

Export apple_atc_dp_tunnel_rate(). It keeps the PHY blocks awake,
enables DPTX PCLK1 with a per-rate selector and programs a fixed AUSPLL
descriptor, without touching the lane mux. Rate 0 stops the clock: PLL
output drivers off, then an APB power-down command. The sleep/clamp
overrides and TX_DP_CTRL0 are left as they are; the next start programs
them again.

A start is refused while PLL outputs are live or a PLL request is
pending, and DP alt mode configuration is refused while the tunnel clock
runs, so the two never share the PLL. The clock is stopped before any
PHY mode change. Only t8103 is supported: the descriptor and selectors
are for that SoC.

Name the TX/RX sleep and clamp value fields next to their override
fields, and add include/linux/soc/apple/dp-tunnel.h for the functions
the Thunderbolt glue, appledrm, the ATC PHY and the display crossbar
call on each other. They are looked up with symbol_get(), so none of
these modules depends on another.

Based on Oliver Lukschander's t6020 tunnel clock work.

Signed-off-by: Chris Kearney <[email protected]>
When DCP retrains a link through a Thunderbolt DP tunnel, the crossbar
connection has to follow it. Add apple_dpxbar_link_down() and
apple_dpxbar_link_up(). They gate and ungate the clocks and enables of
an already selected output. The mux selection is left alone; link_down()
also leaves the ATC output enable set, and link_up() re-asserts it. The
caller keeps the output selected around both; the selection is read
under the crossbar lock.

Also let the clock gates release before enabling the clocks behind them,
both when an output is selected and in link_up(), and warn if they do
not.

Signed-off-by: Chris Kearney <[email protected]>
On Apple silicon the display engine is not wired to the host router's DP
IN adapters; the NHI glue has to route it there. Add an NHI op,
dp_tunnel_changed, called when a DP tunnel from a host DP IN adapter
comes up, before one is torn down, and when the connection manager stops
with such a tunnel in place. Every "down" is paired with an earlier
"up", so a tunnel released twice (at tb_stop() and by a late DPRX
failure) is only reported once.

System and runtime suspend release all DP tunnels through the normal
teardown, so the glue hears about them; they come back through plug
events after resume, which take the full path again.

Only hosts whose glue provides the op get the extra handling, and only
for their own DP IN adapters:
- after activation, pulse the DP IN adapter's HPD propagation bit
  (ADP_DP_CS_3 bit 10) and wait for ADP_DP_CS_2_HPD, at most 2 s under
  tb->lock;
- the DP IN video hop gets 5 NFC credits, including on USB4 routers;
- no LTTPR non-transparent mode on Titan Ridge DP OUT; the host DPTX
  trains the sink through the tunnel;
- the DP OUT adapter must not start link training on its own
  (ADP_DP_CS_3 bit 8) while the tunnel is up; the bit is restored on
  teardown, also when disabling the adapter fails.

The check is safe for routers without a domain, as built by the KUnit
tests.

Signed-off-by: Chris Kearney <[email protected]>
Implement dp_tunnel_changed. It is only registered when
thunderbolt_apple.dp_display=1 is given and the machine is a t8103, so
the connection manager's Apple DP handling stays off otherwise.

When a DP tunnel from a host DP IN adapter comes up:
1. Map the adapter's register block non-posted; posted writes to it take
   an SError.
2. Acknowledge and enable its interrupts.
3. Ask appledrm to route a display pipeline to it. If appledrm is still
   probing (a dock present at boot), wait for it for up to 30 s.

The adapter's DPTX_INACTIVE handshake is run from DCP's link activation
(the adapter may only be woken while DCP drives the DPTX), within one
500 ms budget per call. Before a tunnel is torn down the adapter is put
to sleep and masked synchronously, and nothing touches it after that.

Each adapter has one work item on an ordered queue that brings the
display side in line with the tunnel state, so nothing is allocated on
the way down and whatever was handed to appledrm is always taken back.
When the ACIO is stopped, the display side is released before it powers
off. The parameter is read-only at runtime.

Not covered yet: the DP IN block is found at a fixed offset from the
ACIO "rc" region (there is no device tree node for it), its interrupts
have no handler, and suspend with an active tunnel has not been
validated.

Signed-off-by: Chris Kearney <[email protected]>
Add apple_dcp_tb_dp_tunnel() for the Thunderbolt glue. It picks a free
display pipeline for the port and routes it to the crossbar's
dpin0/dpin1 output. It then out-of-band connects DPTX with the DFP port
(1/2) and the DP IN role (attribute bit 0), and reports the display as
attached.

During link setup:
- SetLinkRate starts or stops the ATC tunnel pixel clock.
- After DidChangeLinkConfiguration the crossbar connection is brought up
  and DP IN is activated. The first time this is the mux selection;
  after that only the clocks are brought back.
- Before WillChangeLinkConfiguration DP IN goes inactive and the
  crossbar clocks go down. Failures are logged and keep the crossbar
  down, so no stream is started without a clock.

Tunnel state, the clock and the crossbar are handled under one lock, so
teardown cannot race a link change, and DCP calls never block on the
mux. The lock (and hpd_mutex, which the tunnel path also reaches before
the DRM device binds) is initialized at probe. While a tunnel owns a
Type-C port, alt mode state for it is not acted on; the tunnel teardown
drops the recorded state and reconnects a fixed HDMI output if one is
live.

The Type-C DP alt mode path is unchanged: DFP port 0, role 0 and a
strict check of DCP's connection reply.

Tested on a MacBook Pro 13" M1 (j293) with a CalDigit TS3 Plus and a
Kensington SD5560T: 3840x2160 at 60 Hz over HBR2 and HBR3, unplug and
replug, monitor cable replug behind the dock, and a dock present at
boot.

Signed-off-by: Chris Kearney <[email protected]>
t8103 boots with the Thunderbolt PCIe port held in reset. Bring the
port up when the tunnel activates, and do it before the port's IOMMU
probes: that IOMMU's invalidate command does not finish while the port
clock is still gated.

Program the port tunables and the reset table, release PERST, enable
the port clock, then program the root-port configuration tunables.
Link training stays in the host driver. If the port is already
running, the host does not replay the reset table. Endpoint memory on
t8103 is left posted.

The PCIe-C IOMMU uses the 64-stream USB4 register block: 16 KiB pages,
a 32-bit IOVA and a 36-bit physical address. The 42-bit four-level
geometry remains on T8110, which is the hardware that walks it.

An xHCI early handoff no longer faults when the capability length read
from a BAR is shorter than 16 bytes or not dword-aligned.

Tested on a MacBook Pro 13" M1 (j293) with a CalDigit TS3 Plus on
USB-1. The tunnel enumerated the dock bridges, four USB host
controllers and an I210. The USB devices and a gigabit link came up,
and the display on the same port still comes up.

Signed-off-by: Chris Kearney <[email protected]>
Cable removal quiesces the PCIe tunnel and then removes the IOMMU.
The IOMMU's runtime resume and remove both issue a command, and that
command cannot complete once the port clock is gated. Every dock
unplug logged that timeout, then a follow-up quiesce skipped the port
and reported success.

Tell the IOMMU to stop issuing commands before the clock is turned
off, and let it issue them again only after the port is back up. An
acknowledgment timeout from a cable that is already gone is no longer
a failed quiesce when the local port has left the running state.

Signed-off-by: Chris Kearney <[email protected]>
Some USB-C display adapters answer the first hotplug with a 128-byte
EDID whose product name is "Non-PnP" and whose preferred mode is
1024x768. The panel timings, including 3840x2160 at 120 Hz, show up
only after HPD drops and returns. macOS ends up with the panel mode.
The first Linux modeset was keeping the placeholder.

When a Type-C output copies that EDID, pulse HPD once. A second
placeholder is left as-is, so a display that really is that mode does
not loop. The pulse is cancelled when the cable goes away.

Signed-off-by: Chris Kearney <[email protected]>
Add a second mux-control entry (index 1) per Type-C PHY crossbar to
both dcpext0's and dcpext1's mux-controls/mux-control-names, named
"typecN-usb4" alongside the existing "typecN" (direct alt-mode) entry.
These are the devicetree handles the display crossbar driver resolves
by name to select a USB4/Thunderbolt DP tunnel route (dpin0/dpin1)
rather than a direct Type-C alt-mode route, on T602X (M2 Pro) j414/j416
machines.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Add the shared header that lets the Thunderbolt/ACIO driver, the DCP
display driver, the ATC PHY and the display crossbar mux driver
cooperate on routing a DisplayPort tunnel over USB4/Thunderbolt on
Apple Silicon (starting with T602X/j416s).

The four declared entry points cover the full path a tunneled DP
stream takes: apple_dcp_tb_dp_tunnel() lets Thunderbolt hand a DP IN
adapter's crossbar output to DCP (or take it back) and runs DCP's
DPTX_INACTIVE handshake via a callback; apple_atc_dp_tunnel_rate()
starts or stops the PHY's pixel clock at a given DP link rate once the
PHY is in USB4 mode; and apple_dpxbar_link_down()/apple_dpxbar_link_up()
let an already-selected crossbar output be quiesced and restored
around a link reconfiguration without disturbing the mux selection.

None of the four providers is a build-time dependency of the others:
each caller resolves its counterpart with symbol_get()/symbol_put(),
so the four drivers can each be loaded independently. This header
keeps those calls type-checked against a single declaration.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Give struct tb_nhi_ops three new optional callbacks -- dp_tunnel_pre_activate,
dp_tunnel_post_activate and dp_tunnel_deactivate -- mirroring the existing
pci_tunnel_* hooks, so a platform NHI driver can observe and participate in
DP tunnel bring-up and teardown: pre_activate runs after DP hops are
programmed but before VE/AE are enabled, post_activate runs once the
adapters are enabled, and deactivate runs when the tunnel comes down.
Export tb_cfg_read() into the USB4 symbol namespace alongside the
already-exported tb_cfg_write(), since an out-of-tree platform NHI driver
implementing these hooks needs tb_port_read()/tb_port_write().

Fix tb_dp_activate() to not abort the rest of its teardown sequence when
disabling one adapter fails: once a port is marked unplugged,
tb_port_read()/tb_port_write() short-circuit to -ENODEV, so a departing
DP OUT adapter always makes the disable call "fail" during a hot-unplug
teardown. Only bail out early when actually activating; keep going on
deactivate regardless of an individual adapter's error, since
tb_tunnel_deactivate() already discards this function's return value and
callers rely on the rest of the teardown running.

Add Apple silicon host DP IN/OUT adapter support, gated on the NHI being
compatible with "apple,t8103-usb4-nhi" (the family also used by
T6020/M2 Pro) so it has no effect on non-Apple hardware. Apple hosts need
several deviations from the standard USB4 DP tunnel sequence: the DP IN
adapter has no physical connector wired to its own hotplug-detect line,
so pulse ADP_DP_CS_3_HPD_PROPAGATE after activation to make it propagate
HPD itself; the sink is trained by the host's DPTX through the tunnel
rather than by the DP OUT adapter's own link training, so hold
ADP_DP_CS_3_NO_AUTO_LT set on DP OUT for the tunnel's lifetime; the
host-side DP IN adapter needs a fixed 5 NFC credits on the video path
rather than the standard credit-allocation formula; on some ports the DP
IN adapter never raises a bandwidth-allocation request notification as
the spec expects, so grant its already-computed non-reduced bandwidth
immediately once capped at what the connection manager reserved; and
because Apple's DPTX negotiates AUX capability through the DP IN adapter
only after the tunnel's paths already exist, treat the tunnel as active
as soon as its paths are programmed and keep it up across a DPRX
capability-read timeout rather than tearing it down.

Add an off-by-default dp_video_counter module parameter that turns on
hardware packet counters on the DP video path for debugging, readable
through the existing debugfs port counter files.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Wire up the tb_nhi_ops dp_tunnel_pre_activate/post_activate/deactivate
hooks so a DisplayPort tunnel programmed by the Thunderbolt connection
manager -- whether the monitor hangs off the host router directly or
off a Thunderbolt/USB4 hub -- gets a real display pipeline attached,
instead of only working through direct HDMI or a USB-C alt-mode
adapter as before.

Add a small, self-contained helper (apple-dpin-handshake.h) that drives
the ACIO DP IN adapter's DPTX_INACTIVE register handshake: HPD/CONTROL/
ACK plus the two link-rate mode fields that must be programmed before
the adapter's crossbar output will pass a real display signal. The
link-rate value is an empirically-determined estimate rather than a
value confirmed against any spec or reference implementation; it is
exposed as a module parameter (dpin_mode_value, default matching the
value confirmed working on T602X/M2 Pro hardware) rather than hardcoded,
in case other Apple silicon generations need a different value.

apple_cio gains the Type-C connector node this router is wired to
(found via the port@1 OF-graph endpoint to the PD controller) and a
per-adapter context with its own lock, mapped-register pointer and
lifetime flags, driven from a dedicated ordered workqueue so tunnel
up/down events are serialized and never lost. When a tunnel activates,
the driver maps the relevant DPIN handshake register block and calls
into the DCP display driver's apple_dcp_tb_dp_tunnel() (resolved via
symbol_get()/symbol_put(), so neither module hard-depends on the other
being loaded) with a callback that runs the DPTX_INACTIVE handshake at
the point DCP itself decides to bring the link up or down; a bounded
retry loop covers DCP still probing when a dock is already present at
boot. Deactivation reverses this in mirror order once the Thunderbolt
core has already disabled both tunnel adapters.

Give apple_cio's RTKit ops a recv_message callback that logs any
message the ACIO M3 coprocessor sends unprompted, for visibility into
ACIO's own asynchronous notifications.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Add afk_send_command_timeout()/afk_service_call_timeout(), which take
an explicit reply timeout instead of the existing functions' hardcoded
one second, and rework afk_send_command()/afk_service_call() as thin
wrappers over them at the previous default. A Thunderbolt DP tunnel's
AUX proxying round-trip for an HPD-assert reply can take longer than a
direct-PHY connection's one-second budget, and the caller needs to
widen just that one call rather than every AFK command in the driver.

Add dev_warn() logging on the failure paths (handler error, timeout,
non-zero retcode, reply magic/group/command mismatch) and a dev_dbg()
on success, so a failed AFK round trip is diagnosable without needing
to instrument individual call sites.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Add core routing support for a USB4/Thunderbolt DisplayPort tunnel
arriving behind a Thunderbolt hub, as opposed to a direct Type-C DP
alt-mode connection. struct apple_dcp_typec_route grows a tunnel flag,
an active_xbar pointer distinct from the route's own crossbar control,
a tunnel_dpin index and an xbar_up flag, so dcp_typec_route_activate()/
deactivate() can be handed the crossbar control to actually use: for a
tunnel this is a dpin0/dpin1 controller resolved at tunnel-creation
time rather than the route's own dpphy control, and the mux selection
for it is deferred until the tunnel pixel clock is confirmed running
rather than issued immediately.

Add apple_dcp_tb_dp_tunnel(), the entry point Thunderbolt calls once
it has stood up a DP IN tunnel: it finds a free Type-C route on the
target port and activates it as a tunnel. A Type-C-only pipeline (no
fixed output of its own) never completes link training for a tunneled
target on this hardware -- DCP firmware accepts request_display but
never issues the follow-up apcall, despite byte-identical connect
parameters, a firmware-internal decision on that coprocessor instance
with no driver-source asymmetry to explain it. A pipeline with a fixed
output of its own reliably reaches a full AUX/DPCD link, so route
scoring prefers it unconditionally for a tunnel route on this hardware.

Add dcp_tunnel_crossbar_up()/down()/set_rate()/dpin_activate(), the
hooks the DPTX endpoint uses to keep the crossbar clocks and the DP IN
adapter's active state in step with DCP's link (re)configuration,
serialized by a new per-DCP tb_lock. Make the Type-C alt-mode mux
callback leave a tunnel-owned port alone -- a tunnel is torn down by
apple_dcp_tb_dp_tunnel() itself, not by an alt-mode notification, and
reapplying a stale alt-mode state on top of one would fight it.

Thread the DFP port selected by route activation through
dcp_dptx_connect() into the DPTX validate/connect calls, which
previously always targeted DFP port 0 -- this is what makes a tunneled
connection train against the Thunderbolt DP IN adapter DCP was
actually told to use, rather than the direct PHY. Widen
DPTX_CONNECT_TIMEOUT from 2s to 8s and the Type-C HPD-assert wait to
8s, and drop DPTX_RECONNECT_RETRIES from 5 to 1: a tunneled
connection's handshake round-trip through the DP IN adapter can
outlast a direct-PHY connection's budget.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
A Thunderbolt/USB4 DisplayPort tunnel reaches the same DCP DPTX
AFK/EPIC endpoint as a direct HDMI or USB-C alt-mode PHY, but several
request/reply shapes and side effects differ: the endpoint has no
local ATC DisplayPort PHY to configure, the pixel clock and display
crossbar connection are owned by the Thunderbolt tunnel infrastructure
instead of being driven directly, and firmware's link-training
sequencing includes calls (INACTIVE_SINK_DETECTED, FORCE_HOTPLUG_DETECT,
GET_ACTIVE_LANE_COUNT) that the direct-PHY path never exercises.

Factor VALIDATE_CONNECTION/CONNECT's remote-port target computation
into dptxport_remote_target(), and add a tunnel "role" attribute bit
that lets firmware distinguish a Thunderbolt DP-IN route from a direct
PHY; tolerate the resulting difference in firmware's attrs reply only
for a tunnel route, still rejecting a mismatch for the direct-PHY case.
Treat a NULL dptx->atcphy (the USB4 DP-IN service has no ATC PHY of
its own) as "report a fixed 4 lanes, skip phy_configure()" in
GET_MAX_LANE_COUNT/SET_ACTIVE_LANE_COUNT. Route SET_LINK_RATE, ACTIVATE
and DEACTIVATE through the dp-tunnel.h API for a tunnel connection
instead of touching the ATC PHY's DP mode or rate registers directly --
the PHY must stay in USB4/Thunderbolt mode for the life of the tunnel.
Bring the tunnel's display crossbar connection down before a re-link
and back up once it completes, and handle GET_ACTIVE_LANE_COUNT,
FORCE_HOTPLUG_DETECT and INACTIVE_SINK_DETECTED explicitly rather than
relying on the generic unhandled-call ACK. Add
dptxport_set_hpd_timeout() so a caller can widen the AFK reply timeout
for the HPD-assert call, since a tunnel's AUX proxying round-trip can
be slower than a direct PHY's.

dcp_hotplug()'s forced link-status retrain recovers a connector that
reports connected without a valid mode set yet, for a Type-C route
switch that can drop the active mode without changing HPD state. A
USB4 tunnel connector's link comes up through the DPTX endpoint's own
crossbar/clock sequencing rather than a Type-C route switch, so
restrict that recovery path to non-tunnel connectors.

Trace the read_edt_data and property-dictionary DCP callbacks' key,
size and result for any connector other than the fixed eDP panel, and
include the firmware-reported mode count in the existing hotplug log
line, to make the boot-property and mode-list exchange with firmware
observable for a tunnel connector.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
apple_dpxbar_set_t602x() only ever programmed the DPPHY fields of the
mux control register and its ATC bit, regardless of which of the three
physical outputs (dpphy, dpin0, dpin1) was actually selected. Selecting
dpin0 or dpin1 therefore only updated driver-internal bookkeeping
without ever routing analog onto the ACIO DP IN pins, and the
enable/disable paths never touched the enable bits the generic
(non-T602X) crossbar path does.

Add helpers to resolve the correct ATC bit and mux-select field for
the index actually being switched, and use them in both the enable and
disable sequences, including the enable-bit sequencing that was
previously only done for the generic crossbar. Reject an out-of-range
index up front rather than proceeding with an unresolved mux mask.

Add apple_dpxbar_link_up()/apple_dpxbar_link_down(), exported for the
DCP driver to reach through symbol_get()/symbol_put() so the crossbar
driver does not need to be a hard module dependency of the display
driver. A Thunderbolt DP tunnel re-link needs to bounce the crossbar's
clock/FIFO gates on an output that is already selected, without
reselecting the mux or dropping the enable bits -- a full teardown/
re-enable would drop the route entirely. Both functions operate on
whichever output the mux already has recorded as selected.

DPIN0's field masks and ATC bit are hardware-confirmed on T602X/M2 Pro;
DPIN1's are filled in by the same per-index resolution by symmetry
with DPPHY/DPIN0's layout, not by independent confirmation on real
hardware -- flagging this here since getting a field encoding wrong on
this hardware is silent (no error, just no picture).

Co-Authored-By: Claude Sonnet 5 <[email protected]>
On T602X (M2 Pro, j416s) Type-C PHYs, a monitor connected directly via
DP alt-mode or a USB-C-to-HDMI adapter already works, because that
path drives the AUSPLL through the PHY's normal per-mode configuration
table. A monitor connected through a USB4/Thunderbolt hub instead
carries DisplayPort as a tunneled stream over the USB4 link, and the
DCP display coprocessor firmware expects the PHY driver to hand it a
dedicated tunnel pixel clock on request, outside the normal
mode-configure path. Nothing implements that request today, so a
tunneled display never gets a clock and stays dark even though the
USB4 link itself comes up.

Add the tunnel clock state machine: atc_tunnel_start() brings up the
fixed AUSPLL frequency descriptor and PCLK1 output for one of the four
standard DisplayPort link rates, after a preflight read of the
gate/output/lock registers confirms the PHY is in the specific idle
state this sequence expects (refusing with -EBUSY otherwise rather
than clobbering live state). Before touching anything it snapshots the
registers it is about to modify; atc_tunnel_restore() replays that
snapshot in reverse to undo the sequence, and is called unconditionally
at the top of atcphy_configure() so any mode change, power-down, or
unplug leaves the tunnel registers exactly as it found them instead of
stuck mid-sequence, and clears the request-guard state so a later
tunnel request is not permanently refused by a stale in-progress flag.
It also waits for ACIOPHY_AUSPLL_LOCK to clear before returning: a
request landing right after a teardown -- a live replug is fast enough
to do this, and so is DCP firmware's own retry cadence -- would
otherwise see the PLL's own not-yet-settled lock bit and refuse itself
as busy, indefinitely.

Expose this through a new exported apple_atc_dp_tunnel_rate(phy, rate)
-- the exact symbol name drivers/gpu/drm/apple/dcp.c resolves via
symbol_get() to ask a PHY for a tunnel clock. It is gated to
apple,j416s machines and to ATC cores that are both a t6020-atcphy and
a recognized Type-C core address, so it is a correctly-typed no-op
everywhere else, and only proceeds while the PHY is already in USB4 or
TBT mode.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
…tention

apple_cio_start()'s reset_control_deassert(acio->reset) is a
request/ack handshake with the M3/PMGR firmware (100ms budget, no
.assert op to fall back on). Confirmed via live journalctl/dmesg to
time out on resume from suspend with an active USB4 tunnel connected,
during the wider resume storm every other coprocessor on the SoC is
also going through. Retry up to APPLE_CIO_START_RETRIES (5) times,
100ms apart, before giving up.

No new code path, no suspend/resume PM hook added -- deliberately not
attempting the more invasive fix (giving apple_cio_driver its own PM
hooks), since apple_cio_tbt_switch_set() documents that an invalid
direct cable-state transition can crash ACIO and trigger an SoC
watchdog reset, and a second independent stop()/start() trigger around
the same suspend/resume window as the Type-C mux's own decision risks
exactly that. This only widens how persistently the existing,
already-serialized call waits for the firmware to answer.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
…eeded

Building on the previous commit (ACIO/Thunderbolt itself now survives
suspend): the display still didn't come back on its own after resume,
only after a physical unplug/replug of the dock. tipd_resume() never
re-verified the port's actual attach state -- it only checks firmware
liveness and re-arms the IRQ. A cable that was never physically
removed generates no fresh attach event, so nothing re-drives
apple_cio_tbt_switch_set()/apple_cio_start(), even though
thunderbolt-core's own tb_resume_noirq() -> tb_free_invalid_tunnels()
had already silently torn down the live DP tunnel underneath it
(confirmed generic thunderbolt-core behaviour, not Apple-specific).

A naive "just re-verify and re-assert the same state" fix is a no-op:
apple_cio_tbt_switch_set()'s first check is
target_cable_info == current_cable_info, and current_cable_info is
only ever written inside apple_cio_start()/apple_cio_stop() themselves
-- re-detecting the same, unchanged cable computes the same target and
hits that early return immediately.

Added cd321x_resume_reverify(), wired only into the Apple-specific
CD321x/sn201202x vtables (the plain TI TPS6598X/TPS25750 variants are
unaffected). It reproduces a genuine unplug-then-replug entirely
through the existing, already-hardware-validated connect() code path:
calls the existing connect() callback twice -- once with
TPS_STATUS_PLUG_PRESENT cleared (a synthetic disconnect), then once
with the real, unmodified status. Both land on the same debounced
cd321x_update_work(), coalescing into a single run with
was_disconnected=true and the correct final state: the exact same
typec_thunderbolt_switch_set() OFF-then-back-on sequence, through the
exact same apple_cio_tbt_switch_set() guard, a real physical replug
already exercises every time someone does it by hand. The synthetic
disconnect always drives through a clean zero state first, the same
shape apple_cio_tbt_switch_set()'s own watchdog-reset warning already
treats as safe (a direct transition between two different nonzero
cable-info states, with no shutdown in between, is what it warns
against).

Triggered from a PM_POST_SUSPEND notifier rather than directly from
tipd_resume(): tipd_resume() is just one individual device's own
.resume() callback, with no guarantee the rest of the system (ACIO/
Thunderbolt in particular) has finished its own resume work yet.
PM_POST_SUSPEND is delivered strictly after dpm_resume_end(), i.e.
after every device has completed its own ordinary resume, which
matters here specifically: driving the reconnect too early can fire
apple_cio_start()'s M3/PMGR reset-deassert handshake while that
firmware is still busy servicing other subsystems' resume, and
exhaust its retry budget outright. A real physical replug never hits
this, because a human always does it seconds after the whole system
has visibly settled.

Confirmed on hardware: real lid-close/s2idle/lid-open cycle, hub never
touched. dmesg shows the full automatic chain (PM_POST_SUSPEND ->
synthetic disconnect and reconnect -> tunnel connect -> modeset)
succeeding with zero ACIO start retries, and the picture returns with
no replug and no manual intervention.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Keep the t8103 and T602X PLL, DP IN handshake and crossbar sequences separate. Retain the M1 PCIe initialization, IOMMU teardown and EDID retry fixes while incorporating the M2 routing, AFK timeouts and resume recovery from Aurora PRs aurora-silicon#14 and aurora-silicon#25.
Track whether the NHI post-activation hook has acquired display state,
including partial setup. Release it once before disabling adapters and
when the domain stops, while the host router is still accessible. Put
the Apple DP IN adapter to sleep before marking its context dead.

Add KUnit coverage for repeated cleanup after domain removal and cleanup
without a prior host activation.

Signed-off-by: Chris Kearney <[email protected]>
Take the port mutex while reading status and scheduling the synthetic
disconnect/reconnect so the PM notifier cannot race the IRQ and debounce
workers.

Signed-off-by: Chris Kearney <[email protected]>
Retain the M1 link-status handling when combining the two display
series. Document the T602X PHY state carried alongside the M1 clock
state.

Signed-off-by: Chris Kearney <[email protected]>
Sample the optional analog diagnostic at tunnel activation instead of
dereferencing a global controller from sysfs. Disable AUX work before
domain removal so racing activation cannot rearm it.

Use an explicit host DP credit quirk for both allocation and
programming, including j416s without the M1 notification hook. Cover the
quirk with KUnit and document the diagnostic parameters.

Signed-off-by: Chris Kearney <[email protected]>
Identify each Type-C connection when queuing a placeholder EDID retry
and serialize HPD pulses with disconnect. Drain stale retries before
reusing a route.

Disable delayed display work before endpoint shutdown or suspend, then
balance the enable on bind and resume. Keep work disabled before the
component binds and retry a cable already routed at boot. Use the
selected connection timeout when reporting elapsed time.

Signed-off-by: Chris Kearney <[email protected]>
Leave a failed restart quiesced and retryable instead of rescanning and
clearing bus_stopped after a reset or link timeout. Resume DART commands
only after the ports have restarted.

Allow DART-disabled builds through no-op stubs, and constrain Apple PCIe
to a module when its optional DART provider is modular.

Signed-off-by: Chris Kearney <[email protected]>
DCP can request a new nonzero link rate during retraining. Restore the
descriptor owned by this tunnel and start the requested rate through the
guarded T602X sequence instead of permanently refusing it as busy. Keep
rejecting clocks owned by another user.

Signed-off-by: Chris Kearney <[email protected]>
Type-C routes are registered before the DRM component binds. Their score
is UINT_MAX-1 until a CRTC exists; adding the j416s preference penalty
wraps it to 98 and can select an unbound, nonpreferred pipeline first.
Keep the sentinel score intact when applying the preference.

Signed-off-by: Chris Kearney <[email protected]>
Booting the T8140 DART changes on an M1 j293 fails the display DART
reservations with -EIO before attach_dev(). Domain finalization copies
prospective stream IDs into the active bitmap, so the new strict root
synchronization runs before the locked roots have been mapped.

Leave the active stream bitmap empty until attachment, and skip TLB
synchronization and teardown for domains with no attached streams.

The legacy M1/M2 display handoff also requires replacing the firmware
root with Linux's page tables after the IOMMU core reconstructs reserved
mappings. Requiring vacant root slots instead rejects this handoff with
-EBUSY. Restore replacement for legacy DARTs, tracking the installed
entries for teardown, while retaining firmware-owned slot protection
for T8110 version 2.2 and newer.

Add KUnit coverage for pre-attachment reserved mapping, legacy root
handoff, and preservation/conflict handling on newer firmware roots.
The pre-attachment and handoff tests fail on the unmodified driver and
pass with this fix; all 42 Thunderbolt tests also pass.

Fixes: 7937979 ("iommu/apple-dart: Support T8140 DARTs and firmware-owned stream roots")
Signed-off-by: Chris Kearney <[email protected]>
cb2206 and others added 2 commits September 30, 2026 09:54
The M1 Pro/Max ATC has the t8103 DP IN adapter registers, the same
crossbar and the same tunnel pixel clock sequence. Install the DP tunnel
hook there too, and clear the DP IN interrupt status the way t8103 does.

Tested on a MacBook Pro 14" M1 Pro (j314s) with an LG UltraFine 5K on
both left ports: 3840x2160@60 at cold boot, on hotplug and after
suspend-to-idle. t6001 is untested.

  apple-display-crossbar 70304c000.mux: dpin0: source preselected, MUX_CTRL=00002002
  phy-apple-atc 703000000.phy: DP tunnel open (CFG0=11833fef SLEEP_CTRL=15570cff TX_DP_CTRL0=0000e00d)
  apple-dcp 28cc00000.dcp: display routed to Thunderbolt DP tunnel dpin0
  apple-dcp 28cc00000.dcp: DPTXPort: SET_LINK_RATE 0x14
  apple-display-crossbar 70304c000.mux: Switched dpin0 to dispext1,0
  apple-dcp 28cc00000.dcp: dcp_hotplug() connected:1 valid_mode:0 nr_modes:5

The second DP tunnel of the display is still refused ("port already
routed"), so it runs as a single 4K stream, not as two 5K tiles.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Christian Bartels <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
iomfb_poweroff() waits 50 ms for the clear swap and sets dcp->crashed
when that times out. When a Thunderbolt display is unplugged, the
firmware is busy powering the external pipe down on its own and answers
the swap a little later. Nothing logs the timeout, but from then on
dcp_crtc_atomic_check() fails every commit with -EINVAL, so a replugged
display stays dark until reboot:

  [CRTC:73] atomic driver check failed

A real firmware crash is reported through the RTKit crash callback. Wait
500 ms, warn on a timeout and carry on with the power-off.

Seen on j314s with an LG UltraFine 5K: unplug, then replug. With this
change the unplug logs "dcp_poweroff() done" and the display comes back
on replug.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Christian Bartels <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@brendonrogers

Copy link
Copy Markdown

Tested: Apple Studio Display at full 5K on MacBook Pro 14" M1 Pro (j314s)

Works at 5120x2880 @ 60 Hz, 10-bit, over a single DP tunnel (dpin0). The Studio Display doesn't need the second tunnel the UltraFine 5K uses, so the dpin1 limitation doesn't apply here.

Setup

  • MacBook Pro 14" M1 Pro (j314s / t6000), left rear Thunderbolt port
  • Apple Studio Display (Thunderbolt 3)
  • Kernel: this branch at 5d524a478, built with the running linux-aurora 7.1.12 config, thunderbolt_apple.dp_display=1
  • m1n1 stage 1 v1.5.2, stage 2 v1.6.1-omarchy.aurora1, system firmware 26.4
  • Omarchy (Asahi ALARM), Hyprland

Result

  • Display attached at boot: picture comes up, Hyprland sees USB-1 as Apple Computer Inc StudioDisplay
  • Modes offered: 5120x2880, 3840x2160, 2560x2880, 2560x1440, 1920x1080 (all 60 Hz)
apple-dcp 28cc00000.dcp: display routed to Thunderbolt DP tunnel dpin0
apple-display-crossbar 70304c000.mux: Switched dpin0 to dispext1,0
apple-dcp 28cc00000.dcp: dcp_dptx_connect(port=0) target=0:0 typec=1 route=borrowed conn_type=20 connected=1
apple-dcp 28cc00000.dcp: set_digital_out_mode(color:48 timing:43) "5120x2880": 60 936000 5120 5128 5160 5200 2880 2986 2994 3000 0x48 0x0
apple-dcp 28cc00000.dcp: set_digital_out_mode() color mode depth:10 format:0 colorimetry:16 eotf:0 range:0 vrr:0

Not working (expected, outside this PR): camera, speakers, mics and the display's USB ports. PCIe-C is refused because my m1n1 doesn't do the preinit handoff:

thunderbolt-apple-acio 701ac0000.cio: PCIe-C tunnel disabled: m1n1 handoff is not initialized
thunderbolt-apple-acio 701ac0000.cio: error -ENODEV: PCIe-C requires a successful m1n1 preinit handoff

Not tested yet: hotplug, sleep/wake, right-hand port.

For comparison, the same Studio Display with packaged linux-aurora 7.1.12.aurora2-11 (no dp_display param) set up the DP tunnel but never activated it (0:5 <-> 1:10 (DP): not active, tearing down).

Thanks for this work!

@brendonrogers

Copy link
Copy Markdown

Follow-up: hotplug, all three ports and sleep/wake with the Studio Display

Same setup as my comment above (MacBook Pro 14" M1 Pro j314s, Studio Display, this branch at 5d524a478, thunderbolt_apple.dp_display=1).

Hotplug and both left ports work. Unplugged and replugged into the other left port; picture back at full 5K ~9 s after plug-in. The link runs at HBR3, 4 lanes.

Port Controller Target Output Result
Left (first) cio@701ac0000 0:0 USB-1 ✅ 5120x2880@60, 10-bit
Left (second) cio@b01ac0000 0:1 USB-2 ✅ 5120x2880@60, 10-bit
Right cio@f01ac0000 0:2 — ❌ no picture

Right-hand port fails: HPD never propagates, then DCP DPTX calls time out and the tunnel is torn down after 12 s.

thunderbolt-apple-nhi f01f00000.nhi: 0:5: HPD did not propagate
apple-dcp 28cc00000.dcp: allocated Type-C DPTX PHY 2
apple-dcp 28cc00000.dcp: display routed to Thunderbolt DP tunnel dpin0
apple-dcp 28cc00000.dcp: dcp_dptx_connect(port=0) target=0:2 typec=1 route=borrowed conn_type=20 connected=0
thunderbolt-apple-acio f01ac0000.cio: dpin0: no DPTX_INACTIVE_ACK=0 (ack=00000001)
apple-dcp 28cc00000.dcp: AFK[ep:2a]: AppleDCPDPTXRemotePort (chan:1) command type 0xc0 tag 0x1100 timed out after 1000 ms
apple-dcp 28cc00000.dcp: dcp_dptx_connect: failed to assert Type-C HPD: -110
apple-dcp 28cc00000.dcp: dcp_dptx_connect: failed to validate DPTX target 0:2: -110
apple-dcp 28cc00000.dcp: DPTXPort: firmware reports link fault 22 on target 0:2
apple-dcp 28cc00000.dcp: DPTXPort: firmware reports link fault 24 on target 0:2
thunderbolt-apple-nhi f01f00000.nhi: 0:5 <-> 1:10 (DP): not active, tearing down

The failure isn't sticky: replugging into a left port afterwards brings the display straight back at 5K, no reboot needed.

Sleep/wake works (short s2idle, ~75 s): on resume the TB link drops and the display re-enumerates. The first dcp_dptx_connect times out, then it reconnects and the picture is back at 5K ~3.5 s after PM: suspend exit. No replug needed.

22:20:30.68 PM: suspend exit
22:20:31.18 thunderbolt 0-1: device disconnected
22:20:32.73 apple-dcp 28cc00000.dcp: dcp_dptx_connect: timed out waiting for port 0 link configuration
22:20:33.54 thunderbolt 0-1: Apple Inc. Studio Display
22:20:34.17 apple-dcp 28cc00000.dcp: set_digital_out_mode(color:48 timing:43) "5120x2880": 60 ...

Still not working (as before): camera, speakers, mics and USB on the display, because PCIe-C is refused without the m1n1 preinit handoff.

Not tested yet: longer sleeps.

@cb2206

cb2206 commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

Right-hand port works here with an LG UltraFine 5K (j314s)

Same machine (MacBook Pro 14" M1 Pro, j314s). I hotplugged an LG UltraFine 5K from the first left port into the right-hand port. Picture came up at 3840x2160@60, 10-bit, as USB-3, and no HPD did not propagate, no -110, no link faults:

apple-display-crossbar f0304c000.mux: dpin0: source preselected, MUX_CTRL=00002002
apple-dcp 28cc00000.dcp: display routed to Thunderbolt DP tunnel dpin0
thunderbolt-apple-acio f01ac0000.cio: dpin0: active (status=00000004)
apple-display-crossbar f0304c000.mux: Switched dpin0 to dispext1,0
thunderbolt-apple-acio f01ac0000.cio: dpin0: DP tunnel up
apple-dcp 28cc00000.dcp: dcp_dptx_connect(port=0) target=0:2 typec=1 route=borrowed conn_type=20 connected=1
apple-dcp 28cc00000.dcp: set_digital_out_mode(color:43 timing:38) "3840x2160": 60 522610 ...

Replug on the right-hand port also works. Unplug gives a clean dpin0: DP tunnel down. On replug the first dcp_dptx_connect reports connected=0, the next one ~6 s later connected=1, and the picture is back ~7 s after plug-in without any intervention:

23:15:30.993 thunderbolt-apple-acio f01ac0000.cio: set cable state: 1
23:15:32.386 apple-dcp 28cc00000.dcp: dcp_dptx_connect(port=0) target=0:2 typec=1 route=borrowed conn_type=20 connected=0
23:15:32.487 thunderbolt-apple-acio f01ac0000.cio: dpin0: DP tunnel up
23:15:38.252 apple-dcp 28cc00000.dcp: dcp_dptx_connect(port=0) target=0:2 typec=1 route=borrowed conn_type=20 connected=1
23:15:38.254 apple-dcp 28cc00000.dcp: set_digital_out_mode(color:43 timing:38) "3840x2160": 60 ...

The second tunnel (dpin1, 0:6 <-> 1:11) fails with -16 and is torn down after ~12 s. That's expected: the UltraFine's 5K mode needs it, and this PR only drives one.

Differences from your setup that might matter:

  • Display: LG UltraFine 5K (Alpine Ridge) vs. Studio Display.
  • Kernel: this branch at 5d524a478 plus an experimental PCIe-C cold init (kernel-side, no m1n1 handoff) and an unrelated EDID fix, thunderbolt_apple.dp_display=1. With it, PCIe-C also comes up on the right-hand port (usb4-pcie-tunnel-2, pcie@f30000000) and the LG's USB devices (hub, audio, controls, camera) enumerate, on first plug and after the replug.

So the right-hand port path itself (f01ac0000 / f0304c000, target 0:2) works on j314s. Your HPD failure is likely specific to the Studio Display or to running without PCIe-C. If you can, a log with thunderbolt.dyndbg=+p on the right-hand port would help narrow it down.

@brendonrogers

Copy link
Copy Markdown

I thought I'd try this morning with the debug log line and after I woke the laptop from sleep the right port just worked. Can't thank you enough for this work.

Couldn't reproduce the right-port failure with thunderbolt + thunderbolt_apple dyndbg enabled. Seven plugs in a row all came up at 5120x2880@60, ~0.6 s after detection, with no HPD did not propagate, -110 or link faults. That includes the exact sequence that failed before (second left port b01ac0000 → right port f01ac0000) three times, plus a right → right replug:

Time Port Result
06:34:32 left b01ac0000 (0:1) ✅
06:34:47 right f01ac0000 (0:2) ✅
06:35:00 left b01ac0000 (0:1) ✅
06:35:11 right f01ac0000 (0:2) ✅
06:35:23 right f01ac0000 (0:2), replug ✅
06:35:34 left b01ac0000 (0:1) ✅
06:35:45 right f01ac0000 (0:2) ✅

I'll keep dyndbg on and post a log if it happens again.

One thing that shows up on every connection, on both ports, right after the mux switch:

apple-display-crossbar f0304c000.mux: Switched dpin0 to dispext1,0
apple-dcp 28cc00000.dcp: set_active_lane_count: unexpected lane count:4 phy: 0

It doesn't stop anything working, but it reports phy: 0 even when PHY 1 or 2 was allocated.

@chriskearney

Copy link
Copy Markdown
Contributor

@cb2206 I've ported these five commits onto #8 (947026902232), on top of DjDeveloperr's dual-stream series from #46. You stay author, and each has a short port note. Your clear-swap fix replaced #46's early return. One edit: I reworded the cycle-slip comment and commit message to describe the observed behaviour without naming macOS internals. t600x also takes #8's dp_display=1 default. A j314s run with the UltraFine on the new head would confirm it. If it holds, this PR could close in favour of #8.

@cb2206

cb2206 commented Oct 2, 2026

Copy link
Copy Markdown
Contributor Author

Closing: these 5 commits are now in #8 (head 99a5545), and the j314s LG run on that head passes. Results are on #8.

@cb2206 cb2206 closed this Oct 2, 2026
DjDeveloperr pushed a commit that referenced this pull request Oct 15, 2026
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.

4 participants