Lancelot Kao | 96a7ee3 | 2021-02-22 18:50:48 -0600 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
Charles Boyer | af72171 | 2022-02-09 09:17:35 -0600 | [diff] [blame] | 3 | # Disable check for usage of the definitions within kudo-lib.sh |
| 4 | # shellcheck disable=SC2034 |
| 5 | |
Charles Boyer | d7d3423 | 2022-02-09 08:32:22 -0600 | [diff] [blame] | 6 | # get_gpio_num |
| 7 | # Dynamically obtains GPIO number from chip base and I2C expanders through line name |
| 8 | # line-name |
| 9 | function get_gpio_num() { |
| 10 | #shellcheck disable=SC2207 |
| 11 | CHIP_PIN=($(gpiofind "$1" | awk '{print substr ($1, 9 ), $2 }')) |
| 12 | #shellcheck disable=SC2128 |
| 13 | if [ -z "$CHIP_PIN" ]; then |
| 14 | echo "Could not find GPIO with name: $1" |
| 15 | return 1 |
| 16 | fi |
| 17 | |
| 18 | if [ "${CHIP_PIN[0]}" -gt 7 ]; then |
| 19 | BUS_ADDR=$(gpiodetect | grep gpiochip"${CHIP_PIN[0]}" | awk '{print substr($2, 2, length($2) - 2)}') |
| 20 | GPIO_BASE=$(cat /sys/bus/i2c/devices/"$BUS_ADDR"/gpio/*/base) |
| 21 | echo "$((GPIO_BASE+CHIP_PIN[1]))" |
| 22 | else |
| 23 | echo "$((CHIP_PIN[0]*32+CHIP_PIN[1]))" |
| 24 | fi |
| 25 | } |
| 26 | |
Lancelot Kao | 96a7ee3 | 2021-02-22 18:50:48 -0600 | [diff] [blame] | 27 | # set_gpio_ctrl |
Charles Boyer | d7d3423 | 2022-02-09 08:32:22 -0600 | [diff] [blame] | 28 | # line-name, high(1)/low(0) |
Lancelot Kao | 96a7ee3 | 2021-02-22 18:50:48 -0600 | [diff] [blame] | 29 | function set_gpio_ctrl() { |
Charles Boyer | d7d3423 | 2022-02-09 08:32:22 -0600 | [diff] [blame] | 30 | #shellcheck disable=SC2046 |
| 31 | gpioset $(gpiofind "$1")="$2" |
Lancelot Kao | 96a7ee3 | 2021-02-22 18:50:48 -0600 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | # get_gpio_ctrl |
Charles Boyer | d7d3423 | 2022-02-09 08:32:22 -0600 | [diff] [blame] | 35 | # line-name |
Lancelot Kao | 96a7ee3 | 2021-02-22 18:50:48 -0600 | [diff] [blame] | 36 | function get_gpio_ctrl() { |
Charles Boyer | d7d3423 | 2022-02-09 08:32:22 -0600 | [diff] [blame] | 37 | GPIO_NUM=$(get_gpio_num "$1") |
| 38 | echo "$GPIO_NUM" > /sys/class/gpio/export |
| 39 | cat /sys/class/gpio/gpio"$GPIO_NUM"/value |
| 40 | echo "$GPIO_NUM" > /sys/class/gpio/unexport |
Lancelot Kao | 96a7ee3 | 2021-02-22 18:50:48 -0600 | [diff] [blame] | 41 | } |
Charles Boyer | af72171 | 2022-02-09 09:17:35 -0600 | [diff] [blame] | 42 | |
Karthikeyan Sundaram | 0759c75 | 2021-11-24 14:33:55 -0600 | [diff] [blame] | 43 | function get_scp_eeprom() { |
Charles Boyer | 878175f | 2022-07-27 15:35:02 -0500 | [diff] [blame] | 44 | scp_eeprom_sel=$(get_gpio_ctrl BACKUP_SCP_SEL) |
Karthikeyan Sundaram | 0759c75 | 2021-11-24 14:33:55 -0600 | [diff] [blame] | 45 | case $scp_eeprom_sel in |
| 46 | 0) |
| 47 | echo " Using Secondary SCP EEPROM" |
| 48 | ;; |
| 49 | 1) |
| 50 | echo " Using Primary SCP EEPROM" |
| 51 | ;; |
| 52 | esac |
| 53 | } |
| 54 | |
Charles Boyer | af72171 | 2022-02-09 09:17:35 -0600 | [diff] [blame] | 55 | # I2C Definitions |
| 56 | # The array is (<bus> <address>), where address is in hexadecimal. |
| 57 | I2C_BMC_CPLD=(13 76) |
| 58 | I2C_MB_CPLD=(34 76) |
| 59 | I2C_S0_SMPRO=(2 4f) |
| 60 | I2C_S1_SMPRO=(2 4e) |
| 61 | I2C_FANCTRL=(18 2c) |
| 62 | I2C_BMC_PWRSEQ=(14 59) |
| 63 | I2C_MB_PWRSEQ1=(32 40) |
| 64 | I2C_MB_PWRSEQ2=(32 41) |
| 65 | I2C_CPU_EEPROM=(40 50) |
| 66 | I2C_S1_CLKGEN=(37 68) |
| 67 | I2C_S1_PCIE_CLKGEN1=(16 6a) |
| 68 | I2C_S1_PCIE_CLKGEN2=(17 67) |
Charles Boyer | 5db75b8 | 2022-02-09 09:30:36 -0600 | [diff] [blame] | 69 | |
| 70 | # Board Version Definitions |
| 71 | BOARDVER_EVT_LAST=64 |
| 72 | BOARDVER_DVT_LAST=127 |
Charles Boyer | 878175f | 2022-07-27 15:35:02 -0500 | [diff] [blame] | 73 | BOARDVER_PVT_LAST=191 |