Skip to content

usb: typec: tipd: idle at shutdown, recover a busy controller, native display HPD keyed on a DT property - #2398

Draft
RyanTheTide wants to merge 9 commits into
mainfrom
sweep/tipd
Draft

RyanTheTide wants to merge 9 commits into
mainfrom
sweep/tipd

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

What: usb: typec: tipd: idle at shutdown, recover a busy controller, native display HPD keyed on a DT property. This PR now carries these drafts as one feature (merge commits, the commits themselves unchanged):

Tested: each part as tested on its own PR (folded bodies below; no hardware row on this head yet). Combined with current main (ba29027) together with the other folds of 11-25: full arm64 build (Image, modules, dtbs; fleet89 config, clang 22, rustc 1.97.1) clean.

Risk: two-way · all Macs (tipd PD controllers)

Not yet: a shutdown/probe row and a native-display HPD row (T8140/T8142) on this head.

#2398 original description

Problem

A CD321x or SN201202x controller that a reboot leaves in the middle of a command keeps running it into the next boot. On a J714s, after a soft reboot, both USB-C controllers ran an LDCM command for more than 3 s. Their SPMI buses reported parity errors meanwhile, the probe failed, and both ports stayed gone until the next boot.

5f0e567 (drivers/usb/typec/tipd/spmi.c, sn201202x_init()) handled this on apple,j714s only: up to five probe tries with fixed waits (200/500/0/1000 ms), a "Gaid" cold reset before the fourth try, then a deferred probe. Every other SN201202x board with the same controller kept a single try. The driver also has no .shutdown, so nothing stops it from leaving a command running at a reboot.

A second board list sits in core.c tipd_sleep_ssps_rules() (J714s, J716c, J813, J815; 475b7ad, f2bdd2e). It selects how the SSPS command around a firmware-driven sleep is sent. The boards in the list are the ones whose controllers carry apple,sleep-ssps.

Change

  1. usb: typec: tipd: leave the controller idle at shutdown, recover a busy one at probe
    • The controller reports a command's end in CMD1: it reads 0, or "!CMD" for an unknown command. The new tipd_cmd_wait_idle() polls CMD1 for that.
    • New tipd_shutdown(), used as .shutdown by the I2C (CD321x, M1/M2) and SPMI (SN201202x) drivers. It stops the interrupt or poll, the LDCM worker and the CD321x workers. Then, under the device lock, it waits for CMD1 to go idle, for at most 5 s (the longest limit the driver gives any command). It does not touch the port, mux or USB role.
    • SN201202x probe: before the first command, it waits up to 5 s for CMD1 to go idle. A failed read counts as busy, as seen on the J714s. Only a controller still busy after that gets one cold reset ("Gaid", written over the running command, never in "DBMa" debug mode), and is then probed once. There is no board check and no retry loop.
    • The "port controller ready" and firmware-sleep "SLEEP: n" lines now print on every SN201202x machine, not only on J714s/J716c.
  2. usb: typec: tipd: apply the sleep's SSPS rules by apple,sleep-ssps, not by board
    • The rules are now keyed on the controller's apple,sleep-ssps (read once into tps->sleep_ssps). The board list is gone.
    • A command found ended is no longer reported as a timeout because its last read came after the limit. This applies to every controller.

Suspend needed no change: commands run synchronously under the device lock, and the prepare already cancels the LDCM worker.

Related open PRs: #2101 adds a reboot notifier that closes a USB4 session before shutdown. It runs earlier and does a different job; the two are compatible. #1889 is about idle sleep; no overlap.

Which machines change, and why it is safe
  • Shutdown wait: every tipd controller on I2C or SPMI. An idle controller costs one register read. A busy one costs up to 5 s, and only if a command really is still running.
  • Probe wait: SN201202x only (M3 and later). Idle at probe costs one CMD1 read. The cold reset is the same "Gaid" the debug-link recovery and the J714s code already used. It is still refused in "DBMa".
  • SSPS rules: same behavior on J714s, J716c, J813 and J815. New on J700 (T8140, Neo), whose controllers carry apple,sleep-ssps (d9b438c). There the rules apply only to a firmware-driven (S2R) sleep. s2idle sends no SSPS. Controllers without the property on the listed boards (the debug-link port) go back to the original command handling; they never send SSPS around a sleep.
  • J815: its controllers do not carry apple,sleep-ssps (the sleep dtsi is included by the J813 only), so it never sent SSPS around a sleep. Its only change is that the S0 at probe and resume goes back to the original handling (5 s limit, reads back to back), as on every board without the property.
  • The timeout fix only changes a result that was wrong (a finished command reported as a timeout).
