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