summaryrefslogtreecommitdiff
path: root/meta-quanta/meta-gsj/recipes-gsj/gsj-hotswap-change-setting/files/gsj-hotswap-change-setting.sh
blob: bed745dda31f4f6615292b1b157e13ed6215afbe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/bash

# Purpose:
#     The purpose of the script is to change the CB/CL ratio setting of the hotswap controller from 1.9x to 3.9x

I2C_BUS=11
CHIP_ADDR=0x15
GPIO_ID=91   #Revision ID
GPIO_BasePath=/sys/class/gpio

function set_hotswap_reg()
{
    #set reg "0xd9" bit 3 to 1
    i2cset -f -y $I2C_BUS $CHIP_ADDR 0xd9 0x08
}

function get_hotswap_value()
{
    #get the value of reg "0xd9", return value should be "0x08"
    echo "$(i2cget -f -y $I2C_BUS $CHIP_ADDR 0xd9)"
}

function export_gpio()
{
    if [ -d "$GPIO_BasePath/gpio$GPIO_ID" ]; then
        echo "gpio$GPIO_ID folder exist, skip export."
    else
        echo "Export gpio$GPIO_ID..."
        echo $GPIO_ID > $GPIO_BasePath/export
    fi
}

function get_gpio_value()
{
    echo "$(cat $GPIO_BasePath/gpio$GPIO_ID/value)"
}

function setting_hotswap()
{
    echo "setting hotswap controller..."
    set_hotswap_reg

    for i in {0..3};
    do
        if [ "$i" == "3" ];then
            echo "change hotswap controller setting failed after retry 3 times."
        else
            hotswap_value=$(get_hotswap_value)
            echo "get hotswap controller return value : $hotswap_value"
            if [ "$hotswap_value" == "0x08" ];then
                echo "change hotswap controller setting success."
                break;
            else
                echo "hotswap controller setting failed, retry $i times..."
            fi
        fi
    done
}

export_gpio
gpio_value=$(get_gpio_value)
if [ "$gpio_value" == "1" ];then
    echo "gpio$GPIO_ID value is: $gpio_value, setting hotswap."
    setting_hotswap
else
    echo "gpio$GPIO_ID value is: $gpio_value, no need to set hotswap."
fi