summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDuncan Laurie <dlaurie@chromium.org>2015-01-17 20:35:23 -0800
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2015-01-18 22:17:27 +0000
commit9da3dfb29fb7d2abf718a6f7173a9591c2c72720 (patch)
tree5782caa6d7abd12572fa0534ac8ca9cba64cd275
parent7dec6938c963e83b0015ec986d9f7fcb0564debc (diff)
downloadchrome-ec-9da3dfb29fb7d2abf718a6f7173a9591c2c72720.tar.gz
charge_state_v2: Fixes for battery present reporting
Fix some issues with how the battery present flag is reported up to the host. If there is no battery presence GPIO or custom function then errors updating the smart battery info can result in the battery present flag reporting BP_NOT_SURE and indicating to the host that the battery is missing. In order to prevent spurious events require a second back-to-back read of a missing battery before the host is notified. When the battery presence does change, the host needs to be told to re-read the static battery info with EC_HOST_EVENT_BATTERY, passed to the OS via Notify command to tell the OS to re-execute _BIF/_BIX method on the ACPI battery device. When sending these events to the host the battery flags should first be updated in LPC shared memory so if the host handles the event quickly it will read the correct updated flags value. BUG=chrome-os-partner:34011 BRANCH=broadwell TEST=manual testing on samus: 1) add a console command that allows the smart battery update function to set batt.is_present to BP_NOT_SURE for a specified number of update cycles. 2) ensure that when the smart battery update only returns the battery missing for one update cycle that it does not result in an event to the host. 3) ensure that if the smart battery update indicates the battery is missing for more than one update cycle, such that the host is notified the battery is missing, that it correctly gets an event to re-read the battery info when it is indicated as present again. Change-Id: I0da004b991ea1a89b34cd7c0f8f3628b813ffe44 Signed-off-by: Duncan Laurie <dlaurie@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/241763 Reviewed-by: Alec Berg <alecaberg@chromium.org>
-rw-r--r--common/charge_state_v2.c34
1 files changed, 27 insertions, 7 deletions
diff --git a/common/charge_state_v2.c b/common/charge_state_v2.c
index 13cf6d20ef..91a41ade34 100644
--- a/common/charge_state_v2.c
+++ b/common/charge_state_v2.c
@@ -171,14 +171,31 @@ static void update_dynamic_battery_info(void)
int *memmap_lfcc = (int *)host_get_memmap(EC_MEMMAP_BATT_LFCC);
uint8_t *memmap_flags = host_get_memmap(EC_MEMMAP_BATT_FLAG);
uint8_t tmp;
- int cap_changed;
+ int send_batt_status_event = 0;
+ int send_batt_info_event = 0;
+ static int batt_present;
tmp = 0;
if (curr.ac)
tmp |= EC_BATT_FLAG_AC_PRESENT;
- if (curr.batt.is_present == BP_YES)
+ if (curr.batt.is_present == BP_YES) {
tmp |= EC_BATT_FLAG_BATT_PRESENT;
+ batt_present = 1;
+ /* Tell the AP to read battery info if it is newly present. */
+ if (!(*memmap_flags & EC_BATT_FLAG_BATT_PRESENT))
+ send_batt_info_event++;
+ } else {
+ /*
+ * Require two consecutive updates with BP_NOT_SURE
+ * before reporting it gone to the host.
+ */
+ if (batt_present)
+ tmp |= EC_BATT_FLAG_BATT_PRESENT;
+ else if (*memmap_flags & EC_BATT_FLAG_BATT_PRESENT)
+ send_batt_info_event++;
+ batt_present = 0;
+ }
if (!(curr.batt.flags & BATT_FLAG_BAD_VOLTAGE))
*memmap_volt = curr.batt.voltage;
@@ -198,12 +215,12 @@ static void update_dynamic_battery_info(void)
*memmap_cap = curr.batt.remaining_capacity;
}
- cap_changed = 0;
if (!(curr.batt.flags & BATT_FLAG_BAD_FULL_CAPACITY) &&
(curr.batt.full_capacity <= (*memmap_lfcc - LFCC_EVENT_THRESH) ||
curr.batt.full_capacity >= (*memmap_lfcc + LFCC_EVENT_THRESH))) {
*memmap_lfcc = curr.batt.full_capacity;
- cap_changed = 1;
+ /* Poke the AP if the full_capacity changes. */
+ send_batt_info_event++;
}
if (curr.batt.is_present == BP_YES &&
@@ -216,12 +233,15 @@ static void update_dynamic_battery_info(void)
/* Tell the AP to re-read battery status if charge state changes */
if (*memmap_flags != tmp)
- host_set_single_event(EC_HOST_EVENT_BATTERY_STATUS);
+ send_batt_status_event++;
+
+ /* Update flags before sending host events. */
*memmap_flags = tmp;
- /* Poke the AP if the full_capacity changes. */
- if (cap_changed)
+ if (send_batt_info_event)
host_set_single_event(EC_HOST_EVENT_BATTERY);
+ if (send_batt_status_event)
+ host_set_single_event(EC_HOST_EVENT_BATTERY_STATUS);
}
static const char * const state_list[] = {