Shawn McCarney | a2461b3 | 2019-10-24 18:53:01 -0500 | [diff] [blame] | 1 | /** |
| 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 McCarney | 0b1a0e7 | 2020-03-11 18:01:44 -0500 | [diff] [blame] | 18 | #include "configuration.hpp" |
Shawn McCarney | afb7fc3 | 2019-12-11 19:42:03 -0600 | [diff] [blame] | 19 | #include "i2c_interface.hpp" |
Shawn McCarney | 0b1a0e7 | 2020-03-11 18:01:44 -0500 | [diff] [blame] | 20 | #include "presence_detection.hpp" |
| 21 | #include "rail.hpp" |
Shawn McCarney | afb7fc3 | 2019-12-11 19:42:03 -0600 | [diff] [blame] | 22 | |
| 23 | #include <memory> |
Shawn McCarney | a2461b3 | 2019-10-24 18:53:01 -0500 | [diff] [blame] | 24 | #include <string> |
Shawn McCarney | afb7fc3 | 2019-12-11 19:42:03 -0600 | [diff] [blame] | 25 | #include <utility> |
Shawn McCarney | 0b1a0e7 | 2020-03-11 18:01:44 -0500 | [diff] [blame] | 26 | #include <vector> |
Shawn McCarney | a2461b3 | 2019-10-24 18:53:01 -0500 | [diff] [blame] | 27 | |
Shawn McCarney | ea7385b | 2019-11-07 12:19:32 -0600 | [diff] [blame] | 28 | namespace phosphor::power::regulators |
Shawn McCarney | a2461b3 | 2019-10-24 18:53:01 -0500 | [diff] [blame] | 29 | { |
| 30 | |
| 31 | /** |
| 32 | * @class Device |
| 33 | * |
| 34 | * A hardware device, such as a voltage regulator or I/O expander. |
| 35 | */ |
| 36 | class Device |
| 37 | { |
| 38 | public: |
| 39 | // Specify which compiler-generated methods we want |
| 40 | Device() = delete; |
| 41 | Device(const Device&) = delete; |
| 42 | Device(Device&&) = delete; |
| 43 | Device& operator=(const Device&) = delete; |
| 44 | Device& operator=(Device&&) = delete; |
| 45 | ~Device() = default; |
| 46 | |
| 47 | /** |
| 48 | * Constructor. |
| 49 | * |
| 50 | * @param id unique device ID |
Shawn McCarney | afb7fc3 | 2019-12-11 19:42:03 -0600 | [diff] [blame] | 51 | * @param isRegulator indicates whether this device is a voltage regulator |
| 52 | * @param fru Field-Replaceable Unit (FRU) for this device |
| 53 | * @param i2cInterface I2C interface to this device |
Shawn McCarney | 0b1a0e7 | 2020-03-11 18:01:44 -0500 | [diff] [blame] | 54 | * @param presenceDetection presence detection for this device, if any |
| 55 | * @param configuration configuration changes to apply to this device, if |
| 56 | * any |
| 57 | * @param rails voltage rails produced by this device, if any |
Shawn McCarney | a2461b3 | 2019-10-24 18:53:01 -0500 | [diff] [blame] | 58 | */ |
Shawn McCarney | 0b1a0e7 | 2020-03-11 18:01:44 -0500 | [diff] [blame] | 59 | explicit Device( |
| 60 | const std::string& id, bool isRegulator, const std::string& fru, |
| 61 | std::unique_ptr<i2c::I2CInterface> i2cInterface, |
| 62 | std::unique_ptr<PresenceDetection> presenceDetection = nullptr, |
| 63 | std::unique_ptr<Configuration> configuration = nullptr, |
| 64 | std::vector<std::unique_ptr<Rail>> rails = |
| 65 | std::vector<std::unique_ptr<Rail>>{}) : |
Shawn McCarney | afb7fc3 | 2019-12-11 19:42:03 -0600 | [diff] [blame] | 66 | id{id}, |
Shawn McCarney | 0b1a0e7 | 2020-03-11 18:01:44 -0500 | [diff] [blame] | 67 | isRegulatorDevice{isRegulator}, fru{fru}, |
| 68 | i2cInterface{std::move(i2cInterface)}, presenceDetection{std::move( |
| 69 | presenceDetection)}, |
| 70 | configuration{std::move(configuration)}, rails{std::move(rails)} |
Shawn McCarney | a2461b3 | 2019-10-24 18:53:01 -0500 | [diff] [blame] | 71 | { |
| 72 | } |
| 73 | |
| 74 | /** |
Shawn McCarney | 0b1a0e7 | 2020-03-11 18:01:44 -0500 | [diff] [blame] | 75 | * Returns the configuration changes to apply to this device, if any. |
Shawn McCarney | a2461b3 | 2019-10-24 18:53:01 -0500 | [diff] [blame] | 76 | * |
Shawn McCarney | 0b1a0e7 | 2020-03-11 18:01:44 -0500 | [diff] [blame] | 77 | * @return Pointer to Configuration object. Will equal nullptr if no |
| 78 | * configuration changes are defined for this device. |
Shawn McCarney | a2461b3 | 2019-10-24 18:53:01 -0500 | [diff] [blame] | 79 | */ |
Shawn McCarney | 0b1a0e7 | 2020-03-11 18:01:44 -0500 | [diff] [blame] | 80 | const std::unique_ptr<Configuration>& getConfiguration() const |
Shawn McCarney | a2461b3 | 2019-10-24 18:53:01 -0500 | [diff] [blame] | 81 | { |
Shawn McCarney | 0b1a0e7 | 2020-03-11 18:01:44 -0500 | [diff] [blame] | 82 | return configuration; |
Shawn McCarney | afb7fc3 | 2019-12-11 19:42:03 -0600 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | /** |
| 86 | * Returns the Field-Replaceable Unit (FRU) for this device. |
| 87 | * |
| 88 | * Returns the D-Bus inventory path of the FRU. If the device itself is not |
| 89 | * a FRU, returns the FRU that contains the device. |
| 90 | * |
| 91 | * @return FRU for this device |
| 92 | */ |
| 93 | const std::string& getFRU() const |
| 94 | { |
| 95 | return fru; |
| 96 | } |
| 97 | |
| 98 | /** |
Shawn McCarney | 0b1a0e7 | 2020-03-11 18:01:44 -0500 | [diff] [blame] | 99 | * Returns the I2C interface to this device. |
Shawn McCarney | afb7fc3 | 2019-12-11 19:42:03 -0600 | [diff] [blame] | 100 | * |
| 101 | * @return I2C interface to device |
| 102 | */ |
| 103 | i2c::I2CInterface& getI2CInterface() |
| 104 | { |
| 105 | return *i2cInterface; |
| 106 | } |
| 107 | |
Shawn McCarney | 0b1a0e7 | 2020-03-11 18:01:44 -0500 | [diff] [blame] | 108 | /** |
| 109 | * Returns the unique ID of this device. |
| 110 | * |
| 111 | * @return device ID |
| 112 | */ |
| 113 | const std::string& getID() const |
| 114 | { |
| 115 | return id; |
| 116 | } |
| 117 | |
| 118 | /** |
| 119 | * Returns the presence detection for this device, if any. |
| 120 | * |
| 121 | * @return Pointer to PresenceDetection object. Will equal nullptr if no |
| 122 | * presence detection is defined for this device. |
| 123 | */ |
| 124 | const std::unique_ptr<PresenceDetection>& getPresenceDetection() const |
| 125 | { |
| 126 | return presenceDetection; |
| 127 | } |
| 128 | |
| 129 | /** |
| 130 | * Returns the voltage rails produced by this device, if any. |
| 131 | * |
| 132 | * @return voltage rails |
| 133 | */ |
| 134 | const std::vector<std::unique_ptr<Rail>>& getRails() const |
| 135 | { |
| 136 | return rails; |
| 137 | } |
| 138 | |
| 139 | /** |
| 140 | * Returns whether this device is a voltage regulator. |
| 141 | * |
| 142 | * @return true if device is a voltage regulator, false otherwise |
| 143 | */ |
| 144 | bool isRegulator() const |
| 145 | { |
| 146 | return isRegulatorDevice; |
| 147 | } |
| 148 | |
Shawn McCarney | a2461b3 | 2019-10-24 18:53:01 -0500 | [diff] [blame] | 149 | private: |
| 150 | /** |
| 151 | * Unique ID of this device. |
| 152 | */ |
| 153 | const std::string id{}; |
Shawn McCarney | afb7fc3 | 2019-12-11 19:42:03 -0600 | [diff] [blame] | 154 | |
| 155 | /** |
| 156 | * Indicates whether this device is a voltage regulator. |
| 157 | */ |
| 158 | const bool isRegulatorDevice{false}; |
| 159 | |
| 160 | /** |
| 161 | * Field-Replaceable Unit (FRU) for this device. |
| 162 | * |
| 163 | * Set to the D-Bus inventory path of the FRU. If the device itself is not |
| 164 | * a FRU, set to the FRU that contains the device. |
| 165 | */ |
| 166 | const std::string fru{}; |
| 167 | |
| 168 | /** |
| 169 | * I2C interface to this device. |
| 170 | */ |
| 171 | std::unique_ptr<i2c::I2CInterface> i2cInterface{}; |
Shawn McCarney | 0b1a0e7 | 2020-03-11 18:01:44 -0500 | [diff] [blame] | 172 | |
| 173 | /** |
| 174 | * Presence detection for this device, if any. Set to nullptr if no |
| 175 | * presence detection is defined for this device. |
| 176 | */ |
| 177 | std::unique_ptr<PresenceDetection> presenceDetection{}; |
| 178 | |
| 179 | /** |
| 180 | * Configuration changes to apply to this device, if any. Set to nullptr if |
| 181 | * no configuration changes are defined for this device. |
| 182 | */ |
| 183 | std::unique_ptr<Configuration> configuration{}; |
| 184 | |
| 185 | /** |
| 186 | * Voltage rails produced by this device, if any. Vector is empty if no |
| 187 | * voltage rails are defined for this device. |
| 188 | */ |
| 189 | std::vector<std::unique_ptr<Rail>> rails{}; |
Shawn McCarney | a2461b3 | 2019-10-24 18:53:01 -0500 | [diff] [blame] | 190 | }; |
| 191 | |
Shawn McCarney | ea7385b | 2019-11-07 12:19:32 -0600 | [diff] [blame] | 192 | } // namespace phosphor::power::regulators |