Repository navigation
usb: typec: tipd: leave the controller idle at shutdown, recover a busy one at probe, SSPS rules by DT - #2398
RyanTheTide wants to merge 4 commits into
Conversation
…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>
|
Blockers: 4.
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 Assisted-by: LLM (Claude:Opus 5.5) |
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 <ryan@aurorasilicon.org>
…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 <ryan@aurorasilicon.org>
|
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. |
|
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. |
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 onapple,j714sonly: 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.ctipd_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 carryapple,sleep-ssps.Change
usb: typec: tipd: leave the controller idle at shutdown, recover a busy one at probetipd_cmd_wait_idle()polls CMD1 for that.tipd_shutdown(), used as.shutdownby 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.usb: typec: tipd: apply the sleep's SSPS rules by apple,sleep-ssps, not by boardapple,sleep-ssps(read once intotps->sleep_ssps). The board list is gone.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
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.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.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.oand all six KUnit test objects build. The only warning is the existingi2c.c:21enum cast, which is untouched.KUnit was not run: the build host is at load ~450. The test objects compile.
Still to run
Hardware rows: pending.
ls /sys/class/typec(all ports present). Do a warmsystemctl reboot, thenjournalctl -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.journalctl -k -b -1 | tailshows no 5 s stall at the tipd shutdown.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.Assisted-by: LLM (Claude:Opus 5.5)