Waking up Ubuntu with USB keyboard

The new machine – Ubuntu 20.04LTS / Ryzen 3700x / Asus TUF GAMING B450M-PLUS, is working well.
Minor glitch is that it doesn’t want to wake up from keyboard.

# grep . /sys/bus/usb/devices/*/power/wakeup
/sys/bus/usb/devices/1-10/power/wakeup:disabled
/sys/bus/usb/devices/1-7.1/power/wakeup:enabled
/sys/bus/usb/devices/1-7.2.3.1/power/wakeup:enabled
/sys/bus/usb/devices/1-7.2.3.2.3/power/wakeup:enabled
/sys/bus/usb/devices/1-7.2.3.2/power/wakeup:disabled
/sys/bus/usb/devices/1-7.2.3.4.4/power/wakeup:enabled
/sys/bus/usb/devices/1-7.2.3.4/power/wakeup:disabled
/sys/bus/usb/devices/1-7.2.3/power/wakeup:disabled
/sys/bus/usb/devices/1-7.2/power/wakeup:disabled
/sys/bus/usb/devices/1-7/power/wakeup:disabled
/sys/bus/usb/devices/1-9/power/wakeup:disabled
/sys/bus/usb/devices/3-1/power/wakeup:enabled
/sys/bus/usb/devices/usb1/power/wakeup:disabled
/sys/bus/usb/devices/usb2/power/wakeup:disabled
/sys/bus/usb/devices/usb3/power/wakeup:disabled
/sys/bus/usb/devices/usb4/power/wakeup:disabled

I am guessing that /sys/bus/usb/devices/usb[1-4] are the root hub. Ones enabled is prob. keyboard and mouse. (For testing I plugged in 2nd set of keyboard mouse.) It might even wake up from bluetooth. (Again, I am guessing 1.7 is usb/bluetooth). So, only thing not cooperating is the root hubs.
I may be wrong, but I’m pretty sure. That means, I want to enable the root hubs to be able to relay the wakeup. (OTOH, this might be wrong, and the machine might wake up too often.)
Anyhow, it’s time to experiment.

First, something needs to happen to the root hub so the wakeup state becomes enabled. Here is my /usr/local/bin/enable-usb-roothub-wakeup.

#!/bin/sh

for roothub_wakeup in /sys/bus/usb/devices/usb*/power/wakeup ; do
  echo 'enabled' > $roothub_wakeup
done

chmod +x /usr/local/bin/enable-usb-roothub-wakeup
to make it executable.

Second, you need to run this thing at start up. You need a systemd’s unit file.
Here is my /etc/systemd/system/usb-wakeup.service

[Unit]
Description=Configure USB wake up for root hub

[Service]
Type=oneshot
ExecStart=/usr/local/bin/enable-usb-roothub-wakeup

[Install]
WantedBy=basic.target

Once you create the file,
systemctl daemon-reload to load the unit file, systemctl enable usb-wakeup so this would run at start up. Also, you could do systemctl start usb-wakeup.

I am hoping this fixes up the usb wakeup. I’ll update once the experiment’s result comes back.

Leave a Reply

Your email address will not be published. Required fields are marked *