1#!/bin/bash
2
3# shellcheck disable=SC2046
4# shellcheck source=meta-ampere/meta-mitchell/recipes-ampere/platform/ampere-platform-init/mtmitchell_platform_gpios_init.sh
5source /usr/sbin/platform_gpios_init.sh
6
7function mtc_board_revision_detection() {
8    # Support to detect MTC board revisions via board ID and to set GPI pins for the host
9    # to identify the board revision.
10
11    # Check the mainboard by board_id (i2c0, address 0x20)
12    board_id=$(i2cget -y -a 0 0x20 0x0 b)
13    if [ "$?" == '1' ]; then
14        echo "Failed to read board_id from i2c"
15    fi
16
17    # BIT[7:6:5:4]
18    # 0000 : EVT1
19    # 0001 : EVT2
20    # 0010 : EVT3
21    # 0011 :
22    # 0100 : DVT1
23    # 0101 : DVT2
24    # 0110 : DVT3
25    # 0111 :
26    # 1000 : PVT1
27    # 1001 : PVT2
28    # 1010 : PVT3
29    # 1011 :
30
31    md_id_7_6_5_4=$(( (board_id & 0xF0)>>4 ))
32
33    # P0[7] -> GPI[1] and P0[6] -> GPI[0]
34    # P[7:6] = 2'b01 for Mitchell 2.0 (PVT2)
35    # P[7:6] = 2'b00 for Mitchell 1.0 (EVTx, DVTx, PVT1 )
36    if [[ $md_id_7_6_5_4 -gt 8 ]]; then
37        # Board is MTC2.0
38        echo "Update GPI1 to low and GPI0 to high"
39        gpioset $(gpiofind gpi1)=0
40        gpioset $(gpiofind gpi0)=1
41    else
42        # Board is MTC1.0
43        echo "Update GPI1 to low and GPI0 to low"
44        gpioset $(gpiofind gpi1)=0
45        gpioset $(gpiofind gpi0)=0
46    fi
47}
48
49#pre platform init function. implemented in platform_gpios_init.sh
50pre-platform-init
51
52# =======================================================
53# Setting default value for device sel and mux
54bootstatus=$(cat /sys/class/watchdog/watchdog0/bootstatus)
55if [ "$bootstatus" == '32' ]; then
56    echo "CONFIGURE: gpio pins to output high after AC power"
57    for gpioName in "${output_high_gpios_in_ac[@]}"; do
58        gpioset $(gpiofind "$gpioName")=1
59    done
60    echo "CONFIGURE: gpio pins to output low after AC power"
61    for gpioName in "${output_low_gpios_in_ac[@]}"; do
62        gpioset $(gpiofind "$gpioName")=0
63    done
64    echo "CONFIGURE: gpio pins to input after AC power"
65    for gpioName in "${input_gpios_in_ac[@]}"; do
66        gpioget $(gpiofind "$gpioName")
67    done
68fi
69
70# =======================================================
71# Setting default value for others gpio pins
72echo "CONFIGURE: gpio pins to output high"
73for gpioName in "${output_high_gpios_in_bmc_reboot[@]}"; do
74    gpioset $(gpiofind "$gpioName")=1
75done
76echo "CONFIGURE: gpio pins to output low"
77for gpioName in "${output_low_gpios_in_bmc_reboot[@]}"; do
78    gpioset $(gpiofind "$gpioName")=0
79done
80echo "CONFIGURE: gpio pins to input"
81for gpioName in "${input_gpios_in_bmc_reboot[@]}"; do
82    gpioget $(gpiofind "$gpioName")
83done
84
85mtc_board_revision_detection
86
87#post platform init function. implemented in platform_gpios_init.sh
88post-platform-init
89
90exit 0
91