| Samuel Jiang | abda561 | 2019-03-21 13:47:13 +0800 | [diff] [blame] | 1 | #!/bin/bash | 
|  | 2 |  | 
|  | 3 | function set_gpio() { | 
|  | 4 | #$1 gpio pin | 
|  | 5 | echo $1 > /sys/class/gpio/export | 
|  | 6 | } | 
|  | 7 |  | 
|  | 8 | function set_gpio_direction(){ | 
|  | 9 | #$1 gpio pin, $2 'in','high','low' | 
|  | 10 | echo $2 > /sys/class/gpio/gpio$1/direction | 
|  | 11 | } | 
|  | 12 |  | 
|  | 13 | function read_gpio_input(){ | 
|  | 14 | #$1 read input gpio pin | 
|  | 15 | cat /sys/class/gpio/gpio$1/value | 
|  | 16 | } | 
|  | 17 |  | 
|  | 18 | function read_present_set_related_power(){ | 
|  | 19 | #$1 read present gpio, $2 output power gpio,$3 output direction | 
|  | 20 | var=$(cat /sys/class/gpio/gpio$1/value) | 
|  | 21 | # present 0 is plugged,present 1 is removal | 
|  | 22 | if [ "$var" == "0" ];then | 
|  | 23 | set_gpio_direction $2 "high" | 
|  | 24 | else | 
|  | 25 | set_gpio_direction $2 "low" | 
|  | 26 | fi | 
|  | 27 | } | 
|  | 28 |  | 
|  | 29 |  | 
|  | 30 | ## Initial U2_PRESNET_N | 
|  | 31 | U2_PRESENT=( 148 149 150 151 152 153 154 155 ) | 
|  | 32 | for i in "${U2_PRESENT[@]}"; | 
|  | 33 | do | 
|  | 34 | set_gpio $i; | 
|  | 35 | set_gpio_direction $i 'in'; | 
|  | 36 | done | 
|  | 37 |  | 
|  | 38 | ## Initial POWER_U2_EN | 
|  | 39 | POWER_U2=( 195 196 202 199 198 197 127 126 ) | 
|  | 40 | for i in "${POWER_U2[@]}"; | 
|  | 41 | do | 
|  | 42 | set_gpio $i; | 
|  | 43 | done | 
|  | 44 |  | 
|  | 45 | ## Initial PWRGD_U2 | 
|  | 46 | PWRGD_U2=( 161 162 163 164 165 166 167 168 ) | 
|  | 47 | for i in "${PWRGD_U2[@]}"; | 
|  | 48 | do | 
|  | 49 | set_gpio $i; | 
|  | 50 | set_gpio_direction $i 'in'; | 
|  | 51 | done | 
|  | 52 |  | 
|  | 53 | ### Initial SSD Power reference U2_PRESNET_N | 
|  | 54 | for i in {0..7}; | 
|  | 55 | do | 
|  | 56 | read_present_set_related_power "${U2_PRESENT[$i]}" "${POWER_U2[$i]}"; | 
|  | 57 | done | 
|  | 58 |  | 
|  | 59 |  | 
|  | 60 | exit 0; |