Skip to content

[follow-up to #8] drm/apple: expose and enforce the routed Type-C CRTC - #193

Merged
RyanTheTide merged 91 commits into
aurora-wipfrom
fix/pr8-review
Oct 8, 2026
Merged

RyanTheTide merged 91 commits into
aurora-wipfrom
fix/pr8-review

Conversation

@RyanTheTide

Copy link
Copy Markdown
Contributor

Dual-stream machines kept advertising every candidate CRTC after the
fabric assigned a connector to one pipeline. An explicit atomic commit
could select the other advertised CRTC and send its framebuffer to a
different physical display.

Publish the active pipeline mask for dual-stream ports as well as
single-stream ports, including routes adopted during DRM binding.
Restore the candidate mask only while the connector is disconnected
and unrouted. Validate the requested CRTC against the actual connector
owner in atomic encoder selection, so stale userspace topology fails
rather than driving another output. The route planner still uses its
separate candidate mask; clients can discover the valid assignment by
re-reading encoder topology on hotplug.

Follow-up to #8; original contributor commits are preserved. These fixes are based on public Linux/PR source and Linux-side tests.

Validation: full arm64 Image, modules and DTB build passed; strict checkpatch passed for the final code changes with only the required Assisted-by trailer diagnostic excluded. Deterministic source-extracted regression tests passed, with the original implementation failing the relevant negative control.

Hardware qualification on aurora-edge is pending. No boot, suspend, fault-injection or firmware recovery pass is claimed. The publication gate is separate from runtime acceptance.

Any outstanding contributor certification on the original PR remains outstanding; no contributor sign-off was added by this follow-up.

🤖 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 <303316+iconidentify@users.noreply.github.com>
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 <303316+iconidentify@users.noreply.github.com>
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 <303316+iconidentify@users.noreply.github.com>
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 <303316+iconidentify@users.noreply.github.com>
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 <303316+iconidentify@users.noreply.github.com>
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 <303316+iconidentify@users.noreply.github.com>
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 <303316+iconidentify@users.noreply.github.com>
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 <303316+iconidentify@users.noreply.github.com>
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 <noreply@anthropic.com>
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 <noreply@anthropic.com>
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 <noreply@anthropic.com>
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 <noreply@anthropic.com>
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 <noreply@anthropic.com>
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. Add dptxport_set_hpd_timeout()
for that HPD-assert call, so a caller can widen the AFK reply timeout,
since a tunnel's AUX proxying round-trip can be slower than a direct
PHY's.

[Chris Kearney: moved dptxport_set_hpd_timeout() here from the next
 commit, which added it after its first caller, so each commit builds]

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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.

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.

[Chris Kearney: dptxport_set_hpd_timeout() moved to the previous commit,
 its first caller]

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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 <noreply@anthropic.com>
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 <noreply@anthropic.com>
…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 <noreply@anthropic.com>
…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 <noreply@anthropic.com>
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 #14 and #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 <303316+iconidentify@users.noreply.github.com>
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 <303316+iconidentify@users.noreply.github.com>
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 <303316+iconidentify@users.noreply.github.com>
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 <303316+iconidentify@users.noreply.github.com>
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 <303316+iconidentify@users.noreply.github.com>
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 <303316+iconidentify@users.noreply.github.com>
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 <303316+iconidentify@users.noreply.github.com>
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 <303316+iconidentify@users.noreply.github.com>
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 <303316+iconidentify@users.noreply.github.com>
chriskearney and others added 28 commits September 30, 2026 16:48
Suspend cleared typec_cable_connected, relying on the Thunderbolt DP
tunnel being released at suspend and set up again at resume, which
reports the cable once more. When the tunnel is kept through
suspend-to-idle nothing reports it again. dcp_poweron() then skips the
DPTX connect, the modeset fails, and every later flip on that CRTC
times out:

  apple-drm soc:display-subsystem: [drm] *ERROR* flip_done timed out
  apple-drm soc:display-subsystem: [drm] *ERROR* [CRTC:59:crtc-1] commit wait timed out

The compositor stalls until the dock is unplugged.

The route already reports cable removal through dcp_dptx_disconnect_oob().
Leave the cable state alone on suspend and clear it only on unbind, so a
kept tunnel resumes like DPMS on.

Signed-off-by: Chris Kearney <303316+iconidentify@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PA1D59hehGmwnpSxrYcDbk
DCP accepts a modeset on an external Type-C output even when the pipe
cannot be enabled yet, and then drops every swap without completing it.
That happens on resume from suspend-to-idle when the sink is slower than
the link: a TV behind the DP-to-HDMI converter of a Kensington SD5560T
dock asserted HPD only after the first modeset. Each flip then waits for
the full commit timeout, and the compositor stalls with it:

  apple-drm soc:display-subsystem: [drm] *ERROR* flip_done timed out
  apple-drm soc:display-subsystem: [drm] *ERROR* [CRTC:59:crtc-1] commit wait timed out

Arm a watchdog when a swap is submitted on a Type-C output. If DCP has
not completed the swap within a second, complete the flip, mark the mode
invalid so further commits do not wait for DCP, and let the hotplug
worker re-apply the active CRTC, a bounded number of times. When the
sink asserts HPD after a failed modeset, re-apply the mode as well.

Signed-off-by: Chris Kearney <303316+iconidentify@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PA1D59hehGmwnpSxrYcDbk
Since "usb: dwc3: apple: Acquire the PHYs at probe", the glue selects
the USB2 PHY role before it releases the dwc3 reset on every bring-up,
including the first one after boot. Before that commit, the first
bring-up's selection was a no-op, and mainline still behaves that way.
For a host, the role was then selected once the core was out of reset:
usb_add_hcd() asks the root hub PHYs for PHY_MODE_USB_HOST_SS, which
the USB2 PHY rejects, and then for PHY_MODE_USB_HOST.

On a Type-C port the USB2 PHY is already running when the glue makes
its selection, because the Type-C mux starts it before the role switch
reaches the glue. Switching the running PHY to host mode while the core
is held in reset leaves the USB2 port unable to see a connection for
the whole session. The SuperSpeed side is unaffected. Selecting host
mode is harmless only when the PHY is in host mode already, and then
the selection does nothing.

On a t8103 (j293) with a CalDigit TS4 in USB4 mode, the first session
on each port after boot never connected USB2. That was 7 of 7 sessions,
across both ports, with the dock present at boot and hot-plugged. The
xHCI USB2 root port stayed powered in RxDetect (PORTSC 0x0a0002a0).
USB2-only devices behind the dock, such as keyboards and mice, never
appeared, and only a replug on the same port brought them up. Later
sessions connected, because the PHY kept host mode from the first one.
Power-cycling only the USB2 PHY around the role change did not help.
Leaving host mode to the root hub did: the dock's USB2 hub connected on
the first session, 0.4 s after the dock, with its keyboard and mice.

Select only device mode before the reset. Device mode has no later
selector, since the glue writes PRTCAP itself and the gadget code sets
no PHY mode, so it keeps its pre-reset selection. Host mode is always
left to the root hub. Only the first host session after boot was
tested. A later device-to-host change reaches the same PHY state: host
mode is clear and the PHY is powered off at the end of the device
session and restarted by the Type-C mux. It is expected to behave the
same, but has not been tested. A fixed-hub controller is unaffected,
because its PHY driver sets host mode for it.

Fixes: 0ab0ac1 ("usb: dwc3: apple: Acquire the PHYs at probe")
Signed-off-by: Chris Kearney <303316+iconidentify@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The previous commit selects the USB2 PHY's mode before dwc3 leaves
reset for device mode only, and leaves host mode to the xHCI root hub.
Selecting host mode there again would bring back sessions without USB2.

Move that choice into dwc3_apple_usb2_mode_before_reset(), which also
rejects states that are not roles, and move the controller state enum
into dwc3-apple-state.h with it. dwc3_apple_core_start() takes both the
validation and the mode from the helper, so the choice lives in one
place. A KUnit suite pins the helper's results for every state. It
covers the helper, not the hardware ordering behind it.

Signed-off-by: Chris Kearney <303316+iconidentify@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
m1n1 copies each machine's apple,tunable-rc onto the node named by
usb4-N-acio, or usb4_N_rc on the 1.6.1 bootloader. The t8103 CIO nodes
were only labels, so a boot image rebuilt from this tree never received
the calibration and the Thunderbolt driver refused to probe.
The 14-inch and 16-inch M2 Pro/Max boards and the M2 Pro/Max mini
enable the CIO nodes without the usb4-N-acio aliases m1n1 searches
for, so a rebuilt boot image never receives apple,tunable-rc.
The base M2 trees already have usb4-N-acio. m1n1 still copies the
PCIe tunnel calibration through usb4_N_pcie, and the 1.6.1 bootloader
still looks up usb4_N_rc. Add those names for both ports.
…ck down

Turning a USB4-tunneled display off and back on in the compositor left
it in standby until a physical replug. atc_tunnel_restore() stopped
PCLK1, cleared the PLL output drivers and replayed the saved descriptor
registers, but never powered the AUSPLL down. The PLL kept running and
ACIOPHY_AUSPLL_LOCK stayed set: the teardown logged "AUSPLL_LOCK did
not clear after teardown (stat=0x8)", and the next atc_tunnel_start()
preflight read +7044=00000008 and refused its own stale lock with
-EBUSY. DCP then modeset into a tunnel with no pixel clock. A replug
only recovered it because it resets the PHY.

Clear the three PLL output drivers one at a time, then send APB command
3 through the same command/ACK handshake atc_tunnel_start() uses for
commands 0 and 0x2000. This powers the AUSPLL down: the lock drops and
the next preflight reads +7044=00000000. The saved descriptor registers
are replayed afterwards, as before. The lock-clear poll stays as a
check, since DCP retries a failed tunnel clock request quickly enough
that the next request must not see a lock that is still dropping.

Confirmed on hardware: M2 Pro (j416s), BenQ 1440p through a USB4 hub.
At boot the preflight reads +7044=00000000 and the tunnel clock comes
up (rate=0xa result=0). Disabling the output in Hyprland takes the
crossbar link down with no "AUSPLL_LOCK did not clear" warning; enabling
it 3s later preflights with +7044=00000000 again, gets rate=0xa
result=0 and "crossbar link up", with no "AUSPLL power-down was not
acked", and the picture comes back without a replug.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit dbaae5c0f6930405f1596deaef05198ad8d1642e)
The t8103 CIO nodes carry a third reg entry, reg-names "pcie-adapter",
and apple,tunable-pcie-adapter, which the binding never described. Both
controllers on j313 therefore failed validation four times over: reg and
reg-names "too long", and the tunable rejected as undocumented.

The third entry is t8103-only -- t8112 has two -- so reg and reg-names
take minItems: 2 and the adapter is described as the optional third.

While here, give thunderbolt-switch a type. It was declared as bare
"true", which dtschema reports as a missing type definition; every user
in tree spells it as a valueless boolean.

Validated against a built t8103-j313.dtb: the eight acio errors and the
thunderbolt-switch warning are gone, with no new diagnostics.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FwdG63dRaMrRbYrUBkSa1i
Conflict in drivers/gpu/drm/apple/afk.c: aurora-wip's 6fdc8fe (#48)
and this series' c61bec5 both reuse torn-down AFK service slots.
Resolved to this series' version, which also refuses to reuse a slot a
DP service owner still pins, keeps the command-tag sequence across
reuse, and has KUnit coverage. #48's afk_alloc_service_slot() and its
teardown debug line are dropped with it; nothing else used them. Its
author tested c61bec5 alone on j416s (11 reconnects in one boot,
256-byte EDID each time, no slot errors) and agreed to this resolution.

1d2904f (defer locked DART root publication until attach) merges
cleanly with this series' legacy locked display-domain handoff: the
new early continue skips only streams with neither a live root nor an
ownership shadow, and attach maps both before syncing, which publishes
the entries collected before attach on both paths.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FwdG63dRaMrRbYrUBkSa1i
A display behind a Thunderbolt dock on t8103 stayed dark unless
thunderbolt_apple.dp_display=1 was passed. The path it enables is the
one this series has been tested on: on a 13" M1 MacBook Pro, CalDigit
TS3 Plus, CalDigit TS4 and Kensington SD5560T docks drove 4K displays
through hotplug, both ports and suspend-to-idle, and the aurora test
builds have shipped it on by default.

Default dp_display to true. Passing 0 still leaves the displays dark.

Signed-off-by: Chris Kearney <303316+iconidentify@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FwdG63dRaMrRbYrUBkSa1i
… M2 Max laptop

The T602X display tunnel path ran only on the machine it was brought up
on, the 16" M2 Pro (j416s): the DP IN handshake, the tunnel pixel clock,
the longer link timeouts, the pipeline preference and the right-hand
port's bandwidth grant were all keyed to "apple,j416s". The 14" M2 Pro
(j414s), 14" M2 Max (j414c) and 16" M2 Max (j416c) use the same ATC PHYs
("apple,t6020-atcphy") and include the same t602x-j414-j416.dtsi, which
carries the crossbar's typecN-usb4 tunnel routes and the USB-C port
layout this code relies on. On those machines a display behind a dock
stayed dark.

Add apple_dp_tunnel_t602x() to the shared DP tunnel header, matching the
four laptops, and use it for the ten j416s checks in appledrm, the ATC
PHY and the Thunderbolt code. The M2 Pro and M2 Max desktops (j474s,
j475c, j475d) are left out: their device tree has no crossbar tunnel
routes yet.

So far only j416s has run this path.

Signed-off-by: Chris Kearney <303316+iconidentify@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FwdG63dRaMrRbYrUBkSa1i
Retain the last available DCP route and avoid retraining unrelated outputs during the immediate DP-to-USB4 teardown sequence. Keep synthetic DPMS disconnects separate from physical cable removal, while allowing positive hotplug events through after a replug. Let the RTKit crash callback, rather than a power-off clear-swap timeout, establish a fatal firmware crash.

[Chris Kearney: ported onto #8. The DPMS handling
 (typec_crtc_off, no reconnect from dcp_poweroff(), ignoring the unplug
 of a powered-off output) is already in aurora-wip as ab7cad0, so
 this keeps that version and adds the route preference, the detach
 retrain guard, the reconnect cancel and the clear-swap change.]

Signed-off-by: Chris Kearney <303316+iconidentify@users.noreply.github.com>
Re-establish the DCP route when a new dock tunnel appears after a
controller detach without a prior teardown callback: force the route
through a down/up cycle instead of treating the old handoff as this one.

Tested on J414s m2fix42: dock DP tunnel enabled USB-3 at 1920x1280@60, direct USB-2 at 3840x2160@120 and eDP at 3024x1964@120 with active CRTCs and zero failed units. Controller-detach disconnect reporting remains under investigation.

[Chris Kearney: ported onto #8 from "arm64: enable
 J414s Thunderbolt DP tunnel and rearm display route". The J414s gates
 that commit added are covered by apple_dp_tunnel_t602x(), which also
 takes in j414c and j416c, so only the route rearm is carried here.]

Signed-off-by: Chris Kearney <303316+iconidentify@users.noreply.github.com>
Route an available direct Type-C DP-alt-mode display to dcpext1 first so dcpext0 remains available for a dock DP tunnel. The tunnel still prefers dcpext0, which is the pipeline that completes link training on T6020.

m2fix45 cold-booted with both displays attached: direct 3840x2160@120 on dcpext1 and dock 1920x1280@60 on dcpext0 came up without port resets, alongside eDP. SEP identity, haptic FF ioctl, and AVD H.264 decode remained functional.

[Chris Kearney: ported onto #8; the J414s check goes
 through apple_dp_tunnel_t602x(), so j414c, j416s and j416c take the same
 pipeline preference, as tested on j416s by Oliver Lukschander and
 proposed for j416c in #50.]

Signed-off-by: Chris Kearney <303316+iconidentify@users.noreply.github.com>
Route DPIN1 through the native T602x crossbar fields and source selector, give the two tunnel streams separate DCP connector/route ownership, and keep both ATC pixel clocks alive at independent link rates. Wait for Type-C IOMFB hotplug after a display power-on.

The dual-dock path was exercised on J414s/m2fix48 with Dell 3840x2160@120 and JTG 1920x1280@60, per-output DPMS and idle/wake; the user confirmed the displayed image. This commit removes a frame-complete callback that had no register side effect. The cleaned tree builds with the Asahi profile; the cleaned commit itself is not yet deployed.

[Chris Kearney: ported onto #8 from "drm/apple: drive
 two J414s dock DP tunnels independently":
 - The J414s checks go through apple_dp_tunnel_t602x(), so all four M2
   Pro/Max laptops get the second connector per port and the per-DP-IN
   pipeline preference (DPIN0 dcpext0, DPIN1 dcpext1). Oliver Lukschander
   ran two displays through one hub on j416s with the same gates.
 - The per-DP-IN ATC clock tracking replaces #8's single-rate T602X
   restart: a rate change reselects that DP IN's PCLK. A DPMS stop gates
   the outputs and keeps the PLL; a PHY mode change still powers the
   AUSPLL down in atc_tunnel_restore(), which now also forgets the users.
   The t8103 tunnel clock path is unchanged.
 - Only the T602X crossbar preselects a DP IN's source; t8103 tunnels
   still select it at link-up, so -EOPNOTSUPP from the selector is not
   an error.]

Signed-off-by: Chris Kearney <303316+iconidentify@users.noreply.github.com>
Apple host USB3 adapters do not acknowledge bandwidth-allocation writes, so their software-only initial allocation should not be treated as consumed USB3 bandwidth when admitting DP tunnels. Read the downstream router USB3 UP adapter consumed-bandwidth counters instead, retaining 900 Mb/s minimum headroom for isochronous traffic. If those counters cannot be read, keep the existing conservative allocation estimate. The change does not cap USB3 bulk traffic or write the unsupported host registers.

The m2fix48 dock test reached Dell 4K120 and JTG 60 with USB devices enumerated; a standalone throughput or isochronous stress test has not been performed.

[Chris Kearney: applies to every Apple host, since apple.c sets
 QUIRK_NO_USB3_BW_ALLOC on all of them, the t8103 included.]

Signed-off-by: Chris Kearney <303316+iconidentify@users.noreply.github.com>
Build the USB4 connection manager and Apple NHI with the Asahi profile.
Keep unrelated SEP and host configuration out of this stack.

[Chris Kearney: ported onto #8 from "arm64: enable
 Apple USB4 modules and J414/J416 firmware aliases". The J414/J416
 underscore aliases are already on this branch, so only the configuration
 is carried.]

Signed-off-by: Chris Kearney <303316+iconidentify@users.noreply.github.com>
…rce early

A Thunderbolt DP tunnel on t8103 leaves the crossbar's DP IN output at
its idle source, dispext0, until DCP reports DidChangeLinkConfig. That
works there because dispext0 is the only external pipeline. On t600x the
Type-C ports are driven by dcpext1 (mux index 2), and a pipeline whose
output still points at dispext0 activates the link, gets no answer from
the sink and gives up before it sets a link rate.

Add apple_dpxbar_preselect(), which writes only the source select of a
DP IN output that is not selected yet. The connection itself still comes
up in the normal mux selection. MUX_IDLE_DISCONNECT puts the output back
at its idle source.

Also skip the FIFO_RD_PCLK1 cycle-slip toggle for DP IN on t6000, which
runs without it, as found on j316c in omacom/linux-aurora#9. The DP PHY output
keeps the toggle.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Christian Bartels <christian@thebartels.de>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

[Chris Kearney: ported onto #8; comment and message
 reworded to describe the observed behaviour only.]
Signed-off-by: Chris Kearney <303316+iconidentify@users.noreply.github.com>
The M1 Pro/Max ATC is the t8103 generation, and the Thunderbolt DP tunnel
pixel clock is set up the same way. Take t6000 and t6001 through
atc_tunnel_start_t8103(). Unlike t8103, which feeds the tunnel from PCLK1
alone, t600x also runs PCLK2 and the DP IN (DPRX) clock with the same
rate selector.

Split the sleep overrides and the TX_DP_CTRL0 setup out of the start
function and add apple_atc_dp_tunnel_open(), which applies both ahead of
the first rate request. On t600x DCP does not set a link rate until the
DP clock path is awake, so the display driver calls this before it tells
DCP about the display. Other SoCs return -EOPNOTSUPP and keep doing all
of it in the rate call.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Christian Bartels <christian@thebartels.de>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

[Chris Kearney: ported onto #8 on top of the per-DP-IN
 T602X tunnel clock; t600x takes the t8103 path for both start and stop.]
Signed-off-by: Chris Kearney <303316+iconidentify@users.noreply.github.com>
… display

With only the SoC checks widened, a Thunderbolt display on the MacBook
Pro 14" M1 Pro (j314s) got as far as an active DP IN adapter. DCP then
stayed silent for 5 s after Activate, every DPTX call timed out, and it
reported link faults 22 and 24 without ever sending SET_LINK_RATE.

All three Type-C routes of j314s use dcpext1 (apple,typec-mux-indices =
<2 2 2>), while the DP IN output idles at dispext0. Point the output at
the pipeline that takes the tunnel and wake the ATC's DP clock path
before the DPTX connect, and put the output back at its idle source when
the route goes away without the crossbar having come up.

Both helpers return -EOPNOTSUPP where they do not apply, so t8103 and
T602X behave as before.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Christian Bartels <christian@thebartels.de>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

[Chris Kearney: ported onto #8 on top of the dual DP
 tunnel series; the tunnel is prepared once its slot is taken.]
Signed-off-by: Chris Kearney <303316+iconidentify@users.noreply.github.com>
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 <christian@thebartels.de>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

[Chris Kearney: ported onto #8, where dp_display
 defaults to on; t600x takes that default too.]
Signed-off-by: Chris Kearney <303316+iconidentify@users.noreply.github.com>
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 <christian@thebartels.de>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

[Chris Kearney: ported onto #8, where DjDeveloperr's
 "preserve Type-C routes across blanking and detach" already stopped
 setting crashed but returned early; this carries on with the power-off.
 This is also the DCP unplug wedge Oliver Lukschander reported on #8.]
Signed-off-by: Chris Kearney <303316+iconidentify@users.noreply.github.com>
The per-port Type-C connectors carry DisplayPort (DP alt mode or a
Thunderbolt/USB4 DP tunnel), but were registered as
DRM_MODE_CONNECTOR_USB, which DRM reserves for USB display adapters
(gud, appletbdrm). Userspace keys on the type: systemd-logind only
counts VGA/DVI/DP/HDMI/TV connectors as external displays, so a
docked lid close suspended the machine instead of honoring
HandleLidSwitchDocked=ignore.

Register them as DisplayPort. The driver's internal "is Type-C" checks
use dcp->connector_type / fixed_connector_type and are unaffected.
Connectors are now named DP-N instead of USB-N.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: RJ Skerry-Ryan <rryan@alum.mit.edu>
A Type-C port's encoder spans every pipeline that can drive the port, and
routing narrows its possible_crtcs to the pipeline actually chosen,
relying on userspace to re-read them on the following hotplug.
Compositors that read possible_crtcs once when the connector appears
(aquamarine, used by Hyprland) never see that. With a USB4 dock carrying
two streams, whichever connector connects first takes the lowest free
CRTC. When that is the DPIN1 connector, it gets dcpext0's CRTC while the
stream is routed to dcpext1, every modeset fails the atomic check with
-EINVAL, and both dock displays stay dark until the dock is replugged
and happens to connect in the other order.

possible_crtcs is meant to be static. On the dual-stream machines
(J414s, J416c):

- Fix the DPIN1 connector to the lowest-indexed Type-C-only pipeline
  (dcpext1), where DPIN1 is always routed, and route DPIN1 only within
  the connector's possible_crtcs.
- Leave the primary connector spanning all its pipelines and stop
  narrowing or restoring possible_crtcs at runtime.
- Route direct DP-alt displays to the lowest free CRTC, which is what a
  compositor picks from the port's fixed possible_crtcs, instead of
  steering them away from dcpext0.

A direct DP-alt display now takes dcpext0 when it is free, so a
single-stream dock on another port lands on the next free pipeline.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: RJ Skerry-Ryan <rryan@alum.mit.edu>

[Chris Kearney: ported onto #8. dcp_typec_dual_stream()
 is apple_dp_tunnel_t602x() here, so j414c and j416s are dual-stream too;
 they share the j414/j416 device tree and the dcpext0/dcpext1 layout.]
Signed-off-by: Chris Kearney <303316+iconidentify@users.noreply.github.com>
Resolves the conflicts with the T8140 PCIe root-port bring-up (#151).
Both sides only add: this branch's PCIe-C tunnel state and properties
(resets, apple,pciec-kernel-init, apple,tunable-*) and the T8140 PIODMA
bootstrap (apple,piodma, map_bus gating, Neo enumeration) are all kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FwdG63dRaMrRbYrUBkSa1i
On the M2 Pro/Max 14" and 16" laptops (J414s/c, J416s/c) the Type-C
ports share the external pipelines: dcpext0 (which also drives HDMI)
and dcpext1, plus dcpext2/3 on the M2 Max boards.  Since "drm/apple:
Keep dual-stream Type-C possible_crtcs fixed", every port's connector
offers all of them.  Compositors read possible_crtcs once and pair
connectors with CRTCs themselves: aquamarine (Hyprland) walks the CRTCs
in index order and gives each to the first connected connector, in
connector order, that can use it.  The fabric instead hands out
pipelines in whatever order the Type-C and Thunderbolt events arrive.

That is a regression from the commit above on a J416c with two direct
DP-alt monitors at boot: when port 1's event was handled first, port 1
took dcpext0 and port 0 dcpext1, and Hyprland paired them the other way
round.  Each connector's modes were then checked against the other
monitor's list, native modes failed the atomic check with -EINVAL, and
only modes both monitors share could be set.  fbdev, which pairs every
connected display afresh on each hotplug, and a dock's DPIN0 stream
attaching after a direct display cross the same way.

Until a compositor owns the display, keep the routes equal to that
pairing computed from scratch: pipelines in CRTC index order, each to
the first stream that wants one and has it in its possible_crtcs, with
the primary connectors in port order ahead of the DPIN1 ones.  A hybrid
pipeline whose HDMI output is live is left to it, unless a tunnel holds
it.  A direct DP-alt stream wants a pipeline while its sink asserts
HPD, as only then can its connector read connected.  Only direct routes
move, each to exactly its planned pipeline.  A Thunderbolt tunnel never
moves once set up.  A direct stream planned onto a pipeline a tunnel
holds stays unrouted and reads disconnected, since putting it anywhere
else would have the compositor cross it with another display; it is
then left out and the pass re-run, so the streams after it are not
planned one pipeline off.

A move is a disconnect and reconnect: every route that moves is taken
down before any comes up, so two never share a pipeline, HPD is
replayed on the new pipeline, and the hotplugs make fbdev and userspace
re-probe.  The pass runs on every DP-alt and tunnel attach, detach and
HPD change, when HDMI is plugged in while a Type-C route has its
pipeline, once DRM is registered, and from postclose when a file that
was DRM master is closed; drm_release() has taken that file off the
file list by then.

A compositor owns the display while any open file has been DRM master:
it pairs its connectors when it starts and keeps that pairing across a
VT switch, where it drops master but keeps the device open.  Until the
last such file is closed routing stays as it was, the lowest free
pipeline on DP entry with preferred_route honoured, and nothing moves.
The check walks the file list under filelist_mutex, taken inside the
fabric lock; nothing takes the two the other way round.

cd321x does not report an unchanged DP state again, so a port left
without a pipeline used to stay dark for the session.  When a route
lets its pipeline go while a compositor owns the display, such a port
now goes back to the pipeline it last had if that is free, as the
compositor keeps a reconnected connector's CRTC, and otherwise takes the
lowest free one, the CRTC it gives a newly connected connector.

Hotplug and retrain work queued for a Type-C connector can run after
its route is gone and connector->dcp is NULL; check for that instead of
dereferencing it.

possible_crtcs stay static, since compositors read them only once, and
the DPIN1 connector stays fixed to dcpext1.  Single-stream machines take
none of the new paths.

Signed-off-by: Chris Kearney <chris@kearneymail.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FwdG63dRaMrRbYrUBkSa1i
Dual-stream machines kept advertising every candidate CRTC after the
fabric assigned a connector to one pipeline. An explicit atomic commit
could select the other advertised CRTC and send its framebuffer to a
different physical display.

Publish the active pipeline mask for dual-stream ports as well as
single-stream ports, including routes adopted during DRM binding.
Restore the candidate mask only while the connector is disconnected
and unrouted. Validate the requested CRTC against the actual connector
owner in atomic encoder selection, so stale userspace topology fails
rather than driving another output. The route planner still uses its
separate candidate mask; clients can discover the valid assignment by
re-reading encoder topology on hotplug.

Assisted-by: LLM
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
@RyanTheTide
RyanTheTide merged commit b1bd8bd into aurora-wip Oct 8, 2026
@RyanTheTide
RyanTheTide deleted the fix/pr8-review branch October 8, 2026 10:22
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.

6 participants