xref: /openbmc/phosphor-hwmon/sysfs.hpp (revision f9aff805)
1 #pragma once
2 
3 #include <string>
4 
5 namespace sysfs
6 {
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     if (entry.empty())
16     {
17         return path + "/"s + type + id;
18     }
19 
20     return path + "/"s + type + id + "_"s + entry;
21 }
22 
23 /** @brief Return the path to the phandle file matching value in io-channels.
24  *
25  *  This function will take two passed in paths.
26  *  One path is used to find the io-channels file.
27  *  The other path is used to find the phandle file.
28  *  The 4 byte phandle value is read from the phandle file(s).
29  *  The 4 byte phandle value and 4 byte index value is read from io-channels.
30  *  When a match is found, the path to the matching phandle file is returned.
31  *
32  *  @param[in] iochanneldir - Path to file for getting phandle from io-channels
33  *  @param[in] phandledir - Path to use for reading from phandle file
34  *
35  *  @return Path to phandle file with value matching that in io-channels
36  */
37 std::string findPhandleMatch(const std::string& iochanneldir,
38                              const std::string& phandledir);
39 
40 /** @brief Find hwmon instances from an open-firmware device tree path
41  *
42  *  Look for a matching hwmon instance given an
43  *  open firmware device path.
44  *
45  *  @param[in] ofNode- The open firmware device path.
46  *
47  *  @returns[in] - The hwmon instance path or an empty
48  *                 string if no match is found.
49  */
50 std::string findHwmonFromOFPath(const std::string& ofNode);
51 
52 /** @brief Find hwmon instances from a device path
53  *
54  *  Look for a matching hwmon instance given a device path that
55  *  starts with /devices.  This path is the DEVPATH udev attribute
56  *  for the device except it has the '/hwmon/hwmonN' stripped off.
57  *
58  *  @param[in] devPath - The device path.
59  *
60  *  @return - The hwmon instance path or an empty
61  *            string if no match is found.
62  */
63 std::string findHwmonFromDevPath(const std::string& devPath);
64 
65 /** @brief Return the path to use for a call out.
66  *
67  *  Return an empty string if a callout path cannot be
68  *  found.
69  *
70  *  @param[in] instancePath - /sys/class/hwmon/hwmon<N> path.
71  *
72  *  @return Path to use for call out
73  */
74 std::string findCalloutPath(const std::string& instancePath);
75 
76 } // namespace sysfs
77 
78 // vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
79