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 <dnojiri@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/446580
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
This commit is contained in:
Daisuke Nojiri
2017-02-22 15:54:00 -08:00
committed by chrome-bot
parent 2dcfd2446c
commit b7f8d9df65

View File

@@ -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)
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_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)
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 */