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 | d8a8617 | 2021-12-08 11:38:26 -0600 | [diff] [blame] | 20 | }; |
| 21 | |
Jim Wright | 7945dd2 | 2021-04-06 16:55:15 -0500 | [diff] [blame] | 22 | /** |
| 23 | * @class UCD90320Monitor |
| 24 | * This class implements fault analysis for the UCD90320 |
| 25 | * power sequencer device. |
| 26 | */ |
| 27 | class 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 Wright | d8fc068 | 2022-01-11 15:36:00 -0600 | [diff] [blame] | 44 | std::uint16_t i2cAddress); |
Jim Wright | 7945dd2 | 2021-04-06 16:55:15 -0500 | [diff] [blame] | 45 | |
Jim Wright | 56ae78e | 2021-12-01 14:46:15 -0600 | [diff] [blame] | 46 | /** |
| 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 Wright | 71a1413 | 2022-01-28 09:46:46 -0600 | [diff] [blame] | 52 | /** @copydoc PowerSequencerMonitor::onFailure() */ |
| 53 | void onFailure(bool timeout, const std::string& powerSupplyError) override; |
| 54 | |
Jim Wright | 7945dd2 | 2021-04-06 16:55:15 -0500 | [diff] [blame] | 55 | private: |
| 56 | /** |
Jim Wright | d8fc068 | 2022-01-11 15:36:00 -0600 | [diff] [blame] | 57 | * Set of GPIO lines to monitor in this UCD chip. |
| 58 | */ |
| 59 | gpiod::line_bulk lines; |
| 60 | |
| 61 | /** |
Jim Wright | 56ae78e | 2021-12-01 14:46:15 -0600 | [diff] [blame] | 62 | * The match to Entity Manager interfaces added. |
| 63 | */ |
| 64 | sdbusplus::bus::match_t match; |
| 65 | |
| 66 | /** |
Jim Wright | d8a8617 | 2021-12-08 11:38:26 -0600 | [diff] [blame] | 67 | * List of pins |
| 68 | */ |
| 69 | std::vector<Pin> pins; |
| 70 | |
| 71 | /** |
Jim Wright | 7945dd2 | 2021-04-06 16:55:15 -0500 | [diff] [blame] | 72 | * The read/write interface to this hardware |
| 73 | */ |
Jim Wright | 56ae78e | 2021-12-01 14:46:15 -0600 | [diff] [blame] | 74 | pmbus::PMBus pmbusInterface; |
| 75 | |
| 76 | /** |
Jim Wright | d8a8617 | 2021-12-08 11:38:26 -0600 | [diff] [blame] | 77 | * List of rail names |
| 78 | */ |
| 79 | std::vector<std::string> rails; |
| 80 | |
| 81 | /** |
Jim Wright | 71a1413 | 2022-01-28 09:46:46 -0600 | [diff] [blame] | 82 | * Checks for PGOOD faults on the device. |
| 83 | * @param[in] additionalData AdditionalData property of the error log entry |
| 84 | * @return bool true if an error log was created |
| 85 | */ |
| 86 | bool checkPGOODFaults(std::map<std::string, std::string>& additionalData); |
| 87 | |
| 88 | /** |
| 89 | * Checks for VOUT faults on the device. |
| 90 | * @param[in] additionalData AdditionalData property of the error log entry |
| 91 | * @return bool true if an error log was created |
| 92 | */ |
| 93 | bool checkVOUTFaults(std::map<std::string, std::string>& additionalData); |
| 94 | |
| 95 | /** |
Jim Wright | 56ae78e | 2021-12-01 14:46:15 -0600 | [diff] [blame] | 96 | * Finds the list of compatible system types using D-Bus methods. |
| 97 | * This list is used to find the correct JSON configuration file for the |
| 98 | * current system. |
| 99 | */ |
| 100 | void findCompatibleSystemTypes(); |
Jim Wright | d8a8617 | 2021-12-08 11:38:26 -0600 | [diff] [blame] | 101 | |
| 102 | /** |
| 103 | * Finds the JSON configuration file. |
| 104 | * Looks for a configuration file based on the list of compatible system |
| 105 | * types. |
| 106 | * Throws an exception if an operating system error occurs while checking |
| 107 | * for the existance of a file. |
| 108 | * @param[in] compatibleSystemTypes List of compatible system types |
| 109 | */ |
| 110 | void findConfigFile(const std::vector<std::string>& compatibleSystemTypes); |
| 111 | |
| 112 | /** |
| 113 | * Parse the JSON configuration file. |
| 114 | * @param[in] pathName the path name |
| 115 | */ |
| 116 | void parseConfigFile(const std::filesystem::path& pathName); |
Jim Wright | d8fc068 | 2022-01-11 15:36:00 -0600 | [diff] [blame] | 117 | |
| 118 | /** |
Jim Wright | 71a1413 | 2022-01-28 09:46:46 -0600 | [diff] [blame] | 119 | * Reads the mfr_status register |
| 120 | * @return uint32_t the register contents |
| 121 | */ |
| 122 | uint32_t readMFRStatus(); |
| 123 | |
| 124 | /** |
| 125 | * Reads the status_word register |
| 126 | * @return uint16_t the register contents |
| 127 | */ |
| 128 | uint16_t readStatusWord(); |
| 129 | |
| 130 | /** |
Jim Wright | d8fc068 | 2022-01-11 15:36:00 -0600 | [diff] [blame] | 131 | * Set up GPIOs |
| 132 | * @param[in] offsets the list of pin offsets |
| 133 | */ |
| 134 | void setUpGpio(const std::vector<unsigned int>& offsets); |
Jim Wright | 7945dd2 | 2021-04-06 16:55:15 -0500 | [diff] [blame] | 135 | }; |
| 136 | |
| 137 | } // namespace phosphor::power::sequencer |