pseq: Create UCD90xDevice class
Create the UCD90xDevice class in the phosphor-power-sequencer
application.
This is a base class for the UCD90x family of power sequencer devices.
Tested:
* Performed the following tests on Rainier and Everest systems
* MFR_STATUS value obtained successfully
* Verified error paths and exceptions thrown
Change-Id: I430ffb95d96e228ce0245ae1c9cb63db72d590c5
Signed-off-by: Shawn McCarney <shawnmm@us.ibm.com>
diff --git a/phosphor-power-sequencer/src/meson.build b/phosphor-power-sequencer/src/meson.build
index ee6057e..02084c9 100644
--- a/phosphor-power-sequencer/src/meson.build
+++ b/phosphor-power-sequencer/src/meson.build
@@ -10,6 +10,7 @@
'rail.cpp',
'services.cpp',
'standard_device.cpp',
+ 'ucd90x_device.cpp',
implicit_include_directories: false,
dependencies: [
nlohmann_json_dep,
diff --git a/phosphor-power-sequencer/src/ucd90x_device.cpp b/phosphor-power-sequencer/src/ucd90x_device.cpp
new file mode 100644
index 0000000..26e96f7
--- /dev/null
+++ b/phosphor-power-sequencer/src/ucd90x_device.cpp
@@ -0,0 +1,68 @@
+/**
+ * Copyright © 2024 IBM Corporation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "ucd90x_device.hpp"
+
+#include "pmbus.hpp"
+
+#include <exception>
+#include <format>
+#include <stdexcept>
+
+namespace phosphor::power::sequencer
+{
+
+using namespace pmbus;
+
+uint64_t UCD90xDevice::getMfrStatus()
+{
+ uint64_t value{0};
+ try
+ {
+ std::string fileName{"mfr_status"};
+ value = pmbusInterface->read(fileName, Type::HwmonDeviceDebug);
+ }
+ catch (const std::exception& e)
+ {
+ throw std::runtime_error{std::format(
+ "Unable to read MFR_STATUS for device {}: {}", name, e.what())};
+ }
+ return value;
+}
+
+void UCD90xDevice::storePgoodFaultDebugData(
+ Services& services, const std::vector<int>& gpioValues,
+ std::map<std::string, std::string>& additionalData)
+{
+ // Store manufacturer-specific MFR_STATUS command value
+ try
+ {
+ uint64_t value = getMfrStatus();
+ services.logInfoMsg(
+ std::format("Device {} MFR_STATUS: {:#014x}", name, value));
+ additionalData.emplace("MFR_STATUS", std::format("{:#014x}", value));
+ }
+ catch (...)
+ {
+ // Ignore error; don't interrupt pgood fault handling
+ }
+
+ // Call parent class method to store standard data
+ PMBusDriverDevice::storePgoodFaultDebugData(services, gpioValues,
+ additionalData);
+}
+
+} // namespace phosphor::power::sequencer
diff --git a/phosphor-power-sequencer/src/ucd90x_device.hpp b/phosphor-power-sequencer/src/ucd90x_device.hpp
new file mode 100644
index 0000000..f5044c8
--- /dev/null
+++ b/phosphor-power-sequencer/src/ucd90x_device.hpp
@@ -0,0 +1,96 @@
+/**
+ * Copyright © 2024 IBM Corporation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#pragma once
+
+#include "pmbus_driver_device.hpp"
+#include "rail.hpp"
+#include "services.hpp"
+
+#include <cstdint>
+#include <map>
+#include <memory>
+#include <string>
+#include <utility>
+#include <vector>
+
+namespace phosphor::power::sequencer
+{
+
+/**
+ * @class UCD90xDevice
+ *
+ * PMBusDriverDevice sub-class for the UCD90X family of power sequencer devices.
+ *
+ * These devices share a common device driver.
+ */
+class UCD90xDevice : public PMBusDriverDevice
+{
+ public:
+ // Specify which compiler-generated methods we want
+ UCD90xDevice() = delete;
+ UCD90xDevice(const UCD90xDevice&) = delete;
+ UCD90xDevice(UCD90xDevice&&) = delete;
+ UCD90xDevice& operator=(const UCD90xDevice&) = delete;
+ UCD90xDevice& operator=(UCD90xDevice&&) = delete;
+ virtual ~UCD90xDevice() = default;
+
+ /**
+ * 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
+ */
+ explicit UCD90xDevice(const std::string& name,
+ std::vector<std::unique_ptr<Rail>> rails,
+ Services& services, uint8_t bus, uint16_t address) :
+ PMBusDriverDevice(name, std::move(rails), services, bus, address,
+ driverName)
+ {}
+
+ /**
+ * Returns the value of the PMBus MFR_STATUS command.
+ *
+ * This is a manufacturer-specific command that replaces the standard
+ * STATUS_MFR_SPECIFIC command on UCD90x devices.
+ *
+ * The returned value is in host-endian order.
+ *
+ * Note that the UCD90x documentation states that this is a paged command.
+ * This means that the PMBus PAGE should be set, and some of the bits in the
+ * command value are page-specific. However, the current device driver only
+ * provides a single file in sysfs, and the driver always sets the PAGE to
+ * 0. Thus, the bits that are page-specific in the returned value are
+ * always for PAGE 0.
+ *
+ * Throws an exception if the value could not be obtained.
+ *
+ * @return MFR_STATUS value
+ */
+ virtual uint64_t getMfrStatus();
+
+ constexpr static std::string driverName{"ucd9000"};
+
+ protected:
+ /** @copydoc PMBusDriverDevice::storePgoodFaultDebugData() */
+ virtual void storePgoodFaultDebugData(
+ Services& services, const std::vector<int>& gpioValues,
+ std::map<std::string, std::string>& additionalData) override;
+};
+
+} // namespace phosphor::power::sequencer