linux kernel usb suspended
Suspend USB devices (turn the power off)
EC20 USB 1-1
注意。这个答案中的信息与旧的内核相关(最多2.6.32)。有关新内核的信息,请参阅tlwhitec。
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
:
power/control
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
遍历usb
for i in /sys/bus/usb/devices/usb* ; do echo "suspend" > $i/power/level; done
uhubctl
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 https://github.com/mvp/uhubctl
cd uhubctl
make
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集线器芯片:
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);
根据文档,从内核2.6.32的USB电源管理有几个变化,似乎在2.6.38中。,你需要等待设备闲置,这是由特定的设备驱动程序控制的。你驱动程序需要支持,否则设备永远不会工作。。但是,如果你幸运,你的设备就可以控制了,使用此功能你需要:
echo "0" > "/sys/bus/usb/devices/usbX/power/autosuspend"
echo "auto" > "/sys/bus/usb/devices/usbX/power/level"
对于2.6.38及以上版本的内核:
echo "0" > "/sys/bus/usb/devices/usbX/power/autosuspend_delay_ms"
echo "auto" > "/sys/bus/usb/devices/usbX/power/control"