summaryrefslogtreecommitdiff
path: root/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/chassis-poweron
blob: f0c9c0dc3ea8c01bbbb30ee21e763511507dd708 (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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/bin/bash

# shellcheck disable=SC2120

# Provide source directive to shellcheck.
# shellcheck source=meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/power-cmd
source /usr/libexec/phosphor-state-manager/power-cmd
# shellcheck source=meta-facebook/meta-yosemite4/recipes-yosemite4/plat-tool/files/yosemite4-common-functions
source /usr/libexec/yosemite4-common-functions

GPIOCHIP_IO_EXP_SLOT_PWR_CTRL=$(basename "/sys/bus/i2c/devices/$SPIDER_BOARD_IO_EXP_BUS_NUM-00$IO_EXP_SLOT_PWR_CTRL_ADDR/"*gpiochip*)
GPIOCHIP_IO_EXP_SLOT_12V_STATUS_CTRL=$(basename "/sys/bus/i2c/devices/$MANAGEMENT_BOARD_IO_EXP_BUS_NUM-00$IO_EXP_SLED_PWR_CTRL_ADDR/"*gpiochip*)

#IO 0:7 input port for showing slot 1:8 power status
#IO 8:16 output port for controlling slot 1:8 power status
CHASSIS_ID=$1
IO_EXP_SLOT_PWR_STATUS=$((CHASSIS_ID - 1))
IO_EXP_SLOT_PWR_CTRL=$((IO_EXP_SLOT_PWR_STATUS + 8))
IO_EXP_SLOT_12V_STATUS=$((CHASSIS_ID + 23))

is_nuvoton_board="$(check_nuvoton_board)"

enable_i3c_hub()
{
    local target_slot="$CHASSIS_ID"
    local hub_path
    local offset_file
    local access_file
    local current_port
    local mask=1

    echo "Do 12V on enable i3c-hub"
    sleep 1
    if [ "$target_slot" -lt 5 ]; then
        hub_path="/sys/kernel/debug/i3c-hub-0-*/reg"
        echo "Slot${target_slot} on i3c hub 0."
    else
        hub_path="/sys/kernel/debug/i3c-hub-1-*/reg"
        echo "Slot${target_slot} on i3c hub 1."
    fi

    for file in $hub_path/{offset,access}; do
        if [[ $file == *"/offset" ]]; then
            offset_file="$file"
        elif [[ $file == *"/access" ]]; then
            access_file="$file"
        fi
    done

    echo "Unlock i3c hub register."
    echo 16 > "$offset_file"
    echo 105 > "$access_file"

    echo "Enable slot${target_slot} i3c port."
    echo 18 > "$offset_file"
    current_port=$(cat "$access_file")
    if [ "$target_slot" -gt 4 ]; then
        ((target_slot=target_slot-4))
    fi
    mask=$((mask << (--target_slot)))
    current_port=$((current_port | mask))
    echo $current_port > "$access_file"
    cat "$access_file"

    echo "Lock i3c hub register."
    echo 16 > "$offset_file"
    echo 0 > "$access_file"
}

# Server 12v power on
chassis-power-on()
{
    if ! gpio_set "$GPIOCHIP_IO_EXP_SLOT_PWR_CTRL" "$IO_EXP_SLOT_PWR_CTRL"=0
    then
        msg="Failed to set slot$1 power on"
        echo "${msg}"
        add_sel "${msg}"
    fi
    sleep 1

    # Check chassis status after doing 12V on
    chassis_status=$(get_ac_on_status "$GPIOCHIP_IO_EXP_SLOT_PWR_CTRL" "$IO_EXP_SLOT_PWR_STATUS")
    if [ "$chassis_status" == "$STATE_ON" ]
    then
        if [ -n "$is_nuvoton_board" ]
        then
            # inform management CPLD that the slot is 12V on
            if ! gpio_set "$GPIOCHIP_IO_EXP_SLOT_12V_STATUS_CTRL" "$IO_EXP_SLOT_12V_STATUS"=1
            then
                echo "Failed to inform management CPLD that slot$1 is 12V on"
            fi
        fi
        enable_i3c_hub

        # Wait for standby sensors to be ready
        sleep 2
        busctl set-property "$CHASSIS_BUS_NAME""$CHASSIS_ID" "$CHASSIS_OBJ_PATH""$CHASSIS_ID" "$CHASSIS_INTF_NAME" "$CHASSIS_PROPERTY_NAME" s "$CHASSIS_ON_PROPERTY"
        echo "Chassis$CHASSIS_ID is power on"
    else
        busctl set-property "$CHASSIS_BUS_NAME""$CHASSIS_ID" "$CHASSIS_OBJ_PATH""$CHASSIS_ID" "$CHASSIS_INTF_NAME" "$CHASSIS_PROPERTY_NAME" s "$CHASSIS_OFF_PROPERTY"
        msg="Failed to power on Chassis$CHASSIS_ID, Chassis$CHASSIS_ID is power off"
        echo "${msg}"
        add_sel "${msg}"
        exit 0;
    fi
}

if ! chassis_status=$(gpio_get "$GPIOCHIP_IO_EXP_SLOT_PWR_CTRL" "$IO_EXP_SLOT_PWR_STATUS"); then
    echo "Failed to get chassis status"
    exit 1
fi

if [ "$chassis_status" == "$STATE_OFF" ]
then
    chassis-power-on
    /usr/libexec/phosphor-state-manager/wait-until-mctp-connection-done "$CHASSIS_ID" && systemctl restart "phosphor-discover-system-state@$CHASSIS_ID.service"
    exit 0;
else
    echo "Chassis$1 is already on"
    exit 0;
fi