Linux: disbale USB without disabling power

07
2014-07
  • Ergot

    TLDR

    I want toggle between the following usages of a usb-port via the terminal:

    1. use like a normal usb-port
    2. only supply energy to charge

    Story

    I recently got me something like a magna doodle that can save your drawings to pdf, which can be moved to your computer via usb afterwards. Now the thing is that you can't save anything while it's plugged in.
    Because it's the only way to charge it, it bugs me that I can't find a software solution and laziness I want to keep it plugged in and toggle the connection to the computer only when needed.
    I noticed that it's charging and usable when it is plugged in and the computer is shut down or suspened. So I guess that there's a way to do it.

    Tech info

    • computer: ThinkPad X201
    • Linux Kernel: 3.14.5-1-ARCH
    • "Magna doodle": Boogie Board Sync
  • Answers
  • Luno

    Darth Android's comment is helpful. It's really much easier to get a powered USB hub that does this.

    From a Linux perspective, USB support is usually compiled into the kernel, not loaded as a module. This means that USB support can't be effectively disabled in software, even by manipulating driver modules (as one might do with a network card, etc).

    Depending on how the device firmware and hoe the device appears to the operating system, it may be possible to tweak the driver into sending a USB disconnect command, which would tell the device to stop accepting further USB commands and enter a charge-only mode. This is non-trivial, however, and this approach is best left to skilled programmers comfortable with device drivers.

  • alex

    Try: echo 0 > /sys/bus/usb/devices/${usb}/authorized where ${usb} is the usb port in question; use lsusb -t to get a list. So... 0=disabled, 1=enabled

    I actually use this to cut off power to an external hdd although from what I know this doesn't really cut off power but instead it's the hdd's power management features that turn it off because it no longer considers it connected. Cutting the power to an usb port seems to be imposible; the only thing that appears to do it is to remove the entire usb module (although I haven't actually checked the voltages or anything :) ).


  • Related Question

    linux - How do you check how much power a USB port can deliver?
  • Peltier

    Some laptops have a special USB port that can deliver more power than the other ones. However it is not always easy to identify which one is the good one, nor how much power it can deliver.

    So is there a good way to figure it out? I'm open to any software or hardware solution.


  • Related Answers
  • Tom Wijsman

    Under Linux, you can see this in the tree of lsusb -v

    1. Debian / Ubuntu:

      Use sudo aptitude install usbutils to obtain this tool.

    2. Redhat / Fedora:

      Use sudo yum install usbutils to obtain this tool.

    3. Gentoo:

      Use sudo emerge usbutils to obtain this tool.


    A solution on Windows which doesn't require additional software is the Device Manager itself:

    1. Go to Device Manager ( devmgmt.msc )

    2. Click View > Devices by connection.

    3. Click on your Machine Name, hit the * to expand everything.

    4. Look through the properties of the different USB Hubs, you can see what devices are connected.

    5. On the power tab, you get to see the power a device is consuming and what is being offered.

      enter image description here

      Just like Jeff Atwood explained, the total power available is 500 mA standard.

    6. On the advanced tab, you get to see bandwidth information.

      enter image description here

    So, this should allow you to see which port provides more power and even power consumption.

    If you have bandwidth problems where USB devices work slowly you can also use this to troubleshoot...

  • Jeff Atwood

    One (very cool!) way I found:

    http://www.ultramobilegeek.com/2007/02/measuring-power-on-peripherals-usb.html

    When I write peripheral reviews for ultra-mobile devices, people constantly ask me how significant the power draw is for the device. Previously, I had no answer. Today, I whipped up a rough way to find a solution.

    I call it my USB Drawbox. Attached to a multimeter, it measures the number of milliamperes (mA) any given device pulls over USB. Generally, devices will request up to 500 mA. Above that, standard ports will shut down power to the device. Some devices, notably external hard drives and CD-ROM drives, can pull power from two USB ports simultaneously using a Y connector.

    usb drawbox

    This little DIY hack requires a tiny bit of solder, a tiny bit of Dremel skills, and a whole lot of testing and tweaking. The way I did it - in a metal Penguin Mints tin - required some VERY careful insulation on the screws that went through the banana jacks. Other than that, it was pretty straightforward.

  • slm

    I'm not sure why the accepted answer is so upvoted, hwinfo --usb doesn't provide any power information, neither does lsusb -v -t. See for yourself:

    hwinfo

    (Ubuntu 12.04)

    % lsb_release -a|grep Des
    Description:    Ubuntu 12.04.1 LTS
    
    % hwinfo --usb
    ...
    ...
    14: USB 00.0: 10900 Printer
      [Created at usb.122]
      UDI: /org/freedesktop/Hal/devices/usb_device_4a9_1069_206NL6_if0_printer_noserial
      Unique ID: IO+7.s5u63YPdXG8
      Parent ID: Uc5H.d7FDLX76qXB
      SysFS ID: /devices/pci0000:00/0000:00:12.2/usb1/1-4/1-4.4/1-4.4:1.0
      SysFS BusID: 1-4.4:1.0
      Hardware Class: printer
      Model: "Canon S820"
      Hotplug: USB
      Vendor: usb 0x04a9 "Canon"
      Device: usb 0x1069 "S820"
      SubVendor: "Canon"
      SubDevice: "S820"
      Revision: "1.02"
      Serial ID: "206NL6"
      Driver: "usblp"
      Driver Modules: "usblp"
      Device File: /dev/usb/lp0
      Device Number: char 180:0
      Speed: 12 Mbps
      Module Alias: "usb:v04A9p1069d0102dc00dsc00dp00ic07isc01ip02"
      Driver Info #0:
        Driver Status: usblp is active
        Driver Activation Cmd: "modprobe usblp"
      Config Status: cfg=new, avail=yes, need=no, active=unknown
      Attached to: #11 (Hub)
    

    (Fedora 14)

    % lsb_release -a|grep Desc
    Description:    Fedora release 14 (Laughlin)
    
    % hwinfo --usb
    ...
    ...
    09: USB 00.0: 10e00 Chipcard Reader
      [Created at usb.122]
      Unique ID: Bgjr.EgDcOidyXjF
      Parent ID: FKGF.0j9+vWlqL56
      SysFS ID: /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.5/2-1.5:1.0
      SysFS BusID: 2-1.5:1.0
      Hardware Class: chipcard
      Model: "Lenovo Integrated Smart Card Reader"
      Hotplug: USB
      Vendor: usb 0x17ef "Lenovo"
      Device: usb 0x1003 "Integrated Smart Card Reader"
      Revision: "1.00"
      Driver: "usbfs"
      Driver Modules: "usbcore"
      Speed: 12 Mbps
      Module Alias: "usb:v17EFp1003d0100dc00dsc00dp00ic0Bisc00ip00"
      Config Status: cfg=new, avail=yes, need=no, active=unknown
      Attached to: #6 (Hub)
    

    lsbusb -v -t

    (Ubuntu 12.04)

    % lsusb -v -t
    /:  Bus 07.Port 1: Dev 1, Class=root_hub, Driver=ohci_hcd/2p, 12M
    /:  Bus 06.Port 1: Dev 1, Class=root_hub, Driver=ohci_hcd/3p, 12M
    /:  Bus 05.Port 1: Dev 1, Class=root_hub, Driver=ohci_hcd/3p, 12M
    /:  Bus 04.Port 1: Dev 1, Class=root_hub, Driver=ohci_hcd/3p, 12M
    /:  Bus 03.Port 1: Dev 1, Class=root_hub, Driver=ohci_hcd/3p, 12M
    /:  Bus 02.Port 1: Dev 1, Class=root_hub, Driver=ehci_hcd/6p, 480M
    /:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=ehci_hcd/6p, 480M
        |__ Port 4: Dev 3, If 0, Class=hub, Driver=hub/4p, 480M
            |__ Port 3: Dev 5, If 0, Class=stor., Driver=usb-storage, 480M
            |__ Port 4: Dev 4, If 0, Class=print, Driver=usblp, 12M
    

    (Fedora 14)

    % lsusb -v -t
    Bus#  2
    `-Dev#   1 Vendor 0x1d6b Product 0x0002
      `-Dev#   2 Vendor 0x8087 Product 0x0020
        |-Dev#   3 Vendor 0x046d Product 0xc521
        `-Dev#   4 Vendor 0x17ef Product 0x1003
    Bus#  1
    `-Dev#   1 Vendor 0x1d6b Product 0x0002
      `-Dev#   2 Vendor 0x8087 Product 0x0020
    

    So what does work?

    Just a regular old lsusb -v does provide the power info.

    % lsusb -v|egrep "^Bus|MaxPower"
    Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
        MaxPower                0mA
    Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
        MaxPower                0mA
    Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
        MaxPower                0mA
    Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
        MaxPower                0mA
    Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
        MaxPower                0mA
    Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
        MaxPower                0mA
    Bus 007 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
        MaxPower                0mA
    Bus 001 Device 003: ID 05e3:0608 Genesys Logic, Inc. USB-2.0 4-Port HUB
        MaxPower              100mA
    Bus 003 Device 002: ID 046d:c517 Logitech, Inc. LX710 Cordless Desktop Laser
        MaxPower               98mA
    Bus 001 Device 004: ID 04a9:1069 Canon, Inc. S820
        MaxPower                2mA
    Bus 001 Device 005: ID 05ac:120a Apple, Inc. iPod Nano
        MaxPower              500mA
        MaxPower              500mA
    

    NOTE: It should be noted that this does not seem to show the maximum amount the port can deliver, but the maximum amount the device can draw at the given port it’s connected to.

    Additional comments

    Also I should mention that hwinfo was not a standard package that was available for my particular version of Fedora. I had to download and compile for myself on Fedora!