Brad Bishop | 26b815f | 2017-01-04 13:32:47 -0500 | [diff] [blame] | 1 | #pragma once |
Patrick Williams | 3667cf3 | 2015-10-20 22:39:11 -0500 | [diff] [blame] | 2 | |
Patrick Williams | 3667cf3 | 2015-10-20 22:39:11 -0500 | [diff] [blame] | 3 | #include <string> |
| 4 | |
Patrick Venture | 043d323 | 2018-08-31 10:10:53 -0700 | [diff] [blame] | 5 | namespace sysfs |
| 6 | { |
Patrick Venture | 1e6324f | 2017-06-01 14:07:05 -0700 | [diff] [blame] | 7 | |
Brad Bishop | a9b5f05 | 2017-01-17 14:50:08 -0500 | [diff] [blame] | 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) |
Patrick Williams | 3667cf3 | 2015-10-20 22:39:11 -0500 | [diff] [blame] | 12 | { |
| 13 | using namespace std::literals; |
| 14 | |
Patrick Venture | 043d323 | 2018-08-31 10:10:53 -0700 | [diff] [blame] | 15 | if (entry.empty()) |
| 16 | { |
Patrick Venture | 9331ab7 | 2018-01-29 09:48:47 -0800 | [diff] [blame] | 17 | return path + "/"s + type + id; |
| 18 | } |
| 19 | |
Patrick Williams | 3667cf3 | 2015-10-20 22:39:11 -0500 | [diff] [blame] | 20 | return path + "/"s + type + id + "_"s + entry; |
| 21 | } |
| 22 | |
Brad Bishop | f4bf63a | 2017-08-28 15:39:19 -0400 | [diff] [blame] | 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 | */ |
Patrick Venture | 043d323 | 2018-08-31 10:10:53 -0700 | [diff] [blame] | 37 | std::string findPhandleMatch(const std::string& iochanneldir, |
| 38 | const std::string& phandledir); |
Brad Bishop | 613a5b3 | 2017-01-05 20:58:13 -0500 | [diff] [blame] | 39 | |
Matt Spinler | 31dbe06 | 2018-03-05 12:01:48 -0600 | [diff] [blame] | 40 | /** @brief Find hwmon instances from an open-firmware device tree path |
Brad Bishop | 613a5b3 | 2017-01-05 20:58:13 -0500 | [diff] [blame] | 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 | */ |
Matt Spinler | 5c014d2 | 2019-04-16 09:13:14 -0500 | [diff] [blame] | 50 | std::string findHwmonFromOFPath(const std::string& ofNode); |
Brad Bishop | 613a5b3 | 2017-01-05 20:58:13 -0500 | [diff] [blame] | 51 | |
Matt Spinler | 626df17 | 2018-03-05 12:03:55 -0600 | [diff] [blame] | 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 | */ |
Matt Spinler | 5c014d2 | 2019-04-16 09:13:14 -0500 | [diff] [blame] | 63 | std::string findHwmonFromDevPath(const std::string& devPath); |
Matt Spinler | 626df17 | 2018-03-05 12:03:55 -0600 | [diff] [blame] | 64 | |
Brad Bishop | 431d26a | 2017-08-25 09:47:58 -0400 | [diff] [blame] | 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 | |
Patrick Venture | dd46739 | 2018-04-20 17:22:49 -0700 | [diff] [blame] | 76 | } // namespace sysfs |
Patrick Venture | 1e6324f | 2017-06-01 14:07:05 -0700 | [diff] [blame] | 77 | |
Brad Bishop | 03476f1 | 2016-12-19 13:09:12 -0500 | [diff] [blame] | 78 | // vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 |