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 | |
Brad Bishop | 754d38c | 2017-09-08 00:46:58 -0400 | [diff] [blame] | 3 | #include <chrono> |
Matt Spinler | 3b8e36e | 2017-07-28 10:44:45 -0500 | [diff] [blame] | 4 | #include <exception> |
Patrick Williams | 3667cf3 | 2015-10-20 22:39:11 -0500 | [diff] [blame] | 5 | #include <fstream> |
| 6 | #include <string> |
| 7 | |
Patrick Venture | 043d323 | 2018-08-31 10:10:53 -0700 | [diff] [blame] | 8 | namespace sysfs |
| 9 | { |
Patrick Venture | 1e6324f | 2017-06-01 14:07:05 -0700 | [diff] [blame] | 10 | |
Brad Bishop | a9b5f05 | 2017-01-17 14:50:08 -0500 | [diff] [blame] | 11 | inline std::string make_sysfs_path(const std::string& path, |
| 12 | const std::string& type, |
| 13 | const std::string& id, |
| 14 | const std::string& entry) |
Patrick Williams | 3667cf3 | 2015-10-20 22:39:11 -0500 | [diff] [blame] | 15 | { |
| 16 | using namespace std::literals; |
| 17 | |
Patrick Venture | 043d323 | 2018-08-31 10:10:53 -0700 | [diff] [blame] | 18 | if (entry.empty()) |
| 19 | { |
Patrick Venture | 9331ab7 | 2018-01-29 09:48:47 -0800 | [diff] [blame] | 20 | return path + "/"s + type + id; |
| 21 | } |
| 22 | |
Patrick Williams | 3667cf3 | 2015-10-20 22:39:11 -0500 | [diff] [blame] | 23 | return path + "/"s + type + id + "_"s + entry; |
| 24 | } |
| 25 | |
Brad Bishop | f4bf63a | 2017-08-28 15:39:19 -0400 | [diff] [blame] | 26 | /** @brief Return the path to the phandle file matching value in io-channels. |
| 27 | * |
| 28 | * This function will take two passed in paths. |
| 29 | * One path is used to find the io-channels file. |
| 30 | * The other path is used to find the phandle file. |
| 31 | * The 4 byte phandle value is read from the phandle file(s). |
| 32 | * The 4 byte phandle value and 4 byte index value is read from io-channels. |
| 33 | * When a match is found, the path to the matching phandle file is returned. |
| 34 | * |
| 35 | * @param[in] iochanneldir - Path to file for getting phandle from io-channels |
| 36 | * @param[in] phandledir - Path to use for reading from phandle file |
| 37 | * |
| 38 | * @return Path to phandle file with value matching that in io-channels |
| 39 | */ |
Patrick Venture | 043d323 | 2018-08-31 10:10:53 -0700 | [diff] [blame] | 40 | std::string findPhandleMatch(const std::string& iochanneldir, |
| 41 | const std::string& phandledir); |
Brad Bishop | 613a5b3 | 2017-01-05 20:58:13 -0500 | [diff] [blame] | 42 | |
Matt Spinler | 31dbe06 | 2018-03-05 12:01:48 -0600 | [diff] [blame] | 43 | /** @brief Find hwmon instances from an open-firmware device tree path |
Brad Bishop | 613a5b3 | 2017-01-05 20:58:13 -0500 | [diff] [blame] | 44 | * |
| 45 | * Look for a matching hwmon instance given an |
| 46 | * open firmware device path. |
| 47 | * |
| 48 | * @param[in] ofNode- The open firmware device path. |
| 49 | * |
| 50 | * @returns[in] - The hwmon instance path or an empty |
| 51 | * string if no match is found. |
| 52 | */ |
Matt Spinler | 5c014d2 | 2019-04-16 09:13:14 -0500 | [diff] [blame] | 53 | std::string findHwmonFromOFPath(const std::string& ofNode); |
Brad Bishop | 613a5b3 | 2017-01-05 20:58:13 -0500 | [diff] [blame] | 54 | |
Matt Spinler | 626df17 | 2018-03-05 12:03:55 -0600 | [diff] [blame] | 55 | /** @brief Find hwmon instances from a device path |
| 56 | * |
| 57 | * Look for a matching hwmon instance given a device path that |
| 58 | * starts with /devices. This path is the DEVPATH udev attribute |
| 59 | * for the device except it has the '/hwmon/hwmonN' stripped off. |
| 60 | * |
| 61 | * @param[in] devPath - The device path. |
| 62 | * |
| 63 | * @return - The hwmon instance path or an empty |
| 64 | * string if no match is found. |
| 65 | */ |
Matt Spinler | 5c014d2 | 2019-04-16 09:13:14 -0500 | [diff] [blame] | 66 | std::string findHwmonFromDevPath(const std::string& devPath); |
Matt Spinler | 626df17 | 2018-03-05 12:03:55 -0600 | [diff] [blame] | 67 | |
Brad Bishop | 431d26a | 2017-08-25 09:47:58 -0400 | [diff] [blame] | 68 | /** @brief Return the path to use for a call out. |
| 69 | * |
| 70 | * Return an empty string if a callout path cannot be |
| 71 | * found. |
| 72 | * |
| 73 | * @param[in] instancePath - /sys/class/hwmon/hwmon<N> path. |
| 74 | * |
| 75 | * @return Path to use for call out |
| 76 | */ |
| 77 | std::string findCalloutPath(const std::string& instancePath); |
| 78 | |
Patrick Venture | dd46739 | 2018-04-20 17:22:49 -0700 | [diff] [blame] | 79 | } // namespace sysfs |
Patrick Venture | 1e6324f | 2017-06-01 14:07:05 -0700 | [diff] [blame] | 80 | |
Brad Bishop | 03476f1 | 2016-12-19 13:09:12 -0500 | [diff] [blame] | 81 | // vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 |