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" |
| 5 | |
| 6 | #include <sdbusplus/bus/match.hpp> |
| 7 | |
Brandon Wyman | a0f33ce | 2019-10-17 18:32:29 -0500 | [diff] [blame] | 8 | namespace phosphor::power::psu |
| 9 | { |
| 10 | /** |
| 11 | * @class PowerSupply |
| 12 | * Represents a PMBus power supply device. |
| 13 | */ |
| 14 | class PowerSupply |
| 15 | { |
| 16 | public: |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 17 | PowerSupply() = delete; |
Brandon Wyman | a0f33ce | 2019-10-17 18:32:29 -0500 | [diff] [blame] | 18 | PowerSupply(const PowerSupply&) = delete; |
| 19 | PowerSupply(PowerSupply&&) = delete; |
| 20 | PowerSupply& operator=(const PowerSupply&) = delete; |
| 21 | PowerSupply& operator=(PowerSupply&&) = delete; |
| 22 | ~PowerSupply() = default; |
| 23 | |
| 24 | /** |
Brandon Wyman | c63941c | 2020-01-27 16:49:33 -0600 | [diff] [blame] | 25 | * @param[in] invpath - String for inventory path to use |
| 26 | * @param[in] i2cbus - The bus number this power supply is on |
| 27 | * @param[in] i2caddr - The 16-bit I2C address of the power supply |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 28 | */ |
Brandon Wyman | c63941c | 2020-01-27 16:49:33 -0600 | [diff] [blame] | 29 | PowerSupply(sdbusplus::bus::bus& bus, const std::string& invpath, |
| 30 | std::uint8_t i2cbus, const std::string& i2caddr) : |
| 31 | bus(bus), |
Brandon Wyman | 8d19577 | 2020-01-27 15:03:51 -0600 | [diff] [blame^] | 32 | inventoryPath(invpath), |
| 33 | pmbusIntf(phosphor::pmbus::createPMBus(i2cbus, i2caddr)) |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 34 | { |
| 35 | // Setup the functions to call when the D-Bus inventory path for the |
| 36 | // Present property changes. |
| 37 | presentMatch = std::make_unique<sdbusplus::bus::match_t>( |
| 38 | bus, |
| 39 | sdbusplus::bus::match::rules::propertiesChanged(inventoryPath, |
| 40 | INVENTORY_IFACE), |
| 41 | [this](auto& msg) { this->inventoryChanged(msg); }); |
| 42 | presentAddedMatch = std::make_unique<sdbusplus::bus::match_t>( |
| 43 | bus, |
| 44 | sdbusplus::bus::match::rules::interfacesAdded() + |
| 45 | sdbusplus::bus::match::rules::path_namespace(inventoryPath), |
| 46 | [this](auto& msg) { this->inventoryChanged(msg); }); |
| 47 | // Get the current state of the Present property. |
| 48 | updatePresence(); |
| 49 | } |
| 50 | |
| 51 | /** |
Brandon Wyman | a0f33ce | 2019-10-17 18:32:29 -0500 | [diff] [blame] | 52 | * Power supply specific function to analyze for faults/errors. |
| 53 | * |
| 54 | * Various PMBus status bits will be checked for fault conditions. |
| 55 | * If a certain fault bits are on, the appropriate error will be |
| 56 | * committed. |
| 57 | */ |
| 58 | void analyze() |
| 59 | { |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Write PMBus CLEAR_FAULTS |
| 64 | * |
| 65 | * This function will be called in various situations in order to clear |
| 66 | * any fault status bits that may have been set, in order to start over |
| 67 | * with a clean state. Presence changes and power state changes will |
| 68 | * want to clear any faults logged. |
| 69 | */ |
| 70 | void clearFaults() |
| 71 | { |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * @brief Adds properties to the inventory. |
| 76 | * |
| 77 | * Reads the values from the device and writes them to the |
| 78 | * associated power supply D-Bus inventory object. |
| 79 | * |
| 80 | * This needs to be done on startup, and each time the presence |
| 81 | * state changes. |
| 82 | * |
| 83 | * Properties added: |
| 84 | * - Serial Number |
| 85 | * - Part Number |
| 86 | * - CCIN (Customer Card Identification Number) - added as the Model |
| 87 | * - Firmware version |
| 88 | */ |
| 89 | void updateInventory() |
| 90 | { |
| 91 | } |
| 92 | |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 93 | /** |
| 94 | * @brief Accessor function to indicate present status |
| 95 | */ |
| 96 | bool isPresent() const |
| 97 | { |
| 98 | return present; |
| 99 | } |
| 100 | |
Brandon Wyman | a0f33ce | 2019-10-17 18:32:29 -0500 | [diff] [blame] | 101 | private: |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 102 | /** @brief systemd bus member */ |
| 103 | sdbusplus::bus::bus& bus; |
| 104 | |
Brandon Wyman | a0f33ce | 2019-10-17 18:32:29 -0500 | [diff] [blame] | 105 | /** @brief True if a fault has already been found and not cleared */ |
| 106 | bool faultFound = false; |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 107 | |
| 108 | /** |
| 109 | * @brief D-Bus path to use for this power supply's inventory status. |
| 110 | **/ |
| 111 | std::string inventoryPath; |
| 112 | |
| 113 | /** @brief True if the power supply is present. */ |
| 114 | bool present = false; |
| 115 | |
| 116 | /** @brief D-Bus match variable used to subscribe to Present property |
| 117 | * changes. |
| 118 | **/ |
| 119 | std::unique_ptr<sdbusplus::bus::match_t> presentMatch; |
| 120 | |
| 121 | /** @brief D-Bus match variable used to subscribe for Present property |
| 122 | * interface added. |
| 123 | */ |
| 124 | std::unique_ptr<sdbusplus::bus::match_t> presentAddedMatch; |
| 125 | |
| 126 | /** |
Brandon Wyman | 8d19577 | 2020-01-27 15:03:51 -0600 | [diff] [blame^] | 127 | * @brief Pointer to the PMBus interface |
| 128 | * |
| 129 | * Used to read or write to/from PMBus power supply devices. |
| 130 | */ |
| 131 | std::unique_ptr<phosphor::pmbus::PMBusBase> pmbusIntf; |
| 132 | |
| 133 | /** |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 134 | * @brief Updates the presence status by querying D-Bus |
| 135 | * |
| 136 | * The D-Bus inventory properties for this power supply will be read to |
| 137 | * determine if the power supply is present or not and update this |
| 138 | * object's present member variable to reflect current status. |
| 139 | **/ |
| 140 | void updatePresence(); |
| 141 | |
| 142 | /** |
| 143 | * @brief Callback for inventory property changes |
| 144 | * |
| 145 | * Process change of Present property for power supply. |
| 146 | * |
| 147 | * @param[in] msg - Data associated with Present change signal |
| 148 | **/ |
| 149 | void inventoryChanged(sdbusplus::message::message& msg); |
Brandon Wyman | a0f33ce | 2019-10-17 18:32:29 -0500 | [diff] [blame] | 150 | }; |
| 151 | |
| 152 | } // namespace phosphor::power::psu |