2

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.

illabout
  • 121
  • 4
  • 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
  • "My keyboard is actually on a KVM switch." That's a different question. Please [edit] and add this essential information to you question. – DavidPostill Feb 14 '18 at 13:55
  • As I said in my previous comment, I've tested that the problem still exists without using the KVM switch. It occurs when using a USB keyboard directly plugged into the computer, as described in the question. Therefore, the KVM switch isn't relevant to this question. – illabout Feb 15 '18 at 02:44
  • I agree that if the problem occured *only* when the keyboard was plugged in through a KVM switch, then it would be relevant information. However, that is not the case. The problem occurs whether or not a KVM switch is being used. – illabout Feb 15 '18 at 02:45
  • Please clarify exactly what action is taking place -- removing keyboard from KVM, removing KVM from computer, removing keyboard from computer, switching KVM without unplugging anything? The symptom may be the same, but the cause and corrective action would be different. And if you're using a KVM, why do you need to unplug anything? – fixer1234 Mar 02 '18 at 04:36
  • @fixer1234 Like I said in a previous comment, the problem occurs whether or not I am using a KVM switch. The fact that I am using a KVM switch is not part of the question. As described in the question, if I just plug/unplug a USB keyboard directly into my laptop, I experience the problem. I will add little bit more explanation to the question about the exact sequence of steps I perform. – illabout Mar 02 '18 at 04:47
  • 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 02 '18 at 05:03
  • @fixer1234 "Unplugging a keyboard from the computer will always cause the problem you describe." If that is true, then you could add it as an answer and I will accept it. (Of course, if you add some sort of reference it would be better for other people who visit this question). – illabout Mar 02 '18 at 05:08
  • @fixer1234 "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)." That is definitely good to know, although it seems like a different question than the one I asked. Maybe I should create a new question asking specifically about suspending while having a KVM connected. (Although I guess you've basically already answered it: "a bad KVM") – illabout Mar 02 '18 at 05:11
  • 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 02 '18 at 05:22

1 Answers1

4

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.

Ale..chenski
  • 12,414
  • 4
  • 35
  • 46
  • 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 02 '18 at 05: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 https://www.intel.com/content/dam/www/public/us/en/documents/technical-specifications/extensible-host-controler-interface-usb-xhci.pdf Somebody needs to enable this wake-up function, you need to consult with Linux people. – Ale..chenski Mar 02 '18 at 05:57