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