如何关闭 USB 端口的电源?

use*_*557 5 usb lubuntu power-management

我正在使用 Lubuntu 16.04。我有从 USB 插座供电的模拟扬声器。我希望它们在我关闭电脑电源并挂起时关闭。我认为这会很容易,但我花了很多时间在谷歌上搜索,但仍然没有解决方案。

我最好的选择似乎是uhubctl,因为它似乎可以在我的硬件上运行(作者警告说并非所有集线器控制器都支持该功能)。我相信这是因为我已经成功关闭了 USB 键盘。

所以现在我需要知道指定什么来关闭扬声器 USB 插座的电源。这肯定需要一些猜测,因为它们不是真正的 USB 设备,不会显示在 lsusb 中。查看后面板和主板手册,我看到插入扬声器的四个插座组被描述为 USB 2.0 端口 7-10。我的鼠标和网络摄像头插入同一组插座。

不带参数运行 uhubctl 给出:

Current status for hub 2-1 [8087:8002, USB 2.00, 8 ports]
Port 1: 0100 power
Port 2: 0100 power
Port 3: 0100 power
Port 4: 0100 power
Port 5: 0100 power
Port 6: 0100 power
Port 7: 0100 power
Port 8: 0100 power
Current status for hub 1-1 [8087:800a, USB 2.00, 6 ports]
Port 1: 0100 power
Port 2: 0100 power
Port 3: 0100 power
Port 4: 0100 power
Port 5: 0100 power
Port 6: 0100 power
Current status for hub 4-5 [174c:3074 ASUS TEK. ASM107x, USB 3.00, 4 ports]
Port 1: 02a0 power 5gbps Rx.Detect
Port 2: 02a0 power 5gbps Rx.Detect
Port 3: 02a0 power 5gbps Rx.Detect
Port 4: 02a0 power 5gbps Rx.Detect
Current status for hub 3-9 [174c:2074 ASUS TEK. ASM107x, USB 2.10, 4 ports]
Port 1: 0100 power
Port 2: 0303 power lowspeed enable connect [047d:2043 NOVATEK Kensington U+P Keyboard]
Port 3: 0100 power
Port 4: 0100 power
Run Code Online (Sandbox Code Playgroud)

那不是很有帮助。我的键盘出现了,但我所有的其他 USB 设备——鼠标、希捷硬盘、网络摄像头——都没有被提及。

我尝试了各种命令:

uhubctl -a off -p 2 -l 3-9     #Turns off keyboard as expected
uhubctl -a off -p 2 -l 4-5     #ALSO turns off keyboard. Why ?

uhubctl -a off -p 12345678 -l 2-1 #Does not turn anything off
uhubctl -a off -p 123456   -l 1-1 #Does not turn anything off
uhubctl -a off -p 134      -l 4-5 #Does not turn anything off.
Run Code Online (Sandbox Code Playgroud)

所以我可以关掉键盘。未列出其他 USB 设备(尽管它们在那里)并且无法关闭。

我不知道集线器名称代表什么,即 2-1、1-1、4-5、3-9。似乎也没有任何方法可以从 lsusb 推断集线器名称。

lsusb 给出:

Bus 002 Device 002: ID 8087:8002 Intel Corp. 
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 008 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 007 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 006 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 005 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 002: ID 8087:800a Intel Corp. 
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 003: ID 174c:3074 ASMedia Technology Inc. ASM1074 SuperSpeed hub
Bus 004 Device 002: ID 0bc2:ab24 Seagate RSS LLC 
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 007: ID 047d:2043 Kensington 
Bus 003 Device 003: ID 174c:2074 ASMedia Technology Inc. ASM1074 High-Speed hub
Bus 003 Device 002: ID 0f62:1001 Acrox Technologies Co., Ltd Targus Mini Trackball Optical Mouse
Bus 003 Device 006: ID 046d:0994 Logitech, Inc. QuickCam Orbit/Sphere AF
Bus 003 Device 004: ID 0b05:180a ASUSTek Computer, Inc. 
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Run Code Online (Sandbox Code Playgroud)

