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()));
+ }
+}
+
}
}
diff --git a/power-sequencer/ucd90160.hpp b/power-sequencer/ucd90160.hpp
index 8bb152b..09a3abf 100644
--- a/power-sequencer/ucd90160.hpp
+++ b/power-sequencer/ucd90160.hpp
@@ -1,6 +1,7 @@
#pragma once
#include <algorithm>
+#include <experimental/filesystem>
#include <map>
#include <vector>
#include "device.hpp"
@@ -57,6 +58,11 @@
private:
/**
+ * Finds the GPIO device path for this device
+ */
+ void findGPIODevice();
+
+ /**
* Checks for VOUT faults on the device.
*
* This device can monitor voltages of its dependent
@@ -147,6 +153,12 @@
bool accessError = false;
/**
+ * The path to the GPIO device used to read
+ * the GPI (PGOOD) status
+ */
+ std::experimental::filesystem::path gpioDevice;
+
+ /**
* Map of device instance to the instance specific data
*/
static const ucd90160::DeviceMap deviceMap;