126b815faSBrad Bishop #pragma once 26292aeedSMatthew Barth 36292aeedSMatthew Barth #include <fstream> 46292aeedSMatthew Barth #include <string> 56292aeedSMatthew Barth 6*1e6324faSPatrick Venture namespace sysfs { 7*1e6324faSPatrick Venture 8a9b5f05bSBrad Bishop inline std::string make_sysfs_path(const std::string& path, 96292aeedSMatthew Barth const std::string& type, 106292aeedSMatthew Barth const std::string& id, 116292aeedSMatthew Barth const std::string& entry) 126292aeedSMatthew Barth { 136292aeedSMatthew Barth using namespace std::literals; 146292aeedSMatthew Barth 156292aeedSMatthew Barth return path + "/"s + type + id + "_"s + entry; 166292aeedSMatthew Barth } 176292aeedSMatthew Barth 18613a5b37SBrad Bishop 19613a5b37SBrad Bishop /** @brief Find hwmon instances 20613a5b37SBrad Bishop * 21613a5b37SBrad Bishop * Look for a matching hwmon instance given an 22613a5b37SBrad Bishop * open firmware device path. 23613a5b37SBrad Bishop * 24613a5b37SBrad Bishop * @param[in] ofNode- The open firmware device path. 25613a5b37SBrad Bishop * 26613a5b37SBrad Bishop * @returns[in] - The hwmon instance path or an empty 27613a5b37SBrad Bishop * string if no match is found. 28613a5b37SBrad Bishop */ 29613a5b37SBrad Bishop std::string findHwmon(const std::string& ofNode); 30613a5b37SBrad Bishop 314db64422SBrad Bishop /** @brief Read an hwmon sysfs value. 324db64422SBrad Bishop * 334db64422SBrad Bishop * Calls exit(3) with bad status on failure. 344db64422SBrad Bishop * 354db64422SBrad Bishop * @param[in] root - The hwmon class root. 364db64422SBrad Bishop * @param[in] instance - The hwmon instance (ex. hwmon1). 374db64422SBrad Bishop * @param[in] type - The hwmon type (ex. temp). 384db64422SBrad Bishop * @param[in] id - The hwmon id (ex. 1). 394db64422SBrad Bishop * @param[in] sensor - The hwmon sensor (ex. input). 404db64422SBrad Bishop * 414db64422SBrad Bishop * @returns - The read value. 424db64422SBrad Bishop */ 434db64422SBrad Bishop int readSysfsWithCallout(const std::string& root, 444db64422SBrad Bishop const std::string& instance, 454db64422SBrad Bishop const std::string& type, 464db64422SBrad Bishop const std::string& id, 474db64422SBrad Bishop const std::string& sensor); 484db64422SBrad Bishop 49048ac87fSMatthew Barth /** @brief Write a hwmon sysfs value 50048ac87fSMatthew Barth * 51048ac87fSMatthew Barth * Calls exit(3) with bad status on failure 52048ac87fSMatthew Barth * 53048ac87fSMatthew Barth * @param[in] value - The value to be written 54048ac87fSMatthew Barth * @param[in] root - The hwmon class root. 55048ac87fSMatthew Barth * @param[in] instance - The hwmon instance (ex. hwmon1). 56048ac87fSMatthew Barth * @param[in] type - The hwmon type (ex. fan). 57048ac87fSMatthew Barth * @param[in] id - The hwmon id (ex. 1). 58048ac87fSMatthew Barth * @param[in] sensor - The hwmon sensor (ex. target). 59048ac87fSMatthew Barth * 60048ac87fSMatthew Barth * @returns - The value written 61048ac87fSMatthew Barth */ 62048ac87fSMatthew Barth uint64_t writeSysfsWithCallout(const uint64_t& value, 63048ac87fSMatthew Barth const std::string& root, 64048ac87fSMatthew Barth const std::string& instance, 65048ac87fSMatthew Barth const std::string& type, 66048ac87fSMatthew Barth const std::string& id, 67048ac87fSMatthew Barth const std::string& sensor); 68048ac87fSMatthew Barth 69*1e6324faSPatrick Venture } 70*1e6324faSPatrick Venture 7103476f11SBrad Bishop // vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 72