Skip to content

Instantly share code, notes, and snippets.

@ioggstream
Created November 7, 2017 13:08
Show Gist options
  • Save ioggstream/8f380d398aef989ac455b93b92d42048 to your computer and use it in GitHub Desktop.
Save ioggstream/8f380d398aef989ac455b93b92d42048 to your computer and use it in GitHub Desktop.
Disable broken xhci device before suspend and avoid freeze.
#!/bin/sh
#
# 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}" == "pre" ]; then
# Do the thing you want before suspend here, e.g.:
echo "Disable broken xhci module before suspending at $(date)..." > /tmp/systemd_suspend_test
grep XHC.*enable /proc/acpi/wakeup && echo XHC > /proc/acpi/wakeup
elif [ "${1}" == "post" ]; then
# Do the thing you want after resume here, e.g.:
echo "Enable broken xhci module at wakeup from $(date)" >> /tmp/systemd_suspend_test
grep XHC.*disable /proc/acpi/wakeup && echo XHC > /proc/acpi/wakeup
fi
@ptrcnull
Copy link

Thanks, it fixed suspending on P51s with Manjaro KDE (5.6.16)

@igor47
Copy link

igor47 commented Jul 16, 2020

i think it fixed my problem on a Thinkpad X1 Carbon 6 Gen . tried upgrading ubuntu 19.10 to 20.04 and also installing bios updates to fix it, to no avail.

my symptoms were that suspend seemed to sometimes work fine, sometimes seem to work but fail to resume, and sometimes it looked like it would suspend, but i would end up with a blinking red dot in the thinkpad logo.

@T12z
Copy link

T12z commented Aug 2, 2020

Seems to have fixed similar symptoms on my Thinkpad X390. Thanks for sharing.

@tomerrr
Copy link

tomerrr commented May 10, 2022

thanks for this. had similar problem on Fedora 35 (Gnome) Dell Latitude 5480 laptop

@rep-movsd
Copy link

rep-movsd commented May 15, 2022

Recently started encountering issues with suspend on my Dell Precision 7710
I tried the above script but to no avail

I found this ancient link https://bugs.launchpad.net/ubuntu/+source/pm-utils/+bug/562484/comments/3 which deals with the issue by unloading the module itself.

I modified the above script as follows and now suspend works fine

  # Do the thing you want before suspend here, e.g.:
  echo "Unload xhci_pci module before suspending at $(date)..." > /tmp/systemd_suspend_test
  modprobe -r xhci_pci
elif [ "${1}" == "post" ]; then
  # Do the thing you want after resume here, e.g.:
  echo "Load xhci_pci module at wakeup from $(date)" >> /tmp/systemd_suspend_test
  modprobe xhci_pci
fi

@psychonaut
Copy link

One thing: it should be bash in shebang not sh.

@ptrcnull
Copy link

One thing: it should be bash in shebang not sh.

why would it need to be bash? it's a perfectly valid posix sh script

@psychonaut
Copy link

interesting... with sh I've got:

./xhci: 15: [: pre: unexpected operator
./xhci: 19: [: pre: unexpected operator

It's debian, so sh is dash.

$ ls -la /bin/sh
lrwxrwxrwx 1 root root 4 Jun 21 13:28 /bin/sh -> dash

When I change to bash it works perfectly fine.

@ptrcnull
Copy link

ah, i was wrong; the test utility specification doesn't require == to be supported, only = or -eq

for maximum compatibility, the script could be edited to use = instead

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment