Brandon Wyman | 24e422f | 2017-07-25 19:40:14 -0500 | [diff] [blame] | 1 | #pragma once |
Brandon Wyman | 1029554 | 2017-08-09 18:20:44 -0500 | [diff] [blame] | 2 | #include <sdbusplus/bus/match.hpp> |
Brandon Wyman | 1db9a9e | 2017-07-26 18:50:22 -0500 | [diff] [blame] | 3 | #include "device.hpp" |
Brandon Wyman | 442035f | 2017-08-08 15:58:45 -0500 | [diff] [blame] | 4 | #include "pmbus.hpp" |
Brandon Wyman | 24e422f | 2017-07-25 19:40:14 -0500 | [diff] [blame] | 5 | |
Brandon Wyman | 1db9a9e | 2017-07-26 18:50:22 -0500 | [diff] [blame] | 6 | namespace witherspoon |
Brandon Wyman | 24e422f | 2017-07-25 19:40:14 -0500 | [diff] [blame] | 7 | { |
| 8 | namespace power |
| 9 | { |
| 10 | namespace psu |
| 11 | { |
| 12 | |
Brandon Wyman | 1029554 | 2017-08-09 18:20:44 -0500 | [diff] [blame] | 13 | namespace sdbusRule = sdbusplus::bus::match::rules; |
| 14 | |
Brandon Wyman | 24e422f | 2017-07-25 19:40:14 -0500 | [diff] [blame] | 15 | /** |
| 16 | * @class PowerSupply |
Brandon Wyman | 1db9a9e | 2017-07-26 18:50:22 -0500 | [diff] [blame] | 17 | * Represents a PMBus power supply device. |
Brandon Wyman | 24e422f | 2017-07-25 19:40:14 -0500 | [diff] [blame] | 18 | */ |
Brandon Wyman | 1db9a9e | 2017-07-26 18:50:22 -0500 | [diff] [blame] | 19 | class PowerSupply : public Device |
Brandon Wyman | 24e422f | 2017-07-25 19:40:14 -0500 | [diff] [blame] | 20 | { |
| 21 | public: |
| 22 | PowerSupply() = delete; |
| 23 | PowerSupply(const PowerSupply&) = delete; |
Brandon Wyman | 24e422f | 2017-07-25 19:40:14 -0500 | [diff] [blame] | 24 | PowerSupply(PowerSupply&&) = default; |
Brandon Wyman | 1db9a9e | 2017-07-26 18:50:22 -0500 | [diff] [blame] | 25 | PowerSupply& operator=(const PowerSupply&) = default; |
Brandon Wyman | 24e422f | 2017-07-25 19:40:14 -0500 | [diff] [blame] | 26 | PowerSupply& operator=(PowerSupply&&) = default; |
| 27 | ~PowerSupply() = default; |
| 28 | |
Brandon Wyman | 1db9a9e | 2017-07-26 18:50:22 -0500 | [diff] [blame] | 29 | /** |
| 30 | * Constructor |
| 31 | * |
| 32 | * @param[in] name - the device name |
| 33 | * @param[in] inst - the device instance |
| 34 | * @param[in] objpath - the path to monitor |
| 35 | * @param[in] invpath - the inventory path to use |
Brandon Wyman | 442035f | 2017-08-08 15:58:45 -0500 | [diff] [blame] | 36 | * @param[in] bus - D-Bus bus object |
Brandon Wyman | 1db9a9e | 2017-07-26 18:50:22 -0500 | [diff] [blame] | 37 | */ |
| 38 | PowerSupply(const std::string& name, size_t inst, |
Brandon Wyman | 442035f | 2017-08-08 15:58:45 -0500 | [diff] [blame] | 39 | const std::string& objpath, |
| 40 | const std::string& invpath, |
Brandon Wyman | 1029554 | 2017-08-09 18:20:44 -0500 | [diff] [blame] | 41 | sdbusplus::bus::bus& bus); |
Brandon Wyman | 1db9a9e | 2017-07-26 18:50:22 -0500 | [diff] [blame] | 42 | |
| 43 | /** |
| 44 | * Power supply specific function to analyze for faults/errors. |
| 45 | * |
| 46 | * Various PMBus status bits will be checked for fault conditions. |
| 47 | * If a certain fault bits are on, the appropriate error will be |
| 48 | * committed. |
| 49 | */ |
| 50 | void analyze() override; |
| 51 | |
| 52 | /** |
| 53 | * Write PMBus CLEAR_FAULTS |
| 54 | * |
| 55 | * This function will be called in various situations in order to clear |
| 56 | * any fault status bits that may have been set, in order to start over |
| 57 | * with a clean state. Presence changes and power state changes will |
| 58 | * want to clear any faults logged. |
| 59 | */ |
| 60 | void clearFaults() override; |
| 61 | |
| 62 | private: |
| 63 | /** |
| 64 | * The path to use for reading various PMBus bits/words. |
| 65 | */ |
| 66 | std::string monitorPath; |
| 67 | |
| 68 | /** |
| 69 | * The D-Bus path to use for this power supply's inventory status. |
| 70 | */ |
| 71 | std::string inventoryPath; |
Brandon Wyman | 442035f | 2017-08-08 15:58:45 -0500 | [diff] [blame] | 72 | |
| 73 | /** @brief Connection for sdbusplus bus */ |
| 74 | sdbusplus::bus::bus& bus; |
| 75 | |
| 76 | /** |
| 77 | * @brief Pointer to the PMBus interface |
| 78 | * |
| 79 | * Used to read out of or write to the /sysfs tree(s) containing files |
| 80 | * that a device driver monitors the PMBus interface to the power |
| 81 | * supplies. |
| 82 | */ |
| 83 | witherspoon::pmbus::PMBus pmbusIntf; |
| 84 | |
| 85 | /** |
Brandon Wyman | 1029554 | 2017-08-09 18:20:44 -0500 | [diff] [blame] | 86 | * @brief True if the power supply is present. |
| 87 | */ |
| 88 | bool present = false; |
| 89 | |
| 90 | /** @brief Used to subscribe to dbus pcap propety changes **/ |
| 91 | std::unique_ptr<sdbusplus::bus::match_t> presentMatch; |
| 92 | |
| 93 | /** |
Brandon Wyman | 442035f | 2017-08-08 15:58:45 -0500 | [diff] [blame] | 94 | * @brief Has a PMBus read failure already been logged? |
| 95 | */ |
| 96 | bool readFailLogged = false; |
| 97 | |
| 98 | /** |
| 99 | * @brief Set to true when a VIN UV fault has been detected |
| 100 | * |
| 101 | * This is the VIN_UV_FAULT bit in the low byte from the STATUS_WORD |
| 102 | * command response. |
| 103 | */ |
| 104 | bool vinUVFault = false; |
| 105 | |
| 106 | /** |
| 107 | * @brief Set to true when an input fault or warning is detected |
| 108 | * |
| 109 | * This is the "INPUT FAULT OR WARNING" bit in the high byte from the |
| 110 | * STATUS_WORD command response. |
| 111 | */ |
| 112 | bool inputFault = false; |
Brandon Wyman | 1029554 | 2017-08-09 18:20:44 -0500 | [diff] [blame] | 113 | |
| 114 | /** @brief Callback for inventory property changes |
| 115 | * |
| 116 | * Process change of Present property for power supply. |
| 117 | * |
| 118 | * @param[in] msg - Data associated with Present change signal |
| 119 | * |
| 120 | */ |
| 121 | void inventoryChanged(sdbusplus::message::message& msg); |
| 122 | |
| 123 | /** |
| 124 | * Updates the presence status by querying D-Bus |
| 125 | * |
| 126 | * The D-Bus inventory properties for this power supply will be read to |
| 127 | * determine if the power supply is present or not and update this |
| 128 | * objects present member variable to reflect current status. |
| 129 | */ |
| 130 | void updatePresence(); |
Brandon Wyman | 24e422f | 2017-07-25 19:40:14 -0500 | [diff] [blame] | 131 | }; |
| 132 | |
| 133 | } |
| 134 | } |
| 135 | } |