Skip to content

usb: typec: tipd: leave the controller idle at shutdown, recover a busy one at probe, SSPS rules by DT - #2398

Draft
RyanTheTide wants to merge 2 commits into
integration/aurorafrom
sweep/tipd
Draft

RyanTheTide wants to merge 2 commits into
integration/aurorafrom
sweep/tipd

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

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.

Assisted-by: LLM (Claude:Opus 5.5)

…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 <hey@djdev.me>
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
…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 <hey@djdev.me>
Suggested-by: Nick <nekreshen@yandex.ru>
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
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