blob: 496218f5fe723db2f8e26335ea51c149e7388b83 [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 Wyman24e422f2017-07-25 19:40:14 -05005
Brandon Wyman1db9a9e2017-07-26 18:50:22 -05006namespace witherspoon
Brandon Wyman24e422f2017-07-25 19:40:14 -05007{
8namespace power
9{
10namespace psu
11{
12
Brandon Wyman10295542017-08-09 18:20:44 -050013namespace sdbusRule = sdbusplus::bus::match::rules;
14
Brandon Wyman24e422f2017-07-25 19:40:14 -050015/**
16 * @class PowerSupply
Brandon Wyman1db9a9e2017-07-26 18:50:22 -050017 * Represents a PMBus power supply device.
Brandon Wyman24e422f2017-07-25 19:40:14 -050018 */
Brandon Wyman1db9a9e2017-07-26 18:50:22 -050019class PowerSupply : public Device
Brandon Wyman24e422f2017-07-25 19:40:14 -050020{
21 public:
22 PowerSupply() = delete;
23 PowerSupply(const PowerSupply&) = delete;
Brandon Wyman24e422f2017-07-25 19:40:14 -050024 PowerSupply(PowerSupply&&) = default;
Brandon Wyman1db9a9e2017-07-26 18:50:22 -050025 PowerSupply& operator=(const PowerSupply&) = default;
Brandon Wyman24e422f2017-07-25 19:40:14 -050026 PowerSupply& operator=(PowerSupply&&) = default;
27 ~PowerSupply() = default;
28
Brandon Wyman1db9a9e2017-07-26 18:50:22 -050029 /**
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 Wyman442035f2017-08-08 15:58:45 -050036 * @param[in] bus - D-Bus bus object
Brandon Wyman1db9a9e2017-07-26 18:50:22 -050037 */
38 PowerSupply(const std::string& name, size_t inst,
Brandon Wyman442035f2017-08-08 15:58:45 -050039 const std::string& objpath,
40 const std::string& invpath,
Brandon Wyman10295542017-08-09 18:20:44 -050041 sdbusplus::bus::bus& bus);
Brandon Wyman1db9a9e2017-07-26 18:50:22 -050042
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 Wyman442035f2017-08-08 15:58:45 -050072
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 Wyman10295542017-08-09 18:20:44 -050086 * @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 Wyman442035f2017-08-08 15:58:45 -050094 * @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 Wyman10295542017-08-09 18:20:44 -0500113
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 Wyman24e422f2017-07-25 19:40:14 -0500131};
132
133}
134}
135}