-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
gpio_input_examples.sh
executable file
·129 lines (112 loc) · 2.91 KB
/
gpio_input_examples.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/bin/bash
modprobe gpio-ich
modprobe gpio-it87
## it87_gp34 = function button
## it87_gp35 = display button
#### ich gpios:
#boot switch -> GPIO12
#sata0 -> GPIO2
#sata1 -> GPIO3
#sata2 -> GPIO4
#sata3 -> GPIO5
#sata4 -> GPIO15
#sata5 -> GPIO9
#sata6 -> GPIO13
#sata7 -> GPIO10
#also possibly:
#sata5 -> GPIO16
#sata6 -> GPIO18
#sata7 -> GPIO11
#sata7 -> GPIO20
## board id:
# GPIO31 GPIO30 GPIO29 SKU
# ------ ------ ------ ----------
# 0 0 0 2HDD box
# 0 0 1 4HDD box
# 0 1 0 6HDD box
# 0 1 1 8HDD box
# 1 0 0 1U
get_gpio_value()
{
local export_folder="/sys/class/gpio/$1"
if [ ! -d "$export_folder" ]; then
return 0
fi
if [ "$(cat $export_folder/direction)" != "in" ]; then
echo "in" > "$export_folder/direction"
fi
echo "$(cat $export_folder/value)"
return 0
}
gpio_chips="$(ls /sys/class/gpio/ | grep gpiochip)"
it87_gpio_base=""
ich_gpio_base=""
for chip in $gpio_chips
do
dir="/sys/class/gpio/$chip"
if [ "$(cat $dir/label)" == "gpio_it87" ]; then
it87_gpio_base="$(cat $dir/base)"
fi
if [ "$(cat $dir/label)" == "gpio_ich" ]; then
ich_gpio_base="$(cat $dir/base)"
fi
done
##offsets corresponding to 34/35
it87_offsets="20 21"
ich_offsets="2 3 4 5 9 10 11 12 13 15 16 18 20 29 30 31"
gpio_list=""
export_list=""
sku=""
if [ "$it87_gpio_base" != "" ]; then
for gpio in $it87_offsets
do
gpio_list="$gpio_list $(($it87_gpio_base+$gpio))"
done
fi
if [ "$ich_gpio_base" != "" ]; then
for gpio in $ich_offsets
do
gpio_list="$gpio_list $(($ich_gpio_base+$gpio))"
export_list="$export_list gpio$(($ich_gpio_base+$gpio))"
done
sku+="$(get_gpio_value gpio$(($ich_gpio_base+31)))"
sku+="$(get_gpio_value gpio$(($ich_gpio_base+30)))"
sku+="$(get_gpio_value gpio$(($ich_gpio_base+29)))"
fi
echo "$(dmidecode --type 11 | grep String\ | cut -d":" -f2)""$(dmidecode --type 0 | grep Version)"
if [ "$sku" == "000" ]; then
echo "BoardID: $sku = 2HDD box"
fi
if [ "$sku" == "001" ]; then
echo "BoardID: $sku = 4HDD box"
fi
if [ "$sku" == "010" ]; then
echo "BoardID: $sku = 6HDD box"
fi
if [ "$sku" == "011" ]; then
echo "BoardID: $sku = 8HDD box"
fi
if [ "$sku" == "100" ]; then
echo "BoardID: $sku = 1U box"
fi
new_array=""
for gpio in $gpio_list
do
echo $gpio > /sys/class/gpio/export 2>/dev/null
done
##assumes all it87 gpio where exported by this script
export_list="$export_list $(ls /sys/class/gpio | grep it87)"
while true
do
x=0
for gpio in $export_list
do
x=$x+1
tmp_val="$(get_gpio_value $gpio)"
if [ "${new_array[$x]}" != "$tmp_val" ] && [ "${new_array[$x]}" != "" ]; then
echo "$gpio" "=" "${new_array[$x]}""->""$tmp_val"
fi
new_array[$x]=$tmp_val
done
sleep 1
done