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" |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 5 | #include "util.hpp" |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 6 | #include "utility.hpp" |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 7 | |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 8 | #include <gpiod.hpp> |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 9 | #include <sdbusplus/bus/match.hpp> |
| 10 | |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 11 | #include <filesystem> |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 12 | #include <stdexcept> |
| 13 | |
Brandon Wyman | a0f33ce | 2019-10-17 18:32:29 -0500 | [diff] [blame] | 14 | namespace phosphor::power::psu |
| 15 | { |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 16 | |
Chanh Nguyen | c12c53b | 2021-04-06 17:24:47 +0700 | [diff] [blame] | 17 | #if IBM_VPD |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 18 | // PMBus device driver "file name" to read for CCIN value. |
| 19 | constexpr auto CCIN = "ccin"; |
| 20 | constexpr auto PART_NUMBER = "part_number"; |
| 21 | constexpr auto FRU_NUMBER = "fru"; |
| 22 | constexpr auto SERIAL_HEADER = "header"; |
| 23 | constexpr auto SERIAL_NUMBER = "serial_number"; |
| 24 | constexpr auto FW_VERSION = "fw_version"; |
| 25 | |
| 26 | // The D-Bus property name to update with the CCIN value. |
| 27 | constexpr auto MODEL_PROP = "Model"; |
| 28 | constexpr auto PN_PROP = "PartNumber"; |
| 29 | constexpr auto SN_PROP = "SerialNumber"; |
| 30 | constexpr auto VERSION_PROP = "Version"; |
| 31 | |
| 32 | // ipzVPD Keyword sizes |
| 33 | static constexpr auto FL_KW_SIZE = 20; |
| 34 | #endif |
| 35 | |
Brandon Wyman | f65c406 | 2020-08-19 13:15:53 -0500 | [diff] [blame] | 36 | constexpr auto LOG_LIMIT = 3; |
| 37 | |
Brandon Wyman | a0f33ce | 2019-10-17 18:32:29 -0500 | [diff] [blame] | 38 | /** |
| 39 | * @class PowerSupply |
| 40 | * Represents a PMBus power supply device. |
| 41 | */ |
| 42 | class PowerSupply |
| 43 | { |
| 44 | public: |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 45 | PowerSupply() = delete; |
Brandon Wyman | a0f33ce | 2019-10-17 18:32:29 -0500 | [diff] [blame] | 46 | PowerSupply(const PowerSupply&) = delete; |
| 47 | PowerSupply(PowerSupply&&) = delete; |
| 48 | PowerSupply& operator=(const PowerSupply&) = delete; |
| 49 | PowerSupply& operator=(PowerSupply&&) = delete; |
| 50 | ~PowerSupply() = default; |
| 51 | |
| 52 | /** |
Brandon Wyman | c63941c | 2020-01-27 16:49:33 -0600 | [diff] [blame] | 53 | * @param[in] invpath - String for inventory path to use |
| 54 | * @param[in] i2cbus - The bus number this power supply is on |
| 55 | * @param[in] i2caddr - The 16-bit I2C address of the power supply |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 56 | * @param[in] gpioLineName - The gpio-line-name to read for presence. See |
| 57 | * https://github.com/openbmc/docs/blob/master/designs/device-tree-gpio-naming.md |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 58 | */ |
Brandon Wyman | c63941c | 2020-01-27 16:49:33 -0600 | [diff] [blame] | 59 | PowerSupply(sdbusplus::bus::bus& bus, const std::string& invpath, |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 60 | std::uint8_t i2cbus, const std::uint16_t i2caddr, |
| 61 | const std::string& gpioLineName); |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 62 | |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 63 | phosphor::pmbus::PMBusBase& getPMBus() |
| 64 | { |
| 65 | return *pmbusIntf; |
| 66 | } |
| 67 | |
Adriana Kobylak | 3ca062a | 2021-10-20 15:27:23 +0000 | [diff] [blame] | 68 | GPIOInterfaceBase* getPresenceGPIO() |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 69 | { |
| 70 | return presenceGPIO.get(); |
| 71 | } |
| 72 | |
B. J. Wyman | d8b8cb1 | 2021-07-15 22:03:34 +0000 | [diff] [blame] | 73 | std::string getPresenceGPIOName() const |
| 74 | { |
| 75 | if (presenceGPIO != nullptr) |
| 76 | { |
| 77 | return presenceGPIO->getName(); |
| 78 | } |
| 79 | else |
| 80 | { |
| 81 | return std::string(); |
| 82 | } |
| 83 | } |
| 84 | |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 85 | /** |
Brandon Wyman | a0f33ce | 2019-10-17 18:32:29 -0500 | [diff] [blame] | 86 | * Power supply specific function to analyze for faults/errors. |
| 87 | * |
| 88 | * Various PMBus status bits will be checked for fault conditions. |
| 89 | * If a certain fault bits are on, the appropriate error will be |
| 90 | * committed. |
| 91 | */ |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 92 | void analyze(); |
Brandon Wyman | a0f33ce | 2019-10-17 18:32:29 -0500 | [diff] [blame] | 93 | |
| 94 | /** |
Brandon Wyman | 59a3579 | 2020-06-04 12:37:40 -0500 | [diff] [blame] | 95 | * Write PMBus ON_OFF_CONFIG |
| 96 | * |
| 97 | * This function will be called to cause the PMBus device driver to send the |
| 98 | * ON_OFF_CONFIG command. Takes one byte of data. |
| 99 | * |
| 100 | * @param[in] data - The ON_OFF_CONFIG data byte mask. |
| 101 | */ |
| 102 | void onOffConfig(uint8_t data); |
| 103 | |
| 104 | /** |
Brandon Wyman | a0f33ce | 2019-10-17 18:32:29 -0500 | [diff] [blame] | 105 | * Write PMBus CLEAR_FAULTS |
| 106 | * |
| 107 | * This function will be called in various situations in order to clear |
| 108 | * any fault status bits that may have been set, in order to start over |
| 109 | * with a clean state. Presence changes and power state changes will |
| 110 | * want to clear any faults logged. |
| 111 | */ |
Brandon Wyman | 3c20846 | 2020-05-13 16:25:58 -0500 | [diff] [blame] | 112 | void clearFaults(); |
Brandon Wyman | a0f33ce | 2019-10-17 18:32:29 -0500 | [diff] [blame] | 113 | |
| 114 | /** |
| 115 | * @brief Adds properties to the inventory. |
| 116 | * |
| 117 | * Reads the values from the device and writes them to the |
| 118 | * associated power supply D-Bus inventory object. |
| 119 | * |
| 120 | * This needs to be done on startup, and each time the presence |
| 121 | * state changes. |
| 122 | * |
| 123 | * Properties added: |
| 124 | * - Serial Number |
| 125 | * - Part Number |
| 126 | * - CCIN (Customer Card Identification Number) - added as the Model |
| 127 | * - Firmware version |
| 128 | */ |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 129 | void updateInventory(); |
Brandon Wyman | a0f33ce | 2019-10-17 18:32:29 -0500 | [diff] [blame] | 130 | |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 131 | /** |
| 132 | * @brief Accessor function to indicate present status |
| 133 | */ |
| 134 | bool isPresent() const |
| 135 | { |
| 136 | return present; |
| 137 | } |
| 138 | |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 139 | /** |
Brandon Wyman | fed0ba2 | 2020-09-26 20:02:51 -0500 | [diff] [blame] | 140 | * @brief Returns the last read value from STATUS_WORD. |
| 141 | */ |
| 142 | uint64_t getStatusWord() const |
| 143 | { |
| 144 | return statusWord; |
| 145 | } |
| 146 | |
| 147 | /** |
Brandon Wyman | f07bc79 | 2021-10-12 19:00:35 +0000 | [diff] [blame] | 148 | * @brief Returns the last read value from STATUS_INPUT. |
| 149 | */ |
| 150 | uint64_t getStatusInput() const |
| 151 | { |
| 152 | return statusInput; |
| 153 | } |
| 154 | |
| 155 | /** |
Jay Meyer | 10d9405 | 2020-11-30 14:41:21 -0600 | [diff] [blame] | 156 | * @brief Returns the last read value from STATUS_MFR. |
| 157 | */ |
| 158 | uint64_t getMFRFault() const |
| 159 | { |
| 160 | return statusMFR; |
| 161 | } |
| 162 | |
| 163 | /** |
Brandon Wyman | 85c7bf4 | 2021-10-19 22:28:48 +0000 | [diff] [blame] | 164 | * @brief Returns the last read value from STATUS_CML. |
| 165 | */ |
| 166 | uint64_t getStatusCML() const |
| 167 | { |
| 168 | return statusCML; |
| 169 | } |
| 170 | |
| 171 | /** |
Brandon Wyman | 6710ba2 | 2021-10-27 17:39:31 +0000 | [diff] [blame] | 172 | * @brief Returns the last read value from STATUS_VOUT. |
| 173 | */ |
| 174 | uint64_t getStatusVout() const |
| 175 | { |
| 176 | return statusVout; |
| 177 | } |
| 178 | |
| 179 | /** |
Brandon Wyman | b10b3be | 2021-11-09 22:12:15 +0000 | [diff] [blame] | 180 | * @brief Returns the last value read from STATUS_IOUT. |
| 181 | */ |
| 182 | uint64_t getStatusIout() const |
| 183 | { |
| 184 | return statusIout; |
| 185 | } |
| 186 | |
| 187 | /** |
Brandon Wyman | 96893a4 | 2021-11-05 19:56:57 +0000 | [diff] [blame] | 188 | * @brief Returns the last value read from STATUS_TEMPERATURE. |
| 189 | */ |
| 190 | uint64_t getStatusTemperature() const |
| 191 | { |
| 192 | return statusTemperature; |
| 193 | } |
| 194 | |
| 195 | /** |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 196 | * @brief Returns true if a fault was found. |
| 197 | */ |
| 198 | bool isFaulted() const |
| 199 | { |
Brandon Wyman | 9ddc622 | 2021-10-28 17:28:01 +0000 | [diff] [blame] | 200 | return (hasCommFault() || vinUVFault || inputFault || voutOVFault || |
Brandon Wyman | 2cf4694 | 2021-10-28 19:09:16 +0000 | [diff] [blame] | 201 | ioutOCFault || voutUVFault || tempFault || pgoodFault || |
| 202 | mfrFault); |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | /** |
Brandon Wyman | b76ab24 | 2020-09-16 18:06:06 -0500 | [diff] [blame] | 206 | * @brief Return whether a fault has been logged for this power supply |
| 207 | */ |
| 208 | bool isFaultLogged() const |
| 209 | { |
| 210 | return faultLogged; |
| 211 | } |
| 212 | |
| 213 | /** |
| 214 | * @brief Called when a fault for this power supply has been logged. |
| 215 | */ |
| 216 | void setFaultLogged() |
| 217 | { |
| 218 | faultLogged = true; |
| 219 | } |
| 220 | |
| 221 | /** |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 222 | * @brief Returns true if INPUT fault occurred. |
| 223 | */ |
| 224 | bool hasInputFault() const |
| 225 | { |
| 226 | return inputFault; |
| 227 | } |
| 228 | |
| 229 | /** |
| 230 | * @brief Returns true if MFRSPECIFIC occurred. |
| 231 | */ |
| 232 | bool hasMFRFault() const |
| 233 | { |
| 234 | return mfrFault; |
| 235 | } |
| 236 | |
| 237 | /** |
| 238 | * @brief Returns true if VIN_UV_FAULT occurred. |
| 239 | */ |
| 240 | bool hasVINUVFault() const |
| 241 | { |
| 242 | return vinUVFault; |
| 243 | } |
| 244 | |
Brandon Wyman | c9efe41 | 2020-10-09 15:42:50 -0500 | [diff] [blame] | 245 | /** |
Brandon Wyman | 6710ba2 | 2021-10-27 17:39:31 +0000 | [diff] [blame] | 246 | * @brief Returns true if VOUT_OV_FAULT occurred. |
| 247 | */ |
| 248 | bool hasVoutOVFault() const |
| 249 | { |
| 250 | return voutOVFault; |
| 251 | } |
| 252 | |
| 253 | /** |
Brandon Wyman | b10b3be | 2021-11-09 22:12:15 +0000 | [diff] [blame] | 254 | * @brief Returns true if IOUT_OC fault occurred (bit 4 STATUS_BYTE). |
| 255 | */ |
| 256 | bool hasIoutOCFault() const |
| 257 | { |
| 258 | return ioutOCFault; |
| 259 | } |
| 260 | |
| 261 | /** |
Brandon Wyman | 2cf4694 | 2021-10-28 19:09:16 +0000 | [diff] [blame] | 262 | * @brief Returns true if VOUT_UV_FAULT occurred. |
| 263 | */ |
| 264 | bool hasVoutUVFault() const |
| 265 | { |
| 266 | return voutUVFault; |
| 267 | } |
| 268 | |
| 269 | /** |
Brandon Wyman | 96893a4 | 2021-11-05 19:56:57 +0000 | [diff] [blame] | 270 | * @brief Returns true if TEMPERATURE fault occurred. |
| 271 | */ |
| 272 | bool hasTempFault() const |
| 273 | { |
| 274 | return tempFault; |
| 275 | } |
| 276 | |
| 277 | /** |
Brandon Wyman | 2916ea5 | 2021-11-06 03:31:18 +0000 | [diff] [blame] | 278 | * @brief Returns true if there is a PGood fault (PGOOD# inactive, or OFF |
| 279 | * bit on). |
| 280 | */ |
| 281 | bool hasPgoodFault() const |
| 282 | { |
| 283 | return pgoodFault; |
| 284 | } |
| 285 | |
| 286 | /** |
Brandon Wyman | c9efe41 | 2020-10-09 15:42:50 -0500 | [diff] [blame] | 287 | * @brief Returns the device path |
| 288 | * |
| 289 | * This can be used for error call outs. |
| 290 | * Example: /sys/bus/i2c/devices/3-0068 |
| 291 | */ |
Brandon Wyman | 4176d6b | 2020-10-07 17:41:06 -0500 | [diff] [blame] | 292 | const std::string getDevicePath() const |
| 293 | { |
| 294 | return pmbusIntf->path(); |
| 295 | } |
| 296 | |
Brandon Wyman | c9efe41 | 2020-10-09 15:42:50 -0500 | [diff] [blame] | 297 | /** |
| 298 | * @brief Returns this power supplies inventory path. |
| 299 | * |
| 300 | * This can be used for error call outs. |
| 301 | * Example: |
| 302 | * /xyz/openbmc_project/inventory/system/chassis/motherboard/powersupply1 |
| 303 | */ |
Brandon Wyman | 7e49527 | 2020-09-26 19:57:46 -0500 | [diff] [blame] | 304 | const std::string& getInventoryPath() const |
| 305 | { |
| 306 | return inventoryPath; |
| 307 | } |
| 308 | |
Brandon Wyman | c9efe41 | 2020-10-09 15:42:50 -0500 | [diff] [blame] | 309 | /** |
| 310 | * @brief Returns the firmware revision version read from the power supply |
| 311 | */ |
| 312 | const std::string& getFWVersion() const |
| 313 | { |
| 314 | return fwVersion; |
| 315 | } |
| 316 | |
Adriana Kobylak | 572a905 | 2021-03-30 15:58:07 +0000 | [diff] [blame] | 317 | /** |
| 318 | * @brief Returns the model name of the power supply |
| 319 | */ |
| 320 | const std::string& getModelName() const |
| 321 | { |
| 322 | return modelName; |
| 323 | } |
| 324 | |
Brandon Wyman | f65c406 | 2020-08-19 13:15:53 -0500 | [diff] [blame] | 325 | /** @brief Returns true if the number of failed reads exceeds limit |
| 326 | * TODO: or CML bit on. |
| 327 | */ |
| 328 | bool hasCommFault() const |
| 329 | { |
Brandon Wyman | 85c7bf4 | 2021-10-19 22:28:48 +0000 | [diff] [blame] | 330 | return ((readFail >= LOG_LIMIT) || (cmlFault)); |
Brandon Wyman | f65c406 | 2020-08-19 13:15:53 -0500 | [diff] [blame] | 331 | } |
| 332 | |
Adriana Kobylak | 4175ffb | 2021-08-02 14:51:05 +0000 | [diff] [blame] | 333 | /** |
| 334 | * @brief Reads the pmbus input voltage and returns that actual voltage |
| 335 | * reading and the calculated input voltage based on thresholds. |
| 336 | * @param[out] actualInputVoltage - The actual voltage reading, in Volts. |
| 337 | * @param[out] inputVoltage - A rounded up/down value of the actual input |
| 338 | * voltage based on thresholds, in Volts. |
| 339 | */ |
| 340 | void getInputVoltage(double& actualInputVoltage, int& inputVoltage) const; |
| 341 | |
Brandon Wyman | a0f33ce | 2019-10-17 18:32:29 -0500 | [diff] [blame] | 342 | private: |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 343 | /** @brief systemd bus member */ |
| 344 | sdbusplus::bus::bus& bus; |
| 345 | |
Brandon Wyman | 9564e94 | 2020-11-10 14:01:42 -0600 | [diff] [blame] | 346 | /** @brief Will be updated to the latest/lastvalue read from STATUS_WORD.*/ |
Brandon Wyman | fed0ba2 | 2020-09-26 20:02:51 -0500 | [diff] [blame] | 347 | uint64_t statusWord = 0; |
| 348 | |
Brandon Wyman | f07bc79 | 2021-10-12 19:00:35 +0000 | [diff] [blame] | 349 | /** @brief Will be updated to the latest/lastvalue read from STATUS_INPUT.*/ |
| 350 | uint64_t statusInput = 0; |
| 351 | |
Jay Meyer | 10d9405 | 2020-11-30 14:41:21 -0600 | [diff] [blame] | 352 | /** @brief Will be updated to the latest/lastvalue read from STATUS_MFR.*/ |
| 353 | uint64_t statusMFR = 0; |
| 354 | |
Brandon Wyman | 85c7bf4 | 2021-10-19 22:28:48 +0000 | [diff] [blame] | 355 | /** @brief Will be updated to the latest/last value read from STATUS_CML.*/ |
| 356 | uint64_t statusCML = 0; |
| 357 | |
Brandon Wyman | 6710ba2 | 2021-10-27 17:39:31 +0000 | [diff] [blame] | 358 | /** @brief Will be updated to the latest/last value read from STATUS_VOUT.*/ |
| 359 | uint64_t statusVout = 0; |
| 360 | |
Brandon Wyman | b10b3be | 2021-11-09 22:12:15 +0000 | [diff] [blame] | 361 | /** @brief Will be updated to the latest/last value read from STATUS_IOUT.*/ |
| 362 | uint64_t statusIout = 0; |
| 363 | |
Brandon Wyman | 96893a4 | 2021-11-05 19:56:57 +0000 | [diff] [blame] | 364 | /** @brief Will be updated to the latest/last value read from |
| 365 | * STATUS_TEMPERATURE.*/ |
| 366 | uint64_t statusTemperature = 0; |
| 367 | |
Brandon Wyman | b76ab24 | 2020-09-16 18:06:06 -0500 | [diff] [blame] | 368 | /** @brief True if an error for a fault has already been logged. */ |
| 369 | bool faultLogged = false; |
| 370 | |
Brandon Wyman | 96893a4 | 2021-11-05 19:56:57 +0000 | [diff] [blame] | 371 | /** @brief True if bit 1 of STATUS_WORD low byte is on. */ |
Brandon Wyman | 85c7bf4 | 2021-10-19 22:28:48 +0000 | [diff] [blame] | 372 | bool cmlFault = false; |
| 373 | |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 374 | /** @brief True if bit 5 of STATUS_WORD high byte is on. */ |
| 375 | bool inputFault = false; |
| 376 | |
| 377 | /** @brief True if bit 4 of STATUS_WORD high byte is on. */ |
| 378 | bool mfrFault = false; |
| 379 | |
| 380 | /** @brief True if bit 3 of STATUS_WORD low byte is on. */ |
| 381 | bool vinUVFault = false; |
| 382 | |
Brandon Wyman | 6710ba2 | 2021-10-27 17:39:31 +0000 | [diff] [blame] | 383 | /** @brief True if bit 5 of STATUS_WORD low byte is on. */ |
| 384 | bool voutOVFault = false; |
| 385 | |
Brandon Wyman | b10b3be | 2021-11-09 22:12:15 +0000 | [diff] [blame] | 386 | /** @brief True if bit 4 of STATUS_WORD low byte is on. */ |
| 387 | bool ioutOCFault = false; |
| 388 | |
Brandon Wyman | 2cf4694 | 2021-10-28 19:09:16 +0000 | [diff] [blame] | 389 | /** @brief True if bit 7 of STATUS_WORD high byte is on and bit 5 (VOUT_OV) |
| 390 | * of low byte is off. */ |
| 391 | bool voutUVFault = false; |
| 392 | |
Brandon Wyman | 96893a4 | 2021-11-05 19:56:57 +0000 | [diff] [blame] | 393 | /** @brief True if bit 2 of STATUS_WORD low byte is on. */ |
| 394 | bool tempFault = false; |
| 395 | |
Brandon Wyman | 2cf4694 | 2021-10-28 19:09:16 +0000 | [diff] [blame] | 396 | /** |
| 397 | * @brief True if bit 11 or 6 of STATUS_WORD is on. PGOOD# is inactive, or |
Brandon Wyman | 2916ea5 | 2021-11-06 03:31:18 +0000 | [diff] [blame] | 398 | * the unit is off. |
| 399 | */ |
| 400 | bool pgoodFault = false; |
| 401 | |
Brandon Wyman | f65c406 | 2020-08-19 13:15:53 -0500 | [diff] [blame] | 402 | /** @brief Count of the number of read failures. */ |
| 403 | size_t readFail = 0; |
| 404 | |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 405 | /** |
| 406 | * @brief D-Bus path to use for this power supply's inventory status. |
| 407 | **/ |
| 408 | std::string inventoryPath; |
| 409 | |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 410 | /** |
| 411 | * @brief The libgpiod object for monitoring PSU presence |
| 412 | */ |
Adriana Kobylak | 3ca062a | 2021-10-20 15:27:23 +0000 | [diff] [blame] | 413 | std::unique_ptr<GPIOInterfaceBase> presenceGPIO = nullptr; |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 414 | |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 415 | /** @brief True if the power supply is present. */ |
| 416 | bool present = false; |
| 417 | |
Adriana Kobylak | 572a905 | 2021-03-30 15:58:07 +0000 | [diff] [blame] | 418 | /** @brief Power supply model name. */ |
| 419 | std::string modelName; |
| 420 | |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 421 | /** @brief D-Bus match variable used to subscribe to Present property |
| 422 | * changes. |
| 423 | **/ |
| 424 | std::unique_ptr<sdbusplus::bus::match_t> presentMatch; |
| 425 | |
| 426 | /** @brief D-Bus match variable used to subscribe for Present property |
| 427 | * interface added. |
| 428 | */ |
| 429 | std::unique_ptr<sdbusplus::bus::match_t> presentAddedMatch; |
| 430 | |
| 431 | /** |
Brandon Wyman | 8d19577 | 2020-01-27 15:03:51 -0600 | [diff] [blame] | 432 | * @brief Pointer to the PMBus interface |
| 433 | * |
| 434 | * Used to read or write to/from PMBus power supply devices. |
| 435 | */ |
Brandon Wyman | 9564e94 | 2020-11-10 14:01:42 -0600 | [diff] [blame] | 436 | std::unique_ptr<phosphor::pmbus::PMBusBase> pmbusIntf = nullptr; |
Brandon Wyman | 8d19577 | 2020-01-27 15:03:51 -0600 | [diff] [blame] | 437 | |
Brandon Wyman | c9efe41 | 2020-10-09 15:42:50 -0500 | [diff] [blame] | 438 | /** @brief Stored copy of the firmware version/revision string */ |
| 439 | std::string fwVersion; |
| 440 | |
Brandon Wyman | 8d19577 | 2020-01-27 15:03:51 -0600 | [diff] [blame] | 441 | /** |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 442 | * @brief The file system path used for binding the device driver. |
| 443 | */ |
| 444 | const std::filesystem::path bindPath; |
| 445 | |
| 446 | /* @brief The string to pass in for binding the device driver. */ |
| 447 | std::string bindDevice; |
| 448 | |
| 449 | /** |
| 450 | * @brief Binds or unbinds the power supply device driver |
| 451 | * |
| 452 | * Called when a presence change is detected to either bind the device |
| 453 | * driver for the power supply when it is installed, or unbind the device |
| 454 | * driver when the power supply is removed. |
| 455 | * |
| 456 | * Writes <device> to <path>/bind (or unbind) |
| 457 | * |
| 458 | * @param present - when true, will bind the device driver |
| 459 | * when false, will unbind the device driver |
| 460 | */ |
| 461 | void bindOrUnbindDriver(bool present); |
| 462 | |
| 463 | /** |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 464 | * @brief Updates the presence status by querying D-Bus |
| 465 | * |
| 466 | * The D-Bus inventory properties for this power supply will be read to |
| 467 | * determine if the power supply is present or not and update this |
| 468 | * object's present member variable to reflect current status. |
| 469 | **/ |
| 470 | void updatePresence(); |
| 471 | |
| 472 | /** |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 473 | * @brief Updates the power supply presence by reading the GPIO line. |
| 474 | */ |
| 475 | void updatePresenceGPIO(); |
| 476 | |
| 477 | /** |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 478 | * @brief Callback for inventory property changes |
| 479 | * |
| 480 | * Process change of Present property for power supply. |
| 481 | * |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 482 | * This is used if we are watching the D-Bus properties instead of reading |
| 483 | * the GPIO presence line ourselves. |
| 484 | * |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 485 | * @param[in] msg - Data associated with Present change signal |
| 486 | **/ |
| 487 | void inventoryChanged(sdbusplus::message::message& msg); |
Brandon Wyman | 9a507db | 2021-02-25 16:15:22 -0600 | [diff] [blame] | 488 | |
| 489 | /** |
| 490 | * @brief Callback for inventory property added. |
| 491 | * |
| 492 | * Process add of the interface with the Present property for power supply. |
| 493 | * |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 494 | * This is used if we are watching the D-Bus properties instead of reading |
| 495 | * the GPIO presence line ourselves. |
| 496 | * |
Brandon Wyman | 9a507db | 2021-02-25 16:15:22 -0600 | [diff] [blame] | 497 | * @param[in] msg - Data associated with Present add signal |
| 498 | **/ |
| 499 | void inventoryAdded(sdbusplus::message::message& msg); |
Brandon Wyman | a0f33ce | 2019-10-17 18:32:29 -0500 | [diff] [blame] | 500 | }; |
| 501 | |
| 502 | } // namespace phosphor::power::psu |