1 #pragma once
2 #include <sdbusplus/bus/match.hpp>
3 #include "device.hpp"
4 #include "pmbus.hpp"
5 
6 namespace witherspoon
7 {
8 namespace power
9 {
10 namespace psu
11 {
12 
13 namespace sdbusRule = sdbusplus::bus::match::rules;
14 
15 /**
16  * @class PowerSupply
17  * Represents a PMBus power supply device.
18  */
19 class PowerSupply : public Device
20 {
21     public:
22         PowerSupply() = delete;
23         PowerSupply(const PowerSupply&) = delete;
24         PowerSupply(PowerSupply&&) = default;
25         PowerSupply& operator=(const PowerSupply&) = default;
26         PowerSupply& operator=(PowerSupply&&) = default;
27         ~PowerSupply() = default;
28 
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
36          * @param[in] bus - D-Bus bus object
37          */
38         PowerSupply(const std::string& name, size_t inst,
39                     const std::string& objpath,
40                     const std::string& invpath,
41                     sdbusplus::bus::bus& bus);
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;
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         /**
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         /**
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;
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();
131 };
132 
133 }
134 }
135 }
136