From a84165968ca78fe7d783e522f79dd01abc6303fd Mon Sep 17 00:00:00 2001 From: Tino Liu Date: Thu, 21 Jun 2018 19:16:08 +0800 Subject: NPCX/fan: Update rpm_actual in duty mode For npcx, this patch makes rpm_actual updated at every hook_tick when fan is in duty mode (in addition to rpm mode). It also sets fan_status to LOCKED if rpm_actual > 0. BUG=b:110451144 BRANCH=master TEST=After `fanduty `, `faninfo` can see actual rpm being updated. Verify that `fanduty` doesn't impact `fanset`. Change-Id: I3685ca2b8e51d5dd12974c83656c88fecae1932c Signed-off-by: Tino Liu Reviewed-on: https://chromium-review.googlesource.com/1111477 Reviewed-by: Daisuke Nojiri Reviewed-by: Vincent Wang --- chip/npcx/fan.c | 7 ++++++- include/fan.h | 18 +++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/chip/npcx/fan.c b/chip/npcx/fan.c index c8d6a6949d..c1a8b671b2 100644 --- a/chip/npcx/fan.c +++ b/chip/npcx/fan.c @@ -334,7 +334,12 @@ void fan_tick_func(void) volatile struct fan_status_t *p_status = fan_status + ch; /* Make sure rpm mode is enabled */ if (p_status->fan_mode != TACHO_FAN_RPM) { - p_status->auto_status = FAN_STATUS_STOPPED; + /* Fan in duty mode still want rpm_actual being updated. */ + p_status->rpm_actual = mft_fan_rpm(ch); + if (p_status->rpm_actual > 0) + p_status->auto_status = FAN_STATUS_LOCKED; + else + p_status->auto_status = FAN_STATUS_STOPPED; continue; } if (!fan_get_enabled(ch)) diff --git a/include/fan.h b/include/fan.h index 86c2822f80..5a2e010e18 100644 --- a/include/fan.h +++ b/include/fan.h @@ -88,7 +88,23 @@ int fan_get_rpm_target(int ch); /* Is the fan stalled when it shouldn't be? */ int fan_is_stalled(int ch); -/* How is the automatic RPM control doing? */ +/** + * STOPPED means not spinning. + * + * When setting fan rpm, some implementations in chip layer (npcx and it83xx) + * is to adjust fan pwm duty steps by steps. In this period, fan_status will + * be marked as CHANGING. After change is done, fan_status will become LOCKED. + * + * In the period of changing pwm duty, if it's trying to increase/decrease duty + * even when duty is already in upper/lower bound. Then this action won't work, + * and fan_status will be marked as FRUSTRATED. + * + * For other implementations in chip layer (mchp and mec1322), there is no + * changing period. So they don't have CHANGING status. + * Just return status as LOCKED in normal spinning case, return STOPPED when + * not spinning, return FRUSTRATED when the related flags (which is read from + * chip's register) is set. + */ enum fan_status { FAN_STATUS_STOPPED = 0, FAN_STATUS_CHANGING = 1, -- cgit v1.2.1