From b7f8d9df654945827d6a21332e140ddecb8bdd1b Mon Sep 17 00:00:00 2001 From: Daisuke Nojiri Date: Wed, 22 Feb 2017 15:54:00 -0800 Subject: Reef: Fix battery LED behavior This patch makes the battery led behave as follows: Charge: Amber on (S0/S3/S5) Full charge: Blue on (S0/S3/S5) Discharge in S3: Amber on 1sec off 3sec Discharge in S5: Off Error: Amber on 1sec off 1sec Discharge in S0: Blue on BUG=chrome-os-partner:63202 BRANCH=none TEST=Fully charge Electro, then the LED shows with no charger in s0: blue with charger in s0: blue with no charger in s3: blinking amber with charger in s3: blue with no charger in s5: off with charger in s5: blue When not fully charged, the LED shows solid amber in s0/3/5. Change-Id: Idbfbbf35b951ce73c06377f292746c8c1c3ce0fd Signed-off-by: Daisuke Nojiri Reviewed-on: https://chromium-review.googlesource.com/446580 Reviewed-by: Aaron Durbin --- board/reef/led.c | 47 ++++++++++++----------------------------------- 1 file changed, 12 insertions(+), 35 deletions(-) diff --git a/board/reef/led.c b/board/reef/led.c index 17a63a9562..ee06d31995 100644 --- a/board/reef/led.c +++ b/board/reef/led.c @@ -95,46 +95,22 @@ static void led_set_battery(void) { static int battery_ticks; static int suspend_ticks; - static int previous_state_suspend; - uint32_t chflags = charge_get_flags(); - battery_ticks++; - suspend_ticks++; switch (charge_get_state()) { case PWR_STATE_CHARGE: led_set_color_battery(LED_AMBER); break; case PWR_STATE_DISCHARGE: - /* Less than 3%, blink one second every two second */ - if (!chipset_in_state(CHIPSET_STATE_ANY_OFF) && - charge_get_percent() < CRITICAL_LOW_BATTERY_PERCENTAGE) - led_set_color_battery( - (battery_ticks % LED_TOTAL_2SECS_TICKS < - LED_ON_1SEC_TICKS) ? LED_AMBER : LED_OFF); - /* Less than 10%, blink one second every four seconds */ - else if (!chipset_in_state(CHIPSET_STATE_ANY_OFF) && - charge_get_percent() < LOW_BATTERY_PERCENTAGE) + if (chipset_in_state(CHIPSET_STATE_ON)) { + led_set_color_battery(LED_BLUE); + } else if (chipset_in_state(CHIPSET_STATE_SUSPEND | + CHIPSET_STATE_STANDBY)) { + /* Blink once every four seconds. */ led_set_color_battery( - (battery_ticks % LED_TOTAL_4SECS_TICKS < - LED_ON_1SEC_TICKS) ? LED_AMBER : LED_OFF); - else { - if (chipset_in_state(CHIPSET_STATE_SUSPEND - | CHIPSET_STATE_STANDBY)) { - if (!previous_state_suspend) - suspend_ticks = 0; - /* Blink once every four seconds. */ - led_set_color_battery( - (suspend_ticks % LED_TOTAL_4SECS_TICKS) - < LED_ON_1SEC_TICKS ? - LED_AMBER : LED_OFF); - previous_state_suspend = 1; - return; - } - - if (chipset_in_state(CHIPSET_STATE_ON)) - led_set_color_battery(LED_BLUE); - else - led_set_color_battery(LED_OFF); + (suspend_ticks % LED_TOTAL_4SECS_TICKS) + < LED_ON_1SEC_TICKS ? LED_AMBER : LED_OFF); + } else { + led_set_color_battery(LED_OFF); } break; case PWR_STATE_ERROR: @@ -146,7 +122,7 @@ static void led_set_battery(void) led_set_color_battery(LED_BLUE); break; case PWR_STATE_IDLE: /* External power connected in IDLE */ - if (chflags & CHARGE_FLAG_FORCE_IDLE) + if (charge_get_flags() & CHARGE_FLAG_FORCE_IDLE) led_set_color_battery( (battery_ticks % LED_TOTAL_4SECS_TICKS < LED_ON_2SECS_TICKS) ? LED_AMBER : LED_BLUE); @@ -157,7 +133,8 @@ static void led_set_battery(void) /* Other states don't alter LED behavior */ break; } - previous_state_suspend = 0; + battery_ticks++; + suspend_ticks++; } /* Called by hook task every 1 sec */ -- cgit v1.2.1