diff --git a/board/fizz/board.c b/board/fizz/board.c index 2aaf71beb9..eb44a25845 100644 --- a/board/fizz/board.c +++ b/board/fizz/board.c @@ -378,6 +378,13 @@ DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT); void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma, int charge_mv) { + /* Turn on/off power shortage alert. Performs the same check as + * system_can_boot_ap(). It's repeated here because charge_manager + * hasn't updated charge_current/voltage when board_set_charge_limit + * is called. */ + led_alert(charge_ma * charge_mv < + CONFIG_CHARGER_LIMIT_POWER_THRESH_CHG_MW * 1000); + /* * We have two FETs connected to two registers: PR257 & PR258. * These control thresholds of the over current monitoring system. @@ -402,7 +409,8 @@ void board_set_charge_limit(int port, int supplier, int charge_ma, gpio_set_level(GPIO_U42_P, 0); gpio_set_level(GPIO_U22_C, 0); } else { - CPRINTS("Current %dmA not supported", charge_mv); + /* TODO(http://crosbug.com/p/65013352) */ + CPRINTS("Current %dmA not supported", charge_ma); } } diff --git a/board/fizz/board.h b/board/fizz/board.h index db037357e3..ea663ba6ec 100644 --- a/board/fizz/board.h +++ b/board/fizz/board.h @@ -63,8 +63,7 @@ /* Charger */ #define CONFIG_CHARGE_MANAGER -/* TODO(dnojiri): Set this right */ -#define CONFIG_CHARGER_LIMIT_POWER_THRESH_CHG_MW 20000 +#define CONFIG_CHARGER_LIMIT_POWER_THRESH_CHG_MW 50000 #define CONFIG_CMD_PD_CONTROL #define CONFIG_EXTPOWER_GPIO @@ -232,6 +231,7 @@ int board_get_version(void); void board_reset_pd_mcu(void); void board_set_tcpc_power_mode(int port, int mode); int board_get_battery_soc(void); +void led_alert(int enable); #endif /* !__ASSEMBLER__ */ diff --git a/board/fizz/led.c b/board/fizz/led.c index a49d1986fa..6bd0796b3e 100644 --- a/board/fizz/led.c +++ b/board/fizz/led.c @@ -87,6 +87,7 @@ static struct { uint32_t interval; int duty_inc; enum led_color color; + int duty; } led_pulse; #define CONFIG_TICK(interval, color) \ @@ -97,18 +98,17 @@ static void config_tick(uint32_t interval, int duty_inc, enum led_color color) led_pulse.interval = interval; led_pulse.duty_inc = duty_inc; led_pulse.color = color; + led_pulse.duty = 0; } static void pulse_power_led(enum led_color color) { - static int duty = 0; - - set_color(EC_LED_ID_POWER_LED, color, duty); - if (duty + led_pulse.duty_inc > 100) + set_color(EC_LED_ID_POWER_LED, color, led_pulse.duty); + if (led_pulse.duty + led_pulse.duty_inc > 100) led_pulse.duty_inc = led_pulse.duty_inc * -1; - else if (duty + led_pulse.duty_inc < 0) + else if (led_pulse.duty + led_pulse.duty_inc < 0) led_pulse.duty_inc = led_pulse.duty_inc * -1; - duty += led_pulse.duty_inc; + led_pulse.duty += led_pulse.duty_inc; } static void led_tick(void); @@ -134,7 +134,7 @@ static void led_tick(void) static void led_suspend(void) { - CONFIG_TICK(LED_PULSE_TICK_US, LED_AMBER); + CONFIG_TICK(LED_PULSE_TICK_US, LED_GREEN); led_tick(); } DECLARE_HOOK(HOOK_CHIPSET_SUSPEND, led_suspend, HOOK_PRIO_DEFAULT); @@ -157,10 +157,21 @@ static void led_resume(void) } DECLARE_HOOK(HOOK_CHIPSET_RESUME, led_resume, HOOK_PRIO_DEFAULT); -void led_alert(void) +void led_alert(int enable) { - CONFIG_TICK(LED_PULSE_US, LED_RED); - led_tick(); + if (enable) { + /* Overwrite the current signal */ + CONFIG_TICK(LED_PULSE_US, LED_RED); + led_tick(); + } else { + /* Restore the previous signal */ + if (chipset_in_state(CHIPSET_STATE_ON)) + led_resume(); + else if (chipset_in_state(CHIPSET_STATE_SUSPEND)) + led_suspend(); + else if (chipset_in_state(CHIPSET_STATE_ANY_OFF)) + led_shutdown(); + } } static int command_led(int argc, char **argv) @@ -182,14 +193,14 @@ static int command_led(int argc, char **argv) } else if (!strcasecmp(argv[1], "amber")) { set_color(id, LED_AMBER, 100); } else if (!strcasecmp(argv[1], "alert")) { - led_alert(); + led_alert(1); } else { return EC_ERROR_PARAM1; } return EC_SUCCESS; } DECLARE_CONSOLE_COMMAND(led, command_led, - "[debug|red|green|amber|off]", + "[debug|red|green|amber|off|alert]", "Turn on/off LED."); void led_get_brightness_range(enum ec_led_id led_id, uint8_t *brightness_range) diff --git a/common/vboot/vboot.c b/common/vboot/vboot.c index 4830d34cce..c645d7b4f9 100644 --- a/common/vboot/vboot.c +++ b/common/vboot/vboot.c @@ -149,7 +149,6 @@ static int verify_and_jump(void) /* Request more power: charging battery or more powerful AC adapter */ static void request_power(void) { - /* TODO(crosbug.com/p/37646390): Blink LED */ CPRINTS("%s", __func__); } @@ -192,7 +191,7 @@ static void vboot_main(void) return; } - if (system_get_image_copy() != SYSTEM_IMAGE_RO || !system_is_locked()) { + if (system_is_in_rw() || !system_is_locked()) { /* * If we're here, it means PD negotiation was attempted but * we didn't get enough power to boot AP. This happens on RW @@ -203,6 +202,10 @@ static void vboot_main(void) * also be here because PD negotiation is still taking place. * If so, we'll briefly show request power sign but it will * be immediately corrected. + * + * We can also get here because we called system_can_boot_ap too + * early. Power will be requested but it should be cancelled by + * board_set_charge_limit as soon as a PD contract is made. */ request_power(); return;