blob: ada73e89c127eba7ea825a20b40dfee678c165fa [file] [log] [blame]
Brad Bishop26b815f2017-01-04 13:32:47 -05001#pragma once
Patrick Williams3667cf32015-10-20 22:39:11 -05002
3#include <fstream>
4#include <string>
5
Patrick Venture1e6324f2017-06-01 14:07:05 -07006namespace sysfs {
7
Brad Bishopa9b5f052017-01-17 14:50:08 -05008inline std::string make_sysfs_path(const std::string& path,
9 const std::string& type,
10 const std::string& id,
11 const std::string& entry)
Patrick Williams3667cf32015-10-20 22:39:11 -050012{
13 using namespace std::literals;
14
15 return path + "/"s + type + id + "_"s + entry;
16}
17
Brad Bishop613a5b32017-01-05 20:58:13 -050018
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 */
29std::string findHwmon(const std::string& ofNode);
30
Brad Bishop4db64422017-02-16 11:33:32 -050031/** @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 */
43int 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
Matthew Barth048ac872017-03-09 14:36:08 -060049 /** @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 */
62uint64_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
Patrick Venture1e6324f2017-06-01 14:07:05 -070069}
70
Brad Bishop03476f12016-12-19 13:09:12 -050071// vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4