Repository navigation
usb: typec: tipd: idle at shutdown, recover a busy controller, native display HPD keyed on a DT property - #2398
RyanTheTide wants to merge 9 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 <[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]>
|
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: 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]>
|
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. |
RyanTheTide
left a comment
There was a problem hiding this comment.
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]>
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 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.#2399 original description
Problem
drivers/usb/typec/tipd/core.cpicks 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_displaywas also set only intipd_resume(), so it was false from probe until the first resume.Change
apple,display-native-hpdon the SN201202x node (documented inapple,sn201202x.yaml).tipd_init()reads it intotps->display_native_hpd, and the three sites use that flag.t8140-j700.dts(2),t8142-j704-usb.dtsi(3),t8142-j813-usb.dtsi(2, used by J813 and J815).DT coverage
From
dtc -I dtb -O dtsof the built DTBs:t8140-j700,t8142-j704,t8142-j813andt8142-j815are 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.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.
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, sodt_binding_checkwas not run.Still to run
Hardware rows: pending.
ls /sys/class/typecshows 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 injournalctl -k -b | grep -iE 'cd321x|sn201202x|typec'.