diff options
author | yoojin <yoojin7.lee@samsung.com> | 2014-06-30 13:51:49 +0900 |
---|---|---|
committer | chrome-internal-fetch <chrome-internal-fetch@google.com> | 2014-07-14 23:44:10 +0000 |
commit | 6a4725e803a72873b1d3392f27a26ca3ab27a02e (patch) | |
tree | ee298d85c9696958f3338e4a522b6e9b74b6a9e2 | |
parent | 15250dc7b358f3b2d94d47d6f3db0a45d7fed060 (diff) | |
download | chrome-ec-6a4725e803a72873b1d3392f27a26ca3ab27a02e.tar.gz |
winky : 3 Color LED
3 Color LED for samsung spec.
* Scenario
- BLUE : System on
- GREEN : System off and Battery full-charged
- RED : System off and Battery charging
* EC only controlled green & red LED.
Blue LED was controlled by HW.
So, when system on, EC sould turn off green & red LED.
BUG=chrome-os-partner:30089
TEST=emerge-winky chromeos-ec
Check LED status as 3color LED scenario.
Change-Id: Icc2375c2dd3bbbbbe73c23eb8972e9c2049e648d
Reviewed-on: https://chromium-review.googlesource.com/205934
Reviewed-by: YongBeum Ha <ybha@samsung.com>
Tested-by: YongBeum Ha <ybha@samsung.com>
Reviewed-by: Mohammed Habibulla <moch@chromium.org>
Commit-Queue: YongBeum Ha <ybha@samsung.com>
-rwxr-xr-x | board/winky/board.h | 3 | ||||
-rw-r--r-- | board/winky/build.mk | 2 | ||||
-rwxr-xr-x | board/winky/led.c | 127 |
3 files changed, 130 insertions, 2 deletions
diff --git a/board/winky/board.h b/board/winky/board.h index e527a65815..917eadbd2e 100755 --- a/board/winky/board.h +++ b/board/winky/board.h @@ -30,12 +30,13 @@ #define CONFIG_KEYBOARD_IRQ_GPIO GPIO_KBD_IRQ_L #define CONFIG_KEYBOARD_PROTOCOL_8042 /* TODO(crosbug.com/p/25418): Add LED support */ -#undef CONFIG_LED_COMMON +#define CONFIG_LED_COMMON #define CONFIG_LOW_POWER_IDLE #undef CONFIG_PECI #define CONFIG_POWER_BUTTON #define CONFIG_POWER_BUTTON_X86 #define CONFIG_PWM +#define CONFIG_PWM_DSLEEP #define CONFIG_SCI_GPIO GPIO_PCH_SCI_L #define CONFIG_TEMP_SENSOR #define CONFIG_TEMP_SENSOR_TMP432 diff --git a/board/winky/build.mk b/board/winky/build.mk index f511912b08..d3bca1d912 100644 --- a/board/winky/build.mk +++ b/board/winky/build.mk @@ -9,4 +9,4 @@ # the IC is TI Stellaris LM4 CHIP:=lm4 -board-y=battery.o board.o +board-y=battery.o board.o led.o diff --git a/board/winky/led.c b/board/winky/led.c new file mode 100755 index 0000000000..4371b68a21 --- /dev/null +++ b/board/winky/led.c @@ -0,0 +1,127 @@ +/* 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 Winky + */ + +#include "charge_state.h" +#include "chipset.h" +#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}; +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, + + /* 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 + * + * @param color Enumerated color value + */ +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]); +} + +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; +} + +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; +} + +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); +} +DECLARE_HOOK(HOOK_INIT, led_init, HOOK_PRIO_DEFAULT); + +/** + * Called by hook task every 250 ms + */ +static void led_tick(void) +{ + static unsigned ticks; + int chstate = charge_get_state(); + + if(chipset_in_state(CHIPSET_STATE_ON)) + { + set_color(LED_OFF); + return; + } + + ticks++; + + /* If we don't control the LED, nothing to do */ + if (!led_auto_control_is_enabled(EC_LED_ID_BATTERY_LED)) + return; + + /* If charging error, blink orange, 25% duty cycle, 4 sec period */ + if (chstate == PWR_STATE_ERROR) { + set_color((ticks % 16) < 4 ? LED_RED : LED_OFF); + return; + } + + /* If charge-force-idle, blink green, 50% duty cycle, 2 sec period */ + if (chstate == PWR_STATE_IDLE && + (charge_get_flags() & CHARGE_FLAG_FORCE_IDLE)) { + set_color((ticks & 0x4) ? LED_GREEN : LED_OFF); + return; + } + + /* If the system is charging, solid orange */ + if (chstate == PWR_STATE_CHARGE) { + set_color(LED_RED); + 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); + return; + } + + /* Otherwise, system is off and AC not connected, LED off */ + set_color(LED_OFF); +} +DECLARE_HOOK(HOOK_TICK, led_tick, HOOK_PRIO_DEFAULT); |