mb/google/bluey: Add AC unplug detection and charging status indication

Implement logic to detect and clear ChromeOS EC AC-unplug events and
provide visual feedback via the LEDs before system shutdown.

Key changes:
- Added `detect_ac_unplug_event` and `clear_ac_unplug_event` to
  monitor power source changes via EC host events.
- Implemented `indicate_charging_status` to provide a 4-second
  notification to the user before the AP powers off.
- Integrated these helpers into `launch_charger_applet` to ensure
  the event state is clean upon entry and the user is notified
  before the system issues a power-off due to charging timeouts or
  state changes.

BUG=none
BRANCH=none
TEST=On Bluey, verify the LED turns on for 4 seconds when
charging fails or AC is removed during the charging applet
before the device powers off.

Change-Id: Ie1ff5ba6f158fe7302e523f984c5e5d5f05d6eae
Signed-off-by: Subrata Banik <subratabanik@google.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/91602
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Kapil Porwal <kapilporwal@google.com>
This commit is contained in:
Subrata Banik 2026-03-08 12:29:21 +00:00
commit ee3aef1c72

View file

@ -43,6 +43,7 @@
#define DELAY_CHARGING_APPLET_MS 2000 /* 2sec */
#define CHARGING_RAIL_STABILIZATION_DELAY_MS 3000 /* 3sec */
#define DELAY_CHARGING_ACTIVE_LB_MS 4000 /* 4sec */
enum charging_status {
CHRG_DISABLE,
@ -83,6 +84,41 @@ static int detect_ec_manual_poweron_event(void)
return 0;
}
static void clear_ac_unplug_event(void)
{
const uint64_t ac_unplug_event =
EC_HOST_EVENT_MASK(EC_HOST_EVENT_AC_DISCONNECTED);
google_chromeec_clear_events_b(ac_unplug_event);
}
static int detect_ac_unplug_event(void)
{
const uint64_t ac_unplug_event_mask =
EC_HOST_EVENT_MASK(EC_HOST_EVENT_AC_DISCONNECTED);
uint64_t events = google_chromeec_get_events_b();
if (!!(events & ac_unplug_event_mask))
return 1;
return 0;
}
/*
* Provides visual feedback via the LEDs and clears the AC unplug
* event to acknowledge the transition into a charging state.
*/
static void indicate_charging_status(void)
{
/* Turn on LEDs to alert user of power state change */
if (CONFIG(EC_GOOGLE_CHROMEEC_LED_CONTROL)) {
google_chromeec_lightbar_on();
mdelay(DELAY_CHARGING_ACTIVE_LB_MS);
}
/* Clear the event to prevent re-triggering in the next iteration */
clear_ac_unplug_event();
}
void launch_charger_applet(void)
{
if (!CONFIG(EC_GOOGLE_CHROMEEC))
@ -93,6 +129,8 @@ void launch_charger_applet(void)
printk(BIOS_INFO, "Inside %s. Initiating charging\n", __func__);
/* Reset AC-unplug detection state and lightbar status before entering loop */
clear_ac_unplug_event();
/* clear any pending power button press and lid open event */
clear_ec_manual_poweron_event();
@ -107,6 +145,8 @@ void launch_charger_applet(void)
* causes a boot hang. Instead, issue a shutdown if not charging.
*/
printk(BIOS_INFO, "Issuing power-off.\n");
if (detect_ac_unplug_event())
indicate_charging_status();
google_chromeec_offmode_heartbeat();
google_chromeec_ap_poweroff();
}
@ -123,6 +163,8 @@ void launch_charger_applet(void)
*/
if (!get_battery_icurr_ma()) {
printk(BIOS_INFO, "Issuing power-off due to change in charging state.\n");
if (detect_ac_unplug_event())
indicate_charging_status();
google_chromeec_offmode_heartbeat();
google_chromeec_ap_poweroff();
}