blob: 16b36a58b98940fd1363de5e52fdfc0a7a84efb2 [file] [log] [blame]
Tom Tung48ea66b2021-08-06 14:19:14 +08001#!/bin/bash
2# Copyright 2021 Google LLC
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16# This is intended to be used as a library for managing gpio line values.
17# Executing this directly will do nothing.
18[ -n "${host_pwr_init-}" ] && return
19
20source /usr/share/gpio-ctrl/lib.sh || exit
21
22# Read by the tooling to determine if the machine is powered on or off
23HOST_GPIO_PGOOD='unset'
24# Set according to whether the host is powered on or off
25HOST_LED_PWR=''
26# Written by the tooling to assert the power button
27HOST_GPIO_PWR_BTN='unset'
28# Written by the tooling to assert a cold reset
29HOST_GPIO_COLD_RESET='unset'
30# Written by the tooling to assert a warm reset
31HOST_GPIO_WARM_RESET='unset'
32
33# Load configurations from a known location in the filesystem to populate
34# named GPIOs
35shopt -s nullglob
36for conf in /usr/share/gpio-host-pwr/conf.d/*.sh; do
37 source "$conf"
38done
39
40##################################################
41# Stop the host watchdog
42# Return:
43# 0 if success, non-zero if error
44##################################################
45host_pwr_stop_watchdog() {
46 # Check to see if we can stop the watchdog safely
47 # We don't want to stop if we are called from the watchdog itself
48 if [ -n "${DONT_STOP_WATCHDOG-}" ]; then
49 return 0
50 fi
51
52 echo 'Stopping the host watchdog' >&2
53 systemctl stop phosphor-watchdog@host0
54}
55
56##################################################
57# Start the host watchdog
58# Return:
59# 0 if success, non-zero if error
60##################################################
61host_pwr_start_watchdog() {
62 echo 'Starting the host watchdog' >&2
63 systemctl start phosphor-watchdog@host0
64}
65
66host_pwr_init=1
67return 0 2>/dev/null
68echo "gpio-host-pwr is a library, not executed directly" >&2
69exit 1