Skip to content

soc: apple: sleep: T8122: PCIe ports past port 0, PD controllers on I2C - #4162

Merged
RyanTheTide merged 4 commits into
mainfrom
soc/t8122-sleep-i2c-pd-pcie-ports
Dec 3, 2026
Merged

RyanTheTide merged 4 commits into
mainfrom
soc/t8122-sleep-i2c-pd-pcie-ports

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

What: Let the T8122 (M3) deep sleep path run on the boards that are not MacBook Airs: USB-C port controllers on I2C (no second SPMI bus) and PCIe ports past port 0. A board that enables a PCIe port whose registers the sleep node does not name has deep sleep refused at .begin, with s2idle unchanged. Nothing changes on the J613 and J615. First of two: the J504/J433/J434 devicetree follows on top.

Tested: J615 (T8122, 27.2 stub, default command line) at bd8d92d: PASS, 3 committed deep sleeps and 1 s2idle, panel, GPU, Wi-Fi and audio back after each wake, 0 GPU faults (row). Later commits change only code that returns before any register access on a board with port 0 alone, so that row still covers the J613/J615 path. At 7f75705: arm64 LLVM=1 W=1 build of sleep.o, pcie-apple.o and apple-dart.o clean (clang 23); t8122-apcie-wake-tests.py (PHY, port-ready and shared root-complex timeouts, and a port the entry left alone) and pciec-policy-tests.py pass; full run-host-tests.py 1032/1040, with the other 8 failing the same way at base (tools missing on the build box); checkpatch --strict 0/0/0 on the new commits. At bd8d92d: dt_binding_check of apple,t8140-sleep.yaml clean. The PCIe down, wake and port-0 functions of base 8ec8740 and of bd8d92d were run against a fake register file: with port 0 alone all 240 accesses are the same, in the same order. With port 1 added, only port 1's and lane 1's blocks and the AXI bridge's word differ.

Risk: two-way door · M3 (T8122). J613 and J615 have port 0 alone and spmi-hpm in their node, so they run the same register sequence. J504, J433 and J434 have no enabled sleep node on main.

Not yet: Ports 1 and 2 have not run on any board.

Details
  • spmi-hpm (0x2e4908000) is the SPMI bus of the Airs' port controllers. The J504, J433 and J434 ADTs (27.2) have no nub-spmi-a0; their hpm* are under i2c0. The driver mapped it unconditionally and wrote its notify enable.
  • The T8122 path shut down and brought back port 0 only. On the other boards port 1 is the SD reader (J504) or Ethernet (J433, J434), and port 2 the USB controller (J434). Their DART restores in noirq, with the port's clock off after a wake: the same access that hung the T6030 without a host that brings the ports back.
  • Ports past port 0: before the shutdown, the port's setup words and the PHY lane's words are read and kept; the lane's are the same offsets as lane 0's, 0x8000 apart, the layout T6030's PHY IP block has. After the wake the AXI bridge's word, the lane and the port get them back, then the port's clock and its PHY lane's clocks come up as port 0's. The PCIe host finds the link down and sets the port up again in .resume, as it does port 0 today.
  • The refusal is by the DT: any available child of the apple,t8122-pcie host past port 0 whose apcie-portN/apcie-phyN is missing.

The MacBook Pro 14-inch (J504) and the iMacs (J433, J434) have the same M3
as the MacBook Airs, with their USB-C port controllers on I2C instead of
SPMI, and with PCIe ports past port 0. Let their sleep node leave out the
port controllers' SPMI bus, which those boards do not have, and name the
registers and the PHY lane of each port past port 0.

Signed-off-by: DjDeveloperr <hey@djdev.me>
The T8122 path was written on the MacBook Airs: USB-C port controllers on
SPMI, and Wi-Fi on PCIe port 0 as the only port. The J504 and the iMacs
(J433, J434) have neither: their port controllers are on I2C, so the second
SPMI bus is not there to touch, and the SD reader, Ethernet and USB
controller are on ports 1 and 2.

