From 683df8042535e697d3037bde1a92992f1d010b06 Mon Sep 17 00:00:00 2001 From: Hank Xie Date: Mon, 28 Mar 2022 02:05:23 -0400 Subject: landia: Porting battery led behavior for firmware spec. This patch changes the battery led behavior to meet firmware spec, and keeps the old behavior of lantis. BUG=b:227121467 BRANCH=dedede TEST=On landia. Set CBI and make sure the battery led works normally. Signed-off-by: Hank Xie Change-Id: I5d1d50f3f6d408d220810df85ad61575ff21f32b Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3552483 Reviewed-by: Devin Lu Reviewed-by: Tommy Chung Reviewed-by: Aseda Aboagye Commit-Queue: Aseda Aboagye --- board/lantis/led.c | 52 +++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 45 insertions(+), 7 deletions(-) diff --git a/board/lantis/led.c b/board/lantis/led.c index 57d537cf13..632f91e118 100644 --- a/board/lantis/led.c +++ b/board/lantis/led.c @@ -133,6 +133,23 @@ int led_set_brightness(enum ec_led_id led_id, const uint8_t *brightness) return EC_SUCCESS; } +/* + * lantis use old led policy. + * Use cbi fw_config to distinguish lantis from other boards. + * numeric_pad tablet mode + * lantis N N + * landrid Y N + * landia N Y + */ +static bool is_led_old_policy(void) +{ + if (get_cbi_fw_config_numeric_pad() == NUMERIC_PAD_ABSENT && + get_cbi_fw_config_tablet_mode() == TABLET_MODE_ABSENT) + return 1; + else + return 0; +} + /* * Set active charge port color to the parameter, turn off all others. * If no port is active (-1), turn off all LEDs. @@ -190,18 +207,39 @@ static void led_set_battery(void) /* Intentional fall-through */ case PWR_STATE_DISCHARGE: /* - * Blink white light (1 sec on, 1 sec off) + * Blink white/amber light (1 sec on, 1 sec off) * when battery capacity is less than 10% */ - if (charge_get_percent() < 10) - led_set_color_battery(RIGHT_PORT, - (battery_ticks & 0x2) ? LED_WHITE : LED_OFF); - else + if (charge_get_percent() < 10) { + if (is_led_old_policy()) { + led_set_color_battery( + RIGHT_PORT, (battery_ticks & 0x2) ? + LED_WHITE : LED_OFF); + } else { + if (led_auto_control_is_enabled( + EC_LED_ID_RIGHT_LED)) + led_set_color_battery( + RIGHT_PORT, + (battery_ticks & 0x2) ? + LED_AMBER : LED_OFF); + if (led_auto_control_is_enabled( + EC_LED_ID_LEFT_LED)) + led_set_color_battery( + LEFT_PORT, + (battery_ticks & 0x2) ? + LED_AMBER : LED_OFF); + } + } else { set_active_port_color(LED_OFF); + } break; case PWR_STATE_ERROR: - set_active_port_color( - (battery_ticks % 0x2) ? LED_WHITE : LED_OFF); + if (is_led_old_policy()) + set_active_port_color( + (battery_ticks % 0x2) ? LED_WHITE : LED_OFF); + else + set_active_port_color( + (battery_ticks % 0x2) ? LED_AMBER : LED_OFF); break; case PWR_STATE_CHARGE_NEAR_FULL: set_active_port_color(LED_WHITE); -- cgit v1.2.1