1#!/bin/bash
2
3# shellcheck disable=SC2046
4
5function bind_rtc_driver() {
6    # If rtc device can not present, bind the device
7    if [[ ! -e /dev/rtc0 ]]; then
8        echo "Bind rtc driver"
9        echo 6-0051 > /sys/bus/i2c/drivers/rtc-pcf85063/bind
10    fi
11}
12
13function pre-platform-init() {
14    echo "Do pre platform init"
15}
16
17function post-platform-init() {
18
19    # When BMC is rebooted, because PSON_L has pull up to P3V3_STB, it changes its
20    # value to HIGH. Add code to check P3V3_STB and recover PSON_L to correct state
21    # before setting BMC_RDY.
22    pgood=$(gpioget $(gpiofind power-chassis-good))
23    if [ "$pgood" == '1' ]; then
24        echo "PSU is on. Setting PSON to 0"
25        gpioset $(gpiofind power-chassis-control)=0
26    else
27        echo "PSU is off. Setting PSON to 1"
28        gpioset $(gpiofind power-chassis-control)=1
29    fi
30
31    gpioset $(gpiofind host0-sysreset-n)=1
32
33    echo "Set default FAN speed to 60%"
34    for filename in /sys/class/hwmon/*/pwm*
35    do
36        echo 153 > "$filename"
37    done
38
39    # Bind rtc driver
40    bind_rtc_driver
41}
42
43export output_high_gpios_in_ac=(
44    # add device enable, mux setting, device select gpios
45    "spi0-backup-sel"
46    "i2c-backup-sel"
47)
48
49export output_low_gpios_in_ac=(
50    # add device enable, mux setting, device select gpios
51    "spi0-program-sel"
52    "ocp-main-pwren"
53)
54
55export input_gpios_in_ac=(
56    # add device enable, mux setting, device select gpios
57)
58
59export output_high_gpios_in_bmc_reboot=(
60    "host0-sysreset-n"
61    "host0-pmin-n"
62    "bmc-debug-mode"
63    "vrd-sel"
64    "spd-sel"
65    "ext-high-temp-n"
66    "fpga-program-b"
67    "wd-disable-n"
68    "hpm-stby-rst-n"
69    "jtag-sel-s0"
70    "cpld-user-mode"
71    "jtag-srst-n"
72    "host0-shd-req-n"
73    "uart1-mode1"
74    "uart2-mode1"
75    "uart3-mode1"
76    "uart4-mode1"
77)
78
79export output_low_gpios_in_bmc_reboot=(
80    "rtc-battery-voltage-read-enable"
81    "s0-rtc-lock"
82    "hpm-fw-recovery"
83    "led-fault"
84    "spi-nor-access"
85    "host0-special-boot"
86    "uart1-mode0"
87    "uart2-mode0"
88    "uart3-mode0"
89    "uart4-mode0"
90)
91
92export input_gpios_in_bmc_reboot=(
93    "s0-vrd-fault-n"
94    "s1-vrd-fault-n"
95    "irq-n"
96    "presence-ps0"
97    "presence-ps1"
98    "hsc-12vmain-alt2-n"
99    "eth-phy-int-n"
100    "s0-pcp-oc-warn-n"
101    "s1-pcp-oc-warn-n"
102    "cpu-bios-recover"
103    "s0-heartbeat"
104    "hs-scout-proc-hot"
105    "s0-vr-hot-n"
106    "s1-vr-hot-n"
107    "hsc-12vmain-alt1-n"
108    "power-chassis-good"
109    "s0-ddr-save"
110    "soc-spi-nor-access"
111    "presence-cpu0"
112    "jtag-dbgr-prsnt-n"
113    "ps0-ac-loss-n"
114    "ps1-ac-loss-n"
115    "s1-ddr-save"
116    "s0-fw-boot-ok"
117    "s1-pcp-pgood"
118    "presence-cpu1"
119    "s0-fault-alert"
120    "s0-sys-auth-failure-n"
121    "host0-ready"
122    "ocp-pgood"
123    "s1-fault-alert"
124    "s1-fw-boot-ok"
125    "s0-spi-auth-fail-n"
126    "s1-sys-auth-failure-n"
127    "cpld-s1-spi-auth-fail-n"
128    "ps0-pgood"
129    "ps1-pgood"
130    "s0-soc-pgood"
131)
132