blob: b4c2af6fc37299730461e3e6eb61ae4df5c4fd8a [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 McCarneyafb7fc32019-12-11 19:42:03 -060018#include "i2c_interface.hpp"
19
20#include <memory>
Shawn McCarneya2461b32019-10-24 18:53:01 -050021#include <string>
Shawn McCarneyafb7fc32019-12-11 19:42:03 -060022#include <utility>
Shawn McCarneya2461b32019-10-24 18:53:01 -050023
Shawn McCarneyea7385b2019-11-07 12:19:32 -060024namespace phosphor::power::regulators
Shawn McCarneya2461b32019-10-24 18:53:01 -050025{
26
27/**
28 * @class Device
29 *
30 * A hardware device, such as a voltage regulator or I/O expander.
31 */
32class Device
33{
34 public:
35 // Specify which compiler-generated methods we want
36 Device() = delete;
37 Device(const Device&) = delete;
38 Device(Device&&) = delete;
39 Device& operator=(const Device&) = delete;
40 Device& operator=(Device&&) = delete;
41 ~Device() = default;
42
43 /**
44 * Constructor.
45 *
46 * @param id unique device ID
Shawn McCarneyafb7fc32019-12-11 19:42:03 -060047 * @param isRegulator indicates whether this device is a voltage regulator
48 * @param fru Field-Replaceable Unit (FRU) for this device
49 * @param i2cInterface I2C interface to this device
Shawn McCarneya2461b32019-10-24 18:53:01 -050050 */
Shawn McCarneyafb7fc32019-12-11 19:42:03 -060051 explicit Device(const std::string& id, bool isRegulator,
52 const std::string& fru,
53 std::unique_ptr<i2c::I2CInterface> i2cInterface) :
54 id{id},
55 isRegulatorDevice{isRegulator}, fru{fru}, i2cInterface{
56 std::move(i2cInterface)}
Shawn McCarneya2461b32019-10-24 18:53:01 -050057 {
58 }
59
60 /**
61 * Returns the unique ID of this device.
62 *
63 * @return device ID
64 */
Shawn McCarney4afb2852019-10-27 18:28:53 -050065 const std::string& getID() const
Shawn McCarneya2461b32019-10-24 18:53:01 -050066 {
67 return id;
68 }
69
Shawn McCarneyafb7fc32019-12-11 19:42:03 -060070 /**
71 * Returns whether this device is a voltage regulator.
72 *
73 * @return true if device is a voltage regulator, false otherwise
74 */
75 bool isRegulator() const
76 {
77 return isRegulatorDevice;
78 }
79
80 /**
81 * Returns the Field-Replaceable Unit (FRU) for this device.
82 *
83 * Returns the D-Bus inventory path of the FRU. If the device itself is not
84 * a FRU, returns the FRU that contains the device.
85 *
86 * @return FRU for this device
87 */
88 const std::string& getFRU() const
89 {
90 return fru;
91 }
92
93 /**
94 * Gets the I2C interface to this device.
95 *
96 * @return I2C interface to device
97 */
98 i2c::I2CInterface& getI2CInterface()
99 {
100 return *i2cInterface;
101 }
102
Shawn McCarneya2461b32019-10-24 18:53:01 -0500103 private:
104 /**
105 * Unique ID of this device.
106 */
107 const std::string id{};
Shawn McCarneyafb7fc32019-12-11 19:42:03 -0600108
109 /**
110 * Indicates whether this device is a voltage regulator.
111 */
112 const bool isRegulatorDevice{false};
113
114 /**
115 * Field-Replaceable Unit (FRU) for this device.
116 *
117 * Set to the D-Bus inventory path of the FRU. If the device itself is not
118 * a FRU, set to the FRU that contains the device.
119 */
120 const std::string fru{};
121
122 /**
123 * I2C interface to this device.
124 */
125 std::unique_ptr<i2c::I2CInterface> i2cInterface{};
Shawn McCarneya2461b32019-10-24 18:53:01 -0500126};
127
Shawn McCarneyea7385b2019-11-07 12:19:32 -0600128} // namespace phosphor::power::regulators