Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a USB controlled power strip that has a single usb port.

enter image description here

If my computer is turned on and connected via usb to the power strip, the power strip will provide electricity to all the sockets. I want to programatically disable power to the usb port on the computer which is connected to the power strip.

This does not work:

$ echo suspend > /sys/bus/usb/devices/usb*/power/level
-bash: echo: write error: Invalid argument

Is there some other way to do this? I would like to be able to connect to my server from somewhere else and turn off power to all the devices connected to the power sockets.

share|improve this question
add comment

3 Answers

up vote 5 down vote accepted

Does the power strip do anything beyond read the +5V a connected USB port provides? (Do you see anything in dmesg when you attach it? Does the output of lsusb change after you plug it in?) If not, the kernel may not even recognize that anything is attached. You can't tell a device to suspend if it never enumerates itself: it would never show up under /sys/bus/usb/devices, and with USB you suspend devices, not ports.

Additionally, from Documentation/usb/power-management.txt:

 power/control

            This file contains one of two words: "on" or "auto".
            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.

            (In kernels up to 2.6.32, you could also specify
            "suspend", meaning that the device should remain
            suspended and autoresume was not allowed.  This
            setting is no longer supported.)

So according to that last little statement, if you have a kernel newer than 2.6.32 it sounds like you cannot force a USB device to suspend anyway.

Sorry that I can't give you the answer you actually wanted, what you were trying to do sounds pretty neat, but I hope it was helpful.

share|improve this answer
    
Thanks for the answer. The power strip seems to work only by detecting the +5V - it does not seem to have any logic inside. Also, the lsusb does not show the power strip. I was fearing that something like this might be the case. I thought it may be possible to control other electrical devices by shutting down the voltage for the power strip USB. Perhaps there is a controllable usb-switch that can be bought somewhere, hm... –  axel22 May 16 '11 at 20:33
add comment
# To enforce suspend immediately when device is unused:
echo -n "0" >$DEV_POWER_PATH"/power/autosuspend_delay_ms"
echo -n "auto" >$DEV_POWER_PATH"/power/control"
# Make the device was not used
rmmod drv_name # see result of lsmod

# Power on: 
echo -n "2000" >$DEV_POWER_PATH"/power/autosuspend_delay_ms"
echo -n "on" >$DEV_POWER_PATH"/power/control"
# Make the device was used.
modprobe drv_name
share|improve this answer
add comment

how about this:

for i in /sys/bus/usb/devices/usb* ; do echo "suspend" > $i/power/level; done

For debugging purposes, you can add an "echo $i" in there somewhere to let you know which devices are being hit.

share|improve this answer
    
Thanks for the answer! Unfortunately, this just outputs the "Invalid argument" error message for all five usb devices. –  axel22 May 16 '11 at 19:57
    
Hmm. That makes it seem like the usb ports don't accept that command. Which kernel are you running? (uname -r) –  Hack Saw May 16 '11 at 20:10
    
I am running 2.6.38-8-generic-pae. I've read somewhere that the "suspend" feature was disabled for this kernel. –  axel22 May 16 '11 at 20:29
    
I wonder if the ports would turn off if you unloaded the device driver. Kind of drastic, but... –  Hack Saw May 16 '11 at 20:32
    
Is it possible to load/unload the device driver for the usb dynamically, without rebooting? Is there a way to do it on a per-port basis? –  axel22 May 16 '11 at 20:34
show 2 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.