Credit

Diljit Singh (5f0e567, 475b7ad) found the cause and wrote the J714s recovery and the sleep rules. Nick (f2bdd2e) extended the rules to the M5 Airs and pointed at apple,sleep-ssps. Both are credited with Suggested-by.

Testing

Build (buildbox, LLVM=1, release config + TYPEC_SN201202X=m, both tipd KUnit suites =m, TYPEC_TPS6598X_DEBUG_COMMANDS=y, W=1), tree = this branch plus #2399: make -j8 W=1 drivers/usb/typec/tipd/ passes. core.o, i2c.o, spmi.o and all six KUnit test objects build. The only warning is the existing i2c.c:21 enum cast, which is untouched.

KUnit was not run: the build host is at load ~450. The test objects compile.

  • Hardware (one-shot test kernel 7.3.0-aurora-swl1 = integration 0abc2f3 + this and the other open sweep PRs, 2026-11-20):
    • T8112 J413, T6000 J316s, T6040 J616s: boot + 20 s idle + 3 s2idle cycles (rtcwake, ~20 s each, rc=0): 0 kernel errors, 0 SError, 0 failed units, 0 AVC; typec ports all present (4 / 5 / 7); 0 tipd/tps6598x/cd321x errors; the reboot out of the test kernel logged no 'still running at shutdown' or controller reset lines.

Still to run

Hardware rows: pending.

  • Neo (T8140 J700), J616s (T6040), M1 Pro (T6000 J316s), M2 (T8112 J413): boot, then ls /sys/class/typec (all ports present). Do a warm systemctl reboot, then journalctl -k -b | grep -E 'sn201202x|tps6598x|cd321x'. Expect no "still running at shutdown", no "from before this boot still running", and no "controller reset" lines. On SN201202x machines, expect one "port controller ready" line per controller.
  • Shutdown time: journalctl -k -b -1 | tail shows no 5 s stall at the tipd shutdown.
  • Neo S2R, only if the test kernel has deep sleep: echo deep > /sys/power/mem_sleep; rtcwake -m mem -s 20 (Neo wake RTC = rtc0), then expect "system power state S3 in N ms" / "S0 in N ms" and the ports back.
  • Not bootable here: J714s, J716c, J813, J815 (M5). They keep the same SSPS behavior; the J714s gets the CMD1 wait in place of the retry loop.
#2399 original description

Problem

drivers/usb/typec/tipd/core.c picks three DisplayPort policies by SoC compatible:

  • cd321x_uses_dp_sid(): !apple,t8140 && !apple,t8142. Follow the partner's DP status (event 37). From 7220ae0, scoped in the adaptation.
  • cd321x_update_work(): !apple,t8140 && !apple,t8142. On a USB4 start, ask the display connector to recheck. From 3c9a8c5.
  • tipd_resume(): h17_display = apple,t8140 || apple,t8142. Do not synthesize an IRQ_HPD pulse. From 46e2253.

The reason is not the SoC. On those machines the display coprocessor's Type-C route has its own HPD path (46e2253: "Integration's DP status interrupt and its HPD rules stay off on those SoCs"). A new board with that route would need its compatible added in three places. h17_display was also set only in tipd_resume(), so it was false from probe until the first resume.

Change

  • New boolean DT property apple,display-native-hpd on the SN201202x node (documented in apple,sn201202x.yaml). tipd_init() reads it into tps->display_native_hpd, and the three sites use that flag.
  • The property is set on every SN201202x node of the T8140 and T8142 boards: t8140-j700.dts (2), t8142-j704-usb.dtsi (3), t8142-j813-usb.dtsi (2, used by J813 and J815).
  • These boards behave as before, except that the IRQ_HPD rule now applies from probe and not only after the first resume. Every other board is unchanged.
DT coverage

From dtc -I dtb -O dts of the built DTBs:

