Controlling a USB power supply (on/off) with Linux Controlling a USB power supply (on/off) with Linux linux linux

Controlling a USB power supply (on/off) with Linux


Note. The information in this answer is relevant for the older kernels (up to 2.6.32). See tlwhitec's answer for the information on the newer kernels.

# disable external wake-up; do this only onceecho disabled > /sys/bus/usb/devices/usb1/power/wakeup echo on > /sys/bus/usb/devices/usb1/power/level       # turn onecho suspend > /sys/bus/usb/devices/usb1/power/level  # turn off

(You may need to change usb1 to usb n)

Source: Documentation/usb/power-management.txt.gz


According to the docs, there were several changes to the USB power management from kernels 2.6.32, which seem to settle in 2.6.38. Now you'll need to wait for the device to become idle, which is governed by the particular device driver. The driver needs to support it, otherwise the device will never reach this state. Unluckily, now the user has no chance to force this. However, if you're lucky and your device can become idle, then to turn this off you need to:

echo "0" > "/sys/bus/usb/devices/usbX/power/autosuspend"echo "auto" > "/sys/bus/usb/devices/usbX/power/level"

or, for kernels around 2.6.38 and above:

echo "0" > "/sys/bus/usb/devices/usbX/power/autosuspend_delay_ms"echo "auto" > "/sys/bus/usb/devices/usbX/power/control"

This literally means, go suspend at the moment the device becomes idle.

So unless your fan is something "intelligent" that can be seen as a device and controlled by a driver, you probably won't have much luck on current kernels.


PowerTOP from Intel allows you to toggle devices such as usb peripherals in real-time. These are called 'tunables'.

sudo apt install powertopsudo powertop
  • Tab over to 'tunables'.
  • Scroll down to your device.
  • Hit enter to toggle power saving mode (Good/Bad)

enter image description here

Note that Bad means the device is always on. Toggling to Good will turn off the device after the preset inactive saving time (default is 2000ms).

See the PowerTOP docs for details on how to make these changes permanent.
It generates the config scripts for you (pretty much as described by other posters on this thread).

NOTE: These scripts do not affect USB pin power (which is always on).
These only send the driver protocol to activate and deactivate a device.

If you want to control pin power, you could use either a supported smart USB hub, or better yet a microcontroller.