summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDevin Lu <Devin.Lu@quantatw.com>2014-09-04 11:37:30 +0800
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-09-10 01:40:55 +0000
commit0cd471d06807de06bf1062b125bad6050177954e (patch)
tree51a13e608f7c421f72889f6a03029a1c48f4ec7e
parent2e392d704e6790196cd50575d7cd5e14d1779c62 (diff)
downloadchrome-ec-0cd471d06807de06bf1062b125bad6050177954e.tar.gz
Candy: Implement the battery LED behavior
Add LED behavior for candy that will the same as wolf. BUG=None BRANCH=rambi TEST=manual Check battery LED show white when battery in charging. Check battery LED turn off when battery fully with ac mode. Check battery LED show amber and blinking every 500ms when charging error. Check battery LED show amber when battery capacity under 15%. Change-Id: Ia445f3b233aaa5d0bcf70accfdc950f1c8158c36 Signed-off-by: Devin Lu <Devin.Lu@quantatw.com> Reviewed-on: https://chromium-review.googlesource.com/216391 Reviewed-by: Mohammed Habibulla <moch@chromium.org>
-rw-r--r--board/candy/board.c3
-rw-r--r--board/candy/board.h2
-rw-r--r--board/candy/led.c87
3 files changed, 46 insertions, 46 deletions
diff --git a/board/candy/board.c b/board/candy/board.c
index 6b5daaa556..ae6b7054d8 100644
--- a/board/candy/board.c
+++ b/board/candy/board.c
@@ -112,6 +112,8 @@ const struct gpio_info gpio_list[] = {
{"WLAN_OFF_L", LM4_GPIO_J, (1<<4), GPIO_OUT_LOW, NULL},
{"PCH_SCI_L", LM4_GPIO_M, (1<<1), GPIO_ODR_HIGH, NULL},
{"KBD_IRQ_L", LM4_GPIO_M, (1<<3), GPIO_ODR_HIGH, NULL},
+ {"BAT_LED0", LM4_GPIO_N, (1<<6), GPIO_OUT_LOW, NULL},
+ {"BAT_LED1", LM4_GPIO_N, (1<<4), GPIO_OUT_LOW, NULL},
};
BUILD_ASSERT(ARRAY_SIZE(gpio_list) == GPIO_COUNT);
@@ -125,7 +127,6 @@ const struct gpio_alt_func gpio_alt_funcs[] = {
{GPIO_D, 0x0f, 2, MODULE_SPI}, /* SPI1 */
{GPIO_L, 0x3f, 15, MODULE_LPC}, /* LPC */
{GPIO_M, 0x21, 15, MODULE_LPC}, /* LPC */
- {GPIO_N, 0x50, 1, MODULE_PWM_LED, GPIO_OPEN_DRAIN}, /* FAN0PWM 3&4 */
};
const int gpio_alt_funcs_count = ARRAY_SIZE(gpio_alt_funcs);
diff --git a/board/candy/board.h b/board/candy/board.h
index a57355f74f..759696cbc5 100644
--- a/board/candy/board.h
+++ b/board/candy/board.h
@@ -132,6 +132,8 @@ enum gpio_signal {
GPIO_WLAN_OFF_L, /* Disable WiFi radio */
GPIO_PCH_SCI_L, /* Assert SCI to PCH */
GPIO_KBD_IRQ_L, /* Negative edge triggered irq. */
+ GPIO_BAT_LED0, /* Battery charger status */
+ GPIO_BAT_LED1, /* Battery charger status */
/* Number of GPIOs; not an actual GPIO */
GPIO_COUNT
diff --git a/board/candy/led.c b/board/candy/led.c
index 99c42a4efd..76fc40ac0b 100644
--- a/board/candy/led.c
+++ b/board/candy/led.c
@@ -10,7 +10,6 @@
#include "gpio.h"
#include "hooks.h"
#include "led_common.h"
-#include "pwm.h"
#include "util.h"
const enum ec_led_id supported_led_ids[] = {EC_LED_ID_BATTERY_LED};
@@ -18,24 +17,13 @@ const int supported_led_ids_count = ARRAY_SIZE(supported_led_ids);
enum led_color {
LED_OFF = 0,
- LED_RED,
- LED_ORANGE,
- LED_YELLOW,
- LED_GREEN,
+ LED_WHITE,
+ LED_AMBER,
/* Number of colors, not a color itself */
LED_COLOR_COUNT
};
-/* Brightness vs. color, for {red, green} LEDs */
-static const uint8_t color_brightness[LED_COLOR_COUNT][2] = {
- {0, 0},
- {100, 0},
- {30, 45},
- {20, 60},
- {0, 100},
-};
-
/**
* Set LED color
*
@@ -43,37 +31,41 @@ static const uint8_t color_brightness[LED_COLOR_COUNT][2] = {
*/
static void set_color(enum led_color color)
{
- pwm_set_duty(PWM_CH_LED_RED, color_brightness[color][0]);
- pwm_set_duty(PWM_CH_LED_GREEN, color_brightness[color][1]);
+ 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:
+ break;
+ }
}
void led_get_brightness_range(enum ec_led_id led_id, uint8_t *brightness_range)
{
- brightness_range[EC_LED_COLOR_RED] = 100;
- brightness_range[EC_LED_COLOR_GREEN] = 100;
+ brightness_range[EC_LED_COLOR_WHITE] = 100;
+ brightness_range[EC_LED_COLOR_YELLOW] = 100;
}
int led_set_brightness(enum ec_led_id led_id, const uint8_t *brightness)
{
- pwm_set_duty(PWM_CH_LED_RED, brightness[EC_LED_COLOR_RED]);
- pwm_set_duty(PWM_CH_LED_GREEN, brightness[EC_LED_COLOR_GREEN]);
- return EC_SUCCESS;
-}
+ if (brightness[EC_LED_COLOR_WHITE] != 0)
+ set_color(LED_WHITE);
+ else if (brightness[EC_LED_COLOR_YELLOW] != 0)
+ set_color(LED_AMBER);
+ else
+ set_color(LED_OFF);
-static void led_init(void)
-{
- /* Configure GPIOs */
- gpio_config_module(MODULE_PWM_LED, 1);
-
- /*
- * Enable PWMs and set to 0% duty cycle. If they're disabled, the LM4
- * seems to ground the pins instead of letting them float.
- */
- pwm_enable(PWM_CH_LED_RED, 1);
- pwm_enable(PWM_CH_LED_GREEN, 1);
- set_color(LED_OFF);
+ return EC_SUCCESS;
}
-DECLARE_HOOK(HOOK_INIT, led_init, HOOK_PRIO_DEFAULT);
/**
* Called by hook task every 250 ms
@@ -89,29 +81,34 @@ static void led_tick(void)
if (!led_auto_control_is_enabled(EC_LED_ID_BATTERY_LED))
return;
- /* If charging error, blink orange, 25% duty cycle, 4 sec period */
+ /* If charging error, blink amber, 500ms period */
if (chstate == PWR_STATE_ERROR) {
- set_color((ticks % 16) < 4 ? LED_ORANGE : LED_OFF);
+ set_color((ticks & 0x2) ? LED_AMBER : LED_OFF);
return;
}
- /* If charge-force-idle, blink green, 50% duty cycle, 2 sec period */
+
+ /* If charge-force-idle, blink white, 1 sec period */
if (chstate == PWR_STATE_IDLE &&
(charge_get_flags() & CHARGE_FLAG_FORCE_IDLE)) {
- set_color((ticks & 0x4) ? LED_GREEN : LED_OFF);
+ set_color((ticks & 0x4) ? LED_WHITE : LED_OFF);
return;
}
- /* If the system is charging, solid orange */
+ /* If the system is charging, solid white */
if (chstate == PWR_STATE_CHARGE) {
- set_color(LED_ORANGE);
+ set_color(LED_WHITE);
return;
}
- /* If AC connected and fully charged (or close to it), solid green */
- if (chstate == PWR_STATE_CHARGE_NEAR_FULL ||
- chstate == PWR_STATE_IDLE) {
- set_color(LED_GREEN);
+ /* If battery capacity under 15% , solid amber */
+ if (chstate == PWR_STATE_DISCHARGE) {
+ if (chipset_in_state(CHIPSET_STATE_ON) ||
+ chipset_in_state(CHIPSET_STATE_SUSPEND))
+ set_color((charge_get_percent() < 15) ?
+ LED_AMBER : LED_OFF);
+ else
+ set_color(LED_OFF);
return;
}