From 0e423969f1ebfb627aad04810802e414c92a4c6e Mon Sep 17 00:00:00 2001 From: Abe Levkoy Date: Fri, 20 Mar 2020 19:00:10 -0600 Subject: volteer: Select LED based on charge port If a port is charging, illuminate the LED next the the charging port. If no port is charging, illuminate both LEDs. BUG=b:139554899 TEST=Attach charger to C0 or C1; LED on attached side is illuminated BRANCH=none Change-Id: I85e3851132f42a35032bcd43bfd02c59c23cc589 Signed-off-by: Abe Levkoy Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2113121 Reviewed-by: Keith Short --- baseboard/volteer/baseboard.c | 5 +---- baseboard/volteer/led.c | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/baseboard/volteer/baseboard.c b/baseboard/volteer/baseboard.c index 4f2df794cc..57abe21bb3 100644 --- a/baseboard/volteer/baseboard.c +++ b/baseboard/volteer/baseboard.c @@ -655,10 +655,7 @@ __override void board_icl_tgl_all_sys_pwrgood(void) static void baseboard_init(void) { - /* Illuminate motherboard and daughter board LEDs equally. - * TODO(b/139554899): Illuminate only the LED next to the active - * charging port. - */ + /* Illuminate motherboard and daughter board LEDs equally to start. */ pwm_enable(PWM_CH_LED4_SIDESEL, 1); pwm_set_duty(PWM_CH_LED4_SIDESEL, 50); diff --git a/baseboard/volteer/led.c b/baseboard/volteer/led.c index 60f3a103bb..f10e95235a 100644 --- a/baseboard/volteer/led.c +++ b/baseboard/volteer/led.c @@ -5,8 +5,10 @@ * Power and battery LED control for Volteer */ +#include "charge_manager.h" #include "common.h" #include "ec_commands.h" +#include "hooks.h" #include "led_common.h" #include "led_pwm.h" #include "pwm.h" @@ -75,3 +77,27 @@ int led_set_brightness(enum ec_led_id led_id, const uint8_t *brightness) return EC_SUCCESS; } + +/* Illuminates the LED on the side of the active charging port. If not charging, + * illuminates both LEDs. + */ +static void led_set_charge_port_tick(void) +{ + int port; + int side_select_duty; + + port = charge_manager_get_active_charge_port(); + switch (port) { + case 0: + side_select_duty = 100; + break; + case 1: + side_select_duty = 0; + break; + default: + side_select_duty = 50; + } + + pwm_set_duty(PWM_CH_LED4_SIDESEL, side_select_duty); +} +DECLARE_HOOK(HOOK_TICK, led_set_charge_port_tick, HOOK_PRIO_DEFAULT); -- cgit v1.2.1