diff options
Diffstat (limited to 'board/kingoftown/led.c')
-rw-r--r-- | board/kingoftown/led.c | 64 |
1 files changed, 49 insertions, 15 deletions
diff --git a/board/kingoftown/led.c b/board/kingoftown/led.c index 295c8effeb..09c1f89598 100644 --- a/board/kingoftown/led.c +++ b/board/kingoftown/led.c @@ -17,12 +17,17 @@ #include "system.h" #include "util.h" +/* Times of tick per 1 second */ +#define TIMES_TICK_ONE_SEC (1000 / HOOK_TICK_INTERVAL_MS) +/* Times of tick per half second */ +#define TIMES_TICK_HALF_SEC (500 / HOOK_TICK_INTERVAL_MS) + #define BAT_LED_ON 1 #define BAT_LED_OFF 0 const enum ec_led_id supported_led_ids[] = { - EC_LED_ID_RIGHT_LED, EC_LED_ID_LEFT_LED, + EC_LED_ID_RIGHT_LED, }; const int supported_led_ids_count = ARRAY_SIZE(supported_led_ids); @@ -53,10 +58,10 @@ int led_set_brightness(enum ec_led_id led_id, const uint8_t *brightness) int port; switch (led_id) { - case EC_LED_ID_RIGHT_LED: + case EC_LED_ID_LEFT_LED: port = 0; break; - case EC_LED_ID_LEFT_LED: + case EC_LED_ID_RIGHT_LED: port = 1; break; default: @@ -81,19 +86,41 @@ static void set_active_port_color(enum led_color color) { int port = charge_manager_get_active_charge_port(); - if (led_auto_control_is_enabled(EC_LED_ID_RIGHT_LED)) - side_led_set_color(0, (port == 0) ? color : LED_OFF); if (led_auto_control_is_enabled(EC_LED_ID_LEFT_LED)) + side_led_set_color(0, (port == 0) ? color : LED_OFF); + if (led_auto_control_is_enabled(EC_LED_ID_RIGHT_LED)) side_led_set_color(1, (port == 1) ? color : LED_OFF); } static void board_led_set_battery(void) { static int battery_ticks; + static int power_ticks; + int led_blink_cycle; uint32_t chflags = charge_get_flags(); battery_ticks++; + /* + * Override battery LED for kingoftown which doesn't have power LED, + * blinking battery white LED to indicate system suspend without + * charging. + */ + if (chipset_in_state(CHIPSET_STATE_ANY_SUSPEND) && + charge_get_state() != PWR_STATE_CHARGE) { + + power_ticks++; + led_blink_cycle = power_ticks % (2 * TIMES_TICK_ONE_SEC); + + side_led_set_color(0, (led_blink_cycle < TIMES_TICK_ONE_SEC) ? + LED_WHITE : LED_OFF); + side_led_set_color(1, (led_blink_cycle < TIMES_TICK_ONE_SEC) ? + LED_WHITE : LED_OFF); + return; + } + + power_ticks = 0; + switch (charge_get_state()) { case PWR_STATE_CHARGE: /* Always indicate when charging, even in suspend. */ @@ -101,28 +128,35 @@ static void board_led_set_battery(void) break; case PWR_STATE_DISCHARGE: if (led_auto_control_is_enabled(EC_LED_ID_RIGHT_LED)) { - if (charge_get_percent() <= 10) - side_led_set_color(0, - (battery_ticks & 0x4) ? LED_WHITE : LED_OFF); + if (charge_get_percent() <= 10) { + led_blink_cycle = + battery_ticks % (2 * TIMES_TICK_ONE_SEC); + side_led_set_color(1, + (led_blink_cycle < TIMES_TICK_ONE_SEC) ? + LED_WHITE : LED_OFF); + } else - side_led_set_color(0, LED_OFF); + side_led_set_color(1, LED_OFF); } if (led_auto_control_is_enabled(EC_LED_ID_LEFT_LED)) - side_led_set_color(1, LED_OFF); + side_led_set_color(0, LED_OFF); break; case PWR_STATE_ERROR: - set_active_port_color((battery_ticks & 0x2) ? - LED_WHITE : LED_OFF); + led_blink_cycle = battery_ticks % TIMES_TICK_ONE_SEC; + set_active_port_color((led_blink_cycle < TIMES_TICK_HALF_SEC) ? + LED_WHITE : LED_OFF); break; case PWR_STATE_CHARGE_NEAR_FULL: set_active_port_color(LED_WHITE); break; case PWR_STATE_IDLE: /* External power connected in IDLE */ - if (chflags & CHARGE_FLAG_FORCE_IDLE) - set_active_port_color((battery_ticks & 0x4) ? + if (chflags & CHARGE_FLAG_FORCE_IDLE) { + led_blink_cycle = battery_ticks % (2 * TIMES_TICK_ONE_SEC); + set_active_port_color( + (led_blink_cycle < TIMES_TICK_ONE_SEC) ? LED_AMBER : LED_OFF); - else + } else set_active_port_color(LED_WHITE); break; default: |