How To: Resume from suspend with wireless USB mouse

Post your tutorials and howtos here.
User avatar
cobb
Posts: 40
Joined: 29 Jan 2014 00:46
Location: Valley Forge PA

How To: Resume from suspend with wireless USB mouse

Postby cobb » 17 Feb 2014 03:49

Problem: I'm a big fan of Logitech's wireless mice but haven't had one yet that would allow me to resume from suspend with it. The issue is that the power for the USB ports to allow it to wake the system has never been enabled on any system (desktop or laptop) automajically.

Solution: Fortunately, once we identify where the mouse is plugged in we can tell the system to enable it to resume by either moving the mouse or clicking a button. I found MY system very odd in that the USB port changed when the system rebooted. We'll deal with that as well. The odd system is Dell desktop so maybe that's part of it's problem. My laptop with Linux Mint doesn't do that so who knows..

First let's identify the mouse with:

Code: Select all

lsusb
and we get:

Code: Select all

bill@optiplex:~/Desktop$ lsusb
Bus 002 Device 002: ID 0bda:8172 Realtek Semiconductor Corp. RTL8191SU 802.11n WLAN Adapter
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 005 Device 002: ID 046d:c52f Logitech, Inc. Unifying Receiver
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 002: ID 413c:2003 Dell Computer Corp. Keyboard
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
We can see our Logitech mouse on Bus 5 Device 2. The identifying information "046d:c52f" is the vendor (046d=Logitech) and deviceId (c52f=M310 model wireless mouse) and we'll need that info in a few minutes. First we need a little more information to make sure we have the device location correct so let's do that with:

Code: Select all

lsusb -t
which gives us:

Code: Select all

bill@optiplex:~/Desktop$ lsusb -t
/:  Bus 05.Port 1: Dev 1, Class=root_hub, Driver=uhci_hcd/2p, 12M
    |__ Port 1: Dev 2, If 0, Class=Human Interface Device, Driver=usbhid, 12M
    |__ Port 1: Dev 2, If 1, Class=Human Interface Device, Driver=usbhid, 12M
/:  Bus 04.Port 1: Dev 1, Class=root_hub, Driver=uhci_hcd/2p, 12M
/:  Bus 03.Port 1: Dev 1, Class=root_hub, Driver=uhci_hcd/2p, 12M
    |__ Port 1: Dev 2, If 0, Class=Human Interface Device, Driver=usbhid, 1.5M
/:  Bus 02.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/8p, 480M
    |__ Port 1: Dev 2, If 0, Class=Vendor Specific Class, Driver=r8712u, 480M
/:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=uhci_hcd/2p, 12M
On Bus 5 Port 1 we see our Device 2. Now let's see if it has the power setting necessary to allow it to resume the system with:

Code: Select all

grep . /sys/bus/usb/devices/*/power/wakeup
which came back with:

Code: Select all

bill@optiplex:~/Desktop$ grep . /sys/bus/usb/devices/*/power/wakeup
/sys/bus/usb/devices/3-1/power/wakeup:enabled
/sys/bus/usb/devices/5-1/power/wakeup:disabled
/sys/bus/usb/devices/usb1/power/wakeup:disabled
/sys/bus/usb/devices/usb2/power/wakeup:disabled
/sys/bus/usb/devices/usb3/power/wakeup:disabled
/sys/bus/usb/devices/usb4/power/wakeup:disabled
/sys/bus/usb/devices/usb5/power/wakeup:disabled
Aha! We can see both Bus 5 Port 1 (where the mouse is located) and USB5 have their wakeup set to disabled. So let's test that we can indeed get the little critter to resume our system from suspend. Drop to a terminal and enter:

Code: Select all

sudo echo enabled > /sys/bus/usb/devices/5-1/power/wakeup
followed by

Code: Select all

sudo echo enabled > /sys/bus/usb/devices/usb5/power/wakeup
Now when we check with:

Code: Select all

