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.

  • So don't unplug your keyboard. If your system is suspended how do you expect it to recognise that a new device has been plugged in? – DavidPostill Feb 14 '18 at 11:13
  • My keyboard is actually on a KVM switch, so if I want to use another computer, I will need to effectively "unplug" the usb keyboard from this laptop in question. However, I have confirmed that the KVM is not related to this problem, and it persists even if I just unplug/replug a normal USB keyboard directly into the laptop. – illabout Feb 14 '18 at 13:10
  • I'm not sure how the laptop would be able to recognize that a new device is plugged in when it is suspended. That's why I am asking the question. I assumed that it would be possible to wake up the laptop from suspend regardless of when I plugged in the keyboard. If it is not possible to wake up a laptop from a USB keyboard if the keyboard was not plugged in before the laptop was suspended, then, well, I would accept that as an answer. – illabout Feb 14 '18 at 13:14
  • 1
    Whether you're actually using a KVM is important. Unplugging a keyboard from the computer will always cause the problem you describe. If you are working through a KVM and the KVM remains connected, you should not have the problem when you switch the KVM or disconnect the keyboard from the KVM (at least as long as the KVM is switched to the other computer; not sure if the KVM is switched to the the computer in question). If the problem occurs when the KVM is connected, at least when switched to the other computer, it indicates a bad KVM (a different cause). – fixer1234 Mar 2 '18 at 5:03
  • 1
    Ali Chen's answer already covers why the problem occurs if you disconnect directly from the computer. A KVM maintains the USB connection when you switch to the other computer. I'm not sure whether it also provides the USB connection when switched to the current computer (i.e., the computer sees the switch as a device and the switch passes the keyboard signal across), or the KVM simply relies on the connected keyboard for that. In the latter case, disconnecting the keyboard from the KVM would break the USB connection. – fixer1234 Mar 2 '18 at 5:22

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.

|improve this answer|||||
  • Where should I look for a "wake-up on hot plug" setting? Would it be something I would be able to enable in the BIOS? – illabout Mar 2 '18 at 5:14
  • @illabout, I have no idea. At hardware level, I know that xHCI has a very comprehensive interrupt capabilities, "interrupter", and USB Status Register (USBSTS) has bit4 that enables "port change detect", which, in turn, gets information from each port's PORTSC (status and control) register, and each PORTSC has bit25 that enables Wake-On-Connect event. See intel.com/content/dam/www/public/us/en/documents/… Somebody needs to enable this wake-up function, you need to consult with Linux people. – Ale..chenski Mar 2 '18 at 5:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.