summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Barth <msbarth@us.ibm.com>2018-03-26 16:57:36 -0500
committerMatt Spinler <spinler@us.ibm.com>2018-04-13 14:33:41 +0000
commit28f8e66dd50d5c855ddf0ea02f2eef56ec0274fc (patch)
treeb66840d70b7eef2612a627efd6ea6f911f92aed8
parent33db92bc2ac5e345d5a42cae8ce48aa55d4dacef (diff)
downloadphosphor-hwmon-28f8e66dd50d5c855ddf0ea02f2eef56ec0274fc.tar.gz
phosphor-hwmon-28f8e66dd50d5c855ddf0ea02f2eef56ec0274fc.zip
Check TARGET_MODE on target sensors
Move the TARGET_MODE config entry to be done on target specific sensors. Tested: Target sensors are still created for the mode given in TARGET_MODE Change-Id: I7731b73e14495360ccb5b8fb8ada59176e9125d3 Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
-rw-r--r--mainloop.cpp46
-rw-r--r--targets.hpp99
2 files changed, 72 insertions, 73 deletions
diff --git a/mainloop.cpp b/mainloop.cpp
index d3987cc..29ce2b3 100644
--- a/mainloop.cpp
+++ b/mainloop.cpp
@@ -285,32 +285,6 @@ auto addValue(const SensorSet::key_type& sensor,
*/
void MainLoop::getObject(SensorSet::container_t::const_reference sensor)
{
- //If this device supports target speeds,
- //check which type to use.
- targetType fanTargetType = targetType::DEFAULT;
- auto targetMode = getenv("TARGET_MODE");
- if (targetMode)
- {
- std::string type{targetMode};
- std::transform(type.begin(), type.end(), type.begin(), toupper);
-
- if (type == RPM_TARGET)
- {
- fanTargetType = targetType::RPM;
- }
- else if (type == PWM_TARGET)
- {
- fanTargetType = targetType::PWM;
- }
- else
- {
- log<level::ERR>(
- "Invalid TARGET_MODE env var found",
- entry("TARGET_MODE=%s", targetMode),
- entry("DEVPATH=%s", _devPath.c_str()));
- }
- }
-
// Get list of return codes for removing sensors on device
std::string deviceRmRCs;
auto devRmRCs = getenv("REMOVERCS");
@@ -422,23 +396,13 @@ void MainLoop::getObject(SensorSet::container_t::const_reference sensor)
addThreshold<WarningObject>(sensor.first.first, id, sensorValue, info);
addThreshold<CriticalObject>(sensor.first.first, id, sensorValue, info);
- if ((fanTargetType == targetType::RPM) ||
- (fanTargetType == targetType::DEFAULT))
- {
- auto target = addTarget<hwmon::FanSpeed>(
- sensor.first, ioAccess, _devPath, info);
-
- if (target)
- {
- target->enable();
- }
- }
-
- if ((fanTargetType == targetType::PWM) ||
- (fanTargetType == targetType::DEFAULT))
+ auto target = addTarget<hwmon::FanSpeed>(
+ sensor.first, ioAccess, _devPath, info);
+ if (target)
{
- addTarget<hwmon::FanPwm>(sensor.first, ioAccess, _devPath, info);
+ target->enable();
}
+ addTarget<hwmon::FanPwm>(sensor.first, ioAccess, _devPath, info);
// All the interfaces have been created. Go ahead
// and emit InterfacesAdded.
diff --git a/targets.hpp b/targets.hpp
index ecef77b..3c6dc0d 100644
--- a/targets.hpp
+++ b/targets.hpp
@@ -101,42 +101,77 @@ std::shared_ptr<T> addTarget(const SensorSet::key_type& sensor,
entry);
if (fs::exists(sysfsFullPath))
{
- uint32_t targetSpeed = 0;
-
- try
+ auto useTarget = true;
+ auto tmEnv = getenv("TARGET_MODE");
+ if (tmEnv)
{
- targetSpeed = ioAccess.read(
- targetName,
- targetId,
- entry,
- sysfs::hwmonio::retries,
- sysfs::hwmonio::delay);
+ std::string mode{tmEnv};
+ std::transform(mode.begin(), mode.end(), mode.begin(), toupper);
+
+ if (mode == RPM_TARGET)
+ {
+ if (type != InterfaceType::FAN_SPEED)
+ {
+ useTarget = false;
+ }
+ }
+ else if (mode == PWM_TARGET)
+ {
+ if (type != InterfaceType::FAN_PWM)
+ {
+ useTarget = false;
+ }
+ }
+ else
+ {
+ using namespace phosphor::logging;
+ log<level::ERR>("Invalid TARGET_MODE env var found",
+ phosphor::logging::entry(
+ "TARGET_MODE=%s", tmEnv),
+ phosphor::logging::entry(
+ "DEVPATH=%s", devPath.c_str()));
+ }
}
- catch (const std::system_error& e)
+
+ if (useTarget)
{
- using namespace phosphor::logging;
- using namespace sdbusplus::xyz::openbmc_project::
- Sensor::Device::Error;
- using metadata = xyz::openbmc_project::Sensor::
- Device::ReadFailure;
-
- report<ReadFailure>(
- metadata::CALLOUT_ERRNO(e.code().value()),
- metadata::CALLOUT_DEVICE_PATH(devPath.c_str()));
-
- log<level::INFO>("Logging failing sysfs file",
- phosphor::logging::entry(
- "FILE=%s", sysfsFullPath.c_str()));
+ uint32_t targetSpeed = 0;
+
+ try
+ {
+ targetSpeed = ioAccess.read(
+ targetName,
+ targetId,
+ entry,
+ sysfs::hwmonio::retries,
+ sysfs::hwmonio::delay);
+ }
+ catch (const std::system_error& e)
+ {
+ using namespace phosphor::logging;
+ using namespace sdbusplus::xyz::openbmc_project::
+ Sensor::Device::Error;
+ using metadata = xyz::openbmc_project::Sensor::
+ Device::ReadFailure;
+
+ report<ReadFailure>(
+ metadata::CALLOUT_ERRNO(e.code().value()),
+ metadata::CALLOUT_DEVICE_PATH(devPath.c_str()));
+
+ log<level::INFO>("Logging failing sysfs file",
+ phosphor::logging::entry(
+ "FILE=%s", sysfsFullPath.c_str()));
+ }
+
+ target = std::make_shared<T>(ioAccess.path(),
+ devPath,
+ targetId,
+ bus,
+ objPath.c_str(),
+ deferSignals,
+ targetSpeed);
+ obj[type] = target;
}
-
- target = std::make_shared<T>(ioAccess.path(),
- devPath,
- targetId,
- bus,
- objPath.c_str(),
- deferSignals,
- targetSpeed);
- obj[type] = target;
}
return target;
OpenPOWER on IntegriCloud