diff --git a/src/mainboard/google/bluey/mainboard.c b/src/mainboard/google/bluey/mainboard.c index c7c136a886..3bdf4f4425 100644 --- a/src/mainboard/google/bluey/mainboard.c +++ b/src/mainboard/google/bluey/mainboard.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -29,6 +30,8 @@ #define USB3_MODE_NORMAL_VAL 0x21 #define USB3_MODE_FLIP_VAL 0x23 +#define LOW_BATTERY_SHUTDOWN_DELAY_SEC 5 + void mainboard_usb_typec_configure(uint8_t port_num, bool inverse_polarity) { if (!CONFIG(MAINBOARD_HAS_PS8820_RETIMER)) @@ -149,12 +152,38 @@ static void display_startup(void) enable_mdss_clk(); } +static void trigger_critical_battery_shutdown(void) +{ + printk(BIOS_WARNING, "Critical battery level detected without charger! Shutting down.\n"); + + if (!CONFIG(EC_GOOGLE_CHROMEEC)) + return; + + /* Set LED to Red to alert the user visually */ + google_chromeec_set_lightbar_rgb(0xff, 0xff, 0x00, 0x00); + + /* Log the event to CMOS/Flash for post-mortem analysis */ + elog_add_event_byte(ELOG_TYPE_LOW_BATTERY_INDICATOR, ELOG_FW_ISSUE_SHUTDOWN); + + /* Allow time for the log to flush and the user to see the LED change */ + delay(LOW_BATTERY_SHUTDOWN_DELAY_SEC); + + google_chromeec_ap_poweroff(); +} + static void mainboard_init(struct device *dev) { configure_parallel_charging(); display_startup(); + /* + * Low-battery boot indicator is done. Therefore, power off if battery + * is critical and not charging + */ + if (get_boot_mode() == LB_BOOT_MODE_LOW_BATTERY) + trigger_critical_battery_shutdown(); + /* Skip mainboard initialization if boot mode is "low-battery" or "off-mode charging"*/ if (is_low_power_boot_with_charger()) return; diff --git a/src/mainboard/google/bluey/romstage.c b/src/mainboard/google/bluey/romstage.c index 12b1479801..2b8e95c201 100644 --- a/src/mainboard/google/bluey/romstage.c +++ b/src/mainboard/google/bluey/romstage.c @@ -109,6 +109,10 @@ static void early_setup_usb(void) void platform_romstage_main(void) { + /* Set LED to Red to alert the user visually */ + if (CONFIG(EC_GOOGLE_CHROMEEC) && google_chromeec_is_critically_low_on_battery()) + google_chromeec_set_lightbar_rgb(0xff, 0xff, 0x00, 0x00); + /* Setup early USB related config */ early_setup_usb();