Skip to content

J873g: rear USB-C PD controllers through tipd, DisplayPort alt mode from Type-C (M6 Mac mini) - #2486

Draft
sithglan wants to merge 36 commits into
aurora-silicon:integration/aurorafrom
sithglan:thomas/j873-typec-tipd
Draft

sithglan wants to merge 36 commits into
aurora-silicon:integration/aurorafrom
sithglan:thomas/j873-typec-tipd

Conversation

@sithglan

@sithglan sithglan commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

#1800 (J873g displays in drm/apple) has merged. Still stacked on #1743 (generation-4 SPMI interrupts; its four commits are included unchanged). Review the last four commits. It stays a draft until #1743 leaves draft.

This is the second step of the order agreed on #2178. The J873g's (Mac mini M6, T8152) three rear USB-C PD controllers (ACE3, sn201202x) now have a single owner, tipd, which runs on their interrupts. drm/apple's T8152 DCPs take DisplayPort alt mode from Type-C instead of polling the controllers over SPMI.

  1. dt-bindings: usb: apple,sn201202x: add the T8152 controllers. apple,t8152-sn201202x with the apple,t8132-sn201202x fallback. Like T8132, the J873g's controllers have no select notification and report the payload length in register 0x1f. tipd's T8132 path needs no change.
  2. dt-bindings: display: apple,t8152-dcp-iboot: describe the USB-C ports as Type-C mode switches. Each port's usb-c node in the shared ports node becomes the port's one display mode switch, with an endpoint at the connector's port@3. It replaces apple,usb-pd.
  3. drm/apple: take the T8152 USB-C display state from the Type-C ports.
    • One Type-C mode switch per rear port, shared by the three DCPs. One switch per DCP would fill the three mode switches a connector's port driver takes (TYPEC_MUX_MAX_DEVS), and leave out the ATC PHY's switch that USB4 needs (J873g: USB4 on the rear USB-C ports through tipd and atc.c (T8152 routers, PCIe-C, M6 Mac mini) #2178).
    • tipd sets the port's state on that switch. It records three things: DP alt mode with HPD high, the pin assignment's lanes, and the plug orientation. Every DCP that drives USB-C is told and looks at the ports 100 ms later.
    • Port claiming, the PHY, the crossbar and the DPTX handling are unchanged.
    • t8152_pd.c is deleted, along with the PD reset ("Gaid", "SSPS") that came with it. A sink that stops answering AUX gets its DisplayPort link released and reconnected instead, at most once a minute.
    • The 250 ms poll remains only for the shared HDMI port's HPD line, which has no interrupt.
  4. arm64: dts: apple: t8152-j873g: hand the rear USB-C PD controllers to tipd.
    • The SPMI controller becomes an interrupt controller (AIC 682).
    • The three controllers get the compatible list, their irq/sleep/wake interrupts (hpm0 11/17/19, hpm1 37/43/45, hpm3 63/69/71) and usb-c-connector children, with graph links to every DCP's route for that port.

Things to know

  • A HPD pulse is not a re-plug. Without a video stream, an EIZO EV2780 drops HPD for about 160 ms every 4.7 s. tipd learns of each pulse afterwards and passes it on as low then high. Treating each pulse as a new sink kept the link from training: link faults, one lane, then a standby link at RBR whose mode list lacked 2560x1440@60, so the next DPMS on failed the atomic check. Now only a changed plug (orientation or lanes), or a sink that leaves DP alt mode with its partner, counts as a new connection.
  • The first DCP to probe registers the three switches, before anything else in its probe. tipd therefore never waits on a DCP that fails to start.
  • The rear ports' USB data path is unchanged (no role-switch links). USB4 through tipd is the next step, reworking J873g: USB4 on the rear USB-C ports through tipd and atc.c (T8152 routers, PCIe-C, M6 Mac mini) #2178.

Testing (M6)

The first version, with a switch per DCP, was tested as below. This head was booted with #2178 on top: all three displays, 6/6 DPMS cycles.

Not tested: a physical replug, a flipped plug and a pin D dock. Nobody is at the machine.

cc @Acelogic @RyanTheTide @DjDeveloperr @LiamRay10

Assisted-by: LLM (Claude:Opus 5.5)

@sithglan

Copy link
Copy Markdown
Contributor Author

Restacked on #1743 instead of #2466, because Ryan asked to land the generation-4 SPMI interrupts once, in #1743. The head is now bd141acf3f1f (was aedc7af5eb3e). This PR's four commits are unchanged (git range-diff). This exact head is booted on the J873g: tipd binds the three controllers with interrupts, all three displays come back on 6/6 DPMS cycles, and source 63 fires on the S2431W's IRQ_HPD. The full row is on #1743.

@sithglan

Copy link
Copy Markdown
Contributor Author

Updated to 182211d0a048 (was bd141acf3f1f): one display switch per rear USB-C port, shared by the three DCPs, instead of a Type-C route per DCP. A connector's port driver takes at most three mode switches (TYPEC_MUX_MAX_DEVS; fwnode_connection_find_matches() stops at the third endpoint without an error). Three DCP routes per connector filled that limit, which would have left out the ATC PHY's switch that USB4 needs (#2178). The switch is the port's usb-c node in the shared ports node, with its endpoint at the connector's port@3. The first DCP to probe registers the switches, and every DCP that drives USB-C is told about each change. The three commits and their messages are updated in place. This tree, with #2178 on top, booted on the J873g: all three displays, 6/6 DPMS cycles.

@sithglan
sithglan force-pushed the thomas/j873-typec-tipd branch from 182211d to 28447d8 Compare November 20, 2026 00:43
@sithglan

Copy link
Copy Markdown
Contributor Author

Restacked on #1743's new head 42f3e094cd39, which drops the unreachable stray-loop drain (8 lines removed, nothing else). The head is now 28447d8189f2, with this PR's four commits unchanged. #2178 is restacked on it as 477250a3fb6c.

@sithglan

Copy link
Copy Markdown
Contributor Author

Restacked on #1800's new head 41e4cb30ada4, which adds an AFK wait queue for the iBoot DCPs' service waits (details on #1800). The head is now 4e0bf8f084d0 (was 28447d8189f2). This PR's own commits are unchanged: git range-diff shows = for all eight.

@RyanTheTide

Copy link
Copy Markdown
Contributor

hdmi_pcon_power() in drivers/gpu/drm/apple/t8152_hdmi.c ends with an unconditional msleep(25) after the PS190 power writes, with no reason given for 25 ms. If the converter needs a power-on settle time, cite where the value comes from; better, wait for the thing that actually matters (the PS190 asserting HPD or answering AUX) with a bounded poll. Separately, the iboot_buffered module parameter is harmless with its default but should not be runtime-writable. Until then this should stay a draft.

@RyanTheTide
RyanTheTide marked this pull request as draft November 20, 2026 23:53
@sithglan
sithglan force-pushed the thomas/j873-typec-tipd branch from 4e0bf8f to e65af2d Compare November 21, 2026 01:31
@sithglan

Copy link
Copy Markdown
Contributor Author

@RyanTheTide both points are in #1800 (3306da7c8297): the msleep(25) after the PS190 power writes is gone, with the reasoning on #1800, and iboot_buffered is 0444. This PR is restacked on it unchanged (e65af2dabb0e).

@sithglan

Copy link
Copy Markdown
Contributor Author

Rebased onto integration/aurora d1b022dc34fb (Ryan's tidy-up on #1799). The new head is 2880a16f6e74. It's on #1800's new head, with #1743's current four commits. The conflicts, the two host-test fixtures that needed the new fields, and the checks (461/461 host tests, W=1 builds) are listed there: #1799 (comment)

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown
Contributor

Re-checked at 2880a16. The four commits this PR adds range-diff as = against e65af2d, so this is a rebase only. Both of my earlier points are fixed in #1800, which this stacks on: the PS190 settle sleep is gone and iboot_buffered is 0444. Nothing else from me here. This PR now just waits on #1800 and #1743.

Assisted-by: LLM (Claude:Opus 5.5)

@sithglan
sithglan force-pushed the thomas/j873-typec-tipd branch 2 times, most recently from 4aebfd7 to 5fbdac0 Compare November 22, 2026 14:35
@sithglan

Copy link
Copy Markdown
Contributor Author

Restacked onto #1800 6f250c0, which adds the display DARTs' power domains (see #1800). This PR's own commits are unchanged.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown
Contributor

Re-checked at 5fbdac0: a rebase onto #1800 6f250c0; the only difference is the deleted t8152_pd.c now carrying #1800's new comment. Our view stands.

Assisted-by: LLM (Claude:Opus 5.5)

A co-processor adopted from the bootloader has already sent its endpoint
map, to the bootloader, so the application endpoints a client starts on
it by hand are not in rtk->endpoints. Every message on them is then
logged as one to an undiscovered endpoint. The T8152 DCP driver would get
one per SET_SURFACE, about 60 lines a second during video.

Add apple_rtkit_adopt_ep() for a client to register an application
endpoint of such a session.

Signed-off-by: Thomas Glanzmann <thomas@glanzmann.de>
The DARTs in front of the T8152 display coprocessors (DCP, DCPEXT) and
their display pipes (ADT "dart,gen3", version 0x300) use the T8110
register layout, but they belong to the SPTM, and the bootloader hands
them over locked. Their TLB command register at 0x80 answers translation
queries instead of flushing. A stream is invalidated the way iBoot does
it: a payload naming the DART and the stream is written to the SoC's TLB
invalidation aperture, which these DARTs share, and a broadcast TLBI
follows.

Add apple,t8152-dart-gen3 for them, without the apple,t8110-dart
fallback, since a T8110 driver would flush through the wrong register,
and a "tlbi" register entry for the DART's window in the aperture.

Signed-off-by: Thomas Glanzmann <thomas@glanzmann.de>
The T8152 display DARTs (ADT "dart,gen3", version 0x300) use the T8110
register layout but belong to the SPTM: their TLB command register at 0x80
answers translation queries instead of flushing. A stream is invalidated
the way iBoot does it, by writing a 128-bit payload (valid, route, SID)
to the SoC's shared TLBI aperture and broadcasting a TLBI, which the DART
snoops. The route is the DART's 0x4604 register.

Admit a Gen3 DART only when the bootloader hands it over locked (its
streams cannot be set up cold yet), map the aperture from a second "tlbi"
reg entry without claiming it, since every Gen3 DART shares it, flush the
whole stream where a range flush would go through 0x80, and do not claim
the fault interrupt or drain stale exceptions, whose handling acknowledges
through that register as well.

The range flush test fixture gains the new hw flag.

Signed-off-by: Thomas Glanzmann <thomas@glanzmann.de>
The Gen3 DART snoops the broadcast TLBI that follows the aperture write.
iBoot and the aura bootloader issue TLBI VALE1OS at EL2 without VHE,
which targets the EL1&0 regime. On a VHE kernel the same instruction
targets EL2&0 while HCR_EL2.TGE is set, so clear TGE around it, as KVM
does to reach the EL1&0 regime.

The J873g display works with this in place; the effect of the change on
its own has not been isolated on hardware.

Signed-off-by: Thomas Glanzmann <thomas@glanzmann.de>
sithglan and others added 26 commits November 22, 2026 15:49
A T8152 Gen3 DART reports a fault as a v2 DART does: a bitmap of the
streams with a pending exception at 0x4000, a record per stream at
0x8000 (status, address), acknowledged by writing the bitmap back.
Request its interrupt and let apple_dart_t8110_v2_irq() report and
acknowledge its faults instead of leaving them to the firmware.

Only the unlock after a lock-on-error exception differs: a Gen3 DART's
TLB command register serves translation queries, so it is not used to
unlock. A Gen3 DART with lock-on-error set says that its stream stays
stopped. The J873g's Gen3 DARTs have it clear.

Tested on the J873g by clearing the AVD DART's SID 0 TTBR during an
H.264 decode: one interrupt, "translation fault: SID:0 write TTBR invalid
at 0x10fff000000 (status 0x00000100)", the bitmap acknowledged with no
repeat, and the decoder retired by its recovery path. After the TTBR was
restored and the decoder reloaded, the same file decoded bit-exact
again. None of the other eight Gen3 DART fault lines fired, including
those of the locked display DARTs with three displays running.

Signed-off-by: Thomas Glanzmann <thomas@glanzmann.de>
afk_init() picks the AFKv2 wire for firmware 27 and for the T8122
external processor on 26.x, both recognised by their IOMFB interface.
The T8152 DCP firmware speaks AFKv2 on every endpoint of its iBoot
interface (the display service, the DPAV controller services and the
DPTX port services), and drm/apple drives no IOMFB interface of it that
a version could key on.

Add hw.afk_v2, which selects AFKv2 for all endpoints of a processor.
No match entry sets it yet.

Signed-off-by: Thomas Glanzmann <thomas@glanzmann.de>
The T8152 DCP does not acknowledge AP QUIESCED, and an IOP INIT while
its AP power is still on panics the firmware ("Invalid AP power: 32").
A session the bootloader leaves running can only be taken over as it
runs, with apple_rtkit_init_adopted(), without the HELLO/EPMAP
handshake: the endpoint map went to the bootloader, and
apple_rtkit_start_ep() refuses an endpoint RTKit does not know.

Add hw.afk_adopt_endpoints. With it afk_start() registers the endpoint
with apple_rtkit_adopt_ep() before it sends anything to it, so its
START_EP goes out and its replies are not taken for an unknown
endpoint's. No match entry sets it yet.

Signed-off-by: Thomas Glanzmann <thomas@glanzmann.de>
A bootloader that drives the display through the DCP firmware can leave
AFK endpoints running with its scanout when it hands over, as the T8152
loader does with the iBoot interface's endpoints. An AFK INIT on a live
endpoint asserts in the firmware.

Add dcp->afk_live_endpoints, bit N for endpoint 0x20 + N, which a
processor's probe fills from such a hand-off (the T8152 loader's
apple,afk-active-endpoints). afk_start() sends an endpoint whose bit is
set a SHUTDOWN and waits for its acknowledgment before START_EP and INIT,
after registering it with an adopted RTKit session so that the
acknowledgment is not taken for an unknown endpoint's. The old session's
ring stays the bootloader's, which keeps it reserved. The mask is zero on
every processor that sets nothing, so their start is unchanged.

The stop of the live endpoints is based on a change by Acelogic for the
T8152 hand-off.

Signed-off-by: Thomas Glanzmann <thomas@glanzmann.de>
afk_send_command() allocates a reply buffer of the output length and
names it in the command, even for a length of zero. The AFKv2 setters
of the T8152 DCP firmware's iBoot interface (SET_POWER, SET_MODE,
SET_SURFACE) answer with a transport status alone. Given a reply
buffer, the firmware copies an empty reply into it and asserts.

Give a command without output no reply buffer: its descriptor carries
address and length zero, which the AFKv2 codec already accepts and
checks the reply against. Every current caller passes an output
length, so none of them changes.

Signed-off-by: Thomas Glanzmann <thomas@glanzmann.de>
afk_recv_handle_init() parses the properties that follow a service's
announced name whenever there are any, and matches the service by the
EPIC provider class found there. Which keys it accepts depends on the
firmware interface version. The T8152 DCP firmware's iBoot service
(disp0-service, dispext-service) is announced by name alone, and the
properties of its DPTX and DPAV services are not needed to drive it:
a property set the parser rejects would leave such a service unopened.

Add hw.afk_announced_names. With it the properties are not parsed, the
service is matched by its announced name, and that name is what its
handler gets as the EPIC name. No match entry sets it yet.

The startup host test's and the apple-dcp service rebind test's
processors gain the flag, and the latter kstrdup(). The provider
admission test looks for the announcement's OPEN in the first 7000
bytes of afk_recv_handle_init() instead of 6500, which no longer reach
it.

Signed-off-by: Thomas Glanzmann <thomas@glanzmann.de>
An announced service that no entry of its endpoint's ops table names
is left unopened, apart from two firmware-specific exceptions that
bind it to the endpoint's first entry. The T8152 DCP firmware's DPAV
controller endpoint announces four services and expects all of them to
be opened, among them dcpav-video-interface, whose opening starts the
firmware's idle power off timer for the display. None of them takes
commands from the host.

Add ep->unmatched_ops, bound to every announced service that no entry
of the endpoint's ops table matches, which is then opened and
initialised like a matched one. It is NULL on every existing endpoint,
whose unmatched services stay unopened as before.

The startup host test's and the apple-dcp service rebind test's
endpoints gain the field.

Signed-off-by: Thomas Glanzmann <thomas@glanzmann.de>
AFK waits one second for an endpoint to start or stop and for a
command or service call to be answered. The T8152 DCP firmware's iBoot
display commands answer only once the DisplayPort work they start is
done: SET_POWER and SET_MODE wait for the link training, during which
the firmware calls into the AP for the PHY. The T8152 displays have
been run on the hardware with three seconds for each of these.

Add hw.afk_timeout_ms, the time afk_start(), afk_shutdown(), the
inherited endpoint stop, afk_send_command(), afk_service_call() and
afk_service_call_len() wait. Zero keeps one second, so every processor
that sets nothing waits as before. Callers that pass their own timeout,
and the legacy reply-length calls, are unchanged.

Signed-off-by: Thomas Glanzmann <thomas@glanzmann.de>
ibootep.c sends the iBoot interface's display commands only for the
T6030 external role's first-pixel diagnostic: the queries and setters
are reachable from its sysfs file and pattern path alone, gated on
dcp->external, and the surface is set through the swap operations
15/16/18/19. The T8152 DCP firmware is driven through this interface
alone and sets its surface with operation 1, SET_SURFACE.

- Add DCP_FIRMWARE_IBOOT, a DCP driven through the iBoot interface
  alone, and dcp_is_iboot(). No match entry selects it yet.
- Build SET_SURFACE (operation 1, one 164-byte layer) and the three
  queries in iboot_build_pattern_request().
- Export ibootep_set_power(), ibootep_get_hpd(),
  ibootep_get_timing_modes(), ibootep_get_color_modes(),
  ibootep_set_mode() and ibootep_set_surface(), with the mode records
  in ibootep.h. On AFKv2 the setters go out without a reply buffer, as
  the firmware asserts on one, and a reply is checked against the
  length the transport reports, through the new afk_send_command_len().
  SET_SURFACE scans out one linear BGRA plane in colour space 2, as the
  bootloader sets it on T8152.
- Open the service for a DCP_FIRMWARE_IBOOT processor under either of
  its names (disp0-service on the main DCP, dispext-service on the
  external ones), without the manual query file: its display driver
  sends every command.

The T6030 external role keeps its gate, its service name, its sysfs
file and its pattern and frame commands as they were.

Signed-off-by: Thomas Glanzmann <thomas@glanzmann.de>
The T8152 (Mac mini J873g) DCPs drive their displays through hardware
no subsystem driver covers yet: the rear USB-C ports' ATC PHYs have no
DisplayPort mode in drivers/phy/apple/atc.c for T8152, the HDMI port's
DisplayPort PHY has no T8152 type in drivers/phy/apple/dptx.c (its
lanes are 0x2800 apart from 0x4500), the PS190 DisplayPort-to-HDMI
converter behind it is powered through the SMC, the ports' ACE3 PD
controllers do not report to the Type-C route layer, and the DCP
firmware's iBoot interface does not hand out the sink's EDID.

Add the T8152 code for them as separate files, each marked interim
until atc.c's DisplayPort mode, tipd and the Type-C route layer take
over. The bootloader trains the displays before Linux starts; the PHYs
keep its setup and reprogram what a link training changes, as the DCP
firmware calls into the AP for them.

t8152_atc.c, the USB-C ports:
- The three DCPs share the three rear ports through the one display
  crossbar. A DCP claims a free ATC under a mutex and gives it up on
  unplug; a monitor stays with its DCP while userspace blanks it. The
  crossbar's upstream reset, clock and enable fields are indexed by DCP
  endpoint * 2 + DPTX port, independently of the downstream DFP0 mux
  fields, which select that endpoint.
- Each ATC has its own PMGR DP clock divider, at 0x300020044 + 8 * n.
- The ATC's DP clock switch (PHY CFG block + 0x14 select, + 0x18 enable,
  + 0x1c status) chooses where each DP pixel clock comes from. PCLK1 is
  switched to PMGR DP clock 0 (select field 1, enable and status bit 1)
  after the divider for the link rate is written, and switched off the
  same way. With source 0 selected the stream clock never followed the
  divider: modes above about 165 MHz pixel clock, and 640x480, stayed
  black while the link trained and the firmware set the mode.
