diff options
author | Daisuke Nojiri <dnojiri@chromium.org> | 2018-08-09 12:47:35 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-08-10 22:43:55 -0700 |
commit | 80cb4643522d5995ee20a27085fd01a9e41e3a6d (patch) | |
tree | 49cf4a1f0ece3a337060d281c1198a16cee55fef | |
parent | 6990ea55076669d74c899d86a8fd76640016b7c1 (diff) | |
download | chrome-ec-80cb4643522d5995ee20a27085fd01a9e41e3a6d.tar.gz |
Fan: Restore thermal control after sysjump
Currently, the fan thermal control is always disabled after sysjump.
This patch makes the EC save the previous thermal control state before
sysjump and restore it after sysjump.
Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org>
BUG=b:112293333
BRANCH=none
TEST=Verify fan spins before sysjump, after sysjump, in OS on Akali.
Change-Id: I2ffc2444e5995def0f0a9206a6863a4b55ba8bc1
Reviewed-on: https://chromium-review.googlesource.com/1169910
Commit-Ready: Daisuke Nojiri <dnojiri@chromium.org>
Tested-by: Daisuke Nojiri <dnojiri@chromium.org>
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
-rw-r--r-- | common/fan.c | 43 | ||||
-rw-r--r-- | test/fan.c | 5 |
2 files changed, 30 insertions, 18 deletions
diff --git a/common/fan.c b/common/fan.c index 46233da715..2ed213316d 100644 --- a/common/fan.c +++ b/common/fan.c @@ -423,35 +423,43 @@ BUILD_ASSERT(CONFIG_FANS <= EC_FAN_SPEED_ENTRIES); /* Saved PWM state across sysjumps */ struct pwm_fan_state { /* TODO(crosbug.com/p/23530): Still treating all fans as one. */ - uint16_t fan_rpm; - uint8_t fan_en; + uint16_t rpm; + uint8_t flag; /* FAN_STATE_FLAG_* */ }; +/* For struct pwm_fan_state.flag */ +#define FAN_STATE_FLAG_ENABLED (1 << 0) +#define FAN_STATE_FLAG_THERMAL (1 << 1) + static void pwm_fan_init(void) { const struct pwm_fan_state *prev; + struct pwm_fan_state state; uint16_t *mapped; int version, size; int i; - int fan = 0; + int fan; for (fan = 0; fan < CONFIG_FANS; fan++) fan_channel_setup(FAN_CH(fan), fans[fan].conf->flags); + /* Restore previous state. */ prev = (const struct pwm_fan_state *) system_get_jump_tag(PWMFAN_SYSJUMP_TAG, &version, &size); if (prev && version == PWM_HOOK_VERSION && size == sizeof(*prev)) { - /* Restore previous state. */ - for (fan = 0; fan < CONFIG_FANS; fan++) { - fan_set_enabled(FAN_CH(fan), prev->fan_en); - fan_set_rpm_target(FAN_CH(fan), prev->fan_rpm); - } + memcpy(&state, prev, sizeof(state)); } else { - /* Set initial fan speed */ - for (fan = 0; fan < CONFIG_FANS; fan++) - fan_set_rpm_target(FAN_CH(fan), - fan_percent_to_rpm(FAN_CH(fan), - CONFIG_FAN_INIT_SPEED)); + memset(&state, 0, sizeof(state)); + state.rpm = fan_percent_to_rpm(FAN_CH(fan), + CONFIG_FAN_INIT_SPEED); + } + + for (fan = 0; fan < CONFIG_FANS; fan++) { + fan_set_enabled(FAN_CH(fan), + state.flag & FAN_STATE_FLAG_ENABLED); + fan_set_rpm_target(FAN_CH(fan), state.rpm); + set_thermal_control_enabled( + fan, state.flag & FAN_STATE_FLAG_THERMAL); } /* Initialize memory-mapped data */ @@ -491,12 +499,15 @@ DECLARE_HOOK(HOOK_SECOND, pwm_fan_second, HOOK_PRIO_DEFAULT); static void pwm_fan_preserve_state(void) { - struct pwm_fan_state state; + struct pwm_fan_state state = {0}; int fan = 0; /* TODO(crosbug.com/p/23530): Still treating all fans as one. */ - state.fan_en = fan_get_enabled(FAN_CH(fan)); - state.fan_rpm = fan_get_rpm_target(FAN_CH(fan)); + if (fan_get_enabled(FAN_CH(fan))) + state.flag |= FAN_STATE_FLAG_ENABLED; + if (thermal_control_enabled[fan]) + state.flag |= FAN_STATE_FLAG_THERMAL; + state.rpm = fan_get_rpm_target(FAN_CH(fan)); system_add_jump_tag(PWMFAN_SYSJUMP_TAG, PWM_HOOK_VERSION, sizeof(state), &state); diff --git a/test/fan.c b/test/fan.c index c5e4c32fd8..6ce33ae495 100644 --- a/test/fan.c +++ b/test/fan.c @@ -31,8 +31,9 @@ static int test_fan(void) sleep(2); - /* With nothing else to do, fans default to full-on */ - TEST_ASSERT(fan_get_rpm_actual(0) == FAN_RPM(0)->rpm_max); + /* With nothing else to do, fans default to CONFIG_FAN_INIT_SPEED*/ + TEST_ASSERT(fan_get_rpm_actual(0) == + fan_percent_to_rpm(0, CONFIG_FAN_INIT_SPEED)); set_thermal_control_enabled(0, 1); |