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