You are not logged in.

#1 2022-01-11 07:09:04

matthew_moppett
Member
Registered: 2022-01-02
Posts: 2

Keyboard and mouse not working after resuming from suspend in Sway.

The problem

I have a Lenovo Ideapad s145 laptop running the Sway window manager. Whenever I suspend to ram and then wake my computer up, the window manager does not receive any input from my keyboard, touchpad, or mouse. The system is not frozen; it reconnects to wifi and then shows the wifi icon, for example. It just won't respond to user inputs except for the magic sysrq commands.

Workarounds

If I disconnect the mouse and plug it back in again, the mouse (but not keyboard or touchpad) starts working again. Using the mouse, I can log out from my Sway session and be returned to the console (tty 1), and at this stage my keyboard starts working again: I can log in at the console, which automatically logs me in to a new Sway session where all my input devices are working perfectly.

In addition, since the problem doesn't seem to affect the console, I can work around the problem by switching to a new tty before I suspend (i.e. using ctrl-alt-f5), logging in at that tty, and typing `systemctl suspend` there. When I resume after doing this, my keyboard works fine, and I can then type `chvt 1` to get back to my Sway session, where both keyboard and mouse work normally.

Update
I can fix the keyboard problem by restarting the `atkbd` driver on wake from suspend, as detailed in my own reply below. That doesn't fix the mouse and touchpad problems, however.

What I've tried so far

After a bit of googling about this issue, I have experimented with adding both `i8042.reset i8042.nomux i8042.nopnp i8042.noloop` and `atkbd.reset=1` to the `GRUB_CMDLINE_LINUX_DEFAULT` line in `/etc/default/grub` and then running `grub-mkconfig -o /boot/grub/grub.cfg` and rebooting, but neither of these options resolved the issue.

System logs

Output of running

 systemctl suspend; sleep 60; journalctl --since "2 minutes ago"

and waking the computer up in the middle of the sleep period: gist.

Output of running

 systemctl suspend; sleep 60; journalctl --since "2 minutes ago"

waking the computer up in the middle of the sleep period, and disconnecting then reconnecting the mouse: gist.

Output of running

 systemctl suspend; sleep 120; journalctl --since "3 minutes ago"

waking the computer up in the middle of the sleep period, and logging in and out of the Sway session as described above: gist.

Output of running

echo start_from_here | sudo tee /dev/kmsg; systemctl suspend; sleep 30; sudo dmesg > dmesg.tmp

and suspending/resuming: gist.

Nothing in these logs seemed to be directly related to the issue to my (admittedly untrained and frankly clueless) eye.

System information

OS: OS: Arch Linux x86_64
Kernel version: 5.15.13-arch1-1
DE: Sway 1:1.6.1-2

Output of `lsmod`: gist
Output of `sudo lspci -v`: gist


Any help would be appreciated.

Last edited by matthew_moppett (2022-01-15 01:39:08)

Offline

#2 2022-01-14 14:49:25

matthew_moppett
Member
Registered: 2022-01-02
Posts: 2

Re: Keyboard and mouse not working after resuming from suspend in Sway.

Update: I now have a partial solution/workaround for this issue. I've set up a systemd service to run the following commands on resuming from suspend:

rmmod atkbd
modprobe atkbd reset=1

This resets my keyboard driver, which seems to fix the problem with my keyboard. Strangely enough, it also seems to fix my mouse problem about 30% of the time (and for the other 70%, I just have to pull out the USB plug and reinsert it to get my mouse working properly). My touchpad, however, still doesn't work after returning from suspend.

I'm not sure if I should mark this post as solved, since I'd still like to find some way of fixing my mouse and touchpad as well -- ideally something that addresses the root cause of the issue. I think my mouse driver is `is xhci_hcd`, but that driver seems to be pre-compiled into my kernel and I don't know how to reset it. And I have no idea what my touchpad driver is.

Instructions for resetting the atkbd driver on resume from suspend

The following instructions reflect how accomplished this goal (I make no claim that they represent best practice):

Make a shell script that resets the keyboard driver. I put mine at `/etc/usr/local/bin/reset-keyboard.sh`:

#! /bin/sh
# Reset the keyboard driver (to work around a bug that freezes the keyboard after waking from sleep).
rmmod atkbd
modprobe atkbd reset=1

This file is going to be run by systemd as root, so make sure it has appropriate permissions (in particular, it should only be writable by root):

sudo chown root:root /usr/local/bin/reset-keyboard.sh
sudo chmod 744 /usr/local/bin/reset-keyboard.sh

Make a new systemd service file and put it in `/etc/systemd/system/` with the following contents:

[Unit]
Description=Reset the keyboard driver after waking from sleep
After=suspend.target hibernate.target hybrid-sleep.target suspend-then-hibernate.target

[Service]
ExecStart=/usr/local/bin/reset-keyboard.sh

[Install]
WantedBy=suspend.target hibernate.target hybrid-sleep.target suspend-then-hibernate.target

Call it something like `reset-keyboard-after-sleep.service`, and make sure it's only writable by root:

sudo chown root:root /etc/systemd/system/reset-keyboard-after-sleep.service
sudo chmod 644 /etc/systemd/system/reset-keyboard-after-sleep.service

Finally, enable the new systemd service (this ensures that the service will be loaded both now and on subsequent boots):

systemctl enable --now reset-keyboard-after-sleep.service

Last edited by matthew_moppett (2022-01-17 02:14:04)

Offline

Board footer

Powered by FluxBB