Brandon Wyman | a0f33ce | 2019-10-17 18:32:29 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Brandon Wyman | 8d19577 | 2020-01-27 15:03:51 -0600 | [diff] [blame] | 3 | #include "pmbus.hpp" |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 4 | #include "types.hpp" |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 5 | #include "utility.hpp" |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 6 | |
| 7 | #include <sdbusplus/bus/match.hpp> |
| 8 | |
Brandon Wyman | a0f33ce | 2019-10-17 18:32:29 -0500 | [diff] [blame] | 9 | namespace phosphor::power::psu |
| 10 | { |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 11 | |
Brandon Wyman | a0f33ce | 2019-10-17 18:32:29 -0500 | [diff] [blame] | 12 | /** |
| 13 | * @class PowerSupply |
| 14 | * Represents a PMBus power supply device. |
| 15 | */ |
| 16 | class PowerSupply |
| 17 | { |
| 18 | public: |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 19 | PowerSupply() = delete; |
Brandon Wyman | a0f33ce | 2019-10-17 18:32:29 -0500 | [diff] [blame] | 20 | PowerSupply(const PowerSupply&) = delete; |
| 21 | PowerSupply(PowerSupply&&) = delete; |
| 22 | PowerSupply& operator=(const PowerSupply&) = delete; |
| 23 | PowerSupply& operator=(PowerSupply&&) = delete; |
| 24 | ~PowerSupply() = default; |
| 25 | |
| 26 | /** |
Brandon Wyman | c63941c | 2020-01-27 16:49:33 -0600 | [diff] [blame] | 27 | * @param[in] invpath - String for inventory path to use |
| 28 | * @param[in] i2cbus - The bus number this power supply is on |
| 29 | * @param[in] i2caddr - The 16-bit I2C address of the power supply |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 30 | */ |
Brandon Wyman | c63941c | 2020-01-27 16:49:33 -0600 | [diff] [blame] | 31 | PowerSupply(sdbusplus::bus::bus& bus, const std::string& invpath, |
| 32 | std::uint8_t i2cbus, const std::string& i2caddr) : |
| 33 | bus(bus), |
Brandon Wyman | 8d19577 | 2020-01-27 15:03:51 -0600 | [diff] [blame] | 34 | inventoryPath(invpath), |
| 35 | pmbusIntf(phosphor::pmbus::createPMBus(i2cbus, i2caddr)) |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 36 | { |
| 37 | // Setup the functions to call when the D-Bus inventory path for the |
| 38 | // Present property changes. |
| 39 | presentMatch = std::make_unique<sdbusplus::bus::match_t>( |
| 40 | bus, |
| 41 | sdbusplus::bus::match::rules::propertiesChanged(inventoryPath, |
| 42 | INVENTORY_IFACE), |
| 43 | [this](auto& msg) { this->inventoryChanged(msg); }); |
| 44 | presentAddedMatch = std::make_unique<sdbusplus::bus::match_t>( |
| 45 | bus, |
| 46 | sdbusplus::bus::match::rules::interfacesAdded() + |
| 47 | sdbusplus::bus::match::rules::path_namespace(inventoryPath), |
| 48 | [this](auto& msg) { this->inventoryChanged(msg); }); |
| 49 | // Get the current state of the Present property. |
| 50 | updatePresence(); |
| 51 | } |
| 52 | |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 53 | phosphor::pmbus::PMBusBase& getPMBus() |
| 54 | { |
| 55 | return *pmbusIntf; |
| 56 | } |
| 57 | |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 58 | /** |
Brandon Wyman | a0f33ce | 2019-10-17 18:32:29 -0500 | [diff] [blame] | 59 | * Power supply specific function to analyze for faults/errors. |
| 60 | * |
| 61 | * Various PMBus status bits will be checked for fault conditions. |
| 62 | * If a certain fault bits are on, the appropriate error will be |
| 63 | * committed. |
| 64 | */ |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 65 | void analyze(); |
Brandon Wyman | a0f33ce | 2019-10-17 18:32:29 -0500 | [diff] [blame] | 66 | |
| 67 | /** |
Brandon Wyman | 59a3579 | 2020-06-04 12:37:40 -0500 | [diff] [blame^] | 68 | * Write PMBus ON_OFF_CONFIG |
| 69 | * |
| 70 | * This function will be called to cause the PMBus device driver to send the |
| 71 | * ON_OFF_CONFIG command. Takes one byte of data. |
| 72 | * |
| 73 | * @param[in] data - The ON_OFF_CONFIG data byte mask. |
| 74 | */ |
| 75 | void onOffConfig(uint8_t data); |
| 76 | |
| 77 | /** |
Brandon Wyman | a0f33ce | 2019-10-17 18:32:29 -0500 | [diff] [blame] | 78 | * Write PMBus CLEAR_FAULTS |
| 79 | * |
| 80 | * This function will be called in various situations in order to clear |
| 81 | * any fault status bits that may have been set, in order to start over |
| 82 | * with a clean state. Presence changes and power state changes will |
| 83 | * want to clear any faults logged. |
| 84 | */ |
Brandon Wyman | 3c20846 | 2020-05-13 16:25:58 -0500 | [diff] [blame] | 85 | void clearFaults(); |
Brandon Wyman | a0f33ce | 2019-10-17 18:32:29 -0500 | [diff] [blame] | 86 | |
| 87 | /** |
| 88 | * @brief Adds properties to the inventory. |
| 89 | * |
| 90 | * Reads the values from the device and writes them to the |
| 91 | * associated power supply D-Bus inventory object. |
| 92 | * |
| 93 | * This needs to be done on startup, and each time the presence |
| 94 | * state changes. |
| 95 | * |
| 96 | * Properties added: |
| 97 | * - Serial Number |
| 98 | * - Part Number |
| 99 | * - CCIN (Customer Card Identification Number) - added as the Model |
| 100 | * - Firmware version |
| 101 | */ |
| 102 | void updateInventory() |
| 103 | { |
| 104 | } |
| 105 | |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 106 | /** |
| 107 | * @brief Accessor function to indicate present status |
| 108 | */ |
| 109 | bool isPresent() const |
| 110 | { |
| 111 | return present; |
| 112 | } |
| 113 | |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 114 | /** |
| 115 | * @brief Returns true if a fault was found. |
| 116 | */ |
| 117 | bool isFaulted() const |
| 118 | { |
| 119 | return faultFound; |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * @brief Returns true if INPUT fault occurred. |
| 124 | */ |
| 125 | bool hasInputFault() const |
| 126 | { |
| 127 | return inputFault; |
| 128 | } |
| 129 | |
| 130 | /** |
| 131 | * @brief Returns true if MFRSPECIFIC occurred. |
| 132 | */ |
| 133 | bool hasMFRFault() const |
| 134 | { |
| 135 | return mfrFault; |
| 136 | } |
| 137 | |
| 138 | /** |
| 139 | * @brief Returns true if VIN_UV_FAULT occurred. |
| 140 | */ |
| 141 | bool hasVINUVFault() const |
| 142 | { |
| 143 | return vinUVFault; |
| 144 | } |
| 145 | |
Brandon Wyman | a0f33ce | 2019-10-17 18:32:29 -0500 | [diff] [blame] | 146 | private: |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 147 | /** @brief systemd bus member */ |
| 148 | sdbusplus::bus::bus& bus; |
| 149 | |
Brandon Wyman | a0f33ce | 2019-10-17 18:32:29 -0500 | [diff] [blame] | 150 | /** @brief True if a fault has already been found and not cleared */ |
| 151 | bool faultFound = false; |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 152 | |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 153 | /** @brief True if bit 5 of STATUS_WORD high byte is on. */ |
| 154 | bool inputFault = false; |
| 155 | |
| 156 | /** @brief True if bit 4 of STATUS_WORD high byte is on. */ |
| 157 | bool mfrFault = false; |
| 158 | |
| 159 | /** @brief True if bit 3 of STATUS_WORD low byte is on. */ |
| 160 | bool vinUVFault = false; |
| 161 | |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 162 | /** |
| 163 | * @brief D-Bus path to use for this power supply's inventory status. |
| 164 | **/ |
| 165 | std::string inventoryPath; |
| 166 | |
| 167 | /** @brief True if the power supply is present. */ |
| 168 | bool present = false; |
| 169 | |
| 170 | /** @brief D-Bus match variable used to subscribe to Present property |
| 171 | * changes. |
| 172 | **/ |
| 173 | std::unique_ptr<sdbusplus::bus::match_t> presentMatch; |
| 174 | |
| 175 | /** @brief D-Bus match variable used to subscribe for Present property |
| 176 | * interface added. |
| 177 | */ |
| 178 | std::unique_ptr<sdbusplus::bus::match_t> presentAddedMatch; |
| 179 | |
| 180 | /** |
Brandon Wyman | 8d19577 | 2020-01-27 15:03:51 -0600 | [diff] [blame] | 181 | * @brief Pointer to the PMBus interface |
| 182 | * |
| 183 | * Used to read or write to/from PMBus power supply devices. |
| 184 | */ |
| 185 | std::unique_ptr<phosphor::pmbus::PMBusBase> pmbusIntf; |
| 186 | |
| 187 | /** |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 188 | * @brief Updates the presence status by querying D-Bus |
| 189 | * |
| 190 | * The D-Bus inventory properties for this power supply will be read to |
| 191 | * determine if the power supply is present or not and update this |
| 192 | * object's present member variable to reflect current status. |
| 193 | **/ |
| 194 | void updatePresence(); |
| 195 | |
| 196 | /** |
| 197 | * @brief Callback for inventory property changes |
| 198 | * |
| 199 | * Process change of Present property for power supply. |
| 200 | * |
| 201 | * @param[in] msg - Data associated with Present change signal |
| 202 | **/ |
| 203 | void inventoryChanged(sdbusplus::message::message& msg); |
Brandon Wyman | a0f33ce | 2019-10-17 18:32:29 -0500 | [diff] [blame] | 204 | }; |
| 205 | |
| 206 | } // namespace phosphor::power::psu |