blob: 7f1d137e8434836acdfa97ed53652e6d92850f08 [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 Wrightd8a86172021-12-08 11:38:26 -060020};
21
Jim Wright7945dd22021-04-06 16:55:15 -050022/**
23 * @class UCD90320Monitor
24 * This class implements fault analysis for the UCD90320
25 * power sequencer device.
26 */
27class UCD90320Monitor : public PowerSequencerMonitor
28{
29 public:
30 UCD90320Monitor() = delete;
31 UCD90320Monitor(const UCD90320Monitor&) = delete;
32 UCD90320Monitor& operator=(const UCD90320Monitor&) = delete;
33 UCD90320Monitor(UCD90320Monitor&&) = delete;
34 UCD90320Monitor& operator=(UCD90320Monitor&&) = delete;
35 virtual ~UCD90320Monitor() = default;
36
37 /**
38 * Create a device object for UCD90320 monitoring.
Jim Wright3accffe2022-03-10 17:19:42 -060039 * @param bus D-Bus bus object
40 * @param i2cBus The bus number of the power sequencer device
41 * @param i2cAddress The I2C address of the power sequencer device
Jim Wright7945dd22021-04-06 16:55:15 -050042 */
43 UCD90320Monitor(sdbusplus::bus::bus& bus, std::uint8_t i2cBus,
Jim Wrightd8fc0682022-01-11 15:36:00 -060044 std::uint16_t i2cAddress);
Jim Wright7945dd22021-04-06 16:55:15 -050045
Jim Wright56ae78e2021-12-01 14:46:15 -060046 /**
47 * Callback function to handle interfacesAdded D-Bus signals
48 * @param msg Expanded sdbusplus message data
49 */
50 void interfacesAddedHandler(sdbusplus::message::message& msg);
51
Jim Wright71a14132022-01-28 09:46:46 -060052 /** @copydoc PowerSequencerMonitor::onFailure() */
53 void onFailure(bool timeout, const std::string& powerSupplyError) override;
54
Jim Wright7945dd22021-04-06 16:55:15 -050055 private:
56 /**
Jim Wright56ae78e2021-12-01 14:46:15 -060057 * The match to Entity Manager interfaces added.
58 */
59 sdbusplus::bus::match_t match;
60
61 /**
Jim Wrightd8a86172021-12-08 11:38:26 -060062 * List of pins
63 */
64 std::vector<Pin> pins;
65
66 /**
Jim Wright7945dd22021-04-06 16:55:15 -050067 * The read/write interface to this hardware
68 */
Jim Wright56ae78e2021-12-01 14:46:15 -060069 pmbus::PMBus pmbusInterface;
70
71 /**
Jim Wrightd8a86172021-12-08 11:38:26 -060072 * List of rail names
73 */
74 std::vector<std::string> rails;
75
76 /**
Jim Wright56ae78e2021-12-01 14:46:15 -060077 * Finds the list of compatible system types using D-Bus methods.
78 * This list is used to find the correct JSON configuration file for the
79 * current system.
80 */
81 void findCompatibleSystemTypes();
Jim Wrightd8a86172021-12-08 11:38:26 -060082
83 /**
84 * Finds the JSON configuration file.
85 * Looks for a configuration file based on the list of compatible system
86 * types.
87 * Throws an exception if an operating system error occurs while checking
88 * for the existance of a file.
Jim Wright3accffe2022-03-10 17:19:42 -060089 * @param compatibleSystemTypes List of compatible system types
Jim Wrightd8a86172021-12-08 11:38:26 -060090 */
91 void findConfigFile(const std::vector<std::string>& compatibleSystemTypes);
92
93 /**
Jim Wright3accffe2022-03-10 17:19:42 -060094 * Analyzes the device pins for errors when the device is known to be in an
95 * error state.
96 * @param message Message property of the error log entry
97 * @param additionalData AdditionalData property of the error log entry
98 */
99 void onFailureCheckPins(std::string& message,
100 std::map<std::string, std::string>& additionalData);
101
102 /**
103 * Analyzes the device rails for errors when the device is known to be in an
104 * error state.
105 * @param message Message property of the error log entry
106 * @param additionalData AdditionalData property of the error log entry
107 * @param powerSupplyError The power supply error to log. A default
108 * std:string, i.e. empty string (""), is passed when there is no power
109 * supply error to log.
110 */
111 void onFailureCheckRails(std::string& message,
112 std::map<std::string, std::string>& additionalData,
113 const std::string& powerSupplyError);
114
115 /**
Jim Wrightd8a86172021-12-08 11:38:26 -0600116 * Parse the JSON configuration file.
Jim Wright3accffe2022-03-10 17:19:42 -0600117 * @param pathName the path name
Jim Wrightd8a86172021-12-08 11:38:26 -0600118 */
119 void parseConfigFile(const std::filesystem::path& pathName);
Jim Wrightd8fc0682022-01-11 15:36:00 -0600120
121 /**
Jim Wright71a14132022-01-28 09:46:46 -0600122 * Reads the mfr_status register
Jim Wrightf6f0da92022-02-28 21:08:33 -0600123 * @return the register contents
Jim Wright71a14132022-01-28 09:46:46 -0600124 */
Jim Wright213ffe92022-06-03 08:54:30 -0500125 uint64_t readMFRStatus();
Jim Wright71a14132022-01-28 09:46:46 -0600126
127 /**
128 * Reads the status_word register
Jim Wrightf6f0da92022-02-28 21:08:33 -0600129 * @return the register contents
Jim Wright71a14132022-01-28 09:46:46 -0600130 */
131 uint16_t readStatusWord();
Jim Wright7945dd22021-04-06 16:55:15 -0500132};
133
134} // namespace phosphor::power::sequencer