blob: 753c6c4cf5a64542d4fac80aa5bd62506178e02b [file] [log] [blame]
Samuel Jiangabda5612019-03-21 13:47:13 +08001#!/bin/bash
2
Samuel Jiange689ff42019-04-25 14:43:23 +08003source /usr/libexec/nvme_powerctrl_library.sh
Samuel Jiangabda5612019-03-21 13:47:13 +08004U2_PRESENT_STATUS=( 1 1 1 1 1 1 1 1 )
Samuel Jiangabda5612019-03-21 13:47:13 +08005
Samuel Jiange689ff42019-04-25 14:43:23 +08006function recovery_power()
7{
8 set_gpio_direction "${POWER_U2[$1]}" "low"
9 sleep 0.2
10 set_gpio_direction "${POWER_U2[$1]}" "high"
11 sleep 0.2
12 check_powergood $1
Samuel Jiangabda5612019-03-21 13:47:13 +080013}
14
Samuel Jiangabda5612019-03-21 13:47:13 +080015
16##Initial U2 present status
17for i in {0..7};
Samuel Jiange689ff42019-04-25 14:43:23 +080018do
19 U2_PRESENT_STATUS[$i]=$(read_gpio_input ${U2_PRESENT[$i]})
Samuel Jiangabda5612019-03-21 13:47:13 +080020done
21
Samuel Jiangabda5612019-03-21 13:47:13 +080022## Loop while
23while :
24do
25 for i in {0..7};
26 do
Samuel Jiange689ff42019-04-25 14:43:23 +080027 ## 1 second scan all loop
Samuel Jiangabda5612019-03-21 13:47:13 +080028 sleep 0.125
Samuel Jiange689ff42019-04-25 14:43:23 +080029 read_present=$(read_gpio_input ${U2_PRESENT[$i]})
30 if [ "$read_present" != "${U2_PRESENT_STATUS[$i]}" ];then
31 U2_PRESENT_STATUS[$i]="$read_present"
32 if [ "$read_present" == $PLUGGED ];then
33 echo "NVME $i Enable Power"
34 enable_nvme_power $i
35 else
36 echo "NVME $i Disable Power"
37 disable_nvme_power $i
38 fi
39 else
40 if [ "${U2_PRESENT_STATUS[$i]}" == $PLUGGED ] &&
41 [ $(read_gpio_input ${PWRGD_U2[$i]}) == 0 ];then
42 echo "NVME $i Recovery Power"
43 recovery_power $i
44 fi
45 fi
Samuel Jiangabda5612019-03-21 13:47:13 +080046 done
47done