linux kernel usb suspended

原文链接: linux kernel usb suspended

Suspend USB devices (turn the power off)

EC20 USB 1-1


disable external wake-up; do this only once

echo disabled > /sys/bus/usb/devices/usb1/power/wakeup

echo on > /sys/bus/usb/devices/usb1/power/level # turn on
echo suspend > /sys/bus/usb/devices/usb1/power/level # turn off 已经弃用了
WARNING! power/level is deprecated; use power/control instead

(你可能需要将usb1更改为usb n)

Additionally, from Documentation/usb/power-management.txt:


        This file contains one of two words: "on" or "auto".
        You can write those words to the file to change the
        device's setting.

        "on" means that the device should be resumed and
        autosuspend is not allowed.  (Of course, system
        suspends are still allowed.)

        "auto" is the normal state in which the kernel is
        allowed to autosuspend and autoresume the device.

        (In kernels up to 2.6.32, you could also specify
        "suspend", meaning that the device should remain
        suspended and autoresume was not allowed.  This
        setting is no longer supported.)

To enforce suspend immediately when device is unused:

echo -n "0" >$DEV_POWER_PATH"/power/autosuspend_delay_ms"
echo -n "auto" >$DEV_POWER_PATH"/power/control"

Make the device was not used

rmmod drv_name # see result of lsmod

Power on:

echo -n "2000" >$DEV_POWER_PATH"/power/autosuspend_delay_ms"
echo -n "on" >$DEV_POWER_PATH"/power/control"

Make the device was used.

modprobe drv_name

echo "on" > "/sys/bus/usb/devices/2-1.7/power/control"
echo "2000" > "/sys/bus/usb/devices/2-1.7/power/autosuspend_delay_ms"
echo -n "2-1.7" > /sys/bus/usb/drivers/usb/bind


for i in /sys/bus/usb/devices/usb* ; do echo "suspend" > $i/power/level; done


You could use my tool uhubctl - command line utility to control USB power per port for compatible USB hubs.

It works only on hubs that support per-port power switching, but note that many modern motherboards have USB hubs that support this feature.

To compile:

git clone
cd uhubctl
To install system-wide as /usr/sbin/uhubctl:

sudo make install
To list status of all hubs, their locations and ports that can be controlled by uhubctl:

sudo uhubctl
(you can avoid using sudo if you configure udev USB permissions).

To turn off power on port 5 of single compatible hub:

sudo uhubctl -a 0 -p 5
If you have more than one compatible hub connected, use -l to specify hub location to control it:

sudo uhubctl -a 0 -p 5 -l 3-1.2
To toggle power off then on:

sudo uhubctl -a 2 -p 5
Note that USB 3.0 hubs are also supported, and quite a few new USB 3.0 hubs actually work well.

Read more here.

你可以配置Terminus FE 1.1 USB集线器芯片:


echo "1-4.4.4" > /sys/bus/usb/drivers/usb/unbind
重新打开电源 - 你可以重新绑定来使用

echo "1-4.4.4" > /sys/bus/usb/drivers/usb/bind
2.每个端口单独切换电源更麻烦:我可以使用hubpower来控制每个端口 - 但是它有一个缺点:hubpower首先断开usbdevfs,导致所有USB设备从系统中断开,至少在Ubuntu 上是这样的:

usb_ioctl.ioctl_code = USBDEVFS_DISCONNECT;
rc = ioctl(fd, USBDEVFS_IOCTL, &usb_ioctl);


echo "0" > "/sys/bus/usb/devices/usbX/power/autosuspend"
echo "auto" > "/sys/bus/usb/devices/usbX/power/level"

echo "0" > "/sys/bus/usb/devices/usbX/power/autosuspend_delay_ms"
echo "auto" > "/sys/bus/usb/devices/usbX/power/control"