usb-hid-wake.sh : Check for power/wakeup property existence

power/wakeup doesn't exist for every sysfs node in
/sys/bus/usb/devices.

Specifically, when we match for usbhid or btusb devices,
the uevent under 1-4:1.0 will have "DRIVER=btusb" but
only the node 1-4 will have power/wakeup. This patch will
echo "enabled" to the power/wakeup of 1-4 port node instead of 1-4:1.0.

This also fixes the problem caused by a race condition between
this script and the btusb driver being registered with the usbcore.
When the script is run on device 1-4 before btusb driver is registered,
"DRIVER=btusb" will be missing from the uevent, and the script will
not have any effect.

When the btusb driver is loaded later, udev will run this script again
for the subnodes 1-4:1.0, but not 1-4. This patch will skip
attempting to write to the nonexistent power/wakeup, and write to the
correct one under 1-4.

Also, clean up some shell scripting style, mainly {} when referring to
variables.

Signed-off-by: Benson Leung <bleung@chromium.org>

BUG=chrome-os-partner:29659,chromium:370581
TEST=powerd_dbus_suspend with bluetooth hid device and usb hid device
Click on both devices, check that wake works.

Change-Id: I5d8dce823bc3ffc6224bc3ab2f285e8f1243e45f
Reviewed-on: https://chromium-review.googlesource.com/204190
Tested-by: Benson Leung <bleung@chromium.org>
Reviewed-by: Benson Leung <bleung@chromium.org>
Commit-Queue: Benson Leung <bleung@chromium.org>
1 file changed