Skip to content

Instantly share code, notes, and snippets.

@samcv
Forked from ioggstream/system-sleep-xhci.sh
Last active December 6, 2023 10:32
Show Gist options
  • Save samcv/12422517dbc201d5ffd8eba6c85ee8c4 to your computer and use it in GitHub Desktop.
Save samcv/12422517dbc201d5ffd8eba6c85ee8c4 to your computer and use it in GitHub Desktop.
Disable broken xhci device before suspend and avoid freeze.
#!/bin/bash
#
# This script should prevent the following suspend errors
# which freezes the Dell Inspiron laptop.
#
# Put it in /usr/lib/systemd/system-sleep/xhci.sh
#
# The PCI 00:14.0 device is the usb xhci controller.
#
# kernel: [67445.560610] pci_pm_suspend(): hcd_pci_suspend+0x0/0x30 returns -16
# kernel: [67445.560619] dpm_run_callback(): pci_pm_suspend+0x0/0x150 returns -16
# kernel: [67445.560624] PM: Device 0000:00:14.0 failed to suspend async: error -16
# kernel: [67445.886961] PM: Some devices failed to suspend, or early wake event detected
if [[ "${1}" == "suspend" ]]; then
# Do the thing you want before suspend here, e.g.:
mapfile -t array < <( grep 'XHC.*enable' /proc/acpi/wakeup | cut -d ' ' -f 1 )
for i in "${array[@]}"; do
printf '%s' "$i" > /proc/acpi/wakeup
printf '%s' "$i" >> /tmp/systemd_suspend_test
done
printf "Disable broken xhci module before suspending at %s...\n" "$(date)" >> /tmp/systemd_suspend_test
fi
if [[ "${1}" == "resume" ]]; then
# Do the thing you want after resume here, e.g.:
mapfile -t array < <( grep 'XHC.*disabled' /proc/acpi/wakeup | cut -d ' ' -f 1 )
for i in "${array[@]}"; do
printf '%s' "$i" > /proc/acpi/wakeup
printf '%s' "$i" >> /tmp/systemd_suspend_test
done
printf "Enable broken xhci module at wakeup from %s\n" "$(date)" >> /tmp/systemd_suspend_test
fi
# xhci suspend/resume service
# Samantha McVey 2019 CC0
[Unit]
Description=Disables XHCI suspend before sleep
Before=sleep.target
After=tlp-sleep.service
StopWhenUnneeded=yes
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/home/samantha/bin/system-sleep-xhci.sh suspend
ExecStop=/home/samantha/bin/system-sleep-xhci.sh resume
[Install]
WantedBy=sleep.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment