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 "host0-ready")" -eq 1 ]; then
9        echo "on"
10    else
11        echo "off"
12    fi
13}
14
15# DC off
16graceful_power_off() {
17    if [ "$(power_status)" == "on" ]; then
18        set_gpio power-host-control 0
19        sleep 1
20        set_gpio power-host-control 1
21        sleep 1
22
23        # wait host power off
24        sleep 10
25    fi
26}
27
28# DC off
29force_power_off() {
30    if [ "$(power_status)" == "on" ]; then
31        set_gpio power-host-control 0
32        sleep 6
33        set_gpio power-host-control 1
34        sleep 1
35    fi
36}
37
38# DC on
39power_on() {
40    if [ "$(power_status)" == "off" ]; then
41        set_gpio power-host-control 0
42        sleep 1
43        set_gpio power-host-control 1
44        sleep 1
45
46        for i in $(seq 1 10)
47        do
48            sleep 1
49            if [ "$(power_status)" == "on" ]; then
50               return 0
51            fi
52
53            if [ "$i" -eq 10 ]; then
54               return 1
55            fi
56        done
57    fi
58    return 0
59}
60