Take the SPMI bus only where the node names it. Shut the ports past port 0
down as port 0, after their setup and their PHY lane's words are saved, and
bring their clocks and that state back with port 0's. Their DART needs that
first, and then the PCIe host, which trains their link again as it does
port 0's. The saved words are the running ones, so no board's tuning is in
here.

A board that enables a port whose registers the node does not name has deep
sleep refused before anything is suspended, as the wake would find its DART
behind a stopped clock. s2idle is not affected.

The register accesses on a board with port 0 alone are the same as before.

Signed-off-by: DjDeveloperr <hey@djdev.me>
@RyanTheTide

Copy link
Copy Markdown
Contributor

Row: bd8d92d + J615 (MacBook Air 15" M3, T8122, macOS 27.2 / 26B123 stub) + default cmdline + PASS

  • Exact-head kernel as a non-default one-shot entry with the saved entry's options, booted with this head's own t8122-j615.dtb through a one-boot DT trial; production restored after.
  • mem_sleep at boot s2idle [deep], "deep sleep is the default" (J615 apple,sleep-tested from arm64: dts: apple: t8122-j615: deep sleep by default #4076), params deep=N untested_commit=N.
  • 3 committed deep sleeps with the PMU RTC: boot object resumes 0 -> 1 -> 2 -> 3, wake NUB.SPMI0.SW3, 22-24 s each; then 1 s2idle.
  • After each wake: eDP connected/enabled, backlight back, aurora-g16 health failed 0, Wi-Fi up with ping, 3 ALSA cards / 2 sinks. glmark2 after the cycles. 0 Oops/WARN, 0 GPU faults, 0 failed units, suspend_stats fail 0.
  • Same as main and soc: apple: sleep: T8122: deep sleep by default on J613 #3760's row on this Mac, not from this change: one Bluetooth: hci0: command 0x0c01 tx timeout on wake 3, and DCP firmware syslog lines at each wake with the panel back.

@DjDeveloperr
DjDeveloperr marked this pull request as ready for review December 3, 2026 10:21
@DjDeveloperr
DjDeveloperr requested review from a team as code owners December 3, 2026 10:21
@github-actions github-actions Bot added area:platform Area from CODEOWNERS (bot) blast:m3 Macs affected, from Merge risk (bot) ci-failing A check failed at the PR head (bot) door:two-way Revertible or not, from Merge risk (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Dec 3, 2026
@github-actions

github-actions Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Merge readiness at 7f757058: not ready yet

Check Detail
CI at head running running: KUnit dcp-topology apple-dart jpeg mt7932
Review ok approved by satchlj
Requested changes ok none
Hardware row at head ok in the PR body at 7f757058
Conflicts ok none
PR text ok Risk: two-way · M3 (T8122). J613 and J615 have port 0 alone and spmi-hpm in their node, so they run the same register sequence. J504, J433 and J434 have no enabled sleep node on main.

Areas: area:gpu, area:platform

Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels.

@github-actions github-actions Bot removed the ci-failing A check failed at the PR head (bot) label Dec 3, 2026

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed bd8d92d347ed. The deep-sleep admission hook refuses enabled extra ports whose resources are missing, and s2idle bypasses that hook. J615 covers the port-0/SPMI path.

The new extra-port wake loop ignores the return from sleep_apcie_port_clock(). The helper stops short when a PHY clock fails to ack. Please show that a dependent DART stays gated on that failure, or handle it before the DART restore can read a stopped port. The existing shared wake path records the return per port. The positive result needs the matching follow-up DTB on a J504 for port 1 or a J434 for ports 1 and 2, with actual deep sleep and the attached endpoints working after wake.

Check PHY clock acknowledgements before restoring extra-port registers.
If a clock or port fails to return, fence its DART and disconnect that
port before the PCI hierarchy resumes. Keep the port 0 MMIO sequence.

Signed-off-by: DjDeveloperr <hey@djdev.me>
@github-actions github-actions Bot added area:gpu Area from CODEOWNERS (bot) needs-hw-row No hardware row at the PR head (bot) labels Dec 3, 2026

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pushed dd1b845ee44a on top of bd8d92d347ed. The extra-port wake checks PHY clocks before it restores port registers. A timeout leaves the DART gated and the failed PCI subtree disconnected, with its config accesses and IRQ still blocked. The port-0 register sequence is unchanged.

The exact-head t8122-apcie-wake-tests.py passed the PHY, port-ready and shared root-complex timeout cases, including the healthy sibling and config access checks. ARCH=arm64 LLVM=1 make W=1 drivers/soc/apple/sleep.o drivers/pci/controller/pcie-apple.o drivers/iommu/apple-dart.o passed. Checkpatch found zero errors and checks, with the usual new-file MAINTAINERS warning. The J504/J434 row remains due.

The sleep entry skips the PCIe shutdown when a power domain does not come up,
and skips a port whose PHY lane is off. Its setup is then not saved, and the
wake left such a port alone: its DART would restore behind a stopped clock.
Treat it as a port that failed to wake.

Also repair the host tests: the new entry split the m3-sleep-steps one and
stopped run-host-tests.py with a syntax error, and pciec-policy-tests.py
lacked what apple_pcie_prepare() now reads. Test both refusals.

Signed-off-by: DjDeveloperr <hey@djdev.me>

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed dd1b845ee44a fresh and pushed one small fix, 7f7570581725. That makes me a pusher at this head.

Fixed in 7f7570581725:

  • tools/asahi/run-host-tests.py: the new entry was inserted in the middle of the m3-sleep-steps-tests.py expression. That is a syntax error, so the whole host-test runner stopped. Moved it below.
  • sleep-t8122.h, t8122_extra_ports_wake(): a port with registers that the entry did not take down was skipped at wake, with its DART left ungated. That happens when the APCIe raise in t8122_apcie_down() fails, or when the lane read as off. The DART's noirq restore could then read behind a stopped clock. Such a port now takes the failed path (DART gated, port disconnected, next sleep refused).
  • pciec-policy-tests.py did not build against the new apple_pcie_prepare(). It now builds, and it tests that the -EIO refusal applies to the T8122 host only.

The rest reads right to me. The PHY clocks are checked before the port is touched, and on a timeout the DART is gated in the wake, before its noirq resume. The root port and subtree are disconnected in the host's noirq resume. Config access is blocked by slot, IRQs stay masked, and enable_device is refused. A second sleep is refused at .begin and at prepare. A reboot clears all of it. Other SoCs: every hook returns early unless the host is apple,t8122-pcie and the failed mask is non-zero. Port 0 is unchanged: on the J613 and J615 the new paths return before any register access. So the J615 row at bd8d92d347ed still covers port 0 at this head. One note, not blocking: after a failed port, prepare also refuses s2idle, not only deep.

Ran at 7f7570581725 on an x86 build box:

  • arm64 LLVM=1 W=1 build of sleep.o, pcie-apple.o and apple-dart.o: clean (clang 23.1.3).
  • t8122-apcie-wake-tests.py, pciec-policy-tests.py and the sleep, DART and PCIe host tests: all pass.
  • Full runner: 1032/1040. The other 8 fail the same way at base, because that box is missing fdtget and rustup 1.93.1.

linux#4067 (731c7e362763) merges with this head without conflicts. Both add DART helpers, but different ones: apple_dart_is_host_resumed() there, apple_dart_host_wake_failed() here. The merged runner and T8122 test pass. Nothing here needs changing once #4067 lands.

Still owed: a J504 (port 1) or J434 (ports 1 and 2) deep-sleep row on this head with #4166's DT, with the endpoints back after each wake.

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed dd1b845ee44a fresh and pushed one small fix, 7f7570581725. That makes me a pusher at this head.

Fixed in 7f7570581725:

  • tools/asahi/run-host-tests.py: the new entry was inserted in the middle of the m3-sleep-steps-tests.py expression. That is a syntax error, so the whole host-test runner stopped. Moved it below.
  • sleep-t8122.h, t8122_extra_ports_wake(): a port with registers that the entry did not take down was skipped at wake, with its DART left ungated. That happens when the APCIe raise in t8122_apcie_down() fails, or when the lane read as off. The DART's noirq restore could then read behind a stopped clock. Such a port now takes the failed path (DART gated, port disconnected, next sleep refused).
  • pciec-policy-tests.py did not build against the new apple_pcie_prepare(). It now builds, and it tests that the -EIO refusal applies to the T8122 host only.

The rest reads right to me. The PHY clocks are checked before the port is touched, and on a timeout the DART is gated in the wake, before its noirq resume. The root port and subtree are disconnected in the host's noirq resume. Config access is blocked by slot, IRQs stay masked, and enable_device is refused. A second sleep is refused at .begin and at prepare. A reboot clears all of it. Other SoCs: every hook returns early unless the host is apple,t8122-pcie and the failed mask is non-zero. Port 0 is unchanged: on the J613 and J615 the new paths return before any register access. So the J615 row at bd8d92d347ed still covers port 0 at this head. One note, not blocking: after a failed port, prepare also refuses s2idle, not only deep.

Ran at 7f7570581725 on an x86 build box:

  • arm64 LLVM=1 W=1 build of sleep.o, pcie-apple.o and apple-dart.o: clean (clang 23.1.3).
  • t8122-apcie-wake-tests.py, pciec-policy-tests.py and the sleep, DART and PCIe host tests: all pass.
  • Full runner: 1032/1040. The other 8 fail the same way at base, because that box is missing fdtget and rustup 1.93.1.

linux#4067 (731c7e362763) merges with this head without conflicts. Both add DART helpers, but different ones: apple_dart_is_host_resumed() there, apple_dart_host_wake_failed() here. The merged runner and T8122 test pass. Nothing here needs changing once #4067 lands.

Still owed: a J504 (port 1) or J434 (ports 1 and 2) deep-sleep row on this head with #4166's DT, with the endpoints back after each wake.

@github-actions github-actions Bot removed the needs-hw-row No hardware row at the PR head (bot) label Dec 3, 2026
@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

linux#4162 peer row: J504 or J434 deep sleep with ports past port 0

Head to test: linux#4162 7f7570581725 (branch soc/t8122-sleep-i2c-pd-pcie-ports).
DT: linux#4166 (draft, dt/t8122-j504-j433-j434-parity, head a536cabbadaf). It sits on #4162's old head
bd8d92d347ed and is 2 commits behind, so build #4162's head with #4166's 5 DT commits on top (no conflicts:
#4166 touches only the 4 .dts/.dtsi files).

Who: anyone with a J504 (MacBook Pro 14" M3: SD reader on port 1) or a J434 (iMac M3 4-port: Ethernet on
port 1, USB on port 2). J433 (Ethernet on port 1) also counts, for port 1. macOS 27.2 stub.

git fetch origin 7f7570581725 a536cabbadaf
git switch -c row4162 7f7570581725
git cherry-pick bd8d92d347ed..a536cabbadaf     # #4166's 5 DT commits
make ARCH=arm64 LLVM=1 Image modules dtbs      # your usual config with CONFIG_APPLE_SOC_SLEEP=y
# boot it once (non-default entry) with t8122-j504.dtb / t8122-j434.dtb and, on the command line:
#   apple_sleep.deep=1 apple_sleep.untested_commit=1
# J504 only: #2392 (SEP alias, MagSafe, Touch ID) must be in too, or deep sleep is refused.

Before the sleeps, note the endpoints: lspci -tv; J504 ls /sys/block | grep mmc with a card inserted;
J433/J434 ip -br link + ping over Ethernet; J434 lsusb -t with a device on the port-2 USB controller.

cat /sys/power/mem_sleep                       # must offer [deep]
for i in 1 2; do echo deep > /sys/power/mem_sleep; rtcwake -m mem -s 20; sleep 15; done
journalctl -k -b | grep -E 'PCIe port .* failed to wake|refused|DART|Oops|WARN|S2R'
cat /sys/power/suspend_stats/fail              # 0

PASS line: Row: 7f7570581725 + #4166 a536cabbadaf + J504|J434 (27.2) + PASS: 2 committed deep sleeps, port 1 (and 2) endpoints back after each wake (SD reads / Ethernet pings / USB enumerates), 0 "failed to wake", 0 Oops/WARN, 0 DART faults in journalctl -k, suspend_stats fail 0.

FAIL to report: any PCIe port N failed to wake line (the port and its DART stay offline by design; a
second sleep is then refused with -EIO until reboot), a hang (VDM/power button), or an endpoint missing
after wake. Attach journalctl -k -b and lspci -tv from before and after.

@satchlj satchlj left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed head 7f7570581725 (non-pusher code review; no J504/J433/J434 hardware here, CI still running):

  • DT binding (apple,t8140-sleep.yaml): oneOf keeps the 21–22 item SPMI layout unchanged for J613/J615 and cleanly models the I2C-PD layout (21–25 items with optional apcie-port1/phy1/port2/phy2).
  • Port-0 invariance: When t8122_extra_ports() is 0, t8122.apcie_port[1..2].port remain NULL, so t8122_apcie_down(), t8122_raise_apcie(), t8122_port0_wake(), and t8122_extra_ports_wake() preserve the exact port-0 MMIO sequence.
  • Admission & refcounting: t8122_sleep_begin() refuses deep sleep unless every enabled extra port has mapped registers and a bound DART device held via devm_add_action_or_reset(s->dev, apple_sleep_put_device, &pdev->dev), with of_node_put(iommu.np), __free(device_node), and put_device() on the !drvdata error path all leak-free.
  • Failure isolation: apple_dart_host_wake_failed() gates DART commands under dart->lock with no MMIO and no sleeping; t8122_extra_ports_wake() handles root-complex timeout, unsaved ports (failed power-domain raise or off lane on entry), PHY clock timeout before touching port registers, and port-ready timeout; pcie-apple.c blocks config space from the root port down, disconnects the root/subordinate bus in resume_noirq, skips resume/enable/disable/IRQ re-enable, and refuses subsequent sleeps with -EIO.
  • Host tests: t8122-apcie-wake-tests.py and pciec-policy-tests.py exercise the extracted kernel functions directly across all four failure modes.

Two tiny non-blocking notes for when J504/J433/J434 run on hardware:

  1. t8122_phy_ip_words has 0x9280 twice (0xcccccccc before 0x9000, then 0xccc8ccc1 after); t8122_port_save() captures the running post-init value for both slots, so worth watching on the first port-1/2 hardware wake whether lane 1/2 needs the initial 0xcccccccc transition before 0x9000.
  2. In t8122_raise_apcie(), the apcie_axi + 0x600 restore loop writes the same t8122.apcie_axi_ports word twice when both ports 1 and 2 are saved (harmless/idempotent; a break; would suffice).

@github-actions github-actions Bot removed the needs-review No approving review from Core or Omarchy Mac yet (bot) label Dec 3, 2026
@RyanTheTide
RyanTheTide merged commit 06a7548 into main Dec 3, 2026
18 checks passed
@RyanTheTide
RyanTheTide deleted the soc/t8122-sleep-i2c-pd-pcie-ports branch December 3, 2026 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:gpu Area from CODEOWNERS (bot) area:platform Area from CODEOWNERS (bot) blast:m3 Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants