blob: 118fe6cc94793be8e1f46fd679f6c0e2e1cce246 [file] [log] [blame]
SpencerKu67f272f2020-03-24 16:18:14 +08001#!/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
6I2C_BUS=11
7CHIP_ADDR=0x15
8GPIO_ID=91 #Revision ID
9GPIO_BasePath=/sys/class/gpio
10
11function set_hotswap_reg()
12{
13 #set reg "0xd9" bit 3 to 1
14 i2cset -f -y $I2C_BUS $CHIP_ADDR 0xd9 0x08
15}
16
17function get_hotswap_value()
18{
19 #get the value of reg "0xd9", return value should be "0x08"
Patrick Williams8c226232023-04-15 20:05:21 -050020 i2cget -f -y $I2C_BUS $CHIP_ADDR 0xd9
SpencerKu67f272f2020-03-24 16:18:14 +080021}
22
23function 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
33function get_gpio_value()
34{
Patrick Williams8c226232023-04-15 20:05:21 -050035 cat $GPIO_BasePath/gpio$GPIO_ID/value
SpencerKu67f272f2020-03-24 16:18:14 +080036}
37
38function 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
60export_gpio
61gpio_value=$(get_gpio_value)
62if [ "$gpio_value" == "1" ];then
63 echo "gpio$GPIO_ID value is: $gpio_value, setting hotswap."
64 setting_hotswap
65else
66 echo "gpio$GPIO_ID value is: $gpio_value, no need to set hotswap."
Patrick Williams8c226232023-04-15 20:05:21 -050067fi