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 18 #include "i2c_interface.hpp" 19 20 #include <memory> 21 #include <string> 22 #include <utility> 23 24 namespace phosphor::power::regulators 25 { 26 27 /** 28 * @class Device 29 * 30 * A hardware device, such as a voltage regulator or I/O expander. 31 */ 32 class 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 47 * @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 50 */ 51 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)} 57 { 58 } 59 60 /** 61 * Returns the unique ID of this device. 62 * 63 * @return device ID 64 */ 65 const std::string& getID() const 66 { 67 return id; 68 } 69 70 /** 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 103 private: 104 /** 105 * Unique ID of this device. 106 */ 107 const std::string id{}; 108 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{}; 126 }; 127 128 } // namespace phosphor::power::regulators 129