summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRandall Spangler <rspangler@chromium.org>2012-10-11 15:10:26 -0700
committerRong Chang <rongchang@chromium.org>2012-10-16 01:01:55 -0700
commit8b8d73ff4c9c231edc65e97172bdbf586b75903f (patch)
tree75e881674f927133b74aeb4ea8349fdc5a6ccde0
parentef1ff6bd12ef6bf812bf15b8540836321ad550f4 (diff)
downloadchrome-ec-8b8d73ff4c9c231edc65e97172bdbf586b75903f.tar.gz
link:re-enable fan RPM controller when needed
Previously, any command which set the fan duty manually would leave the PWM RPM controller disabled. Setting the fan back to auto mode via 'ectool autofanctrl' or 'autofan' or 'ectool pwmsetfanrpm' wouldn't turn the controller back on. Now it does. BUG=chrome-os-partner:14307 BRANCH=link TEST=manual - Reboot in recovery mode and wait for INSERT screen - From EC console fanduty 100 -> fan turns on all the way faninfo -> mode is duty fanset 6000 -> fan turns down to a lower level faninfo -> mode is rpm fanduty 0 -> fan turns off all the way faninfo -> mode is duty (wait a min or so for the system to heat up) autofan -> fan turns on faninfo -> mode is rpm - Reboot normally - From root shell ectool fanduty 100 -> fan turns on all the way ectool pwmsetfanrpm 6000 -> fan turns down to a lower level Original-Change-Id: I3b07e8b49500f5f8a42f20909d2869cf63987d6d Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/35335 Reviewed-by: Sameer Nanda <snanda@chromium.org> (cherry picked from commit e764bdbb03780d1e4c879edd046923c5c2d409a5) Change-Id: I16a97b0cbc61e03ccde754552c9713950118a319 Reviewed-on: https://gerrit.chromium.org/gerrit/35680 Reviewed-by: Rong Chang <rongchang@chromium.org> Tested-by: Rong Chang <rongchang@chromium.org>
-rw-r--r--chip/lm4/pwm.c94
-rw-r--r--common/pwm_commands.c1
-rw-r--r--common/thermal.c5
-rw-r--r--include/pwm.h8
4 files changed, 70 insertions, 38 deletions
diff --git a/chip/lm4/pwm.c b/chip/lm4/pwm.c
index 431f04036f..c3c8be73a4 100644
--- a/chip/lm4/pwm.c
+++ b/chip/lm4/pwm.c
@@ -32,7 +32,6 @@
*/
#define CPU_FAN_SCALE 2
-
#define PWM_SYSJUMP_TAG 0x504d /* "PM" */
#define PWM_HOOK_VERSION 1
/* the previous pwm state before reboot_ec. */
@@ -44,7 +43,6 @@ struct pwm_state {
char pad; /* Pad to multiple of 4 bytes. */
};
-
/* Configures the GPIOs for the fan module. */
static void configure_gpios(void)
{
@@ -69,6 +67,30 @@ int pwm_get_fan_enabled(void)
return (LM4_FAN_FANCTL & (1 << FAN_CH_CPU)) ? 1 : 0;
}
+static int pwm_get_rpm_mode(void)
+{
+ return (LM4_FAN_FANCH(FAN_CH_CPU) & 0x0001) ? 0 : 1;
+}
+
+void pwm_set_rpm_mode(int rpm_mode)
+{
+ int was_enabled = pwm_get_fan_enabled();
+ int was_rpm = pwm_get_rpm_mode();
+
+ if (!was_rpm && rpm_mode) {
+ /* Enable RPM control */
+ pwm_enable_fan(0);
+ LM4_FAN_FANCH(FAN_CH_CPU) &= ~0x0001;
+
+ pwm_enable_fan(was_enabled);
+ } else if (was_rpm && !rpm_mode) {
+ /* Disable RPM mode */
+ pwm_enable_fan(0);
+ LM4_FAN_FANCH(FAN_CH_CPU) |= 0x0001;
+ pwm_enable_fan(was_enabled);
+ }
+}
+
int pwm_get_fan_rpm(void)
{
return (LM4_FAN_FANCST(FAN_CH_CPU) & MAX_RPM) * CPU_FAN_SCALE;
@@ -125,6 +147,34 @@ int pwm_set_keyboard_backlight(int percent)
return EC_SUCCESS;
}
+int pwm_set_fan_duty(int percent)
+{
+ int pwm;
+
+ if (percent < 0)
+ percent = 0;
+ else if (percent > 100)
+ percent = 100;
+
+ pwm = (MAX_PWM * percent) / 100;
+
+ /* Move the fan to manual control */
+ pwm_set_rpm_mode(0);
+
+ /* Always enable the fan */
+ pwm_enable_fan(1);
+
+#ifdef CONFIG_TASK_THERMAL
+ /* Disable thermal engine automatic fan control. */
+ thermal_control_fan(0);
+#endif
+
+ /* Set the duty cycle */
+ LM4_FAN_FANCMD(FAN_CH_CPU) = pwm << 16;
+
+ return EC_SUCCESS;
+}
+
/**
* Return non-zero if fan is enabled but stalled
*/
@@ -171,8 +221,8 @@ static int command_fan_info(int argc, char **argv)
((LM4_FAN_FANCMD(FAN_CH_CPU) >> 16)) * 100 / MAX_PWM);
ccprintf("Status: %d\n",
(LM4_FAN_FANSTS >> (2 * FAN_CH_CPU)) & 0x03);
- ccprintf("Enable: %s\n",
- pwm_get_fan_enabled() ? "yes" : "no");
+ ccprintf("Mode: %s\n", pwm_get_rpm_mode() ? "rpm" : "duty");
+ ccprintf("Enable: %s\n", pwm_get_fan_enabled() ? "yes" : "no");
ccprintf("Power: %s\n",
gpio_get_level(GPIO_PGOOD_5VALW) ? "yes" : "no");
@@ -196,10 +246,8 @@ static int command_fan_set(int argc, char **argv)
return EC_ERROR_PARAM1;
/* Move the fan to automatic control */
- if (LM4_FAN_FANCH(FAN_CH_CPU) & 0x0001) {
- pwm_enable_fan(0);
- LM4_FAN_FANCH(FAN_CH_CPU) &= ~0x0001;
- }
+ pwm_set_rpm_mode(1);
+
/* Always enable the fan */
pwm_enable_fan(1);
@@ -215,36 +263,6 @@ DECLARE_CONSOLE_COMMAND(fanset, command_fan_set,
"Set fan speed",
NULL);
-int pwm_set_fan_duty(int percent)
-{
- int pwm;
-
- if (percent < 0)
- percent = 0;
- else if (percent > 100)
- percent = 100;
-
- pwm = (MAX_PWM * percent) / 100;
-
- /* Move the fan to manual control */
- if (!(LM4_FAN_FANCH(FAN_CH_CPU) & 0x0001)) {
- pwm_enable_fan(0);
- LM4_FAN_FANCH(FAN_CH_CPU) |= 0x0001;
- }
- /* Always enable the fan */
- pwm_enable_fan(1);
-
-#ifdef CONFIG_TASK_THERMAL
- /* Disable thermal engine automatic fan control. */
- thermal_control_fan(0);
-#endif
-
- /* Set the duty cycle */
- LM4_FAN_FANCMD(FAN_CH_CPU) = pwm << 16;
-
- return EC_SUCCESS;
-}
-
static int ec_command_fan_duty(int argc, char **argv)
{
int percent = 0;
diff --git a/common/pwm_commands.c b/common/pwm_commands.c
index b23f2d82d2..40543623e2 100644
--- a/common/pwm_commands.c
+++ b/common/pwm_commands.c
@@ -30,6 +30,7 @@ int pwm_command_set_fan_target_rpm(struct host_cmd_handler_args *args)
#ifdef CONFIG_TASK_THERMAL
thermal_control_fan(0);
#endif
+ pwm_set_rpm_mode(1);
pwm_set_fan_target_rpm(p->rpm);
return EC_RES_SUCCESS;
diff --git a/common/thermal.c b/common/thermal.c
index c452fff495..6aa8209848 100644
--- a/common/thermal.c
+++ b/common/thermal.c
@@ -83,6 +83,11 @@ int thermal_get_threshold(enum temp_sensor_type type, int threshold_id)
int thermal_control_fan(int enable)
{
fan_ctrl_on = enable;
+
+ /* If controlling the fan, need it in RPM-control mode */
+ if (enable)
+ pwm_set_rpm_mode(1);
+
return EC_SUCCESS;
}
diff --git a/include/pwm.h b/include/pwm.h
index 0d21769233..1def4f6172 100644
--- a/include/pwm.h
+++ b/include/pwm.h
@@ -14,6 +14,14 @@
* enables the power supply to the fan. */
int pwm_enable_fan(int enable);
+/**
+ * Enable/disable fan RPM control logic.
+ *
+ * @param rpm_mode Enable (1) or disable (0) RPM control loop; when
+ * disabled, fan duty cycle will be used.
+ */
+void pwm_set_rpm_mode(int enable);
+
/* Get the current fan RPM. */
int pwm_get_fan_rpm(void);