Find the path for the GPIO device

This path is required to access a GPIO later.

Change-Id: I4ec64adbf939c5f0eaa12b7e18345d0fa2247a7d
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
diff --git a/power-sequencer/ucd90160.cpp b/power-sequencer/ucd90160.cpp
index 704c4e0..156c8f4 100644
--- a/power-sequencer/ucd90160.cpp
+++ b/power-sequencer/ucd90160.cpp
@@ -38,6 +38,7 @@
 const auto DRIVER_NAME = "ucd9000"s;
 constexpr auto NUM_PAGES = 16;
 
+namespace fs = std::experimental::filesystem;
 using namespace pmbus;
 using namespace phosphor::logging;
 using namespace sdbusplus::xyz::openbmc_project::Control::Device::Error;
@@ -51,6 +52,7 @@
               DRIVER_NAME,
               instance)
 {
+    findGPIODevice();
 }
 
 void UCD90160::onFailure()
@@ -184,5 +186,32 @@
 
 }
 
+void UCD90160::findGPIODevice()
+{
+    auto& path = interface.path();
+
+    //In the driver directory, look for a subdirectory
+    //named gpiochipX, where X is some number.  Then
+    //we'll access the GPIO at /dev/gpiochipX.
+    if (fs::is_directory(path))
+    {
+        for (auto& f : fs::directory_iterator(path))
+        {
+            if (f.path().filename().string().find("gpiochip") !=
+                    std::string::npos)
+            {
+                gpioDevice = "/dev" / f.path().filename();
+                break;
+            }
+        }
+    }
+
+    if (gpioDevice.empty())
+    {
+        log<level::ERR>("Could not find UCD90160 GPIO device path",
+                entry("BASE_PATH=%s", path.c_str()));
+    }
+}
+
 }
 }