- A monitor that also carries USB3 negotiates pin assignment D (data
  status bit 5): two DisplayPort lanes, and only the PMA that carries
  them is set up. GET_MAX_LANE_COUNT reports the route's lanes.
- A cold start powers the ATC's dependencies (USB AON, the common PSD,
  both DP power states), the common block and AUX, and starts the lanes
  at HBR at once: from cold, AUX only works with the DP PLL and PMAs
  running. A power down undoes what it powered up.
- The EDID is read through the AP AUX controller aux0, which the three
  DCPs share and take in turn; its output select for an ATC port is the
  ATC instance * 3 + its local DFP.

t8152_hdmi.c, the HDMI port:
- The bootloader wires the HDMI PHY (source select, APB 0x10) to the
  main DCP (0) when no USB-C display is attached at boot, and then never
  starts DCPEXT0; next to a USB-C display it wires DCPEXT0 (1). The
  source select is read only while the PHY's PMGR power state is
  requested and active: a USB-C-only boot leaves the PHY off, and a read
  of its registers then raises an SError.
- When the bootloader left HDMI off (no monitor at boot leaves its PLL
  unlocked), the HDMI port becomes one of the shared ports. A DCP that
  drives no USB-C display takes it when the HPD line goes high, starts
  the PHY from cold (PMGR and PSD power, the PS190, source select, PLL,
  AUX and PHY power, the tunables, PLL and PHY activation, four lanes,
  impedance calibration), keeps the link up across display off, and
  gives the port back once the sink is gone. The source select takes
  every DCP's crossbar endpoint, DCPEXT1's 2 included, so DCPEXT1 takes
  the port while the other two drive USB-C monitors. The HPD line is
  requested once for all of them.
