Linux USB: turning the power on and off?

后端 未结 13 1318
遥遥无期
遥遥无期 2020-12-07 10:41

How can I programmatically enable and disable the power to a particular USB port on Linux? Is such a thing even possible? Mac answers appreciated as well!

I was tryi

相关标签:
13条回答
  • 2020-12-07 11:09

    @Kristian Typically you won't find software controlled port power controlled advertised because users shouldn't be conscious of this layer. I don't think there's many use cases for it other than to force misbehaving bus powered devices into a known state, and handle dumb as a post devices that only use USB for power. Perhaps Mark's device falls into the latter category. It's a crude, last resort mechanism.

    As I mentioned, I haven't looked into the implementation details for the unbinding hack and I've only tried it on the EHCI host controller embedded in my motherboard, an "Intel Corporation 6 Series/C200 Series Chipset Family USB Enhanced Host Controller (rev 05)." I would guess that this host controller has the PPC bit of HCSPARAMS set, indicating software control of port power switches, per EHCI spec.

    If you're interfacing with an external hub, "a hub indicates whether or not it supports power switching by the setting of the Logical Power Switching Mode field in wHubCharacteristics," according to the USB 2.0 spec. I don't rememeber if the compliance tests ensure this functionality or not, but if they do, you'd need only find a hub with the USB 2.0 logo. I speculate the hack would send a set port feature request, but it may cycle more than just the target port. Again, per USB 2.0 spec, "a hub with power switches can switch power to all ports as a group/ gang, to each port individually, or have an arbitrary number of gangs of one or more ports." I'm not sure if there's a nice command line tool to get wHubCharacteristics.

    In short, there's not a great generic way to handle this problem, as far as I know. However, it is possible to interrogate an internal or external hub to determine its level of support and then, if supported, use it. It's just a question of how much time you want to spend doing so.

    0 讨论(0)
提交回复
热议问题