xref: /openbmc/openbmc/meta-facebook/meta-harma/recipes-phosphor/gpio/phosphor-gpio-monitor/auto-power (revision 2d3c44e1e6f08d211b0c3820ebd4081fd7bd51e0)
1#!/bin/bash
2
3check-auto-power-condition() {
4    # Define the fixed prefix of the FRU path
5    FRU_PREFIX="/xyz/openbmc_project/FruDevice/Minerva_PDB"
6
7    # Dynamically search for a matching path that starts with the prefix
8    FRU_PATH=$(busctl tree xyz.openbmc_project.FruDevice | grep "$FRU_PREFIX" | awk '{print $2}')
9
10    # Retrieve the BOARD_FRU_VERSION_ID property value for the matched path
11    if [ -n "$FRU_PATH" ]; then
12        FRU_VERSION=$(busctl get-property xyz.openbmc_project.FruDevice "$FRU_PATH" xyz.openbmc_project.FruDevice BOARD_FRU_VERSION_ID | sed -n 's/.*FRU Ver //p')
13    else
14        FRU_VERSION=""
15    fi
16
17    # Simple version comparison without bc
18    if [ -n "$FRU_VERSION" ]; then
19        FRU_VERSION_INT=$(echo "$FRU_VERSION" | awk -F. '{printf "%d%02d\n", $1, $2}')
20    else
21        FRU_VERSION_INT=""
22    fi
23
24    THRESHOLD_INT=$(echo "0.02" | awk -F. '{printf "%d%02d\n", $1, $2}')
25
26    MESSAGE=$1
27    number="${MESSAGE%%_*}"
28
29    echo "FRU_PATH: $FRU_PATH, FRU_VERSION: $FRU_VERSION, FRU_VERSION_INT: $FRU_VERSION_INT, number: $number"
30    # This is a workaround for DVT1 to avoid SGPIO bouncing during CPLD power recovery.
31    # In DVT1, auto power on/off is triggered by direct GPIO21 (GPIOC6), but this pin cannot change in DVT2
32    # because the standby power will not be lost.
33
34    # If the version and number conditions are met and the file exists
35    if [ -n "$FRU_VERSION_INT" ] && [ "$FRU_VERSION_INT" -le "$THRESHOLD_INT" ] && [ "$number" -eq 2 ]; then
36        return 1
37    fi
38
39    return 0
40}
41