• linux控制USB的绑定/解绑


    linux控制USB的绑定/解绑

    http://www.jianshu.com/p/57293f9be558

    今天工作中遇到一个问题, 要用代码实现USB的enable和disable. 谷歌了一番, 最终找到理想答案, 我在这里做一个简短porting. 来源:墙外某博

    • 首先通过lsusb -t来查看USB端口信息:
        /:  Bus 02.Port 1: Dev 1, class="root_hub", Driver=ehci-pci/3p, 480M
        |__ Port 1: Dev 2, If 0, class="hub", Driver=hub/8p, 480M
            |__ Port 6: Dev 78, If 0, class="vend"., Driver=, 480M
            |__ Port 6: Dev 78, If 1, class="vend"., Driver=usbfs, 480M
            |__ Port 6: Dev 78, If 2, class="comm"., Driver=cdc_acm, 480M
            |__ Port 6: Dev 78, If 3, class="data", Driver=cdc_acm, 480M
            |__ Port 6: Dev 78, If 4, class="comm"., Driver=cdc_acm, 480M
            |__ Port 6: Dev 78, If 5, class="data", Driver=cdc_acm, 480M
            |__ Port 6: Dev 78, If 6, class="comm"., Driver=cdc_acm, 480M
            |__ Port 6: Dev 78, If 7, class="data", Driver=cdc_acm, 480M
      /:  Bus 01.Port 1: Dev 1, class="root_hub", Driver=ehci-pci/3p, 480M
        |__ Port 1: Dev 2, If 0, class="hub", Driver=hub/6p, 480M
            |__ Port 1: Dev 6, If 0, class="HID", Driver=usbhid, 1.5M
            |__ Port 1: Dev 6, If 1, class="HID", Driver=usbhid, 1.5M
            |__ Port 3: Dev 9, If 0, class="HID", Driver=usbhid, 1.5M
      (注: 你可以插拔一下要控制的USB, 来确定到底是哪个BUS的哪个port.)
      在这里我要操作BUS 02的port 1下的port 6.
    • 执行以下command去unbind这个USB:
      echo '2-1.6' | sudo tee /sys/bus/usb/drivers/usb/unbind
      其实用不用tee都行, 直接重定向也可以. 需要注意的是, 所要echo的字符串:"$bus_num"-"$port1_num"."$port2_num"
      大概是这么个format.
    • 重新bind的command, 只需要把上面command中的unbind改成bind.
      echo '2-1.6' | sudo tee /sys/bus/usb/drivers/usb/bind

    That's it.

    Knowledge from work

    如果觉得我的文章对您有用,请随意赞赏。您的支持将鼓励我继续创作!



    作者:Edward_f0cus
    链接:http://www.jianshu.com/p/57293f9be558
    來源:简书
    著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
  • 相关阅读:
    第四章学习小结
    第三章学习小结
    第二章学习小结
    DS第五章学习小结
    DS第四章学习小结
    DS第三章小结
    第五章小结
    第四章小结
    第三章小结
    第二章小结
  • 原文地址:https://www.cnblogs.com/LiuYanYGZ/p/7656172.html
Copyright © 2020-2023  润新知