tags:

views:

6426

answers:

6

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

I was trying for a BOC (don't pretend you weren't try to get one too!) and ended up with one of these, and would like to get some use out of the thing by hooking it up to our server monitor.

update: It doesn't seem this is possible. All of the API's that suspend power basically tell the connected device to turn off, but power is still available on pin 1, so simple devices such as these lights can't be directly controlled programmatically. Perhaps the hub solution mentioned will work.

+2  A: 

Digs through bookmarks

http://blog.andrew.net.au/2009/01/01#usb_power_control

Seems like you need to connect it to a hub and control the hub's power. None of the root hubs I have seen seems to be able to support power control.

Savant Degrees
http://www.gniibe.org/ac-power-by-usb/ac-power-control.html this too
Savant Degrees
+6  A: 

There is a sys entry for this in Linux. From Documentation/usb/power-management.txt:

power/level

This file contains one of three words: "on", "auto",
or "suspend".  You can write those words to the file
to change the device's setting.

"on" means that the device should be resumed and
autosuspend is not allowed.  (Of course, system
suspends are still allowed.)

"auto" is the normal state in which the kernel is
allowed to autosuspend and autoresume the device.

"suspend" means that the device should remain
suspended, and autoresume is not allowed.  (But remote
wakeup may still be allowed, since it is controlled
separately by the power/wakeup attribute.)

Something like: echo on > /sys/bus/usb/devices/usb5/power/level

You may need to play with the autosuspend setting as well. Without telling the kernel to stop trying, it may suspend the port automatically.

Good luck!

mixonic
By my reading of the USB 2.0 specification the power rails out of the USB port are still available. A device connected to the port should limit its power consumption to 500uA for low power and 2.5mA for high power (normally 5 unit load devices). The suggestion for controlling the power through a hub looks more likely to succeed, assuming that the hub allows the power output to be disabled.
Ian
+1 Works for suspending a USB stick.
starblue
A: 

I'd be more inclined to cut the wire and hook it up to a serial port w/ some type of simple relay running ofF one of the 'recieve ready'pin. Then you could just pull the line down (signal 'i'm ready to receive') to the serial port file every time there is some isssue. When it's done, just signal 'i'm full'

My understanding of those things, however, is that they draw a lot of current until they fully charge the capacitor, then release it all at once to flash the bulb. I can't imagine such a sudden discharge is good for the circuitry of the computer. you may need some diode current traps to prevent feedback into the serial port.

Every time my alarm goes off, the computer shuts down!

Ape-inago
A: 

In OS X you can access a USB device from user space and request it to suspend.

You can find a general example in the USB Device Interface Guide. You will need to use the IOUSBDeviceInterface182 (or higher) USBDeviceSuspend method.

Note: Hubs and controller ports may have ganged power supplies, meaning the same switch is shared by multiple ports. if this is the case and your device is in the same group as another active device, it will not be powered down.

Hasturkun
A: 

Hi. I'v tried "sudo echo "suspend" > /sys/bus/usb/devices/usb3/power/level", but only get permissions denied. Tried to enter the file with nano, but get the same. Running Ubuntu 10.10.

Bjorn
A: 

Bjom all you need to do is to run sudo su before trying that command. It will give you required permission. By the way, I didn't understand whether after all it is possible to turn of a usb device in linux distros like ubuntu. I need this to reduce power consumption on my laptop!

Aario