diff options
author | Ted Kuo <tedkuo@ami.com.tw> | 2015-03-31 08:17:53 +0800 |
---|---|---|
committer | ChromeOS Commit Bot <chromeos-commit-bot@chromium.org> | 2015-04-02 01:21:12 +0000 |
commit | 42f1a19471d5bbb0030f45468d041fec7b3952c7 (patch) | |
tree | 9e89f6762f68c33b2b801dd711be670b57de36a5 | |
parent | 45979aee2ecabd8d64814c406709aef7319fe21d (diff) | |
download | chrome-ec-42f1a19471d5bbb0030f45468d041fec7b3952c7.tar.gz |
Ninja, Sumo: Implement power LED
Based on the code cloned from Rambi, and implement power LED control.
BUG=None
TEST=make -j buildall, make -j tests
BRANCH=None
Signed-off-by: Ted Kuo <tedkuo@ami.com.tw>
Change-Id: I9c89186dd6731a5bbacbd153847288896cd573dc
Reviewed-on: https://chromium-review.googlesource.com/263160
Reviewed-by: Mohammed Habibulla <moch@chromium.org>
Commit-Queue: Ted Kuo <tedkuo@ami.com.tw>
Tested-by: Ted Kuo <tedkuo@ami.com.tw>
-rw-r--r-- | board/ninja/board.c | 3 | ||||
-rw-r--r-- | board/ninja/board.h | 3 | ||||
-rw-r--r-- | board/ninja/led.c | 57 | ||||
-rw-r--r-- | board/sumo/board.c | 3 | ||||
-rw-r--r-- | board/sumo/board.h | 3 | ||||
-rw-r--r-- | board/sumo/led.c | 57 |
6 files changed, 76 insertions, 50 deletions
diff --git a/board/ninja/board.c b/board/ninja/board.c index 2d1ae31b99..f0370e0490 100644 --- a/board/ninja/board.c +++ b/board/ninja/board.c @@ -122,7 +122,7 @@ 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 */ + {GPIO_N, 0x10, 1, MODULE_PWM_LED, GPIO_OPEN_DRAIN}, /* FAN0PWM 3 */ }; const int gpio_alt_funcs_count = ARRAY_SIZE(gpio_alt_funcs); @@ -157,7 +157,6 @@ BUILD_ASSERT(ARRAY_SIZE(adc_channels) == ADC_CH_COUNT); /* PWM channels. Must be in the exactly same order as in enum pwm_channel. */ const struct pwm_t pwm_channels[] = { - {4, PWM_CONFIG_ACTIVE_LOW}, {3, PWM_CONFIG_ACTIVE_LOW}, }; diff --git a/board/ninja/board.h b/board/ninja/board.h index cca6df42f1..02bbade16b 100644 --- a/board/ninja/board.h +++ b/board/ninja/board.h @@ -154,8 +154,7 @@ enum adc_channel { }; enum pwm_channel { - PWM_CH_LED_GREEN, - PWM_CH_LED_RED, + PWM_CH_LED_BLUE_POWER_LED, /* Number of PWM channels */ PWM_CH_COUNT diff --git a/board/ninja/led.c b/board/ninja/led.c index 079b9873e6..4179a92462 100644 --- a/board/ninja/led.c +++ b/board/ninja/led.c @@ -2,7 +2,7 @@ * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. * - * Battery LED control for Ninja + * Power LED control for Ninja */ #include "charge_state.h" @@ -13,27 +13,21 @@ #include "pwm.h" #include "util.h" -const enum ec_led_id supported_led_ids[] = {EC_LED_ID_BATTERY_LED}; +const enum ec_led_id supported_led_ids[] = {EC_LED_ID_POWER_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, + LED_BLUE, /* 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}, +/* Brightness vs. color, for Power LED */ +static const uint8_t color_brightness[LED_COLOR_COUNT] = { + 0, + 100, }; /** @@ -43,20 +37,17 @@ 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]); + pwm_set_duty(PWM_CH_LED_BLUE_POWER_LED, color_brightness[color]); } 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_BLUE] = 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]); + pwm_set_duty(PWM_CH_LED_BLUE_POWER_LED, brightness[EC_LED_COLOR_BLUE]); return EC_SUCCESS; } @@ -69,8 +60,7 @@ static void led_init(void) * 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); + pwm_enable(PWM_CH_LED_BLUE_POWER_LED, 1); set_color(LED_OFF); } DECLARE_HOOK(HOOK_INIT, led_init, HOOK_PRIO_DEFAULT); @@ -80,5 +70,30 @@ DECLARE_HOOK(HOOK_INIT, led_init, HOOK_PRIO_DEFAULT); */ static void led_tick(void) { + static unsigned power_ticks; + static int previous_state_suspend; + + power_ticks++; + + /* If we don't control the LED, nothing to do */ + if (!led_auto_control_is_enabled(EC_LED_ID_POWER_LED)) + return; + + if (chipset_in_state(CHIPSET_STATE_ON)) { + set_color(LED_BLUE); + } else if (chipset_in_state(CHIPSET_STATE_SUSPEND)) { + if (!previous_state_suspend) { + previous_state_suspend = 1; + power_ticks = 0; + } + /* Flashing 1 sec on, 1 sec off */ + set_color((power_ticks % 8) < 4 ? LED_BLUE : LED_OFF); + return; + } else { + set_color(LED_OFF); + } + + previous_state_suspend = 0; + } DECLARE_HOOK(HOOK_TICK, led_tick, HOOK_PRIO_DEFAULT); diff --git a/board/sumo/board.c b/board/sumo/board.c index 607934d5c5..5496f50c9d 100644 --- a/board/sumo/board.c +++ b/board/sumo/board.c @@ -122,7 +122,7 @@ 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 */ + {GPIO_N, 0x10, 1, MODULE_PWM_LED, GPIO_OPEN_DRAIN}, /* FAN0PWM 3 */ }; const int gpio_alt_funcs_count = ARRAY_SIZE(gpio_alt_funcs); @@ -157,7 +157,6 @@ BUILD_ASSERT(ARRAY_SIZE(adc_channels) == ADC_CH_COUNT); /* PWM channels. Must be in the exactly same order as in enum pwm_channel. */ const struct pwm_t pwm_channels[] = { - {4, PWM_CONFIG_ACTIVE_LOW}, {3, PWM_CONFIG_ACTIVE_LOW}, }; diff --git a/board/sumo/board.h b/board/sumo/board.h index c103e4baf1..bed57f0a3f 100644 --- a/board/sumo/board.h +++ b/board/sumo/board.h @@ -154,8 +154,7 @@ enum adc_channel { }; enum pwm_channel { - PWM_CH_LED_GREEN, - PWM_CH_LED_RED, + PWM_CH_LED_BLUE_POWER_LED, /* Number of PWM channels */ PWM_CH_COUNT diff --git a/board/sumo/led.c b/board/sumo/led.c index dd1370413c..7028b249de 100644 --- a/board/sumo/led.c +++ b/board/sumo/led.c @@ -2,7 +2,7 @@ * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. * - * Battery LED control for Sumo + * Power LED control for Sumo */ #include "charge_state.h" @@ -13,27 +13,21 @@ #include "pwm.h" #include "util.h" -const enum ec_led_id supported_led_ids[] = {EC_LED_ID_BATTERY_LED}; +const enum ec_led_id supported_led_ids[] = {EC_LED_ID_POWER_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, + LED_BLUE, /* 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}, +/* Brightness vs. color, for Power LED */ +static const uint8_t color_brightness[LED_COLOR_COUNT] = { + 0, + 100, }; /** @@ -43,20 +37,17 @@ 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]); + pwm_set_duty(PWM_CH_LED_BLUE_POWER_LED, color_brightness[color]); } 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_BLUE] = 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]); + pwm_set_duty(PWM_CH_LED_BLUE_POWER_LED, brightness[EC_LED_COLOR_BLUE]); return EC_SUCCESS; } @@ -69,8 +60,7 @@ static void led_init(void) * 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); + pwm_enable(PWM_CH_LED_BLUE_POWER_LED, 1); set_color(LED_OFF); } DECLARE_HOOK(HOOK_INIT, led_init, HOOK_PRIO_DEFAULT); @@ -80,5 +70,30 @@ DECLARE_HOOK(HOOK_INIT, led_init, HOOK_PRIO_DEFAULT); */ static void led_tick(void) { + static unsigned power_ticks; + static int previous_state_suspend; + + power_ticks++; + + /* If we don't control the LED, nothing to do */ + if (!led_auto_control_is_enabled(EC_LED_ID_POWER_LED)) + return; + + if (chipset_in_state(CHIPSET_STATE_ON)) { + set_color(LED_BLUE); + } else if (chipset_in_state(CHIPSET_STATE_SUSPEND)) { + if (!previous_state_suspend) { + previous_state_suspend = 1; + power_ticks = 0; + } + /* Flashing 1 sec on, 1 sec off */ + set_color((power_ticks % 8) < 4 ? LED_BLUE : LED_OFF); + return; + } else { + set_color(LED_OFF); + } + + previous_state_suspend = 0; + } DECLARE_HOOK(HOOK_TICK, led_tick, HOOK_PRIO_DEFAULT); |