blob: 9cee5f4406927af98f0c61a6f19b6762b9b489fd [file] [log] [blame]
Lancelot Kao96a7ee32021-02-22 18:50:48 -06001#!/bin/bash
2
Charles Boyeraf721712022-02-09 09:17:35 -06003# Disable check for usage of the definitions within kudo-lib.sh
4# shellcheck disable=SC2034
5
Charles Boyerd7d34232022-02-09 08:32:22 -06006# get_gpio_num
7# Dynamically obtains GPIO number from chip base and I2C expanders through line name
8# line-name
9function 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 Kao96a7ee32021-02-22 18:50:48 -060027# set_gpio_ctrl
Charles Boyerd7d34232022-02-09 08:32:22 -060028# line-name, high(1)/low(0)
Lancelot Kao96a7ee32021-02-22 18:50:48 -060029function set_gpio_ctrl() {
Charles Boyerd7d34232022-02-09 08:32:22 -060030 #shellcheck disable=SC2046
31 gpioset $(gpiofind "$1")="$2"
Lancelot Kao96a7ee32021-02-22 18:50:48 -060032}
33
34# get_gpio_ctrl
Charles Boyerd7d34232022-02-09 08:32:22 -060035# line-name
Lancelot Kao96a7ee32021-02-22 18:50:48 -060036function get_gpio_ctrl() {
Charles Boyerd7d34232022-02-09 08:32:22 -060037 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 Kao96a7ee32021-02-22 18:50:48 -060041}
Charles Boyeraf721712022-02-09 09:17:35 -060042
43# I2C Definitions
44# The array is (<bus> <address>), where address is in hexadecimal.
45I2C_BMC_CPLD=(13 76)
46I2C_MB_CPLD=(34 76)
47I2C_S0_SMPRO=(2 4f)
48I2C_S1_SMPRO=(2 4e)
49I2C_FANCTRL=(18 2c)
50I2C_BMC_PWRSEQ=(14 59)
51I2C_MB_PWRSEQ1=(32 40)
52I2C_MB_PWRSEQ2=(32 41)
53I2C_CPU_EEPROM=(40 50)
54I2C_S1_CLKGEN=(37 68)
55I2C_S1_PCIE_CLKGEN1=(16 6a)
56I2C_S1_PCIE_CLKGEN2=(17 67)
Charles Boyer5db75b82022-02-09 09:30:36 -060057
58# Board Version Definitions
59BOARDVER_EVT_LAST=64
60BOARDVER_DVT_LAST=127