Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions install/config/all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
32 changes: 32 additions & 0 deletions install/config/hardware/apple/fix-t2-suspend.sh
Original file line number Diff line number Diff line change
@@ -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
Comment thread
jjohnson marked this conversation as resolved.
Comment thread
jjohnson marked this conversation as resolved.
Comment thread
jjohnson marked this conversation as resolved.
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
86 changes: 86 additions & 0 deletions install/config/hardware/apple/t2-suspend
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#!/bin/bash

# Legacy apple_bce 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)
# * 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

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"; }

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
}

load() {
mod_ld "$1" || {
modprobe "$1" 2>/dev/null && log "Loaded $1" || true
}
}

is_bcm4364() { lspci -nn | grep -q "$BRCMF_D3COLD_PCI_ID"; }

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 &&
log "${d##*/} Unbound" || true
done

systemctl stop tiny-dfr 2>/dev/null || true

for m in "${PRE_MODS[@]}"; do skip "$m" || 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)
require_legacy_driver

load apple_bce; sleep 2

for m in "${POST_MODS[@]}"; do skip "$m" || load "$m"; done

systemctl reset-failed tiny-dfr 2>/dev/null &&
systemctl restart tiny-dfr 2>/dev/null || true

log "Resume complete"
;;
*)
echo "Usage: $0 {pre|post}"; exit 1 ;;
esac
28 changes: 28 additions & 0 deletions migrations/1780075490.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
echo "Install t2-suspend T2 suspend/resume service"

if lspci -nn 2>/dev/null | grep -q "106b:180[12]"; then
Comment thread
jjohnson marked this conversation as resolved.
Comment thread
jjohnson marked this conversation as resolved.
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