blob: 91beec5667b4752413a0b86153dd235ff5292605 [file] [log] [blame]
Samuel Jiang94ca0612019-03-21 13:47:13 +08001#!/bin/bash
2
3U2_PRESENT_STATUS=( 1 1 1 1 1 1 1 1 )
4U2_PRESENT=( 148 149 150 151 152 153 154 155 )
5POWER_U2=( 195 196 202 199 198 197 127 126 )
6PWRGD_U2=( 161 162 163 164 165 166 167 168 )
7
8
9function set_gpio_direction(){
10 #$1 gpio pin, $2 'in','high','low'
11 echo $2 > /sys/class/gpio/gpio$1/direction
12}
13
14function read_present_set_related_power(){
15 #$1 read present number, $2 output power gpio
16 var="${U2_PRESENT_STATUS[$1]}"
17 # present 0 is plugged,present 1 is removal
18 if [ "$var" == "0" ];then
19 set_gpio_direction $2 "high"
20 else
21 set_gpio_direction $2 "low"
22 fi
23}
24
25function update_u2_status(){
26 #$1 read present gpio
27 var=$(cat /sys/class/gpio/gpio$2/value)
28 U2_PRESENT_STATUS[$1]="$var"
29}
30
31function check_present_and_powergood(){
32 #$2 present gpio, $3 powergood gpio
33 present=$(cat /sys/class/gpio/gpio$2/value)
34 pwrgd=$(cat /sys/class/gpio/gpio$3/value)
35 path=`expr $1`
36 if [ "$present" -eq 0 ] && [ "$pwrgd" -eq 1 ];then
37 busctl set-property xyz.openbmc_project.nvme.manager /xyz/openbmc_project/nvme/$path xyz.openbmc_project.Inventory.Item Present b true
38 else
39 busctl set-property xyz.openbmc_project.nvme.manager /xyz/openbmc_project/nvme/$path xyz.openbmc_project.Inventory.Item Present b false
40 if [ "$present" -eq "$pwrgd" ];then
41 #set fault led
42 busctl set-property xyz.openbmc_project.LED.GroupManager /xyz/openbmc_project/led/groups/led\_u2\_$1\_fault xyz.openbmc_project.Led.Group Asserted b true
43 else
44 busctl set-property xyz.openbmc_project.LED.GroupManager /xyz/openbmc_project/led/groups/led\_u2\_$1\_fault xyz.openbmc_project.Led.Group Asserted b false
45 fi
46
47 fi
48
49
50}
51
52##Initial U2 present status
53for i in {0..7};
54do
55 update_u2_status $i "${U2_PRESENT[$i]}"
56done
57
58
59## Loop while
60while :
61do
62 for i in {0..7};
63 do
64 ## 1 scend scan all loop
65 sleep 0.125
66 read=$(cat /sys/class/gpio/gpio${U2_PRESENT[$i]}/value)
67 if [ "${U2_PRESENT_STATUS[$1]}" != read ];then
68 update_u2_status $i "${U2_PRESENT[$i]}"
69 read_present_set_related_power $i "${POWER_U2[$i]}"
70 check_present_and_powergood $i "${U2_PRESENT[$i]}" "${POWER_U2[$i]}"
71 fi
72 done
73done