From 82e873da24f741b3199ca5a8dd08bf9aee17bcf1 Mon Sep 17 00:00:00 2001 From: ChromeOS Developer Date: Mon, 17 Mar 2014 12:02:46 -0700 Subject: [PATCH] Charge State: Update memory-mapped AC status in the hook handler Update the AC status immediately in the AC_CHANGE_HOOK handler so the memmory-mapped value shared with the host is correct prior to the host receiving an "AC changed" ACPI notification. BUG=chromium:349681 BRANCH=ToT TEST=Plug/unplug AC power. Verify that the host 'ACEX' bit is set prior to it receiving ACPI event 4 (or cleared before ACPI event 5). See crbug.com/349681#c12 Change-Id: I5c84e05b6886c5da9e8504cb803c80c3ec7c23fb Original-Change-Id: I1496efe1cfac9995e88bf9d84414ee903886d9ed Signed-off-by: Dave Parker Reviewed-on: https://chromium-review.googlesource.com/190345 Reviewed-by: Randall Spangler Reviewed-on: https://chromium-review.googlesource.com/192136 --- common/charge_state_v1.c | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/common/charge_state_v1.c b/common/charge_state_v1.c index bb2c681ef9..d08aa2430b 100644 --- a/common/charge_state_v1.c +++ b/common/charge_state_v1.c @@ -874,18 +874,40 @@ void charger_task(void) /* Hooks */ /** - * Charge notification hook. + * Chipset notification hook. * - * This is triggered when the AC state changes or the system boots, so that - * we can update our charging state. + * This is triggered when the system boots or resumes, so that we can update + * our charging state. */ -static void charge_hook(void) +static void chipset_hook(void) { /* Wake up the task now */ task_wake(TASK_ID_CHARGER); } -DECLARE_HOOK(HOOK_CHIPSET_RESUME, charge_hook, HOOK_PRIO_DEFAULT); -DECLARE_HOOK(HOOK_AC_CHANGE, charge_hook, HOOK_PRIO_DEFAULT); +DECLARE_HOOK(HOOK_CHIPSET_RESUME, chipset_hook, HOOK_PRIO_DEFAULT); + +/** + * AC change notification hook. + * + * This is triggered when the AC state changes, so that we can update the + * memory-mapped AC status and our charging state. + */ +static void ac_change_hook(void) +{ + /** + * Update the memory-mapped AC_PRESENT flag immediately so the + * state is correct prior to the host being notified of the AC + * change event. + */ + if (extpower_is_present()) + *task_ctx.memmap_batt_flags |= EC_BATT_FLAG_AC_PRESENT; + else + *task_ctx.memmap_batt_flags &= ~EC_BATT_FLAG_AC_PRESENT; + + /* Wake up the task now */ + task_wake(TASK_ID_CHARGER); +} +DECLARE_HOOK(HOOK_AC_CHANGE, ac_change_hook, HOOK_PRIO_DEFAULT); static void charge_init(void) {