Refactor findGPIODevice

Update findGPIODevice() to work on the path passed
into it instead of just on the gpioDevice member
variable.

Now it can be called both for finding the path for
the UCD chip as well as for the device that has the
GPIOs used for GPU isolation.

Change-Id: I01b93ece63cf28a11f0b438741689823280c7e2f
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
diff --git a/power-sequencer/ucd90160.cpp b/power-sequencer/ucd90160.cpp
index a088b8e..c819d66 100644
--- a/power-sequencer/ucd90160.cpp
+++ b/power-sequencer/ucd90160.cpp
@@ -46,13 +46,13 @@
 using namespace sdbusplus::xyz::openbmc_project::Power::Fault::Error;
 
 UCD90160::UCD90160(size_t instance) :
-    Device(DEVICE_NAME, instance),
-    interface(std::get<ucd90160::pathField>(
-                      deviceMap.find(instance)->second),
-              DRIVER_NAME,
-              instance)
+        Device(DEVICE_NAME, instance),
+        interface(std::get<ucd90160::pathField>(
+                          deviceMap.find(instance)->second),
+                  DRIVER_NAME,
+                  instance),
+        gpioDevice(findGPIODevice(interface.path()))
 {
-    findGPIODevice();
 }
 
 void UCD90160::onFailure()
@@ -254,9 +254,9 @@
             metadata::RAW_STATUS(nv.get().c_str()));
 }
 
-void UCD90160::findGPIODevice()
+fs::path UCD90160::findGPIODevice(const fs::path& path)
 {
-    auto& path = interface.path();
+    fs::path gpioDevicePath;
 
     //In the driver directory, look for a subdirectory
     //named gpiochipX, where X is some number.  Then
@@ -268,17 +268,19 @@
             if (f.path().filename().string().find("gpiochip") !=
                     std::string::npos)
             {
-                gpioDevice = "/dev" / f.path().filename();
+                gpioDevicePath = "/dev" / f.path().filename();
                 break;
             }
         }
     }
 
-    if (gpioDevice.empty())
+    if (gpioDevicePath.empty())
     {
-        log<level::ERR>("Could not find UCD90160 GPIO device path",
+        log<level::ERR>("Could not find GPIO device path",
                 entry("BASE_PATH=%s", path.c_str()));
     }
+
+    return gpioDevicePath;
 }
 
 }
diff --git a/power-sequencer/ucd90160.hpp b/power-sequencer/ucd90160.hpp
index 3232264..e470614 100644
--- a/power-sequencer/ucd90160.hpp
+++ b/power-sequencer/ucd90160.hpp
@@ -61,9 +61,17 @@
     private:
 
         /**
-         * Finds the GPIO device path for this device
+         * Given the device path for a chip, find its gpiochip
+         * path
+         *
+         * @param[in] path - device path, like
+         *                   /sys/devices/.../i2c-11/11-0064
+         *
+         * @return fs::path - The gpiochip path, like
+         *                   /dev/gpiochip1
          */
-        void findGPIODevice();
+        static std::experimental::filesystem::path findGPIODevice(
+                const std::experimental::filesystem::path& path);
 
         /**
          * Checks for VOUT faults on the device.