pseq: Setup UCD90320 device GPIOs
Setup GPIOs for UCD90320 device. GPIOs will be used for power good fault
isolation. Use libgpiod.
Signed-off-by: Jim Wright <jlwright@us.ibm.com>
Change-Id: I9c104e3fddcb1847a95f6fb67bf6c139745f2d0c
diff --git a/phosphor-power-sequencer/src/ucd90320_monitor.cpp b/phosphor-power-sequencer/src/ucd90320_monitor.cpp
index e001c43..af04ff0 100644
--- a/phosphor-power-sequencer/src/ucd90320_monitor.cpp
+++ b/phosphor-power-sequencer/src/ucd90320_monitor.cpp
@@ -199,6 +199,9 @@
}
log<level::DEBUG>(fmt::format("Found rails: {}", rails).c_str());
+ // List of line offsets for libgpiod
+ std::vector<unsigned int> offsets;
+
// Parse pin information from config file
auto pinsIterator = rootElement.find("pins");
if (pinsIterator != rootElement.end())
@@ -212,12 +215,13 @@
lineIterator != pinElement.end())
{
std::string name = (*nameIterator).get<std::string>();
- int line = (*lineIterator).get<int>();
+ unsigned int line = (*lineIterator).get<unsigned int>();
Pin pin;
pin.name = name;
pin.line = line;
pins.emplace_back(std::move(pin));
+ offsets.emplace_back(line);
}
else
{
@@ -238,6 +242,7 @@
}
log<level::DEBUG>(
fmt::format("Found number of pins: {}", rails.size()).c_str());
+ setUpGpio(offsets);
}
catch (const std::exception& e)
{
@@ -248,4 +253,12 @@
}
}
+void UCD90320Monitor::setUpGpio(const std::vector<unsigned int>& offsets)
+{
+ gpiod::chip chip{"ucd90320", gpiod::chip::OPEN_BY_LABEL};
+ lines = chip.get_lines(offsets);
+ lines.request(
+ {"phosphor-power-control", gpiod::line_request::DIRECTION_INPUT, 0});
+}
+
} // namespace phosphor::power::sequencer
diff --git a/phosphor-power-sequencer/src/ucd90320_monitor.hpp b/phosphor-power-sequencer/src/ucd90320_monitor.hpp
index d7b66ad..2453251 100644
--- a/phosphor-power-sequencer/src/ucd90320_monitor.hpp
+++ b/phosphor-power-sequencer/src/ucd90320_monitor.hpp
@@ -3,6 +3,7 @@
#include "pmbus.hpp"
#include "power_sequencer_monitor.hpp"
+#include <gpiod.hpp>
#include <sdbusplus/bus.hpp>
#include <sdbusplus/bus/match.hpp>
@@ -15,7 +16,7 @@
struct Pin
{
std::string name;
- int line;
+ unsigned int line;
};
/**
@@ -40,7 +41,7 @@
* @param[in] i2cAddress The I2C address of the power sequencer device
*/
UCD90320Monitor(sdbusplus::bus::bus& bus, std::uint8_t i2cBus,
- const std::uint16_t i2cAddress);
+ std::uint16_t i2cAddress);
/**
* Callback function to handle interfacesAdded D-Bus signals
@@ -50,6 +51,11 @@
private:
/**
+ * Set of GPIO lines to monitor in this UCD chip.
+ */
+ gpiod::line_bulk lines;
+
+ /**
* The D-Bus bus object
*/
sdbusplus::bus::bus& bus;
@@ -96,6 +102,12 @@
* @param[in] pathName the path name
*/
void parseConfigFile(const std::filesystem::path& pathName);
+
+ /**
+ * Set up GPIOs
+ * @param[in] offsets the list of pin offsets
+ */
+ void setUpGpio(const std::vector<unsigned int>& offsets);
};
} // namespace phosphor::power::sequencer