1#!/bin/bash
2
3# Find the GPIO pin associated with "pch-ready"
4GPIO_PIN=$(gpiofind "pch-ready")
5
6if [ -z "${GPIO_PIN}" ]; then
7    echo "gpio 'pch-ready' not found in device tree. Exiting."
8    exit 0
9fi
10
11# Extract gpiochip and line offset from the GPIO_PIN
12GPIO_CHIP=$(echo "$GPIO_PIN" | cut -d' ' -f1)  # Extract gpiochip
13GPIO_LINE=$(echo "$GPIO_PIN" | cut -d' ' -f2)  # Extract line offset
14
15# Poll the GPIO value until it reads 1 (indicating power sequence completion)
16while true; do
17    GPIO_VALUE=$(gpioget "$GPIO_CHIP" "$GPIO_LINE")
18
19    if [ "$GPIO_VALUE" -eq 0 ]; then
20        echo "PCH Standby Power Sequence Complete"
21        exit 0
22    else
23        echo "Waiting for PCH Standby Power Sequence..."
24        sleep 5
25    fi
26done
27