summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLei YU <mine260309@gmail.com>2018-01-31 13:51:05 +0800
committerLei YU <mine260309@gmail.com>2018-02-02 14:20:52 +0800
commita4bba96ed8e6a706928bd2c4de5f113df9304047 (patch)
tree221c329632b8d1b5825995b6dcd2c4ac4aaa761f
parent9331ab7846750a05b90efd845935bfd3275e694c (diff)
downloadphosphor-hwmon-a4bba96ed8e6a706928bd2c4de5f113df9304047.tar.gz
phosphor-hwmon-a4bba96ed8e6a706928bd2c4de5f113df9304047.zip
Add pwm id as fan pwm target
The current code assumes fan and pwm has the same id. This commit add the support to use pwmX as fan pwm target by PWM_TARGET_ environment. E.g. PWM_TARGET_fan0 = "1" PWM_TARGET_fan1 = "1" PWM_TARGET_fan2 = "2" PWM_TARGET_fan3 = "2" The above config tells hwmon to set pwm1 for fan0/1's pwm target, and set pwm2 for fan2/3's pwm target. Change-Id: Ic1d850ca3d6d20274d905fa9004d7eba2718e9eb Signed-off-by: Lei YU <mine260309@gmail.com>
-rw-r--r--targets.hpp57
1 files changed, 22 insertions, 35 deletions
diff --git a/targets.hpp b/targets.hpp
index b671467..de86170 100644
--- a/targets.hpp
+++ b/targets.hpp
@@ -65,6 +65,9 @@ std::shared_ptr<T> addTarget(const SensorSet::key_type& sensor,
// Check if target sysfs file exists
std::string sysfsFullPath;
+ std::string targetName = sensor.first;
+ std::string targetId = sensor.second;
+ std::string entry = hwmon::entry::target;
using namespace std::literals;
const std::string pwm = "pwm"s;
@@ -72,47 +75,32 @@ std::shared_ptr<T> addTarget(const SensorSet::key_type& sensor,
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);
+ targetName = pwm;
+ // If PWM_TARGET is set, use the specified pwm id
+ auto id = getEnv("PWM_TARGET", sensor);
+ if (!id.empty())
+ {
+ targetId = id;
+ }
+ entry = empty;
}
+ sysfsFullPath = sysfs::make_sysfs_path(ioAccess.path(),
+ targetName,
+ targetId,
+ entry);
if (fs::exists(sysfsFullPath))
{
uint32_t targetSpeed = 0;
try
{
- 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);
- }
+ targetSpeed = ioAccess.read(
+ targetName,
+ targetId,
+ entry,
+ sysfs::hwmonio::retries,
+ sysfs::hwmonio::delay);
}
catch (const std::system_error& e)
{
@@ -133,12 +121,11 @@ std::shared_ptr<T> addTarget(const SensorSet::key_type& sensor,
target = std::make_shared<T>(ioAccess.path(),
devPath,
- sensor.second,
+ targetId,
bus,
objPath.c_str(),
deferSignals,
targetSpeed);
- auto type = Targets<T>::type;
obj[type] = target;
}
OpenPOWER on IntegriCloud