Repository navigation
usb: typec: tipd: sn201202x: J714s: enter and leave a sleep as macOS does - #2597
Conversation
08d64ba to
9d91a02
Compare
…does On the J714s about one deep sleep in ten to fifty, entered some 40 s after a Type-C event on the Dell monitor's port, hung before the commit. Traces of macOS's own sleeps on the J714s show it handles the three port controllers (both USB-C ports and MagSafe) differently at both ends of a sleep. At the entry, before any USB or PHY stop, macOS sends each one: SPMI WAKEUP, a read of SYS_PWR_STATE, DATA1 = 0x03 and 'SSPS', CMD1 read until the command ends (7-12 ms), DATA1 read, and SPMI SLEEP straight after it. No INT_EVENT1 read, no INT_CLEAR1, no LDCM and no LOCK, and nothing more until the wake. At the wake: WAKEUP, INT_EVENT1 read and the same 13 bytes written to INT_CLEAR1 (even when none are set), the status registers read, then SSPS 0x00. Linux sent S3 at the prepare but SLEEP only at the suspend. In between, the 500 ms poll, on system_power_efficient_wq, which the freezer leaves running, kept reading and clearing INT_EVENT1 and reading the status of a controller already in S3; these controllers have no interrupt on the J714s. sn201202x_prepare() also read the liquid detector first and could send LDCM, a command of up to 5 s, which these controllers have been seen to run for over 3 s and then fail with SPMI parity faults and NACKs; right after a replug a measurement can still be running. On the J714s, for a firmware sleep of a polled SN201202x with apple,sleep-ssps and no apple,usb-remote-wake (all three controllers), whose port is last known dry or mitigated (any other enters as before, so its detector reading or mitigation can still refuse the sleep): - prepare: the poll is stopped first (one already running finishes), the prepare neither reads the liquid detector nor sends LDCM, then tipd_prepare() as before (the port's work cancelled, then S3), and SPMI SLEEP right after it under the port lock. A SLEEP that fails is sent again at the suspend, as before; a refused S3 refuses the sleep as before, and the poll is started again. - suspend: nothing more is sent to a controller asleep since the prepare. - resume: WAKEUP as before, then cd321x_wake_events(): INT_EVENT1 read and the same bytes written to INT_CLEAR1, STATUS and DATA_STATUS read; then SSPS S0, which used to wait for the complete. What the poll would have kept of the events is kept (a plug event, a controller found reset, a new DisplayPort status); the resume's revalidation reads the whole port state afresh, as before. - complete: a sleep given up after the prepare, with no resume, wakes the controller there; the poll is started again if no resume did. Linux's own reads around the commands stay (the wake helper's MODE select, the CMD1 busy read before SSPS, the SYS_PWR_STATE check after it, the second WAKEUP of the switch to S0); what goes is the traffic macOS never sends between the entry and the wake. Nothing outside tipd calls into a port controller during a sleep except apple-sleep's debug link cut, which sends its own WAKEUP. A register access that reaches a controller asleep since the prepare all the same is logged with its call stack (the first in a sleep), and the controller is woken for it: before the suspend it then stays awake and the suspend sends SLEEP as before; after the suspend it is put back to sleep after the access. Besides the S3 and S0 commands' own lines, one line per controller at each end of a sleep: sn201202x 1-0a: sleep entry: poll and port work stopped, LDCM skipped (last result 1); S3 at the prepare, 14 ms; SLEEP: 0, 120 us after it; no sleep confirmation on the polled bus sn201202x 1-0a: sleep wake: events 00...00 cleared: 0; status 0x1080b2cd, data status 0x80008571; S0: 0, 12 ms after the WAKEUP; 0 register accesses while asleep /sys/module/sn201202x/parameters/macos_entry (default on, read at each sleep's prepare) switches it; 0 enters and wakes as before. Tested on the J714s (M5 Pro), each sleep a logind deep sleep 40 s after a replug of the Dell's port. Switched in one boot: on, 15 sleeps, 0 hangs; off, 15 sleeps, 1 hang. The hang came once more with this entry on (in the SMC's answer to the AP IDLE message, which a separate RTKit change addresses), so this alone doesn't fix it; it removes the SPMI traffic macOS doesn't send. With the rest of the J714s macOS entry and that change: 22 sleeps, 0 hangs, every device back after each wake. Signed-off-by: Diljit Singh <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
9d91a02 to
3c26593
Compare
|
Thanks for the careful write-up and the on/off sleep counts. One point on selection. We select behaviour by a hardware property, not by the list of machines it was tested on. The reason given here is the controller's protocol (what macOS sends an SN201202x at sleep entry and wake), but the path is gated on the board:
The rest of that condition already describes the hardware: an Smaller: We can run no-regression sleep rows on the machines we have once it is keyed on the controller. |
J714s (M5 Pro) deep sleep: the port controllers' sleep entry and wake, copied from macOS's traces of its own sleeps on the J714s.
What changes (J714s, firmware sleep, polled SN201202x with
apple,sleep-sspsand noapple,usb-remote-wake: all three controllers)sn201202x.macos_entry, default on; 0 keeps the old entry.Testing (M5 Pro, logind deep sleeps each 40 s after a replug of the Dell monitor's port)
Series (each targets
integration/auroraso CI runs; merge in this order):replugtest trigger (independent)Review: an independent review found nothing blocking. Fixed from it:
macos_sleep, and the message describes Linux's extra reads honestly.🤖 Generated with Claude Code