summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChromeOS Developer <dparker@chromium.org>2014-03-17 12:02:46 -0700
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-03-17 20:07:50 +0000
commit64ce74e56a79f6d02480bb8ccf7beb3a15f440df (patch)
treeb4fda2083df8b72952309d5c22aac886213acf9b
parentc409d841ca6d4106776d7c93f665797eefe871b4 (diff)
downloadchrome-ec-64ce74e56a79f6d02480bb8ccf7beb3a15f440df.tar.gz
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: I1496efe1cfac9995e88bf9d84414ee903886d9ed Signed-off-by: Dave Parker <dparker@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/190345 Reviewed-by: Randall Spangler <rspangler@chromium.org>
-rw-r--r--common/charge_state.c34
1 files changed, 28 insertions, 6 deletions
diff --git a/common/charge_state.c b/common/charge_state.c
index ea1ef7ce0a..7711dfebb0 100644
--- a/common/charge_state.c
+++ b/common/charge_state.c
@@ -881,18 +881,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)
{