t8140-j700:  sn201202x nodes=2  apple,display-native-hpd=2
t8142-j704:  sn201202x nodes=3  apple,display-native-hpd=3
t8142-j813:  sn201202x nodes=2  apple,display-native-hpd=2
t8142-j815:  sn201202x nodes=2  apple,display-native-hpd=2
t6040-j616s: sn201202x nodes=4  apple,display-native-hpd=0
t6041-j614c: sn201202x nodes=4  apple,display-native-hpd=0

t8140-j700, t8142-j704, t8142-j813 and t8142-j815 are every T8140/T8142 DTB in the Makefile.

Credit

Chris Kearney wrote the DP status follow and the display-route keying (7220ae0, 3c9a8c5). Diljit Singh wrote the H17 route handshake (46e2253). Both are credited with Suggested-by.

Testing

Build (buildbox, LLVM=1, release config + TYPEC_SN201202X=m, both tipd KUnit suites =m, TYPEC_TPS6598X_DEBUG_COMMANDS=y, W=1), tree = this branch plus #2398: make -j8 W=1 drivers/usb/typec/tipd/ passes. core.o, i2c.o, spmi.o and all six KUnit test objects build. The only warning is the existing i2c.c:21 enum cast, which is untouched.

KUnit was not run: the build host is at load ~450. The test objects compile.

DTBs build: apple/t8140-j700 t8142-j704 t8142-j813 t8142-j815 t6040-j616s t6041-j614c. The binding YAML parses. dtschema is not installed on the build host, so dt_binding_check was not run.

Still to run

Hardware rows: pending.

  • Neo (T8140 J700): ls /sys/class/typec shows port0 and port1. With the dock and display on the rear port: hot-unplug and replug the display. Expect the display to come back as on the current kernel, and no "Invalid DP pin assignment" or mux errors in journalctl -k -b | grep -iE 'cd321x|sn201202x|typec'.
  • J616s (T6040) and the M1 Pro and M2: no property, so behavior is unchanged. A dock or display hotplug on any one of them is a regression check.
  • Not bootable here: J704 (T8142), J813, J815. Their DT gets the property, so behavior stays as before.

…sy one at probe

A controller that the previous boot left in the middle of a command
keeps running it into the next boot. On a J714s, after a soft reboot,
the SN201202x controllers of both USB-C ports ran an LDCM command for
more than three seconds; their SPMI buses meanwhile reported parity
errors and unacknowledged commands, the probe failed, and both ports
stayed gone. Commit 5f0e567 handled that on the J714s only, by
trying the probe up to five times with fixed waits, and a cold reset
("Gaid") before the fourth try. Nothing in it is specific to that
board: every CD321x and SN201202x has the same command register, and
any of them can be left busy by a reboot.

The controller reports a command's end in its command register (CMD1
reads 0, or "!CMD" for an unknown command). Use that:

- tipd_shutdown(), the .shutdown of the I2C and SPMI drivers: stop the
  interrupt (or the poll), the LDCM worker and the CD321x workers, the
  only senders of commands once user space is gone, then wait under the
  device lock for CMD1 to show the controller idle, for at most the
  longest limit the driver gives a command (5 s). The port, mux and USB
  role are left alone.

- SN201202x probe: before the first command, read CMD1 until the
  controller is idle, counting a failed read as busy (as on the J714s),
  for at most 5 s. Only a controller still busy after that is
  cold-reset once, "Gaid" written over the running command, unless it
  is in the boot loader's debug mode ("DBMa"); then it is waited for
  again and probed once. No machine check, no retry loop.

The probe and firmware-sleep SLEEP lines that printed only on the J714s
and J716c now print on every SN201202x machine; they are one line per
controller.

The suspend path already ends with no command in flight: every command
runs synchronously under the device lock, and the prepare cancels the
LDCM worker before the sleep.

Fixes: 5f0e567 ("usb: typec: tipd: sn201202x: J714s: try a failed probe again, with a reset")
Suggested-by: Diljit Singh <[email protected]>
Signed-off-by: Ryan Murray <[email protected]>
…ot by board

