Skip to content

Instantly share code, notes, and snippets.

@marcotini
Forked from hfreire/rpi-usb.sh
Created May 31, 2018 17:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcotini/b52f9d5bfdbad6c37ea92fcd8f82c30b to your computer and use it in GitHub Desktop.
Save marcotini/b52f9d5bfdbad6c37ea92fcd8f82c30b to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment