blob: 2453251fd22292248699cbef31f9b6077d49384b [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.
39 * @param[in] bus D-Bus bus object
40 * @param[in] i2cBus The bus number of the power sequencer device
41 * @param[in] i2cAddress The I2C address of the power sequencer device
42 */
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 Wright7945dd22021-04-06 16:55:15 -050052 private:
53 /**
Jim Wrightd8fc0682022-01-11 15:36:00 -060054 * Set of GPIO lines to monitor in this UCD chip.
55 */
56 gpiod::line_bulk lines;
57
58 /**
Jim Wright7945dd22021-04-06 16:55:15 -050059 * The D-Bus bus object
60 */
61 sdbusplus::bus::bus& bus;
62
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 Wrightd8a86172021-12-08 11:38:26 -060079 * List of rail names
80 */
81 std::vector<std::string> rails;
82
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.
96 * @param[in] compatibleSystemTypes List of compatible system types
97 */
98 void findConfigFile(const std::vector<std::string>& compatibleSystemTypes);
99
100 /**
101 * Parse the JSON configuration file.
102 * @param[in] pathName the path name
103 */
104 void parseConfigFile(const std::filesystem::path& pathName);
Jim Wrightd8fc0682022-01-11 15:36:00 -0600105
106 /**
107 * Set up GPIOs
108 * @param[in] offsets the list of pin offsets
109 */
110 void setUpGpio(const std::vector<unsigned int>& offsets);
Jim Wright7945dd22021-04-06 16:55:15 -0500111};
112
113} // namespace phosphor::power::sequencer