grep . /sys/bus/usb/devices/*/power/wakeup
we get:

Code: Select all

bill@optiplex:~/Desktop$ grep . /sys/bus/usb/devices/*/power/wakeup
/sys/bus/usb/devices/3-1/power/wakeup:enabled
/sys/bus/usb/devices/5-1/power/wakeup:enabled
/sys/bus/usb/devices/usb1/power/wakeup:disabled
/sys/bus/usb/devices/usb2/power/wakeup:disabled
/sys/bus/usb/devices/usb3/power/wakeup:disabled
/sys/bus/usb/devices/usb4/power/wakeup:disabled
/sys/bus/usb/devices/usb5/power/wakeup:enabled
and that should do the trick. Suspend your system and it should resume with the mouse. Yay! Now all we have to do is make this permanent as it will not survive a reboot. We'll do this by modifying our rc.local for the USB port and creating a udev rule for the mouse itself.

This is where I ran into a little stumbling block. When I rebooted to verify that it was not going to persist across the reboot I found this:

Code: Select all

bill@optiplex:~$ lsusb
Bus 005 Device 002: ID 0bda:8172 Realtek Semiconductor Corp. RTL8191SU 802.11n WLAN Adapter
Bus 005 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 002: ID 046d:c52f Logitech, Inc. Unifying Receiver
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 002: ID 413c:2003 Dell Computer Corp. Keyboard
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Hmmmm.. now the mouse is is at Bus 4 (USB4) Device 2. Not as simple as it is on my laptop but no worries, we can deal with that. First let's modify our rc.local to enable the USB ports to wake the system. I included a comment in mine so three days from now when I'm old and senile I'll remember what I did. Drop to a command prompt and:

Code: Select all

sudo mousepad /etc/rc.local
and in my case I added

Code: Select all

# my entries to allow power to usb ports to wake with mouse and keyboard
# I had to do all usb ports as the keyboard and mouse seem to change ports across a reboot

echo enabled > /sys/bus/usb/devices/usb1/power/wakeup
echo enabled > /sys/bus/usb/devices/usb2/power/wakeup
echo enabled > /sys/bus/usb/devices/usb3/power/wakeup
echo enabled > /sys/bus/usb/devices/usb4/power/wakeup
echo enabled > /sys/bus/usb/devices/usb5/power/wakeup
to match all my possible USB ports that the system could swap my mouse to. So now my rc.local looks like this:

Code: Select all

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

echo 2000 > /sys/module/block/parameters/events_dfl_poll_msecs

# my entries to allow power to usb ports to wake with mouse and keyboard
# I had to do all usb ports as the keyboard and mouse seem to change ports across a reboot

echo enabled > /sys/bus/usb/devices/usb1/power/wakeup
echo enabled > /sys/bus/usb/devices/usb2/power/wakeup
echo enabled > /sys/bus/usb/devices/usb3/power/wakeup
echo enabled > /sys/bus/usb/devices/usb4/power/wakeup
echo enabled > /sys/bus/usb/devices/usb5/power/wakeup
exit 0
as I added my entries in after the existing entries and before the "exit 0". all that left is to create a udev rule to enable the power wakeup function on the mouse. Doing it this way ensures it identifies the mouse by it's info and will enable the power wakeup no matter where it gets plugged in. We'll create a file called "90-wireless-mouse-wakeup.rules" or you could call it "90-whateveryourlittleheartdesires.rules". Drop to a terminal again and

Code: Select all

sudo mousepad /etc/udev/rules.d/90-wireless-mouse-wakeup.rules
and in the file created enter

Code: Select all

SUBSYSTEM=="usb", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c52f" RUN+="/bin/sh -c 'echo enabled > /sys$env{DEVPATH}/../power/wakeup'"
replacing the "046d" in the idVendor and the "c52f" in the idProduct with the values from your mouse that you got from the

Code: Select all

lsusb
output. Save the file, reboot and you should have a wireless mouse that will resume your sleepy system on demand. If you've hung in there with me this far congratulations and you deserve a beverage of your choice.. :lol:

