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