From 3a460ea765417ce70bd760b91f46feca7cccb828 Mon Sep 17 00:00:00 2001 From: Randall Spangler Date: Mon, 27 Feb 2012 10:43:14 -0800 Subject: [PATCH] Disable fan PWM when +5VS is disabled Signed-off-by: Randall Spangler BUG=chrome-os-partner:8097 TEST=manual faninfo should report fan is disabled powerbtn system turns on, fan turns on faninfo should report fan is enabled powerbtn system turns off, fan turns off faninfo should report fan is disabled again Change-Id: I8e94c142bf18d07f83bac05287bcd503a098cee7 --- chip/lm4/pwm.c | 29 ++++++++++++++++++++++------- common/x86_power.c | 7 +++++++ include/pwm.h | 4 ++++ 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/chip/lm4/pwm.c b/chip/lm4/pwm.c index bcb19f49a0..1bfeeff6b4 100644 --- a/chip/lm4/pwm.c +++ b/chip/lm4/pwm.c @@ -43,6 +43,17 @@ static void configure_gpios(void) } +int pwm_enable_fan(int enable) +{ + if (enable) + LM4_FAN_FANCTL |= (1 << FAN_CH_CPU); + else + LM4_FAN_FANCTL &= ~(1 << FAN_CH_CPU); + + return EC_SUCCESS; +} + + int pwm_get_fan_rpm(void) { return (LM4_FAN_FANCST(FAN_CH_CPU) & MAX_RPM) * CPU_FAN_SCALE; @@ -90,6 +101,9 @@ static int command_fan_info(int argc, char **argv) ((LM4_FAN_FANCMD(FAN_CH_CPU) >> 16)) * 100 / MAX_PWM); uart_printf(" status: %d\n", (LM4_FAN_FANSTS >> (2 * FAN_CH_CPU)) & 0x03); + uart_printf(" enabled: %s\n", + LM4_FAN_FANCTL & (1 << FAN_CH_CPU) ? "yes" : "no"); + return EC_SUCCESS; } DECLARE_CONSOLE_COMMAND(faninfo, command_fan_info); @@ -116,9 +130,9 @@ static int command_fan_set(int argc, char **argv) /* Move the fan to automatic control */ if (LM4_FAN_FANCH(FAN_CH_CPU) & 0x0001) { - LM4_FAN_FANCTL &= ~(1 << FAN_CH_CPU); - LM4_FAN_FANCH(FAN_CH_CPU) &= ~0x0001; - LM4_FAN_FANCTL |= (1 << FAN_CH_CPU); + pwm_enable_fan(0); + LM4_FAN_FANCH(FAN_CH_CPU) &= ~0x0001; + pwm_enable_fan(1); } rv = pwm_set_fan_target_rpm(rpm); @@ -151,9 +165,9 @@ static int command_fan_duty(int argc, char **argv) /* Move the fan to manual control */ if (!(LM4_FAN_FANCH(FAN_CH_CPU) & 0x0001)) { - LM4_FAN_FANCTL &= ~(1 << FAN_CH_CPU); + pwm_enable_fan(0); LM4_FAN_FANCH(FAN_CH_CPU) |= 0x0001; - LM4_FAN_FANCTL |= (1 << FAN_CH_CPU); + pwm_enable_fan(1); } /* Set the duty cycle */ @@ -234,8 +248,9 @@ int pwm_init(void) pwm_set_fan_target_rpm(-1); pwm_set_keyboard_backlight(0); - /* Enable CPU fan and keyboard backlight */ - LM4_FAN_FANCTL |= (1 << FAN_CH_CPU) | (1 << FAN_CH_KBLIGHT); + /* Enable keyboard backlight. Fan will be enabled later by whatever + * controls the fan power supply. */ + LM4_FAN_FANCTL |= (1 << FAN_CH_KBLIGHT); return EC_SUCCESS; } diff --git a/common/x86_power.c b/common/x86_power.c index f1454fe93e..c4c3452a5b 100644 --- a/common/x86_power.c +++ b/common/x86_power.c @@ -9,6 +9,7 @@ #include "clock.h" #include "console.h" #include "gpio.h" +#include "pwm.h" #include "task.h" #include "timer.h" #include "uart.h" @@ -261,6 +262,9 @@ void x86_power_task(void) /* Turn on power rails */ gpio_set_level(GPIO_ENABLE_VS, 1); + /* Enable fan, now that +5VS is turned on */ + pwm_enable_fan(1); + /* Wait for non-core power rails good */ wait_in_signals(IN_PGOOD_ALL_NONCORE); @@ -293,6 +297,9 @@ void x86_power_task(void) /* Assert RCINn */ gpio_set_level(GPIO_PCH_RCINn, 0); + /* Disable fan, since it's powered by +5VS */ + pwm_enable_fan(0); + /* Turn off power rails */ gpio_set_level(GPIO_ENABLE_VS, 0); diff --git a/include/pwm.h b/include/pwm.h index ff76c89744..cbf11c5e95 100644 --- a/include/pwm.h +++ b/include/pwm.h @@ -13,6 +13,10 @@ /* Initializes the module. */ int pwm_init(void); +/* Enables/disables the fan. This should be called by whatever function + * enables the power supply to the fan. */ +int pwm_enable_fan(int enable); + /* Gets the current fan RPM. */ int pwm_get_fan_rpm(void);