Skip to content

Instantly share code, notes, and snippets.

@rfc1459
Created April 16, 2013 10:53
Show Gist options
  • Save rfc1459/5395044 to your computer and use it in GitHub Desktop.
Save rfc1459/5395044 to your computer and use it in GitHub Desktop.
/etc/pm/sleep.d/20_custom-ehci_hcd for Dell XPS 13 Developer Edition
#!/bin/bash
# inspired by http://art.ubuntuforums.org/showpost...0&postcount=19
# ...and http://thecodecentral.com/2011/01/18...ot-working-bug
# tidied by tqzzaa :)
# fixed and reformatted by Matteo Panella (@rfc1459)
VERSION=1.2
DEV_LIST=/tmp/usb-dev-list
DRIVERS_DIR=/sys/bus/pci/drivers
DRIVERS="ehci xhci" # ehci_hcd, xhci_hcd
HEX="[[:xdigit:]]"
MAX_BIND_ATTEMPTS=2
BIND_WAIT=0.1
unbindDev() {
echo -n > $DEV_LIST 2>/dev/null
for driver in $DRIVERS; do
DDIR=$DRIVERS_DIR/${driver}_hcd
for dev in `ls $DDIR 2>/dev/null | egrep "^$HEX+:$HEX+:$HEX"`; do
echo -n "$dev" > $DDIR/unbind
echo "$driver $dev" >> $DEV_LIST
done
echo -n > $DDIR/unbind
done
}
bindDev() {
if [ -s $DEV_LIST ]; then
while read driver dev; do
DDIR=$DRIVERS_DIR/${driver}_hcd
echo -n > $DDIR/bind
while [ $((MAX_BIND_ATTEMPTS)) -gt 0 ]; do
echo -n "$dev" > $DDIR/bind
if [ ! -L "$DDIR/$dev" ]; then
sleep $BIND_WAIT
else
break
fi
MAX_BIND_ATTEMPTS=$((MAX_BIND_ATTEMPTS-1))
done
done < $DEV_LIST
fi
rm $DEV_LIST 2>/dev/null
chvt 1
chvt 7
}
case "$1" in
hibernate)
unbindDev;;
thaw)
bindDev;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment