Linux – wake from suspend from usb keyboard stops working after unplugging/replugging keyboard

keyboardlinuxsuspendusbusb-keyboard

Waking from suspend from a USB keyboard stops working on my laptop if I have unplugged and replugged the keyboard while the laptop is in suspend.

I'm on Linux, specifically NixOS (although I imagine this question would be relevant for any distro).

Waking from suspend works fine if I don't unplug the USB keyboard during suspend.

/sys/bus/usb/devices/1-7.1 is the keyboard in question. /sys/bus/usb/devices/1-7.1/power/wakeup is set to enabled, both before and after suspend.

My laptop is a Lemur 8 from System76. There are no BIOS options related to USB wake from suspend.

I am suspending the laptop by running sudo systemctl suspend from a terminal.


edit: I wanted to clarify the exact steps I am performing:

  1. The computer is turned on, awake, and the USB keyboard is plugged in.
  2. I suspend the laptop using sudo systemctl suspend from a terminal.
  3. With the laptop suspended, I unplug the USB keyboard.
  4. With the laptop still suspended, I re-plug the USB keyboard.
  5. I hit a key on the USB keyboard, expecting it to wake the laptop. Nothing happens. The laptop does not wake up.

If I don't do steps 3 and 4 (that is to say, if I don't unplug and re-plug the USB keyboard), I am able to wake the laptop up by hitting a key on the USB keyboard.

Best Answer

When a USB port with attached LS keyboard is in SUSPEND, the bus is in idle LS state, D- is high, no activity. To wake up, the system expects the wake-up signaling sequence - "K-state" should be generated by keyboard (in LS mode the K-state is D+ = high, opposite to FS/HS bus states).

When you unplug the keyboard while in suspend state, the port hardware logic will sense "USB disconnect" (SE0 state), and the port will move into "disabled" state. This will cancel the wake-up mode.

To make the computer to wake up in this situation, you need to enable something like "wake-up on hot plug". I am not sure if this function is available.

Related Question