SpencerKu | 83d0a87 | 2020-03-24 16:18:14 +0800 | [diff] [blame^] | 1 | #!/bin/bash |
| 2 | |
| 3 | # Purpose: |
| 4 | # The purpose of the script is to change the CB/CL ratio setting of the hotswap controller from 1.9x to 3.9x |
| 5 | |
| 6 | I2C_BUS=11 |
| 7 | CHIP_ADDR=0x15 |
| 8 | GPIO_ID=91 #Revision ID |
| 9 | GPIO_BasePath=/sys/class/gpio |
| 10 | |
| 11 | function set_hotswap_reg() |
| 12 | { |
| 13 | #set reg "0xd9" bit 3 to 1 |
| 14 | i2cset -f -y $I2C_BUS $CHIP_ADDR 0xd9 0x08 |
| 15 | } |
| 16 | |
| 17 | function get_hotswap_value() |
| 18 | { |
| 19 | #get the value of reg "0xd9", return value should be "0x08" |
| 20 | echo "$(i2cget -f -y $I2C_BUS $CHIP_ADDR 0xd9)" |
| 21 | } |
| 22 | |
| 23 | function export_gpio() |
| 24 | { |
| 25 | if [ -d "$GPIO_BasePath/gpio$GPIO_ID" ]; then |
| 26 | echo "gpio$GPIO_ID folder exist, skip export." |
| 27 | else |
| 28 | echo "Export gpio$GPIO_ID..." |
| 29 | echo $GPIO_ID > $GPIO_BasePath/export |
| 30 | fi |
| 31 | } |
| 32 | |
| 33 | function get_gpio_value() |
| 34 | { |
| 35 | echo "$(cat $GPIO_BasePath/gpio$GPIO_ID/value)" |
| 36 | } |
| 37 | |
| 38 | function setting_hotswap() |
| 39 | { |
| 40 | echo "setting hotswap controller..." |
| 41 | set_hotswap_reg |
| 42 | |
| 43 | for i in {0..3}; |
| 44 | do |
| 45 | if [ "$i" == "3" ];then |
| 46 | echo "change hotswap controller setting failed after retry 3 times." |
| 47 | else |
| 48 | hotswap_value=$(get_hotswap_value) |
| 49 | echo "get hotswap controller return value : $hotswap_value" |
| 50 | if [ "$hotswap_value" == "0x08" ];then |
| 51 | echo "change hotswap controller setting success." |
| 52 | break; |
| 53 | else |
| 54 | echo "hotswap controller setting failed, retry $i times..." |
| 55 | fi |
| 56 | fi |
| 57 | done |
| 58 | } |
| 59 | |
| 60 | export_gpio |
| 61 | gpio_value=$(get_gpio_value) |
| 62 | if [ "$gpio_value" == "1" ];then |
| 63 | echo "gpio$GPIO_ID value is: $gpio_value, setting hotswap." |
| 64 | setting_hotswap |
| 65 | else |
| 66 | echo "gpio$GPIO_ID value is: $gpio_value, no need to set hotswap." |
| 67 | fi |