Add in support for detecting an output overcurrent fault

When analyzing the STATUS_WORD bits, check if the IOUT_OC_FAULT bit is
on. That bit indicates that an output overcurrent fault condition has
occurred. Call out the power supply reporting that.

Change-Id: I18c7cd981ffc1b73ab52c90d32ba34195013e65e
Signed-off-by: Brandon Wyman <bjwyman@gmail.com>
diff --git a/power-supply/power_supply.cpp b/power-supply/power_supply.cpp
index 467144b..cd7f87f 100644
--- a/power-supply/power_supply.cpp
+++ b/power-supply/power_supply.cpp
@@ -105,8 +105,6 @@
 
             if ((statusWord & status_word::VIN_UV_FAULT) && !vinUVFault)
             {
-                vinUVFault = true;
-
                 util::NamesValues nv;
                 nv.add("STATUS_WORD", statusWord);
 
@@ -161,6 +159,10 @@
 
             if (powerOn)
             {
+                std::uint8_t statusVout = 0;
+                std::uint8_t statusIout = 0;
+                std::uint8_t statusMFR  = 0;
+
                 // Check PG# and UNIT_IS_OFF
                 if (((statusWord & status_word::POWER_GOOD_NEGATED) ||
                      (statusWord & status_word::UNIT_IS_OFF)) &&
@@ -195,6 +197,33 @@
                     powerOnFault = true;
                 }
 
+                // Check for an output overcurrent fault.
+                if ((statusWord & status_word::IOUT_OC_FAULT) &&
+                    !outputOCFault)
+                {
+                    statusInput = pmbusIntf.read(STATUS_INPUT, Type::Debug);
+                    statusVout = pmbusIntf.read(STATUS_VOUT, Type::Debug);
+                    statusIout = pmbusIntf.read(STATUS_IOUT, Type::Debug);
+                    statusMFR = pmbusIntf.read(STATUS_MFR, Type::Debug);
+
+                    util::NamesValues nv;
+                    nv.add("STATUS_WORD", statusWord);
+                    nv.add("STATUS_INPUT", statusInput);
+                    nv.add("STATUS_VOUT", statusVout);
+                    nv.add("STATUS_IOUT", statusIout);
+                    nv.add("MFR_SPECIFIC", statusMFR);
+
+                    using metadata = xyz::openbmc_project::Power::Fault::
+                            PowerSupplyOutputOvercurrent;
+
+                    report<PowerSupplyOutputOvercurrent>(
+                            metadata::RAW_STATUS(nv.get().c_str()),
+                            metadata::CALLOUT_INVENTORY_PATH(
+                                    inventoryPath.c_str()));
+
+                    outputOCFault = true;
+                }
+
             }
         }
     }
@@ -229,6 +258,7 @@
             readFailLogged = false;
             vinUVFault = false;
             inputFault = false;
+            outputOCFault = false;
         }
     }
 
@@ -278,6 +308,7 @@
             vinUVFault = false;
             inputFault = false;
             powerOnFault = false;
+            outputOCFault = false;
             powerOnTimer.start(powerOnInterval, Timer::TimerType::oneshot);
         }
         else
diff --git a/power-supply/power_supply.hpp b/power-supply/power_supply.hpp
index e9bd9f3..d47ee3c 100644
--- a/power-supply/power_supply.hpp
+++ b/power-supply/power_supply.hpp
@@ -142,6 +142,14 @@
         bool inputFault = false;
 
         /**
+         * @brief Set to true when an output over current fault is detected
+         *
+         * This is the "IOUT_OC_FAULT" bit in the low byte from the STATUS_WORD
+         * command response.
+         */
+        bool outputOCFault = false;
+
+        /**
          * @brief Callback for inventory property changes
          *
          * Process change of Present property for power supply.