omarchy icon indicating copy to clipboard operation
omarchy copied to clipboard

Add T2 suspend/resume support

Open jjohnson opened this issue 6 months ago • 6 comments

Summary

Adds suspend/resume support for Apple T2 Macs. The apple_bce module must be unloaded before suspend (its PCI PM can't handle D3 entry), but userspace ALSA clients (PipeWire/WirePlumber) keep it pinned. This service unbinds aaudio before suspend, unloads apple_bce and dependent T2 modules, then reloads everything after resume.

Tested on

  • Model: MacBookPro15,4 (MacBook Pro 13", 2019)
  • Kernel: 6.19.13-arch1-Watanare-T2-1-t2 (T2 Arch Linux)
  • Userspace: PipeWire + WirePlumber (no stop/restart needed across suspend)

Test results (extended suspend/resume testing including overnight and multi-night)

Condition Result
Clean suspend/resume (audio, Wi-Fi, Touch Bar, USB, keyboard) Pass
External monitor (HDMI) across suspend Pass
Overnight suspend cycle (8+ hours) Pass
Multi-night suspend cycle (48+ hours) Pass
Bluetooth audio (headset playback and mic) across suspend Pass
Built-in webcam after resume Pass
invalid position / scheduling while atomic kernel errors Gone
appletbdrm *ERROR* Failed to send message on module unload Gone
brcmfmac: brcmf_pcie_pm_enter_D3: Timeout Gone
Playback resume after suspend (Spotify, local audio) Pass
Record after resume (microphone input) Pass
Wi-Fi reconnect after resume Pass
Bluetooth stays connected across suspend (not unloaded) Pass
Screen capture (grim) after resume Pass
Audio recording (arecord) after resume Pass

For testers

The service installs and enables automatically via Omarchy on T2 Macs (detected via PCI ID 106b:180[12]). To test:

# After updating Omarchy, the migration runs automatically on next update,
# or run it local manually:
OMARCHY_PATH=~/Projects/omarchy bash ~/Projects/omarchy/migrations/1780075490.sh

# Check status:
systemctl status omarchy-apple-t2-suspend.service
journalctl -t t2-suspend

# Test a suspend cycle:
systemctl suspend

Kernel module requirement (just for clean audio after reload)

This fix requires the os_timestamp patch for the PLAYBACK stream in apple-bce-drv. Without it, aaudio_pcm_pointer returns a wild position from the T2 dev_timestamp after module re-probe, causing XRUN and "scheduling while atomic" from the DMA IRQ context.

The patch is one line in audio/pcm.c: change dev_timestamp → os_timestamp in the aaudio_handle_stream_timestamp call for the PLAYBACK substream.

The patch is not yet merged upstream. The pull request is open at t2linux/apple-bce-drv. In the meantime, testers can apply the one-line fix and rebuild:

git clone https://github.com/t2linux/apple-bce-drv
cd apple-bce-drv
sed -i 's/substream, dev_timestamp)/substream, os_timestamp)/' audio/pcm.c
make -C /lib/modules/$(uname -r)/build M=$PWD
# Backup original compressed module, then install the patched one
sudo mv /lib/modules/$(uname -r)/kernel/drivers/staging/apple-bce/apple-bce.ko.zst \
       /lib/modules/$(uname -r)/kernel/drivers/staging/apple-bce/apple-bce.ko.zst.bak
sudo cp apple-bce.ko /lib/modules/$(uname -r)/kernel/drivers/staging/apple-bce/
sudo depmod -a

Model compatibility

The module lists in PRE_MODS/POST_MODS cover all T2 peripherals known on the MacBookPro15,4. Other T2 models (MacBookAir, Mac mini, Mac Pro, iMac) may need adjustments if their Wi-Fi chipset or other modules differ. The mod_ld guard skips absent modules silently, so the service is safe to run on any T2 Mac.

Untested on dGPU-equipped T2 Macs (15"/16" MacBook Pro). Models with a discrete GPU may require additional module handling not covered here.

Debugging

If suspend/resume doesn't work on your model, run these and share the output:

# Did the service run?
journalctl -t t2-suspend

# Kernel errors during suspend/resume
dmesg | grep -iE "XRUN|appletbdrm|brcmfmac|apple_bce|invalid position|scheduling while atomic"

# Module state after resume
lsmod | grep -E "apple|brcmfmac"

# T2 module version
modinfo apple_bce | grep -E "version|srcversion"

# Active suspend method
cat /sys/power/mem_sleep

# Model / Kernel identification
cat /sys/class/dmi/id/product_name
cat /sys/class/dmi/id/product_version
uname -r
cat /proc/cmdline

# T2 PCI devices + GPU
lspci -nn | grep -iE "106b|vga|3d|display"

jjohnson avatar May 29 '26 17:05 jjohnson

Awesome. This is very much needed in order to run Omarchy on older Intel MacBooks. Looking forward to trying this out!

liquid1982 avatar Jun 01 '26 15:06 liquid1982

Any suggestion on how to test this particular fix on my macbook?

maulik13 avatar Jun 08 '26 13:06 maulik13

The PR description has step-by-step test instructions under "For testers".

jjohnson avatar Jun 08 '26 21:06 jjohnson

This is awesome and badly needed! Would be great to also get it upstreamed into some of the other distros/build tools for the t2linux wiki. They've been quite responsive the few times I've reached out and opened PRs.

https://wiki.t2linux.org/

I've had good experience with https://github.com/t2linux/T2-Mint in particular

RayBB avatar Jun 10 '26 19:06 RayBB

Tested on MacBookAir8,1 (2018 Retina Air, T2) with kernel 7.0.11-arch1-Watanare-T2-1-t2.

Cloned the add-t2-suspend branch and ran the migration. KERNEL_CMDLINE[default]+=" pcie_ports=compat intel_iommu=on iommu=pt pcie_port_pm=off"

The service runs correctly: aaudio unbound, apple_bce and all T2 modules unloaded in order before sleep, all reloaded cleanly after resume. No Thunderbolt D3hot errors, no audio XRUNs, no brcmfmac timeouts. Wi-Fi, keyboard/trackpad, USB-C data and charging all working after resume.

I've been using it as a daily driver and it works fine across multiple suspend cycles.

TopperH avatar Jun 11 '26 15:06 TopperH

@jjohnson - Thanks for putting this clean solution together to fix the suspend/resume long standing issue for T2 Mac users.

I have tested using the provided testing steps on my MacBookPro16,1. The suspend/resume now resumes rather than previously hanging the system. However the Wi-Fi does not properly load on resume consistently. The Wi-Fi interface (wlan0) only has properly loaded post resume 1% of the time when testing the fix.

Current result: suspend/resume works, Touch Bar comes back, Wi-Fi does NOT comes back.

Please see the attached t2-debug.txt: t2-debug.txt

joshpavlovich avatar Jun 14 '26 16:06 joshpavlovich

Tested on MacBookPro15,4 (MacBook Pro 13", 2019)

  • Kernel: 7.0.12-arch1-Watanare-T2-1-t2
  • Userspace: PipeWire + WirePlumber
  • Suspend mode: s2idle [deep]

Setup:

  • Cloned the add-t2-suspend branch and ran migration 1780075490.sh
  • Applied the one-line os_timestamp patch to apple-bce-drv (audio/pcm.c:304: dev_timestamp → os_timestamp) and rebuilt the module

Results:

Condition Result
Clean suspend/resume (audio, Wi-Fi, Touch Bar, USB, keyboard) ✅ Pass
Playback resume after suspend (Spotify, local audio) ✅ Pass
Record after resume (microphone input) ✅ Pass
Wi-Fi reconnect after resume ✅ Pass
Touch Bar (tiny-dfr) after resume ✅ Pass
invalid position / scheduling while atomic kernel errors ❌ Gone
brcmfmac: brcmf_pcie_pm_enter_D3: Timeout ❌ Gone
appletbdrm *ERROR* Failed to send message on module unload ❌ Gone

Logs:

Jun 15 19:33:59 mbp2019 t2-suspend[2315]: 0000:02:00.3 Unbound
Jun 15 19:33:59 mbp2019 t2-suspend[2353]: Unloaded appletbdrm
Jun 15 19:33:59 mbp2019 t2-suspend[2371]: Unloaded hid_appletb_kbd
Jun 15 19:33:59 mbp2019 t2-suspend[2389]: Unloaded brcmfmac_wcc
Jun 15 19:34:00 mbp2019 t2-suspend[2396]: Unloaded apple_bce
Jun 15 19:34:00 mbp2019 t2-suspend[2398]: Ready to suspend
Jun 15 19:35:52 mbp2019 t2-suspend[2488]: Loaded apple_bce
Jun 15 19:35:54 mbp2019 t2-suspend[2517]: Loaded brcmfmac
Jun 15 19:35:54 mbp2019 t2-suspend[2527]: Loaded brcmfmac_wcc
Jun 15 19:35:55 mbp2019 t2-suspend[2543]: Loaded hid_appletb_kbd
Jun 15 19:35:55 mbp2019 t2-suspend[2552]: Loaded appletbdrm
Jun 15 19:35:55 mbp2019 t2-suspend[2562]: Resume complete

No XRUNs, no brcmfmac D3 timeouts, no appletbdrm errors. Everything working cleanly across multiple suspend/resume cycles. The os_timestamp patch is essential for clean audio after module reload — without it you get XRUNs from wild dev_timestamp after re-probe.

voioo avatar Jun 15 '26 17:06 voioo

@joshpavlovich Thanks for testing! This is the first data point on a 16,1 and confirms the module lifecycle works — suspend/resume and Touch Bar recovering is good progress.

The Wi-Fi D3cold issue (Unable to change power state from D3cold to D0) is specific to this model.

A couple things to try:

  1. Add pcie_port_pm=off to your kernel cmdline — this disables PCIe port power management and should prevent the D3cold entry entirely. This is the simplest fix if it works.
  2. If that doesn't help, try pcie_aspm=off — more aggressive, disables Active State Power Management at the PCIe link level.
  3. Alternative on the recovery side: try forcing the device out of D3cold before the module reload by adding this to the post-resume path in the script: echo "on" > /sys/bus/pci/devices/0000:05:00.0/power/control If the device leaves D3cold, the existing modprobe brcmfmac should succeed.

Also, if you could collect debug info with collect-t2-debug > ~/t2-debug.txt (defined in the PR description) and attach that file above instead of a lengthy debug in PR.

jjohnson avatar Jun 18 '26 02:06 jjohnson

Hello. I have a target macbook that I can devote to testing if someone can give me appropriate instructions.

I'm sure people have noticed that #5129 is also open; here's making it explicit.

hoclun-rigsep avatar Jun 19 '26 13:06 hoclun-rigsep