blob: 9bcbf7729b4e6718f217e704fa8ab470d591ae1b [file] [log] [blame]
Jim Wright7945dd22021-04-06 16:55:15 -05001#pragma once
2
3#include "pmbus.hpp"
4#include "power_sequencer_monitor.hpp"
5
Jim Wrightd8fc0682022-01-11 15:36:00 -06006#include <gpiod.hpp>
Jim Wright7945dd22021-04-06 16:55:15 -05007#include <sdbusplus/bus.hpp>
Jim Wright56ae78e2021-12-01 14:46:15 -06008#include <sdbusplus/bus/match.hpp>
Jim Wright7945dd22021-04-06 16:55:15 -05009
Jim Wrightd8a86172021-12-08 11:38:26 -060010#include <filesystem>
11#include <vector>
12
Jim Wright7945dd22021-04-06 16:55:15 -050013namespace phosphor::power::sequencer
14{
15
Jim Wrightd8a86172021-12-08 11:38:26 -060016struct Pin
17{
18 std::string name;
Jim Wrightd8fc0682022-01-11 15:36:00 -060019 unsigned int line;
Jim Wrightc91eed02022-07-22 11:27:06 -050020 std::string presence;
21};
22
23struct Rail
24{
25 std::string name;
26 std::string presence;
Jim Wrightd8a86172021-12-08 11:38:26 -060027};
28
Jim Wright7945dd22021-04-06 16:55:15 -050029/**
30 * @class UCD90320Monitor
31 * This class implements fault analysis for the UCD90320
32 * power sequencer device.
33 */
34class UCD90320Monitor : public PowerSequencerMonitor
35{
36 public:
37 UCD90320Monitor() = delete;
38 UCD90320Monitor(const UCD90320Monitor&) = delete;
39 UCD90320Monitor& operator=(const UCD90320Monitor&) = delete;
40 UCD90320Monitor(UCD90320Monitor&&) = delete;
41 UCD90320Monitor& operator=(UCD90320Monitor&&) = delete;
42 virtual ~UCD90320Monitor() = default;
43
44 /**
45 * Create a device object for UCD90320 monitoring.
Jim Wright3accffe2022-03-10 17:19:42 -060046 * @param bus D-Bus bus object
47 * @param i2cBus The bus number of the power sequencer device
48 * @param i2cAddress The I2C address of the power sequencer device
Jim Wright7945dd22021-04-06 16:55:15 -050049 */
Patrick Williams7354ce62022-07-22 19:26:56 -050050 UCD90320Monitor(sdbusplus::bus_t& bus, std::uint8_t i2cBus,
Jim Wrightd8fc0682022-01-11 15:36:00 -060051 std::uint16_t i2cAddress);
Jim Wright7945dd22021-04-06 16:55:15 -050052
Jim Wright56ae78e2021-12-01 14:46:15 -060053 /**
54 * Callback function to handle interfacesAdded D-Bus signals
55 * @param msg Expanded sdbusplus message data
56 */
Patrick Williams7354ce62022-07-22 19:26:56 -050057 void interfacesAddedHandler(sdbusplus::message_t& msg);
Jim Wright56ae78e2021-12-01 14:46:15 -060058
Jim Wright71a14132022-01-28 09:46:46 -060059 /** @copydoc PowerSequencerMonitor::onFailure() */
60 void onFailure(bool timeout, const std::string& powerSupplyError) override;
61
Jim Wright7945dd22021-04-06 16:55:15 -050062 private:
63 /**
Jim Wright56ae78e2021-12-01 14:46:15 -060064 * The match to Entity Manager interfaces added.
65 */
66 sdbusplus::bus::match_t match;
67
68 /**
Jim Wrightd8a86172021-12-08 11:38:26 -060069 * List of pins
70 */
71 std::vector<Pin> pins;
72
73 /**
Jim Wright7945dd22021-04-06 16:55:15 -050074 * The read/write interface to this hardware
75 */
Jim Wright56ae78e2021-12-01 14:46:15 -060076 pmbus::PMBus pmbusInterface;
77
78 /**
Jim Wrightc91eed02022-07-22 11:27:06 -050079 * List of rails
Jim Wrightd8a86172021-12-08 11:38:26 -060080 */
Jim Wrightc91eed02022-07-22 11:27:06 -050081 std::vector<Rail> rails;
Jim Wrightd8a86172021-12-08 11:38:26 -060082
83 /**
Jim Wright56ae78e2021-12-01 14:46:15 -060084 * Finds the list of compatible system types using D-Bus methods.
85 * This list is used to find the correct JSON configuration file for the
86 * current system.
87 */
88 void findCompatibleSystemTypes();
Jim Wrightd8a86172021-12-08 11:38:26 -060089
90 /**
91 * Finds the JSON configuration file.
92 * Looks for a configuration file based on the list of compatible system
93 * types.
94 * Throws an exception if an operating system error occurs while checking
95 * for the existance of a file.
Jim Wright3accffe2022-03-10 17:19:42 -060096 * @param compatibleSystemTypes List of compatible system types
Jim Wrightd8a86172021-12-08 11:38:26 -060097 */
98 void findConfigFile(const std::vector<std::string>& compatibleSystemTypes);
99
100 /**
Jim Wrightc91eed02022-07-22 11:27:06 -0500101 * Returns whether the hardware with the specified inventory path is
102 * present.
103 * If an error occurs while obtaining the presence value, presence is
104 * assumed to be false. An empty string path indicates no presence check is
105 * needed.
106 * @param inventoryPath D-Bus inventory path of the hardware
107 * @return true if hardware is present, false otherwise
108 */
109 bool isPresent(const std::string& inventoryPath);
110
111 /**
Jim Wright3accffe2022-03-10 17:19:42 -0600112 * Analyzes the device pins for errors when the device is known to be in an
113 * error state.
114 * @param message Message property of the error log entry
115 * @param additionalData AdditionalData property of the error log entry
116 */
117 void onFailureCheckPins(std::string& message,
118 std::map<std::string, std::string>& additionalData);
119
120 /**
121 * Analyzes the device rails for errors when the device is known to be in an
122 * error state.
123 * @param message Message property of the error log entry
124 * @param additionalData AdditionalData property of the error log entry
125 * @param powerSupplyError The power supply error to log. A default
126 * std:string, i.e. empty string (""), is passed when there is no power
127 * supply error to log.
128 */
129 void onFailureCheckRails(std::string& message,
130 std::map<std::string, std::string>& additionalData,
131 const std::string& powerSupplyError);
132
133 /**
Jim Wrightd8a86172021-12-08 11:38:26 -0600134 * Parse the JSON configuration file.
Jim Wright3accffe2022-03-10 17:19:42 -0600135 * @param pathName the path name
Jim Wrightd8a86172021-12-08 11:38:26 -0600136 */
137 void parseConfigFile(const std::filesystem::path& pathName);
Jim Wrightd8fc0682022-01-11 15:36:00 -0600138
139 /**
Jim Wright71a14132022-01-28 09:46:46 -0600140 * Reads the mfr_status register
Jim Wrightf6f0da92022-02-28 21:08:33 -0600141 * @return the register contents
Jim Wright71a14132022-01-28 09:46:46 -0600142 */
Jim Wright213ffe92022-06-03 08:54:30 -0500143 uint64_t readMFRStatus();
Jim Wright71a14132022-01-28 09:46:46 -0600144
145 /**
146 * Reads the status_word register
Jim Wrightf6f0da92022-02-28 21:08:33 -0600147 * @return the register contents
Jim Wright71a14132022-01-28 09:46:46 -0600148 */
149 uint16_t readStatusWord();
Jim Wright7945dd22021-04-06 16:55:15 -0500150};
151
152} // namespace phosphor::power::sequencer