blob: 08aa7a0549e7d8ec157f8fa72cd9f26a4a8b2842 [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
4
Samuel Jiangabda5612019-03-21 13:47:13 +08005function set_gpio() {
6 #$1 gpio pin
7 echo $1 > /sys/class/gpio/export
8}
9
Samuel Jiange689ff42019-04-25 14:43:23 +080010echo "Read Clock Gen Value is: $CLOCK_GEN_VALUE"
Samuel Jiangabda5612019-03-21 13:47:13 +080011
Samuel Jiange689ff42019-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 Jiangabda5612019-03-21 13:47:13 +080018done
19
20## Initial POWER_U2_EN
Samuel Jiange689ff42019-04-25 14:43:23 +080021for i in ${!POWER_U2[@]};
Samuel Jiangabda5612019-03-21 13:47:13 +080022do
Samuel Jiange689ff42019-04-25 14:43:23 +080023 set_gpio ${POWER_U2[$i]};
Samuel Jiangabda5612019-03-21 13:47:13 +080024done
25
26## Initial PWRGD_U2
Samuel Jiange689ff42019-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 Jiangabda5612019-03-21 13:47:13 +080032done
33
Samuel Jiange689ff42019-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 Jiangabda5612019-03-21 13:47:13 +080041for i in {0..7};
42do
Samuel Jiange689ff42019-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
Samuel Jiang4ac9d5f2019-10-02 11:19:39 +080048 set_gpio_direction "${RST_BMC_U2[$i]}" "low"
49 set_gpio_direction "${POWER_U2[$i]}" "low"
Samuel Jiangabda5612019-03-21 13:47:13 +080050
Samuel Jiange689ff42019-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 Jiangabda5612019-03-21 13:47:13 +080057
Samuel Jiange689ff42019-04-25 14:43:23 +080058exit 0;