Grant Williams | a8c0af0 | 2022-04-29 12:03:41 -0500 | [diff] [blame^] | 1 | #!/bin/bash |
| 2 | |
| 3 | # Disable check for usage of the definitions within mori-lib.sh |
| 4 | #shellcheck disable=SC2034 |
| 5 | |
| 6 | # get_gpio_num |
| 7 | # Dynamically obtains GPIO number from chip base and I2C expanders |
| 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 | |
| 27 | # set_gpio_ctrl |
| 28 | # line-name, high(1)/low(0) |
| 29 | function set_gpio_ctrl() { |
| 30 | #shellcheck disable=SC2046 |
| 31 | gpioset $(gpiofind "$1")="$2" |
| 32 | } |
| 33 | |
| 34 | # get_gpio_ctrl |
| 35 | # line-name |
| 36 | function get_gpio_ctrl() { |
| 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 |
| 41 | } |
| 42 | |
| 43 | # Start definitions |
| 44 | |
| 45 | # I2C Definitions |
| 46 | # The array is (<bus> <address>), where address is in hexadecimal. |
| 47 | I2C_BMC_CPLD=(13 76) |
| 48 | I2C_MB_CPLD=(0 76) |
| 49 | I2C_FANCTRL=(35 2c) |
| 50 | I2C_BMC_PWRSEQ=(48 59) |
| 51 | I2C_MB_PWRSEQ=(40 40) |
| 52 | I2C_CPU_EEPROM=(19 50) |