Update analyze function to check STATUS_WORD

The STATUS_WORD PMBus command response will be the start of the power
supply fault analysis. Update the analyze() function to read its value
and process (select) fault bits.

Signed-off-by: Brandon Wyman <bjwyman@gmail.com>
Change-Id: If7274ad237c0604a56008676ae64804a5fd2854e
diff --git a/phosphor-power-supply/power_supply.cpp b/phosphor-power-supply/power_supply.cpp
index a6be9f5..7e617a9 100644
--- a/phosphor-power-supply/power_supply.cpp
+++ b/phosphor-power-supply/power_supply.cpp
@@ -1,24 +1,21 @@
 #include "power_supply.hpp"
 
 #include "types.hpp"
-#include "utility.hpp"
+#include "util.hpp"
 
-namespace phosphor
-{
-namespace power
-{
-namespace psu
+#include <xyz/openbmc_project/Common/Device/error.hpp>
+
+namespace phosphor::power::psu
 {
 
 using namespace phosphor::logging;
+using namespace sdbusplus::xyz::openbmc_project::Common::Device::Error;
 
 void PowerSupply::updatePresence()
 {
     try
     {
-        // Use getProperty utility function to get presence status.
-        util::getProperty(INVENTORY_IFACE, PRESENT_PROP, inventoryPath,
-                          INVENTORY_MGR_IFACE, bus, this->present);
+        present = getPresence(bus, inventoryPath);
     }
     catch (const sdbusplus::exception::SdBusError& e)
     {
@@ -28,6 +25,74 @@
     }
 }
 
+void PowerSupply::analyze()
+{
+    using namespace phosphor::pmbus;
+
+    if (present)
+    {
+        try
+        {
+            auto statusWord{pmbusIntf->read(STATUS_WORD, Type::Debug)};
+
+            if (statusWord)
+            {
+                if (statusWord & status_word::INPUT_FAULT_WARN)
+                {
+                    if (!inputFault)
+                    {
+                        log<level::INFO>(
+                            "INPUT fault",
+                            entry("STATUS_WORD=0x%04X",
+                                  static_cast<uint16_t>(statusWord)));
+                    }
+
+                    faultFound = true;
+                    inputFault = true;
+                }
+
+                if (statusWord & status_word::MFR_SPECIFIC_FAULT)
+                {
+                    if (!mfrFault)
+                    {
+                        log<level::INFO>(
+                            "MFRSPECIFIC fault",
+                            entry("STATUS_WORD=0x%04X",
+                                  static_cast<uint16_t>(statusWord)));
+                    }
+                    faultFound = true;
+                    mfrFault = true;
+                }
+
+                if (statusWord & status_word::VIN_UV_FAULT)
+                {
+                    if (!vinUVFault)
+                    {
+                        log<level::INFO>(
+                            "VIN_UV fault",
+                            entry("STATUS_WORD=0x%04X",
+                                  static_cast<uint16_t>(statusWord)));
+                    }
+
+                    faultFound = true;
+                    vinUVFault = true;
+                }
+            }
+            else
+            {
+                faultFound = false;
+                inputFault = false;
+                mfrFault = false;
+                vinUVFault = false;
+            }
+        }
+        catch (ReadFailure& e)
+        {
+            phosphor::logging::commit<ReadFailure>();
+        }
+    }
+}
+
 void PowerSupply::inventoryChanged(sdbusplus::message::message& msg)
 {
     std::string msgSensor;
@@ -53,6 +118,4 @@
     }
 }
 
-} // namespace psu
-} // namespace power
-} // namespace phosphor
+} // namespace phosphor::power::psu