blob: f29514f9e7638d0e49a12c80d9c3aec85243e779 (
plain)
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
# Copyright 2014-present Facebook. All Rights Reserved.
DEVMEM=/sbin/devmem
devmem_set_bit() {
local addr
local val
addr=$1
val=$($DEVMEM $addr)
val=$((val | (0x1 << $2)))
$DEVMEM $addr 32 $val
}
devmem_clear_bit() {
local addr
local val
addr=$1
val=$($DEVMEM $addr)
val=$((val & ~(0x1 << $2)))
$DEVMEM $addr 32 $val
}
scu_addr() {
echo $((0x1E6E2000 + 0x$1))
}
GPIODIR="/sys/class/gpio"
GPIOEXPORT="$GPIODIR/export"
gpio_dir() {
echo "$GPIODIR/gpio$1"
}
gpio_name2value() {
local first remaining base val
remaining=$1
val=0
while [ -n "$remaining" ]; do
first=${remaining:0:1}
case "$first" in
[[:lower:]])
base=$(printf "%d" "'$first'")
base=$((base - 96))
val=$((val * 26 + base))
;;
[[:upper:]])
base=$(printf "%d" "'$first'")
base=$((base - 64))
val=$((val * 26 + base))
;;
*)
if [ $val -gt 0 ]; then
val=$((val-1))
fi
val=$((val * 8 + $remaining))
break
;;
esac
remaining=${remaining:1}
done
echo "$val"
}
gpio_export() {
local gpio
gpio=$(gpio_name2value $1)
dir=$(gpio_dir $gpio)
if [ ! -d ${dir} ]; then
echo $gpio > $GPIOEXPORT
fi
}
gpio_set() {
local gpio
local val
gpio=$(gpio_name2value $1)
val=$2
dir=$(gpio_dir $gpio)
if [ ! -d ${dir} ]; then
echo $gpio > $GPIOEXPORT
fi
echo out > ${dir}/direction
echo $val > ${dir}/value
}
gpio_get() {
local gpio
local val
gpio=$(gpio_name2value $1)
dir=$(gpio_dir $gpio)
if [ ! -d ${dir} ]; then
echo $gpio > $GPIOEXPORT
fi
echo in > ${dir}/direction
cat ${dir}/value
}
# Check to see if BMC power-on-reset
is_bmc_por() {
local val
# Read the Watch Dog Counter
val=$(devmem 0x1e785010 2>/dev/null)
if [ "$((val & 0xff00))" == "0" ]; then
# Power ON Reset
echo 1
else
echo 0
fi
}
# Check to see if server is present in given slot or not
is_server_prsnt() {
local prsnt
case $1 in
1)
prsnt=$(gpio_get H5)
;;
2)
prsnt=$(gpio_get H4)
;;
3)
prsnt=$(gpio_get H7)
;;
4)
prsnt=$(gpio_get H6)
;;
*)
prsnt=$(gpio_get H4)
;;
esac
if [ $prsnt == "0" ]; then
echo 1
else
echo 0
fi
}
yosemite_is_server_on() {
local curr_pwr_cpu
curr_pwr_cpu=$(python -c 'import sys; sys.path.append("/usr/local/fbpackages/utils"); import power_util; print power_util.get_pwr_cpu()')
if [ $curr_pwr_cpu == "1" ]; then
echo 1
else
echo 0
fi
}
|