Jim Wright | 7945dd2 | 2021-04-06 16:55:15 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "pmbus.hpp" |
| 4 | #include "power_sequencer_monitor.hpp" |
| 5 | |
Jim Wright | d8fc068 | 2022-01-11 15:36:00 -0600 | [diff] [blame] | 6 | #include <gpiod.hpp> |
Jim Wright | 7945dd2 | 2021-04-06 16:55:15 -0500 | [diff] [blame] | 7 | #include <sdbusplus/bus.hpp> |
Jim Wright | 56ae78e | 2021-12-01 14:46:15 -0600 | [diff] [blame] | 8 | #include <sdbusplus/bus/match.hpp> |
Jim Wright | 7945dd2 | 2021-04-06 16:55:15 -0500 | [diff] [blame] | 9 | |
Jim Wright | d8a8617 | 2021-12-08 11:38:26 -0600 | [diff] [blame] | 10 | #include <filesystem> |
| 11 | #include <vector> |
| 12 | |
Jim Wright | 7945dd2 | 2021-04-06 16:55:15 -0500 | [diff] [blame] | 13 | namespace phosphor::power::sequencer |
| 14 | { |
| 15 | |
Jim Wright | d8a8617 | 2021-12-08 11:38:26 -0600 | [diff] [blame] | 16 | struct Pin |
| 17 | { |
| 18 | std::string name; |
Jim Wright | d8fc068 | 2022-01-11 15:36:00 -0600 | [diff] [blame] | 19 | unsigned int line; |
Jim Wright | c91eed0 | 2022-07-22 11:27:06 -0500 | [diff] [blame] | 20 | std::string presence; |
| 21 | }; |
| 22 | |
| 23 | struct Rail |
| 24 | { |
| 25 | std::string name; |
| 26 | std::string presence; |
Jim Wright | d8a8617 | 2021-12-08 11:38:26 -0600 | [diff] [blame] | 27 | }; |
| 28 | |
Jim Wright | 7945dd2 | 2021-04-06 16:55:15 -0500 | [diff] [blame] | 29 | /** |
| 30 | * @class UCD90320Monitor |
| 31 | * This class implements fault analysis for the UCD90320 |
| 32 | * power sequencer device. |
| 33 | */ |
| 34 | class 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 Wright | 3accffe | 2022-03-10 17:19:42 -0600 | [diff] [blame] | 46 | * @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 Wright | 7945dd2 | 2021-04-06 16:55:15 -0500 | [diff] [blame] | 49 | */ |
Patrick Williams | 7354ce6 | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 50 | UCD90320Monitor(sdbusplus::bus_t& bus, std::uint8_t i2cBus, |
Jim Wright | d8fc068 | 2022-01-11 15:36:00 -0600 | [diff] [blame] | 51 | std::uint16_t i2cAddress); |
Jim Wright | 7945dd2 | 2021-04-06 16:55:15 -0500 | [diff] [blame] | 52 | |
Jim Wright | 56ae78e | 2021-12-01 14:46:15 -0600 | [diff] [blame] | 53 | /** |
| 54 | * Callback function to handle interfacesAdded D-Bus signals |
| 55 | * @param msg Expanded sdbusplus message data |
| 56 | */ |
Patrick Williams | 7354ce6 | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 57 | void interfacesAddedHandler(sdbusplus::message_t& msg); |
Jim Wright | 56ae78e | 2021-12-01 14:46:15 -0600 | [diff] [blame] | 58 | |
Jim Wright | 71a1413 | 2022-01-28 09:46:46 -0600 | [diff] [blame] | 59 | /** @copydoc PowerSequencerMonitor::onFailure() */ |
| 60 | void onFailure(bool timeout, const std::string& powerSupplyError) override; |
| 61 | |
Jim Wright | 7945dd2 | 2021-04-06 16:55:15 -0500 | [diff] [blame] | 62 | private: |
| 63 | /** |
Jim Wright | 56ae78e | 2021-12-01 14:46:15 -0600 | [diff] [blame] | 64 | * The match to Entity Manager interfaces added. |
| 65 | */ |
| 66 | sdbusplus::bus::match_t match; |
| 67 | |
| 68 | /** |
Jim Wright | d8a8617 | 2021-12-08 11:38:26 -0600 | [diff] [blame] | 69 | * List of pins |
| 70 | */ |
| 71 | std::vector<Pin> pins; |
| 72 | |
| 73 | /** |
Jim Wright | 7945dd2 | 2021-04-06 16:55:15 -0500 | [diff] [blame] | 74 | * The read/write interface to this hardware |
| 75 | */ |
Jim Wright | 56ae78e | 2021-12-01 14:46:15 -0600 | [diff] [blame] | 76 | pmbus::PMBus pmbusInterface; |
| 77 | |
| 78 | /** |
Jim Wright | c91eed0 | 2022-07-22 11:27:06 -0500 | [diff] [blame] | 79 | * List of rails |
Jim Wright | d8a8617 | 2021-12-08 11:38:26 -0600 | [diff] [blame] | 80 | */ |
Jim Wright | c91eed0 | 2022-07-22 11:27:06 -0500 | [diff] [blame] | 81 | std::vector<Rail> rails; |
Jim Wright | d8a8617 | 2021-12-08 11:38:26 -0600 | [diff] [blame] | 82 | |
| 83 | /** |
Jim Wright | 56ae78e | 2021-12-01 14:46:15 -0600 | [diff] [blame] | 84 | * 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 Wright | d8a8617 | 2021-12-08 11:38:26 -0600 | [diff] [blame] | 89 | |
| 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 Wright | 3accffe | 2022-03-10 17:19:42 -0600 | [diff] [blame] | 96 | * @param compatibleSystemTypes List of compatible system types |
Jim Wright | d8a8617 | 2021-12-08 11:38:26 -0600 | [diff] [blame] | 97 | */ |
| 98 | void findConfigFile(const std::vector<std::string>& compatibleSystemTypes); |
| 99 | |
| 100 | /** |
Jim Wright | c91eed0 | 2022-07-22 11:27:06 -0500 | [diff] [blame] | 101 | * 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 Wright | 3accffe | 2022-03-10 17:19:42 -0600 | [diff] [blame] | 112 | * 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 Wright | d8a8617 | 2021-12-08 11:38:26 -0600 | [diff] [blame] | 134 | * Parse the JSON configuration file. |
Jim Wright | 3accffe | 2022-03-10 17:19:42 -0600 | [diff] [blame] | 135 | * @param pathName the path name |
Jim Wright | d8a8617 | 2021-12-08 11:38:26 -0600 | [diff] [blame] | 136 | */ |
| 137 | void parseConfigFile(const std::filesystem::path& pathName); |
Jim Wright | d8fc068 | 2022-01-11 15:36:00 -0600 | [diff] [blame] | 138 | |
| 139 | /** |
Jim Wright | 71a1413 | 2022-01-28 09:46:46 -0600 | [diff] [blame] | 140 | * Reads the mfr_status register |
Jim Wright | f6f0da9 | 2022-02-28 21:08:33 -0600 | [diff] [blame] | 141 | * @return the register contents |
Jim Wright | 71a1413 | 2022-01-28 09:46:46 -0600 | [diff] [blame] | 142 | */ |
Jim Wright | 213ffe9 | 2022-06-03 08:54:30 -0500 | [diff] [blame] | 143 | uint64_t readMFRStatus(); |
Jim Wright | 71a1413 | 2022-01-28 09:46:46 -0600 | [diff] [blame] | 144 | |
| 145 | /** |
| 146 | * Reads the status_word register |
Jim Wright | f6f0da9 | 2022-02-28 21:08:33 -0600 | [diff] [blame] | 147 | * @return the register contents |
Jim Wright | 71a1413 | 2022-01-28 09:46:46 -0600 | [diff] [blame] | 148 | */ |
| 149 | uint16_t readStatusWord(); |
Jim Wright | 7945dd2 | 2021-04-06 16:55:15 -0500 | [diff] [blame] | 150 | }; |
| 151 | |
| 152 | } // namespace phosphor::power::sequencer |