diff options
author | Yilun Lin <yllin@google.com> | 2019-03-22 10:33:12 +0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2019-04-18 03:27:52 -0700 |
commit | 6e1bde480783c9f27b5a7de8a51aa72c4a759310 (patch) | |
tree | 5174bac75c4ef817b9661ce721730a331a32e714 /board/kukui/led.c | |
parent | 8f8ad2ee39598f033b9c2ffdc9523b3d60465201 (diff) | |
download | chrome-ec-6e1bde480783c9f27b5a7de8a51aa72c4a759310.tar.gz |
kukui/led: Fix LED behaviours.
Red for error state and discharge in low power.
Blue for charging.
Green for charged almost full.
Also, fix the ectool led battery not working.
TEST=See blue LED when charging, green LED when battery full.
TEST=see ectool led battery red=x blue=y green=z works.
xyz are the combinations from 0 to 7.
BUG=b:128812582, b:129720983
BRANCH=None
Change-Id: I45d2395197fd9f0713aae8a41ae69c5bc92548b9
Signed-off-by: Yilun Lin <yllin@google.com>
Reviewed-on: https://chromium-review.googlesource.com/1568891
Commit-Ready: Yilun Lin <yllin@chromium.org>
Tested-by: Yilun Lin <yllin@chromium.org>
Reviewed-by: Ting Shen <phoenixshen@chromium.org>
Diffstat (limited to 'board/kukui/led.c')
-rw-r--r-- | board/kukui/led.c | 69 |
1 files changed, 38 insertions, 31 deletions
diff --git a/board/kukui/led.c b/board/kukui/led.c index f66dd46fbf..ca111ca54b 100644 --- a/board/kukui/led.c +++ b/board/kukui/led.c @@ -3,7 +3,6 @@ * found in the LICENSE file. * * Battery LED control for Kukui board. - *TODO(b:80160408): Implement mt6370 led driver. */ #include "battery.h" @@ -17,54 +16,50 @@ const enum ec_led_id supported_led_ids[] = { EC_LED_ID_BATTERY_LED }; const int supported_led_ids_count = ARRAY_SIZE(supported_led_ids); #define LED_OFF MT6370_LED_ID_OFF -#define LED_GREEN MT6370_LED_ID1 -#define LED_RED MT6370_LED_ID2 +#define LED_RED MT6370_LED_ID1 +#define LED_GREEN MT6370_LED_ID2 +#define LED_BLUE MT6370_LED_ID3 #define LED_MASK_OFF 0 -#define LED_MASK_GREEN MT6370_MASK_RGB_ISNK1DIM_EN -#define LED_MASK_RED MT6370_MASK_RGB_ISNK2DIM_EN +#define LED_MASK_RED MT6370_MASK_RGB_ISNK1DIM_EN +#define LED_MASK_GREEN MT6370_MASK_RGB_ISNK2DIM_EN +#define LED_MASK_BLUE MT6370_MASK_RGB_ISNK3DIM_EN static void kukui_led_set_battery(void) { - static int battery_second; - uint32_t chflags = charge_get_flags(); + static enum charge_state prv_chstate = PWR_STATE_UNCHANGE; + enum charge_state chstate; + uint8_t blue = 0, green = 0, red = 0; - battery_second++; + chstate = charge_get_state(); - switch (charge_get_state()) { + if (prv_chstate == chstate) + return; + + prv_chstate = chstate; + + switch (chstate) { case PWR_STATE_CHARGE: /* Always indicate when charging, even in suspend. */ - mt6370_led_set_color(LED_MASK_RED); + blue = 1; break; case PWR_STATE_DISCHARGE: if (charge_get_percent() <= 10) - mt6370_led_set_color((battery_second & 0x4) ? - LED_MASK_RED : LED_MASK_OFF); - else - mt6370_led_set_color(LED_MASK_OFF); + red = 1; break; case PWR_STATE_ERROR: - mt6370_led_set_color((battery_second & 0x2) ? - LED_MASK_RED : LED_MASK_OFF); + red = 1; break; case PWR_STATE_CHARGE_NEAR_FULL: - mt6370_led_set_color(LED_MASK_GREEN); - break; - case PWR_STATE_IDLE: /* External power connected in IDLE. */ - if (chflags & CHARGE_FLAG_FORCE_IDLE) { - mt6370_led_set_color(LED_MASK_RED); - mt6370_led_set_dim_mode(LED_RED, - MT6370_LED_DIM_MODE_BREATH); - } else { - mt6370_led_set_color(LED_MASK_GREEN); - mt6370_led_set_dim_mode(LED_GREEN, - MT6370_LED_DIM_MODE_BREATH); - } + green = 1; break; default: /* Other states don't alter LED behavior */ - break; + return; } + mt6370_led_set_brightness(LED_RED, red); + mt6370_led_set_brightness(LED_BLUE, blue); + mt6370_led_set_brightness(LED_GREEN, green); } void led_get_brightness_range(enum ec_led_id led_id, uint8_t *brightness_range) @@ -72,8 +67,9 @@ void led_get_brightness_range(enum ec_led_id led_id, uint8_t *brightness_range) if (led_id != EC_LED_ID_BATTERY_LED) return; - brightness_range[EC_LED_COLOR_GREEN] = MT6370_LED_BRIGHTNESS_MAX; brightness_range[EC_LED_COLOR_RED] = MT6370_LED_BRIGHTNESS_MAX; + brightness_range[EC_LED_COLOR_GREEN] = MT6370_LED_BRIGHTNESS_MAX; + brightness_range[EC_LED_COLOR_BLUE] = MT6370_LED_BRIGHTNESS_MAX; } int led_set_brightness(enum ec_led_id led_id, const uint8_t *brightness) @@ -81,8 +77,9 @@ int led_set_brightness(enum ec_led_id led_id, const uint8_t *brightness) if (led_id != EC_LED_ID_BATTERY_LED) return EC_ERROR_INVAL; - mt6370_led_set_brightness(LED_GREEN, brightness[EC_LED_COLOR_GREEN]); mt6370_led_set_brightness(LED_RED, brightness[EC_LED_COLOR_RED]); + mt6370_led_set_brightness(LED_GREEN, brightness[EC_LED_COLOR_GREEN]); + mt6370_led_set_brightness(LED_BLUE, brightness[EC_LED_COLOR_BLUE]); return EC_SUCCESS; } @@ -93,3 +90,13 @@ static void led_second(void) kukui_led_set_battery(); } DECLARE_HOOK(HOOK_SECOND, led_second, HOOK_PRIO_DEFAULT); + +static void kukui_led_init(void) +{ + /* Enable all LEDs, and set brightness to 0. */ + mt6370_led_set_brightness(LED_RED, 0); + mt6370_led_set_brightness(LED_GREEN, 0); + mt6370_led_set_brightness(LED_BLUE, 0); + mt6370_led_set_color(LED_MASK_RED | LED_MASK_GREEN | LED_MASK_BLUE); +} +DECLARE_HOOK(HOOK_INIT, kukui_led_init, HOOK_PRIO_DEFAULT); |