126b815faSBrad Bishop #pragma once 26292aeedSMatthew Barth 36292aeedSMatthew Barth #include <string> 46292aeedSMatthew Barth 5043d3230SPatrick Venture namespace sysfs 6043d3230SPatrick Venture { 71e6324faSPatrick Venture make_sysfs_path(const std::string & path,const std::string & type,const std::string & id,const std::string & entry)8*94539af6SPatrick Williamsinline std::string make_sysfs_path( 9*94539af6SPatrick Williams const std::string& path, const std::string& type, const std::string& id, 10*94539af6SPatrick Williams const std::string& entry) 116292aeedSMatthew Barth { 126292aeedSMatthew Barth using namespace std::literals; 136292aeedSMatthew Barth 14043d3230SPatrick Venture if (entry.empty()) 15043d3230SPatrick Venture { 169331ab78SPatrick Venture return path + "/"s + type + id; 179331ab78SPatrick Venture } 189331ab78SPatrick Venture 196292aeedSMatthew Barth return path + "/"s + type + id + "_"s + entry; 206292aeedSMatthew Barth } 216292aeedSMatthew Barth 22f4bf63adSBrad Bishop /** @brief Return the path to the phandle file matching value in io-channels. 23f4bf63adSBrad Bishop * 24f4bf63adSBrad Bishop * This function will take two passed in paths. 25f4bf63adSBrad Bishop * One path is used to find the io-channels file. 26f4bf63adSBrad Bishop * The other path is used to find the phandle file. 27f4bf63adSBrad Bishop * The 4 byte phandle value is read from the phandle file(s). 28f4bf63adSBrad Bishop * The 4 byte phandle value and 4 byte index value is read from io-channels. 29f4bf63adSBrad Bishop * When a match is found, the path to the matching phandle file is returned. 30f4bf63adSBrad Bishop * 31f4bf63adSBrad Bishop * @param[in] iochanneldir - Path to file for getting phandle from io-channels 32f4bf63adSBrad Bishop * @param[in] phandledir - Path to use for reading from phandle file 33f4bf63adSBrad Bishop * 34f4bf63adSBrad Bishop * @return Path to phandle file with value matching that in io-channels 35f4bf63adSBrad Bishop */ 36043d3230SPatrick Venture std::string findPhandleMatch(const std::string& iochanneldir, 37f4bf63adSBrad Bishop const std::string& phandledir); 38613a5b37SBrad Bishop 3931dbe062SMatt Spinler /** @brief Find hwmon instances from an open-firmware device tree path 40613a5b37SBrad Bishop * 41613a5b37SBrad Bishop * Look for a matching hwmon instance given an 42613a5b37SBrad Bishop * open firmware device path. 43613a5b37SBrad Bishop * 44613a5b37SBrad Bishop * @param[in] ofNode- The open firmware device path. 45613a5b37SBrad Bishop * 46613a5b37SBrad Bishop * @returns[in] - The hwmon instance path or an empty 47613a5b37SBrad Bishop * string if no match is found. 48613a5b37SBrad Bishop */ 495c014d2bSMatt Spinler std::string findHwmonFromOFPath(const std::string& ofNode); 50613a5b37SBrad Bishop 51626df17aSMatt Spinler /** @brief Find hwmon instances from a device path 52626df17aSMatt Spinler * 53626df17aSMatt Spinler * Look for a matching hwmon instance given a device path that 54626df17aSMatt Spinler * starts with /devices. This path is the DEVPATH udev attribute 55626df17aSMatt Spinler * for the device except it has the '/hwmon/hwmonN' stripped off. 56626df17aSMatt Spinler * 57626df17aSMatt Spinler * @param[in] devPath - The device path. 58626df17aSMatt Spinler * 59626df17aSMatt Spinler * @return - The hwmon instance path or an empty 60626df17aSMatt Spinler * string if no match is found. 61626df17aSMatt Spinler */ 625c014d2bSMatt Spinler std::string findHwmonFromDevPath(const std::string& devPath); 63626df17aSMatt Spinler 64431d26a5SBrad Bishop /** @brief Return the path to use for a call out. 65431d26a5SBrad Bishop * 66431d26a5SBrad Bishop * Return an empty string if a callout path cannot be 67431d26a5SBrad Bishop * found. 68431d26a5SBrad Bishop * 69431d26a5SBrad Bishop * @param[in] instancePath - /sys/class/hwmon/hwmon<N> path. 70431d26a5SBrad Bishop * 71431d26a5SBrad Bishop * @return Path to use for call out 72431d26a5SBrad Bishop */ 73431d26a5SBrad Bishop std::string findCalloutPath(const std::string& instancePath); 74431d26a5SBrad Bishop 75dd467396SPatrick Venture } // namespace sysfs 76