Only write pwm_enable if it has an env var
Some device drivers don't need pwmX_enable written, so
only do it if an environment variable is present that
contains the value to write.
The environment variable is specified in the conf file
along with the other enviroment variables and would look like:
ENABLE_fan1 = "2"
Change-Id: I484ada60957cb0d2b133a69b36bf12cbaad948dc
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
diff --git a/fan_speed.cpp b/fan_speed.cpp
index 13aa266..2652f8d 100644
--- a/fan_speed.cpp
+++ b/fan_speed.cpp
@@ -1,9 +1,10 @@
+#include <phosphor-logging/elog-errors.hpp>
+#include <xyz/openbmc_project/Control/Device/error.hpp>
+#include "sensorset.hpp"
+#include "env.hpp"
#include "fan_speed.hpp"
#include "hwmon.hpp"
#include "sysfs.hpp"
-#include <experimental/filesystem>
-#include <phosphor-logging/elog-errors.hpp>
-#include <xyz/openbmc_project/Control/Device/error.hpp>
using namespace phosphor::logging;
@@ -57,20 +58,15 @@
void FanSpeed::enable()
{
- namespace fs = std::experimental::filesystem;
-
- auto fullPath = sysfs::make_sysfs_path(ioAccess.path(),
- type::pwm,
- id,
- entry::enable);
-
- if (fs::exists(fullPath))
+ auto enable = getEnv("ENABLE", type, id);
+ if (!enable.empty())
{
- //This class always uses RPM mode
+ auto val = std::stoul(enable);
+
try
{
ioAccess.write(
- enable::rpmMode,
+ val,
type::pwm,
id,
entry::enable,
@@ -87,6 +83,12 @@
xyz::openbmc_project::Control::Device::
WriteFailure::CALLOUT_DEVICE_PATH(devPath.c_str()));
+ auto fullPath = sysfs::make_sysfs_path(
+ ioAccess.path(),
+ type::pwm,
+ id,
+ entry::enable);
+
log<level::INFO>("Logging failing sysfs file",
phosphor::logging::entry("FILE=%s", fullPath.c_str()));
diff --git a/fan_speed.hpp b/fan_speed.hpp
index b47d718..3203178 100644
--- a/fan_speed.hpp
+++ b/fan_speed.hpp
@@ -48,7 +48,8 @@
uint64_t target(uint64_t value) override;
/**
- * @brief Writes the pwm_enable sysfs entry.
+ * @brief Writes the pwm_enable sysfs entry if the
+ * env var with the value to write is present
*/
void enable();
diff --git a/hwmon.hpp b/hwmon.hpp
index a64d564..5a4744c 100644
--- a/hwmon.hpp
+++ b/hwmon.hpp
@@ -17,11 +17,6 @@
static const std::string enable = cenable;
}
-namespace enable
-{
-static const auto rpmMode = 2;
-}
-
namespace type
{
static constexpr auto cfan = "fan";