Skip to content

usb: typec: tipd: sn201202x: J714s: enter and leave a sleep as macOS does - #2597

Merged
DjDeveloperr merged 1 commit into
integration/aurorafrom
djdev/m5-j714s-tipd-macos-entry
Nov 20, 2026
Merged

DjDeveloperr merged 1 commit into
integration/aurorafrom
djdev/m5-j714s-tipd-macos-entry

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

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-ssps and no apple,usb-remote-wake: all three controllers)

  • prepare: the 500 ms poll stops first (it runs on a workqueue the freezer leaves running), the liquid detector is left alone (no LDCM at entry), S3 as before, then SPMI SLEEP right after it. macOS sends nothing more until the wake.
  • suspend: nothing more to a controller asleep since the prepare.
  • resume: WAKEUP, INT_EVENT1 read and the same 13 bytes written to INT_CLEAR1, STATUS/DATA_STATUS read, then SSPS S0, as macOS does.
  • complete: a sleep given up after the prepare wakes the controller; the poll restarts.
  • A register access that reaches a sleeping controller anyway is logged once per sleep with a stack, and gets the controller woken for it.
  • Switch: 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)

  • Switched in one boot: on, 15 sleeps, 0 hangs; off, 15 sleeps, 1 hang.
  • The hang came once more with this on (the SMC's late AP IDLE ack; the RTKit PR in this series covers that), so this alone isn't the fix. It removes SPMI traffic macOS doesn't send.
  • With the whole series (this, the cable-change and USB-wake PRs, the RTKit wait): 22 sleeps, 0 hangs, every device back after each wake.
  • The hardware gate on the integration tip plus this series is posted below when it's done.

Series (each targets integration/aurora so CI runs; merge in this order):

  1. this PR: sleep entry/wake
  2. cable change SSPS/USBw (includes this commit)
  3. USB wake arm after the PHYs' stop (includes 1 and 2)
  4. RTKit saved-scope AP state wait (independent)
  5. tipd debugfs replug test trigger (independent)

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

  • The macOS entry is taken only from a port last known dry or mitigated. Any other port enters as before, where LDCM can refuse the sleep.
  • A stray register access before the suspend keeps the controller awake, and the suspend sends SLEEP. After the suspend, SLEEP follows the access; the decision is passed through, not re-read.
  • The field is now macos_sleep, and the message describes Linux's extra reads honestly.

🤖 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-entry branch from 9d91a02 to 3c26593 Compare November 20, 2026 20:28
@DjDeveloperr
DjDeveloperr merged commit d527525 into integration/aurora Nov 20, 2026
1 check passed
@RyanTheTide

Copy link
Copy Markdown
Contributor

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:

  • drivers/usb/typec/tipd/spmi.c:1212 return READ_ONCE(macos_entry) && sn201202x_j714s() && sn->polled &&
  • spmi.c:789-792 sn201202x_j714s() = of_machine_is_compatible("apple,j714s")

The rest of that condition already describes the hardware: an apple,sn201202x controller, polled, with apple,sleep-ssps and without apple,usb-remote-wake. The J716c has the same SoC and controllers and is already in sn201202x_sleep_board() (spmi.c:784-787), yet keeps the old entry as written. Could the J714s term go, so those properties select it? If a board is known to need the old entry, a comment citing that hardware reason would cover it.

Smaller: macos_entry (spmi.c:1203-1205) is a default-on module parameter. Fine as a debug switch, as long as nothing needs it set.

We can run no-regression sleep 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