Samuel Jiang | 94ca061 | 2019-03-21 13:47:13 +0800 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
Samuel Jiang | efc4e1d | 2019-04-25 14:43:23 +0800 | [diff] [blame] | 3 | source /usr/libexec/nvme_powerctrl_library.sh |
| 4 | |
Samuel Jiang | 94ca061 | 2019-03-21 13:47:13 +0800 | [diff] [blame] | 5 | function set_gpio() { |
| 6 | #$1 gpio pin |
| 7 | echo $1 > /sys/class/gpio/export |
| 8 | } |
| 9 | |
Samuel Jiang | efc4e1d | 2019-04-25 14:43:23 +0800 | [diff] [blame] | 10 | echo "Read Clock Gen Value is: $CLOCK_GEN_VALUE" |
Samuel Jiang | 94ca061 | 2019-03-21 13:47:13 +0800 | [diff] [blame] | 11 | |
Samuel Jiang | efc4e1d | 2019-04-25 14:43:23 +0800 | [diff] [blame] | 12 | ## Initial U2_PRESENT_N |
| 13 | for i in ${!U2_PRESENT[@]}; |
| 14 | do |
| 15 | set_gpio ${U2_PRESENT[$i]}; |
| 16 | set_gpio_direction ${U2_PRESENT[$i]} 'in'; |
| 17 | echo "Read $i SSD present: $(read_gpio_input ${U2_PRESENT[$i]})" |
Samuel Jiang | 94ca061 | 2019-03-21 13:47:13 +0800 | [diff] [blame] | 18 | done |
| 19 | |
| 20 | ## Initial POWER_U2_EN |
Samuel Jiang | efc4e1d | 2019-04-25 14:43:23 +0800 | [diff] [blame] | 21 | for i in ${!POWER_U2[@]}; |
Samuel Jiang | 94ca061 | 2019-03-21 13:47:13 +0800 | [diff] [blame] | 22 | do |
Samuel Jiang | efc4e1d | 2019-04-25 14:43:23 +0800 | [diff] [blame] | 23 | set_gpio ${POWER_U2[$i]}; |
Samuel Jiang | 94ca061 | 2019-03-21 13:47:13 +0800 | [diff] [blame] | 24 | done |
| 25 | |
| 26 | ## Initial PWRGD_U2 |
Samuel Jiang | efc4e1d | 2019-04-25 14:43:23 +0800 | [diff] [blame] | 27 | for i in ${!PWRGD_U2[@]}; |
| 28 | do |
| 29 | set_gpio ${PWRGD_U2[$i]}; |
| 30 | set_gpio_direction ${PWRGD_U2[$i]} 'in'; |
| 31 | echo "Read $i SSD Power Good: $(read_gpio_input ${PWRGD_U2[$i]})" |
Samuel Jiang | 94ca061 | 2019-03-21 13:47:13 +0800 | [diff] [blame] | 32 | done |
| 33 | |
Samuel Jiang | efc4e1d | 2019-04-25 14:43:23 +0800 | [diff] [blame] | 34 | ## Initial RST_BMC_U2 |
| 35 | for i in ${!RST_BMC_U2[@]}; |
| 36 | do |
| 37 | set_gpio ${RST_BMC_U2[$i]}; |
| 38 | done |
| 39 | |
| 40 | ### Initial related Power by Present |
Samuel Jiang | 94ca061 | 2019-03-21 13:47:13 +0800 | [diff] [blame] | 41 | for i in {0..7}; |
| 42 | do |
Samuel Jiang | efc4e1d | 2019-04-25 14:43:23 +0800 | [diff] [blame] | 43 | update_value=$(printf '%x\n' "$((0x01 <<$i))") |
| 44 | if [ $(read_gpio_input ${U2_PRESENT[$i]}) == $PLUGGED ];then |
| 45 | CLOCK_GEN_VALUE=$(printf '0x%x\n' \ |
| 46 | "$(($CLOCK_GEN_VALUE | 0x$update_value))") |
| 47 | else |
| 48 | set_gpio_direction "${RST_BMC_U2[$1]}" "low" |
| 49 | set_gpio_direction "${POWER_U2[$1]}" "low" |
Samuel Jiang | 94ca061 | 2019-03-21 13:47:13 +0800 | [diff] [blame] | 50 | |
Samuel Jiang | efc4e1d | 2019-04-25 14:43:23 +0800 | [diff] [blame] | 51 | CLOCK_GEN_VALUE=$(printf '0x%x\n' \ |
| 52 | "$(($CLOCK_GEN_VALUE & ~0x$update_value))") |
| 53 | fi |
| 54 | done |
| 55 | i2cset -y $I2C_BUS $CHIP_ADDR 0 $CLOCK_GEN_VALUE s |
| 56 | echo "Read Clock Gen Value again is: $CLOCK_GEN_VALUE" |
Samuel Jiang | 94ca061 | 2019-03-21 13:47:13 +0800 | [diff] [blame] | 57 | |
Samuel Jiang | efc4e1d | 2019-04-25 14:43:23 +0800 | [diff] [blame] | 58 | exit 0; |