How to prevent a USB mouse auto-suspending in Linux when a laptop’s power supply is disconnected
February 26, 2013 7 Comments
I found that my USB mouse (and external USB keyboard) went to sleep when the mains power supply was disconnected from my laptop. This was annoying because I had to click a mouse button and wait a couple of seconds in order to wake up the mouse. You can see from the console output below that several USB devices were being auto-suspended when I unplugged the laptop PSU:
# # PSU is currently connected.
# for d in /sys/bus/usb/devices/[0-9]* ; do if [[ -e $d/product ]] ; then echo -e "`basename $d`\t`cat $d/power/control`\t`cat $d/speed`\t`cat $d/product`" ; fi ; done
1-1.2 on 1.5 USB Laser Mouse
1-1.3 on 12 BCM2046 Bluetooth Device
2-1.2 on 12 Fingerprint Sensor
2-1.3 on 480 USB 2.0 Camera
2-1.6 on 1.5 USB Keyboard
# # Now I will disconnect the PSU...
# # PSU is currently disconnected.
# for d in /sys/bus/usb/devices/[0-9]* ; do if [[ -e $d/product ]] ; then echo -e "`basename $d`\t`cat $d/power/control`\t`cat $d/speed`\t`cat $d/product`" ; fi ; done
1-1.2 auto 1.5 USB Laser Mouse
1-1.3 auto 12 BCM2046 Bluetooth Device
2-1.2 auto 12 Fingerprint Sensor
2-1.3 auto 480 USB 2.0 Camera
2-1.6 auto 1.5 USB Keyboard
#
I found out the Vendor ID (046d) and Product ID (c052) of my Logitech NX50 USB portable/travel mouse by unplugging then reconnecting the USB mouse and using the dmesg
command:
[13628.909728] usb 1-1.2: USB disconnect, device number 5
[13634.454132] usb 1-1.2: new low-speed USB device number 6 using ehci_hcd
[13634.535107] usb 1-1.2: New USB device found, idVendor=046d, idProduct=c052
[13634.535111] usb 1-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[13634.535113] usb 1-1.2: Product: USB Laser Mouse
[13634.535115] usb 1-1.2: Manufacturer: Logitech
[13634.540168] input: Logitech USB Laser Mouse as /devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.2/1-1.2:1.0/input/input17
[13634.540582] hid-generic 0003:046D:C052.0005: input,hidraw0: USB HID v1.10 Mouse [Logitech USB Laser Mouse] on usb-0000:00:1a.0-1.2/input0
First I tried creating a local Udev rule:
# cat /etc/udev/rules.d/91-local.rules
ACTION=="add", SUBSYSTEM=="usb", ATTR{product}=="USB Laser Mouse", ATTR{power/control}="on"
That didn’t stop the mouse from auto-suspending (and neither did “Logitech USB Laser Mouse” instead of “USB Laser Mouse”), so I tried creating a Udev rule specifying the Vendor ID and Product ID of the mouse:
# cat /etc/udev/rules.d/91-local.rules
ACTION=="add", SUBSYSTEM=="usb", ATTRS{idVendor}=="046d", ATTR{idProduct}=="c052", TEST=="power/control", ATTR{power/control}="on"
That didn’t stop the mouse from auto-suspending either.
Then I remembered that laptop-mode-tools is installed on my laptop:
# eix laptop-mode-tools
[I] app-laptop/laptop-mode-tools
Available versions: 1.60-r1 (~)1.62-r1 {(+)acpi apm bluetooth scsi}
Installed versions: 1.62-r1(18:10:15 11/01/13)(acpi bluetooth -apm -scsi)
Homepage: http://www.samwel.tk/laptop_mode/
Description: Linux kernel laptop_mode user-space utilities
So then I tried adding the mouse model to the blacklist in /etc/laptop-mode/conf.d/usb-autosuspend.conf by making AUTOSUSPEND_USBID_BLACKLIST="046d:c052"
as shown below:
# # Configuration file for Laptop Mode Tools module usb-autosuspend. # # For more information, consult the laptop-mode.conf(8) manual page. # ############################################################################### # USB autosuspend settings # ------------------------ # # If you enable this setting, laptop mode tools will automatically enable the # USB autosuspend feature for all devices. # # NOTE: Some USB devices claim they support autosuspend, but implement it in a # broken way. This can mean keyboards losing keypresses, or optical mice turning # their LED completely off. If you have a device that misbehaves, add its USB ID # to the blacklist below and complain to your hardware vendor. ################################################################################ # Enable debug mode for this module # Set to 1 if you want to debug this module DEBUG=0 # Enable USB autosuspend feature? # Set to 0 to disable CONTROL_USB_AUTOSUSPEND="auto" # Set this to use opt-in/whitelist instead of opt-out/blacklist for deciding # which USB devices should be autosuspended. # AUTOSUSPEND_USE_WHITELIST=0 means AUTOSUSPEND_*_BLACKLIST will be used. # AUTOSUSPEND_USE_WHITELIST=1 means AUTOSUSPEND_*_WHITELIST will be used. AUTOSUSPEND_USE_WHITELIST=0 # The list of USB IDs that should not use autosuspend. Use lsusb to find out the # IDs of your USB devices. # Example: AUTOSUSPEND_USBID_BLACKLIST="046d:c025 0123:abcd" AUTOSUSPEND_USBID_BLACKLIST="046d:c052" # The list of USB driver types that should not use autosuspend. The driver # type is given by "DRIVER=..." in a USB device's uevent file. # Example: AUTOSUSPEND_USBID_BLACKLIST="usbhid usb-storage" AUTOSUSPEND_USBTYPE_BLACKLIST="" # The list of USB IDs that should use autosuspend. Use lsusb to find out the # IDs of your USB devices. # Example: AUTOSUSPEND_USBID_WHITELIST="046d:c025 0123:abcd" AUTOSUSPEND_USBID_WHITELIST="" # The list of USB driver types that should use autosuspend. The driver # type is given by "DRIVER=..." in a USB device's uevent file. # Example: AUTOSUSPEND_USBTYPE_WHITELIST="usbhid usb-storage" AUTOSUSPEND_USBTYPE_WHITELIST="" # Trigger auto-suspension of the USB deivce under conditional circumstances BATT_SUSPEND_USB=1 LM_AC_SUSPEND_USB=0 NOLM_AC_SUSPEND_USB=0 # USB Auto-Suspend timeout in seconds # Number of seconds after which the USB devices should suspend AUTOSUSPEND_TIMEOUT=2
And now the mouse no longer suspends when I unplug the PSU:
# # PSU is currently connected.
# for d in /sys/bus/usb/devices/[0-9]* ; do if [[ -e $d/product ]] ; then echo -e "`basename $d`\t`cat $d/power/control`\t`cat $d/speed`\t`cat $d/product`" ; fi ; done
1-1.2 on 1.5 USB Laser Mouse
1-1.3 on 12 BCM2046 Bluetooth Device
2-1.2 on 12 Fingerprint Sensor
2-1.3 on 480 USB 2.0 Camera
2-1.6 on 1.5 USB Keyboard
# # Now I will disconnect the PSU...
# # PSU is currently disconnected.
# for d in /sys/bus/usb/devices/[0-9]* ; do if [[ -e $d/product ]] ; then echo -e "`basename $d`\t`cat $d/power/control`\t`cat $d/speed`\t`cat $d/product`" ; fi ; done
1-1.2 on 1.5 USB Laser Mouse
1-1.3 auto 12 BCM2046 Bluetooth Device
2-1.2 auto 12 Fingerprint Sensor
2-1.3 auto 480 USB 2.0 Camera
2-1.6 auto 1.5 USB Keyboard
# # Now I will reconnect the PSU...
# # PSU is currently connected.
# for d in /sys/bus/usb/devices/[0-9]* ; do if [[ -e $d/product ]] ; then echo -e "`basename $d`\t`cat $d/power/control`\t`cat $d/speed`\t`cat $d/product`" ; fi ; done
1-1.2 on 1.5 USB Laser Mouse
1-1.3 on 12 BCM2046 Bluetooth Device
2-1.2 on 12 Fingerprint Sensor
2-1.3 on 480 USB 2.0 Camera
2-1.6 on 1.5 USB Keyboard
#
So configuring laptop-mode-tools solved the problem with the mouse. Mind you, I will probably simply make CONTROL_USB_AUTOSUSPEND="no"
in /etc/laptop-mode/conf.d/usb-autosuspend.conf
, as I don’t want the internal USB devices in my laptop (Bluetooth adapter, fingerprint sensor and Webcam) to auto-suspend either.
UPDATE October 22, 2014: Version 1.65 and upwards of Laptop Mode Tools functions in a different way to earlier versions, so please see my post Laptop Mode Tools revisited due to a change in its functionality regarding the new way of configuring Laptop Mode Tools to stop USB devices auto-suspending.
You might try just disabling autosuspend. https://www.kernel.org/doc/Documentation/usb/power-management.txt Not sure if it will work for this or not.
Many, many thanks for this. On-and-off over the last year I have read (and applied) various little half-tweaks and unfinished “fixes” (never having time to do more than a quick Google-and-hope), but until had not been able to fully “solve” all the weird behaviour due to laptop-mode. This was the first time I found something which:
[A] explained exactly what the problem is (laptop-mode having a rather surprising default mode of operation)
[B] showed how to concisely list *all* devices which are affected by it without fishing through reams of irrelevant info (the loop in /sys/bus/usb devices)
[C] showed how to *permanently* resolve all of them without just disabling all autosuspend (by blacklisting specific devices from conf, rather than using overrides)
Thanks, you made my day.
You’re welcome. Glad it was of help.
Version 1.65 and upwards of Laptop Mode Tools functions in a different way to earlier versions, so please see my new post ‘Laptop Mode Tools revisited due to a change in its functionality’ on October 22, 2014 regarding the new way of configuring Laptop Mode Tools to stop USB devices auto-suspending.
I do not know if
CONTROL_USB_AUTOSUSPEND=”no”
works to disable autosuspend, but documentation says to set
CONTROL_USB_AUTOSUSPEND=0
(a zero).
Regards,
Josep
Pingback: Laptop Mode Tools revisited due to a change in its functionality | Fitzcarraldo's Blog
Pingback: Wake-on-LAN (WOL) | Webové stránky Jana Faixe