Delphine CC Chiu | bed8669 | 2023-02-22 13:17:37 +0800 | [diff] [blame] | 1 | #!/bin/bash -e |
| 2 | |
| 3 | # Provide source directive to shellcheck. |
| 4 | # shellcheck source=meta-facebook/recipes-phosphor/state/phosphor-state-manager/greatlakes/power-cmd |
| 5 | source /usr/libexec/phosphor-state-manager/power-cmd |
| 6 | |
| 7 | SLOT_ID="$1" |
| 8 | |
| 9 | function get_power_status() |
| 10 | { |
| 11 | POWER_OK_SLOT=$(( $1+9 )) |
| 12 | HOST_INSTANCE=$(( $1-1 << 2 )) |
| 13 | |
| 14 | chassis_status=$(gpioget 0 $POWER_OK_SLOT) |
| 15 | if [ "$chassis_status" == "$STATE_OFF" ]; then |
| 16 | echo "AC Off" |
| 17 | return 0 |
| 18 | fi |
| 19 | |
| 20 | response="$(busctl call "$SERVICE" "$OBJECT_PATH" "$INTERFACE" sendRequest yyyyay "$HOST_INSTANCE" 0x38 "$LUN" 0x03 "$IANA_LEN" "$IANA")" |
| 21 | # Responses are BIC gpio states, the GPIO B7 represents host DC status |
| 22 | result=$(echo "$response" | cut -d" " -f "$PWRGD_SYS_PWROK_INDEX") |
| 23 | res="$(( "$result" & 0x80 ))" |
| 24 | host_status="$(( "$res" >> 7 ))" |
| 25 | if [ "$host_status" == "$STATE_OFF" ]; then |
| 26 | echo "Host Off" |
| 27 | return 0 |
| 28 | fi |
| 29 | } |
| 30 | |
| 31 | set_host_state() |
| 32 | { |
| 33 | PROPERTY_VAL="xyz.openbmc_project.State.Host.HostState.$2" |
| 34 | busctl set-property "$HOST_BUS_NAME$1" "$HOST_OBJ_PATH$1" "$HOST_INTF_NAME" "$HOST_PROPERTY_NAME" s "$PROPERTY_VAL" |
| 35 | } |
| 36 | |
| 37 | set_chassis_state() |
| 38 | { |
| 39 | PROPERTY_VAL="xyz.openbmc_project.State.Chassis.PowerState.$2" |
| 40 | busctl set-property "$CHASSIS_BUS_NAME$1" "$CHASSIS_OBJ_PATH$1" "$CHASSIS_INTF_NAME" "$CHASSIS_PROPERTY_NAME" s "$PROPERTY_VAL" |
| 41 | } |
| 42 | |
| 43 | |
| 44 | POWER_STATUS=$(get_power_status "$SLOT_ID") |
| 45 | |
| 46 | # Default power status |
| 47 | CHASSIS_STATE_VAL="Off" |
| 48 | HOST_STATE_VAL="Off" |
| 49 | |
| 50 | # Real power status |
| 51 | if [ "$POWER_STATUS" != "AC Off" ]; then |
| 52 | CHASSIS_STATE_VAL="On" |
| 53 | if [ "$POWER_STATUS" != "Host Off" ]; then |
| 54 | HOST_STATE_VAL="Running" |
| 55 | fi |
| 56 | fi |
| 57 | |
| 58 | set_chassis_state "$SLOT_ID" "$CHASSIS_STATE_VAL" |
| 59 | set_host_state "$SLOT_ID" "$HOST_STATE_VAL" |