How to disable all USB devices from a host controller


Posted by Diego Assencio on 2013.12.23 under Linux (Peripherals)

To disable all USB devices which are controlled by a specific USB host controller, you first need to find out which controller you want to act on (I am assuming there is a specific USB device which you want to disable). Open a terminal and run:

lsusb -t

This is the output I get on my laptop:

/:  Bus 02.Port 1: Dev 1, Class=root_hub, Driver=ehci_hcd/3p, 480M
    |__ Port 1: Dev 2, If 0, Class=hub, Driver=hub/8p, 480M
        |__ Port 6: Dev 4, If 0, Class=hub, Driver=hub/3p, 12M
            |__ Port 1: Dev 5, If 0, Class=HID, Driver=usbhid, 12M
            |__ Port 2: Dev 6, If 0, Class=HID, Driver=, 12M
            |__ Port 3: Dev 7, If 0, Class='bInterfaceClass 0xe0 not yet handled', Driver=btusb, 12M
            |__ Port 3: Dev 7, If 1, Class='bInterfaceClass 0xe0 not yet handled', Driver=btusb, 12M
            |__ Port 3: Dev 7, If 2, Class=vend., Driver=, 12M
            |__ Port 3: Dev 7, If 3, Class=app., Driver=, 12M
/:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=ehci_hcd/3p, 480M
    |__ Port 1: Dev 2, If 0, Class=hub, Driver=hub/6p, 480M
        |__ Port 4: Dev 3, If 0, Class='bInterfaceClass 0x0e not yet handled', Driver=uvcvideo, 480M
        |__ Port 4: Dev 3, If 1, Class='bInterfaceClass 0x0e not yet handled', Driver=uvcvideo, 480M

As I described in a previous post, each line starting with "Bus" corresponds to a USB host controller. All devices which branch from a given controller are managed by it. To disable them all, run:

echo '<bus>-1' | sudo tee /sys/bus/usb/drivers/usb/unbind

For instance, with bus=2:

echo '2-1' | sudo tee /sys/bus/usb/drivers/usb/unbind

This is the output of lsusb -t which I get after running the command above:

/:  Bus 02.Port 1: Dev 1, Class=root_hub, Driver=ehci_hcd/3p, 480M
/:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=ehci_hcd/3p, 480M
    |__ Port 1: Dev 2, If 0, Class=hub, Driver=hub/6p, 480M
        |__ Port 4: Dev 3, If 0, Class='bInterfaceClass 0x0e not yet handled', Driver=uvcvideo, 480M
        |__ Port 4: Dev 3, If 1, Class='bInterfaceClass 0x0e not yet handled', Driver=uvcvideo, 480M

The second USB host controller ("Bus 02") manages the external USB ports of my laptop. Before running the command above, I could insert a USB drive to one of the ports and see it being detected with dmesg. After running the command, the USB drive was no longer detected after being inserted. Also, my external optical mouse went off. Interestingly, however, my laptop's keyboard (device #5 under bus #2) kept on working, so some devices might still stay functional.

To reenable all devices managed by a USB host controller, run:

echo '<bus>-1' | sudo tee /sys/bus/usb/drivers/usb/bind

The output of lsusb -t should now show the original USB device tree (however, the device numbers will change as they are merely indices given to USB devices as they are detected).

Comments

No comments posted yet.