Repository navigation
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
Draft
RyanTheTide wants to merge 2 commits into
RyanTheTide wants to merge 2 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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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)