xref: /openbmc/phosphor-power/pmbus.hpp (revision c3324424b278e761497ea0e639ecc7bae5e1bcb6)
1015e3adeSMatt Spinler #pragma once
2015e3adeSMatt Spinler 
39c7897ceSBrandon Wyman #include <filesystem>
4015e3adeSMatt Spinler #include <string>
5015e3adeSMatt Spinler #include <vector>
6015e3adeSMatt Spinler 
7ab093328SLei YU namespace phosphor
8015e3adeSMatt Spinler {
9015e3adeSMatt Spinler namespace pmbus
10015e3adeSMatt Spinler {
11015e3adeSMatt Spinler 
129c7897ceSBrandon Wyman namespace fs = std::filesystem;
13ff5f339cSBrandon Wyman 
144175ffb7SAdriana Kobylak // The file name Linux uses to capture the READ_VIN from pmbus.
154175ffb7SAdriana Kobylak constexpr auto READ_VIN = "in1_input";
164175ffb7SAdriana Kobylak 
174175ffb7SAdriana Kobylak namespace in_input
184175ffb7SAdriana Kobylak {
194175ffb7SAdriana Kobylak // VIN thresholds in Volts
204175ffb7SAdriana Kobylak constexpr auto VIN_VOLTAGE_MIN = 20;
214175ffb7SAdriana Kobylak constexpr auto VIN_VOLTAGE_110_THRESHOLD = 160;
224175ffb7SAdriana Kobylak 
234175ffb7SAdriana Kobylak // VIN actual values in Volts
244175ffb7SAdriana Kobylak // VIN_VOLTAGE_0:   VIN < VIN_VOLTAGE_MIN
254175ffb7SAdriana Kobylak // VIN_VOLTAGE_110: VIN_VOLTAGE_MIN < VIN < VIN_VOLTAGE_110_THRESHOLD
264175ffb7SAdriana Kobylak // VIN_VOLTAGE_220: VIN_VOLTAGE_110_THRESHOLD < VIN
274175ffb7SAdriana Kobylak constexpr auto VIN_VOLTAGE_0 = 0;
284175ffb7SAdriana Kobylak constexpr auto VIN_VOLTAGE_110 = 110;
294175ffb7SAdriana Kobylak constexpr auto VIN_VOLTAGE_220 = 220;
304175ffb7SAdriana Kobylak } // namespace in_input
314175ffb7SAdriana Kobylak 
3210295547SBrandon Wyman // The file name Linux uses to capture the STATUS_WORD from pmbus.
33e7e432b4SMatt Spinler constexpr auto STATUS_WORD = "status0";
3410295547SBrandon Wyman 
35253dc9b9SBrandon Wyman // The file name Linux uses to capture the STATUS_INPUT from pmbus.
36253dc9b9SBrandon Wyman constexpr auto STATUS_INPUT = "status0_input";
37e7e432b4SMatt Spinler 
38764c797eSBrandon Wyman // Voltage out status.
39764c797eSBrandon Wyman // Overvoltage fault or warning, Undervoltage fault or warning, maximum or
40764c797eSBrandon Wyman // minimum warning, ....
41e7e432b4SMatt Spinler // Uses Page substitution
42e7e432b4SMatt Spinler constexpr auto STATUS_VOUT = "statusP_vout";
43e7e432b4SMatt Spinler 
44de16d053SMatt Spinler namespace status_vout
45de16d053SMatt Spinler {
46de16d053SMatt Spinler // Mask of bits that are only warnings
47de16d053SMatt Spinler constexpr auto WARNING_MASK = 0x6A;
48f0f02b9aSMatt Spinler } // namespace status_vout
49de16d053SMatt Spinler 
50764c797eSBrandon Wyman // Current output status bits.
51764c797eSBrandon Wyman constexpr auto STATUS_IOUT = "status0_iout";
52764c797eSBrandon Wyman 
53764c797eSBrandon Wyman // Manufacturing specific status bits
54764c797eSBrandon Wyman constexpr auto STATUS_MFR = "status0_mfr";
55764c797eSBrandon Wyman 
5612661f1eSBrandon Wyman // Reports on the status of any fans installed in position 1 and 2.
5708cac06bSBrandon Wyman constexpr auto STATUS_FANS_1_2 = "status0_fan12";
5812661f1eSBrandon Wyman 
5912661f1eSBrandon Wyman // Reports on temperature faults or warnings. Overtemperature fault,
6012661f1eSBrandon Wyman // overtemperature warning, undertemperature warning, undertemperature fault.
6112661f1eSBrandon Wyman constexpr auto STATUS_TEMPERATURE = "status0_temp";
6212661f1eSBrandon Wyman 
6385c7bf41SBrandon Wyman // Reports on the communication, memory, logic fault(s).
6485c7bf41SBrandon Wyman constexpr auto STATUS_CML = "status0_cml";
6585c7bf41SBrandon Wyman 
66e7e432b4SMatt Spinler namespace status_word
67e7e432b4SMatt Spinler {
68e7e432b4SMatt Spinler constexpr auto VOUT_FAULT = 0x8000;
69764c797eSBrandon Wyman 
70764c797eSBrandon Wyman // The IBM CFF power supply driver does map this bit to power1_alarm in the
71764c797eSBrandon Wyman // hwmon space, but since the other bits that need to be checked do not have
72764c797eSBrandon Wyman // a similar mapping, the code will just read STATUS_WORD and use bit masking
73764c797eSBrandon Wyman // to see if the INPUT FAULT OR WARNING bit is on.
74764c797eSBrandon Wyman constexpr auto INPUT_FAULT_WARN = 0x2000;
75764c797eSBrandon Wyman 
763f1242f3SBrandon Wyman // The bit mask representing the MFRSPECIFIC fault, bit 4 of STATUS_WORD high
773f1242f3SBrandon Wyman // byte. A manufacturer specific fault or warning has occurred.
783f1242f3SBrandon Wyman constexpr auto MFR_SPECIFIC_FAULT = 0x1000;
793f1242f3SBrandon Wyman 
80764c797eSBrandon Wyman // The bit mask representing the POWER_GOOD Negated bit of the STATUS_WORD.
81764c797eSBrandon Wyman constexpr auto POWER_GOOD_NEGATED = 0x0800;
82764c797eSBrandon Wyman 
8312661f1eSBrandon Wyman // The bit mask representing the FAN FAULT or WARNING bit of the STATUS_WORD.
8412661f1eSBrandon Wyman // Bit 2 of the high byte of STATUS_WORD.
8512661f1eSBrandon Wyman constexpr auto FAN_FAULT = 0x0400;
8612661f1eSBrandon Wyman 
87764c797eSBrandon Wyman // The bit mask representing the UNITI_IS_OFF bit of the STATUS_WORD.
88764c797eSBrandon Wyman constexpr auto UNIT_IS_OFF = 0x0040;
89764c797eSBrandon Wyman 
90ab05c079SBrandon Wyman // Bit 5 of the STATUS_BYTE, or lower byte of STATUS_WORD is used to indicate
91ab05c079SBrandon Wyman // an output overvoltage fault.
92ab05c079SBrandon Wyman constexpr auto VOUT_OV_FAULT = 0x0020;
93ab05c079SBrandon Wyman 
94b165c251SBrandon Wyman // The bit mask representing that an output overcurrent fault has occurred.
95b165c251SBrandon Wyman constexpr auto IOUT_OC_FAULT = 0x0010;
96b165c251SBrandon Wyman 
97764c797eSBrandon Wyman // The IBM CFF power supply driver does map this bit to in1_alarm, however,
98764c797eSBrandon Wyman // since a number of the other bits are not mapped that way for STATUS_WORD,
99764c797eSBrandon Wyman // this code will just read the entire STATUS_WORD and use bit masking to find
100764c797eSBrandon Wyman // out if that fault is on.
101764c797eSBrandon Wyman constexpr auto VIN_UV_FAULT = 0x0008;
102764c797eSBrandon Wyman 
103875b363cSBrandon Wyman // The bit mask representing the TEMPERATURE FAULT or WARNING bit of the
104875b363cSBrandon Wyman // STATUS_WORD. Bit 2 of the low byte (STATUS_BYTE).
105875b363cSBrandon Wyman constexpr auto TEMPERATURE_FAULT_WARN = 0x0004;
106875b363cSBrandon Wyman 
10785c7bf41SBrandon Wyman // The bit mask representing the CML (Communication, Memory, and/or Logic) fault
10885c7bf41SBrandon Wyman // bit of the STATUS_WORD. Bit 1 of the low byte (STATUS_BYTE).
10985c7bf41SBrandon Wyman constexpr auto CML_FAULT = 0x0002;
110f0f02b9aSMatt Spinler } // namespace status_word
111875b363cSBrandon Wyman 
112e8c9cd64SLei YU namespace status_vout
113e8c9cd64SLei YU {
114e8c9cd64SLei YU // The IBM CFF power supply driver maps MFR's OV_FAULT and VAUX_FAULT to this
115e8c9cd64SLei YU // bit.
116e8c9cd64SLei YU constexpr auto OV_FAULT = 0x80;
117e8c9cd64SLei YU 
118e8c9cd64SLei YU // The IBM CFF power supply driver maps MFR's UV_FAULT to this bit.
119e8c9cd64SLei YU constexpr auto UV_FAULT = 0x10;
120e8c9cd64SLei YU } // namespace status_vout
121e8c9cd64SLei YU 
122875b363cSBrandon Wyman namespace status_temperature
123875b363cSBrandon Wyman {
124875b363cSBrandon Wyman // Overtemperature Fault
125875b363cSBrandon Wyman constexpr auto OT_FAULT = 0x80;
126f0f02b9aSMatt Spinler } // namespace status_temperature
127e7e432b4SMatt Spinler 
12859a35793SBrandon Wyman constexpr auto ON_OFF_CONFIG = "on_off_config";
12959a35793SBrandon Wyman 
13059a35793SBrandon Wyman // From PMBus Specification Part II Revsion 1.2:
13159a35793SBrandon Wyman // The ON_OFF_CONFIG command configures the combination of CONTROL pin input
13259a35793SBrandon Wyman // and serial bus commands needed to turn the unit on and off. This includes how
13359a35793SBrandon Wyman // the unit responds when power is applied.
13459a35793SBrandon Wyman // Bits [7:5] - 000 - Reserved
13559a35793SBrandon Wyman // Bit 4 - 1 - Unit does not power up until commanded by the CONTROL pin and
13659a35793SBrandon Wyman // OPERATION command (as programmed in bits [3:0]).
13759a35793SBrandon Wyman // Bit 3 - 0 - Unit ignores the on/off portion of the OPERATION command from
13859a35793SBrandon Wyman // serial bus.
13959a35793SBrandon Wyman // Bit 2 - 1 - Unit requires the CONTROL pin to be asserted to start the unit.
14059a35793SBrandon Wyman // Bit 1 - 0 - Polarity of the CONTROL pin. Active low (Pull pin low to start
14159a35793SBrandon Wyman // the unit).
14259a35793SBrandon Wyman // Bit 0 - 1 - Turn off the output and stop transferring energy to the output as
14359a35793SBrandon Wyman // fast as possible.
14459a35793SBrandon Wyman constexpr auto ON_OFF_CONFIG_CONTROL_PIN_ONLY = 0x15;
14559a35793SBrandon Wyman 
146015e3adeSMatt Spinler /**
1474dc4678eSMatt Spinler  * Where the access should be done
14857868bc5SMatt Spinler  */
14957868bc5SMatt Spinler enum class Type
15057868bc5SMatt Spinler {
1514dc4678eSMatt Spinler     Base,            // base device directory
1524dc4678eSMatt Spinler     Hwmon,           // hwmon directory
1534dc4678eSMatt Spinler     Debug,           // pmbus debug directory
1544dc4678eSMatt Spinler     DeviceDebug,     // device debug directory
1554dc4678eSMatt Spinler     HwmonDeviceDebug // hwmon device debug directory
15657868bc5SMatt Spinler };
15757868bc5SMatt Spinler 
15857868bc5SMatt Spinler /**
1598d195771SBrandon Wyman  * @class PMBusBase
1608d195771SBrandon Wyman  *
1618d195771SBrandon Wyman  * This is a base class for PMBus to assist with unit testing via mocking.
1628d195771SBrandon Wyman  */
1638d195771SBrandon Wyman class PMBusBase
1648d195771SBrandon Wyman {
1658d195771SBrandon Wyman   public:
1668d195771SBrandon Wyman     virtual ~PMBusBase() = default;
1673f1242f3SBrandon Wyman 
16832453e9bSBrandon Wyman     virtual uint64_t read(const std::string& name, Type type,
16932453e9bSBrandon Wyman                           bool errTrace = true) = 0;
1701d7a7df8SBrandon Wyman     virtual std::string readString(const std::string& name, Type type) = 0;
171*c3324424SBrandon Wyman     virtual std::vector<uint8_t> readBinary(const std::string& name, Type type,
172*c3324424SBrandon Wyman                                             size_t length) = 0;
17359a35793SBrandon Wyman     virtual void writeBinary(const std::string& name, std::vector<uint8_t> data,
17459a35793SBrandon Wyman                              Type type) = 0;
1759564e945SBrandon Wyman     virtual void findHwmonDir() = 0;
1764176d6beSBrandon Wyman     virtual const fs::path& path() const = 0;
1776710ba2cSBrandon Wyman     virtual std::string insertPageNum(const std::string& templateName,
1786710ba2cSBrandon Wyman                                       size_t page) = 0;
1798d195771SBrandon Wyman };
1808d195771SBrandon Wyman 
1818d195771SBrandon Wyman /**
1828d195771SBrandon Wyman  * Wrapper function for PMBus
1838d195771SBrandon Wyman  *
1848d195771SBrandon Wyman  * @param[in] bus - I2C bus
1858d195771SBrandon Wyman  * @param[in] address - I2C address (as a 2-byte string, e.g. 0069)
1868d195771SBrandon Wyman  *
1878d195771SBrandon Wyman  * @return PMBusBase pointer
1888d195771SBrandon Wyman  */
1898d195771SBrandon Wyman std::unique_ptr<PMBusBase> createPMBus(std::uint8_t bus,
1908d195771SBrandon Wyman                                        const std::string& address);
1918d195771SBrandon Wyman 
1928d195771SBrandon Wyman /**
193015e3adeSMatt Spinler  * @class PMBus
194015e3adeSMatt Spinler  *
195015e3adeSMatt Spinler  * This class is an interface to communicating with PMBus devices
196015e3adeSMatt Spinler  * by reading and writing sysfs files.
19757868bc5SMatt Spinler  *
19857868bc5SMatt Spinler  * Based on the Type parameter, the accesses can either be done
19957868bc5SMatt Spinler  * in the base device directory (the one passed into the constructor),
20057868bc5SMatt Spinler  * or in the hwmon directory for the device.
201015e3adeSMatt Spinler  */
2028d195771SBrandon Wyman class PMBus : public PMBusBase
203015e3adeSMatt Spinler {
204015e3adeSMatt Spinler   public:
205015e3adeSMatt Spinler     PMBus() = delete;
2068d195771SBrandon Wyman     virtual ~PMBus() = default;
207015e3adeSMatt Spinler     PMBus(const PMBus&) = default;
208015e3adeSMatt Spinler     PMBus& operator=(const PMBus&) = default;
209015e3adeSMatt Spinler     PMBus(PMBus&&) = default;
210015e3adeSMatt Spinler     PMBus& operator=(PMBus&&) = default;
211015e3adeSMatt Spinler 
212015e3adeSMatt Spinler     /**
213015e3adeSMatt Spinler      * Constructor
214015e3adeSMatt Spinler      *
215015e3adeSMatt Spinler      * @param[in] path - path to the sysfs directory
216015e3adeSMatt Spinler      */
217f0f02b9aSMatt Spinler     PMBus(const std::string& path) : basePath(path)
218015e3adeSMatt Spinler     {
219ff5f339cSBrandon Wyman         findHwmonDir();
220015e3adeSMatt Spinler     }
221015e3adeSMatt Spinler 
222015e3adeSMatt Spinler     /**
2238f0d953fSMatt Spinler      * Constructor
2248f0d953fSMatt Spinler      *
2258f0d953fSMatt Spinler      * This version is required when DeviceDebug
2268f0d953fSMatt Spinler      * access will be used.
2278f0d953fSMatt Spinler      *
2288f0d953fSMatt Spinler      * @param[in] path - path to the sysfs directory
2298f0d953fSMatt Spinler      * @param[in] driverName - the device driver name
2308f0d953fSMatt Spinler      * @param[in] instance - chip instance number
2318f0d953fSMatt Spinler      */
232f0f02b9aSMatt Spinler     PMBus(const std::string& path, const std::string& driverName,
2338f0d953fSMatt Spinler           size_t instance) :
2348f0d953fSMatt Spinler         basePath(path),
235f0f02b9aSMatt Spinler         driverName(driverName), instance(instance)
2368f0d953fSMatt Spinler     {
2378f0d953fSMatt Spinler         findHwmonDir();
2388f0d953fSMatt Spinler     }
2398f0d953fSMatt Spinler 
2408f0d953fSMatt Spinler     /**
2418d195771SBrandon Wyman      * Wrapper function for PMBus
2428d195771SBrandon Wyman      *
2438d195771SBrandon Wyman      * @param[in] bus - I2C bus
2448d195771SBrandon Wyman      * @param[in] address - I2C address (as a 2-byte string, e.g. 0069)
2458d195771SBrandon Wyman      *
2468d195771SBrandon Wyman      * @return PMBusBase pointer
2478d195771SBrandon Wyman      */
2488d195771SBrandon Wyman     static std::unique_ptr<PMBusBase> createPMBus(std::uint8_t bus,
2498d195771SBrandon Wyman                                                   const std::string& address);
2508d195771SBrandon Wyman 
2518d195771SBrandon Wyman     /**
252015e3adeSMatt Spinler      * Reads a file in sysfs that represents a single bit,
253015e3adeSMatt Spinler      * therefore doing a PMBus read.
254015e3adeSMatt Spinler      *
255015e3adeSMatt Spinler      * @param[in] name - path concatenated to
256015e3adeSMatt Spinler      *                   basePath to read
2578f0d953fSMatt Spinler      * @param[in] type - Path type
258015e3adeSMatt Spinler      *
259015e3adeSMatt Spinler      * @return bool - false if result was 0, else true
260015e3adeSMatt Spinler      */
26157868bc5SMatt Spinler     bool readBit(const std::string& name, Type type);
262015e3adeSMatt Spinler 
263015e3adeSMatt Spinler     /**
264015e3adeSMatt Spinler      * Reads a file in sysfs that represents a single bit,
265015e3adeSMatt Spinler      * where the page number passed in is substituted
266015e3adeSMatt Spinler      * into the name in place of the 'P' character in it.
267015e3adeSMatt Spinler      *
268015e3adeSMatt Spinler      * @param[in] name - path concatenated to
269015e3adeSMatt Spinler      *                   basePath to read
270015e3adeSMatt Spinler      * @param[in] page - page number
2718f0d953fSMatt Spinler      * @param[in] type - Path type
272015e3adeSMatt Spinler      *
273015e3adeSMatt Spinler      * @return bool - false if result was 0, else true
274015e3adeSMatt Spinler      */
275f0f02b9aSMatt Spinler     bool readBitInPage(const std::string& name, size_t page, Type type);
276f855e82aSBrandon Wyman     /**
2773b7b38baSBrandon Wyman      * Checks if the file for the given name and type exists.
2783b7b38baSBrandon Wyman      *
2793b7b38baSBrandon Wyman      * @param[in] name   - path concatenated to basePath to read
2803b7b38baSBrandon Wyman      * @param[in] type   - Path type
2813b7b38baSBrandon Wyman      *
2823b7b38baSBrandon Wyman      * @return bool - True if file exists, false if it does not.
2833b7b38baSBrandon Wyman      */
2843b7b38baSBrandon Wyman     bool exists(const std::string& name, Type type);
2853b7b38baSBrandon Wyman 
2863b7b38baSBrandon Wyman     /**
287f855e82aSBrandon Wyman      * Read byte(s) from file in sysfs.
288f855e82aSBrandon Wyman      *
289f855e82aSBrandon Wyman      * @param[in] name   - path concatenated to basePath to read
2908f0d953fSMatt Spinler      * @param[in] type   - Path type
29132453e9bSBrandon Wyman      * @param[in] errTrace - true to enable tracing error (defaults to true)
292f855e82aSBrandon Wyman      *
293f855e82aSBrandon Wyman      * @return uint64_t - Up to 8 bytes of data read from file.
294f855e82aSBrandon Wyman      */
29532453e9bSBrandon Wyman     uint64_t read(const std::string& name, Type type,
29632453e9bSBrandon Wyman                   bool errTrace = true) override;
297015e3adeSMatt Spinler 
298015e3adeSMatt Spinler     /**
299fbae7b6cSMatt Spinler      * Read a string from file in sysfs.
300fbae7b6cSMatt Spinler      *
301fbae7b6cSMatt Spinler      * @param[in] name   - path concatenated to basePath to read
302fbae7b6cSMatt Spinler      * @param[in] type   - Path type
303fbae7b6cSMatt Spinler      *
304fbae7b6cSMatt Spinler      * @return string - The data read from the file.
305fbae7b6cSMatt Spinler      */
3061d7a7df8SBrandon Wyman     std::string readString(const std::string& name, Type type) override;
307fbae7b6cSMatt Spinler 
308fbae7b6cSMatt Spinler     /**
309fa23e330SMatt Spinler      * Read data from a binary file in sysfs.
310fa23e330SMatt Spinler      *
311fa23e330SMatt Spinler      * @param[in] name   - path concatenated to basePath to read
312fa23e330SMatt Spinler      * @param[in] type   - Path type
313fa23e330SMatt Spinler      * @param[in] length - length of data to read, in bytes
314fa23e330SMatt Spinler      *
315fa23e330SMatt Spinler      * @return vector<uint8_t> - The data read from the file.
316fa23e330SMatt Spinler      */
317f0f02b9aSMatt Spinler     std::vector<uint8_t> readBinary(const std::string& name, Type type,
318fa23e330SMatt Spinler                                     size_t length);
319fa23e330SMatt Spinler 
320fa23e330SMatt Spinler     /**
321015e3adeSMatt Spinler      * Writes an integer value to the file, therefore doing
322015e3adeSMatt Spinler      * a PMBus write.
323015e3adeSMatt Spinler      *
324015e3adeSMatt Spinler      * @param[in] name - path concatenated to
325015e3adeSMatt Spinler      *                   basePath to write
326015e3adeSMatt Spinler      * @param[in] value - the value to write
3278f0d953fSMatt Spinler      * @param[in] type - Path type
328015e3adeSMatt Spinler      */
32957868bc5SMatt Spinler     void write(const std::string& name, int value, Type type);
330015e3adeSMatt Spinler 
331015e3adeSMatt Spinler     /**
33259a35793SBrandon Wyman      * Writes binary data to a file in sysfs.
33359a35793SBrandon Wyman      *
33459a35793SBrandon Wyman      * @param[in] name - path concatenated to basePath to write
33559a35793SBrandon Wyman      * @param[in] data - The data to write to the file
33659a35793SBrandon Wyman      * @param[in] type - Path type
33759a35793SBrandon Wyman      */
33859a35793SBrandon Wyman     void writeBinary(const std::string& name, std::vector<uint8_t> data,
33959a35793SBrandon Wyman                      Type type) override;
34059a35793SBrandon Wyman 
34159a35793SBrandon Wyman     /**
342015e3adeSMatt Spinler      * Returns the sysfs base path of this device
343015e3adeSMatt Spinler      */
3444176d6beSBrandon Wyman     const fs::path& path() const override
345015e3adeSMatt Spinler     {
346015e3adeSMatt Spinler         return basePath;
347015e3adeSMatt Spinler     }
348015e3adeSMatt Spinler 
349015e3adeSMatt Spinler     /**
350015e3adeSMatt Spinler      * Replaces the 'P' in the string passed in with
351015e3adeSMatt Spinler      * the page number passed in.
352015e3adeSMatt Spinler      *
353015e3adeSMatt Spinler      * For example:
354015e3adeSMatt Spinler      *   insertPageNum("inP_enable", 42)
355015e3adeSMatt Spinler      *   returns "in42_enable"
356015e3adeSMatt Spinler      *
357015e3adeSMatt Spinler      * @param[in] templateName - the name string, with a 'P' in it
358015e3adeSMatt Spinler      * @param[in] page - the page number to insert where the P was
359015e3adeSMatt Spinler      *
360015e3adeSMatt Spinler      * @return string - the new string with the page number in it
361015e3adeSMatt Spinler      */
3626710ba2cSBrandon Wyman     std::string insertPageNum(const std::string& templateName,
3636710ba2cSBrandon Wyman                               size_t page) override;
364015e3adeSMatt Spinler 
36557868bc5SMatt Spinler     /**
36657868bc5SMatt Spinler      * Finds the path relative to basePath to the hwmon directory
36757868bc5SMatt Spinler      * for the device and stores it in hwmonRelPath.
36857868bc5SMatt Spinler      */
3699564e945SBrandon Wyman     void findHwmonDir() override;
370ff5f339cSBrandon Wyman 
371ff5f339cSBrandon Wyman     /**
372ff5f339cSBrandon Wyman      * Returns the path to use for the passed in type.
373ff5f339cSBrandon Wyman      *
3748f0d953fSMatt Spinler      * @param[in] type - Path type
375ff5f339cSBrandon Wyman      *
3768f0d953fSMatt Spinler      * @return fs::path - the full path
377ff5f339cSBrandon Wyman      */
378ff5f339cSBrandon Wyman     fs::path getPath(Type type);
37957868bc5SMatt Spinler 
380015e3adeSMatt Spinler   private:
381015e3adeSMatt Spinler     /**
382ba05348fSMatt Spinler      * Returns the device name
383ba05348fSMatt Spinler      *
384ba05348fSMatt Spinler      * This is found in the 'name' file in basePath.
385ba05348fSMatt Spinler      *
386ba05348fSMatt Spinler      * @return string - the device name
387ba05348fSMatt Spinler      */
388ba05348fSMatt Spinler     std::string getDeviceName();
389ba05348fSMatt Spinler 
390ba05348fSMatt Spinler     /**
391015e3adeSMatt Spinler      * The sysfs device path
392015e3adeSMatt Spinler      */
393ff5f339cSBrandon Wyman     fs::path basePath;
394015e3adeSMatt Spinler 
39557868bc5SMatt Spinler     /**
396ff5f339cSBrandon Wyman      * The directory name under the basePath hwmon directory
39757868bc5SMatt Spinler      */
398ff5f339cSBrandon Wyman     fs::path hwmonDir;
399ff5f339cSBrandon Wyman 
400ff5f339cSBrandon Wyman     /**
4018f0d953fSMatt Spinler      * The device driver name.  Used for finding the device
4028f0d953fSMatt Spinler      * debug directory.  Not required if that directory
4038f0d953fSMatt Spinler      * isn't used.
4048f0d953fSMatt Spinler      */
4058f0d953fSMatt Spinler     std::string driverName;
4068f0d953fSMatt Spinler 
4078f0d953fSMatt Spinler     /**
4088f0d953fSMatt Spinler      * The device instance number.
4098f0d953fSMatt Spinler      *
410cab48342SGunnar Mills      * Used in conjunction with the driver name for finding
4118f0d953fSMatt Spinler      * the debug directory.  Not required if that directory
4128f0d953fSMatt Spinler      * isn't used.
4138f0d953fSMatt Spinler      */
4148f0d953fSMatt Spinler     size_t instance = 0;
4158f0d953fSMatt Spinler 
4168f0d953fSMatt Spinler     /**
417ff5f339cSBrandon Wyman      * The pmbus debug path with status files
418ff5f339cSBrandon Wyman      */
4198f0d953fSMatt Spinler     const fs::path debugPath = "/sys/kernel/debug/";
420015e3adeSMatt Spinler };
421015e3adeSMatt Spinler 
422f0f02b9aSMatt Spinler } // namespace pmbus
423ab093328SLei YU } // namespace phosphor
424