Samuel Jiang | abda561 | 2019-03-21 13:47:13 +0800 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
Samuel Jiang | e689ff4 | 2019-04-25 14:43:23 +0800 | [diff] [blame] | 3 | source /usr/libexec/nvme_powerctrl_library.sh |
Samuel Jiang | abda561 | 2019-03-21 13:47:13 +0800 | [diff] [blame] | 4 | U2_PRESENT_STATUS=( 1 1 1 1 1 1 1 1 ) |
Samuel Jiang | abda561 | 2019-03-21 13:47:13 +0800 | [diff] [blame] | 5 | |
Samuel Jiang | e689ff4 | 2019-04-25 14:43:23 +0800 | [diff] [blame] | 6 | function 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 Jiang | abda561 | 2019-03-21 13:47:13 +0800 | [diff] [blame] | 13 | } |
| 14 | |
Samuel Jiang | abda561 | 2019-03-21 13:47:13 +0800 | [diff] [blame] | 15 | |
| 16 | ##Initial U2 present status |
| 17 | for i in {0..7}; |
Samuel Jiang | e689ff4 | 2019-04-25 14:43:23 +0800 | [diff] [blame] | 18 | do |
| 19 | U2_PRESENT_STATUS[$i]=$(read_gpio_input ${U2_PRESENT[$i]}) |
Samuel Jiang | abda561 | 2019-03-21 13:47:13 +0800 | [diff] [blame] | 20 | done |
| 21 | |
Samuel Jiang | abda561 | 2019-03-21 13:47:13 +0800 | [diff] [blame] | 22 | ## Loop while |
| 23 | while : |
| 24 | do |
| 25 | for i in {0..7}; |
| 26 | do |
Samuel Jiang | e689ff4 | 2019-04-25 14:43:23 +0800 | [diff] [blame] | 27 | ## 1 second scan all loop |
Samuel Jiang | abda561 | 2019-03-21 13:47:13 +0800 | [diff] [blame] | 28 | sleep 0.125 |
Samuel Jiang | e689ff4 | 2019-04-25 14:43:23 +0800 | [diff] [blame] | 29 | 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 Jiang | abda561 | 2019-03-21 13:47:13 +0800 | [diff] [blame] | 46 | done |
| 47 | done |