xref: /openbmc/openpower-occ-control/i2c_occ.hpp (revision bcef3b4870bd93e6350f952706861bfac79982f4)
10ab90ca7SLei YU #pragma once
20ab90ca7SLei YU 
3*bcef3b48SGeorge Liu #include <filesystem>
40ab90ca7SLei YU #include <vector>
50ab90ca7SLei YU 
60ab90ca7SLei YU #ifdef I2C_OCC
70ab90ca7SLei YU 
80ab90ca7SLei YU namespace i2c_occ
90ab90ca7SLei YU {
100ab90ca7SLei YU 
11*bcef3b48SGeorge Liu namespace fs = std::filesystem;
120ab90ca7SLei YU 
130ab90ca7SLei YU /** @brief Get file content
140ab90ca7SLei YU  *
150ab90ca7SLei YU  * Get at most NAME_LENGTH bytes of content from file. If the file is smaller
160ab90ca7SLei YU  * than NAME_LENGTH bytes, return the valid parts.
170ab90ca7SLei YU  *
180ab90ca7SLei YU  * @param[in] f - The path of file
190ab90ca7SLei YU  *
200ab90ca7SLei YU  * @return The string of file content
210ab90ca7SLei YU  */
220ab90ca7SLei YU std::string getFileContent(const fs::path& f);
230ab90ca7SLei YU 
240ab90ca7SLei YU /** @brief Find all devices of occ hwmon
250ab90ca7SLei YU  *
260ab90ca7SLei YU  * It iterates in path, finds all occ hwmon devices
270ab90ca7SLei YU  *
280ab90ca7SLei YU  * E.g. If "path/3-0050/name" exists and its content is "p8-occ-hwmon",
290ab90ca7SLei YU  * "3-0050" is returned.
300ab90ca7SLei YU  *
310ab90ca7SLei YU  * @param[in] path - The path to search
320ab90ca7SLei YU  *
330ab90ca7SLei YU  * @return A vector of strings containing the occ hwmon device path
3441470e56SLei YU            where the first device is master occ
350ab90ca7SLei YU  */
360ab90ca7SLei YU std::vector<std::string> getOccHwmonDevices(const char* path);
370ab90ca7SLei YU 
380ab90ca7SLei YU /** @brief Convert i2c name to DBus path
390ab90ca7SLei YU  *
400ab90ca7SLei YU  * It converts '-' to '_' so that it becomes a valid DBus path.
410ab90ca7SLei YU  * E.g. 3-0050 converts to 3_0050
420ab90ca7SLei YU  *
430ab90ca7SLei YU  * @param[in,out] path - The i2c name to convert
440ab90ca7SLei YU  */
450ab90ca7SLei YU void i2cToDbus(std::string& name);
460ab90ca7SLei YU 
470ab90ca7SLei YU /** @brief Convert DBus path to i2c name
480ab90ca7SLei YU  *
490ab90ca7SLei YU  * It converts '_' to '_' so that it becomes a valid i2c name
500ab90ca7SLei YU  * E.g. 3_0050 converts to 3-0050
510ab90ca7SLei YU  *
520ab90ca7SLei YU  * @param[in,out] path - The DBus path to convert
530ab90ca7SLei YU  */
540ab90ca7SLei YU void dbusToI2c(std::string& path);
550ab90ca7SLei YU 
560ab90ca7SLei YU /** @brief Get i2c name from full DBus path
570ab90ca7SLei YU  *
580ab90ca7SLei YU  * It extract the i2c name from the full DBus path.
590ab90ca7SLei YU  * E.g. /org/open_power/control/3_0050 returns "3-0050"
600ab90ca7SLei YU  *
610ab90ca7SLei YU  * @param[in] dbusPath - The full DBus path
620ab90ca7SLei YU  *
630ab90ca7SLei YU  * @return The i2c name
640ab90ca7SLei YU  */
650ab90ca7SLei YU std::string getI2cDeviceName(const std::string& dbusPath);
660ab90ca7SLei YU 
670ab90ca7SLei YU } // namespace i2c_occ
680ab90ca7SLei YU 
690ab90ca7SLei YU #endif
70