blob: e9bd9f3787aecd36c33fbdfb3227e20f0407679a [file] [log] [blame]
Brandon Wyman24e422f2017-07-25 19:40:14 -05001#pragma once
Brandon Wyman10295542017-08-09 18:20:44 -05002#include <sdbusplus/bus/match.hpp>
Brandon Wyman1db9a9e2017-07-26 18:50:22 -05003#include "device.hpp"
Brandon Wyman442035f2017-08-08 15:58:45 -05004#include "pmbus.hpp"
Brandon Wyman431fbe42017-08-18 16:22:09 -05005#include "timer.hpp"
Brandon Wyman24e422f2017-07-25 19:40:14 -05006
Brandon Wyman1db9a9e2017-07-26 18:50:22 -05007namespace witherspoon
Brandon Wyman24e422f2017-07-25 19:40:14 -05008{
9namespace power
10{
11namespace psu
12{
13
Brandon Wyman10295542017-08-09 18:20:44 -050014namespace sdbusRule = sdbusplus::bus::match::rules;
15
Brandon Wyman24e422f2017-07-25 19:40:14 -050016/**
17 * @class PowerSupply
Brandon Wyman1db9a9e2017-07-26 18:50:22 -050018 * Represents a PMBus power supply device.
Brandon Wyman24e422f2017-07-25 19:40:14 -050019 */
Brandon Wyman1db9a9e2017-07-26 18:50:22 -050020class PowerSupply : public Device
Brandon Wyman24e422f2017-07-25 19:40:14 -050021{
22 public:
23 PowerSupply() = delete;
24 PowerSupply(const PowerSupply&) = delete;
Brandon Wyman24e422f2017-07-25 19:40:14 -050025 PowerSupply(PowerSupply&&) = default;
Brandon Wyman1db9a9e2017-07-26 18:50:22 -050026 PowerSupply& operator=(const PowerSupply&) = default;
Brandon Wyman24e422f2017-07-25 19:40:14 -050027 PowerSupply& operator=(PowerSupply&&) = default;
28 ~PowerSupply() = default;
29
Brandon Wyman1db9a9e2017-07-26 18:50:22 -050030 /**
31 * Constructor
32 *
33 * @param[in] name - the device name
34 * @param[in] inst - the device instance
35 * @param[in] objpath - the path to monitor
36 * @param[in] invpath - the inventory path to use
Brandon Wyman442035f2017-08-08 15:58:45 -050037 * @param[in] bus - D-Bus bus object
Brandon Wyman431fbe42017-08-18 16:22:09 -050038 * @param[in] e - event object
39 * @param[in] t - time to allow power supply to assert PG#
Brandon Wyman1db9a9e2017-07-26 18:50:22 -050040 */
41 PowerSupply(const std::string& name, size_t inst,
Brandon Wyman442035f2017-08-08 15:58:45 -050042 const std::string& objpath,
43 const std::string& invpath,
Brandon Wyman431fbe42017-08-18 16:22:09 -050044 sdbusplus::bus::bus& bus,
45 event::Event& e,
46 std::chrono::seconds& t);
Brandon Wyman1db9a9e2017-07-26 18:50:22 -050047
48 /**
49 * Power supply specific function to analyze for faults/errors.
50 *
51 * Various PMBus status bits will be checked for fault conditions.
52 * If a certain fault bits are on, the appropriate error will be
53 * committed.
54 */
55 void analyze() override;
56
57 /**
58 * Write PMBus CLEAR_FAULTS
59 *
60 * This function will be called in various situations in order to clear
61 * any fault status bits that may have been set, in order to start over
62 * with a clean state. Presence changes and power state changes will
63 * want to clear any faults logged.
64 */
65 void clearFaults() override;
66
67 private:
68 /**
69 * The path to use for reading various PMBus bits/words.
70 */
71 std::string monitorPath;
72
73 /**
Brandon Wyman442035f2017-08-08 15:58:45 -050074 * @brief Pointer to the PMBus interface
75 *
76 * Used to read out of or write to the /sysfs tree(s) containing files
77 * that a device driver monitors the PMBus interface to the power
78 * supplies.
79 */
80 witherspoon::pmbus::PMBus pmbusIntf;
81
82 /**
Brandon Wyman431fbe42017-08-18 16:22:09 -050083 * @brief D-Bus path to use for this power supply's inventory status.
Brandon Wyman10295542017-08-09 18:20:44 -050084 */
Brandon Wyman431fbe42017-08-18 16:22:09 -050085 std::string inventoryPath;
86
87 /** @brief Connection for sdbusplus bus */
88 sdbusplus::bus::bus& bus;
89
90 /** @brief True if the power supply is present. */
Brandon Wyman10295542017-08-09 18:20:44 -050091 bool present = false;
92
Brandon Wyman431fbe42017-08-18 16:22:09 -050093 /** @brief Used to subscribe to D-Bus property changes to Present **/
Brandon Wyman10295542017-08-09 18:20:44 -050094 std::unique_ptr<sdbusplus::bus::match_t> presentMatch;
95
Brandon Wyman431fbe42017-08-18 16:22:09 -050096 /** @brief True if the power is on. */
97 bool powerOn = false;
98
Brandon Wyman764c7972017-08-22 17:05:36 -050099 /** @brief True if power on fault has been detected/reported. */
100 bool powerOnFault = false;
101
Brandon Wyman431fbe42017-08-18 16:22:09 -0500102 /** @brief The sd_event structure used by the power on timer. */
103 event::Event& event;
104
105 /**
106 * @brief Interval to setting powerOn to true.
107 *
108 * The amount of time to wait from power state on to setting the
109 * internal powerOn state to true. The amount of time the power supply
110 * is allowed to delay setting DGood/PG#.
111 */
112 std::chrono::seconds powerOnInterval;
113
114 /**
115 * @brief Timer used to delay setting the internal powerOn state.
116 *
117 * The timer used to do the callback after the power state has been on
118 * long enough.
119 */
120 Timer powerOnTimer;
121
122 /** @brief Used to subscribe to D-Bus power on state changes **/
123 std::unique_ptr<sdbusplus::bus::match_t> powerOnMatch;
124
Brandon Wyman764c7972017-08-22 17:05:36 -0500125 /** @brief Has a PMBus read failure already been logged? */
Brandon Wyman442035f2017-08-08 15:58:45 -0500126 bool readFailLogged = false;
127
128 /**
129 * @brief Set to true when a VIN UV fault has been detected
130 *
131 * This is the VIN_UV_FAULT bit in the low byte from the STATUS_WORD
132 * command response.
133 */
134 bool vinUVFault = false;
135
136 /**
137 * @brief Set to true when an input fault or warning is detected
138 *
139 * This is the "INPUT FAULT OR WARNING" bit in the high byte from the
140 * STATUS_WORD command response.
141 */
142 bool inputFault = false;
Brandon Wyman10295542017-08-09 18:20:44 -0500143
Brandon Wyman764c7972017-08-22 17:05:36 -0500144 /**
145 * @brief Callback for inventory property changes
Brandon Wyman10295542017-08-09 18:20:44 -0500146 *
147 * Process change of Present property for power supply.
148 *
149 * @param[in] msg - Data associated with Present change signal
150 *
151 */
152 void inventoryChanged(sdbusplus::message::message& msg);
153
154 /**
155 * Updates the presence status by querying D-Bus
156 *
157 * The D-Bus inventory properties for this power supply will be read to
158 * determine if the power supply is present or not and update this
159 * objects present member variable to reflect current status.
160 */
161 void updatePresence();
Brandon Wyman431fbe42017-08-18 16:22:09 -0500162
163 /**
164 * @brief Updates the poweredOn status by querying D-Bus
165 *
166 * The D-Bus property for the sytem power state will be read to
167 * determine if the system is powered on or not.
168 */
169 void updatePowerState();
170
Brandon Wyman764c7972017-08-22 17:05:36 -0500171 /**
172 * @brief Callback for power state property changes
173 *
Brandon Wyman431fbe42017-08-18 16:22:09 -0500174 * Process changes to the powered on stat property for the system.
175 *
176 * @param[in] msg - Data associated with the power state signal
177 */
178 void powerStateChanged(sdbusplus::message::message& msg);
179
Brandon Wyman24e422f2017-07-25 19:40:14 -0500180};
181
182}
183}
184}