Skip to content

T6050 (M5 Pro, J714s): suspend to RAM - #1963

Merged
DjDeveloperr merged 25 commits into
integration/aurorafrom
j714s/t6050-s2r
Nov 15, 2026
Merged

DjDeveloperr merged 25 commits into
integration/aurorafrom
j714s/t6050-s2r

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

What this is

Deep sleep (suspend to RAM through the SoC's firmware sleep) on the 14-inch M5 Pro MacBook Pro (J714s), with Wi-Fi
and Bluetooth up, the SD reader's PCIe port, and a display on a USB-C port. 25 commits:

commit
01-04 rtkit/mailbox/SART/AIC, spin table, cluster power gate, PMP what the last steps of the entry need
05 soc: apple: sleep: T6050 the profile: entry, commit, wake, refusal
06-09 SMC, NVMe (ANS2), SIO/AOP/AOP2, HID/RTC/port controllers each coprocessor's stop and restart
10-11 display coprocessors (firmware 27), GPU
12-13 Type-C PHY and dwc3, PCIe (the N1's link, the SD reader's port)
14 J714s device tree the SoC data itself is the boot loader's
15-16 N1 (Wi-Fi/Bluetooth), headphone codec
17-20 binding, the internal panel's AV services, A407 swaps, the panel's wake sequence the panel lit after a wake
21 a display on a USB-C port across a sleep released before, plugged again after
22 SPMI controller: recovery after a failed exchange so that one bad reply does not take the PMU's RTC until a reboot
23 RTKit: the PMP's CoreAnalytics event on endpoint 7 acknowledged the PMP's one message some minutes after boot is answered, not refused
24 the sleep: the PMU's latched interrupt on the SPMI controller acknowledged every sleep after the first lasts, not only the first
25 host tests the tools' tests follow the series

Run on the J714s only. Every other machine keeps the base behaviour. The tree has eleven boards with this
SoC. The sleep profile is the J714s's alone, and everything this series adds outside the profile that changes what
a machine does is behind a test of the board (apple,j714s), of a node or property that only the J714s device
tree has, or of a firmware sleep, which only a profile gives. That includes what the display processors on
firmware 27 gained (the panel's AV services, A407 swaps, the sleep's answer on the endpoints): it is selected per
processor at probe on the J714s, and the other T6050 boards and T8142 run the base's code there. What is not
behind a test is bookkeeping that every machine executes (counters, flags, lists, tests that are false); each
item is listed under "Other machines". Nothing of this series has run on any board but the J714s.

The runs behind this text used the J714s device tree with its two USB4 router nodes disabled (see "Does not work
yet": a USB4 dock). The tree as it is in this repository, with the routers enabled, has not run with this series.

Works (measured on one J714s)

Measured with the private stack described under "What the public series cannot do alone" applied, with Wi-Fi and
Bluetooth on and both USB4 router nodes disabled in the device tree the runs booted. The last run, of this revision's
head with that stack: seven passes in one boot: six real sleeps and wakes, all clean by the run's checks and each asleep for 24 to 29 s
(the first until its RTC alarm; the other five ended some seconds before it, see "Does not work yet"), and a sleep refused
at .enter back to normal; each commit step started at its place in the device tree's schedule; the PMP's event was acknowledged
and no auxiliary buffer request was refused. Three later additions change what the machine does: the commit
window's steps now start at the device tree's schedule, and the timer honours the SMC's idle-to-timer spacing
(earlier revisions computed those times in 32 bits, which wrapped at the M5's 1 GHz counter, so every step was due
within a few microseconds before the timer and the steps ran back to back from there; every run of those revisions slept that way); the PMP's CoreAnalytics event is acknowledged (commit 23); and the PMU's interrupt latched on the SPMI controller is
acknowledged before each sleep and at each wake (commit 24): before it, once the first sleep's alarm had fired, every
later sleep of the boot was back within about a second. Three more are in the later runs only (most of
the runs behind the list below are of revisions without them): the port controllers are woken before their power
state command and the command's end is read at intervals, with a 1 s limit (in the runs that had it the command ended
in 10 to 11 ms on both controllers and no sleep was refused for it); the sleep's own PMU commands before the commit
run under the SPMI driver's lock and leave nothing in its reply FIFO (no PMU command has failed since); and the SPMI
driver recovers from a failed exchange (commit 22), which has not run: no exchange has failed since.

  • One sleep. A real deep sleep and wake (on the RTC alarm, or on the SMC's wake some seconds before it, see "Does not work yet"), 5 to 6 s of the kernel's clock from suspend entry to suspend exit in the last runs (that clock does not count
    the time asleep), with the
    internal panel lit at its level after the wake, Wi-Fi and Bluetooth back, the SD reader's port back in the early
    resume, NVMe and the root filesystem intact.
  • Several sleeps in one boot. Up to six sleeps and wakes one after another without a reboot; in the last run all six were clean and each
    was asleep for 24 to 29 s, the first until its RTC alarm and the other five not (see "Does not work yet"). After each wake: the GPU answers (a headless Vulkan query), AOP2's endpoints are open again, the SIO's firmware is up, the
    internal panel is lit, Wi-Fi and Bluetooth are back, the camera delivers frames, no display processor has crashed
    and the run's check of the pass found nothing wrong.
  • The external display returns at its full mode. In the two runs that had a 4K display on the left USB-C port
    (DisplayPort alternate mode), the display is released before the sleep and is back at 3840x2160 at 120 Hz within
    5 s of every one of those wakes. The later runs had no external display attached.
  • A sleep refused at .enter returns to a working desktop, camera included. A refusal forced behind the
    coprocessor checks, after one real sleep: every power word the entry had lowered is back, the panel is lit, the
    external display (where one was attached) is back at its mode, the GPU answers, and the camera delivers frames
    (its three DARTs are reset and restored at its next start). In the last run the five real sleeps that followed that refusal in the same boot were all
    clean. In earlier runs the sleeps after it were clean but for the PMP's message (below), and in one run they were
    refused (below).
  • The public boot loader. The later runs used the loader built from the head of the public aura PR arm64: dts: apple: t8140-j700: keep the idle E cluster out of its lowest OPP #214, which
    is merged into aura's main branch now, again with the private stack applied to the kernel.
  • The PMP's message some minutes after boot is answered. About a quarter of an hour after boot the PMP sends one
    CoreAnalytics event; in the last run it was acknowledged (the test head prints the acknowledgement; the public code
    logs it at debug level), and neither "refused auxiliary buffer request" nor "not acknowledged" appeared. Earlier
    revisions refused it with one error line; no sleep was refused for it, but the runs' checks marked that pass.

Does not work yet

  • A USB4 or Thunderbolt dock is not supported across a sleep. With the USB4 routers enabled in the device tree
    and a dock attached, the router stays powered and this series refuses the sleep at its entry check, before anything
    is stopped; the machine stays awake and working (read from the code). Development kits that took the router down
    for the sleep did sleep and wake with a dock attached, but the dock did not come back without a replug, or the
    machine failed right after the wake. The router firmware's own sleep and wake with the dock kept is not in these
    commits and follows in a later PR. That is why the runs for this PR had the two USB4 router nodes disabled in the
    device tree they booted. With the routers enabled and nothing attached to them their power words are off (the
    driver powers a router only while a USB4 or Thunderbolt cable is connected), so the entry's check passes; this was
    read from the code, not run. A display on a USB-C port in DisplayPort alternate mode does not need a router: it
    works and returns after the wake, as above.
  • Storage behind a dock (tunnelled NVMe) is not implemented and has not been tried; it comes with the dock work.
  • A sleep can end some seconds before its RTC alarm (known limitation, open). In the last run five of the six
    sleeps woke a few seconds before their alarm, after 24 to 28 s asleep, on the N1 radio's (Wi-Fi and Bluetooth)
    wake through the SMC, and the first ran to its alarm; every wake record carries the radio's bit (bit 13, which the
    J714s's SMC event names call wifibt, as on T8132). In earlier runs with the radio not booted, the sleeps ran to
    their alarm. What is missing is the radio's hand-over
    before the sleep. Sleep itself works: each of those wakes was clean by every check under "Works". Earlier revisions
    had a worse form: every sleep after the first in a boot came back within about a second; commit 24 fixes that, with
    its device tree property (see "What the public series cannot do alone").
  • A sleep can be refused, and then the machine stays awake and working. Two cases were seen. In one run a port
    controller had not ended its power state command at the earlier revisions' 3 s limit and the sleep was refused at
    the prepare; the change to that command in commit 09 (the controller woken first, the command's end read at
    intervals) is for this, and in the runs that had it no sleep was refused for the command. In another run, after the forced refusal, one of the sleep's own PMU
    reads before the commit failed (that sleep was refused) and left its reply in the SPMI controller's FIFO; the SPMI
    driver took that word for the reply to its next command and refused the bus from then on, the PMU's RTC went with
    it, no alarm could be armed, and the three sleeps that followed were refused for that. The PMU exchange under the
    driver's lock and commit 22 are for this: since the first, no PMU read has failed in any run; the recovery has not
    been exercised. Every one of these refusals returned to a working desktop.
  • A display behind a USB4 tunnel and one on the HDMI port refuse the sleep.
  • A crashed external display processor refuses the sleep until a reboot.
  • The dark-wake path with a released display was read, not run.
  • A lit keyboard backlight across a sleep or a refusal was not exercised (its PWM block is one of the idle words the
    entry switches off; the refusal's line names it if that happens).

Follow-ups, not in this PR: the N1 radio's hand-over before the sleep (the early wake above), a USB4 or Thunderbolt
dock across a sleep (the router firmware's own sleep), and the J714s's wake-record names: the SMC driver gives this
board's SMC T8140's bit table, but the J714s numbers its bits as T8132 does (the lid at bit 8, the radio at bit 13),
so the profile's wakes do not use the table: the wake record is printed without names and the lid is not read at the wake.

What the public series cannot do alone

With these 25 commits alone the internal panel does not light after a wake and an external display does not
return.
Both need the display coprocessors stopped and restarted between the stages of the wake, with DART and
power steps whose values are not in the device tree yet. AOP2's endpoints also stay closed after a sleep without the
wake message's words in the device tree (the next sleep then sends AP IDLE only). Commit 24 acts only with its device tree property (the SPMI controller's status word and the PMU's bits in it), which is the boot loader's to give: without it every sleep after the first in a boot is back within about a second, as before. That code, the device tree values
(the SoC's sequences and schedule with its runway, the display calls' argument bytes, the wait before the panel's
video interface is opened, AOP2's messages, the PMU's interrupt source that commit 24 acknowledges) and the per-step test code are kept in a
private stack on top of this series; everything under "Works" was measured with that stack applied. Their public
form: the DART steps through the existing lease interface, the power words from the sleep controller's device tree
data, the handshake through the PMC interface the binding already describes, the values from the boot loader.

The interrupt mask the SPMI buses have through the sleep is in the profile's match data, the same field and the
same value the T8140 and T8132 profiles already have in this driver.

Timings in the public code are the drivers' own choices, not a specification's: a port controller's power state
command is read 5 ms apart (a round value) with the driver's usual 1 s limit, and the rest are bounds (300 ms + 5 s
USB host stop, 15 s HPD low, 20 s display watcher, 250 ms per AOP2 wake answer and per external display device
call). The waits that place a step in time come from the device tree: the commit schedule and its runway, the
SMC's spacings, the wait before the panel's video interface is opened (commit 18; without the property it is
opened as it is announced). AOP2's ring and answer layout
in commit 08 is protocol structure read from the running firmware.

The public code keeps nine module parameters that select or switch off a step, each described in the code:
v27_two_stage, v27_soft_first, v27_sleep_power_oob, t6050_ext_services, t6050_ext_sleep (appledrm),
t6050_auss_off (the sleep driver), t6050_sd_port_wake (pcie-apple), sleep_s3_refuse, sleep_ssps_ms
(tps6598x). Their defaults are what ran; sleep_ssps_ms went from 3000 to 1000 with the port controllers' change,
and that ran in one run.

The other T6050 boards

What selects the sleep profile, per board. The base has no T6050 sleep profile at all: on every one of these boards
"mem" is s2idle today.

board sleep controller node (apple,t6050-sleep) in its device tree the profile's board test (apple,j714s) result with this series
J714s yes, added by commit 14 true the profile binds: deep sleep
J714c no false no profile: as the base
J716c no false no profile: as the base
J716s no false no profile: as the base
J775c no false no profile: as the base
J775d no false no profile: as the base
J873s no false no profile: as the base
K114c no false no profile: as the base
K114s no false no profile: as the base
K116c no false no profile: as the base
K116s no false no profile: as the base

The two tests are independent: the driver binds only a node with that compatible, and the T6050 profile's match
data names the board, so a node on another board is refused at probe ("unsupported board/CPU inventory"). The ten
other boards' compiled device trees are byte for byte the base's (all eleven were compiled before and after the
series and compared). Of the T6050 boards only the J714s has the nodes and properties the series' drivers need
beside the profile (the cores' power-gate enables, AOP2 and its mailbox, the SIO's mailbox, apple,sleep-ssps on
its port controllers).

Other machines

T8140 and T8132: their sleep profiles, tables and steps are as before, and no line is added to their console in a
boot, a sleep and a wake that succeed (one new error line exists for a coprocessor that does not acknowledge its
idle, row 01). What follows is every commit that touches code another machine builds, with what that machine
executes of it. "J714s only" names a test of the board in the code; "the profile" is the J714s's sleep profile;
"a firmware sleep" is one that a profile drives, so on a T6050 board other than the J714s it never happens.

commit shared code what another machine gets
01 RTKit, mailbox, SART, AIC Not behind a test of the board or SoC, every RTKit user: each received message is counted in and out of its work (two counters); the polled idle that T8140 and T8132 sleeps use counts what it receives and, only when an idle is not acknowledged, prints one error line with the last message. The new entry points and flags (ans_*, strict_*, the saved lane) are set by the profile's callers only. The mailbox's idle status is read on apple,t6050-asc-mailbox only, from the polled idle. The SART's new write rule is SARTv4's (only apple,t6050-sart has it) and is applied after a firmware sleep only. AIC: apple,t6050-aic3 gets its own match entry, the same description as before plus the save and restore around a firmware sleep, which are set up on the J714s only (another T6050 board: one test at boot)
02 spin table Not behind a test, every machine that holds parked cores through the spin table (T8140, T8132): each hold request has a generation that a held core acknowledges, and an error slot per core. The two new per-core callbacks (cpu_hold, cpu_restore) and the cpu_postboot that calls the second are absent or return at once without them, so those machines' cores do what they did
03 cluster power gate The driver's match and loop are the same; the node with the per-core words is in the J714s device tree only. T8140, T8132: the text of one debug line changes ("cluster N power gate" to "power gate N")
04 PMP apple,sram-keep is read only where the SoC's configuration has no range and the property is present. Not behind a test: the PMP's commit stop returns its error code where it returned 1 (on T8140 the number in the error line of a failed stop). The report driver's boot-time PTD step is for apple,t6050-pmp-v2-report with the property apple,ptd-boot: a T6050 board without the property gets one compatible test, one flag and one property lookup when the PMP is ready, and no write
05 sleep driver, DART Sleep driver: T8140's and T8132's operations and tables have no change; the shared functions take the T6050 branch only with the profile's regions, flags or optional operations. Executed on every profile: a power word's address goes through one helper (the same address without regions), a core's start and stop bits through one that takes the cluster from MPIDR affinity 2 unless the profile names another level (T8140 and T8132 name none: the base's bits), two arrays are larger, and each coprocessor registered for a first stop keeps a reference to its power-domain node. DART: the firmware 27 admission is for ten DARTs on the J714s; the ISP DARTs' save at runtime suspend and their lost mark are J714s only (the ISP DARTs of another T6050 board do what they did). Every DART: a mutex, a list and a counter are initialised at probe; one lock is taken around a bit set at of_xlate; each map, unmap, attach, TLB flush, domain finalize and domain free first walks the domain's DARTs for a flag that only the ten J714s display DARTs have, and goes on as before without it; the lifecycle mutex is taken at remove and tried at shutdown (it is free unless a J714s sleep lease pinned it); the system suspend and resume callbacks test flags that are never set there; one new debug line ("restoring after sleep"). The commit runway is read from the device tree by the profile. The SPMI controller driver, every machine: two exported functions that try and release its exchange lock; only the profile's PMU commands call them
06 SMC Every SMC: each command first passes a guard that returns at its first test unless the machine is the J714s with apple,t6050-smc; the driver gains .suspend and .remove callbacks, which return at once without a sleep policy (only the profile gives one). The warning, the notice and the wake record of other machines are the base's statements
07 NVMe (ANS) The sleep is the profile's, and its registration tests the board. T6050's ANS2 on every T6050 board: one counter is incremented per request and one flag is cleared at a reset, both read by the sleep only. Other controllers: tests of state that is never set there
08 SIO, AOP, AOP2 SIO: the T6050 description (the stop registered for the sleep's last steps, the line per wake and the failure line's new start) is J714s only; on another T6050 board the node is taken by its generic compatible, as before. Every SIO: two optional properties (apple,channel-threshold, apple,channel-limit) are read at probe, and without them the channel words are the SoC's as before; the system suspend and resume callbacks are wrappers that call the base's two functions unless the description is the J714s's; the commit stop T8140 registers returns its error code where it returned 1. Every AOP: two optional properties (apple,sleep-endpoints, apple,wake-endpoints) are read at probe; without them the order is the configuration's, as before. The AOP2 driver binds apple,t6050-aop2, a node only the J714s device tree enables
09 HID, RTKit helper, RTC, port controllers HID: only an interface whose node has apple,sleep-report (no device tree in this repository has one). RTKit helper: apple,t6050-mtp, in a firmware sleep only. RTC, not behind a test: the driver treats the alarm interrupt as optional for every compatible; the binding still requires it everywhere but T6050, so a correct device tree behaves as before. Port controllers (tipd): the wake before the power state command, its reads at intervals, the refusal, the limits, every new or changed line and the sleep-only handling of a controller without a connector are J714s only; elsewhere, other T6050 boards included, the lines, their levels, the command limits, the reads and the probe are the base's. Everywhere: two module parameters exist and do nothing, the prepare callback returns a value (always 0 there), the command function calls an inner one with a gap of 0 (the base's loop), and every SN201202x has a wake hook that is called under the J714s test only
10 display coprocessors The firmware 27 sleep and wake are for T6050 compatibles with the profile. What they need of the shared firmware 27 paths is J714s only, by a flag each processor gets at probe: a 12-byte message on channel 0 with a sleep or wake answer's code taken as that answer, the record of the AFK endpoints 0x20 to 0x3f, the marks for unhandled application traffic and a failed compact reply, and the sleep's A500 in the method table (a J714s copy of the 27.0 table; the shared table is the base's, so a 27.2 or 27.3 build is checked against the same list as before). Any other firmware 27 display (other T6050 boards, T8142): that flag tested, false. Every display endpoint: the jobs of a service are counted
11 GPU The stop at the commit and the lookups of its nodes are the J714s provider's. Every G17 GPU that restarts after a firmware sleep (T8140): an optional property (apple,sleep-ps-auto) is read when the domain is raised, and without it the saved state is used as before; the sleep's prepare asks the sleep driver whether the commit stops the firmware (false there, so the base's test decides). GPUs without the fabric bridge (T6040, T6041, T6050, T8142): the core gating is written again in that restart, which among those only the J714s reaches today
12 Type-C PHY, dwc3 dwc3: the stop of a running host from a work with its bounds, and the wait for a Type-C PHY that is not started after a sleep, are J714s only. Other machines: the base's stop statements are in a function that the notifier calls in place; the new .prepare returns at its first test; two works and a completion are initialised at probe and never queued; the role switch starts the controller through one call in place of two, with the same argument. PHY (the T6050 driver, so every T6050 board): the release of a wrapper domain still held at a stop, the stop of a safe state with a domain still held and the PM notifier are J714s only; the sleep callbacks act in a firmware sleep only; what is left on another T6050 board is tests of flags that only those paths set
13 PCIe The adopted host's sleep (its PM notifier, the port it takes down, the lookup of its DART) is set up on the J714s only. The T6050 host on another T6050 board: tests of flags that stay zero, in the config access, the suspend, the resume and the shutdown. Other hosts take none of the new branches; one module parameter exists everywhere
14, 17 J714s device tree, the display binding J714s only
15 N1 (Wi-Fi/Bluetooth) The T6050 N1 driver, so every T6050 board with an N1: the teardown and the reset act in a firmware sleep only, with a warm reset named by the root port's node; otherwise the suspend takes the base's branch. One idle workqueue is created when the module loads
16 headphone codec Not behind a test of the board or SoC, every machine with a CS42L84 whose "mem" is the firmware sleep, so T8132 too: the codec is reset, its cached registers are written back and the jack state is read again after the wake. Not run there. On a T6050 board other than the J714s there is no firmware sleep
18 panel AV services J714s only (the processor's flag): the endpoints 0x24 to 0x31 are started, each announced service opened, calls made on three of them (and on the HDCP interface with a device tree word), one info line printed, the video interface opened after a wait from the device tree, and a service announced without keys matched by its name on firmware 27 endpoints. Any other firmware 27 panel (other T6050 boards, T8142): not started, the name match as on the base; the flag tested, false
19 A407 swaps J714s only: a processor with the 27.0 method table there submits every swap as A407 with the longer request (its own copy of the table, its own request record and serializer, and A407 forms of the paired-display split and probe). Every other firmware 27 display (other T6050 boards, T8142), and a J714s on a 27.2 or 27.3 build: A408 with the base's table, request and code, behind one false test at the swap, in the paired swap and in the paired probe
20 the panel's wake sequence Reached from the firmware 27 sleep path only; three module parameters exist everywhere; at a firmware 27 mode set the J714s flag is tested before the sleep's mark is read
21 external display J714s only (the board and apple,t6050-dcpext): the Type-C reconnect skipped for a crashed processor, the refusal of a deep sleep by a crashed processor with its PM notifier, the link line with its search of the firmware's log lines and the EDID checksum. With the firmware 27 sleep (the profile): the release and the wake calls. Every display processor: a few struct members without a use, a flag test at the start, per mode set and at get_modes, one more read in the Type-C reconnect work, and the HPD low time through a field that is 0 there (the base's 1 s)
22 SPMI controller J714s only. Every other machine with a generation 4 controller (the other T6050 boards, T8142): after a failed exchange the next command tests the board and is refused, as before, and so is every later one. The earlier generations (T8140 and T8132 among them) keep their FIFO flush; that branch has no change
23 RTKit, the PMP's endpoint 7 J714s only: the one CoreAnalytics event with every field zero is acknowledged. Another T6050 board: a flag set false at boot, the endpoint's handling as on the base (that word refused with its error line). The handler exists only for apple,t6050-pmp-v2; no other SoC's coprocessors reach it
24 sleep driver, its binding The T6050 profile only (the J714s's), and only with apple,spmi-pmu-sources, a property no device tree in this repository sets yet (the boot loader is to give it): one read and at most one write of an SPMI controller status word before the sleep's SPMI masks and at the wake. Every other machine: nothing
25 host tests (tools/asahi) the test harnesses' stubs know the series' new fields and helpers, so the driver code they extract compiles again; every assertion and mutation they had is kept; no kernel code

Nothing else in the series runs on another machine. Not run on any machine but the J714s: all of the above is from
reading the code, which is why the rows below are asked for.

Known base bug this PR leaves in place on other machines. On every machine whose "mem" is the deep sleep, the
base's dwc3-apple PM notifier stops a running USB host inside the notifier chain (not for a fixed-hub port that
sleeps in place). A device driver that unregisters a PM notifier when its device goes then waits for the chain it
was called from: r8152 does, so a suspend with such an adapter on a Type-C port never gets past the notifiers. This
series fixes it (the stop runs from a work, bounded) but only on the J714s, the one board the fix has run on; T8140
and T8132 machines keep the base's behaviour, deadlock included. It was seen on the J714s only. The same fix without
the board test is the follow-up PR #1947, with its own rows. Whichever of the two merges second
drops the board test from commit 12's hunk.

Checks

  • C syntax (clang -fsyntax-only with an older tree's compile lines and generated headers), at an earlier revision of this series with 22 commits (later revisions changed some of them, commit 05 among them): every C file each of those
    commits touches, at that commit: 0 errors, apart from three files that are not compiled alone (the two KUnit
    files, checked through their parents with the test option defined at that revision's head, and the display
    template, through the file that includes it). This head is covered by its full build below and its test head by
    its native build on the M5. Rust not checked separately.
  • This exact public head: a full cross build (make ARCH=arm64 LLVM=1 Image modules, the M5 kit's configuration):
    builds, no error, no warning in a file the series touches. Its test head was built natively on the M5 for the run under "Works".
  • dtbs_check of apple/t6050-j714s.dtb against all bindings, at the public tip and the test head of an earlier revision of this series: 14 records, the same 14 as before this series' additions, none from the series. Not run again since; commit 24, added after that run, gives the sleep binding one more property (apple,spmi-pmu-sources), which no device tree in this repository sets.
  • All eleven T6050 boards' and the three T8142 boards' device trees compiled at the base and at the public tip: all
    identical but the J714s's, which commit 14 changes.
  • git diff --check on the public series: clean.
  • checkpatch (--strict) on the 25 commits: 0 errors, 207 warnings, 99 checks. The warnings are lines of 101 to
    125 columns, the author name against the sign-off's, bindings in the same patch as their code, memory barriers
    without a comment and new files without a MAINTAINERS entry.
  • No KUnit run.

To run before merge

The Neo rows failed on the two previous heads: after the first deep sleep three of the Neo's cores (E cores 1-3)
did not come back online (a 15.6 s resume where the base takes 0.17 s), and every later sleep was refused because
those cores could not answer the hold. Bisected on the Neo to commit 05, then to its sleep driver part. The cause:
the cluster's MPIDR level was written inline as affinity ?: 2, and MPIDR_LEVEL_SHIFT() uses its argument as
1 << level, unparenthesized, so the default never applied. On T8140 and T8132, which name no level, a core's
cluster came from affinity 0: on the Neo, E core 1 was started and stopped with P core 1's bits, and E cores 2 and 3
with bits no core has and with cluster words past the end of the CPU-start block. Commit 05 now reads the level
into a variable, so those machines compute the base's bits. The previous head's commit 26 (the base's hold on those
machines) was not the cause and is dropped.

Run on this head, on a Neo (T8140, J700) with its usual configuration and device tree (the rows are below):

  • Rows 2 to 4: pass, against the base kit's rows on the same Neo. The boot has no kernel line the base kit's boots
    lack (beyond addresses, sizes, times, the kernel's name and systemd's own start-up lines); both sleeps wake with all
    six cores online, back in 0.175 and 0.168 s (the base kit: 0.167 to 0.177 s); neither sleep adds a console line.
    Kits of the series up to commit 05 and of the previous head, each with only this fix added, pass the same rows.
  • Row 1: pass for the Neo's configuration. The base and this head were rebuilt with every C, Rust and device tree
    file the series touches recompiled: no warning in the series' files on either side. Of the series' files this
    configuration does not build, the T6050 radio, Bluetooth and DisplayPort PHY drivers are compiled by the M5
    configuration's full build under "Checks", and the tools' test files by CI's host tests; the two KUnit files are
    compiled by neither. The KUnit part was not run: neither configuration has KUnit, and CI's KUnit job runs the SEP
    suites only.
  • Row 5: pass. After the wakes, the Neo's device check (GPU, storage, audio cards, inputs, video nodes, Wi-Fi and
    Bluetooth) matches the Neo's default kernel, which does not have the series.
  • Row 6: pass. A sleep refused late, then one more deep sleep: no "refusal: raised again" or "refusal: switched off
    and on again" line, and the next sleep is clean, as on the default kernel.
  • Row 7: not run: no external display at hand for the Neo.
  • Row 8: not run: no T6050 board other than the J714s and no T8142 on firmware 27.0 at hand.

On a Neo (T8140, J700), this PR's head, the Neo's usual configuration and device tree, against the same kit without
the series:

  1. Build. No new warning in the series' files; the sleep driver's KUnit suite passes for all three profiles if the
    configuration has it.
  2. Boot to the desktop: no new console line. In particular no "incomplete sleep profile", no line of the T6050
    profile, no "port controller ready", no "ext N: link" line.
  3. One deep sleep and wake: it sleeps, it wakes, the Neo's resume time holds, and there is no new console line at
    all: no "restoring after sleep", no "SIO: restarted after the sleep", no "system power state S3 in N ms" or "S0 in
    N ms", no "command SSPS not done after", no "SLEEP: N", no "refusal:" line, no "host streams" line from a DART.
  4. A second deep sleep and wake in the same boot: the same.
  5. After the wakes, the Neo's usual device check (GPU, storage, audio, input, camera, Wi-Fi and Bluetooth): as
    without the series.
  6. A sleep refused late (the Neo's forced late refusal), then one more deep sleep: it returns as without the series,
    with no "refusal: raised again" or "refusal: switched off and on again" line, and the next sleep is clean.
  7. With an external display, if one is at hand: connect, mode set, one sleep and wake: as without the series, no
    "ext N: link" line, the firmware's own log lines at their level.
  8. On a T6050 board other than the J714s, if one is at hand: boot to the desktop and one suspend ("mem" is s2idle
    there): as without the series; no "port controller ready", no "ext N: link" line, no "panel AV" line, no line
    of the T6050 profile, the port controllers' lines as on the base. The same on a T8142 on firmware 27.0.

Rows 1 to 4 are required; 5 to 8 are cheap. Do not run a row with an r8152 adapter on a Type-C port: that hangs on
the base (above) and is #1947's row.

Also before merge: the SPMI driver's recovery (commit 22) has not been exercised on any head; a failed exchange has not
happened since the PMU exchange moved under the driver's lock.

🤖 Generated with Claude Code

…eep's last steps

On T6050 (M5 Pro) the sleep stops several coprocessors in its last steps, with
interrupts off and one CPU running, after the point where their drivers' own
.suspend could still refuse. This adds what those stops need:

- RTKit: a polled idle (AP IDLE and the firmware's IDLE_DONE, read from the
  mailbox with no interrupt), the mailbox's receive-enable bit for a client's
  own idle, a saved-context lane for the SMC (one AP message across the commit
  with its acknowledgement tracked), and the firmware 27 display stop's two
  state acknowledgements.
- RTKit: a strict restart that is refused now says why (the idle that was
  not acknowledged, a crash, or the power states the firmware reported). A
  second entry, apple_rtkit_warm_restart_stopped(), restarts a coprocessor
  whose CPU its owner has verified stopped after a sleep that turned its
  power off: the states recorded before the sleep describe a firmware that
  no longer runs, and refusing on them left the display dead (-EUCLEAN, -117).
  The refusal has not recurred since, so this entry has not run on hardware.
- Mailbox: send and receive without waiting, for those polled stops.
- SART: T6050's (v4) entries replayed after a sleep, and checked against the
  saved ones before ANS restarts. Every entry but the last is written back,
  in use or not, as macOS does at each wake: an unused entry otherwise keeps
  what the power-off left in it and fails the next sleep's check. The last
  entry is written only when it is in use; left idle it comes back from a
  sleep with flags and no range, which admits nothing and is accepted in an
  entry that is neither the boot loader's nor a driver's. The check names
  each entry it refuses, with what it reads, the snapshot and its owner.
- AIC: the sleep's mask-all and its event acknowledge, exported for the M5
  path that masks every interrupt in its last steps.

No functional change for other SoCs. What every RTKit user executes of this
is two counters per received message; the polled idle of the T8140 and
T8132 sleeps counts what it receives and prints one error line when an idle
is not acknowledged. The rest is used only by the T6050 sleep path.
The AIC's save and restore around a firmware sleep are set up on the J714s
only, the board the sleep has run on: on another T6050 board the AIC is as
before.

Measured on the M5 Pro (J714s): with these stops in place the SoC's sleep
engine gets past its coprocessor waits; with the full series a real sleep of
about 28 s on the RTC alarm returns with every coprocessor back.

Signed-off-by: Diljit Singh <[email protected]>
The Apple sleep holds the secondary cores in the spin table's hold loop while
it decides whether to enter. On T6050 each held core sets its own power-down
control before the commit, and puts it back if the sleep is refused or after
the core boots again:

- cpu_hold/cpu_restore power ops: a held core runs cpu_hold once per hold
  request, its result is collected by spin_table_hold_parked(), and an error
  releases the hold with nothing left changed.
- cpu_restore also runs when a held core is sent back to the park, and from
  the core's postboot after a wake.

No change for a power-ops user without the new callbacks.

Measured on the M5 Pro: a real sleep returns with all 18 cores back.

Signed-off-by: Diljit Singh <[email protected]>
On T6050 the power-gate page holds one word per core, and the boot loader
leaves the boot core's (core 0) and core 12's enable clear. With core 0's
clear, the boot core never powers off in WFI, so the boot cluster never powers
down and the SoC's sleep sequencer never gets past its first sequence: the
watchdog resets the machine about five seconds after the commit.

Add apple,t6050-cluster-pwrgate to the binding and describe the per-core case
in the driver; the J714s DT lists core 0's and core 12's words.

Measured on the M5 Pro without an OS: core 0 stays powered in WFI with its
word clear, and powers off once the word is set. Every real sleep of the
series ran with both enables set at boot.

Signed-off-by: Diljit Singh <[email protected]>
A real sleep on the M5 Pro loses the PMP's firmware SRAM. Without it the PMP
did not come back after the wake (-62). The PMP driver now saves the
firmware SRAM range the DT gives (apple,sram-keep, set by the boot loader)
before the sleep and writes it back before the PMP's run bit. The report
driver lets the sleep own the PTD entries it releases and raises around the
commit, writes the PTD entries the DT gives once the PMP runs
(apple,ptd-boot), and the PMP's commit stop reports its result.

Without the properties nothing is kept or written: the boot loader has yet to
provide them.

Measured on the M5 Pro: PMP back after a real sleep with this change;
without it, -62.

Signed-off-by: Diljit Singh <[email protected]>
Add the T6050 profile to the Apple SoC sleep driver: the sleep entry and the
wake on the M5 Pro's PMGR power, clock, perf and table banks of both dies,
the CPU clusters, the PMU over nub-spmi0 and the coprocessors' last stops.
With it the J714s enters a real deep sleep and wakes on the PMU's RTC alarm.

What it does, each step shown to be needed by a run without it:
- The stopped cores take the deep-sleep WFI after the commit: the first
  engine sequence completes.
- The memory performance floor stepped down before the commit.
- The radio's PCIe link shut down before the commit, its DART waiting for its
  host after the wake: the sleep stops turning round into a stalled wake: all 18 cores come
  up and the resume completes.
- nub-spmi0's sleep mask written first of the SPMI masks.
- The AP wake-enable words armed with every source but the DT's
  apple,wake-enable masked: the first real sleep, woken by the RTC alarm, the
  wake status the RTC's source alone.
- The storage link's power words forced on, polled and back to automatic at
  the wake, ANS fenced only on its own power chain: ANS back, root filesystem
  intact.
- The GFX die's interrupt controller word saved before the sleep and written
  back at the wake, GFX written off at the return: GPU firmware back.
- The AP pins saved and restored, all but the DT's apple,pinctrl-skip-pins: the pins the
  sleep changed are all put back and HPD is asserted.
- The display coprocessors' late stop for firmware 27 (V27) and the DART
  lease it needs from the DART driver.

The SoC's data comes from the DT, where the boot loader is to put it: the
commit window's schedule and the SMC's sleep spacings (without them there is
no deep sleep), the register sequences, word lists and values the entry and
the wake take, the clock and CPM set-up, the wake sources, the SPMI buses'
interrupt masks, the pins, the PTD entries, the DARTs' GAPF slices, and the
radio link's and the shared PCIe PHY's sequences. Any other item missing leaves its step out. The binding
documents each one.

The DART changes are in this commit because the sleep and the DART's V27
lease call each other. A DART whose sleep lease was lost keeps its lifecycle
lock; its shutdown now leaves such a DART alone instead of waiting for the
lock forever, which hung a reboot after a failed display restart.

The T6050 ISP DARTs keep their state at runtime, so their runtime suspend
saved nothing and no resume wrote anything, but the sleep resets the block:
after it the camera's firmware faulted on its first access. Their registers
are now saved at runtime suspend, marked lost in the noirq resume of a
firmware-driven sleep, and at the ISP's next power-up the probe's reset of
the host streams is repeated and the saved tables and controls are written
back and read back. Nothing is written at the wake itself, and the secure
core's streams stay untouched. The save and the lost mark are taken on the
J714s only; another T6050 board's ISP DARTs do what they did.

The retained-state check of the V27 lease took any changed table word for
lost state, and the display's sleep then failed at its late step. But an
external display's DART can come back from a real sleep with a different
table word on a stream that is off. Such a word is now accepted, only when
the stream is not enabled and neither the value before the sleep nor the
one after has the valid bit: it names no table, and it is behind the lock,
so nothing could put the old value back. It is logged once per stream per
boot with the DART, the stream and both values. A change on an enabled
stream, or a valid bit on either side, is still a loss. This is a
correction of the lease check this commit adds, so it is part of it. It
derives from Linux's own logs only.

Before the entry commits, the sleep controller reads the PMU's RTC on
nub-spmi0 by hand. That bus belongs to the SPMI controller's driver, and
the two share its reply FIFO: a reply word read in the wrong place would
refuse the sleep and stay in the FIFO, where the driver would take it for
the reply to its next command. The SPMI core's API can't serve these
commands: they run inside cpu_suspend(), on the boot core alone with
interrupts off, and the driver's exchange takes a mutex and sleeps while it
polls. So the exchange is by hand, but:
- it runs under the driver's exchange lock, taken without waiting
  (apple_spmi_fifo_trylock(), new in spmi-apple-controller). A held lock
  means an exchange of the driver's is under way: the sleep is refused
  (-EBUSY) and the bus left alone. The controller's device is found once,
  from the node at the sleep controller's "spmi" block.
- a reply word is read only when the status says the FIFO holds one; a
  short reply fails the command instead of reading an empty FIFO.
- after a failed command the late reply is waited for and the FIFO read
  empty, and a reply with more words than asked for is a failure, so
  nothing is left for the driver.
The commands behind the SPMI masks take no lock: the entry is committed and
the driver sends nothing until the wake. The SPMI driver itself only gains
the two exported lock functions; nothing calls them without this profile.

The profile is the J714s's: its node is in that board's device tree only,
and the profile's match data names the board, so the driver refuses the node
on any other. The other T6050 boards have no sleep profile, as before. The
interrupt mask the SPMI buses have through the sleep is the profile's match
data (spmi_notify_sleep): it matches the T8140 and T8132 entries, the same
field and the same value. The margin the entry keeps from the SMC's idle
notice to the timer, which no step of the commit schedule may reach, comes
from the device tree with the schedule (apple,commit-runway-us); without
the property it is the schedule's earliest step and one millisecond.

The T8140 and T8132 profiles, their tables and every step they take are as
before. What T6050 needs of the shared code is optional and taken only where
a profile sets it, and those two set none of it: an own register map
(map_regs), an entry that runs with the boot core's context saved first
(early_context, with its own platform operations for the late scopes), own
irreversible steps (commit_regs), own wake words (own_wake), a stated CPU
topology that the probe checks (cpu_clusters; the cluster's MPIDR level
stays 2 unless a profile names one), and per-core hooks for the held and
the stopped cores (a second spin-table operations table). A helper that
takes a power word's address goes through one function that returns the
same address as before for a profile without regions.

The cluster's level is read into a variable before MPIDR_AFFINITY_LEVEL():
MPIDR_LEVEL_SHIFT() uses its argument as `1 << level`, unparenthesized, so
`affinity ?: 2` written inline parses as `(1 << affinity) ?: 2` and the
default never applies. Written that way, T8140's E cores 1-3 took their
cluster from affinity 0: E core 1 was started and stopped with P core 1's
bits, E cores 2 and 3 with bits no core has and with cluster words past the
end of the CPU-start block, and none of the three was back after the first
sleep.

AUSS, the power domain the USB4 routers share, is taken down at the entry,
after each router's CIO_AUSS word, as macOS has it before every sleep. Linux
keeps AUSS always on, since not all of its users are described, so it was
the one domain still up at the commit, and a sleep entered with it on ended
in a reset five seconds later. The wake's replay raises the
words again; after a refusal the sleep driver does. One console line at the
entry has AUSS's word before and after. apple_sleep.t6050_auss_off=0 leaves
AUSS as it is.

After the wake each power word the replay could not raise is named, with its
bank and offset and the word before the sleep, at the wake and now. A word
under automatic power that was not fully on before the sleep (the SEP's) is
not counted: its owner starts it later.

The sleep claim of a display DART admits a short list of clients, filled
when a device's iommus entry is translated. A device whose iommus names
several DARTs is configured again until the last of them has probed, and
each attempt the IOMMU core abandons leaves its stream maps on the lists,
all for the same device. With the external display DARTs in the display
subsystem's iommus the internal display DART collected more entries than a
claim holds and the sleep was refused ("has an unexpected client"). When a
device gets a new stream map on a DART, the entries the list still has for
that device are taken off.

A refusal at .enter raises again what the entry and the stage lowered: the
idle power words, the words capped at state 4 and the PMC's sleep channels.
After a sleep the wake's replay raises them; after a refusal only AUSS had a
restore, and the words stayed down while the power-domain driver counted
them as on. With the camera's domain up at the entry, its children then
failed to power on and the next access to the camera was an SError. Each
lowered or capped word is remembered as it read and written back last
first; one line says what was raised, and each word that does not come back
is named.

A word the refusal switched off and on again is back, but the block behind
it comes back with its registers at reset, as after a real sleep, and
pm_resume_via_firmware() is false: no driver's resume writes them. The
refusal keeps the set of those words until the next sleep begins, names them
in one line, and apple_sleep_refusal_cycled() answers for one power
controller's node. The ISP's three DARTs sit in ISP_SYS, one of those words:
after a refusal stream 0's table and the remaps of the firmware's streams
were gone, the firmware's first access faulted (translation fault, TTBR
invalid), its first command timed out and the camera failed with -ETIME
until the next real sleep. Their noirq resume now asks for their own domain,
marks the host streams lost and writes the address filter back as after a
sleep; the restore itself is the one a real wake uses. Only the
apple,t6050-isp-dart DARTs ask, and a sleep driver without the T6050
profile answers false. Measured on the M5 Pro: after a sleep refused at
.enter the camera delivers frames again and three more sleeps in the same
boot are clean.

Signed-off-by: Diljit Singh <[email protected]>
… record

The M5 Pro's SMC takes the sleep notice in the sleep's last steps, after the
coprocessors' stops, over the RTKit saved-context lane, with the spacing the
sleep driver gives between its messages (pmVC, SLPA, the AP idle). Its log and report words that
arrive in that window are deferred and answered after the wake, before the AP
acknowledge; a command still in flight at the wake no longer quarantines the
SMC. The wake reads the SMC's wake record.

apple_smc_write_noirq() lets another driver write a key from its noirq
resume, with the reply polled for. SMC traffic stays interrupt driven; this
is the one exception, for the PCIe host's reset of the N1, which has to come
before the port's bring-up, itself a noirq step (see the pcie-apple commit).
The caller is ordered after the SMC's own noirq resume by a device link.

Measured on the M5 Pro: SMC back after a real sleep and its wake record read;
before, its noirq restore failed (-71) and it was quarantined.

The sleep notice is four steps (pmVC, MBSE = slpa, the AP's idle state, and
the messages drained around it), each with a bounded wait, and a failure
past the commit is fatal. A failed notice names its step, how long it was
given, how far into the notice it failed and the SMC's last reply.

Signed-off-by: Diljit Singh <[email protected]>
…ast steps

On the M5 Pro the sleep makes ANS's final stop itself, in its last steps. The
NVMe driver flushes and shuts the controller down in .suspend,
registers its last check and stop with the sleep, and after a real wake waits
for the sleep's receipt that the storage link's words are back before it
restarts ANS. A failed receipt fences the controller instead of restarting it
over a link that isn't there.

Measured on the M5 Pro: ANS restarts and the root filesystem stays intact
after a real sleep.

Signed-off-by: Diljit Singh <[email protected]>
The SIO and AOP2 run until the sleep's commit, which stops them in its last
steps. On T6050:

- The SIO is stopped by the sleep's commit with its polled idle; a runtime
  suspend would let its domain go off under the firmware. Its channel words
  come from the DT.
- AOP2 gets a driver that starts it and stops its endpoints for a sleep, then
  sends AP IDLE; its INIT argument and sleep message come from the DT, and so
  do the order its endpoints open in and the order they get the message in
  (apple,open-endpoints, apple,sleep-endpoints); without them, endpoint
  order.
- AOP2's rings are not made again across a sleep, so the sleep element goes
  where its ring's write pointer stands, with the endpoint's count in the
  message's first word, and the message that tells the firmware carries the
  ring's read pointer and its new and old write pointers. The firmware's
  answers are taken off its ring, so that ring does not fill up over the
  sleeps of a boot. An element written at the ring's start every time is
  right for the first sleep of a boot only.
- AOP2 is restarted after the sleep: AP ON, then the DT's wake message
  (apple,wake-message, new in the binding) on the ring of each endpoint the
  stop closed, each answer waited for by interrupt for at most 250 ms. The
  resume reads the sleep core's stopped flag before it clears the ready flag
  (clearing the one clears the other) and also goes by the driver's own
  record of its stop. An endpoint whose wake element is not answered stays
  closed and gets no sleep element at the next sleep; without a wake message
  all stay closed and the next sleep sends AP IDLE only. A stop that finds
  the firmware still in the last sleep's AP IDLE, or crashed, sends nothing.
  Without the restart the firmware stayed in the first sleep's AP IDLE and
  crashed at the second sleep's stop.
- AOP's driver already stops its endpoints and sends AP IDLE in its late
  suspend, and sends AP ON and START on each stopped endpoint in its resume.
  The order it stops them in and the order it starts them in now come from
  the DT (apple,sleep-endpoints, apple,wake-endpoints); without them the
  endpoints stop and start in endpoint order.

The bindings take the form in which the two run: the SIO's ASC bank split
around its mailbox window as on T8140, AOP2's ASC wrapper alone, and for
each its mailbox as a provider node that has the transport interrupts. A
node without a mailbox provider is described as before.

One line per wake from each: "SIO: restarted after the sleep, firmware up,
protocol v…, CPU control …" (the start reply's line is the probe's alone, so
nothing said the SIO was back), and "AOP: restarted after the sleep, AP ON,
N of N endpoints open again", or why not. The stop's line is followed by one
with the first endpoint's ring pointers, its count and the answers read. The
T6050 description of the SIO (its stop by the sleep's commit, the line per
wake and the new start of its failure line) is in force on the J714s only,
the board it has run on: on another T6050 board the node is taken by its
generic compatible, as before, and another SoC's SIO keeps its debug line
and its failure line as they were. The AOP2 driver binds a node that only
the J714s device tree enables.

Measured on the M5 Pro: with both stopped the commit's coprocessor checks pass
and a real sleep returns; four sleeps in one boot, with the SIO restarted and
all six AOP2 endpoints open again after each.

Signed-off-by: Diljit Singh <[email protected]>
…, the port controllers

- dockchannel-hid: an interface whose DT node has apple,sleep-report is sent
  those bytes before the MTP's idle.
- rtc-apple-pmu: the alarm's interrupt is optional. T6050's SPMI controllers
  are not described as interrupt controllers (the controller driver does not
  handle their generation 4 interrupt layout), so its RTC node has none; the
  alarm still wakes the SoC, which is how the sleep is woken. The binding
  gains apple,t6050-pmu-rtc with the T6041 fallback and requires the
  interrupt everywhere else.
- tipd: the SN201202x port controllers flagged apple,sleep-ssps go to system
  power state S3 and are sent SLEEP before the commit. A controller that
  does not take S3 refuses the sleep at the prepare, where nothing has been
  stopped yet, and is completed there (S0 again, the cable read anew): a
  sleep entered behind a controller that had stopped answering on its bus
  ended in a reset, the SMC not answering the sleep notice at the commit.
  tps6598x_core.sleep_s3_refuse=0 lets the sleep go on.
  The controller raises no interrupt for a command's end, so the end is read
  from the command register. Each such read is a register selection of its
  own, which the controller answers by loading the register again; read
  back to back, with nothing between the loads, and sent to a controller
  that nothing had woken since its probe or the last resume (these
  controllers are polled here, so the driver's idle sleep and the wake that
  goes with it are off), the power state command ended late or not within
  its limit. So the controller is woken before the command (the bus's
  WAKEUP, and the wait for its answer, on every path that changes the system
  power state) and its status is read at intervals, the caller sleeping in
  between: the first read a little after the command is written, the
  following ones 5 ms apart. The 5 ms is a round value, chosen to give the
  controller time between two loads of its command register, and the first
  read comes a quarter of it after the write; tested on the J714s. A command
  found ended is not called timed out because that read was made past the
  limit. The limit is sleep_ssps_ms,
  1000 by default, the limit every other command of this driver has, and
  1000 to 5000 by the parameter; a command with a limit above one second
  prints a line each second while it runs. The S0 command after the sleep
  prints its result and time; a controller that does not take S0 is set up
  again by its next event. A controller without a connector (the J714s's
  MagSafe one) registers no port: it is woken, switched and sent SLEEP with
  the system's sleep and is asleep otherwise.
  All of this is in force on the J714s only, the board it has run on: the
  wake before the command and the reads at intervals, the rule for a
  command that ends at its limit, the refusal, the limit and its use for S3,
  the lines (the wait's, the S3 and S0 results with their times, "port
  controller ready", the SLEEP result) and the handling of a controller
  without a connector. Other machines' port controllers carry
  apple,sleep-ssps too, other boards with the T6050 among them, and there
  everything is as before: the command goes out without a wake and is read
  back to back, a read made past the limit is a timeout, a failed S3 is the
  same warning and the sleep goes on, a taken S3 is the same debug line, S3
  has the default command limit and S0 5 s, the S0 command's result is not
  looked at, and a controller without a connector is probed like any other.
  The two module parameters exist everywhere and do nothing there.

Measured on the M5 Pro: the PMU alarm wakes a real sleep at its time (27.9 s
on a 30 s alarm by the machine's own clock), and both ports come back.

Signed-off-by: Diljit Singh <[email protected]>
The five display coprocessors of the M5 Pro (firmware 27) go through the
sleep: a reversible prepare at .suspend, then in the sleep's last steps A484
with the restartable-sleep flags and A500, the internal display's DART stopped
between the two, and their firmware's polled stop. The DART is stopped only
once A484 was answered: stopped before it, the firmware never answered A484,
the stop was undone and the suspend failed with the display left off. If the
DART's stop fails, the display is turned back on and the sleep is refused. At the wake, A500 in its wake
form, then A484 state 1 with the flags: the plain form after a flags-form
power-off is accepted and changes nothing. The calls' argument bytes come from
the DT; without them the V27 sleep calls are not made.

A step that fails names its phase and caller, and a resume that does not
restart a coprocessor says which earlier step failed. After a sleep that
turned the coprocessor off, a restart refused on the states recorded before
the sleep is done with apple_rtkit_warm_restart_stopped() once the
coprocessor's CPU is seen stopped.

Measured on the M5 Pro: all five DCPs restart after a real sleep, the
firmware reports the power-on, and with the pin restore HPD comes back. The
internal panel's link after a wake needs the panel's services and the wake
sequence of the later commits.

The sleep exchange closes and opens an AFK endpoint with a three word
message, and the firmware answers in the same form. Those twelve bytes also
read as a compact EPIC header: on an endpoint that has carried compact
traffic (an external processor's audio endpoint, once a display with audio
was attached) the compact parser dropped the answer as a broken fragment
and the sleep step timed out. The answer is now offered to the sleep code
first, which takes only its exact form.

What this needs of the paths every firmware 27 processor shares (the answer
offered to the sleep code first, the record of the endpoints 0x20 to 0x3f,
the mark for unhandled application traffic and for a compact reply that
failed) is behind one flag of the processor, set at probe for firmware 27
on the J714s, the board it has run on. Every other machine on firmware 27,
other T6050 boards and T8142 included, takes the paths it took before.
The sleep's A500 is in the method table of the J714s only, a copy of the
27.0 table made at probe: the shared table keeps its methods, so the list a
27.2 or 27.3 build is checked against before it is started stays what it
was.

Signed-off-by: Diljit Singh <[email protected]>
…start

On the M5 Pro the GPU firmware is stopped in the sleep's last steps, before
its commit (GFX then GFX1: AP IDLE, IOP IDLE, receiving and the CPU's run bit
off), and restarted after the wake with its core gating written again before
the run bit: a real sleep powers the domain off.

After a first sleep the GPU's domain runs under automatic power, as it does
under macOS: between jobs its power word has its target on and nothing
powered, with the firmware still running. Before a first sleep the boot's
word never reads that low, so a first stop always finds the domain up. A
stop that takes such a word for a domain that is off sends the firmware no
IDLE, and the second sleep of a boot then leaves firmware that was never
stopped: after the wake neither instance answers the restart ("RTKit:
endpoint discovery failed: -62", "GPU firmware did not come back: ETIME")
and the device is lost for every client. A word with its target on and
automatic power enabled is not off: the stop takes the domain out of
automatic power, waits for it to be up, and idles and stops both instances
from there; the wake puts automatic power back as the stop found it. A
domain that is really off, or that does not come up, is still not touched,
and the stop warns that the firmware was not stopped.

Measured on the M5 Pro: both GPU roles initialize after a real sleep, and
vulkaninfo answers after the wake, also after a second sleep in the same
boot.

Signed-off-by: Diljit Singh <[email protected]>
On the M5 Pro a firmware sleep takes the Type-C PHY's state. The PHY idles its
CPU, with no power-down message, and powers down at a system sleep, keeps a port's always-on
USB domain if the port is in use, forgets its cached hardware state at the
noirq resume and restarts from the first mode set after the wake; a sleep that
is abandoned restarts it in its old mode. dwc3-apple waits for its PHY after a
sleep instead of failing its reset, on the J714s; elsewhere a
PHY that is not started is the error it was. What the PHY gained outside its
sleep callbacks (a wrapper domain still held at a stop is released, a safe
state with a domain still held is stopped again, and the notifier that holds
a port's always-on domain over a deep sleep) is in force on the J714s only;
on another T6050 board the stop, the safe state and the probe are as before.

That wait does not ask whether the sleep was a real one: a suspend that a
driver refuses after the port controllers went to their sleep state leaves
the PHY stopped in the same way, and a PHY that kept running never reports
-ENOLINK. While the wait is open, a role switch that still comes before the
port controller's mode request returns the error without a line in the log,
and the port controller tries again. This corrects the wait this commit
adds, so it is part of it: with the wait tied to a real sleep, a second
suspend refused by the display (-16) left both controllers with "Failed to
start after sleep, err=-67" until the port controller's next try (two
runs, our own logs).

Measured on the M5 Pro: both ports "CIO mode up" after a real sleep, xHCI
buses registered, no -67 from dwc3 and no SError; before, dwc3 failed to
deassert its reset (-67) on both controllers.

A host stopped for a deep sleep was stopped from PM_SUSPEND_PREPARE, which
disconnects its devices inside the PM notifier chain. A driver that
unregisters a PM notifier as its device goes then waits for the chain it was
called from: r8152 does so when its interface closes, and with such an
adapter on a port the suspend never got past the notifiers. The stop now
runs from a work. The notifier waits 300 ms for it and otherwise lets the
chain go on; the stop then ends behind the chain, and the controller's
prepare callback, after the freezer and before any device suspends, waits
up to 5 s for it. The glue of a running host is a syscore device, for which
the PM core calls no prepare, so the notifier lifts that mark while a stop
is left running. A stop that has not ended by the prepare's limit, or that
failed, refuses the sleep. The start after such a sleep, or after one given
up, comes from a work that follows the stop. A stop that ends within the
notifier's wait leaves everything as it was, and so does a controller that
is not a host.

The stop from a work has run on the J714s only, and the path is every
Apple SoC's, so it is taken on that board only. Elsewhere, other boards with
the T6050 included, the stop stays inside the notifier chain, as before,
r8152's wait included, until a sleep with a USB device attached has run
there with the work; the same change without the board test is a separate
patch.

Signed-off-by: Diljit Singh <[email protected]>
…ader's port

With a host driver bound, a firmware sleep on the J714s was refused (-EBUSY).
Now, for the port a boot loader trained (the N1, Wi-Fi and Bluetooth):

- noirq suspend: the routes and interrupt mask saved, the DART saved and
  gated, then the sleep driver's link shutdown.
- noirq resume: once the sleep driver has the shared PHY and the root complex
  running again, the port's reset table and enable, the root complex setup,
  the sleep driver's port wake steps, the routes, the DART, its DART wake
  steps, then the lane clocks, PERST# and the link. The wake steps are the
  boot loader's, from the DT. A wake that fails leaves the port held down and the
  functions marked disconnected.
- The N1's firmware does not survive the sleep and the N1 needs its warm
  reset (the port's apple,function-warm-reset: the SMC and its key; the
  writes are the boot loader's, apple,warm-reset-writes). The reset is given
  in the noirq resume while the port is still down, before the port is set
  up, so the link trains a chip that was just reset. Given later, on a
  trained link, the reset took the link down and it never came back; that
  left Wi-Fi and Bluetooth dead after every sleep.
- That reset is an SMC write with its reply polled for, the one SMC write
  outside the interrupt-driven path. It can't move to a phase with interrupts:
  the port has to be up before the PCI core's noirq restore of the root port
  and the functions, and the reset has to come before the port. The host is
  ordered after the SMC by a device link.
- apple_pcie_t6050_warm_reset_done() tells the N1's driver that the host gave
  the reset at this wake. For a suspend abandoned before the host's shutdown,
  where the link never went down, apple_pcie_t6050_port_recycle() takes the
  port down, gives the reset and brings the port up, in process context with
  the SMC's interrupt.

The host can probe before its DART. It then found no DART to hand the port's
state to and refused every sleep (-EBUSY) until a restart; it now looks the
DART up again when a suspend starts, before the freeze.

A port Linux powers and trains (the SD card reader) has its functions removed
and the port parked before the freeze, as macOS takes that port down before
the radio's. Its DART is clocked by the port: it is saved and gated before
the park and marked as one its host resumes, so nothing writes it while the
port is down. The root port is suspended at run time before the park, while
it still answers; left idle, it was put into D3hot a moment after the park,
through a port that no longer answered ("Unable to change power state from
D0 to D3hot, device inaccessible").

After the wake that port comes back as under macOS, after the radio's port:
the reader's power, 150 ms for it (the wait of the
boot-time bring-up of the same port), the port's reset table and enable, the
root complex setup, the routes, the DART, the lane clocks, PERST# and the
link. The reader's power is an SMC key behind the SMC's interrupt-driven
path, so this is the host's early resume, the first phase with interrupts
and the one right after the noirq phase the radio's port comes back in. The
root port's config space went with the port's registers; it is written back
there from a copy taken before the park. The port's functions are looked
for once the resume is over, where devices can be added.

The PCI core's own noirq resume of that root port still runs before the
port is up: it reports the root port once ("Unable to change power state
from D3hot to D0, device inaccessible") and restores nothing. Avoiding that
line would take the reader's power written with a polled SMC reply in the
noirq phase, a second SMC write outside the interrupt-driven path.

After a suspend that was abandoned, or a wake that could not give the N1
its reset, the N1's driver takes the radio's port down and up once more,
and the shared PHY with it; the parked port then comes back when the resume
is over. pcie_apple.t6050_sd_port_wake=2 does that at every wake, and 0
leaves the port parked, with no functions, until a restart. A port still
parked at shutdown is left as it is.

Measured on the M5 Pro: the shutdown with the link's domains held is what lets
the sleep's wake programs run. With the reset before the port, Wi-Fi and
Bluetooth are back after a real sleep and after a suspend that was refused
late. The wake path and the bound-driver case ran on the J714s with the
rest of this series, with the two USB4 routers disabled in its device tree
and the SoC's values the device tree does not carry yet supplied on top
(see the PR).

The host's part of the sleep (its PM notifier, the port it takes down and
the DART it looks up for it) is set up on the J714s only, the board it has
run on. On another T6050 board the adopted host registers nothing and is as
before.

Signed-off-by: Diljit Singh <[email protected]>
Describe the J714s's sleep: the sleep controller with its blocks, the
coprocessors it stops, the radio's PCIe host and the AP pin controller. Also
the PMU's RTC with its alarm as a wake source, the per-core power-gate
enables, the domains kept on through the commit, the port controllers' sleep
state, AOP2 and its mailbox, the SIO with its mailbox, and the N1's warm
reset on its PCIe port.

The SoC data the boot loader is to add (see the bindings) is not in this
tree; with it the J714s's default sleep becomes deep (suspend to RAM).

Signed-off-by: Diljit Singh <[email protected]>
The N1's firmware does not survive a firmware sleep on the M5 Pro. Its
drivers saved the functions' config space and expected the firmware to be
there after the wake; Wi-Fi and Bluetooth were dead until a restart.

Now, when the root port names the N1's warm reset and the SMC is bound:

- Before the sleep every DMA mapping of the three functions is released and
  the firmware is told nothing: Bluetooth removes its HCI device and frees
  its arena in its own suspend, then the Control function's suspend takes
  Wi-Fi and every IPC and boot buffer down. The root port's
  apple,endpoint-sleep-smc-writes, if the boot loader gave any, follow.
- After the wake the host has reset the N1 before its link trained (see the
  pcie-apple commit). The Control function's resume writes the root port's
  apple,endpoint-wake-smc-writes, if any, and queues one work item for once
  tasks run again: it removes the three functions and enumerates them again,
  so the firmware boots from its ROM as at power-on.
- After a suspend abandoned before the host's shutdown the N1 was taken down
  but its link never went down. The work item then has the host take the
  port down and up around the reset (apple_pcie_t6050_port_recycle()): a
  reset on a trained link loses the link for good.

Measured on the M5 Pro: Wi-Fi and Bluetooth back after a real sleep and
after a suspend refused late.

After a suspend that was abandoned with the radio's link still up, the
functions are removed and the host cycles the port around the warm reset.
With the functions gone the root port is idle and its runtime suspend could
start while the host had the port down; the link was then not active after
the port came up. A runtime PM reference is held on the bridge from before
the removal to the new enumeration.

A suspend given up after Bluetooth's suspend and before function 0's own
leaves function 0 running, with its IPC holding interrupt vectors and DMA
buffers of functions 1 and 2. Removing the functions in that state freed
those vectors on a device with no MSI data left (a NULL dereference, with
the PCI rescan lock held, so the suspend never exited). Function 0 is now
taken down first, as its suspend takes it down, while all three functions
exist.

Signed-off-by: Diljit Singh <[email protected]>
A firmware-driven system sleep on the Apple laptops ends with the
codec's reset line asserted: the platform's sleep entry drives it low,
and the pins are put back that way after the wake. The driver had no
system sleep callbacks, so nothing released the reset again and nothing
wrote the registers back. Every transfer after the wake was refused by
the bus with no acknowledge, and the jack stayed dead until a reboot.

Add system sleep callbacks for that kind of sleep. On suspend, stop the
interrupt and the remote poll, close the register map to the bus, mark
the cache dirty and assert the reset. On resume, release the reset and
wait as the probe does, check the device ID, write the cached registers
back, set plug detection up again and report the jack as it is now, in
case the plug changed while the machine slept.

The codec restarts on its internal oscillator, and stops answering if
it is switched to a clock that isn't running, so the clock selection in
the cache is put back to the oscillator before the registers are
written. The next unmute sets the clocks up as usual.

A failed resume logs one line naming the step that failed; after a
failure the register map stays closed, so later writes land in the
cache.

Other sleep states don't reset the codec and are left as they were.

Signed-off-by: Diljit Singh <[email protected]>
…round a firmware 27 sleep

Four properties of the T6050 internal panel's display coprocessor, read by
the display driver's sleep and wake path and by its panel AV services:

- apple,sleep-display-power-args: the eight bytes after the power state in
  the plain set_power_state (A484) request, the one that moves the display's
  own state without the sleep's power-down;
- apple,sleep-display-stage-args: the arguments of the two calls with
  arguments made before that request, A414's eight bytes and A487's four;
- apple,panel-hdcp-open-arg: one word of the call made to the panel's HDCP
  interface when it opens;
- apple,panel-video-open-delay-us: the wait between the announcement of the
  panel's video interface and its opening.

Like apple,sleep-power-args and apple,sleep-a500-args they are set by the boot
loader. Without the first two the display's own state is left alone across
a sleep. They are allowed on apple,t6050-dcp only: the driver moves the
display's own state for the internal panel alone.

Signed-off-by: Diljit Singh <[email protected]>
On DCP firmware 27 the internal panel's display processor announces its
AV and DisplayPort services (device, service, video interface,
controllers, power, ambient compensation, HDCP) and its descriptor
manager on endpoints 0x24-0x31. macOS opens every one of them at boot,
and again whenever the firmware announces them afresh after the display
pipeline powered on; it then makes one call on the DP device, the AV
controller and the ambient compensation service. Linux never started
these endpoints, so the firmware's announcements went unanswered.

That is harmless while the boot link stays up, but after the pipeline
is powered off and on the firmware publishes the video interface, sees
the panel's hot-plug, and then waits: it exports no modes, and the next
mode set times out with the panel dark.

Start the endpoints after IOMFB, open each service as it is announced,
make macOS's calls, answer the ambient compensation service's own call
as macOS does, and tear a service down when the firmware closes it so
its slot is reused by the next announcement.

The video interface is opened only after the firmware's own plug on it,
which ends by closing the interface, and before the firmware's next round
of reports: it exports the panel's modes only if the interface is open by
then. The wait after the announcement that puts the open there comes from
the device tree (apple,panel-video-open-delay-us, where the boot loader is
to put it); without the property the interface is opened as it is
announced.

The HDCP interface gets one call when it opens, as macOS makes it; one word
of it comes from the DT (apple,panel-hdcp-open-arg) and without the
property the call is not made.

These services exist on a firmware 27 internal panel (T6050, and a T8142
that reports firmware 27.0). They are started on the J714s only, the board
this has run on: the start of the endpoints, their lookup for received
messages and the name match for the descriptor manager are behind the
processor's J714s flag. Every other firmware 27 panel leaves the
announcements unanswered, as before.

Signed-off-by: Diljit Singh <[email protected]>
…does

The firmware 27 method table sends swap_submit as A408 with a 0xff4-byte
request, the layout carried over from H17P, where A407 is unused. macOS
27 never sends A408: every swap, on the internal panel and on an
external display, goes out as A407
with a 0x1d30-byte input and a 12-byte reply, after its A406.

The A407 request is the A408 one up to +0xfb0 (the swap record, four
surface descriptors and their DVAs, unk_u64_a), then six more surface
descriptors from +0xfd0 and their DVAs from +0x1cd8, then the same tail
(unkbool at +0x1d08 through unknown_output_null at +0x1d2f), with ten
surface null flags from +0x1d23 instead of four. macOS flags the
surfaces it does not present null.

On the A408 path, a present of an overlay surface alone (surface 0 not
in the swap) darkens the whole panel until the overlay is removed. This
happens with the surface IDs, surface flags, swap-record fields and
surface descriptor macOS uses on its cursor-only swaps set one by one
and all together, and with the overlay on surface 3, the surface macOS
uses for its cursor. The swap call is what still differs.

Send swap_submit as A407 with that layout on the J714s, the board it has
run on. The 27.0 method table and the A408 request, its serializer and the
paired-display code that uses them are left as they are; a processor on
the J714s with the 27.0 table has its own copy of the table, made at probe,
with that one entry changed, and the A407 request beside the A408 one (its
own serializer, its own records, and A407 forms of the paired split and of
the paired-display probe). Every other machine on firmware 27, other T6050
boards and T8142 included, sends A408 as before. The six extra
surfaces are not presented and are flagged null. The reply is the same.

Signed-off-by: Diljit Singh <[email protected]>
After a firmware 27 sleep the internal panel stayed dark: the resume's mode
set timed out, and the display's own state was never moved. This brings the
sleep and the wake of the internal display into the order macOS has:

- The display has two states, the hard power state (set_power_state with
  the sleep's flags) and its own, soft state (the plain set_power_state,
  with a short stage of calls before it). Before the sleep the soft state
  goes off first, then the hard one; at the wake the hard one comes on
  first, then the stage and the soft one. The stage's arguments and the
  plain request's bytes come from the DT (apple,sleep-display-stage-args,
  apple,sleep-display-power-args); without both the soft state is left
  alone, as before.
- After each hard power call the AP's state word (A115) is sent, with A489
  before the call.
- Every set_power_state of a sleep and a wake goes on the command context.
- No mode set after the wake's power-on when the mode is the one the panel
  has: the firmware brings the link and the mode back itself once frames
  arrive, and a mode set sent before that waits out the firmware's timeout.
- The last frame is presented again right after the power-on, with the
  colour matrix and its brightness correction before that swap.
- That present carries the panel's level: it comes before DRM's DPMS-on
  and the backlight core's resume, so the DPMS-off, suspend and blank marks
  are cleared for it. The resend budget stays for the firmware's
  enable-backlight request that follows the power-on.

Reached only from the firmware 27 sleep path of apple,t6050-dcp; the mode
set's test of the mark the sleep leaves is behind the processor's J714s
flag.

Signed-off-by: Diljit Singh <[email protected]>
A T6050 external display processor refused the system sleep while a
display was attached to its USB-C port. macOS does not keep an external
display's session across a sleep either: it unplugs the display from the
firmware's side before the sleep calls, the processor then sleeps like
an idle one, and the display is plugged again after the wake.

Do the same. At the processor's suspend, with the DRM device already
suspended, the display is released through the path a pulled cable
takes: the display and its audio, the DPTX link, HPD toward the
firmware, the DP PHY and the crossbar output. The port is held unrouted
until the wake, so a port controller event during the sleep cannot route
it again. The processor's own sleep sequence is unchanged. A released
display's CRTC resumes disabled, as one whose mode needs a new link
does, and the port controller's state after the wake, applied anew,
brings the display back as a newly plugged one on the pipeline it had.
A suspend that fails after the release lets the port go at once, since
a device whose suspend failed gets no resume.

Every external display processor, idle or not, now also gets the wake's
two calls, A500's wake form and the power state with the sleep's flags,
as macOS sends them. The flags move the firmware's hard power state, and
the plain form after a flagged off changes nothing: without the calls a
display plugged in after a sleep would stay dark. The pipe state the
driver tracks is left as it was before the sleep, so the display's own
power-on goes through the usual path.

appledrm.t6050_ext_sleep=0 gives the previous behaviour: the sleep is
refused with a display attached, and the external processors get no wake
call. A display behind a USB4 tunnel and one on the HDMI port still
refuse the sleep.

Only reached on apple,t6050-dcpext with the firmware 27 sleep selected.

A suspend given up after the release brings the display back the same
way, and the sleep calls wait for the release to settle first: the
firmware's own unplug work must be over before the processor's sessions
close.

With a display, an external processor announces its AV and DP device and
service interfaces at every plug. Once the sleep step has started their
endpoints, an announcement left unanswered holds the firmware's plug before
it reports the display. They are now opened as announced, and the DP device
gets its first call. An interface the firmware ends itself that has a call
or an opening unanswered at the sleep is skipped, never waited for.
appledrm.t6050_ext_services=0 leaves them unanswered.

A watcher reports whether the released display is lit again within 20 s of
the resume. A display that is not is given up: its port is released as at
the sleep, with a bound above the firmware's own wait, so the next sleep
finds an idle processor instead of a link it cannot take down.

An external processor that has crashed refuses the sleep in the PM
notifier, before anything is stopped; stopping a crashed processor for a
sleep is not implemented.

Each processor's sleep step notes its calls with their results and times
on one line.

The Type-C reconnect work leaves a crashed processor's port alone, once
and said, instead of running each call of a connect to its limit; on the
J714s's apple,t6050-dcpext only, the others try their connects as before.

Whether a display that came back after a sleep at another mode has another
link, another mode list or only another mode could not be read from the
log. After a mode set on an external display, one line: the rate and lane
count of the firmware's last link configuration, whether its mode set used
DSC (from the line the firmware prints for every mode set), the size of
the mode list, the published EDID's maker, product and CRC, and the mode.
It is printed once per connection and again when any of it changes, on the
J714s's apple,t6050-dcpext only. The line, the search of the firmware's log
lines it needs (a separate RTKit operations table, so no other processor's
log line is looked at) and the EDID's CRC at get_modes are behind one flag
of the hardware description that only that compatible sets and that is
cleared at probe on every other board; every other display processor does
what it did before this commit. The refusal of a deep sleep by a crashed
processor, and the PM notifier it needs, are for the same board.

Signed-off-by: Diljit Singh <[email protected]>
…controller

After one unexpected or late reply the driver refuses every later command
on a generation 4 controller for good: it has no FIFO flush there, and a
late reply must not answer a new command. One glitch so takes the bus's
devices, the PMU's RTC among them, until the next boot; with the RTC gone
no alarm can be armed and every later sleep is refused.

Recover instead: before the next command, give the bus a command's whole
timeout to finish and read the reply FIFO until it is empty. An old
exchange's words are gone then, and the failure is cleared. A FIFO that
does not empty keeps the failure, as before.

Only on the J714s, the board this is for and the only one it can be run
on today. Generation 4 is apple,t8142-spmi (T8142 and T6050): every other
machine with such a controller, the other T6050 boards included, keeps
the refusal, and the earlier generations keep their FIFO flush.

Signed-off-by: Diljit Singh <[email protected]>
The T6050 PMP firmware (apple,t6050-pmp-v2) has its auxiliary buffer
request on endpoint 7, and some minutes after it has started it sends one
CoreAnalytics event on the same endpoint, with every field zero. The driver
took that word for a changed buffer request, refused it with "RTKit:
refused auxiliary buffer request" and left the firmware without an answer.

Answer that event with an event acknowledgement whose fields are zero too,
in the CoreAnalytics layout that apple_rtkit_coreanalytics_rx() already
uses for the other coprocessors' events. Only that exact message is taken;
every other word on the endpoint is handled as before.

On the J714s only, the board this is for; on another T6050 board the
endpoint behaves as before. No other SoC has this endpoint handler.

Signed-off-by: Diljit Singh <[email protected]>
…pts on nub-spmi0

Only the first deep sleep of a boot stayed asleep: until its alarm, or
until a wake the SMC reports some seconds before it. Every later one went
through the whole entry and commit and was back within about a second,
cleanly, whether or not a refused sleep came between them.

nub-spmi0 latches each interrupt the PMU sends, the alarm's among them, in
a peripheral status word. A latched source that is enabled holds the
controller's interrupt output up, and that output is one of the AP wake
sources the sleep keeps armed. The boot sequence enables the PMU's source,
but no Linux driver takes interrupts on this generation 4 controller, so
nothing ever acknowledged it: once the first sleep's alarm had fired, at
its wake or just after an earlier one, every later commit found the wake
source already up and the SoC came straight back.

macOS acknowledges that source at every wake, before it restores the
controller's run-time mask. Do the same at the wake, and once more just
before the sleep's own SPMI masks, for a source latched while the system
ran (Linux has no handler that would take it then). An event the PMU sends
after that still wakes the sleep, as it should; an alarm already due is
re-armed after the timer and fires again at once.

The word and the bits come from the new apple,spmi-pmu-sources property;
without it nothing changes. The T6050 profile is the J714s's only, so no
other board or SoC is affected. No poll is added: one read and at most one
write, twice per sleep.

Measured on the M5 Pro: six real sleeps in one boot, and a refused one
between the first and the second. Each sleep from the second on was asleep
for 20 to 27 s, where before every sleep after the first was back within
about a second. None of the six lasted until its alarm: each, the first
too, ended 2 to 10 s before it on a wake the SMC reports, which this
change does not address.

Signed-off-by: Diljit Singh <[email protected]>
The host tests build production functions against stubs of the
structures and helpers those functions use. The T6050 (J714s) deep
sleep series adds fields, helpers and calls to several of them, so the
extracted code stopped compiling and these tests failed before their
first case:

- rtkit-retained-tests: the IOP power acknowledgment can fail an ANS
  sleep transaction. The stub gets the transaction's state and the
  test extracts apple_rtkit_ans_fail(). None of its wakes arms the
  transaction; the test now also asserts that none failed it.
- rtkit-oslog-tests, and the apple-dcp oslog-events and syslog-policy
  units: a failed OSLog echo is noted for the firmware 27 sleep, and a
  log buffer the firmware owns is not parsed. Add the field and the
  buffer flag, and model CONFIG_APPLE_SOC_SLEEP as the shared Apple
  configuration builds it.
- apple-dart-fw-tests: releasing a device and freeing a domain now look
  at the J714s display sleep's owner and the firmware 27 provider's
  client list. Add those fields, MAX_DARTS_PER_DEVICE as the fixture's
  arrays hold it, and a client removal that aborts on a provider DART.
- mtp-pm-tests: a firmware-driven suspend sends the interfaces' sleep
  reports. Stub that next to the host state call, which the test never
  reaches either.
- apple-dcp: a Type-C port held unrouted for a sleep (the quiesce,
  transaction and accounting units), a display released for a sleep
  (the lifecycle units), the dwc3 glue's wait for its PHY after a
  sleep, the firmware 27 endpoints in dcp_afkep() and dcp_recv_msg(),
  the panel AV service's close, the AFK receive job count, the RTKit
  RX dispatch now split out of apple_rtkit_rx_work(), and the link
  report of T6050's external processors, which now sits among the
  extracted mode helpers. The fields are added and never set, the
  split RX helpers are extracted, and the link report's EDID note is
  stubbed to fail if it is ever reached.

Every new path stays inert, as on any machine but the J714s: the new
fields are zero, no fixture is a J714s or firmware 27 processor, and
none asks for a link report. No case, assertion or mutation is
removed, and every mutation is still caught.

Signed-off-by: Diljit Singh <[email protected]>
@DjDeveloperr
DjDeveloperr marked this pull request as ready for review November 15, 2026 14:04
@DjDeveloperr
DjDeveloperr merged commit e5974c2 into integration/aurora Nov 15, 2026
8 checks passed
@joshuaswarren

Copy link
Copy Markdown
Contributor

[Joshua's agent] Question on the T6050 sleep data, from a 14-inch M5 Max (K114c) bring-up.

We rebased onto integration/aurora with this PR's sleep driver and copied t6050-j714s-sleep.dtsi to the K114c. The dtb builds. The driver stops at probe with no commit schedule in the DT.

The binding lists about 40 properties the boot loader adds: apple,commit-schedule-us, apple,smc-sleep-policy, apple,seq-*, apple,radio-*, apple,phy-*, apple,wake-order, apple,entry-clk-words, apple,entry-perf-words, apple,ptd-sleep, apple,pmu-*, apple,complex-requests and the clock and CPM boot sets. In aura main only apple,wake-enable, apple,wake-enable-gfx and apple,pinctrl-skip-pins are produced (76f6d953). We found no source for the rest in aura, m1n1 or this tree.

Where do the J714s values come from, and is the generator (or the macOS trace it reads) available? If it takes a macOS sleep trace, we will run it on the M5 Max and send the K114c dtsi back as its own PR, with the Mac it ran on.

@RyanTheTide
RyanTheTide deleted the j714s/t6050-s2r branch November 16, 2026 05:08
m0d16l14n1 added a commit to m0d16l14n1/linux that referenced this pull request Nov 16, 2026
aurora-silicon#1963 drains a generation 4 controller's late reply after a failed
exchange, on the J714s only. The J813 and J815 (MacBook Air, M5) have the
same generation 4 nub-spmi controllers, and their deep sleep writes the
PMU on the same queue, so a stray reply there would refuse every later
command in the sleep. Take the J714s's recovery on both.

Assisted-by: Claude Opus 5.5
Signed-off-by: Nick <[email protected]>
m0d16l14n1 added a commit to m0d16l14n1/linux that referenced this pull request Nov 16, 2026
Add T8142 (J813, J815) to the sleep driver as its own apple_sleep_ops
and match data, on aurora-silicon#1963's coprocessor stops. The steps follow macOS
27.2.1 (26B131) as two traces of its sleep entry under aura's
virtualized SPTM show them: a J815 one (two cores, the whole entry to the
S2R timer) and gig3m's J813 one (ten cores, the memory controller
hooked). Where both hooked a block, they agree write for write.

- lower_io: the RAM clean, ATC0 with T8142's words, the radio's port
  stopped, then ANS's PCIe block in AppleT8142PCIe's order
  (APCIECoreRCGen4: PHY_SW before SYS_ST, the AUS5 pair inside an UP-bit
  window, the PLLs, the AXI enables, the gate loop).
- last_mile: AppleT8142PMGR::quiescePerfState (SoC to 3, DCS to 3
  through 5), the CPM gates around the AP's PMC vote, the complexes off,
  the quiesce read, then the memory side as the J813 trace has it, 4.6
  to 2.7 ms before the S2R timer: each AMCC plane's +0x28000 word cleared
  two bits at a time, the six SoC NI tables zeroed, the eight DCS
  channels' enables stepped down and their lanes strobed, the clock word
  0x380038000 <- 0x30000, and the CLLT "sleep hack" (EARLY_WAKEUP_CFG
  bits 17:16) right before the timer.
- SPTM's per-DART PS write-disable bits (/chosen/dart-ps-wr-dis-entries):
  while one is set, the PMGR drops writes to that DART's power word. The
  four macOS's SPTM clears during its entry (SEP, centauri, PMP, SIO DMA;
  the DCP's stays with the DART driver) are cleared, only where set, and
  reported after the wake. The watchdog's page 2 (+0x2c |= 0x20) before
  WD2, restored at the wake.
- wake: restoreHW, each complex on with its bit-4 wait, pwrgate
  +0x0/+0x60, the words back, ATC0, SEP, the CPM gates, WD2, ANS's block,
  and the radio's link trained again as aura trains it at boot.
- resume and pre_commit: T8132's (WD2 is at the same address).

Generic parts it needs, each a no-op on the other SoCs:
- SPMI generation 4's queue on the sleep's bus (status +0x200, FIFOs
  +0x210/+0x220, notification enable/ack +0x420/+0x620), with bounded
  drains around a PMU write.
- Register blocks a SoC doesn't have: T8142 has no pmc-dcp, clock
  muxes, PTD, cluster DCS or DVFM blocks.
- An untested SoC: deep sleep only with apple_sleep.deep=1, never the
  default; each sleep a dry run that refuses after every check unless
  apple_sleep.untested_commit=1; each step noted in PMU scratch (0x8308)
  for the boot after a reset (apple_sleep_note_sub() for a coprocessor's
  own steps).
- A radio link with no restore (apple,radio-host without trainable port
  data) refuses a real sleep while its host is bound.

The complexes' ACC word 0x40f8, which restoreHW writes, is only written
with apple_sleep.acc_wake=1: every Linux access to it has hung a J815 so
far.

The SoC data test accepts a matched SoC that is untested but gated, and
checks the SoC NI and PS write-disable tables.

Derived from the binaries, the traces and T8132's measurements; no M5
has gone through a full sleep and wake with it yet.

Assisted-by: Claude Opus 5.5
Signed-off-by: Nick <[email protected]>
DjDeveloperr pushed a commit that referenced this pull request Nov 17, 2026
#1963 drains a generation 4 controller's late reply after a failed
exchange, on the J714s only. The J813 and J815 (MacBook Air, M5) have the
same generation 4 nub-spmi controllers, and their deep sleep writes the
PMU on the same queue, so a stray reply there would refuse every later
command in the sleep. Take the J714s's recovery on both.

Assisted-by: Claude Opus 5.5
Signed-off-by: Nick <[email protected]>
DjDeveloperr pushed a commit that referenced this pull request Nov 17, 2026
Add T8142 (J813, J815) to the sleep driver as its own apple_sleep_ops
and match data, on #1963's coprocessor stops. The steps follow macOS
27.2.1 (26B131) as two traces of its sleep entry under aura's
virtualized SPTM show them: a J815 one (two cores, the whole entry to the
S2R timer) and gig3m's J813 one (ten cores, the memory controller
hooked). Where both hooked a block, they agree write for write.

- lower_io: the RAM clean, ATC0 with T8142's words, the radio's port
  stopped, then ANS's PCIe block in AppleT8142PCIe's order
  (APCIECoreRCGen4: PHY_SW before SYS_ST, the AUS5 pair inside an UP-bit
  window, the PLLs, the AXI enables, the gate loop).
- last_mile: AppleT8142PMGR::quiescePerfState (SoC to 3, DCS to 3
  through 5), the CPM gates around the AP's PMC vote, the complexes off,
  the quiesce read, then the memory side as the J813 trace has it, 4.6
  to 2.7 ms before the S2R timer: each AMCC plane's +0x28000 word cleared
  two bits at a time, the six SoC NI tables zeroed, the eight DCS
  channels' enables stepped down and their lanes strobed, the clock word
  0x380038000 <- 0x30000, and the CLLT "sleep hack" (EARLY_WAKEUP_CFG
  bits 17:16) right before the timer.
- SPTM's per-DART PS write-disable bits (/chosen/dart-ps-wr-dis-entries):
  while one is set, the PMGR drops writes to that DART's power word. The
  four macOS's SPTM clears during its entry (SEP, centauri, PMP, SIO DMA;
  the DCP's stays with the DART driver) are cleared, only where set, and
  reported after the wake. The watchdog's page 2 (+0x2c |= 0x20) before
  WD2, restored at the wake.
- wake: restoreHW, each complex on with its bit-4 wait, pwrgate
  +0x0/+0x60, the words back, ATC0, SEP, the CPM gates, WD2, ANS's block,
  and the radio's link trained again as aura trains it at boot.
- resume and pre_commit: T8132's (WD2 is at the same address).

Generic parts it needs, each a no-op on the other SoCs:
- SPMI generation 4's queue on the sleep's bus (status +0x200, FIFOs
  +0x210/+0x220, notification enable/ack +0x420/+0x620), with bounded
  drains around a PMU write.
- Register blocks a SoC doesn't have: T8142 has no pmc-dcp, clock
  muxes, PTD, cluster DCS or DVFM blocks.
- An untested SoC: deep sleep only with apple_sleep.deep=1, never the
  default; each sleep a dry run that refuses after every check unless
  apple_sleep.untested_commit=1; each step noted in PMU scratch (0x8308)
  for the boot after a reset (apple_sleep_note_sub() for a coprocessor's
  own steps).
- A radio link with no restore (apple,radio-host without trainable port
  data) refuses a real sleep while its host is bound.

The complexes' ACC word 0x40f8, which restoreHW writes, is only written
with apple_sleep.acc_wake=1: every Linux access to it has hung a J815 so
far.

The SoC data test accepts a matched SoC that is untested but gated, and
checks the SoC NI and PS write-disable tables.

Derived from the binaries, the traces and T8132's measurements; no M5
has gone through a full sleep and wake with it yet.

Assisted-by: Claude Opus 5.5
Signed-off-by: Nick <[email protected]>
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