Add fan pwm interface target
The current daemon only supports RPM-based fan control, whereas the
hwmon interface for PWM is often present. This implements the Fan
Control PWM dbus interface.
This CL is not the complete solution, but if mixed with a follow-on CL
that does this, I think it'll be ideal. For instance, this assumes the
pwm number matches, whereas the other CL lets you specify the
corresponding PWM target for the fan.
Change-Id: I23aaa0619cdefba0a004ac0d26dc6b928e78f1e8
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/targets.hpp b/targets.hpp
index 5e938b0..b671467 100644
--- a/targets.hpp
+++ b/targets.hpp
@@ -5,6 +5,7 @@
#include <phosphor-logging/log.hpp>
#include <xyz/openbmc_project/Sensor/Device/error.hpp>
#include "fan_speed.hpp"
+#include "fan_pwm.hpp"
/** @class Targets
* @brief Target type traits.
@@ -27,6 +28,12 @@
static constexpr InterfaceType type = InterfaceType::FAN_SPEED;
};
+template <>
+struct Targets<hwmon::FanPwm>
+{
+ static constexpr InterfaceType type = InterfaceType::FAN_PWM;
+};
+
/** @brief addTarget
*
* Creates the target type interface
@@ -54,25 +61,58 @@
auto& bus = *std::get<sdbusplus::bus::bus*>(info);
auto& obj = std::get<Object>(info);
auto& objPath = std::get<std::string>(info);
+ auto type = Targets<T>::type;
// Check if target sysfs file exists
- auto sysfsFullPath = sysfs::make_sysfs_path(ioAccess.path(),
- sensor.first,
- sensor.second,
- hwmon::entry::target);
+ std::string sysfsFullPath;
+
+ using namespace std::literals;
+ const std::string pwm = "pwm"s;
+ const std::string empty = ""s;
+
+ if (InterfaceType::FAN_PWM == type)
+ {
+ /* We're leveraging that the sensor ID matches for PWM.
+ * TODO(venture): There's a CL from intel that allows
+ * this to be specified via an environment variable.
+ */
+ sysfsFullPath = sysfs::make_sysfs_path(ioAccess.path(),
+ pwm,
+ sensor.second,
+ empty);
+ }
+ else
+ {
+ sysfsFullPath = sysfs::make_sysfs_path(ioAccess.path(),
+ sensor.first,
+ sensor.second,
+ hwmon::entry::target);
+ }
+
if (fs::exists(sysfsFullPath))
{
uint32_t targetSpeed = 0;
try
{
- targetSpeed = ioAccess.read(
- sensor.first,
- sensor.second,
- hwmon::entry::target,
- sysfs::hwmonio::retries,
- sysfs::hwmonio::delay);
-
+ if (InterfaceType::FAN_PWM == type)
+ {
+ targetSpeed = ioAccess.read(
+ pwm,
+ sensor.second,
+ empty,
+ sysfs::hwmonio::retries,
+ sysfs::hwmonio::delay);
+ }
+ else
+ {
+ targetSpeed = ioAccess.read(
+ sensor.first,
+ sensor.second,
+ hwmon::entry::target,
+ sysfs::hwmonio::retries,
+ sysfs::hwmonio::delay);
+ }
}
catch (const std::system_error& e)
{