psu-ng: Add in ability to get presence via GPIO

The device tree and entity-manager (D-Bus) properties have the power
supply GPIO presence lines named, so we can use those GPIO line names to
find the GPIO device to read for determining power supply presence.

Some systems have the power supply presence lines in a gpio-keys section
(notably IBM Rainier). To facilitate continued function while running
with a device tree that has not removed those device tree entries, allow
for a fallback to the old inventory D-Bus propertiesChanged or
interfaceAdded matches for presence.

Change-Id: I5002aa62e5b460463cc26328c889a3786b467a3c
Signed-off-by: B. J. Wyman <bjwyman@gmail.com>
diff --git a/phosphor-power-supply/psu_manager.cpp b/phosphor-power-supply/psu_manager.cpp
index fdb5d52..63473f7 100644
--- a/phosphor-power-supply/psu_manager.cpp
+++ b/phosphor-power-supply/psu_manager.cpp
@@ -16,6 +16,7 @@
 constexpr auto i2cBusProp = "I2CBus";
 constexpr auto i2cAddressProp = "I2CAddress";
 constexpr auto psuNameProp = "Name";
+constexpr auto presLineName = "NamedPresenceGpio";
 
 constexpr auto supportedConfIntf =
     "xyz.openbmc_project.Configuration.SupportedConfiguration";
@@ -98,6 +99,7 @@
     uint64_t* i2cbus = nullptr;
     uint64_t* i2caddr = nullptr;
     std::string* psuname = nullptr;
+    std::string* preslineptr = nullptr;
 
     for (const auto& property : properties)
     {
@@ -115,6 +117,11 @@
             {
                 psuname = std::get_if<std::string>(&properties[psuNameProp]);
             }
+            else if (property.first == presLineName)
+            {
+                preslineptr =
+                    std::get_if<std::string>(&properties[presLineName]);
+            }
         }
         catch (std::exception& e)
         {
@@ -125,11 +132,21 @@
     {
         std::string invpath = basePSUInvPath;
         invpath.push_back(psuname->back());
+        std::string presline = "";
 
         log<level::DEBUG>(fmt::format("Inventory Path: {}", invpath).c_str());
 
-        auto psu =
-            std::make_unique<PowerSupply>(bus, invpath, *i2cbus, *i2caddr);
+        if (nullptr != preslineptr)
+        {
+            presline = *preslineptr;
+        }
+
+        log<level::DEBUG>(
+            fmt::format("make PowerSupply bus: {} addr: {} presline: {}",
+                        *i2cbus, *i2caddr, presline)
+                .c_str());
+        auto psu = std::make_unique<PowerSupply>(bus, invpath, *i2cbus,
+                                                 *i2caddr, presline);
         psus.emplace_back(std::move(psu));
     }