blob: 80fb3d6958c8abbf529e4d38da9ca9f8b4d109b2 [file] [log] [blame]
Brad Bishop26b815f2017-01-04 13:32:47 -05001#pragma once
Patrick Williams3667cf32015-10-20 22:39:11 -05002
Patrick Williams3667cf32015-10-20 22:39:11 -05003#include <string>
4
Patrick Venture043d3232018-08-31 10:10:53 -07005namespace sysfs
6{
Patrick Venture1e6324f2017-06-01 14:07:05 -07007
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
Patrick Venture043d3232018-08-31 10:10:53 -070015 if (entry.empty())
16 {
Patrick Venture9331ab72018-01-29 09:48:47 -080017 return path + "/"s + type + id;
18 }
19
Patrick Williams3667cf32015-10-20 22:39:11 -050020 return path + "/"s + type + id + "_"s + entry;
21}
22
Brad Bishopf4bf63a2017-08-28 15:39:19 -040023/** @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 */
Patrick Venture043d3232018-08-31 10:10:53 -070037std::string findPhandleMatch(const std::string& iochanneldir,
38 const std::string& phandledir);
Brad Bishop613a5b32017-01-05 20:58:13 -050039
Matt Spinler31dbe062018-03-05 12:01:48 -060040/** @brief Find hwmon instances from an open-firmware device tree path
Brad Bishop613a5b32017-01-05 20:58:13 -050041 *
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 */
Matt Spinler5c014d22019-04-16 09:13:14 -050050std::string findHwmonFromOFPath(const std::string& ofNode);
Brad Bishop613a5b32017-01-05 20:58:13 -050051
Matt Spinler626df172018-03-05 12:03:55 -060052/** @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 */
Matt Spinler5c014d22019-04-16 09:13:14 -050063std::string findHwmonFromDevPath(const std::string& devPath);
Matt Spinler626df172018-03-05 12:03:55 -060064
Brad Bishop431d26a2017-08-25 09:47:58 -040065/** @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 */
74std::string findCalloutPath(const std::string& instancePath);
75
Patrick Venturedd467392018-04-20 17:22:49 -070076} // namespace sysfs
Patrick Venture1e6324f2017-06-01 14:07:05 -070077
Brad Bishop03476f12016-12-19 13:09:12 -050078// vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4