From 8e5d197b840d4498dcb714b60cc1d38202a7a7a7 Mon Sep 17 00:00:00 2001 From: Lei YU Date: Fri, 26 Jan 2018 17:14:00 +0800 Subject: Add factor and offset for fan monitor For fans controlled via pwm, the fan target and speed are different, where the fan target is pwm and the speed is rpm. Usually it is a linear mapping from pwm to rpm. So this commit defines the optional configs, factor and offset for calculating the expected fan speed from target, e.g. - name: fan0 has_target: true factor: 21 offset: 1600 The fan monitor service will calculate expected fan speed as: target * factor + offset The default value is 1 for factor and 0 for offset if they are not defined. Tested: Use this config together with the following commit's changes, test on Romulus and ensures the fan monitor works OK; Without this config, fan monitor always mark fans as non-functional due to the fan speed does not match the pwm value. Change-Id: If5e25368b4530df7a7face9377efb58804db21df Signed-off-by: Lei YU --- monitor/tach_sensor.hpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'monitor/tach_sensor.hpp') diff --git a/monitor/tach_sensor.hpp b/monitor/tach_sensor.hpp index dd89bbf..50951cd 100644 --- a/monitor/tach_sensor.hpp +++ b/monitor/tach_sensor.hpp @@ -62,6 +62,8 @@ class TachSensor * @param[in] id - the id of the sensor * @param[in] hasTarget - if the sensor supports * setting the speed + * @param[in] factor - the factor of the sensor target + * @param[in] offset - the offset of the sensor target * @param[in] timeout - Normal timeout value to use * @param[in] events - sd_event pointer */ @@ -70,6 +72,8 @@ class TachSensor Fan& fan, const std::string& id, bool hasTarget, + size_t factor, + size_t offset, size_t timeout, phosphor::fan::event::EventPtr& events); @@ -94,6 +98,22 @@ class TachSensor return _hasTarget; } + /** + * @brief Returns the factor of the sensor target + */ + inline size_t getFactor() const + { + return _factor; + } + + /** + * @brief Returns the offset of the sensor target + */ + inline size_t getOffset() const + { + return _offset; + } + /** * Returns true if the hardware behind this * sensor is considered working OK/functional. @@ -216,6 +236,16 @@ class TachSensor */ const bool _hasTarget; + /** + * @brief The factor of target to get fan rpm + */ + const size_t _factor; + + /** + * @brief The offset of target to get fan rpm + */ + const size_t _offset; + /** * @brief The input speed, from the Value dbus property */ -- cgit v1.2.1