- The PS190 is powered through the SMC when the port is set up, before
  anything reads HPD or an EDID: it drives the HPD line only while it is
  powered, and while it is off every AUX request on the USB-C ports
  ends with channel status 2 as well. Without the SMC bound yet, the
  setup is deferred.

t8152_aux.c: the AUX controllers' request framing. Bits 21:8 of the
retry register are a 14-bit reply timeout, set to 3200; read as a
three-bit delay, the EDID through a USB-C to HDMI adapter timed out. A
sink left in D3 is woken before DDC.

t8152_pd.c: the ACE3 plug, orientation, DP alt mode and HPD state over
SPMI, read through the logical register window under the SPMI device's
lock, which the USB4 port monitor takes as well. A controller in power
state 7 enters alt mode only after SSPS 0. A sink that stopped answering
AUX after a monitor's deep sleep comes back after a reset (Gaid) and
SSPS 0.

t8152_dptx.c: the DPTX port service's calls into the AP apply link
rate, lanes and drive settings to these PHYs and read the drive
settings back as they were set; an unsupported GET_DRIVE_SETTINGS was
followed by a firmware crash. The port's release is group 8 command 7,
and its HPD call (group 8 command 8) carries a status in its reply's
first word. dptxep.c serves the same calls for PHY framework PHYs, the
crossbar mux and Thunderbolt tunnels; its connect and display request,
its call numbers and its port records are used here.

