OpenELEC/OpenELEC.tv — Issue #80: Enable just using USB port for wakeup.
Author: queeup
Created: 2011-12-03 10:47:06+00:00
State: open

On eventlircd package we are using wakeup_enable script but it enabling all usb ports. On some systems that cause wakeup immediately problem. We can usethis script for enable just used USB port for wakeup.

```sh
#!/bin/sh

findUSBPort() {
local FD=7
local tmpFile=$(mktemp)
local eof=0
local line
local usbPort=""
local pciDevice=""
local inBlock="0"
local token=$1

lshal > $tmpFile

# Open files.
eval exec "$FD<$tmpFile"

while [ $eof -eq 0 ]
do
if read line <&$FD; then
if [ -n "$(echo $line | grep -i $token)" ]; then
if [ "$inBlock" = "0" ]; then
inBlock="1"
token="linux.sysfs_path"
else
pciDevice=$(echo $line | awk -F/ '{ print $5}')
eof=1
fi
fi
else
eof=1
fi
done

if [ -n "$pciDevice" ] ; then
usbPort=$(cat /proc/acpi/wakeup | grep $pciDevice | awk '{ print $1}')
fi

echo $usbPort
}

lircDriver=$(dmesg | grep -i 'lirc' | sed -n 's/.*(\(.*\)).*/\1/p')
if [ ! -n "$lircDriver" ] ; then
# No lirc driver loaded
echo "No lirc driver loaded!"
exit 0
fi

usbPort=$(findUSBPort "${lircDriver}")
if [ -z "$usbPort" ]; then
# No USB Remote found
echo "No USB Remote found!"
exit 0
fi

usbDevice=$(dmesg | grep $lircDriver | sed -n 's/.* \(.*\):1.*/\1/p')
if [ -z "$usbDevice" ]; then
# No USB Device found
echo "No USB Device found!"
exit 0
fi

usbStatus=`cat /proc/acpi/wakeup | grep $usbPort | awk {'print $3}'`
if [ "$usbStatus" = "*disabled" ]; then
echo $usbPort > /proc/acpi/wakeup
echo -1 >/sys/module/usbcore/parameters/autosuspend
echo enabled > /sys/bus/usb/devices/"$usbDevice"/power/wakeup
fi

exit 0
```