Skip to content

usb: typec: tipd: sn201202x: J714s: arm USB wake after the PHYs' stop, as macOS does - #2601

Merged
DjDeveloperr merged 3 commits into
integration/aurorafrom
djdev/m5-j714s-tipd-macos-usbw
Nov 20, 2026
Merged

DjDeveloperr merged 3 commits into
integration/aurorafrom
djdev/m5-j714s-tipd-macos-usbw

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

J714s (M5 Pro) deep sleep: arm each USB-C port controller's USB wake right after its PHY stops, and hand the lines back at the wake, as macOS does.

Depends on #2597 and #2598. This branch includes both; review only the last commit, sn201202x: J714s: arm USB wake after the PHYs' stop.

What macOS does (traces of its sleeps on the J714s, with and without partners)

  • Only on USB-C controllers with a partner, never on MagSafe's: a second window 0.5-0.65 ms after the port's ATC PHY CPU stops (54-73 ms after SSPS 0x03): CMD1 idle read, DATA1 = 0x09, USBw, its end read, SLEEP.
  • At the wake, with SSPS 0x00: USBw 0x80, then USBw 0x00.

What changes

  • apple-sleep's .prepare_late (after every device's noirq suspend, before the SMC scope) calls a new notifier chain.
  • With the macOS entry on, sn201202x wakes each J714s controller with a connector and a partner there, sends USBw 0x09 over polled SPMI, and puts it back to sleep.
  • At the wake it sends USBw 0x80 and 0x00 whenever the arm went out, even if its end wasn't seen.
  • Every USBw uses the gapped CMD1 reads. With back-to-back reads the arm timed out on both USB-C controllers, the lines were never handed back, and every USB device on them was gone after the wake (the dock's until a reboot).
  • Switch: sn201202x.macos_usbw, default on.

Testing (M5 Pro, Dell hub + Thunderbolt 5 dock attached): 28 logind deep sleeps, each 40 s after a replug of the Dell's port. Every USBw 0x09/0x80/0x00 answered 0, and every USB device on both ports came back after each wake.

Review: an independent review found nothing blocking. Fixed from it:

  • If the wake's WAKEUP fails, the complete wakes the controller and hands the lines back.
  • The USBw modes are shared with core (TIPD_USBW_*), and the connector check is cached at probe.
  • The docs say only T6050's .prepare_late calls the chain.

Open, for the early-wake work: these polled exchanges come after the SPMI controller's noirq park, and nothing re-acks the reply vector after them, as the debug-link cut does. The early-wake rate with this on is being counted in the J714s gates (none in the first 22 sleeps beyond the baseline 1).

🤖 Generated with Claude Code

…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]>
@DjDeveloperr
DjDeveloperr force-pushed the djdev/m5-j714s-tipd-macos-usbw branch from ab29c91 to 8e9f9de Compare November 20, 2026 20:28
DjDeveloperr and others added 2 commits November 20, 2026 15:47
…macOS does

A trace of macOS on the J714s, while the Dell monitor's port controller
(Linux's sn201202x 1-0a) saw its cable go and come back, shows what it
sends the controller at a cable change:

- 28 ms after the detach: register 0x50 written with 64 bytes, 00 20
  and 62 zeros (read back as zeros from 3 ms later; its function is not
  known);
- 60 ms after the detach: SYS_PWR_STATE read (0x00), DATA1 = 0x02 and
  SSPS;
- at the attach, after the events and the status registers: DATA1 =
  0x00 and SSPS;
- some 530 ms later: SYS_PWR_STATE read twice, DATA1 = 0x00 and USBw.

No other 4CC command goes to the controller between the detach and the
USBw. Linux sent SSPS only at a sleep's two ends and never USBw on the
J714s (no apple,usb-remote-wake), so after a cable change the controller
was left as the change left it.

On the USB-C ports' SN201202x of the J714s (not MagSafe's, which has no
connector and wasn't traced): register 0x50 as macOS writes it, then
SSPS 0x02, at a detach while running; SSPS 0x00 at an attach while
running, or at the attach after such a detach in any phase but a
sleep's or the port's setup and removal (whose own S0 or reset covers
it), so a 0x02 is always undone; and USBw 0x00 at the running update
after the attach's 500 ms debounce, unless the cable went again before
it. Each logs one line. The USBw reads CMD1 with the gaps
the sleep's SSPS uses (5 ms): read back to back, a J714s controller's
USBw ended late or not within its 1 s limit in one of four attaches.

/sys/module/tps6598x_core/parameters/macos_attach (default on) switches
it; 0 sends neither, as before.

The apple-dcp lifecycle selftests extract cd321x_update_work(); their
fixture gets a no-op cd321x_macos_usbw() where the update calls it.

Tested on the J714s (M5 Pro) together with the rest of the J714s macOS
sleep entry, in 28 logind deep sleeps each entered 40 s after a replug
of the Dell's port: every register 0x50 write, SSPS and USBw answered 0.
One of those sleeps hung (the SMC's AP IDLE ack, on a tree without the
saved lane's log echo) and one woke early; after every other wake every
device came back.

Signed-off-by: Diljit Singh <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…, as macOS does

Traces of macOS's sleeps on the J714s, with and without a partner on
the ports, show a second window on every USB-C port controller with a
partner, never on MagSafe's. It opens 0.51-0.65 ms after the port's ATC
PHY CPU has stopped and 54-73 ms after the controller's SSPS 0x03: CMD1
idle read, DATA1 = 0x09, USBw, its end read, DATA1 read, SLEEP. No
SYS_PWR_STATE read, and nothing else until the commit. At the wake, in
the window of its SSPS 0x00: USBw 0x80, then USBw 0x00, 11-18 ms apart.
Linux armed no USB wake on the J714s (no apple,usb-remote-wake), and
the macOS sleep entry ended the controller's part at SSPS 0x03 and
SLEEP.

apple-sleep's T6050 .prepare_late, which runs after every device's
noirq suspend (the USB PHYs' stops) and before the SMC's scope, now
calls a notifier chain (no other SoC's ops call it). sn201202x registers
on it on the J714s. With the macOS entry, each controller with a
connector and a partner is woken there, sent USBw 0x09 and put back to
sleep, over polled SPMI. At its wake, after SSPS 0x00, it gets USBw 0x80
and then USBw 0x00, whenever the arm went out, even if its end was not
seen; if the wake's WAKEUP failed, the complete wakes it and hands the
lines back instead: with back-to-back CMD1 reads
the arm timed out after 1 s on both USB-C controllers, was never handed
back, and every USB device on them was gone after the wake, the dock's
until a reboot. Every USBw now reads CMD1 with the sleep's SSPS gaps
(5 ms), and the controller ends it in time. Each step logs one line.

The USBw modes move to tps6598x.h (TIPD_USBW_*), and
tipd_usbw_locked() is exported for sn201202x. On a boot with
apple-sleep's debug link up, the SMC scope's cut resets that port's
controller after its arm; the wake's hand-back then goes to a controller
with no arm, which is harmless.

/sys/module/sn201202x/parameters/macos_usbw (default on, read at each
sleep) switches it; 0 arms nothing, as before.

Tested on the J714s (M5 Pro) together with the rest of the J714s macOS
sleep entry, 28 logind deep sleeps each entered 40 s after a replug of
the Dell monitor's port, with the Dell's hub and a Thunderbolt 5 dock
attached: every USBw 0x09, 0x80 and 0x00 answered 0. One of those
sleeps hung (the SMC's AP IDLE ack, on a tree without the saved lane's
log echo) and one woke early; after every other wake every USB device
on both ports came back.

Signed-off-by: Diljit Singh <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@DjDeveloperr
DjDeveloperr force-pushed the djdev/m5-j714s-tipd-macos-usbw branch from 8e9f9de to 298ad9c Compare November 20, 2026 20:47
@DjDeveloperr
DjDeveloperr merged commit d2e9e1f into integration/aurora Nov 20, 2026
7 checks passed
@RyanTheTide

Copy link
Copy Markdown
Contributor

Thanks. Handing the lines back at the complete after a failed WAKEUP is a good catch.

As on #2597 and #2598: the USB-wake arm is described as the controller's protocol after its PHY stops, but it is registered by board:

  • drivers/usb/typec/tipd/spmi.c:1027 if (sn201202x_j714s()) { (the notifier registration in probe)

The facts it depends on are already per device: an SN201202x with a connector (spmi.c:1028-1031) and a partner at the time of the sleep. Also, the chain is called only where apple-sleep's .prepare_late calls it. Registering for every SN201202x with a connector would let the J716c (same controllers) pick it up, and other SoCs would never be called. If a board must not get the arm, a comment with the hardware reason would cover it.

macos_usbw (spmi.c:1232-1234) is another default-on module parameter. Fine for debugging, as long as nothing depends on it.

We can run no-regression rows on the machines we have once it is keyed on the controller.

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.

2 participants