From 46af344b8745a1c6a5ea495abd16df3e456092ea Mon Sep 17 00:00:00 2001 From: Dave Parker Date: Fri, 19 Jul 2013 19:45:06 -0700 Subject: Battery LED control for Slippy BUG=chrome-os-partner:21180 BRANCH=slippy TEST=Manual. Verify LED is amber while charging, blue when charged, and off when external power disconnected. Signed-off-by: Dave Parker Change-Id: If80bb9b0c70951d257621a2fe3ef20cd8749a033 Reviewed-on: https://gerrit.chromium.org/gerrit/62848 Tested-by: Dave Parker Reviewed-by: Randall Spangler Commit-Queue: Dave Parker --- board/slippy/board.h | 5 +-- common/build.mk | 1 + common/led_slippy.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++ include/config.h | 1 + 4 files changed, 96 insertions(+), 2 deletions(-) create mode 100644 common/led_slippy.c diff --git a/board/slippy/board.h b/board/slippy/board.h index d27d3ec54b..ed9530d5aa 100644 --- a/board/slippy/board.h +++ b/board/slippy/board.h @@ -29,6 +29,7 @@ #ifdef HAS_TASK_KEYPROTO #define CONFIG_KEYBOARD_PROTOCOL_8042 #endif +#define CONFIG_LED_SLIPPY #define CONFIG_LID_SWITCH #define CONFIG_LPC #define CONFIG_PECI @@ -136,8 +137,8 @@ enum gpio_signal { GPIO_PCH_RTCRST_L, /* Not supposed to be here */ GPIO_PCH_SRTCRST_L, /* Not supposed to be here */ - BAT_LED0_L, /* Battery charging LED - Blue */ - BAT_LED1_L, /* Battery charging LED - Amber */ + GPIO_BAT_LED0_L, /* Battery charging LED - Blue */ + GPIO_BAT_LED1_L, /* Battery charging LED - Amber */ /* Number of GPIOs; not an actual GPIO */ GPIO_COUNT diff --git a/common/build.mk b/common/build.mk index bbe964dc7c..88d598ee7a 100644 --- a/common/build.mk +++ b/common/build.mk @@ -41,6 +41,7 @@ common-$(CONFIG_KEYBOARD_TEST)+=keyboard_test.o common-$(CONFIG_LED_DRIVER_LP5562)+=led_driver_lp5562.o led_lp5562.o common-$(CONFIG_LED_FALCO)+=led_falco.o common-$(CONFIG_LED_PEPPY)+=led_peppy.o +common-$(CONFIG_LED_SLIPPY)+=led_slippy.o common-$(CONFIG_LID_SWITCH)+=lid_switch.o common-$(CONFIG_LPC)+=port80.o common-$(CONFIG_ONEWIRE_LED)+=onewire_led.o diff --git a/common/led_slippy.c b/common/led_slippy.c new file mode 100644 index 0000000000..c23ce13c17 --- /dev/null +++ b/common/led_slippy.c @@ -0,0 +1,91 @@ +/* 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 Slippy. + */ + +#include "battery.h" +#include "charge_state.h" +#include "chipset.h" +#include "gpio.h" +#include "hooks.h" +#include "lid_switch.h" + +#define LED_TOTAL_TICKS 16 +#define LED_ON_TICKS 4 + +enum led_color { + LED_OFF = 0, + LED_BLUE, + LED_AMBER, + LED_COLOR_COUNT /* Number of colors, not a color itself */ +}; + +static int led_set_color(enum led_color color, enum gpio_signal gpio_led_blue_l, + enum gpio_signal gpio_led_amber_l) +{ + switch (color) { + case LED_OFF: + gpio_set_level(gpio_led_blue_l, 1); + gpio_set_level(gpio_led_amber_l, 1); + break; + case LED_BLUE: + gpio_set_level(gpio_led_blue_l, 0); + gpio_set_level(gpio_led_amber_l, 1); + break; + case LED_AMBER: + gpio_set_level(gpio_led_blue_l, 1); + gpio_set_level(gpio_led_amber_l, 0); + break; + default: + return EC_ERROR_UNKNOWN; + } + return EC_SUCCESS; +} + +static int bat_led_set_color(enum led_color color) +{ + return led_set_color(color, GPIO_BAT_LED0_L, GPIO_BAT_LED1_L); +} + +/* Called by hook task every 250mSec */ +static void led_tick(void) +{ + static int ticks; + uint32_t chflags = charge_get_flags(); + + /* Battery LED is on the c-panel */ + if (!lid_is_open()) { + bat_led_set_color(LED_OFF); + return; + } + + ticks++; + + switch (charge_get_state()) { + case PWR_STATE_CHARGE: + bat_led_set_color(LED_AMBER); + break; + case PWR_STATE_CHARGE_NEAR_FULL: + bat_led_set_color(LED_BLUE); + break; + case PWR_STATE_DISCHARGE: + bat_led_set_color(LED_OFF); + break; + case PWR_STATE_ERROR: + bat_led_set_color((ticks & 0x2) ? LED_AMBER : LED_OFF); + break; + case PWR_STATE_IDLE: /* External power connected in IDLE state. */ + if (chflags & CHARGE_FLAG_FORCE_IDLE) + bat_led_set_color((ticks & 0x4) ? LED_BLUE : LED_OFF); + else + bat_led_set_color(LED_BLUE); + break; + default: + /* Other states don't alter LED behavior */ + break; + } +} +DECLARE_HOOK(HOOK_TICK, led_tick, HOOK_PRIO_DEFAULT); + diff --git a/include/config.h b/include/config.h index c0a6963646..77177c6452 100644 --- a/include/config.h +++ b/include/config.h @@ -105,6 +105,7 @@ CONFIG_KEYBOARD_SUPPRESS_NOISE CONFIG_LED_DRIVER_LP5562 CONFIG_LED_FALCO CONFIG_LED_PEPPY +CONFIG_LED_SLIPPY CONFIG_LID_SWITCH CONFIG_LOW_POWER_IDLE CONFIG_LPC -- cgit v1.2.1