summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDevin Lu <Devin.Lu@quantatw.com>2014-04-09 16:58:11 +0800
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-04-17 16:38:51 +0000
commit21d46dc03e7a636433bab0bc8c6bdd401808509f (patch)
tree695337e33706159f41f6f0bcd22e44c71e68ae2b
parentbb16a635394e35adea755bea67d66a5bf600d16d (diff)
downloadchrome-ec-21d46dc03e7a636433bab0bc8c6bdd401808509f.tar.gz
blaze: implement the power and battery LED behavior
Add LED behavior for blaze that will the same as falco and kip. BUG=None BRANCH=ToT TEST=manual Check battery LED show Amber when battery in charging. Check battery LED show white when battery fully. Check battery LED show blinking every 500ms when charging error. Check PWR LED light when system power on. Check PWR LED off when system power down. Check PWR LED will blinking every 1sec when system into suspend. Change-Id: I830952361d3282ff78d29a9a33bd09b64b093ee1 Signed-off-by: Devin Lu <Devin.Lu@quantatw.com> Reviewed-on: https://chromium-review.googlesource.com/193744 Reviewed-by: Yung-chieh Lo <yjlou@chromium.org>
-rw-r--r--board/blaze/board.c4
-rw-r--r--board/blaze/board.h5
-rw-r--r--board/blaze/build.mk2
-rw-r--r--board/blaze/ec.tasklist1
-rw-r--r--board/blaze/led.c193
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);