1#!/bin/bash
2
3# shellcheck source=meta-facebook/recipes-fb/obmc_functions/files/fb-common-functions
4source /usr/libexec/fb-common-functions
5
6# Power Good Status
7power_status() {
8    if [ "$(get_gpio "power-cpu-good")" -eq 1 ]; then
9        echo "on"
10    else
11        echo "off"
12    fi
13}
14
15# DC off
16power_off() {
17    if [ "$(power_status)" == "on" ]; then
18        echo "Set Host Power Off"
19        set_gpio power-host-control 0
20        sleep 6
21        set_gpio power-host-control 1
22        sleep 1
23    fi
24}
25
26# DC on
27power_on() {
28    if [ "$(power_status)" == "off" ]; then
29        set_gpio power-host-control 0
30        sleep 1
31        set_gpio power-host-control 1
32        sleep 1
33
34        for i in $(seq 1 10)
35        do
36            sleep 1
37            if [ "$(power_status)" == "on" ]; then
38
39               echo "Set Host Power On"
40               return 0
41            fi
42
43            if [ "$i" -eq 10 ]; then
44               echo "Set Host Power On Fail"
45               return 1
46            fi
47        done
48    fi
49    return 0
50}
51
52# Host reset
53power_reset() {
54    echo "Set Host Reset"
55    set_gpio reset-control 0
56    sleep 1
57    set_gpio reset-control 1
58    sleep 1
59}
60