The HDMI PHY's power state check is based on a change by Acelogic.

The files are built with the new DRM_APPLE_DCP_T8152, enabled in
asahi.config, and nothing uses them yet. A MAINTAINERS entry for the
T8152 display covers them and the binding.

Signed-off-by: Thomas Glanzmann <thomas@glanzmann.de>
A caller that needs an endpoint's services, or the state one of their
init callbacks sets up, can only poll for them. Give each endpoint a
wait queue that is woken once a service has opened and its init
callback has run, on each path that opens one: compact, AFKv2 and a
deferred AFKv2 open. The host-test fixtures that build those paths get
the wait queue too.

Signed-off-by: Thomas Glanzmann <thomas@glanzmann.de>
The T8152 (Mac mini J873g) DCP firmware offers a small display service,
disp0-service on the main DCP and dispext-service on the DCPEXTs, next
to its IOMFB interface. The bootloader drives the J873g displays through
it, with the DPTX port service that the firmware calls into the AP for
the PHY and the DPAV controller services it expects to be opened, all
over AFKv2. Add these DCPs to drm/apple as the DCP_FIRMWARE_IBOOT
variant, matched by apple,t8152-dcp-iboot, with the shared AFK code and
the iBoot commands of ibootep.c. The match data selects AFKv2 on every
endpoint, endpoints registered with an RTKit session taken without its
map, services matched by their announced name and a three-second AFK
timeout. dcp_platform_probe() hands such a DCP to iomfb_iboot.c.

