diff options
author | jmbills <jason.m.bills@intel.com> | 2021-10-04 22:42:48 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-04 22:42:48 +0300 |
commit | 0c9e31989c615598b5d042ffab385606660c93c0 (patch) | |
tree | 8019999b0ca042482e5193d6cabc06220c71d776 /meta-google/recipes-google/host-power-ctrl/gpio-host-pwr/host_poweron.sh | |
parent | 04cd92067d2481643df5010cb39b2134b648cf4d (diff) | |
parent | ffe6d597d9e3d4407cf8062b5d6505a80ce08f41 (diff) | |
download | openbmc-0c9e31989c615598b5d042ffab385606660c93c0.tar.xz |
Update
Diffstat (limited to 'meta-google/recipes-google/host-power-ctrl/gpio-host-pwr/host_poweron.sh')
-rwxr-xr-x | meta-google/recipes-google/host-power-ctrl/gpio-host-pwr/host_poweron.sh | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/meta-google/recipes-google/host-power-ctrl/gpio-host-pwr/host_poweron.sh b/meta-google/recipes-google/host-power-ctrl/gpio-host-pwr/host_poweron.sh new file mode 100755 index 000000000..2e6eb0217 --- /dev/null +++ b/meta-google/recipes-google/host-power-ctrl/gpio-host-pwr/host_poweron.sh @@ -0,0 +1,65 @@ +#!/bin/bash +# Copyright 2021 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +source /usr/share/gpio-host-pwr/lib.sh || exit + +gpio_build_cache 10 "$HOST_GPIO_PGOOD" "$HOST_GPIO_PWR_BTN" || exit +gpio_init "$HOST_GPIO_PGOOD" || exit + +# Set the power status LED +if [ -n "$HOST_LED_PWR" ]; then + echo 'none' > /sys/class/leds/"$HOST_LED_PWR"/trigger || true + echo '255' > /sys/class/leds/"$HOST_LED_PWR"/brightness || true +fi + +# Ensure the watchdog is available before the host starts +host_pwr_start_watchdog || true + +# We don't want to do anything if the machine is already on +pgood="$(gpio_get_value "$HOST_GPIO_PGOOD")" || exit +if (( pgood == 1 )); then + echo 'Host is already running, doing nothing' >&2 + exit 0 +fi + +# Do a quick push of the button if PGOOD +echo "Starting host power" >&2 +rc=0 +gpio_set_value "$HOST_GPIO_PWR_BTN" 1 || rc=$? +sleep 0.1 +gpio_set_value "$HOST_GPIO_PWR_BTN" 0 || rc=$? + +# Loop until we realize that host power is on +# Limit the loop count to 10 seconds as we should never +# have to wait this long for poweroff +s=$SECONDS +while true; do + if ! pgood="$(gpio_get_value "$HOST_GPIO_PGOOD")"; then + rc=1 + break + fi + if (( pgood == 1 )); then + echo 'Host is now on' >&2 + break + fi + if (( SECONDS - s > 10 )); then + echo 'Poweron timed out, terminating' >&2 + rc=2 + break + fi + sleep 0.1 +done + +exit $rc |