xref: /openbmc/phosphor-hwmon/sysfs.hpp (revision 9ca659f96268c0db1a3a8fbaa85a5aa69e6fcae9)
1 #pragma once
2 
3 #include <fstream>
4 #include <string>
5 
6 inline std::string make_sysfs_path(const std::string& path,
7                                    const std::string& type,
8                                    const std::string& id,
9                                    const std::string& entry)
10 {
11     using namespace std::literals;
12 
13     return path + "/"s + type + id + "_"s + entry;
14 }
15 
16 
17 /** @brief Find hwmon instances
18  *
19  *  Look for a matching hwmon instance given an
20  *  open firmware device path.
21  *
22  *  @param[in] ofNode- The open firmware device path.
23  *
24  *  @returns[in] - The hwmon instance path or an empty
25  *                 string if no match is found.
26  */
27 std::string findHwmon(const std::string& ofNode);
28 
29 /** @brief Read an hwmon sysfs value.
30  *
31  *  Calls exit(3) with bad status on failure.
32  *
33  *  @param[in] root - The hwmon class root.
34  *  @param[in] instance - The hwmon instance (ex. hwmon1).
35  *  @param[in] type - The hwmon type (ex. temp).
36  *  @param[in] id - The hwmon id (ex. 1).
37  *  @param[in] sensor - The hwmon sensor (ex. input).
38  *
39  *  @returns - The read value.
40  */
41 int readSysfsWithCallout(const std::string& root,
42                          const std::string& instance,
43                          const std::string& type,
44                          const std::string& id,
45                          const std::string& sensor);
46 
47 // vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
48