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 ] && [ "$(get_gpio "power-card-enable")" -eq 0 ] ; 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 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 61# Host reset 62power_reset() { 63 set_gpio reset-control 0 64 sleep 1 65 set_gpio reset-control 1 66 sleep 1 67 return 0 68} 69