Taking the session over:
- A running session is adopted without the RTKit handshake
  (apple_rtkit_init_adopted(), apple_rtkit_adopt_running()): the DCP
  does not acknowledge AP QUIESCED, and an IOP INIT while its AP power
  is on panics it. A session the loader quiesced after a failed display
  setup (/chosen apple,dcp-rtkit-running = 0; the older J873 loader
  build v0.1.0-259-ga30a589a predates the property and is recognised by
  its 640x1136 placeholder framebuffer) is woken instead, and so is an
  unused DCPEXT the loader marks apple,rtkit-wake, once its PSD reads
  powered (a read of the coprocessor while it is gated hangs the
  machine) and its CPU runs.
- The loader's AFK endpoint hand-off (apple,afk-active-endpoints) is
  required and fills dcp->afk_live_endpoints, so afk_start() stops each
  endpoint the loader left running: an AFK INIT on a live endpoint
  asserts in the firmware. Without the property there is no telling
  whether an endpoint is live, and the DCP is not taken over.
- A woken DCPEXT's oslog endpoint offers a 0x5ff8-byte ring at
  0x100033cc000, the log segment of its own firmware addressed with the
  coprocessor's DRAM tag in bit 40, which only the firmware's retained
  DART tables map. With that buffer request failed, RTKit rejected the
  firmware's write counters as invalid instead of acknowledging them,
  which the firmware waits for before AP power transitions. The ring is
  taken as the firmware's, without a CPU mapping; the other buffers go
  through drm/apple's RTKit shared memory hooks. The surface log lines
  go to the debug level.
- Once the session is taken it is retained until reboot like the other
  live sessions (dcp_retain_live_session(), split out of
  dcp_pin_live_session()). A failed start stops the endpoint work,
  detaches RTKit with its buffers kept and leaves the device bound, so
  nothing retries over a partly started session.

Starting the display:
- A new iBoot session has no surface, and a pipe that still runs then
  fetches from a null base (IOMFB axi_rd_err, firmware NMI): the display
  is powered off at once and powered on only after a SET_SURFACE.
- The DPAV controller endpoint's four services are opened without a
  handler. Opening dcpav-video-interface starts the firmware's idle
  power off timer: a powered display without a following SET_MODE
  counts as idle, and the firmware takes the link down 30 s later, as
  it did with HDMI 30 s after boot while the compositor still had the
  output on. SET_MODE is sent again a second after that interface
  opens, from a work outside the AFK receive queues.
- The DPTX port services are bound in the order they are announced. On
  USB-C the inherited DPTX link is released before the first connection.
- The DCP fetches through dart-dcp and the display pipe scans out
  through dart-disp0; both are locked, with live roots of their own. One
  domain over both would publish dart-dcp's root into dart-disp0 and
  drop the bootloader's scanout mappings, so the scanout stream is a
  child device with a domain of its own. Scanout buffers are mapped
  there at their DCP address, cacheable, since the pipe faults on
  entries with the DART's no-cache bit, and below any range the
  firmware already maps there (a buffer mapped over one flickered).
  They are written through a write-combined mapping: the pipe does not
  snoop the CPU caches.
- The bootloader's simple-framebuffer is taken over.

KMS (iboot_drm.c), one DRM device per DCP:
- Changing the surface between Linux buffers made later SET_MODEs crash
  the firmware. Three scanout buffers of at least 3840x2160 are
  allocated at probe; a frame's damage is copied by the CPU into one that
  is not on screen, which SET_SURFACE then shows, at most once per
  refresh by an hrtimer: there is no vblank interrupt, and several swaps
  within one refresh let an older frame stay on screen. The pitch is
  64-byte aligned, as the firmware refuses an unaligned one.
- The firmware takes a mode as width, height and a 16.16 refresh rate
  and picks the timing itself. The modes are the sink's EDID modes the
  firmware also lists, or the firmware's list with CVT timings. A DRM
  mode is matched to the firmware mode nearest by the exact refresh
  rate, within 1 Hz: next to an EIZO EV2780's 2560x1440@59.951
  (241.5 MHz) the firmware lists a 60.000 Hz standard mode of its own
  (byte 0 bit 6), which it drives at 312.25 MHz and the monitor does
  not take.
- The EDID is read through the AP's DisplayPort AUX controllers while
  the firmware does no AUX itself, since the iBoot interface does not
  hand it out.
- A mode must fit the lanes the route may train, as GET_MAX_LANE_COUNT
  reports them, not those of the last training: a monitor that drops
  and reasserts HPD while the display is off is trained without a
  stream on a single lane, and 2560x1440@60 then failed the atomic check
  when the outputs came back on.
- Right after power on the firmware still trains the link and fails
  SET_MODE; it takes the mode once the link is up, so SET_MODE is
  retried. The colour mode is the deepest valid one up to 32 bpp, as
  SET_MODE refuses the deeper ones the HDMI converter offers.
- USB-C hotplug is polled from the PD controllers every 250 ms, HDMI
  from the converter's HPD line. An unplug releases DPTX and powers the
  PHY down, a sink that no longer answers after a monitor's deep sleep
  gets a fresh DP alt mode entry at most once a minute, and a quick
  reconnect restores a CRTC that was enabled.
- drm/apple's per-DCP DRM device of dcpext_drm.c and dcpext_scanout.c
  does not fit: it is the T6030 external role's diagnostic, with one
  fixed 3840x2160 mode and the swap operations instead of SET_SURFACE.
  The DRM driver is named "apple-dcpib" (DCP iBoot interface), apart
  from the display subsystem's "apple"; appledrm.iboot_buffered=0 copies
  frames into the buffer on screen instead.

Removal, shutdown and system sleep leave the firmware session alone. An
unbind unplugs the DRM device, releases its committed state without
touching the firmware, and detaches RTKit; the session stays retained,
and a new bind is refused until reboot.

The live endpoint hand-off and the retained failed start are based on
changes by Acelogic.

Tested on the J873g with HDMI and two rear USB-C monitors: all three
come up, HDMI-A-1 at 2560x1440@59.951, DP-1 at 2560x1440@59.951 and
DP-2 at 1920x1200@59.950. DPMS off and on works on each output, and so
does HDMI at 1920x1080 and back. mpv runs fullscreen at 60 fps with no
dropped frame after the first five. Unbinding DCPEXT1 removes its DRM
device without a warning, and a new bind is refused with -EBUSY.
Earlier runs of the same display code on the J873g: booted without
HDMI, a monitor plugged in later is taken by a free DCP (DCPEXT0, and in
another run DCPEXT1 with source select 2), which starts the PHY from
cold and runs 2560x1440@60 at HBR3, DCPEXT0 within 0.6 s; with the
bootloader's DCP start failing on purpose, HDMI and both USB-C monitors
come up at their EDID modes; woken DCPEXTs log no buffer error.

Signed-off-by: Thomas Glanzmann <thomas@glanzmann.de>
The DARTs of the main DCP and of DCPEXT0, and those of their display
pipes (ADT dart-dcp, dart-disp0, dart-dcpext0 and dart-dispext0), belong
to the SPTM, and the bootloader hands them over locked. Their TLB is
invalidated through the SoC's TLB invalidation aperture
(dart-tlbi-aperture), not through the T8110 TLB command register.

Describe them as apple,t8152-dart-gen3 with their windows in the
aperture (ADT tlbi-aperture-offset 0x400 and 0x480). The second register
window of the display pipe DARTs, their SMMU instance, is not used and
is dropped. The other display DARTs keep their description until
something uses them.

Signed-off-by: Thomas Glanzmann <thomas@glanzmann.de>
The bootloader trains the J873g displays through the DCP firmware's iBoot
interface and hands both DCPs over with their RTKit sessions running:
the main DCP drives a USB-C display on one of the rear ports, or HDMI
when no USB-C display is attached at boot, and DCPEXT0 drives the HDMI
port next to a USB-C display.

Add both DCPs with their post-office mailboxes and enable their Gen3
DARTs, with the DMA window in the upper half of the firmware's 64 GiB
window, above the firmware's and the bootloader's mappings. The main DCP
lists the three rear USB-C ports with their ATC PHY, PMGR power states,
tunables and PD controllers on nub-spmi-a0. DCPEXT0 has the HDMI PHY,
the read-only PMGR power states of the PHY and of its CPU, and the HPD
line of the DP-to-HDMI converter on the AOP's GPIO controller, which is
polled since its interrupts belong to the AOP. Each DCP has the AP
DisplayPort AUX controller that reads the sink's EDID.

Resources are from the 26A434 ADT.

Signed-off-by: Thomas Glanzmann <thomas@glanzmann.de>
Describe DCPEXT1 (ADT dcpext1: ASC at 0x502e00000, post-office
mailbox 7, IRQs 306/266, DARTs dart-dcpext1 SID 23 and dart-dispext1
SID 0) with its PMGR2 PSD admission register. Give each controller its
crossbar source, let DCPEXT0 and DCPEXT1 use the main DCP's USB-C port
children, and widen dp-clock to the PMGR ATC DP clock dividers of all
ATCs.

Signed-off-by: Thomas Glanzmann <thomas@glanzmann.de>
Give the HDMI node the dptx-phy's PSD service (5), the SMC writes that
power the PS190 (ADT dp2hdmi-gpio0 function-dp2hdmi_pwr_en and
function-hdmi_pwr_en, SMC key pcIO) and the dptx-phy tunables from the
ADT, so that the DCP driver can start HDMI without the bootloader.

Signed-off-by: Thomas Glanzmann <thomas@glanzmann.de>
The display coprocessor has a power state of its own, which its DARTs
follow. Allow the node to name it.

Signed-off-by: Thomas Glanzmann <thomas@glanzmann.de>
Every enabled DART must name the power state of the engine it serves
(scripts/dtc/apple-dart-pd-check.py). The six J873g display DARTs named
none.

Their engines are the display coprocessors, whose PMGR states are
DISP_CPU (dcp), DISPEXT0_CPU (dcpext0) and DISPEXT1_CPU (dcpext1) in the
26A434 ADT. The AP does not switch those: a coprocessor is started
through its PSD service (coproc-psd), and its firmware runs the state;
Linux only reads DISPEXT0_CPU (coproc-ps). So they are described as
firmware-owned: the OS keeps them on and never reads or writes them,
which leaves the display hand-off and the HDMI cold start as they are.
The coprocessor nodes name the same state as their DARTs.

DISP_CPU sits at PMGR offset 0x14000 (it reads 0x0f0000ff on J873g, as
DISPEXT0/1_CPU do), past the 0x14000 the PMGR node described, so the
node now spans the ADT's 0x1c000 PMGR window.

Signed-off-by: Thomas Glanzmann <thomas@glanzmann.de>
Generation 4 (t8142, t6050) had its interrupt refused at probe. macOS's
trace (reported by Dj on the Aurora M5 Pro thread) acks peripheral sources
0..255 per bit in words from +0x600, with the controller fault source 263
at +0x620 bit 7. On K114c the PMIC RTC alarm sets +0x600 bit 2 (read-only
probe, alarm armed 20 s out).

Take the mask and ack bank offsets from the hw table (gen1 unchanged,
shared with a host check in spmi-apple-irq.h). Generation 4 has no mask
bank we could find (no word in 0x20..0x7f or 0x500..0x6ff toggles), so
sources are masked in the cache only. Commands stay polled: the RX
notification is not wired for gen 4.

Tested: host check of the register math; compile only, not booted.
Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com>
Probe on K114c: +0x400..0x41c toggle and restore (8 words), +0x420 does not,
matching the +0x600 ack bank 0x200 above (Dj, seq 713, from write offsets in a
macOS trace). The alarm latches +0x600 bit 2 once the PMIC alarm mask byte
0x200e is 0 (as rtc-macsmc writes it) and a write of 4 to +0x600 clears it
(measured). Whether the +0x400 bit gates the AIC line is not measured.

Drop the cache-only masking for gen 4. On a firmware resume re-apply the runtime
mask, since a firmware sleep entry writes the mask bank itself.
Host check extended; compile only, not booted.

Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com>
…ask writes

Both open code points from review:

The controller's fault source (263, word 0x620 bit 7 on gen4) shares its
ack word with the notification word the handler reads first, and the
stray-source path acked it directly: queued fault records were lost.
Drain the queue before the bit is acked, in both the notification-word
path and the readq stray path.

gen4 has no notification source, and the word at +0x420 does not behave
as a mask bank, so the init and teardown loops now write only the
num_irqs / 32 mask words on gen4 (the legacy controllers keep the
extra notification word).

The host-test file is dropped: kbuild never built it and it checked
constants against themselves.
The stray-queue loop visits ack words 0 to 3 (bytes 0 to 24), while the gen4 fault source lives in word 8 (0x620), which the chained handler already reads and drains before acking. The hunk also compared a word index against byte offsets. It could never fire; remove it.

Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com>
The USB-C PD controllers behind the J873g's (T8152) SPMI controller at
0x308908000 answer as the T8132 ones do: no register-selection
interrupt, so a selection is polled, and the payload length of the
selected register is read from register 0x1f. Their event, sleep and
wake sources are interrupts 11/17/19, 37/43/45 and 63/69/71 of that
controller.

Add apple,t8152-sn201202x with apple,t8132-sn201202x as fallback, so
that the T8132 interrupt layout (irq, sleep, wake) applies.

Signed-off-by: Thomas Glanzmann <thomas@glanzmann.de>
… as Type-C mode switches

A T8152 DCP drives the rear USB-C port whose PD controller reports a
DisplayPort sink. So far the DCP read the controllers itself, through
apple,usb-pd. The controllers belong to the USB Type-C port driver
instead, which passes the DisplayPort alt mode state of a port to the
Type-C mode switches its connector's graph leads to.

