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