blob: 919899a22eaf7d1004f7ffe5061760c734d88df6 [file] [log] [blame]
Shawn McCarneya2461b32019-10-24 18:53:01 -05001/**
2 * Copyright © 2019 IBM Corporation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#pragma once
17
Shawn McCarney0b1a0e72020-03-11 18:01:44 -050018#include "configuration.hpp"
Shawn McCarneyafb7fc32019-12-11 19:42:03 -060019#include "i2c_interface.hpp"
Shawn McCarneydb0b8332020-04-06 14:13:04 -050020#include "id_map.hpp"
Shawn McCarney0b1a0e72020-03-11 18:01:44 -050021#include "presence_detection.hpp"
22#include "rail.hpp"
Shawn McCarneyafb7fc32019-12-11 19:42:03 -060023
24#include <memory>
Shawn McCarneya2461b32019-10-24 18:53:01 -050025#include <string>
Shawn McCarneyafb7fc32019-12-11 19:42:03 -060026#include <utility>
Shawn McCarney0b1a0e72020-03-11 18:01:44 -050027#include <vector>
Shawn McCarneya2461b32019-10-24 18:53:01 -050028
Shawn McCarneyea7385b2019-11-07 12:19:32 -060029namespace phosphor::power::regulators
Shawn McCarneya2461b32019-10-24 18:53:01 -050030{
31
32/**
33 * @class Device
34 *
35 * A hardware device, such as a voltage regulator or I/O expander.
36 */
37class Device
38{
39 public:
40 // Specify which compiler-generated methods we want
41 Device() = delete;
42 Device(const Device&) = delete;
43 Device(Device&&) = delete;
44 Device& operator=(const Device&) = delete;
45 Device& operator=(Device&&) = delete;
46 ~Device() = default;
47
48 /**
49 * Constructor.
50 *
51 * @param id unique device ID
Shawn McCarneyafb7fc32019-12-11 19:42:03 -060052 * @param isRegulator indicates whether this device is a voltage regulator
53 * @param fru Field-Replaceable Unit (FRU) for this device
54 * @param i2cInterface I2C interface to this device
Shawn McCarney0b1a0e72020-03-11 18:01:44 -050055 * @param presenceDetection presence detection for this device, if any
56 * @param configuration configuration changes to apply to this device, if
57 * any
58 * @param rails voltage rails produced by this device, if any
Shawn McCarneya2461b32019-10-24 18:53:01 -050059 */
Shawn McCarney0b1a0e72020-03-11 18:01:44 -050060 explicit Device(
61 const std::string& id, bool isRegulator, const std::string& fru,
62 std::unique_ptr<i2c::I2CInterface> i2cInterface,
63 std::unique_ptr<PresenceDetection> presenceDetection = nullptr,
64 std::unique_ptr<Configuration> configuration = nullptr,
65 std::vector<std::unique_ptr<Rail>> rails =
66 std::vector<std::unique_ptr<Rail>>{}) :
Shawn McCarneyafb7fc32019-12-11 19:42:03 -060067 id{id},
Shawn McCarney0b1a0e72020-03-11 18:01:44 -050068 isRegulatorDevice{isRegulator}, fru{fru},
69 i2cInterface{std::move(i2cInterface)}, presenceDetection{std::move(
70 presenceDetection)},
71 configuration{std::move(configuration)}, rails{std::move(rails)}
Shawn McCarneya2461b32019-10-24 18:53:01 -050072 {
73 }
74
75 /**
Shawn McCarneydb0b8332020-04-06 14:13:04 -050076 * Adds this Device object to the specified IDMap.
77 *
78 * Also adds any Rail objects in this Device to the IDMap.
79 *
80 * @param idMap mapping from IDs to the associated Device/Rail/Rule objects
81 */
82 void addToIDMap(IDMap& idMap);
83
84 /**
Shawn McCarney0b1a0e72020-03-11 18:01:44 -050085 * Returns the configuration changes to apply to this device, if any.
Shawn McCarneya2461b32019-10-24 18:53:01 -050086 *
Shawn McCarney0b1a0e72020-03-11 18:01:44 -050087 * @return Pointer to Configuration object. Will equal nullptr if no
88 * configuration changes are defined for this device.
Shawn McCarneya2461b32019-10-24 18:53:01 -050089 */
Shawn McCarney0b1a0e72020-03-11 18:01:44 -050090 const std::unique_ptr<Configuration>& getConfiguration() const
Shawn McCarneya2461b32019-10-24 18:53:01 -050091 {
Shawn McCarney0b1a0e72020-03-11 18:01:44 -050092 return configuration;
Shawn McCarneyafb7fc32019-12-11 19:42:03 -060093 }
94
95 /**
96 * Returns the Field-Replaceable Unit (FRU) for this device.
97 *
98 * Returns the D-Bus inventory path of the FRU. If the device itself is not
99 * a FRU, returns the FRU that contains the device.
100 *
101 * @return FRU for this device
102 */
103 const std::string& getFRU() const
104 {
105 return fru;
106 }
107
108 /**
Shawn McCarney0b1a0e72020-03-11 18:01:44 -0500109 * Returns the I2C interface to this device.
Shawn McCarneyafb7fc32019-12-11 19:42:03 -0600110 *
111 * @return I2C interface to device
112 */
113 i2c::I2CInterface& getI2CInterface()
114 {
115 return *i2cInterface;
116 }
117
Shawn McCarney0b1a0e72020-03-11 18:01:44 -0500118 /**
119 * Returns the unique ID of this device.
120 *
121 * @return device ID
122 */
123 const std::string& getID() const
124 {
125 return id;
126 }
127
128 /**
129 * Returns the presence detection for this device, if any.
130 *
131 * @return Pointer to PresenceDetection object. Will equal nullptr if no
132 * presence detection is defined for this device.
133 */
134 const std::unique_ptr<PresenceDetection>& getPresenceDetection() const
135 {
136 return presenceDetection;
137 }
138
139 /**
140 * Returns the voltage rails produced by this device, if any.
141 *
142 * @return voltage rails
143 */
144 const std::vector<std::unique_ptr<Rail>>& getRails() const
145 {
146 return rails;
147 }
148
149 /**
150 * Returns whether this device is a voltage regulator.
151 *
152 * @return true if device is a voltage regulator, false otherwise
153 */
154 bool isRegulator() const
155 {
156 return isRegulatorDevice;
157 }
158
Shawn McCarneya2461b32019-10-24 18:53:01 -0500159 private:
160 /**
161 * Unique ID of this device.
162 */
163 const std::string id{};
Shawn McCarneyafb7fc32019-12-11 19:42:03 -0600164
165 /**
166 * Indicates whether this device is a voltage regulator.
167 */
168 const bool isRegulatorDevice{false};
169
170 /**
171 * Field-Replaceable Unit (FRU) for this device.
172 *
173 * Set to the D-Bus inventory path of the FRU. If the device itself is not
174 * a FRU, set to the FRU that contains the device.
175 */
176 const std::string fru{};
177
178 /**
179 * I2C interface to this device.
180 */
181 std::unique_ptr<i2c::I2CInterface> i2cInterface{};
Shawn McCarney0b1a0e72020-03-11 18:01:44 -0500182
183 /**
184 * Presence detection for this device, if any. Set to nullptr if no
185 * presence detection is defined for this device.
186 */
187 std::unique_ptr<PresenceDetection> presenceDetection{};
188
189 /**
190 * Configuration changes to apply to this device, if any. Set to nullptr if
191 * no configuration changes are defined for this device.
192 */
193 std::unique_ptr<Configuration> configuration{};
194
195 /**
196 * Voltage rails produced by this device, if any. Vector is empty if no
197 * voltage rails are defined for this device.
198 */
199 std::vector<std::unique_ptr<Rail>> rails{};
Shawn McCarneya2461b32019-10-24 18:53:01 -0500200};
201
Shawn McCarneyea7385b2019-11-07 12:19:32 -0600202} // namespace phosphor::power::regulators