Matt Spinler | 015e3ad | 2017-08-01 11:20:47 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Brandon Wyman | 9c7897c | 2019-03-28 17:42:34 -0500 | [diff] [blame] | 3 | #include <filesystem> |
Matt Spinler | 015e3ad | 2017-08-01 11:20:47 -0500 | [diff] [blame] | 4 | #include <string> |
| 5 | #include <vector> |
| 6 | |
Lei YU | ab09332 | 2019-10-09 16:43:22 +0800 | [diff] [blame] | 7 | namespace phosphor |
Matt Spinler | 015e3ad | 2017-08-01 11:20:47 -0500 | [diff] [blame] | 8 | { |
| 9 | namespace pmbus |
| 10 | { |
| 11 | |
Brandon Wyman | 9c7897c | 2019-03-28 17:42:34 -0500 | [diff] [blame] | 12 | namespace fs = std::filesystem; |
Brandon Wyman | ff5f339 | 2017-08-11 17:43:22 -0500 | [diff] [blame] | 13 | |
Adriana Kobylak | 4175ffb | 2021-08-02 14:51:05 +0000 | [diff] [blame] | 14 | // The file name Linux uses to capture the READ_VIN from pmbus. |
| 15 | constexpr auto READ_VIN = "in1_input"; |
| 16 | |
Brandon Wyman | ae35ac5 | 2022-05-23 22:33:40 +0000 | [diff] [blame] | 17 | // The file name Linux uses to capture the MFR_POUT_MAX from pmbus. |
| 18 | constexpr auto MFR_POUT_MAX = "max_power_out"; |
| 19 | // The max_power_out value expected to be read for 1400W IBM CFFPS type. |
| 20 | constexpr auto IBM_CFFPS_1400W = 30725; |
| 21 | |
Adriana Kobylak | 4175ffb | 2021-08-02 14:51:05 +0000 | [diff] [blame] | 22 | namespace in_input |
| 23 | { |
| 24 | // VIN thresholds in Volts |
| 25 | constexpr auto VIN_VOLTAGE_MIN = 20; |
| 26 | constexpr auto VIN_VOLTAGE_110_THRESHOLD = 160; |
| 27 | |
| 28 | // VIN actual values in Volts |
| 29 | // VIN_VOLTAGE_0: VIN < VIN_VOLTAGE_MIN |
| 30 | // VIN_VOLTAGE_110: VIN_VOLTAGE_MIN < VIN < VIN_VOLTAGE_110_THRESHOLD |
| 31 | // VIN_VOLTAGE_220: VIN_VOLTAGE_110_THRESHOLD < VIN |
| 32 | constexpr auto VIN_VOLTAGE_0 = 0; |
| 33 | constexpr auto VIN_VOLTAGE_110 = 110; |
| 34 | constexpr auto VIN_VOLTAGE_220 = 220; |
| 35 | } // namespace in_input |
| 36 | |
Brandon Wyman | 1029554 | 2017-08-09 18:20:44 -0500 | [diff] [blame] | 37 | // The file name Linux uses to capture the STATUS_WORD from pmbus. |
Matt Spinler | e7e432b | 2017-08-21 15:01:40 -0500 | [diff] [blame] | 38 | constexpr auto STATUS_WORD = "status0"; |
Brandon Wyman | 1029554 | 2017-08-09 18:20:44 -0500 | [diff] [blame] | 39 | |
Brandon Wyman | 253dc9b | 2017-08-12 13:45:52 -0500 | [diff] [blame] | 40 | // The file name Linux uses to capture the STATUS_INPUT from pmbus. |
| 41 | constexpr auto STATUS_INPUT = "status0_input"; |
Matt Spinler | e7e432b | 2017-08-21 15:01:40 -0500 | [diff] [blame] | 42 | |
Brandon Wyman | 764c797 | 2017-08-22 17:05:36 -0500 | [diff] [blame] | 43 | // Voltage out status. |
| 44 | // Overvoltage fault or warning, Undervoltage fault or warning, maximum or |
| 45 | // minimum warning, .... |
Matt Spinler | e7e432b | 2017-08-21 15:01:40 -0500 | [diff] [blame] | 46 | // Uses Page substitution |
| 47 | constexpr auto STATUS_VOUT = "statusP_vout"; |
| 48 | |
Matt Spinler | de16d05 | 2017-12-13 13:22:14 -0600 | [diff] [blame] | 49 | namespace status_vout |
| 50 | { |
| 51 | // Mask of bits that are only warnings |
| 52 | constexpr auto WARNING_MASK = 0x6A; |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 53 | } // namespace status_vout |
Matt Spinler | de16d05 | 2017-12-13 13:22:14 -0600 | [diff] [blame] | 54 | |
Brandon Wyman | 764c797 | 2017-08-22 17:05:36 -0500 | [diff] [blame] | 55 | // Current output status bits. |
| 56 | constexpr auto STATUS_IOUT = "status0_iout"; |
| 57 | |
| 58 | // Manufacturing specific status bits |
| 59 | constexpr auto STATUS_MFR = "status0_mfr"; |
| 60 | |
Brandon Wyman | 12661f1 | 2017-08-31 15:28:21 -0500 | [diff] [blame] | 61 | // Reports on the status of any fans installed in position 1 and 2. |
Brandon Wyman | 08cac06 | 2021-11-19 23:30:27 +0000 | [diff] [blame] | 62 | constexpr auto STATUS_FANS_1_2 = "status0_fan12"; |
Brandon Wyman | 12661f1 | 2017-08-31 15:28:21 -0500 | [diff] [blame] | 63 | |
| 64 | // Reports on temperature faults or warnings. Overtemperature fault, |
| 65 | // overtemperature warning, undertemperature warning, undertemperature fault. |
| 66 | constexpr auto STATUS_TEMPERATURE = "status0_temp"; |
| 67 | |
Brandon Wyman | 85c7bf4 | 2021-10-19 22:28:48 +0000 | [diff] [blame] | 68 | // Reports on the communication, memory, logic fault(s). |
| 69 | constexpr auto STATUS_CML = "status0_cml"; |
| 70 | |
Matt Spinler | e7e432b | 2017-08-21 15:01:40 -0500 | [diff] [blame] | 71 | namespace status_word |
| 72 | { |
| 73 | constexpr auto VOUT_FAULT = 0x8000; |
Brandon Wyman | 764c797 | 2017-08-22 17:05:36 -0500 | [diff] [blame] | 74 | |
| 75 | // The IBM CFF power supply driver does map this bit to power1_alarm in the |
| 76 | // hwmon space, but since the other bits that need to be checked do not have |
| 77 | // a similar mapping, the code will just read STATUS_WORD and use bit masking |
| 78 | // to see if the INPUT FAULT OR WARNING bit is on. |
| 79 | constexpr auto INPUT_FAULT_WARN = 0x2000; |
| 80 | |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 81 | // The bit mask representing the MFRSPECIFIC fault, bit 4 of STATUS_WORD high |
| 82 | // byte. A manufacturer specific fault or warning has occurred. |
| 83 | constexpr auto MFR_SPECIFIC_FAULT = 0x1000; |
| 84 | |
Brandon Wyman | 764c797 | 2017-08-22 17:05:36 -0500 | [diff] [blame] | 85 | // The bit mask representing the POWER_GOOD Negated bit of the STATUS_WORD. |
| 86 | constexpr auto POWER_GOOD_NEGATED = 0x0800; |
| 87 | |
Brandon Wyman | 12661f1 | 2017-08-31 15:28:21 -0500 | [diff] [blame] | 88 | // The bit mask representing the FAN FAULT or WARNING bit of the STATUS_WORD. |
| 89 | // Bit 2 of the high byte of STATUS_WORD. |
| 90 | constexpr auto FAN_FAULT = 0x0400; |
| 91 | |
Brandon Wyman | 764c797 | 2017-08-22 17:05:36 -0500 | [diff] [blame] | 92 | // The bit mask representing the UNITI_IS_OFF bit of the STATUS_WORD. |
| 93 | constexpr auto UNIT_IS_OFF = 0x0040; |
| 94 | |
Brandon Wyman | ab05c07 | 2017-08-30 18:26:41 -0500 | [diff] [blame] | 95 | // Bit 5 of the STATUS_BYTE, or lower byte of STATUS_WORD is used to indicate |
| 96 | // an output overvoltage fault. |
| 97 | constexpr auto VOUT_OV_FAULT = 0x0020; |
| 98 | |
Brandon Wyman | b165c25 | 2017-08-25 18:59:54 -0500 | [diff] [blame] | 99 | // The bit mask representing that an output overcurrent fault has occurred. |
| 100 | constexpr auto IOUT_OC_FAULT = 0x0010; |
| 101 | |
Brandon Wyman | 764c797 | 2017-08-22 17:05:36 -0500 | [diff] [blame] | 102 | // The IBM CFF power supply driver does map this bit to in1_alarm, however, |
| 103 | // since a number of the other bits are not mapped that way for STATUS_WORD, |
| 104 | // this code will just read the entire STATUS_WORD and use bit masking to find |
| 105 | // out if that fault is on. |
| 106 | constexpr auto VIN_UV_FAULT = 0x0008; |
| 107 | |
Brandon Wyman | 875b363 | 2017-09-13 18:46:03 -0500 | [diff] [blame] | 108 | // The bit mask representing the TEMPERATURE FAULT or WARNING bit of the |
| 109 | // STATUS_WORD. Bit 2 of the low byte (STATUS_BYTE). |
| 110 | constexpr auto TEMPERATURE_FAULT_WARN = 0x0004; |
| 111 | |
Brandon Wyman | 85c7bf4 | 2021-10-19 22:28:48 +0000 | [diff] [blame] | 112 | // The bit mask representing the CML (Communication, Memory, and/or Logic) fault |
| 113 | // bit of the STATUS_WORD. Bit 1 of the low byte (STATUS_BYTE). |
| 114 | constexpr auto CML_FAULT = 0x0002; |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 115 | } // namespace status_word |
Brandon Wyman | 875b363 | 2017-09-13 18:46:03 -0500 | [diff] [blame] | 116 | |
Lei YU | e8c9cd6 | 2019-11-04 14:24:41 +0800 | [diff] [blame] | 117 | namespace status_vout |
| 118 | { |
| 119 | // The IBM CFF power supply driver maps MFR's OV_FAULT and VAUX_FAULT to this |
| 120 | // bit. |
| 121 | constexpr auto OV_FAULT = 0x80; |
| 122 | |
| 123 | // The IBM CFF power supply driver maps MFR's UV_FAULT to this bit. |
| 124 | constexpr auto UV_FAULT = 0x10; |
| 125 | } // namespace status_vout |
| 126 | |
Brandon Wyman | 875b363 | 2017-09-13 18:46:03 -0500 | [diff] [blame] | 127 | namespace status_temperature |
| 128 | { |
| 129 | // Overtemperature Fault |
| 130 | constexpr auto OT_FAULT = 0x80; |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 131 | } // namespace status_temperature |
Matt Spinler | e7e432b | 2017-08-21 15:01:40 -0500 | [diff] [blame] | 132 | |
Brandon Wyman | 59a3579 | 2020-06-04 12:37:40 -0500 | [diff] [blame] | 133 | constexpr auto ON_OFF_CONFIG = "on_off_config"; |
| 134 | |
| 135 | // From PMBus Specification Part II Revsion 1.2: |
| 136 | // The ON_OFF_CONFIG command configures the combination of CONTROL pin input |
| 137 | // and serial bus commands needed to turn the unit on and off. This includes how |
| 138 | // the unit responds when power is applied. |
| 139 | // Bits [7:5] - 000 - Reserved |
| 140 | // Bit 4 - 1 - Unit does not power up until commanded by the CONTROL pin and |
| 141 | // OPERATION command (as programmed in bits [3:0]). |
| 142 | // Bit 3 - 0 - Unit ignores the on/off portion of the OPERATION command from |
| 143 | // serial bus. |
| 144 | // Bit 2 - 1 - Unit requires the CONTROL pin to be asserted to start the unit. |
| 145 | // Bit 1 - 0 - Polarity of the CONTROL pin. Active low (Pull pin low to start |
| 146 | // the unit). |
| 147 | // Bit 0 - 1 - Turn off the output and stop transferring energy to the output as |
| 148 | // fast as possible. |
| 149 | constexpr auto ON_OFF_CONFIG_CONTROL_PIN_ONLY = 0x15; |
| 150 | |
Matt Spinler | 015e3ad | 2017-08-01 11:20:47 -0500 | [diff] [blame] | 151 | /** |
Matt Spinler | 4dc4678 | 2018-01-04 14:29:16 -0600 | [diff] [blame] | 152 | * Where the access should be done |
Matt Spinler | 57868bc | 2017-08-03 10:07:41 -0500 | [diff] [blame] | 153 | */ |
| 154 | enum class Type |
| 155 | { |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 156 | Base, // base device directory |
| 157 | Hwmon, // hwmon directory |
| 158 | Debug, // pmbus debug directory |
| 159 | DeviceDebug, // device debug directory |
| 160 | HwmonDeviceDebug // hwmon device debug directory |
Matt Spinler | 57868bc | 2017-08-03 10:07:41 -0500 | [diff] [blame] | 161 | }; |
| 162 | |
| 163 | /** |
Brandon Wyman | 8d19577 | 2020-01-27 15:03:51 -0600 | [diff] [blame] | 164 | * @class PMBusBase |
| 165 | * |
| 166 | * This is a base class for PMBus to assist with unit testing via mocking. |
| 167 | */ |
| 168 | class PMBusBase |
| 169 | { |
| 170 | public: |
| 171 | virtual ~PMBusBase() = default; |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 172 | |
Brandon Wyman | 32453e9 | 2021-12-15 19:00:14 +0000 | [diff] [blame] | 173 | virtual uint64_t read(const std::string& name, Type type, |
| 174 | bool errTrace = true) = 0; |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 175 | virtual std::string readString(const std::string& name, Type type) = 0; |
Brandon Wyman | c332442 | 2022-03-24 20:30:57 +0000 | [diff] [blame] | 176 | virtual std::vector<uint8_t> readBinary(const std::string& name, Type type, |
| 177 | size_t length) = 0; |
Brandon Wyman | 59a3579 | 2020-06-04 12:37:40 -0500 | [diff] [blame] | 178 | virtual void writeBinary(const std::string& name, std::vector<uint8_t> data, |
| 179 | Type type) = 0; |
Brandon Wyman | 9564e94 | 2020-11-10 14:01:42 -0600 | [diff] [blame] | 180 | virtual void findHwmonDir() = 0; |
Brandon Wyman | 4176d6b | 2020-10-07 17:41:06 -0500 | [diff] [blame] | 181 | virtual const fs::path& path() const = 0; |
Brandon Wyman | 6710ba2 | 2021-10-27 17:39:31 +0000 | [diff] [blame] | 182 | virtual std::string insertPageNum(const std::string& templateName, |
| 183 | size_t page) = 0; |
Shawn McCarney | fb0ccb8 | 2024-04-24 13:14:41 -0500 | [diff] [blame] | 184 | virtual fs::path getPath(Type type) = 0; |
Brandon Wyman | 8d19577 | 2020-01-27 15:03:51 -0600 | [diff] [blame] | 185 | }; |
| 186 | |
| 187 | /** |
| 188 | * Wrapper function for PMBus |
| 189 | * |
| 190 | * @param[in] bus - I2C bus |
| 191 | * @param[in] address - I2C address (as a 2-byte string, e.g. 0069) |
| 192 | * |
| 193 | * @return PMBusBase pointer |
| 194 | */ |
| 195 | std::unique_ptr<PMBusBase> createPMBus(std::uint8_t bus, |
| 196 | const std::string& address); |
| 197 | |
| 198 | /** |
Matt Spinler | 015e3ad | 2017-08-01 11:20:47 -0500 | [diff] [blame] | 199 | * @class PMBus |
| 200 | * |
| 201 | * This class is an interface to communicating with PMBus devices |
| 202 | * by reading and writing sysfs files. |
Matt Spinler | 57868bc | 2017-08-03 10:07:41 -0500 | [diff] [blame] | 203 | * |
| 204 | * Based on the Type parameter, the accesses can either be done |
| 205 | * in the base device directory (the one passed into the constructor), |
| 206 | * or in the hwmon directory for the device. |
Matt Spinler | 015e3ad | 2017-08-01 11:20:47 -0500 | [diff] [blame] | 207 | */ |
Brandon Wyman | 8d19577 | 2020-01-27 15:03:51 -0600 | [diff] [blame] | 208 | class PMBus : public PMBusBase |
Matt Spinler | 015e3ad | 2017-08-01 11:20:47 -0500 | [diff] [blame] | 209 | { |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 210 | public: |
| 211 | PMBus() = delete; |
Brandon Wyman | 8d19577 | 2020-01-27 15:03:51 -0600 | [diff] [blame] | 212 | virtual ~PMBus() = default; |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 213 | PMBus(const PMBus&) = default; |
| 214 | PMBus& operator=(const PMBus&) = default; |
| 215 | PMBus(PMBus&&) = default; |
| 216 | PMBus& operator=(PMBus&&) = default; |
Matt Spinler | 015e3ad | 2017-08-01 11:20:47 -0500 | [diff] [blame] | 217 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 218 | /** |
| 219 | * Constructor |
| 220 | * |
| 221 | * @param[in] path - path to the sysfs directory |
| 222 | */ |
| 223 | PMBus(const std::string& path) : basePath(path) |
| 224 | { |
| 225 | findHwmonDir(); |
| 226 | } |
Matt Spinler | 015e3ad | 2017-08-01 11:20:47 -0500 | [diff] [blame] | 227 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 228 | /** |
| 229 | * Constructor |
| 230 | * |
| 231 | * This version is required when DeviceDebug |
| 232 | * access will be used. |
| 233 | * |
| 234 | * @param[in] path - path to the sysfs directory |
| 235 | * @param[in] driverName - the device driver name |
| 236 | * @param[in] instance - chip instance number |
| 237 | */ |
| 238 | PMBus(const std::string& path, const std::string& driverName, |
| 239 | size_t instance) : |
Patrick Williams | f540219 | 2024-08-16 15:20:53 -0400 | [diff] [blame] | 240 | basePath(path), driverName(driverName), instance(instance) |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 241 | { |
| 242 | findHwmonDir(); |
| 243 | } |
Matt Spinler | 015e3ad | 2017-08-01 11:20:47 -0500 | [diff] [blame] | 244 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 245 | /** |
Brandon Wyman | 8d19577 | 2020-01-27 15:03:51 -0600 | [diff] [blame] | 246 | * Wrapper function for PMBus |
| 247 | * |
| 248 | * @param[in] bus - I2C bus |
| 249 | * @param[in] address - I2C address (as a 2-byte string, e.g. 0069) |
| 250 | * |
| 251 | * @return PMBusBase pointer |
| 252 | */ |
Patrick Williams | f540219 | 2024-08-16 15:20:53 -0400 | [diff] [blame] | 253 | static std::unique_ptr<PMBusBase> |
| 254 | createPMBus(std::uint8_t bus, const std::string& address); |
Brandon Wyman | 8d19577 | 2020-01-27 15:03:51 -0600 | [diff] [blame] | 255 | |
| 256 | /** |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 257 | * Reads a file in sysfs that represents a single bit, |
| 258 | * therefore doing a PMBus read. |
| 259 | * |
| 260 | * @param[in] name - path concatenated to |
| 261 | * basePath to read |
| 262 | * @param[in] type - Path type |
| 263 | * |
| 264 | * @return bool - false if result was 0, else true |
| 265 | */ |
| 266 | bool readBit(const std::string& name, Type type); |
Matt Spinler | 8f0d953 | 2017-08-21 11:22:37 -0500 | [diff] [blame] | 267 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 268 | /** |
| 269 | * Reads a file in sysfs that represents a single bit, |
| 270 | * where the page number passed in is substituted |
| 271 | * into the name in place of the 'P' character in it. |
| 272 | * |
| 273 | * @param[in] name - path concatenated to |
| 274 | * basePath to read |
| 275 | * @param[in] page - page number |
| 276 | * @param[in] type - Path type |
| 277 | * |
| 278 | * @return bool - false if result was 0, else true |
| 279 | */ |
| 280 | bool readBitInPage(const std::string& name, size_t page, Type type); |
| 281 | /** |
| 282 | * Checks if the file for the given name and type exists. |
| 283 | * |
| 284 | * @param[in] name - path concatenated to basePath to read |
| 285 | * @param[in] type - Path type |
| 286 | * |
| 287 | * @return bool - True if file exists, false if it does not. |
| 288 | */ |
| 289 | bool exists(const std::string& name, Type type); |
Matt Spinler | 015e3ad | 2017-08-01 11:20:47 -0500 | [diff] [blame] | 290 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 291 | /** |
| 292 | * Read byte(s) from file in sysfs. |
| 293 | * |
| 294 | * @param[in] name - path concatenated to basePath to read |
| 295 | * @param[in] type - Path type |
Brandon Wyman | 32453e9 | 2021-12-15 19:00:14 +0000 | [diff] [blame] | 296 | * @param[in] errTrace - true to enable tracing error (defaults to true) |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 297 | * |
| 298 | * @return uint64_t - Up to 8 bytes of data read from file. |
| 299 | */ |
Brandon Wyman | 32453e9 | 2021-12-15 19:00:14 +0000 | [diff] [blame] | 300 | uint64_t read(const std::string& name, Type type, |
| 301 | bool errTrace = true) override; |
Brandon Wyman | 3b7b38b | 2017-09-25 16:43:45 -0500 | [diff] [blame] | 302 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 303 | /** |
| 304 | * Read a string from file in sysfs. |
| 305 | * |
| 306 | * @param[in] name - path concatenated to basePath to read |
| 307 | * @param[in] type - Path type |
| 308 | * |
| 309 | * @return string - The data read from the file. |
| 310 | */ |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 311 | std::string readString(const std::string& name, Type type) override; |
Matt Spinler | 015e3ad | 2017-08-01 11:20:47 -0500 | [diff] [blame] | 312 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 313 | /** |
| 314 | * Read data from a binary file in sysfs. |
| 315 | * |
| 316 | * @param[in] name - path concatenated to basePath to read |
| 317 | * @param[in] type - Path type |
| 318 | * @param[in] length - length of data to read, in bytes |
| 319 | * |
| 320 | * @return vector<uint8_t> - The data read from the file. |
| 321 | */ |
| 322 | std::vector<uint8_t> readBinary(const std::string& name, Type type, |
| 323 | size_t length); |
Matt Spinler | fbae7b6 | 2018-01-04 14:33:13 -0600 | [diff] [blame] | 324 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 325 | /** |
| 326 | * Writes an integer value to the file, therefore doing |
| 327 | * a PMBus write. |
| 328 | * |
| 329 | * @param[in] name - path concatenated to |
| 330 | * basePath to write |
| 331 | * @param[in] value - the value to write |
| 332 | * @param[in] type - Path type |
| 333 | */ |
| 334 | void write(const std::string& name, int value, Type type); |
Matt Spinler | fa23e33 | 2018-01-18 11:24:58 -0600 | [diff] [blame] | 335 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 336 | /** |
Brandon Wyman | 59a3579 | 2020-06-04 12:37:40 -0500 | [diff] [blame] | 337 | * Writes binary data to a file in sysfs. |
| 338 | * |
| 339 | * @param[in] name - path concatenated to basePath to write |
| 340 | * @param[in] data - The data to write to the file |
| 341 | * @param[in] type - Path type |
| 342 | */ |
| 343 | void writeBinary(const std::string& name, std::vector<uint8_t> data, |
| 344 | Type type) override; |
| 345 | |
| 346 | /** |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 347 | * Returns the sysfs base path of this device |
| 348 | */ |
Brandon Wyman | 4176d6b | 2020-10-07 17:41:06 -0500 | [diff] [blame] | 349 | const fs::path& path() const override |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 350 | { |
| 351 | return basePath; |
| 352 | } |
Matt Spinler | 015e3ad | 2017-08-01 11:20:47 -0500 | [diff] [blame] | 353 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 354 | /** |
| 355 | * Replaces the 'P' in the string passed in with |
| 356 | * the page number passed in. |
| 357 | * |
| 358 | * For example: |
| 359 | * insertPageNum("inP_enable", 42) |
| 360 | * returns "in42_enable" |
| 361 | * |
| 362 | * @param[in] templateName - the name string, with a 'P' in it |
| 363 | * @param[in] page - the page number to insert where the P was |
| 364 | * |
| 365 | * @return string - the new string with the page number in it |
| 366 | */ |
Brandon Wyman | 6710ba2 | 2021-10-27 17:39:31 +0000 | [diff] [blame] | 367 | std::string insertPageNum(const std::string& templateName, |
| 368 | size_t page) override; |
Matt Spinler | 015e3ad | 2017-08-01 11:20:47 -0500 | [diff] [blame] | 369 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 370 | /** |
| 371 | * Finds the path relative to basePath to the hwmon directory |
| 372 | * for the device and stores it in hwmonRelPath. |
| 373 | */ |
Brandon Wyman | 9564e94 | 2020-11-10 14:01:42 -0600 | [diff] [blame] | 374 | void findHwmonDir() override; |
Matt Spinler | 015e3ad | 2017-08-01 11:20:47 -0500 | [diff] [blame] | 375 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 376 | /** |
| 377 | * Returns the path to use for the passed in type. |
| 378 | * |
| 379 | * @param[in] type - Path type |
| 380 | * |
| 381 | * @return fs::path - the full path |
| 382 | */ |
Shawn McCarney | fb0ccb8 | 2024-04-24 13:14:41 -0500 | [diff] [blame] | 383 | fs::path getPath(Type type) override; |
Brandon Wyman | ff5f339 | 2017-08-11 17:43:22 -0500 | [diff] [blame] | 384 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 385 | private: |
| 386 | /** |
| 387 | * Returns the device name |
| 388 | * |
| 389 | * This is found in the 'name' file in basePath. |
| 390 | * |
| 391 | * @return string - the device name |
| 392 | */ |
| 393 | std::string getDeviceName(); |
Matt Spinler | 57868bc | 2017-08-03 10:07:41 -0500 | [diff] [blame] | 394 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 395 | /** |
| 396 | * The sysfs device path |
| 397 | */ |
| 398 | fs::path basePath; |
Matt Spinler | 015e3ad | 2017-08-01 11:20:47 -0500 | [diff] [blame] | 399 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 400 | /** |
| 401 | * The directory name under the basePath hwmon directory |
| 402 | */ |
| 403 | fs::path hwmonDir; |
Matt Spinler | ba05348 | 2018-01-04 14:26:05 -0600 | [diff] [blame] | 404 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 405 | /** |
| 406 | * The device driver name. Used for finding the device |
| 407 | * debug directory. Not required if that directory |
| 408 | * isn't used. |
| 409 | */ |
| 410 | std::string driverName; |
Matt Spinler | 015e3ad | 2017-08-01 11:20:47 -0500 | [diff] [blame] | 411 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 412 | /** |
| 413 | * The device instance number. |
| 414 | * |
| 415 | * Used in conjunction with the driver name for finding |
| 416 | * the debug directory. Not required if that directory |
| 417 | * isn't used. |
| 418 | */ |
| 419 | size_t instance = 0; |
Brandon Wyman | ff5f339 | 2017-08-11 17:43:22 -0500 | [diff] [blame] | 420 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 421 | /** |
| 422 | * The pmbus debug path with status files |
| 423 | */ |
| 424 | const fs::path debugPath = "/sys/kernel/debug/"; |
Matt Spinler | 015e3ad | 2017-08-01 11:20:47 -0500 | [diff] [blame] | 425 | }; |
| 426 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 427 | } // namespace pmbus |
Lei YU | ab09332 | 2019-10-09 16:43:22 +0800 | [diff] [blame] | 428 | } // namespace phosphor |