USB Power Saving

From Gentoo Wiki
Jump to:navigation Jump to:search
This article is a stub. Please help out by expanding it - how to get started.

This guide describes the Linux's ability to power off USB devices and to let USB devices request to wake them up again.

It is important to note many optical mice do not support power saving. Once they lose power they cannot detect motion and cannot power back on when motion is invoked. With this being stated, it is possible to use specific driver calls or the sysfs /sys/bus/usb/devices/usb[1-]/power/control file to enable or disable auto-suspend for individual USB peripherals.

Kernel

KERNEL
Device Drivers  --->
    [*] USB support  --->
      <M>   Support for Host-side USB
      [*]     USB runtime power management (autosuspend) and wakeup
Note
Starting with the 3.10 kernel release, dynamic power management support for USB is present when the kernel has been built with CONFIG_PM_RUNTIME enabled. The older CONFIG_USB_SUSPEND option for USB runtime power management auto-suspend and wakeup has been eliminated.
KERNEL
Power management and ACPI options  --->
    [ ] Suspend to RAM and standby
    [ ] Hibernation (aka 'suspend to disk')
    [*] Run-time PM core functionality
    [ ] Power Management Debug Support

Set autosuspend to 1 second:

FILE /etc/modprobe.d/usb.conf
options usbcore autosuspend=1

Enforce for every device:

FILE /etc/udev/rules.d/60-power.rules
SUBSYSTEM!="usb", GOTO="power_usb_rules_end"
ACTION!="add", GOTO="power_usb_rules_end"

KERNEL=="[0-9]*:*", WAIT_FOR_SYSFS="bInterfaceProtocol"
PROGRAM="/bin/sleep 0.1"

ATTR{power/level}=="*", ATTR{power/level}="auto"

LABEL="power_usb_rules_end"

If to autosuspend a specific USB device with newer kernels install sys-apps/usbutils package and use lsusb utility to select specific device.

root #lsusb
Bus 007 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 002: ID 05af:1012 Jing-Mold Enterprise Co., Ltd 
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 002: ID 09da:9090 A4Tech Co., Ltd. XL-730K / XL-750BK / XL-755BK Mice
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub

If PM_RUNTIME=y has been set in the kernel config and want your A4Tech mouse to autosuspend after 45 minutes of idle state then add usbcore.autosuspend=2700 as a value to the GRUB_CMDLINE_LINUX_DEFAULT variable inside the config file found in /etc/default/grub. Regenerate the grub.cfg config via the grub2-mkconfig command and reboot in order for the changes to reflected on the next system reboot.

root #grub2-mkconfig -o /path/to/grub.cfg

Next add the following file into the local.d services:

FILE /etc/local.d/mouse_auto_sleep.start
echo "auto" > /sys/bus/usb/devices/3-3/power/control

As you see here bus number of the mouse is 3 and the device number of 2 is auto-increased by 1 there by kernel into 3 (its usual behavior). Do not forget to make the local.d file executable:

root #chmod +x /etc/local.d/mouse_auto_sleep.start

Read /usr/src/linux/Documentation/usb/power-management.txt for more information on power management in Linux.

See also