Keyboard/touchpad do not wake after closing laptop lid

My laptop has always had an issue on linux in which after closing the lid and reopening it, the keyboard or touchpad will stop working. The behavior on lid close is currently “sleep.” I’ve seen this answer, but it didn’t work in Ubuntu or Pop!_OS, and I’m not sure how I’d configure the GRUB_CMDLINE_LINUX equivalent on NixOS anyway. I’ve also tried configuring/reinstalling Wayland and X11 (again, while using Ubuntu and Pop!_OS) but I’ve never had any luck.

I’m thinking maybe just resetting the USB controller on wake (if that’s a good idea) or something might do it, but I don’t know where to start.

1 Like

I believe you can set the kernel command line through boot.kernelParams NixOS option. However, I have the same issue (Sony Vaio laptop) and adding atkdb.reset there did not fix it for me either.

I have observed that external mouse still works so I can start the onboard on-screen-keyboard and toggle Num Lock there, which seems to jump start the keyboard. Alternately, I can run numlockx toggle to do the same.

On Wayland, none of the methods works to toggle Num Lock, though. I recently learned about sudo -- bash -c 'evemu-event /dev/input/event0 --type EV_KEY --code KEY_NUMLOCK --value 1 --sync; evemu-event /dev/input/event0 --type EV_KEY --code KEY_NUMLOCK --value 0 --sync', which might do it, but did not test it yet.

Yup, I have a Sony Vaio laptop too. The keyboard stops working 100% of the time, but the touchpad is much less frequent so I can still log in and use the virtual keyboard if something needs to be saved, but I haven’t tried Num Lock. I’ll give that a shot, at least it’s a workaround for now.

I would like to try to add the numlock toggle script as systemd sleep hook when I have some time to debug this.

The USB autosuspend theory sounds interesting too but I am not completely convinced because I do not see the built-in keyboard in lsusb.

Edit: looks like that is handed by ISA:

$ sudo lsinput
 0: 0001:0001 I8042  isa0060/serio0/i AT Translated Set 2 keyb KEY MSC LED     
[...]
18: 0002:0007 I8042  isa0060/serio1/i SynPS/2 Synaptics TouchP KEY ABS

Just found these two answers Ubuntu 17.04 keyboard not responding after suspend - Ask Ubuntu & Ubuntu 17.04 keyboard not responding after suspend - Ask Ubuntu since dmesg | grep i8042, which sound promising since it prints the devices. I will try it on next reboot.

Solved on my machine by adding the line
powerManagement.powerUpCommands = "sudo rmmod atkbd; sudo modprobe atkbd reset=1";
to configuration.nix.
Thanks to mich41 on this Arch Linux forum post for the idea.
cc @jtojnar

sudo or modprobe were not on my PATH but the former was not necessary. I settled on

powerManagement.resumeCommands = "${pkgs.kmod}/bin/rmmod atkbd; ${pkgs.kmod}/bin/modprobe atkbd reset=1";

thanks for bringing this to my attention again.

1 Like