lsusb -t 给出:

/:  Bus 08.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/2p, 10000M
/:  Bus 07.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/2p, 480M
/:  Bus 06.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/2p, 10000M
/:  Bus 05.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/2p, 480M
/:  Bus 04.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/6p, 5000M
    |__ Port 1: Dev 2, If 0, Class=Mass Storage, Driver=uas, 5000M
    |__ Port 5: Dev 3, If 0, Class=Hub, Driver=hub/4p, 5000M
/:  Bus 03.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/15p, 480M
    |__ Port 5: Dev 2, If 0, Class=Human Interface Device, Driver=usbhid, 1.5M
    |__ Port 9: Dev 3, If 0, Class=Hub, Driver=hub/4p, 480M
        |__ Port 2: Dev 7, If 0, Class=Human Interface Device, Driver=usbhid, 1.5M
        |__ Port 2: Dev 7, If 1, Class=Human Interface Device, Driver=usbhid, 1.5M
    |__ Port 10: Dev 4, If 1, Class=Vendor Specific Class, Driver=btusb, 12M
    |__ Port 10: Dev 4, If 2, Class=Vendor Specific Class, Driver=btusb, 12M
    |__ Port 10: Dev 4, If 0, Class=Vendor Specific Class, Driver=btusb, 12M
    |__ Port 10: Dev 4, If 3, Class=Application Specific Interface, Driver=, 12M
    |__ Port 14: Dev 6, If 0, Class=Video, Driver=uvcvideo, 480M
    |__ Port 14: Dev 6, If 1, Class=Video, Driver=uvcvideo, 480M
    |__ Port 14: Dev 6, If 2, Class=Audio, Driver=snd-usb-audio, 480M
    |__ Port 14: Dev 6, If 3, Class=Audio, Driver=snd-usb-audio, 480M
/:  Bus 02.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/2p, 480M
    |__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/8p, 480M
/:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/2p, 480M
    |__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/6p, 480M
Run Code Online (Sandbox Code Playgroud)

我可以看到集线器名称和总线/端口号之间存在某种关系,但我无法提出规则。

我从 lsusb 注意到 USB 2.0 设备似乎使用 Intel 控制器,而 USB 3.0 和 2.1 设备似乎使用 ASUS 控制器。我想知道英特尔芯片是否可能不支持电源控制,所以我尝试了 USB 2.1 插座中的扬声器,当它连接到键盘时我可以关闭。没运气。

有人知道为什么 uhubctrl 会这样吗?

也许 uhubctl 是一个红鲱鱼,不会起作用。我知道还有其他方法可以在 Ubuntu 中切换电源,但它们似乎取决于能够确定代表 USB 插座的目录。这我不知道该怎么做。

mvp*_*mvp 7

uhubctl 作者在这里:

  • uhubctl是使用用于USB设备如Linux内核相同的寻址方法:b-x.y.z,其中b是USB总线号,然后xyz是集线器链的端口号从根USB集线器开始对于给定的总线。此寻址是半稳定的 - 如果您将 USB 设备拔出并重新插入相同的物理端口,它不会改变。
  • 要回答你的第二个问题,我需要引用这个从uhubctl自述:

如果您有兼容的 USB 3.0 集线器连接到 USB3 上游端口,它将被检测为 2 个独立的虚拟集线器:USB2 和 USB3,并且您的 USB 设备将连接到 USB2 或 USB3 虚拟集线器,具体取决于它们的功能和连接速度。要控制此类集线器的电源,需要关闭/打开 USB2 和 USB3 虚拟集线器的电源,以使电源关闭/打开更改生效。uhubctl 将尝试自动执行此操作(除非您使用选项 -e 禁用此行为)。

  • 最后,uhubctl 将只列出声称支持 PPPS(每端口电源切换)的 USB 集线器。但是,有些集线器声称支持但实际上并不工作(交换电路在物理上丢失)。我正在维护已知可以正常工作的所有集线器的列表

如果您碰巧找到与 uhubctl 配合使用但未列出的集线器,请在此处报告。