1#!/bin/bash 2# shellcheck source=meta-facebook/recipes-fb/obmc_functions/files/fb-common-functions 3source /usr/libexec/fb-common-functions 4 5GPIO_HIGH=1 6GPIO_LOW=0 7 8wait_gpio_value() 9{ 10 local net_name=$1 11 local max_retries=$3 12 local delay_secs=$4 13 local expd_val=$2 14 15 local gpio_val=0 16 local trycnt=1 17 18 until [[ $gpio_val -gt 0 || $trycnt -gt $max_retries ]] 19 do 20 gpio_val=$(get_gpio "$net_name") 21 rc=$? 22 if [[ $rc -ne 0 ]]; then 23 err_msg="Unable to read $net_name" 24 echo "$err_msg" 25 return 1 26 fi 27 if [[ $gpio_val -eq $expd_val ]]; then 28 return 0 29 fi 30 sleep "$delay_secs" 31 ((trycnt++)) 32 done 33 34 err_msg="wait_gpio_value failed, gpio_val=$gpio_val, exp_val=$expd_val" 35 echo "$err_msg" 36 return 1 37} 38 39bind_i2c_muxes() 40{ 41 # Module 0 I2C Mux 42 # i2c24 - i2c27 43 bind_i2c_device pca954x 0-0071 44 # i2c28 - i2c31 45 bind_i2c_device pca954x 0-0072 46 # i2c32 - i2c35 47 bind_i2c_device pca954x 0-0073 48 49 # Module 1 I2C Mux 50 # i2c36 - i2c39 51 bind_i2c_device pca954x 0-0075 52 # i2c40 - i2c43 53 bind_i2c_device pca954x 0-0076 54 # i2c44 - i2c47 55 bind_i2c_device pca954x 0-0077 56 57 # HDD Board I2C Mux, i2c48 - i2c55 58 bind_i2c_device pca954x 5-0070 59} 60 61bind_gpio_expanders() 62{ 63 # Module 0 IOEXP 64 bind_i2c_device pca953x 2-0020 65 # Module 1 IOEXP 66 bind_i2c_device pca953x 2-0021 67 # HMC IOEXP 68 bind_i2c_device pca953x 2-0027 69 # BMC IOEXP 70 bind_i2c_device pca953x 6-0021 71 # IO Mezz 0 IOEXP 72 bind_i2c_device pca953x 29-0020 73 # IO Mezz 1 IOEXP 74 bind_i2c_device pca953x 41-0021 75} 76 77bind_fru_eeproms() 78{ 79 # Module 0 FRU 80 bind_i2c_device at24 13-0050 81 # Module 1 FRU 82 bind_i2c_device at24 12-0050 83 # HMC FRU 84 bind_i2c_device at24 13-0057 85 # Left CBC FRU 86 bind_i2c_device at24 13-0054 87 # Right CBC FRU 88 bind_i2c_device at24 13-0055 89 # IO Mezz 0 FRU 90 bind_i2c_device at24 29-0050 91 # IO Mezz 1 FRU 92 bind_i2c_device at24 41-0050 93 # HDD Board FRU 94 bind_i2c_device at24 54-0052 95} 96 97reset_host_usb() 98{ 99 set_gpio "USB2_HUB_RESET_L" "$GPIO_LOW" 100 sleep 1 101 set_gpio "USB2_HUB_RESET_L" "$GPIO_HIGH" 102} 103 104rebind_hmc_usb_network() 105{ 106 echo 1e6a1000.usb > /sys/bus/platform/drivers/ehci-platform/unbind 107 echo 1e6a1000.usb > /sys/bus/platform/drivers/ehci-platform/bind 108} 109 110is_stby_good() 111{ 112 local gpio_val 113 114 if ! gpio_val=$(get_gpio "STBY_POWER_PG_3V3"); then 115 return 1 116 fi 117 118 if [[ $gpio_val -eq 0 ]]; then 119 return 1 120 fi 121 122 return 0 123} 124 125set_bmc_ready() 126{ 127 local bmc_ready="/sys/class/leds/bmc_ready_noled/brightness" 128 local bmc_ready_cpld="/sys/class/leds/bmc_ready_cpld_noled/brightness" 129 130 echo 1 > ${bmc_ready} 131 echo 1 > ${bmc_ready_cpld} 132 return 0 133} 134 135if ! is_stby_good; then 136 set_gpio "SCM_HPM_STBY_RST_N" "$GPIO_LOW" 137fi 138 139set_gpio "SCM_HPM_STBY_EN" "$GPIO_HIGH" 140set_gpio "stby_power_en_cpld" "$GPIO_HIGH" 141if ! wait_gpio_value "STBY_POWER_PG_3V3" "$GPIO_HIGH" 20 1; then 142 echo "Error: failed to get STBY_POWER_PG_3V3 as high (1) in 20 sec" 143 exit 1 144fi 145set_gpio "stby_power_gd_cpld" "$GPIO_HIGH" 146 147bind_i2c_muxes 148bind_gpio_expanders 149 150reset_host_usb 151 152set_gpio "HMC_PGOOD" "$GPIO_HIGH" 153set_gpio "EROT_FPGA_RST_L" "$GPIO_HIGH" 154set_gpio "SEC_EROT_FPGA_RST_L" "$GPIO_HIGH" 155set_gpio "HMC_EROT_RST_L" "$GPIO_HIGH" 156set_gpio "SCM_HPM_STBY_RST_N" "$GPIO_HIGH" 157 158if ! wait_gpio_value "HMC_READY" "$GPIO_HIGH" 180 1; then 159 echo "Error: failed to get HMC_READY as high (1) in 180 sec" 160 exit 1 161fi 162 163rebind_hmc_usb_network 164 165if ! wait_gpio_value "FPGA_READY_BMC" "$GPIO_HIGH" 180 1; then 166 echo "Error: failed to get FPGA_READY_BMC as high (1) in 180 sec" 167 exit 1 168fi 169 170bind_fru_eeproms 171set_bmc_ready 172 173exit 0 174