From 163263c9a3eedacff191b50a9da55fd1454fcc86 Mon Sep 17 00:00:00 2001 From: Philip Chen Date: Thu, 10 May 2018 23:38:04 -0700 Subject: [PATCH] scarlet: Clamp reported battery SOC when charge terminates After we set TE (CL:958295), rt946x terminates charging when the charge current is below IEOC in constant-voltage mode. When AC is plugged and rt946x terminates, we see cases that battery SOC falls below BATTERY_LEVEL_NEAR_FULL but rt946x doesn't re-enable charging yet, which leads to amber LED. The Chrome OS UI might also show battery is not full in this case. Let's clamp the reported battery SOC in this scenario to avoid user confusion. BUG=b:77870927 BRANCH=scarlet TEST=When AC is on, charge terminates, and BATTERY_LEVEL_NEAR_FULL is hit, confirm battery SOC is overwritten. Change-Id: I4575e562873d149d6f349ddb578334d107e21776 Signed-off-by: Philip Chen Reviewed-on: https://chromium-review.googlesource.com/1055194 Commit-Ready: Philip Chen Tested-by: Philip Chen Reviewed-by: Nicolas Boichat --- board/scarlet/battery.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/board/scarlet/battery.c b/board/scarlet/battery.c index bc3ec6e84c..25b161dee2 100644 --- a/board/scarlet/battery.c +++ b/board/scarlet/battery.c @@ -242,6 +242,16 @@ int charger_profile_override(struct charge_state_data *curr) break; } + /* + * When the charger says it's done charging, even if fuel gauge says + * SOC < BATTERY_LEVEL_NEAR_FULL, we'll overwrite SOC with + * BATTERY_LEVEL_NEAR_FULL. So we can ensure both Chrome OS UI + * and battery LED indicate full charge. + */ + if (rt946x_is_charge_done()) + curr->batt.state_of_charge = MAX(BATTERY_LEVEL_NEAR_FULL, + curr->batt.state_of_charge); + return 0; }