diff options
author | Ko_Ko <Ko_Ko@compal.corp-partner.google.com> | 2021-01-12 13:55:20 +0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-01-22 11:27:14 +0000 |
commit | 337ecb7548dba920ba2881043fcfd9a307423a83 (patch) | |
tree | 3b522622372795ea7818a1d3528f98b1a89eaebb | |
parent | c4e22d8bb5da73415ac81df0386ea53cf8c32dd0 (diff) | |
download | chrome-ec-337ecb7548dba920ba2881043fcfd9a307423a83.tar.gz |
Madoo: LED function
This CL does two things
1. Implement customer's new request for LED behavior.
Turn off LED when AC is in but not charging.
2. Fix the issue that right port LED will keep on sometime,
when plug in AC to left port during low battery.
BUG=b:173464588
BRANCH=dedede
TEST=flash on DVT board and verify LED functions
Signed-off-by: Ko_Ko <Ko_Ko@compal.corp-partner.google.com>
Change-Id: Iadbc0e1ba037faa00d869e2b2917aecbe6d476fa
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2623868
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
Reviewed-by: Ko Ko <ko_ko@compal.corp-partner.google.com>
Tested-by: Ko Ko <ko_ko@compal.corp-partner.google.com>
Commit-Queue: Ko Ko <ko_ko@compal.corp-partner.google.com>
-rw-r--r-- | board/madoo/led.c | 50 |
1 files changed, 48 insertions, 2 deletions
diff --git a/board/madoo/led.c b/board/madoo/led.c index 639a05c764..31afda0f56 100644 --- a/board/madoo/led.c +++ b/board/madoo/led.c @@ -62,12 +62,54 @@ void led_set_color_power(enum ec_led_colors color) gpio_set_level(GPIO_PWR_LED_WHITE_L, LED_OFF_LVL); } +/* + * Turn off battery LED, if AC is present but battery is not charging. + * It could be caused by battery's protection like OTP. + */ +int battery_safety_check(void) +{ + uint8_t data[6]; + int rv; + + /* ignore battery in error state because it has other behavior */ + if (charge_get_state() == PWR_STATE_ERROR) + return false; + + /* turn off LED due to a safety fault */ + rv = sb_read_mfgacc(PARAM_SAFETY_STATUS, + SB_ALT_MANUFACTURER_ACCESS, data, sizeof(data)); + if (rv) + return false; + /* + * Each bit represents for one safey status, and normally they should + * all be 0. Data reads from LSB to MSB. + * data[2] - BIT 7-0 + * AOLDL, AOLD, OCD2, OCD1, OCC2, OCC1, COV, CUV + * + * data[3] - BIT 15-8 + * RSVD, CUVC, OTD, OTC, ASCDL, ASCD, ASCCL, ASCC + * + * data[4] - BIT 23-16 + * CHGC, OC, RSVD, CTO, RSVD, PTO, RSVD, OTF + * + * data[5] - BIT 31-24 + * RSVD, RSVD, OCDL, COVL, UTD, UTC, PCHGC, CHGV + */ + if (data[2] || data[3] || data[4] || data[5]) + return true; + + return false; +} + void led_set_color_battery(enum ec_led_colors color) { switch (color) { case EC_LED_COLOR_WHITE: /* Ports are controlled by different GPIO */ - if (charge_manager_get_active_charge_port() == 1 || + if (battery_safety_check()) { + gpio_set_level(GPIO_BAT_LED_WHITE_L, LED_OFF_LVL); + gpio_set_level(GPIO_EC_CHG_LED_R_W, LED_OFF_LVL); + } else if (charge_manager_get_active_charge_port() == 1 || system_get_board_version() < 3) { gpio_set_level(GPIO_BAT_LED_WHITE_L, LED_ON_LVL); gpio_set_level(GPIO_BAT_LED_AMBER_L, LED_OFF_LVL); @@ -78,7 +120,10 @@ void led_set_color_battery(enum ec_led_colors color) break; case EC_LED_COLOR_AMBER: /* Ports are controlled by different GPIO */ - if (charge_get_state() == PWR_STATE_ERROR && + if (battery_safety_check()) { + gpio_set_level(GPIO_BAT_LED_AMBER_L, LED_OFF_LVL); + gpio_set_level(GPIO_EC_CHG_LED_R_Y, LED_OFF_LVL); + } else if (charge_get_state() == PWR_STATE_ERROR && system_get_board_version() >= 3) { gpio_set_level(GPIO_EC_CHG_LED_R_W, LED_OFF_LVL); gpio_set_level(GPIO_EC_CHG_LED_R_Y, LED_ON_LVL); @@ -86,6 +131,7 @@ void led_set_color_battery(enum ec_led_colors color) system_get_board_version() < 3) { gpio_set_level(GPIO_BAT_LED_WHITE_L, LED_OFF_LVL); gpio_set_level(GPIO_BAT_LED_AMBER_L, LED_ON_LVL); + gpio_set_level(GPIO_EC_CHG_LED_R_Y, LED_OFF_LVL); } else if (charge_manager_get_active_charge_port() == 0) { gpio_set_level(GPIO_EC_CHG_LED_R_W, LED_OFF_LVL); gpio_set_level(GPIO_EC_CHG_LED_R_Y, LED_ON_LVL); |