Skip to content

Instantly share code, notes, and snippets.

@hfreire
Last active Jul 24, 2019
Embed
What would you like to do?
Enable/disable power on Raspberry Pi USB ports + Ethernet
#!/bin/sh
SOC_USB=/sys/devices/platform/soc/20980000.usb
if [ ! -d $SOC_USB ];
then
SOC_USB=/sys/devices/platform/soc/3f980000.usb # Raspberry Pi 3
fi
BUSPOWER=$SOC_USB/buspower
is_usb_power_on ()
{
cat $BUSPOWER | grep "Bus Power = 0x1" >/dev/null
}
case $1 in
stop)
if is_usb_power_on
then
echo 0x0 > $BUSPOWER
fi
;;
start)
if ! is_usb_power_on
then
echo 0x1 > $BUSPOWER
fi
;;
status)
if is_usb_power_on
then
echo "USB power is on"
else
echo "USB power is off"
fi
;;
*)
echo "Usage: $0 start|stop|status" >&2
exit 2
;;
esac
exit 0
@suuuehgi

This comment has been minimized.

Copy link

@suuuehgi suuuehgi commented Oct 2, 2017

This does not work for RPi 3b. There you can:

ON
echo '1-1' > /sys/bus/usb/drivers/usb/bind
OFF
echo '1-1' > /sys/bus/usb/drivers/usb/unbind

For the status: You might check if folders (symlinks) are present in /sys/bus/usb/drivers/usb.

@thijstriemstra

This comment has been minimized.

Copy link

@thijstriemstra thijstriemstra commented May 12, 2018

is it possible to disable individual usb ports?

@MarcLV

This comment has been minimized.

Copy link

@MarcLV MarcLV commented Jul 31, 2018

I've googled a bit and it seems like you cant disable individual usb ports on the RPi 3b

@dotps1

This comment has been minimized.

Copy link

@dotps1 dotps1 commented Oct 22, 2018

the code for the rpi 3b doesn't work, permission denied, even using elevation.

@hg42

This comment has been minimized.

Copy link

@hg42 hg42 commented Mar 29, 2019

@dotps1 if you run commands with redirection a simple sudo doesn't work, because the redirection is done by the unprivileged shell (before sudo starts).

Instead you can replace
echo XYZ >PROTECTED-FILE
by something like
echo XYZ | sudo tee PROTECTED-FILE
(and appending like >>FILE would be replaced by | sudo tee -a FILE`)

or become root by sudo su first...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment