blob: 6a84cbade90d4272b55dcbce5585eb172f1b1a5d [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
Patrick Williams02e598a2024-08-16 15:21:23 -04008inline std::string
9 make_sysfs_path(const std::string& path, const std::string& type,
10 const std::string& id, const std::string& entry)
Patrick Williams3667cf32015-10-20 22:39:11 -050011{
12 using namespace std::literals;
13
Patrick Venture043d3232018-08-31 10:10:53 -070014 if (entry.empty())
15 {
Patrick Venture9331ab72018-01-29 09:48:47 -080016 return path + "/"s + type + id;
17 }
18
Patrick Williams3667cf32015-10-20 22:39:11 -050019 return path + "/"s + type + id + "_"s + entry;
20}
21
Brad Bishopf4bf63a2017-08-28 15:39:19 -040022/** @brief Return the path to the phandle file matching value in io-channels.
23 *
24 * This function will take two passed in paths.
25 * One path is used to find the io-channels file.
26 * The other path is used to find the phandle file.
27 * The 4 byte phandle value is read from the phandle file(s).
28 * The 4 byte phandle value and 4 byte index value is read from io-channels.
29 * When a match is found, the path to the matching phandle file is returned.
30 *
31 * @param[in] iochanneldir - Path to file for getting phandle from io-channels
32 * @param[in] phandledir - Path to use for reading from phandle file
33 *
34 * @return Path to phandle file with value matching that in io-channels
35 */
Patrick Venture043d3232018-08-31 10:10:53 -070036std::string findPhandleMatch(const std::string& iochanneldir,
37 const std::string& phandledir);
Brad Bishop613a5b32017-01-05 20:58:13 -050038
Matt Spinler31dbe062018-03-05 12:01:48 -060039/** @brief Find hwmon instances from an open-firmware device tree path
Brad Bishop613a5b32017-01-05 20:58:13 -050040 *
41 * Look for a matching hwmon instance given an
42 * open firmware device path.
43 *
44 * @param[in] ofNode- The open firmware device path.
45 *
46 * @returns[in] - The hwmon instance path or an empty
47 * string if no match is found.
48 */
Matt Spinler5c014d22019-04-16 09:13:14 -050049std::string findHwmonFromOFPath(const std::string& ofNode);
Brad Bishop613a5b32017-01-05 20:58:13 -050050
Matt Spinler626df172018-03-05 12:03:55 -060051/** @brief Find hwmon instances from a device path
52 *
53 * Look for a matching hwmon instance given a device path that
54 * starts with /devices. This path is the DEVPATH udev attribute
55 * for the device except it has the '/hwmon/hwmonN' stripped off.
56 *
57 * @param[in] devPath - The device path.
58 *
59 * @return - The hwmon instance path or an empty
60 * string if no match is found.
61 */
Matt Spinler5c014d22019-04-16 09:13:14 -050062std::string findHwmonFromDevPath(const std::string& devPath);
Matt Spinler626df172018-03-05 12:03:55 -060063
Brad Bishop431d26a2017-08-25 09:47:58 -040064/** @brief Return the path to use for a call out.
65 *
66 * Return an empty string if a callout path cannot be
67 * found.
68 *
69 * @param[in] instancePath - /sys/class/hwmon/hwmon<N> path.
70 *
71 * @return Path to use for call out
72 */
73std::string findCalloutPath(const std::string& instancePath);
74
Patrick Venturedd467392018-04-20 17:22:49 -070075} // namespace sysfs