blob: ec9723f26711e26de87f712840e9c3e35f480b22 [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
William A. Kennington IIIc17e6442023-06-02 16:29:54 -070020# shellcheck source=meta-google/recipes-google/gpio/gpio-ctrl/lib.sh
Tom Tung48ea66b2021-08-06 14:19:14 +080021source /usr/share/gpio-ctrl/lib.sh || exit
22
23# Read by the tooling to determine if the machine is powered on or off
William A. Kennington IIIc17e6442023-06-02 16:29:54 -070024# shellcheck disable=SC2034
Tom Tung48ea66b2021-08-06 14:19:14 +080025HOST_GPIO_PGOOD='unset'
26# Set according to whether the host is powered on or off
William A. Kennington IIIc17e6442023-06-02 16:29:54 -070027# shellcheck disable=SC2034
Tom Tung48ea66b2021-08-06 14:19:14 +080028HOST_LED_PWR=''
29# Written by the tooling to assert the power button
William A. Kennington IIIc17e6442023-06-02 16:29:54 -070030# shellcheck disable=SC2034
Tom Tung48ea66b2021-08-06 14:19:14 +080031HOST_GPIO_PWR_BTN='unset'
32# Written by the tooling to assert a cold reset
William A. Kennington IIIc17e6442023-06-02 16:29:54 -070033# shellcheck disable=SC2034
Tom Tung48ea66b2021-08-06 14:19:14 +080034HOST_GPIO_COLD_RESET='unset'
35# Written by the tooling to assert a warm reset
William A. Kennington IIIc17e6442023-06-02 16:29:54 -070036# shellcheck disable=SC2034
Tom Tung48ea66b2021-08-06 14:19:14 +080037HOST_GPIO_WARM_RESET='unset'
38
39# Load configurations from a known location in the filesystem to populate
40# named GPIOs
41shopt -s nullglob
42for conf in /usr/share/gpio-host-pwr/conf.d/*.sh; do
William A. Kennington IIIc17e6442023-06-02 16:29:54 -070043 # shellcheck source=/dev/null
Tom Tung48ea66b2021-08-06 14:19:14 +080044 source "$conf"
45done
46
47##################################################
48# Stop the host watchdog
49# Return:
50# 0 if success, non-zero if error
51##################################################
52host_pwr_stop_watchdog() {
53 # Check to see if we can stop the watchdog safely
54 # We don't want to stop if we are called from the watchdog itself
55 if [ -n "${DONT_STOP_WATCHDOG-}" ]; then
56 return 0
57 fi
58
59 echo 'Stopping the host watchdog' >&2
60 systemctl stop phosphor-watchdog@host0
61}
62
63##################################################
64# Start the host watchdog
65# Return:
66# 0 if success, non-zero if error
67##################################################
68host_pwr_start_watchdog() {
69 echo 'Starting the host watchdog' >&2
70 systemctl start phosphor-watchdog@host0
71}
72
73host_pwr_init=1