xref: /openbmc/phosphor-hwmon/sysfs.hpp (revision 048ac87fa06a2a1c42f51c9f87931271a4f5a401)
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  /** @brief Write a hwmon sysfs value
48   *
49   *  Calls exit(3) with bad status on failure
50   *
51   *  @param[in] value - The value to be written
52   *  @param[in] root - The hwmon class root.
53   *  @param[in] instance - The hwmon instance (ex. hwmon1).
54   *  @param[in] type - The hwmon type (ex. fan).
55   *  @param[in] id - The hwmon id (ex. 1).
56   *  @param[in] sensor - The hwmon sensor (ex. target).
57   *
58   *  @returns - The value written
59   */
60 uint64_t writeSysfsWithCallout(const uint64_t& value,
61                                const std::string& root,
62                                const std::string& instance,
63                                const std::string& type,
64                                const std::string& id,
65                                const std::string& sensor);
66 
67 // vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
68