Power supply input faults resolution

If the AC power is plugged in when the system is totally off,
psu-monitor doesn't get to resolve errors because it can not see their
states change from faulted to not faulted.

Tested:

Physically cut off power and reapplied it to check for any incorrect LED
indications for the power supply. Checked error logs to make sure input
power faults were resolved.

Signed-off-by: Aatir Manzur <aatrapps@gmail.com>
Change-Id: I893b67fabc9075fdd0ea3ae3a2912bc443cbadf8
diff --git a/power-supply/power_supply.cpp b/power-supply/power_supply.cpp
index 3af4bc4..487921d 100644
--- a/power-supply/power_supply.cpp
+++ b/power-supply/power_supply.cpp
@@ -89,6 +89,24 @@
     powerOnTimer(e, std::bind([this]() { this->powerOn = true; }))
 {
     using namespace sdbusplus::bus;
+    using namespace witherspoon::pmbus;
+    std::uint16_t statusWord = 0;
+    try
+    {
+        // Read the 2 byte STATUS_WORD value to check for faults.
+        statusWord = pmbusIntf.read(STATUS_WORD, Type::Debug);
+        if (!((statusWord & status_word::INPUT_FAULT_WARN) ||
+              (statusWord & status_word::VIN_UV_FAULT)))
+        {
+            resolveError(inventoryPath,
+                         std::string(PowerSupplyInputFault::errName));
+        }
+    }
+    catch (ReadFailure& e)
+    {
+        log<level::INFO>("Unable to read the 2 byte STATUS_WORD value to check "
+                         "for power-supply input faults.");
+    }
     presentMatch = std::make_unique<match_t>(
         bus, match::rules::propertiesChanged(inventoryPath, INVENTORY_IFACE),
         [this](auto& msg) { this->inventoryChanged(msg); });