From 8ef4aec00dc8dc07c32bbc173cec72328791874c Mon Sep 17 00:00:00 2001 From: Jeff Johnson Date: Fri, 29 May 2026 12:12:19 -0400 Subject: [PATCH 1/3] Add t2 suspend-resume support * install/config/hardware/apple/t2-suspend: manages apple_bce module for clean suspend/resume by unbinding aaudio and unloading T2 modules before suspend, reloading after resume * install/config/hardware/apple/fix-t2-suspend.sh: install-time setup, copies script to /usr/local/libexec/omarchy/apple/t2-suspend and enables omarchy-apple-t2-suspend.service * migrations/1780075490.sh: install t2-suspend for existing T2 installs --- install/config/all.sh | 1 + .../config/hardware/apple/fix-t2-suspend.sh | 32 +++++++++ install/config/hardware/apple/t2-suspend | 66 +++++++++++++++++++ migrations/1780075490.sh | 28 ++++++++ 4 files changed, 127 insertions(+) create mode 100644 install/config/hardware/apple/fix-t2-suspend.sh create mode 100644 install/config/hardware/apple/t2-suspend create mode 100644 migrations/1780075490.sh diff --git a/install/config/all.sh b/install/config/all.sh index 0c3b839822..d4ce0d7197 100644 --- a/install/config/all.sh +++ b/install/config/all.sh @@ -64,6 +64,7 @@ run_logged $OMARCHY_INSTALL/config/hardware/framework/qmk-hid.sh run_logged $OMARCHY_INSTALL/config/hardware/apple/fix-spi-keyboard.sh run_logged $OMARCHY_INSTALL/config/hardware/apple/fix-suspend-nvme.sh run_logged $OMARCHY_INSTALL/config/hardware/apple/fix-t2.sh +run_logged $OMARCHY_INSTALL/config/hardware/apple/fix-t2-suspend.sh run_logged $OMARCHY_INSTALL/config/hardware/lenovo/fix-yoga-pro7-bass-speakers.sh diff --git a/install/config/hardware/apple/fix-t2-suspend.sh b/install/config/hardware/apple/fix-t2-suspend.sh new file mode 100644 index 0000000000..7bd9daaeea --- /dev/null +++ b/install/config/hardware/apple/fix-t2-suspend.sh @@ -0,0 +1,32 @@ +# Detect T2 MacBook models using PCI IDs +# Vendor: 106b (Apple), Device IDs: 1801 or 1802 (T2 Security Chip) +if lspci -nn 2>/dev/null | grep -q "106b:180[12]"; then + echo "Configuring T2 suspend/resume service..." + + # Install the suspend helper from the Omarchy repo + sudo mkdir -p /usr/local/libexec/omarchy/apple + sudo cp "$OMARCHY_PATH/install/config/hardware/apple/t2-suspend" /usr/local/libexec/omarchy/apple/t2-suspend + sudo chmod +x /usr/local/libexec/omarchy/apple/t2-suspend + + # Write the systemd service + sudo tee /etc/systemd/system/omarchy-apple-t2-suspend.service >/dev/null <<'UNIT_EOF' +[Unit] +Description=Apple T2 suspend/resume +Before=sleep.target +StopWhenUnneeded=yes + +[Service] +Type=oneshot +RemainAfterExit=yes +ExecStart=/usr/local/libexec/omarchy/apple/t2-suspend pre +ExecStop=/usr/local/libexec/omarchy/apple/t2-suspend post +TimeoutStopSec=10 + +[Install] +WantedBy=sleep.target +UNIT_EOF + + sudo systemctl enable omarchy-apple-t2-suspend.service + + echo "T2 suspend/resume service enabled." +fi diff --git a/install/config/hardware/apple/t2-suspend b/install/config/hardware/apple/t2-suspend new file mode 100644 index 0000000000..ef7eba700c --- /dev/null +++ b/install/config/hardware/apple/t2-suspend @@ -0,0 +1,66 @@ +#!/bin/bash + +# Apple T2 suspend/resume helper. Runs as a Before=sleep.target +# systemd service so the T2 coprocessor is fully active during pre. + +# Pre: +# - unbinds aaudio (releases ALSA FDs held by userspace) +# - stops tiny-dfr (prevents spurious wake-ups) +# - unloads T2 modules (reverse dep order; brcmfmac for D3) +# Post: +# - reloads apple_bce, then sleeps to let T2 firmware init +# - reloads T2 modules (forward dep order), restarts tiny-dfr + +PRE_MODS=(appletbdrm hid_appletb_kbd hid_appletb_bl brcmfmac_wcc brcmfmac) +POST_MODS=(brcmfmac brcmfmac_wcc hid_appletb_bl hid_appletb_kbd appletbdrm) + +set -euo pipefail + +LOG_TAG="t2-suspend" + +log() { logger -t "$LOG_TAG" "$1"; } + +mod_ld() { [[ -d /sys/module/$1 ]]; } + +unload() { + mod_ld "$1" && modprobe -r "$1" 2>/dev/null && + log "Unloaded $1" || true +} + +load() { + mod_ld "$1" || { + modprobe "$1" 2>/dev/null && log "Loaded $1" || true + } +} + +case "${1:-}" in + pre) + for d in /sys/bus/pci/drivers/aaudio/0000:*; do + [[ -e $d ]] || continue + echo "${d##*/}" > /sys/bus/pci/drivers/aaudio/unbind 2>/dev/null && + log "${d##*/} Unbound" || true + done + + systemctl stop tiny-dfr 2>/dev/null || true + + for m in "${PRE_MODS[@]}"; do unload "$m"; done + unload apple_bce + + if ! udevadm settle --timeout=5; then + log "Timed out waiting for udev queue to settle" + fi + + log "Ready to suspend" + ;; + post) + load apple_bce; sleep 2 + + for m in "${POST_MODS[@]}"; do load "$m"; done + + systemctl start tiny-dfr 2>/dev/null || true + + log "Resume complete" + ;; + *) + echo "Usage: $0 {pre|post}"; exit 1 ;; +esac diff --git a/migrations/1780075490.sh b/migrations/1780075490.sh new file mode 100644 index 0000000000..c211b955e5 --- /dev/null +++ b/migrations/1780075490.sh @@ -0,0 +1,28 @@ +echo "Install t2-suspend T2 suspend/resume service" + +if lspci -nn 2>/dev/null | grep -q "106b:180[12]"; then + sudo mkdir -p /usr/local/libexec/omarchy/apple + sudo cp "$OMARCHY_PATH/install/config/hardware/apple/t2-suspend" /usr/local/libexec/omarchy/apple/t2-suspend + sudo chmod +x /usr/local/libexec/omarchy/apple/t2-suspend + + sudo tee /etc/systemd/system/omarchy-apple-t2-suspend.service >/dev/null <<'UNIT_EOF' +[Unit] +Description=Apple T2 suspend/resume +Before=sleep.target +StopWhenUnneeded=yes + +[Service] +Type=oneshot +RemainAfterExit=yes +ExecStart=/usr/local/libexec/omarchy/apple/t2-suspend pre +ExecStop=/usr/local/libexec/omarchy/apple/t2-suspend post +TimeoutStopSec=10 + +[Install] +WantedBy=sleep.target +UNIT_EOF + + sudo systemctl daemon-reload + sudo systemctl enable omarchy-apple-t2-suspend.service + echo "T2 suspend/resume service installed and enabled." +fi From 2d89b3334598f85a23b3476ec7038c7e3fa95e52 Mon Sep 17 00:00:00 2001 From: Jeff Johnson Date: Mon, 20 Jul 2026 20:17:11 -0400 Subject: [PATCH 2/3] t2-suspend: brcmfmac, hci_bcm4377, tiny-dfr fix * Skip brcmfmac unload on BCM4364; kernel PCI PM handles D3cold, keep, unload on BCM4377b and unknown chipsets to avoid D3 timeout * Add hci_bcm4377 to module lists for Bluetooth recovery after resume * Fix tiny-dfr start: use reset-failed + restart instead of stop/start, start is a no-op on already-running units --- install/config/hardware/apple/t2-suspend | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/install/config/hardware/apple/t2-suspend b/install/config/hardware/apple/t2-suspend index ef7eba700c..8b3ca673ae 100644 --- a/install/config/hardware/apple/t2-suspend +++ b/install/config/hardware/apple/t2-suspend @@ -6,17 +6,19 @@ # Pre: # - unbinds aaudio (releases ALSA FDs held by userspace) # - stops tiny-dfr (prevents spurious wake-ups) -# - unloads T2 modules (reverse dep order; brcmfmac for D3) +# - unloads T2 modules (reverse dep order) +# * on BCM4377b brcmfmac removed before sleep to avoid D3 timeout +# * on BCM4364 brcmfmac stays bound; kernel PCI PM handles D3cold # Post: # - reloads apple_bce, then sleeps to let T2 firmware init # - reloads T2 modules (forward dep order), restarts tiny-dfr -PRE_MODS=(appletbdrm hid_appletb_kbd hid_appletb_bl brcmfmac_wcc brcmfmac) -POST_MODS=(brcmfmac brcmfmac_wcc hid_appletb_bl hid_appletb_kbd appletbdrm) - set -euo pipefail LOG_TAG="t2-suspend" +BRCMF_D3COLD_PCI_ID=14e4:4464 +PRE_MODS=(appletbdrm hid_appletb_kbd hid_appletb_bl brcmfmac_wcc brcmfmac hci_bcm4377) +POST_MODS=(hci_bcm4377 brcmfmac brcmfmac_wcc hid_appletb_bl hid_appletb_kbd appletbdrm) log() { logger -t "$LOG_TAG" "$1"; } @@ -33,6 +35,10 @@ load() { } } +is_bcm4364() { lspci -nn | grep -q "$BRCMF_D3COLD_PCI_ID"; } + +skip() { is_bcm4364 && [[ $1 == "brcmfmac" || $1 == "brcmfmac_wcc" ]]; } + case "${1:-}" in pre) for d in /sys/bus/pci/drivers/aaudio/0000:*; do @@ -43,7 +49,7 @@ case "${1:-}" in systemctl stop tiny-dfr 2>/dev/null || true - for m in "${PRE_MODS[@]}"; do unload "$m"; done + for m in "${PRE_MODS[@]}"; do skip "$m" || unload "$m"; done unload apple_bce if ! udevadm settle --timeout=5; then @@ -55,9 +61,10 @@ case "${1:-}" in post) load apple_bce; sleep 2 - for m in "${POST_MODS[@]}"; do load "$m"; done + for m in "${POST_MODS[@]}"; do skip "$m" || load "$m"; done - systemctl start tiny-dfr 2>/dev/null || true + systemctl reset-failed tiny-dfr 2>/dev/null && + systemctl restart tiny-dfr 2>/dev/null || true log "Resume complete" ;; From b220d8976667369879c0a8e7605f54e81c19cbfd Mon Sep 17 00:00:00 2001 From: Jeff Johnson Date: Wed, 22 Jul 2026 16:50:13 -0400 Subject: [PATCH 3/3] t2-suspend: skip non-apple_bce kernels --- install/config/hardware/apple/t2-suspend | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/install/config/hardware/apple/t2-suspend b/install/config/hardware/apple/t2-suspend index 8b3ca673ae..0573ff895e 100644 --- a/install/config/hardware/apple/t2-suspend +++ b/install/config/hardware/apple/t2-suspend @@ -1,6 +1,6 @@ #!/bin/bash -# Apple T2 suspend/resume helper. Runs as a Before=sleep.target +# Legacy apple_bce suspend/resume helper. Runs as a Before=sleep.target # systemd service so the T2 coprocessor is fully active during pre. # Pre: @@ -24,6 +24,15 @@ log() { logger -t "$LOG_TAG" "$1"; } mod_ld() { [[ -d /sys/module/$1 ]]; } +require_legacy_driver() { + # apple_bce is intentionally unloaded during pre, so check the kernel's + # module metadata rather than /sys/module for both pre and post. + if ! modinfo apple_bce >/dev/null 2>&1; then + log "Skipping: legacy apple_bce driver is unavailable" + exit 0 + fi +} + unload() { mod_ld "$1" && modprobe -r "$1" 2>/dev/null && log "Unloaded $1" || true @@ -41,6 +50,8 @@ skip() { is_bcm4364 && [[ $1 == "brcmfmac" || $1 == "brcmfmac_wcc" ]]; } case "${1:-}" in pre) + require_legacy_driver + for d in /sys/bus/pci/drivers/aaudio/0000:*; do [[ -e $d ]] || continue echo "${d##*/}" > /sys/bus/pci/drivers/aaudio/unbind 2>/dev/null && @@ -59,6 +70,8 @@ case "${1:-}" in log "Ready to suspend" ;; post) + require_legacy_driver + load apple_bce; sleep 2 for m in "${POST_MODS[@]}"; do skip "$m" || load "$m"; done