Skip to content

usb: typec: tipd: cd321x: J714s: SSPS and USBw at a cable change, as macOS does - #2598

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

DjDeveloperr merged 2 commits into
integration/aurorafrom
djdev/m5-j714s-tipd-macos-cable

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

J714s (M5 Pro): what macOS sends a port controller at a cable change, from a trace of macOS while the Dell monitor's port saw its cable go and come back.

Depends on #2597. This branch includes its commit; review only the last commit, cd321x: J714s: SSPS and USBw at a cable change.

What changes (every SN201202x on the J714s, only while running, not in a sleep's phases)

  • detach: register 0x50 written with 64 bytes 00 20 + 62 zeros (as macOS writes it; function unknown), then SSPS 0x02.
  • attach: SSPS 0x00, then USBw 0x00 at the update after the 500 ms debounce.
  • New tipd_usbw_locked(): USBw with CMD1 read at the sleep's SSPS gaps (5 ms). With back-to-back reads a J714s controller's USBw ended late or past its 1 s limit in about one of four attaches.
  • Linux used to send SSPS only at a sleep's ends and never USBw on the J714s, so the controller stayed as the change left it.
  • One log line per step. Switch: tps6598x_core.macos_attach, default on.

Testing (M5 Pro): 28 logind deep sleeps, each 40 s after a replug of the Dell's port. Every register 0x50 write, SSPS and USBw answered 0, and every device came back after each wake.

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

  • A detach's SSPS 0x02 is always undone at the next attach, in any phase but a sleep's or setup/removal.
  • MagSafe's controller (no connector) is left out.
  • The pending USBw flag is cleared at every cable change.
  • The test provenance in the message is corrected.

🤖 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-cable branch from 600fb72 to 07610a4 Compare November 20, 2026 20:28
…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]>
@DjDeveloperr
DjDeveloperr force-pushed the djdev/m5-j714s-tipd-macos-cable branch from 07610a4 to 7bfcd5d Compare November 20, 2026 20:47
@DjDeveloperr
DjDeveloperr merged commit 8f61970 into integration/aurora Nov 20, 2026
1 check passed
@RyanTheTide

Copy link
Copy Markdown
Contributor

Thanks, and for listing what changed after the independent review.

The same point as on #2597, for this commit's cable-change path. We select behaviour by a hardware property, not by the machines it was tested on. The reason here is the controller's protocol at a cable change, but it is gated on the board:

  • drivers/usb/typec/tipd/core.c:1553-1554 if (!READ_ONCE(macos_attach) || !device_is_compatible(dev, "apple,sn201202x") || !of_machine_is_compatible("apple,j714s"))

The controller compatible and the connector child already pick the right ports (and leave MagSafe's out). The J716c's SN201202x ports have both and are left out only by the board term. Could it go, or could a comment cite the hardware reason another board must not get SSPS/USBw at a cable change?

Two smaller things:

  • macos_attach (core.c:1535-1537) is a default-on module parameter. Fine for debugging, as long as nothing needs it.
  • The register 0x50 write (core.c:1541-1545) has no known function. A note on what fails without it, or dropping it if nothing does, would help reviewers.

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