I hope this works out for you. It has saved me from reaching for my power button on every system I've setup this way so hopefully it'll work for you as well.
Technology slave by coincidence.. Linux user by choice.

kurotsugi
Posts: 2240
Joined: 09 Jan 2014 00:17

Re: How To: Resume from suspend with wireless USB mouse

Postby kurotsugi » 17 Feb 2014 08:46

I'm just wondering. the udev rule should be enough and we didn't need the rc.local script anymore. am I wrong?

User avatar
cobb
Posts: 40
Joined: 29 Jan 2014 00:46
Location: Valley Forge PA

Re: How To: Resume from suspend with wireless USB mouse

Postby cobb » 17 Feb 2014 15:46

kurotsugi wrote:I'm just wondering. the udev rule should be enough and we didn't need the rc.local script anymore. am I wrong?
I'd say that depends and may work on your system with just the udev rule but you'd have to try it. It did not work on my Dell Optiplex with just enabling the port for the mouse. I had to do the usb port as well. I also saw inconsistent information concerning the acpi status of the usb port like this:

Code: Select all

bill@optiplex:~/Desktop$ cat /proc/acpi/wakeup
Device	S-state	  Status   Sysfs node
VBTN	  S4	*enabled 
PCI0	  S5	*disabled  no-bus:pci0000:00
PCI4	  S5	*disabled  pci:0000:00:1e.0
PCI2	  S5	*disabled  pci:0000:00:1c.0
PCI3	  S5	*disabled
PCI1	  S5	*disabled  pci:0000:00:01.0
PCI5	  S5	*disabled
PCI6	  S5	*disabled
USB0	  S3	*enabled   pci:0000:00:1d.0
USB1	  S3	*enabled   pci:0000:00:1d.1
USB2	  S3	*enabled   pci:0000:00:1d.2
USB3	  S3	*enabled   pci:0000:00:1d.3
Notice USB3 seems to indicate that it should allow resume from suspend and "originally" my keyboard was on Bus 3 Device 2. Simply echoing enable to /sys/bus/usb/devices/3-1/power/wakeup did not allow the keyboard to resume the system until I also echoed enable to /sys/bus/usb/devices/usb3/power/wakeup. Then add in the odd behavior of my devices showing up on different usb ports following a reboot (without moving the device) and on my system it was/is indeed necessary to ensure the ports are enabled as well as the devices themselves.

I have also observed different behavior in my experiments across different distros where I first started working on resolving this while running Mint (Ubuntu flavor) that may or may not be due to the different init systems in use. On Mint, my ports would toggle back to disabled by default across a suspend-resume cycle. On a more "native" Debian release like here, on my Optiplex the setting holds across suspend-resume cycles but resets across a reboot. How much of this can be attributed to the Dell's bios or hardware interaction I don't know. I chose to enable the ports (all ports) via the rc.local for that reason.

As with most things OS related it's a case of YMMV for any given hardware/software combination. I chose the "overkill path" as I could replicate consistently on my system that it would work that way.. :lol: You should see the gyrations I had to go through to get an MCE remote to wake up this system.
Technology slave by coincidence.. Linux user by choice.

kurotsugi
Posts: 2240
Joined: 09 Jan 2014 00:17

Re: How To: Resume from suspend with wireless USB mouse

Postby kurotsugi » 17 Feb 2014 16:17

that would be great. I'll try it now.

User avatar
civfreak
Posts: 44
Joined: 18 Feb 2014 00:02
Location: Florida

Re: How To: Resume from suspend with wireless USB mouse

Postby civfreak » 19 Feb 2014 07:11

Thanks Cobb....that did the trick. 8-)
Dell M6700 Laptop (where do I dump the spent fuel rods?)/Windows 8.1/SolydX x64

Image

Sly Dok
Posts: 36
Joined: 27 Jun 2014 22:14
Location: Netherlands

Re: How To: Resume from suspend with wireless USB mouse

Postby Sly Dok » 07 Jul 2014 19:52

Thank you for this helpful tutorial!


Return to “Tutorials”

Who is online

Users browsing this forum: No registered users and 8 guests