diff options
author | Randall Spangler <rspangler@chromium.org> | 2012-06-25 12:17:30 -0700 |
---|---|---|
committer | Gerrit <chrome-bot@google.com> | 2012-06-25 15:37:42 -0700 |
commit | aab92d552d7274f00e624bc8bc74ec41d3101b6d (patch) | |
tree | 959ee3f59f4fcec375bda081e51b0c872db2920d | |
parent | 24395bcc874e61a712acd9e377fadbb3e1ba75dd (diff) | |
download | chrome-ec-aab92d552d7274f00e624bc8bc74ec41d3101b6d.tar.gz |
Shut off keyboard backlight at chipset shutdown
This ensures the keyboard backlight will go off even if the chipset
shuts down due to overheating (or some other unclean shutdown).
(Also fixes inter-function line spacing to linux kernel coding style
and reformats a few comments.)
BUG=chrome-os-partner:10718
TEST=manual
1. power on system
2. turn on keyboard backlight (kblight 100 at EC console)
3. power off system (for example, via power button)
4. keyboard backlight should turn off
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Change-Id: I5bbcd1681ae9c972c9875e9c720617bdf51e3d64
Reviewed-on: https://gerrit.chromium.org/gerrit/26039
-rw-r--r-- | chip/lm4/pwm.c | 52 |
1 files changed, 26 insertions, 26 deletions
diff --git a/chip/lm4/pwm.c b/chip/lm4/pwm.c index fff33f03b3..511410c6c2 100644 --- a/chip/lm4/pwm.c +++ b/chip/lm4/pwm.c @@ -23,15 +23,16 @@ #define MAX_RPM 0x1fff /* Max PWM for fan controller */ #define MAX_PWM 0x1ff -/* Scaling factor for requested/actual RPM for CPU fan. We need this because +/* + * Scaling factor for requested/actual RPM for CPU fan. We need this because * the fan controller on Blizzard filters tach pulses that are less than 64 * 15625Hz ticks apart, which works out to ~7000rpm on an unscaled fan. By * telling the controller we actually have twice as many edges per revolution, * the controller can handle fans that actually go twice as fast. See - * crosbug.com/p/7718. */ + * crosbug.com/p/7718. + */ #define CPU_FAN_SCALE 2 - /* Configures the GPIOs for the fan module. */ static void configure_gpios(void) { @@ -41,7 +42,6 @@ static void configure_gpios(void) gpio_set_alternate_function(LM4_GPIO_M, 0xc0, 1); } - int pwm_enable_fan(int enable) { if (enable) @@ -52,19 +52,16 @@ int pwm_enable_fan(int enable) return EC_SUCCESS; } - int pwm_get_fan_rpm(void) { return (LM4_FAN_FANCST(FAN_CH_CPU) & MAX_RPM) * CPU_FAN_SCALE; } - int pwm_get_fan_target_rpm(void) { return (LM4_FAN_FANCMD(FAN_CH_CPU) & MAX_RPM) * CPU_FAN_SCALE; } - int pwm_set_fan_target_rpm(int rpm) { /* Apply fan scaling */ @@ -79,7 +76,6 @@ int pwm_set_fan_target_rpm(int rpm) return EC_SUCCESS; } - int pwm_enable_keyboard_backlight(int enable) { if (enable) @@ -90,27 +86,23 @@ int pwm_enable_keyboard_backlight(int enable) return EC_SUCCESS; } - int pwm_get_keyboard_backlight_enabled(void) { return (LM4_FAN_FANCTL & (1 << FAN_CH_KBLIGHT)) ? 1 : 0; } - int pwm_get_keyboard_backlight(void) { return ((LM4_FAN_FANCMD(FAN_CH_KBLIGHT) >> 16) * 100 + MAX_PWM / 2) / MAX_PWM; } - int pwm_set_keyboard_backlight(int percent) { LM4_FAN_FANCMD(FAN_CH_KBLIGHT) = ((percent * MAX_PWM + 50) / 100) << 16; return EC_SUCCESS; } - static void update_lpc_mapped_memory(void) { int i, r; @@ -129,15 +121,14 @@ static void update_lpc_mapped_memory(void) mapped[0] = 0xfffe; } - static void check_fan_failure(void) { if (pwm_get_fan_target_rpm() != 0 && (LM4_FAN_FANCTL & (1 << FAN_CH_CPU)) && ((LM4_FAN_FANSTS >> (2 * FAN_CH_CPU)) & 0x03) == 0) { - /* Fan enabled but stalled. Issues warning. - * As we have thermal shutdown protection, issuing warning - * here should be enough. + /* + * Fan enabled but stalled. Issues warning. As we have thermal + * shutdown protection, issuing warning here should be enough. */ lpc_set_host_events( EC_HOST_EVENT_MASK(EC_HOST_EVENT_THERMAL)); @@ -145,7 +136,6 @@ static void check_fan_failure(void) } } - void pwm_task(void) { while (1) { @@ -180,7 +170,6 @@ DECLARE_CONSOLE_COMMAND(faninfo, command_fan_info, "Print fan info", NULL); - static int command_fan_set(int argc, char **argv) { int rpm = 0; @@ -297,7 +286,8 @@ static int pwm_init(void) /* Disable all fans */ LM4_FAN_FANCTL = 0; - /* Configure CPU fan: + /* + * Configure CPU fan: * 0x8000 = bit 15 = auto-restart * 0x0000 = bit 14 = slow acceleration * 0x0000 = bits 13:11 = no hysteresis @@ -306,10 +296,12 @@ static int pwm_init(void) * 0x0020 = bits 5:4 = average 4 edges when calculating RPM * 0x000c = bits 3:2 = 8 pulses per revolution * (see note at top of file) - * 0x0000 = bit 0 = automatic control */ + * 0x0000 = bit 0 = automatic control + */ LM4_FAN_FANCH(FAN_CH_CPU) = 0x802c; - /* Configure keyboard backlight: + /* + * Configure keyboard backlight: * 0x0000 = bit 15 = auto-restart * 0x0000 = bit 14 = slow acceleration * 0x0000 = bits 13:11 = no hysteresis @@ -317,22 +309,24 @@ static int pwm_init(void) * 0x0000 = bits 7:6 = no fast start * 0x0000 = bits 5:4 = average 4 edges when calculating RPM * 0x0000 = bits 3:2 = 4 pulses per revolution - * 0x0001 = bit 0 = manual control */ + * 0x0001 = bit 0 = manual control + */ LM4_FAN_FANCH(FAN_CH_KBLIGHT) = 0x0001; /* Set initial fan speed to maximum, backlight off */ pwm_set_fan_target_rpm(-1); pwm_set_keyboard_backlight(0); - /* Enable keyboard backlight. Fan will be enabled later by whatever - * controls the fan power supply. */ + /* + * 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; } DECLARE_HOOK(HOOK_INIT, pwm_init, HOOK_PRIO_DEFAULT); - static int pwm_resume(void) { pwm_enable_fan(1); @@ -340,10 +334,16 @@ static int pwm_resume(void) } DECLARE_HOOK(HOOK_CHIPSET_RESUME, pwm_resume, HOOK_PRIO_DEFAULT); - static int pwm_suspend(void) { pwm_enable_fan(0); return EC_SUCCESS; } DECLARE_HOOK(HOOK_CHIPSET_SUSPEND, pwm_suspend, HOOK_PRIO_DEFAULT); + +static int pwm_shutdown(void) +{ + pwm_set_keyboard_backlight(0); + return EC_SUCCESS; +} +DECLARE_HOOK(HOOK_CHIPSET_SHUTDOWN, pwm_shutdown, HOOK_PRIO_DEFAULT); |