axe*_*l22 6 usb power-management
我有一个 USB 控制的电源板,它有一个 USB 端口。
如果我的电脑打开并通过 USB 连接到电源板,电源板将为所有插座供电。我想以编程方式禁用连接到电源板的计算机上的 USB 端口的电源。
这不起作用:
$ echo suspend > /sys/bus/usb/devices/usb*/power/level
-bash: echo: write error: Invalid argument
Run Code Online (Sandbox Code Playgroud)
有没有其他方法可以做到这一点?我希望能够从其他地方连接到我的服务器并关闭所有连接到电源插座的设备的电源。
除了读取连接的 USB 端口提供的 +5V 电压外,电源板还能做任何事情吗?(dmesg
当你附加它时你看到了什么吗?lsusb
插入后输出是否改变?)如果没有,内核甚至可能无法识别附加任何东西。如果设备从不枚举自身,您就不能告诉它挂起:它永远不会出现在 /sys/bus/usb/devices 下,并且使用 USB 挂起的是设备,而不是端口。
此外,来自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.)
Run Code Online (Sandbox Code Playgroud)
因此,根据最后一个小声明,如果您的内核比 2.6.32 更新,则听起来您无论如何都无法强制 USB 设备挂起。
抱歉,我不能给你你真正想要的答案,你试图做的听起来很整洁,但我希望它有帮助。
小智 5
# 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
Run Code Online (Sandbox Code Playgroud)