blob: 71116fbe9a90397c8bff35841fc5e9f3997c53d3 [file] [log] [blame]
Samuel Jiang94ca0612019-03-21 13:47:13 +08001#!/bin/bash
2
Samuel Jiangefc4e1d2019-04-25 14:43:23 +08003source /usr/libexec/nvme_powerctrl_library.sh
4
Samuel Jiang94ca0612019-03-21 13:47:13 +08005function set_gpio() {
6 #$1 gpio pin
7 echo $1 > /sys/class/gpio/export
8}
9
Samuel Jiangefc4e1d2019-04-25 14:43:23 +080010echo "Read Clock Gen Value is: $CLOCK_GEN_VALUE"
Samuel Jiang94ca0612019-03-21 13:47:13 +080011
Samuel Jiangefc4e1d2019-04-25 14:43:23 +080012## Initial U2_PRESENT_N
13for i in ${!U2_PRESENT[@]};
14do
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 Jiang94ca0612019-03-21 13:47:13 +080018done
19
20## Initial POWER_U2_EN
Samuel Jiangefc4e1d2019-04-25 14:43:23 +080021for i in ${!POWER_U2[@]};
Samuel Jiang94ca0612019-03-21 13:47:13 +080022do
Samuel Jiangefc4e1d2019-04-25 14:43:23 +080023 set_gpio ${POWER_U2[$i]};
Samuel Jiang94ca0612019-03-21 13:47:13 +080024done
25
26## Initial PWRGD_U2
Samuel Jiangefc4e1d2019-04-25 14:43:23 +080027for i in ${!PWRGD_U2[@]};
28do
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 Jiang94ca0612019-03-21 13:47:13 +080032done
33
Samuel Jiangefc4e1d2019-04-25 14:43:23 +080034## Initial RST_BMC_U2
35for i in ${!RST_BMC_U2[@]};
36do
37 set_gpio ${RST_BMC_U2[$i]};
38done
39
40### Initial related Power by Present
Samuel Jiang94ca0612019-03-21 13:47:13 +080041for i in {0..7};
42do
Samuel Jiangefc4e1d2019-04-25 14:43:23 +080043 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 Jiang94ca0612019-03-21 13:47:13 +080050
Samuel Jiangefc4e1d2019-04-25 14:43:23 +080051 CLOCK_GEN_VALUE=$(printf '0x%x\n' \
52 "$(($CLOCK_GEN_VALUE & ~0x$update_value))")
53 fi
54done
55i2cset -y $I2C_BUS $CHIP_ADDR 0 $CLOCK_GEN_VALUE s
56echo "Read Clock Gen Value again is: $CLOCK_GEN_VALUE"
Samuel Jiang94ca0612019-03-21 13:47:13 +080057
Samuel Jiangefc4e1d2019-04-25 14:43:23 +080058exit 0;