Auto Suspend USB devices in Linux
The USB choreography
I recently purchased two LG monitors. They have a USB hub that I use to connect my mouse and keyboard, and it turns out that the USB devices connected to it are not powered off when I turn off the monitors. Since I’m using RGB keyboard/mice and I don’t want them to be always on, I decided to take a look at what Linux could do.

The monitor USB ports on top, and the USB HUB at the bottom
After experimenting with the monitor options for a while and double-checking all the cables, I didn’t have any luck, so I decided to investigate what I could do from Linux.
Listing USB devices
This is a collection of USB tools for use on Linux and BSD systems to query what type of USB devices are connected to the system. This is to be run on a USB host (i.e. a machine you plug USB devices into), not on a USB device (i.e. a device you plug into a USB host.)
You can get a list of all USB devices connected to your Linux system by using the command lsusb
provided by usb-utils
. The list for me includes the USB hub that my monitor uses and the two devices connected directly to the USB ports on the monitor:
lsusb
[...]
Bus 001 Device 016: ID 0b05:1877 ASUSTek Computer, Inc. ROG Gladius II Origin
Bus 001 Device 034: ID 0b05:18f8 ASUSTek Computer, Inc. ROG STRIX SCOPE
Bus 001 Device 033: ID 043e:9a39 LG Electronics USA, Inc. 27UP850
The output gives us:
- Bus and device number (these are logical).
- Vendor ID and Product ID (in hexadecimal). We will use these later!
- Device name. Usually the manufacturer and product name.
For example, my mouse is numbered 016
, named ASUSTek Computer, Inc. ROG Gladius II Origin
, and has a vendor ID 0b05
and a product ID 1877
.
There are databases online with these IDs, such as the USB ID Repository [2]:
The logical device numbers are assigned dynamically by the kernel. This means that if you unplug one of these USB devices and then plug it back in, the numbers will change.
Auto-suspending with udev
We can create udev rule files to trigger actions on these USB devices during certain events.
On Arch Linux these are under: /etc/udev/rules.d/
Creating the rule
Create a new file 99-usb-autosuspend.rules
with the following contents to autosuspend the USB devices after 300000ms
of inactivity, which in this scenario means how long since you last typed anything with your keyboard or moved your mouse:
# Auto-suspend the mouse 0b05:1877
ACTION=="add", SUBSYSTEM=="usb", ATTR{idVendor}=="0b05", ATTR{idProduct}=="1877", TEST=="power/control", ATTR{power/control}="auto", ATTR{power/autosuspend_delay_ms}="300000"
# Auto-suspend the keyboard 0b05:18f8
ACTION=="add", SUBSYSTEM=="usb", ATTR{idVendor}=="0b05", ATTR{idProduct}=="18f8", TEST=="power/control", ATTR{power/control}="auto", ATTR{power/autosuspend_delay_ms}="300000"
I had to plug in another one to recover from my first attempt doing this, as I forgot to change this value and the keyboard was disconnecting every other second and it was hard to do anything.
Notice the use the same attributes ATTR
{idVendor}
and {idProduct}
we got earlier from the command lsusb
for each device.
These are known as matchers
:
SUBSYSTEMS
- match against the subsystem of the device, or the subsystem of any of the parent devices
ATTRS
- match a sysfs attribute of the device, or a sysfs attribute of any of the parent devices
We are setting power/control
to auto
and power/autosuspend_delay_ms
to 300000 ms
(5 min of inactivity). The USB devices will wake up again if you press a key on the keyboard and click on your mouse (moving the mouse was not enough for me).
auto is the normal state in which the kernel is allowed to autosuspend and autoresume the device.
power/autosuspend_delay_ms This file contains an integer value, which is the number of milliseconds the device should remain idle before the kernel will autosuspend it (the idle-delay time). The default is 2000.
Kernel/USB/Power Management/The User Interface for Dynamic PM [4]
Checking the auto-suspend
You can check if the auto-suspend is actually working using the power/control
and power/autosuspend_delay_ms
files.
$ cat /sys/devices/pci0000:00/0000:00:14.0/usb1/1-13/1-13.2/1-13.2.2/power/control
auto
# cat /sys/devices/pci0000:00/0000:00:14.0/usb1/1-13/1-13.2/1-13.2.2/power/autosuspend_delay_ms
300000
Reloading udev
Once the file is there, reload the rules with udevadm using the --reload
flag:
udevadm control --reload-rules
Remember to run this as root
or use sudo
otherwise you’ll get this error message:
Failed to send reload request: Permission denied
And that’s all, you are done now! The USB devices should auto suspend after the inactivity period.