126b815faSBrad Bishop #pragma once 26292aeedSMatthew Barth 36292aeedSMatthew Barth #include <fstream> 46292aeedSMatthew Barth #include <string> 56292aeedSMatthew Barth 6a9b5f05bSBrad Bishop inline std::string make_sysfs_path(const std::string& path, 76292aeedSMatthew Barth const std::string& type, 86292aeedSMatthew Barth const std::string& id, 96292aeedSMatthew Barth const std::string& entry) 106292aeedSMatthew Barth { 116292aeedSMatthew Barth using namespace std::literals; 126292aeedSMatthew Barth 136292aeedSMatthew Barth return path + "/"s + type + id + "_"s + entry; 146292aeedSMatthew Barth } 156292aeedSMatthew Barth 16613a5b37SBrad Bishop 17613a5b37SBrad Bishop /** @brief Find hwmon instances 18613a5b37SBrad Bishop * 19613a5b37SBrad Bishop * Look for a matching hwmon instance given an 20613a5b37SBrad Bishop * open firmware device path. 21613a5b37SBrad Bishop * 22613a5b37SBrad Bishop * @param[in] ofNode- The open firmware device path. 23613a5b37SBrad Bishop * 24613a5b37SBrad Bishop * @returns[in] - The hwmon instance path or an empty 25613a5b37SBrad Bishop * string if no match is found. 26613a5b37SBrad Bishop */ 27613a5b37SBrad Bishop std::string findHwmon(const std::string& ofNode); 28613a5b37SBrad Bishop 294db64422SBrad Bishop /** @brief Read an hwmon sysfs value. 304db64422SBrad Bishop * 314db64422SBrad Bishop * Calls exit(3) with bad status on failure. 324db64422SBrad Bishop * 334db64422SBrad Bishop * @param[in] root - The hwmon class root. 344db64422SBrad Bishop * @param[in] instance - The hwmon instance (ex. hwmon1). 354db64422SBrad Bishop * @param[in] type - The hwmon type (ex. temp). 364db64422SBrad Bishop * @param[in] id - The hwmon id (ex. 1). 374db64422SBrad Bishop * @param[in] sensor - The hwmon sensor (ex. input). 384db64422SBrad Bishop * 394db64422SBrad Bishop * @returns - The read value. 404db64422SBrad Bishop */ 414db64422SBrad Bishop int readSysfsWithCallout(const std::string& root, 424db64422SBrad Bishop const std::string& instance, 434db64422SBrad Bishop const std::string& type, 444db64422SBrad Bishop const std::string& id, 454db64422SBrad Bishop const std::string& sensor); 464db64422SBrad Bishop 47*048ac87fSMatthew Barth /** @brief Write a hwmon sysfs value 48*048ac87fSMatthew Barth * 49*048ac87fSMatthew Barth * Calls exit(3) with bad status on failure 50*048ac87fSMatthew Barth * 51*048ac87fSMatthew Barth * @param[in] value - The value to be written 52*048ac87fSMatthew Barth * @param[in] root - The hwmon class root. 53*048ac87fSMatthew Barth * @param[in] instance - The hwmon instance (ex. hwmon1). 54*048ac87fSMatthew Barth * @param[in] type - The hwmon type (ex. fan). 55*048ac87fSMatthew Barth * @param[in] id - The hwmon id (ex. 1). 56*048ac87fSMatthew Barth * @param[in] sensor - The hwmon sensor (ex. target). 57*048ac87fSMatthew Barth * 58*048ac87fSMatthew Barth * @returns - The value written 59*048ac87fSMatthew Barth */ 60*048ac87fSMatthew Barth uint64_t writeSysfsWithCallout(const uint64_t& value, 61*048ac87fSMatthew Barth const std::string& root, 62*048ac87fSMatthew Barth const std::string& instance, 63*048ac87fSMatthew Barth const std::string& type, 64*048ac87fSMatthew Barth const std::string& id, 65*048ac87fSMatthew Barth const std::string& sensor); 66*048ac87fSMatthew Barth 6703476f11SBrad Bishop // vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 68