Chanh Nguyen | 2fc68eb | 2022-04-28 09:11:28 +0000 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
Thang Q. Nguyen | d9c8965 | 2023-10-05 09:02:31 +0700 | [diff] [blame] | 3 | # shellcheck disable=SC2046 |
Patrick Williams | 0731ef8 | 2023-04-16 16:41:45 -0500 | [diff] [blame] | 4 | # shellcheck source=meta-ampere/meta-mitchell/recipes-ampere/platform/ampere-platform-init/mtmitchell_platform_gpios_init.sh |
Chau Ly | deffe1d | 2024-11-07 08:49:00 +0000 | [diff] [blame] | 5 | # shellcheck source=meta-ampere/meta-common/recipes-ampere/platform/ampere-utils/utils-lib.sh |
Chanh Nguyen | 2fc68eb | 2022-04-28 09:11:28 +0000 | [diff] [blame] | 6 | source /usr/sbin/platform_gpios_init.sh |
Chau Ly | deffe1d | 2024-11-07 08:49:00 +0000 | [diff] [blame] | 7 | source /usr/sbin/utils-lib.sh |
| 8 | |
| 9 | function 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 Nguyen | 2fc68eb | 2022-04-28 09:11:28 +0000 | [diff] [blame] | 30 | |
Chanh Nguyen | 3d2fa85 | 2024-07-12 04:38:54 +0000 | [diff] [blame] | 31 | function 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 Nguyen | 2fc68eb | 2022-04-28 09:11:28 +0000 | [diff] [blame] | 73 | #pre platform init function. implemented in platform_gpios_init.sh |
| 74 | pre-platform-init |
| 75 | |
| 76 | # ======================================================= |
| 77 | # Setting default value for device sel and mux |
| 78 | bootstatus=$(cat /sys/class/watchdog/watchdog0/bootstatus) |
| 79 | if [ "$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. Nguyen | d9c8965 | 2023-10-05 09:02:31 +0700 | [diff] [blame] | 82 | gpioset $(gpiofind "$gpioName")=1 |
Chanh Nguyen | 2fc68eb | 2022-04-28 09:11:28 +0000 | [diff] [blame] | 83 | done |
| 84 | echo "CONFIGURE: gpio pins to output low after AC power" |
| 85 | for gpioName in "${output_low_gpios_in_ac[@]}"; do |
Thang Q. Nguyen | d9c8965 | 2023-10-05 09:02:31 +0700 | [diff] [blame] | 86 | gpioset $(gpiofind "$gpioName")=0 |
Chanh Nguyen | 2fc68eb | 2022-04-28 09:11:28 +0000 | [diff] [blame] | 87 | done |
Chanh Nguyen | 2fc68eb | 2022-04-28 09:11:28 +0000 | [diff] [blame] | 88 | fi |
| 89 | |
| 90 | # ======================================================= |
| 91 | # Setting default value for others gpio pins |
| 92 | echo "CONFIGURE: gpio pins to output high" |
| 93 | for gpioName in "${output_high_gpios_in_bmc_reboot[@]}"; do |
Thang Q. Nguyen | d9c8965 | 2023-10-05 09:02:31 +0700 | [diff] [blame] | 94 | gpioset $(gpiofind "$gpioName")=1 |
Chanh Nguyen | 2fc68eb | 2022-04-28 09:11:28 +0000 | [diff] [blame] | 95 | done |
| 96 | echo "CONFIGURE: gpio pins to output low" |
| 97 | for gpioName in "${output_low_gpios_in_bmc_reboot[@]}"; do |
Thang Q. Nguyen | d9c8965 | 2023-10-05 09:02:31 +0700 | [diff] [blame] | 98 | gpioset $(gpiofind "$gpioName")=0 |
Chanh Nguyen | 2fc68eb | 2022-04-28 09:11:28 +0000 | [diff] [blame] | 99 | done |
Chanh Nguyen | 2fc68eb | 2022-04-28 09:11:28 +0000 | [diff] [blame] | 100 | |
Chau Ly | deffe1d | 2024-11-07 08:49:00 +0000 | [diff] [blame] | 101 | socket-based-fan-conf-update |
Chanh Nguyen | 3d2fa85 | 2024-07-12 04:38:54 +0000 | [diff] [blame] | 102 | mtc_board_revision_detection |
| 103 | |
Chanh Nguyen | 2fc68eb | 2022-04-28 09:11:28 +0000 | [diff] [blame] | 104 | #post platform init function. implemented in platform_gpios_init.sh |
| 105 | post-platform-init |
| 106 | |
| 107 | exit 0 |