Skip to content

Commit 2a5a5ff

Browse files
authored
Add clusterboard ethernet transeiver led control script
Script that allows enabling or disabling the yellow/green pairs of leds on the pine64 clusterboard that show ethernet state. Depends on https://github.com/wkz/phytool to function.
1 parent f226dc1 commit 2a5a5ff

File tree

1 file changed

+121
-0
lines changed

1 file changed

+121
-0
lines changed

clusterboard-RTL8211E-led-ctrl.sh

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
#!/bin/bash
2+
3+
# Thanks to joncostello from the pine64 for the inspiration for writing this
4+
# https://forum.pine64.org/showthread.php?tid=9780
5+
6+
MODE="none"
7+
QUIET=0
8+
9+
LedsOff() {
10+
# set to extension page, extension Page44
11+
phytool write eth0/0/31 0x0007
12+
phytool write eth0/0/30 0x2c
13+
# link rx/tx steady mode, no link up indicator
14+
phytool write eth0/0/0x1a 0x0000
15+
phytool write eth0/0/0x1c 0x0000
16+
# switch to the PHY’s Page
17+
phytool write eth0/0/31 0x0000
18+
} # LedsOff
19+
20+
LedsOn() {
21+
# set to extension page, extension Page44
22+
phytool write eth0/0/31 0x0007
23+
phytool write eth0/0/30 0x2c
24+
# link rx/tx blinking mode, re-enable link up indicator
25+
phytool write eth0/0/0x1a 0x00d1
26+
phytool write eth0/0/0x1c 0x9770
27+
# switch to the PHY’s Page
28+
phytool write eth0/0/31 0x0000
29+
} # LedsOn
30+
31+
Main() {
32+
ParseOptions "$@"
33+
34+
if [ $# -eq 0 ] || [ ${MODE} == "none" ]; then
35+
DisplayUsage
36+
exit 1
37+
fi
38+
39+
CheckRootPriv
40+
CheckDependencies
41+
42+
case "${MODE}" in
43+
enable_leds)
44+
if [ $QUIET != 1 ]; then echo "Disabling NIC Leds..."; fi
45+
LedsOff
46+
exit 0
47+
;;
48+
disable_leds)
49+
if [ $QUIET != 1 ]; then echo "Enabling NIC Leds..."; fi
50+
LedsOn
51+
exit 0
52+
;;
53+
show_regs)
54+
LACR=$(phytool read eth0/0/0x1a)
55+
LCR=$(phytool read eth0/0/0x1c)
56+
57+
echo "LED Action Control Register (LACR) = ${LACR}"
58+
echo "LED Control Register (LCR) = ${LCR}"
59+
exit 0
60+
;;
61+
esac
62+
63+
exit 1
64+
} # Main
65+
66+
ParseOptions() {
67+
while getopts ':hHedsq' opt ; do
68+
case ${opt} in
69+
h|H)
70+
DisplayUsage
71+
exit 0
72+
;;
73+
e)
74+
MODE="enable_leds"
75+
;;
76+
d)
77+
MODE="disable_leds"
78+
;;
79+
s)
80+
MODE="show_regs"
81+
;;
82+
q)
83+
QUIET=1
84+
;;
85+
\?)
86+
echo "Invalid option: ${OPTARG}" 1>&2
87+
exit 1
88+
;;
89+
:)
90+
echo "Invalid option: ${OPTARG} requires an argument." 1>&2
91+
exit 1
92+
;;
93+
esac
94+
done
95+
shift $((OPTIND -1))
96+
} # ParseOptions
97+
98+
DisplayUsage() {
99+
echo "Usage: ${0##*/} [-h] [-e] [-d] [-s] [-q]"
100+
echo "############################################################################"
101+
echo "Use clusterboard-RTL8211E-led-ctrl for the following tasks:"
102+
echo " -e enables the RTL8211E (ethernet transceiver) leds"
103+
echo " -d disables the RTL8211E (ethernet transceiver) leds"
104+
echo " -s shows the current RTL8211E LACR/LCR register values"
105+
echo " -q hides output from enable/disable commands"
106+
echo " -h displays this help screen"
107+
echo "############################################################################"
108+
} # DisplayUsage
109+
110+
CheckRootPriv() {
111+
if [ "$(id -u)" != "0" ]; then
112+
echo -ne "This script must be executed as root. Exiting\n" >&2
113+
exit 1
114+
fi
115+
} # CheckRootPriv
116+
117+
CheckDependencies() {
118+
command -v phytool >/dev/null 2>&1 || { echo >&2 "phytool (https://github.com/wkz/phytool) is required but not detected. Aborting."; exit 1; }
119+
} # CheckDependencies
120+
121+
Main "$@"

0 commit comments

Comments
 (0)