-
-
Save elin3t/5379f216362e69be466529e3d7286dea to your computer and use it in GitHub Desktop.
Enable/disable power on Raspberry Pi USB ports + Ethernet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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