Describe one display switch per port, shared by the DCPs: the port's
usb-c node in the shared ports node (the one apple,usb-c-ports refers
to) is the mode switch, with an endpoint at the display port (port@3)
of the port's usb-c-connector. The DCPs already share these nodes for
the port's PHY registers and tunables, and each port has one owner at
a time. One switch per DCP instead would fill the three mode switches
a connector's port driver looks at (fwnode_typec_mux_get() collects
the matches into a three-entry array and stops at the third endpoint
without an error), and leave out the port's ATC PHY, which needs one
for USB4. Drop apple,usb-pd, which nothing reads any more.

Signed-off-by: Thomas Glanzmann <thomas@glanzmann.de>
The T8152 DCPs found a USB-C display by reading the rear ports' PD
controllers over SPMI every 250 ms (t8152_pd.c): plug and orientation
from STATUS (0x1a), DisplayPort connection, pin assignment and HPD
from DATA_STATUS (0x5f), through the controllers' register window
(select at 0x00, length at 0x1f, data from 0x20). With tipd bound to
the same controllers, tipd failed to read its events while the
display path polled. The controllers belong to tipd now.

Take the state from the Type-C class instead: one Type-C mode switch
per rear port, the port's usb-c node in the shared ports node, with an
endpoint at the display port of the port's connector. tipd sets the
port's mode on it. The switch records whether the port is in
DisplayPort alt mode with HPD high, the lanes of the pin assignment
(two for B, D and F, which share the cable with USB 3) and the plug
orientation of the Type-C port, once, next to the port claims of
t8152_atc.c, and tells every DCP that drives USB-C to look at the
ports. The port claim and the PHY, crossbar and DPTX handling of
t8152_atc.c and iboot_drm.c stay as they were.

One switch per port, not one per DCP: a connector's port driver takes
three mode switches at most (TYPEC_MUX_MAX_DEVS;
fwnode_connection_find_matches() stops at the third endpoint and
returns success). A switch per DCP would fill all three on every J873g
rear connector, and the port's ATC PHY, which needs one for USB4,
would never be called.

A HPD pulse is not a new sink. Without a video stream, an EV2780 drops
HPD for about 160 ms every 4.7 s; the PD controller reports it after
the fact, and tipd passes it on as HPD low and then high. Connecting
the sink anew on each pulse kept its link from coming up (link faults,
one lane, then a standby link trained at RBR whose mode list lacked
the enabled mode, so the next DPMS on failed atomic check). The 250 ms
poll never saw these pulses. A switch event is looked at 100 ms later,
which takes such a low and high together, and only a changed plug
(orientation, lanes) or a sink that leaves DP alt mode with its
partner is a new connection.

dcp-fabric.c's route layer itself does not fit these DCPs: it switches
a DP PHY and the display crossbar through their drivers and connects
the sink through the DCP's IOMFB DPTX service, while the iBoot
interface DCPs program the ATC PHY and the crossbar themselves and
connect through their own DPTX port service. Their switches only
record the state, in t8152_typec.c.

The 250 ms work now only re-arms while a DCP can take the shared HDMI
port, whose HPD line has no interrupt.

The PD controller reset that made a sink which stopped answering AUX
enter DP alt mode again (a cold reset, "Gaid", then system power state
S0, "SSPS") is gone: the controller is tipd's, and tipd puts it into
S0 whenever it sets the controller up. What remains is the DisplayPort
side, at most once a minute: release the link and connect the port's
sink again. HPD changes now reach the display path as they happen.

The first DCP that probes registers the switches, ahead of everything
else in its probe, and they stay until the driver is unloaded: tipd
keeps the switch it found, and must not wait for a DCP that cannot
start. A switch that cannot be registered is disabled in the live tree,
so that tipd goes on without it.

Signed-off-by: Thomas Glanzmann <thomas@glanzmann.de>
… tipd

The PD controllers of the three rear USB-C ports were described for the
display path alone, which read them over SPMI itself. Describe them
for tipd, which owns them from now on, and the display path takes their
DisplayPort alt mode state from the Type-C class:

- the controllers as apple,t8152-sn201202x, with the T8132 fallback:
  tipd's SPMI transport then polls the register selection and reads
  the payload length from register 0x1f, as these controllers need;
- the SPMI controller (AIC 682) as the interrupt controller of their
  event, sleep and wake sources: 11/17/19 (back-middle), 37/43/45
  (back-left) and 63/69/71 (back-right), rising edge, as in the ADT.
  In a test with the compatibles and interrupts alone, tipd bound all
  three, took its events by interrupt, and both display partners showed
  DisplayPort alt mode active;
- a usb-c-connector per controller, whose display port (port@3) leads
  to the port's usb-c node in the main DCP's shared ports node, the
  port's one display switch for all three DCPs. The USB port (port@0)
  stays unlinked: the USB data path is not changed here.

The DCP's usb-c nodes lose apple,usb-pd, which nothing reads any more.

Signed-off-by: Thomas Glanzmann <thomas@glanzmann.de>
@sithglan

Copy link
Copy Markdown
Contributor Author

#1797 has merged with its trailer-free head a7907d9. This branch still carried #1797's earlier commits, including 17cb996 with the Co-Authored-By: trailer Ryan asked to drop. I replaced them with the merged ones.

  • This is a message-only remap: f53d6de → 377db77, and the tree is identical (60331d7efe84).
  • This PR's own 36 commits keep the same patches, authors, dates and messages. GitHub now lists only those commits.
  • It merges cleanly into integration/aurora daa9e2d.

Assisted-by: LLM (Claude:Opus 5.5)

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