diff options
-rw-r--r-- | board/blaze/board.c | 4 | ||||
-rw-r--r-- | board/blaze/board.h | 5 | ||||
-rw-r--r-- | board/blaze/build.mk | 2 | ||||
-rw-r--r-- | board/blaze/ec.tasklist | 1 | ||||
-rw-r--r-- | board/blaze/led.c | 193 |
5 files changed, 199 insertions, 6 deletions
diff --git a/board/blaze/board.c b/board/blaze/board.c index 9a66b32d39..c46161a7bc 100644 --- a/board/blaze/board.c +++ b/board/blaze/board.c @@ -80,8 +80,8 @@ const struct gpio_info gpio_list[] = { {"KB_OUT10", GPIO_C, (1<<5), GPIO_KB_OUTPUT, NULL}, {"KB_OUT11", GPIO_C, (1<<4), GPIO_KB_OUTPUT, NULL}, {"KB_OUT12", GPIO_A, (1<<13), GPIO_KB_OUTPUT, NULL}, - {"PWR_LED0", GPIO_B, (1<<10), GPIO_OUT_LOW, NULL}, - {"BAT_LED0", GPIO_B, (1<<11), GPIO_OUT_LOW, NULL}, + {"AC_LED", GPIO_B, (1<<10), GPIO_OUT_LOW, NULL}, + {"CHG_LED", GPIO_B, (1<<11), GPIO_OUT_LOW, NULL}, {"BAT_LED1", GPIO_A, (1<<8), GPIO_OUT_LOW, NULL}, {"CHARGING", GPIO_A, (1<<11), GPIO_OUT_LOW, NULL}, {"EC_BL_OVERRIDE", GPIO_H, (1<<1), GPIO_ODR_HIGH, NULL}, diff --git a/board/blaze/board.h b/board/blaze/board.h index 3a32140f20..93ebcffef1 100644 --- a/board/blaze/board.h +++ b/board/blaze/board.h @@ -24,6 +24,7 @@ #define CONFIG_PWM #define CONFIG_POWER_BUTTON #define CONFIG_VBOOT_HASH +#define CONFIG_LED_COMMON #ifndef __ASSEMBLER__ @@ -84,8 +85,8 @@ enum gpio_signal { GPIO_KB_OUT10, GPIO_KB_OUT11, GPIO_KB_OUT12, - GPIO_PWR_LED0, - GPIO_BAT_LED0, + GPIO_AC_LED, + GPIO_CHG_LED, GPIO_BAT_LED1, GPIO_CHARGING, GPIO_EC_BL_OVERRIDE, diff --git a/board/blaze/build.mk b/board/blaze/build.mk index 834905dfa4..605af9c169 100644 --- a/board/blaze/build.mk +++ b/board/blaze/build.mk @@ -10,4 +10,4 @@ CHIP:=stm32 CHIP_FAMILY:=stm32l CHIP_VARIANT:=stm32l100 -board-y=board.o battery.o +board-y=board.o battery.o led.o diff --git a/board/blaze/ec.tasklist b/board/blaze/ec.tasklist index 94974ddddc..17add5094d 100644 --- a/board/blaze/ec.tasklist +++ b/board/blaze/ec.tasklist @@ -16,7 +16,6 @@ */ #define CONFIG_TASK_LIST \ TASK_ALWAYS(HOOKS, hook_task, NULL, LARGER_TASK_STACK_SIZE) \ - TASK_NOTEST(POWERLED, power_led_task, NULL, 256) \ TASK_ALWAYS(CHARGER, charger_task, NULL, TASK_STACK_SIZE) \ TASK_NOTEST(CHIPSET, chipset_task, NULL, TASK_STACK_SIZE) \ TASK_ALWAYS(HOSTCMD, host_command_task, NULL, TASK_STACK_SIZE) \ diff --git a/board/blaze/led.c b/board/blaze/led.c new file mode 100644 index 0000000000..5c3adacb17 --- /dev/null +++ b/board/blaze/led.c @@ -0,0 +1,193 @@ +/* Copyright (c) 2014 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. + * + * Battery LED control for Blaze + */ + +#include "charge_state.h" +#include "chipset.h" +#include "extpower.h" +#include "gpio.h" +#include "hooks.h" +#include "led_common.h" +#include "util.h" +#include "battery.h" + +const enum ec_led_id supported_led_ids[] = { + EC_LED_ID_BATTERY_LED, EC_LED_ID_POWER_LED}; +const int supported_led_ids_count = ARRAY_SIZE(supported_led_ids); + +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_AC_LED, 0); + gpio_set_level(GPIO_CHG_LED, 0); + break; + case LED_WHITE: + gpio_set_level(GPIO_AC_LED, 1); + gpio_set_level(GPIO_CHG_LED, 0); + break; + case LED_AMBER: + gpio_set_level(GPIO_AC_LED, 0); + gpio_set_level(GPIO_CHG_LED, 1); + 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_LED_POWER_L, 1); + break; + case LED_WHITE: + gpio_set_level(GPIO_LED_POWER_L, 0); + break; + default: + return EC_ERROR_UNKNOWN; + } + return EC_SUCCESS; +} + +void led_get_brightness_range(enum ec_led_id led_id, uint8_t *brightness_range) +{ + switch (led_id) { + case EC_LED_ID_BATTERY_LED: + brightness_range[EC_LED_COLOR_WHITE] = 100; + brightness_range[EC_LED_COLOR_YELLOW] = 100; + break; + case EC_LED_ID_POWER_LED: + brightness_range[EC_LED_COLOR_WHITE] = 100; + break; + default: + /* Nothing to do */ + break; + } +} + +int led_set_brightness(enum ec_led_id led_id, const uint8_t *brightness) +{ + switch (led_id) { + case EC_LED_ID_BATTERY_LED: + if (brightness[EC_LED_COLOR_WHITE] != 0) + bat_led_set_color(LED_WHITE); + else if (brightness[EC_LED_COLOR_YELLOW] != 0) + bat_led_set_color(LED_AMBER); + else + bat_led_set_color(LED_OFF); + break; + case EC_LED_ID_POWER_LED: + if (brightness[EC_LED_COLOR_WHITE] != 0) + pwr_led_set_color(LED_WHITE); + else + pwr_led_set_color(LED_OFF); + break; + default: + break; + } + return EC_SUCCESS; +} + +static void blaze_led_set_power(void) +{ + static int power_ticks; + static int previous_state_suspend; + + power_ticks++; + + /* Solid On: when the computer is ON (S0) & the LED color is White. + * Blinking: when the computer is in Standby, sequence of 1 second ON, + * 1 second OFF, The LED color is white. */ + + if (chipset_in_state(CHIPSET_STATE_SUSPEND)) { + /* Reset ticks if entering suspend so LED turns off + * as soon as possible. */ + if (!previous_state_suspend) + power_ticks = 0; + + pwr_led_set_color((power_ticks & 0x2) ? LED_WHITE : LED_OFF); + + previous_state_suspend = 1; + return; + } + + previous_state_suspend = 0; + + if (chipset_in_state(CHIPSET_STATE_ON)) + pwr_led_set_color(LED_WHITE); + else + pwr_led_set_color(LED_OFF); +} + +static void blaze_led_set_battery(void) +{ + static int battery_ticks; + uint32_t chflags = charge_get_flags(); + + battery_ticks++; + + /* Solid ON White: means AC adapter is attached to system + * and battery is full. + * Solid ON Amber: means a battery is charging. + * Blinking white slowly: The fuel gauge is less than 12%. + * Sequence of Blink is 1 second On, + * 1 second Off. + * Blinking white quickly: When the primary or secondary battery is not + * communicating with EC, EC will blink the + * white LED at the sequence 0.5 second On + * and 0.5 second Off. */ + + /* Battery LED is solid white if AC connected, unless the battery is + * is charging or there is an error. + * Battery LED should be off if AC not present*/ + bat_led_set_color(extpower_is_present() ? LED_WHITE : LED_OFF); + + switch (charge_get_state()) { + case PWR_STATE_CHARGE: + bat_led_set_color(LED_AMBER); + break; + case PWR_STATE_DISCHARGE: + /* See crosbug.com/p/22159. There's a 3% difference + * between the battery level seen by the kernel and what's + * really going on, so if they want to see 12%, we use 15%. + * Hard code this number here, because this only affects the + * LED color, not the battery charge state. */ + if (charge_get_percent() < 15) + bat_led_set_color( + (battery_ticks & 0x2) ? LED_WHITE : LED_OFF); + break; + case PWR_STATE_ERROR: + bat_led_set_color((battery_ticks & 0x1) ? LED_WHITE : LED_OFF); + break; + case PWR_STATE_IDLE: + if (chflags & CHARGE_FLAG_FORCE_IDLE) + bat_led_set_color( + (battery_ticks & 0x2) ? LED_AMBER : LED_OFF); + break; + default: + /* Other states don't alter LED behavior */ + break; + } +} + +/* Called by hook task every 500mSec */ +static void led_tick(void) +{ + if (led_auto_control_is_enabled(EC_LED_ID_POWER_LED)) + blaze_led_set_power(); + if (led_auto_control_is_enabled(EC_LED_ID_BATTERY_LED)) + blaze_led_set_battery(); +} +DECLARE_HOOK(HOOK_TICK, led_tick, HOOK_PRIO_DEFAULT); |