The rules for the system power state command around a firmware-driven
sleep (wake the controller first, read the command register at 5 ms
intervals, the 1 s limit and its lines, a failed S3 refuses the sleep, a
failed S0 sets the controller up again) were keyed on a list of boards:
J714s, J716c, J813, J815. They exist because of how the SN201202x
answers its command register, and the boards that send the command are
the ones whose controllers carry apple,sleep-ssps. The J815 commit that
extended the list says as much ("their sleep node asks for the command
(apple,sleep-ssps), so apply the J714s's rules there as well").

Read apple,sleep-ssps into tps->sleep_ssps in tipd_init() and key the
rules on it. Every controller that sends SSPS around a firmware sleep
now follows the rules. The one board this adds is the J700 (T8140),
whose controllers carry apple,sleep-ssps since d9b438c but kept
the original command behavior; it sends SSPS only in a
firmware-driven (S2R) sleep. Controllers without the property on the
listed boards (the debug-link port) return to the original command
behavior; they never send SSPS around a sleep.

A command found ended is no longer called a timeout because its last
read came after the limit, on every controller: the end is in the
register, not in the clock.

Fixes: 475b7ad ("HID, rtc, usb: typec: tipd: T6050 sleep: MTP's reports, the PMU alarm, the port controllers")
Fixes: f2bdd2e ("usb: typec: tipd: the sleep's SSPS rules on the M5 Airs too")
Suggested-by: Diljit Singh <[email protected]>
Suggested-by: Nick <[email protected]>
Signed-off-by: Ryan Murray <[email protected]>
Three CD321x/SN201202x display policies were keyed on the SoC: on T8140
and T8142 the driver does not follow the partner's DP status (event 37
stays masked), does not synthesize an IRQ_HPD pulse for a quick HPD
low/high, and does not send the display connector a recheck when a USB4
route starts. The reason is the display route, not the SoC: on those
machines the display coprocessor's Type-C route has its own HPD path,
which is why the gates came with it (46e2253: "Integration's DP
status interrupt and its HPD rules stay off on those SoCs"). A new
board with the same route would need another compatible in three
places.

Describe it on the controller instead: apple,display-native-hpd, read
in tipd_init() into tps->display_native_hpd, and set on every
SN201202x node of the T8140 and T8142 boards (J700, J704, J813, J815).
Those boards keep their behavior, and every other board is unchanged.

h17_display was also only set in tipd_resume(), so it was false from
probe until the first resume on T8140 and T8142. The property is read
at probe, so the IRQ_HPD rule holds from boot.

Fixes: 7220ae0 ("usb: typec: tipd: follow the DP status of an SN201202x partner")
Fixes: 3c9a8c5 ("usb: typec: tipd: key the CD321x display route on the selected mode")
Fixes: 46e2253 ("usb: typec: keep the H17 display route handshake")
Suggested-by: Chris Kearney <[email protected]>
Suggested-by: Diljit Singh <[email protected]>
Signed-off-by: Ryan Murray <[email protected]>
…iption

The description of apple,display-native-hpd has a ": " in a plain
scalar, which YAML reads as a mapping, so the schema does not parse.
Make it a literal block.

Fixes: ea26780 ("usb: typec: tipd: key the native display HPD path on a DT property")
Signed-off-by: Ryan Murray <[email protected]>
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Blockers: 4.

  1. The PR conflicts with integration/aurora, and its second commit is superseded. 6465f0a ("usb: typec: tipd: the sleep's SSPS rules and the probe reset from the DT", usb: typec: tipd: the sleep's SSPS rules and the probe reset from the DT #2640) already removed both board lists. It keys the SSPS rules and the probe lines on apple,sleep-ssps-rules (core.c:364 and spmi.c:787 on integration/aurora) and the probe reset on apple,reset-on-failed-probe (spmi.c:856). Drop commit 2. If the J700 should get the rules, add apple,sleep-ssps-rules to its controllers in t8140-j700.dts. Rebase commit 1 onto the current file.

  2. drivers/usb/typec/tipd/spmi.c:801-814: the cold reset now runs on every SN201202x whose CMD1 does not read idle within 5 s, and a failed read counts as busy. On integration/aurora the reset runs only where the DT opts in. A "Gaid" written to the controller of a port that is sinking power can drop the PD contract, and on a Mac with a flat battery that contract is its power. Keep the reset behind apple,reset-on-failed-probe. The CMD1 wait in place of the fixed 200/500/0/1000 ms waits is the part worth keeping, and it can apply everywhere.

  3. spmi.c:773-781: the "DBMa" guard only works when MODE reads (!ret && !memcmp(...)). The reset path is taken exactly when register reads fail ("command register unreadable"), and then the guard is skipped and the debug link's controller is reset. Refuse the reset when MODE cannot be read.

  4. host-tests fails on this head: apple-dcp not ok 79 - probe-transaction-rollback. The harness in tools/testing/selftests/drivers/gpu/apple-dcp/accounting.py builds the tipd probe path and needs updating with the new probe flow.

Also: removing the -EPROBE_DEFER fallback (spmi.c:812-813) means a reset that does not bring the controller back now fails the probe for good. Before, the probe was deferred.

HW row (after the rebase): J616s and Neo J700, warm systemctl reboot x3: no "still running at shutdown", no reset lines, all typec ports present, and no added stall at the tipd shutdown in journalctl -k -b -1. M1 Pro and M2: the same for the I2C .shutdown. Plus 0 AVC, 0 failed units and 0 new kernel errors.

Assisted-by: LLM (Claude:Opus 5.5)

Conflicts: apple,sn201202x.yaml (kept apple,display-native-hpd and integration's new properties), tps6598x.h (display_native_hpd replaces h17_display; kept integration's replug fields).

Signed-off-by: Ryan Murray <[email protected]>
tipd now takes the native display HPD path from the controller's
apple,display-native-hpd property instead of the machine compatible.
The lifecycle, quiesce and transaction fixtures model a native H17
(T8140) controller: add display_native_hpd to their struct tps6598x
mocks, set it in the lifecycle fixture, and have the transaction
fixture's device_property_read_bool() report the property, so the
extracted tipd code builds and keeps the native path it had.

Signed-off-by: Ryan Murray <[email protected]>
Conflicts: tipd core.c/tps6598x.h (integration's #2640 SSPS rules from apple,sleep-ssps-rules replace this branch's apple,sleep-ssps commit 9fc5296, which is dropped; tipd_shutdown()/CMD1 idle wait kept), spmi.c (integration's DT-keyed probe/SLEEP lines and USBw kept; probe waits for CMD1 idle, cold reset only with apple,reset-on-failed-probe, otherwise deferred; the retry loop goes).

Signed-off-by: Ryan Murray <[email protected]>
…e is unreadable

sn201202x_cold_reset() skips a controller in the boot loader's debug
mode (DBMa), but wrote "Gaid" over the running command whenever the
mode read failed, so a controller in that mode on a bus that fails reads
was reset. Refuse the reset unless the mode was read and is not DBMa.

Signed-off-by: Ryan Murray <[email protected]>
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Merged integration/aurora (f5f023b); conflicts in drivers/usb/typec/tipd/{core.c,spmi.c,tps6598x.h} resolved: the apple,sleep-ssps commit is dropped in favour of #2640, tipd_shutdown() and the probe's CMD1 idle wait stay, the Gaid cold reset only runs with apple,reset-on-failed-probe (otherwise the probe defers), plus a follow-up commit refusing the reset when MODE is unreadable. drivers/usb/typec/tipd/ incl. KUnit tests (arm64 fleet config, LLVM, W=1) builds with no new warnings; sn201202x-transport, j613-mux-order and apple-dcp selftests (92/92) pass.

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

The review points are addressed on the merged head, and host-tests pass. Still needed: J616s and Neo J700 rows (three warm reboots with no "still running at shutdown" or reset lines, all Type-C ports present, no shutdown stall), the same on an M1 Pro and an M2 for the I2C shutdown, and the title and description updated now that the SSPS commit is dropped.

@RyanTheTide RyanTheTide left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Review at dbc5428. The shared shutdown path stops IRQ/polling and work before it waits out the command. A J413 warm boot should show its I2C Type-C ports and an attached dock re-enumerate. Please include a command that clears and a permanently busy one in the host coverage. The existing short-sleep results measure a different callback.

…path on a DT property, not T8140/T8142

Folds #2399 into this PR unchanged.

Signed-off-by: Ryan Murray <[email protected]>
@RyanTheTide RyanTheTide changed the title usb: typec: tipd: leave the controller idle at shutdown, recover a busy one at probe, SSPS rules by DT usb: typec: tipd: idle at shutdown, recover a busy controller, native display HPD keyed on a DT property Nov 25, 2026

This branch has not been deployed

No deployments
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.

1 participant