pseq: Move bus/addr higher in class hierarchy
Update the PowerSequencerDevice class hierarchy within the
phosphor-power-sequencer application.
The I2C bus and address for the power sequencer device(s) in the system
are now defined in the JSON configuration file.
Move the I2C bus and address properties to the top of the
PowerSequencerDevice class hierarchy.
For sub-classes that already had these properties, order the constructor
parameters to match the order in the JSON.
Tested:
* Ran automated test cases
Change-Id: Ida6886cbc62a9c8abd3bed294f6ddcd1851ccd62
Signed-off-by: Shawn McCarney <shawnmm@us.ibm.com>
diff --git a/phosphor-power-sequencer/src/pmbus_driver_device.hpp b/phosphor-power-sequencer/src/pmbus_driver_device.hpp
index 6823907..9e77626 100644
--- a/phosphor-power-sequencer/src/pmbus_driver_device.hpp
+++ b/phosphor-power-sequencer/src/pmbus_driver_device.hpp
@@ -54,18 +54,18 @@
* Constructor.
*
* @param name Device name
- * @param rails Voltage rails that are enabled and monitored by this device
- * @param services System services like hardware presence and the journal
* @param bus I2C bus for the device
* @param address I2C address for the device
+ * @param rails Voltage rails that are enabled and monitored by this device
+ * @param services System services like hardware presence and the journal
* @param driverName Device driver name
* @param instance Chip instance number
*/
explicit PMBusDriverDevice(
- const std::string& name, std::vector<std::unique_ptr<Rail>> rails,
- Services& services, uint8_t bus, uint16_t address,
+ const std::string& name, uint8_t bus, uint16_t address,
+ std::vector<std::unique_ptr<Rail>> rails, Services& services,
const std::string& driverName = "", size_t instance = 0) :
- StandardDevice(name, std::move(rails)), bus{bus}, address{address},
+ StandardDevice(name, bus, address, std::move(rails)),
driverName{driverName}, instance{instance}
{
pmbusInterface =
@@ -73,26 +73,6 @@
}
/**
- * Returns the I2C bus for the device.
- *
- * @return I2C bus
- */
- uint8_t getBus() const
- {
- return bus;
- }
-
- /**
- * Returns the I2C address for the device.
- *
- * @return I2C address
- */
- uint16_t getAddress() const
- {
- return address;
- }
-
- /**
* Returns the device driver name.
*
* @return driver name
@@ -222,16 +202,6 @@
const std::string& fileName);
/**
- * I2C bus for the device.
- */
- uint8_t bus;
-
- /**
- * I2C address for the device.
- */
- uint16_t address;
-
- /**
* Device driver name.
*/
std::string driverName;
diff --git a/phosphor-power-sequencer/src/power_control.cpp b/phosphor-power-sequencer/src/power_control.cpp
index c1d0079..fbf2d5f 100644
--- a/phosphor-power-sequencer/src/power_control.cpp
+++ b/phosphor-power-sequencer/src/power_control.cpp
@@ -398,14 +398,14 @@
if (deviceProperties->type == UCD90160Device::deviceName)
{
device = std::make_unique<UCD90160Device>(
- std::move(rails), services, deviceProperties->bus,
- deviceProperties->address);
+ deviceProperties->bus, deviceProperties->address,
+ std::move(rails), services);
}
else if (deviceProperties->type == UCD90320Device::deviceName)
{
device = std::make_unique<UCD90320Device>(
- std::move(rails), services, deviceProperties->bus,
- deviceProperties->address);
+ deviceProperties->bus, deviceProperties->address,
+ std::move(rails), services);
}
else
{
diff --git a/phosphor-power-sequencer/src/power_sequencer_device.hpp b/phosphor-power-sequencer/src/power_sequencer_device.hpp
index a133f41..b7907c0 100644
--- a/phosphor-power-sequencer/src/power_sequencer_device.hpp
+++ b/phosphor-power-sequencer/src/power_sequencer_device.hpp
@@ -52,6 +52,20 @@
virtual const std::string& getName() const = 0;
/**
+ * Returns the I2C bus for the device.
+ *
+ * @return I2C bus
+ */
+ virtual uint8_t getBus() const = 0;
+
+ /**
+ * Returns the I2C address for the device.
+ *
+ * @return I2C address
+ */
+ virtual uint16_t getAddress() const = 0;
+
+ /**
* Returns the voltage rails that are enabled and monitored by this device.
*
* @return voltage rails
diff --git a/phosphor-power-sequencer/src/standard_device.hpp b/phosphor-power-sequencer/src/standard_device.hpp
index 227e3bc..03a6bf0 100644
--- a/phosphor-power-sequencer/src/standard_device.hpp
+++ b/phosphor-power-sequencer/src/standard_device.hpp
@@ -19,6 +19,7 @@
#include "rail.hpp"
#include "services.hpp"
+#include <cstdint>
#include <map>
#include <memory>
#include <string>
@@ -53,11 +54,14 @@
* Constructor.
*
* @param name device name
+ * @param bus I2C bus for the device
+ * @param address I2C address for the device
* @param rails voltage rails that are enabled and monitored by this device
*/
- explicit StandardDevice(const std::string& name,
+ explicit StandardDevice(const std::string& name, uint8_t bus,
+ uint16_t address,
std::vector<std::unique_ptr<Rail>> rails) :
- name{name}, rails{std::move(rails)}
+ name{name}, bus{bus}, address{address}, rails{std::move(rails)}
{}
/** @copydoc PowerSequencerDevice::getName() */
@@ -66,6 +70,18 @@
return name;
}
+ /** @copydoc PowerSequencerDevice::getBus() */
+ virtual uint8_t getBus() const override
+ {
+ return bus;
+ }
+
+ /** @copydoc PowerSequencerDevice::getAddress() */
+ virtual uint16_t getAddress() const override
+ {
+ return address;
+ }
+
/** @copydoc PowerSequencerDevice::getRails() */
virtual const std::vector<std::unique_ptr<Rail>>& getRails() const override
{
@@ -173,6 +189,16 @@
std::string name{};
/**
+ * I2C bus for the device.
+ */
+ uint8_t bus;
+
+ /**
+ * I2C address for the device.
+ */
+ uint16_t address;
+
+ /**
* Voltage rails that are enabled and monitored by this device.
*/
std::vector<std::unique_ptr<Rail>> rails{};
diff --git a/phosphor-power-sequencer/src/ucd90160_device.hpp b/phosphor-power-sequencer/src/ucd90160_device.hpp
index 4b62766..fa7c5e9 100644
--- a/phosphor-power-sequencer/src/ucd90160_device.hpp
+++ b/phosphor-power-sequencer/src/ucd90160_device.hpp
@@ -48,14 +48,15 @@
/**
* Constructor.
*
- * @param rails Voltage rails that are enabled and monitored by this device
- * @param services System services like hardware presence and the journal
* @param bus I2C bus for the device
* @param address I2C address for the device
+ * @param rails Voltage rails that are enabled and monitored by this device
+ * @param services System services like hardware presence and the journal
*/
- explicit UCD90160Device(std::vector<std::unique_ptr<Rail>> rails,
- Services& services, uint8_t bus, uint16_t address) :
- UCD90xDevice(deviceName, std::move(rails), services, bus, address)
+ explicit UCD90160Device(uint8_t bus, uint16_t address,
+ std::vector<std::unique_ptr<Rail>> rails,
+ Services& services) :
+ UCD90xDevice(deviceName, bus, address, std::move(rails), services)
{}
constexpr static std::string deviceName{"UCD90160"};
diff --git a/phosphor-power-sequencer/src/ucd90320_device.hpp b/phosphor-power-sequencer/src/ucd90320_device.hpp
index c52c6ce..cadcbf6 100644
--- a/phosphor-power-sequencer/src/ucd90320_device.hpp
+++ b/phosphor-power-sequencer/src/ucd90320_device.hpp
@@ -48,14 +48,15 @@
/**
* Constructor.
*
- * @param rails Voltage rails that are enabled and monitored by this device
- * @param services System services like hardware presence and the journal
* @param bus I2C bus for the device
* @param address I2C address for the device
+ * @param rails Voltage rails that are enabled and monitored by this device
+ * @param services System services like hardware presence and the journal
*/
- explicit UCD90320Device(std::vector<std::unique_ptr<Rail>> rails,
- Services& services, uint8_t bus, uint16_t address) :
- UCD90xDevice(deviceName, std::move(rails), services, bus, address)
+ explicit UCD90320Device(uint8_t bus, uint16_t address,
+ std::vector<std::unique_ptr<Rail>> rails,
+ Services& services) :
+ UCD90xDevice(deviceName, bus, address, std::move(rails), services)
{}
constexpr static std::string deviceName{"UCD90320"};
diff --git a/phosphor-power-sequencer/src/ucd90x_device.hpp b/phosphor-power-sequencer/src/ucd90x_device.hpp
index f5044c8..45dd774 100644
--- a/phosphor-power-sequencer/src/ucd90x_device.hpp
+++ b/phosphor-power-sequencer/src/ucd90x_device.hpp
@@ -51,15 +51,16 @@
* Constructor.
*
* @param name Device name
- * @param rails Voltage rails that are enabled and monitored by this device
- * @param services System services like hardware presence and the journal
* @param bus I2C bus for the device
* @param address I2C address for the device
+ * @param rails Voltage rails that are enabled and monitored by this device
+ * @param services System services like hardware presence and the journal
*/
- explicit UCD90xDevice(const std::string& name,
+ explicit UCD90xDevice(const std::string& name, uint8_t bus,
+ uint16_t address,
std::vector<std::unique_ptr<Rail>> rails,
- Services& services, uint8_t bus, uint16_t address) :
- PMBusDriverDevice(name, std::move(rails), services, bus, address,
+ Services& services) :
+ PMBusDriverDevice(name, bus, address, std::move(rails), services,
driverName)
{}