fansensor: enable fan sensors through fanN_enable sysfs if available
The hwmon sysfs standard defines a fanN_enable file to enable or
disable the sensors[0]. This change will attempt to enable the sensors
with this enable file if they are found.
Tested:
with max31790 and recent patch[1] and saw that fanN_enable files
were 0 before fansensor started, and 1 after fansensor started, with the
appropriate entity-manager config.
[0]: https://www.kernel.org/doc/html/latest/hwmon/sysfs-interface.html#fans
[1]: https://patchwork.kernel.org/project/linux-hwmon/patch/20220829195930.2521755-1-justinledford@google.com/
Signed-off-by: Justin Ledford <justinledford@google.com>
Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: Ic56a6528d3fa468d54c03c674540179d4a56036b
diff --git a/src/FanMain.cpp b/src/FanMain.cpp
index 4e7542b..a192380 100644
--- a/src/FanMain.cpp
+++ b/src/FanMain.cpp
@@ -150,6 +150,31 @@
pwmPath = path;
return true;
}
+
+// The argument to this function should be the fanN_input file that we want to
+// enable. The function will locate the corresponding fanN_enable file if it
+// exists. Note that some drivers don't provide this file if the sensors are
+// always enabled.
+void enableFanInput(const fs::path& fanInputPath)
+{
+ std::error_code ec;
+ std::string path(fanInputPath.string());
+ boost::replace_last(path, "input", "enable");
+
+ bool exists = fs::exists(path, ec);
+ if (ec || !exists)
+ {
+ return;
+ }
+
+ std::fstream enableFile(path, std::ios::out);
+ if (!enableFile.good())
+ {
+ return;
+ }
+ enableFile << 1;
+}
+
void createRedundancySensor(
const boost::container::flat_map<std::string, std::shared_ptr<TachSensor>>&
sensors,
@@ -486,6 +511,8 @@
findLimits(limits, baseConfiguration);
+ enableFanInput(path);
+
auto& tachSensor = tachSensors[sensorName];
tachSensor = nullptr;
tachSensor = std::make_shared<TachSensor>(