diff options
author | Dave Parker <dparker@chromium.org> | 2013-06-19 16:10:58 -0700 |
---|---|---|
committer | ChromeBot <chrome-bot@google.com> | 2013-06-21 10:58:00 -0700 |
commit | 9a24fd348edf872f42d458bd60e4832532e48ef9 (patch) | |
tree | 100d4051d6aca087c8ffe82f8bfaf9c63616d69b | |
parent | ff9ee74b3ffa1c14ed058f178ad584a443dfa15c (diff) | |
download | chrome-ec-9a24fd348edf872f42d458bd60e4832532e48ef9.tar.gz |
Power and battery LED control for Falco.
BUG=chrome-os-partner:19914
BRANCH=falco
TEST=manual and constrained by hw issues.
Signed-off-by: Dave Parker <dparker@chromium.org>
Change-Id: Ief919c5ecf296ee358556d65260f245916c1ecb1
Reviewed-on: https://gerrit.chromium.org/gerrit/59513
Reviewed-by: Randall Spangler <rspangler@chromium.org>
-rw-r--r-- | board/falco/board.h | 2 | ||||
-rw-r--r-- | common/build.mk | 1 | ||||
-rw-r--r-- | common/led_falco.c | 100 |
3 files changed, 102 insertions, 1 deletions
diff --git a/board/falco/board.h b/board/falco/board.h index 6490568dbf..8498cc0468 100644 --- a/board/falco/board.h +++ b/board/falco/board.h @@ -27,6 +27,7 @@ #ifdef HAS_TASK_KEYPROTO #define CONFIG_KEYBOARD_PROTOCOL_8042 #endif +#define CONFIG_LED_FALCO #define CONFIG_LID_SWITCH #define CONFIG_LPC #define CONFIG_PECI @@ -191,7 +192,6 @@ enum board_version { BOARD_VERSION_EVT = 1, }; - #endif /* !__ASSEMBLER__ */ #endif /* __BOARD_H */ diff --git a/common/build.mk b/common/build.mk index 7cd213458b..59b271d2c6 100644 --- a/common/build.mk +++ b/common/build.mk @@ -35,6 +35,7 @@ common-$(CONFIG_IR357x)+=ir357x.o common-$(CONFIG_KEYBOARD_PROTOCOL_8042)+=keyboard_8042.o common-$(CONFIG_KEYBOARD_PROTOCOL_MKBP)+=keyboard_mkbp.o common-$(CONFIG_KEYBOARD_TEST)+=keyboard_test.o +common-$(CONFIG_LED_FALCO)+=led_falco.o common-$(CONFIG_LID_SWITCH)+=lid_switch.o common-$(CONFIG_LP5562)+=lp5562.o lp5562_battery_led.o common-$(CONFIG_LPC)+=port80.o diff --git a/common/led_falco.c b/common/led_falco.c new file mode 100644 index 0000000000..eb7567e4f5 --- /dev/null +++ b/common/led_falco.c @@ -0,0 +1,100 @@ +/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + * + * Power and battery LED control for Falco. + */ + +#include "battery.h" +#include "board.h" +#include "charge_state.h" +#include "chipset.h" +#include "extpower.h" +#include "gpio.h" +#include "hooks.h" + +enum led_color { + LED_OFF = 0, + LED_WHITE, + LED_AMBER, + LED_COLOR_COUNT /* Number of colors, not a color itself */ +}; + +static int bat_led_set_color(enum led_color color) +{ + switch (color) { + case LED_OFF: + gpio_set_level(GPIO_BAT_LED0, 1); + gpio_set_level(GPIO_BAT_LED1, 1); + break; + case LED_WHITE: + gpio_set_level(GPIO_BAT_LED0, 0); + gpio_set_level(GPIO_BAT_LED1, 1); + break; + case LED_AMBER: + gpio_set_level(GPIO_BAT_LED0, 1); + gpio_set_level(GPIO_BAT_LED1, 0); + break; + default: + return EC_ERROR_UNKNOWN; + } + return EC_SUCCESS; +} + +static int pwr_led_set_color(enum led_color color) +{ + switch (color) { + case LED_OFF: + gpio_set_level(GPIO_PWR_LED_L, 1); + break; + case LED_WHITE: + gpio_set_level(GPIO_PWR_LED_L, 0); + break; + default: + return EC_ERROR_UNKNOWN; + } + return EC_SUCCESS; +} + +/* Called by hook task every 250mSec */ +static void led_tick(void) +{ + static int ticks; + uint32_t chflags = charge_get_flags(); + + ticks++; + + if (chipset_in_state(CHIPSET_STATE_ANY_OFF)) + pwr_led_set_color(LED_OFF); + else if (chipset_in_state(CHIPSET_STATE_ON)) + pwr_led_set_color(LED_WHITE); + else if (chipset_in_state(CHIPSET_STATE_SUSPEND)) + pwr_led_set_color((ticks & 0x4) ? LED_WHITE : LED_OFF); + + /* Battery LED is solid white if AC connected, unless the battery is + * is charging or there is an error. */ + bat_led_set_color(extpower_is_present() ? LED_WHITE : LED_OFF); + + switch (charge_get_state()) { + case PWR_STATE_IDLE: + if (chflags & CHARGE_FLAG_FORCE_IDLE) + bat_led_set_color((ticks & 0x4) ? LED_AMBER : LED_OFF); + else if (charge_get_percent() <= BATTERY_LEVEL_LOW) + bat_led_set_color((ticks & 0x4) ? LED_WHITE : LED_OFF); + else + bat_led_set_color(LED_WHITE); + break; + case PWR_STATE_CHARGE: + case PWR_STATE_CHARGE_NEAR_FULL: + bat_led_set_color(LED_AMBER); + break; + case PWR_STATE_ERROR: + bat_led_set_color((ticks & 0x2) ? LED_WHITE : LED_OFF); + break; + default: + /* Other states don't alter LED behavior */ + break; + } +} +DECLARE_HOOK(HOOK_TICK, led_tick, HOOK_PRIO_DEFAULT); + |