blob: e6646f44e7e6258e85f56ef7e92849b9e5df3971 [file] [log] [blame]
Chanh Nguyen2fc68eb2022-04-28 09:11:28 +00001#!/bin/bash
2
Thang Q. Nguyend9c89652023-10-05 09:02:31 +07003# shellcheck disable=SC2046
Patrick Williams0731ef82023-04-16 16:41:45 -05004# shellcheck source=meta-ampere/meta-mitchell/recipes-ampere/platform/ampere-platform-init/mtmitchell_platform_gpios_init.sh
Chau Lydeffe1d2024-11-07 08:49:00 +00005# shellcheck source=meta-ampere/meta-common/recipes-ampere/platform/ampere-utils/utils-lib.sh
Chanh Nguyen2fc68eb2022-04-28 09:11:28 +00006source /usr/sbin/platform_gpios_init.sh
Chau Lydeffe1d2024-11-07 08:49:00 +00007source /usr/sbin/utils-lib.sh
8
9function socket-based-fan-conf-update() {
10 echo "Checking phosphor-fan configurations based on CPU 1 presence..."
11 fanControlConfDir="/usr/share/phosphor-fan-presence/control/com.ampere.Hardware.Chassis.Model.MtMitchell"
12 targetConf=groups.json
13
14 if [[ "$(sx_present 1)" == "0" ]]; then
15 refConf=groups_2p.json
16 echo "CPU 1 is present"
17 echo "Using fan configs for 2P at $fanControlConfDir/$refConf"
18 else
19 refConf=groups_1p.json
20 echo "CPU 1 is NOT present"
21 echo "Using fan configs for 1P at $fanControlConfDir/$refConf"
22 fi
23
24 if [ -f "$fanControlConfDir/$refConf" ]; then
25 cp "$fanControlConfDir/$refConf" "$fanControlConfDir/$targetConf"
26 else
27 echo "The reference fan config $fanControlConfDir/$refConf does not exist!!"
28 fi
29}
Chanh Nguyen2fc68eb2022-04-28 09:11:28 +000030
Chanh Nguyen3d2fa852024-07-12 04:38:54 +000031function mtc_board_revision_detection() {
32 # Support to detect MTC board revisions via board ID and to set GPI pins for the host
33 # to identify the board revision.
34
35 # Check the mainboard by board_id (i2c0, address 0x20)
36 board_id=$(i2cget -y -a 0 0x20 0x0 b)
37 if [ "$?" == '1' ]; then
38 echo "Failed to read board_id from i2c"
39 fi
40
41 # BIT[7:6:5:4]
42 # 0000 : EVT1
43 # 0001 : EVT2
44 # 0010 : EVT3
45 # 0011 :
46 # 0100 : DVT1
47 # 0101 : DVT2
48 # 0110 : DVT3
49 # 0111 :
50 # 1000 : PVT1
51 # 1001 : PVT2
52 # 1010 : PVT3
53 # 1011 :
54
55 md_id_7_6_5_4=$(( (board_id & 0xF0)>>4 ))
56
57 # P0[7] -> GPI[1] and P0[6] -> GPI[0]
58 # P[7:6] = 2'b01 for Mitchell 2.0 (PVT2)
59 # P[7:6] = 2'b00 for Mitchell 1.0 (EVTx, DVTx, PVT1 )
60 if [[ $md_id_7_6_5_4 -gt 8 ]]; then
61 # Board is MTC2.0
62 echo "Update GPI1 to low and GPI0 to high"
63 gpioset $(gpiofind gpi1)=0
64 gpioset $(gpiofind gpi0)=1
65 else
66 # Board is MTC1.0
67 echo "Update GPI1 to low and GPI0 to low"
68 gpioset $(gpiofind gpi1)=0
69 gpioset $(gpiofind gpi0)=0
70 fi
71}
72
Chanh Nguyen2fc68eb2022-04-28 09:11:28 +000073#pre platform init function. implemented in platform_gpios_init.sh
74pre-platform-init
75
76# =======================================================
77# Setting default value for device sel and mux
78bootstatus=$(cat /sys/class/watchdog/watchdog0/bootstatus)
79if [ "$bootstatus" == '32' ]; then
80 echo "CONFIGURE: gpio pins to output high after AC power"
81 for gpioName in "${output_high_gpios_in_ac[@]}"; do
Thang Q. Nguyend9c89652023-10-05 09:02:31 +070082 gpioset $(gpiofind "$gpioName")=1
Chanh Nguyen2fc68eb2022-04-28 09:11:28 +000083 done
84 echo "CONFIGURE: gpio pins to output low after AC power"
85 for gpioName in "${output_low_gpios_in_ac[@]}"; do
Thang Q. Nguyend9c89652023-10-05 09:02:31 +070086 gpioset $(gpiofind "$gpioName")=0
Chanh Nguyen2fc68eb2022-04-28 09:11:28 +000087 done
Chanh Nguyen2fc68eb2022-04-28 09:11:28 +000088fi
89
90# =======================================================
91# Setting default value for others gpio pins
92echo "CONFIGURE: gpio pins to output high"
93for gpioName in "${output_high_gpios_in_bmc_reboot[@]}"; do
Thang Q. Nguyend9c89652023-10-05 09:02:31 +070094 gpioset $(gpiofind "$gpioName")=1
Chanh Nguyen2fc68eb2022-04-28 09:11:28 +000095done
96echo "CONFIGURE: gpio pins to output low"
97for gpioName in "${output_low_gpios_in_bmc_reboot[@]}"; do
Thang Q. Nguyend9c89652023-10-05 09:02:31 +070098 gpioset $(gpiofind "$gpioName")=0
Chanh Nguyen2fc68eb2022-04-28 09:11:28 +000099done
Chanh Nguyen2fc68eb2022-04-28 09:11:28 +0000100
Chau Lydeffe1d2024-11-07 08:49:00 +0000101socket-based-fan-conf-update
Chanh Nguyen3d2fa852024-07-12 04:38:54 +0000102mtc_board_revision_detection
103
Chanh Nguyen2fc68eb2022-04-28 09:11:28 +0000104#post platform init function. implemented in platform_gpios_init.sh
105post-platform-init
106
107exit 0