psu-ng: Change detection of brownout errors

Brownout errors can occur such that the power supplies are able to
recover but the chassis power good is lost and the system powers down.
In these cases the power supply application should continue to process
the brownout condition so that the brownout error is logged and the auto
power restart happens correctly. Use the power state and the chassis
pgood properties from the power control service to allow this to happen.

The power supply driver or device may not latch the AC fault. Set an
expiring indication that the AC fault occurred.

A power supply may not indicate the loss of AC and may only indicate the
loss of power good. As long as at least one power supply indicates the
AC loss, tolerate the pgood failure indications.

The net of the changes is that a brownout error will be issued when the
chassis power good is lost, and all present power supplies indicate an
AC failure or a power good failure, and at least one power supply
indicates an AC failure.

Signed-off-by: Jim Wright <jlwright@us.ibm.com>
Change-Id: I5a11746a036d0a66b11c76ec12784b8870fa306f
diff --git a/phosphor-power-supply/power_supply.hpp b/phosphor-power-supply/power_supply.hpp
index ec58bf3..2c61f13 100644
--- a/phosphor-power-supply/power_supply.hpp
+++ b/phosphor-power-supply/power_supply.hpp
@@ -45,6 +45,9 @@
 constexpr auto LOG_LIMIT = 3;
 constexpr auto DEGLITCH_LIMIT = 3;
 constexpr auto PGOOD_DEGLITCH_LIMIT = 5;
+// Number of polls to remember that an AC fault occured. Should remain greater
+// than PGOOD_DEGLITCH_LIMIT.
+constexpr auto AC_FAULT_LIMIT = 6;
 
 /**
  * @class PowerSupply
@@ -380,6 +383,15 @@
     }
 
     /**
+     * @brief Returns true if an AC fault has occurred in the window of
+     * interest.
+     */
+    bool hasACFault() const
+    {
+        return acFault != 0;
+    }
+
+    /**
      * @brief Returns the device path
      *
      * This can be used for error call outs.
@@ -685,6 +697,13 @@
     size_t psCS12VFault = 0;
 
     /**
+     * @brief Set to AC_FAULT_LIMIT when AC fault is detected, decremented when
+     * AC fault has cleared. Effectively forms a timer since last AC failure.
+     * Zero indicates being outside the window of concern.
+     */
+    size_t acFault = 0;
+
+    /**
      * @brief Count of the number of read failures.
      */
     size_t readFail = 0;