summaryrefslogtreecommitdiff
path: root/common/battery.c
diff options
context:
space:
mode:
authorDaisuke Nojiri <dnojiri@chromium.org>2018-11-09 09:43:42 -0800
committerchrome-bot <chrome-bot@chromium.org>2018-11-16 05:01:57 -0800
commitcd2364b2da37d851baa36378eb3c8dd5846ab98a (patch)
treee057eda720f6e96681b5b235f26a50bef0349c09 /common/battery.c
parenta2c7fd10c148a913828f63fdbc0599f63804b22e (diff)
downloadchrome-ec-cd2364b2da37d851baa36378eb3c8dd5846ab98a.tar.gz
Battery: Use host full capacity to compute display percentage
The full capacity known by the host may slightly differ from the full capacity known by the EC because we notify the host of the new capacity only if the difference is larger than 5 mAh. This patch makes the EC use the host's full capacity instead of the local full capacity to compute the display percentage. Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> BUG=b:109954565,b:80270446 BRANCH=none TEST=Verify display percentages printed by EC and power_supply_info move up synchronously on charge and the LED and the taskbar icon turn to full at the same time. TEST=buildall Change-Id: Ie695a9937a22fc7a769b82448f4600d4491935b3 Reviewed-on: https://chromium-review.googlesource.com/1330101 Commit-Ready: Daisuke Nojiri <dnojiri@chromium.org> Tested-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Jett Rink <jettrink@chromium.org>
Diffstat (limited to 'common/battery.c')
-rw-r--r--common/battery.c34
1 files changed, 18 insertions, 16 deletions
diff --git a/common/battery.c b/common/battery.c
index c143826802..a23b8c2505 100644
--- a/common/battery.c
+++ b/common/battery.c
@@ -22,9 +22,9 @@
#define CPRINTS(format, args...) cprints(CC_CHARGER, format, ## args)
/* See config.h for details */
-static int batt_full_factor = CONFIG_BATT_FULL_FACTOR;
-static int batt_host_full_factor = CONFIG_BATT_HOST_FULL_FACTOR;
-static int batt_host_shutdown_pct = CONFIG_BATT_HOST_SHUTDOWN_PERCENTAGE;
+const static int batt_full_factor = CONFIG_BATT_FULL_FACTOR;
+const static int batt_host_full_factor = CONFIG_BATT_HOST_FULL_FACTOR;
+const static int batt_host_shutdown_pct = CONFIG_BATT_HOST_SHUTDOWN_PERCENTAGE;
#ifdef CONFIG_BATTERY_V2
/*
@@ -574,6 +574,7 @@ void battery_compensate_params(struct batt_params *batt)
int numer, denom;
int remain = batt->remaining_capacity;
int full = batt->full_capacity;
+ int lfcc = *(int *)host_get_memmap(EC_MEMMAP_BATT_LFCC);
if ((batt->flags & BATT_FLAG_BAD_FULL_CAPACITY) ||
(batt->flags & BATT_FLAG_BAD_REMAINING_CAPACITY))
@@ -582,18 +583,19 @@ void battery_compensate_params(struct batt_params *batt)
if (remain <= 0 || full <= 0)
return;
- if (batt_host_full_factor == 100) {
- /* full_factor is effectively disabled in powerd. */
- batt->full_capacity = full * batt_full_factor / 100;
- full = batt->full_capacity;
- if (remain > full) {
- batt->remaining_capacity = full;
- remain = batt->remaining_capacity;
- }
- } else if (remain * 100 > full * batt_full_factor) {
- batt->remaining_capacity = full;
- batt->display_charge = 1000;
+ /* full_factor != 100 isn't supported. EC and host are not able to
+ * act on soc changes synchronously. */
+ if (batt_host_full_factor != 100)
return;
+
+ /* full_factor is effectively disabled in powerd. */
+ batt->full_capacity = full * batt_full_factor / 100;
+ if (lfcc == 0)
+ /* EC just reset. Assume host full is equal. */
+ lfcc = batt->full_capacity;
+ if (remain > lfcc) {
+ batt->remaining_capacity = lfcc;
+ remain = batt->remaining_capacity;
}
/*
@@ -601,8 +603,8 @@ void battery_compensate_params(struct batt_params *batt)
* charge = 100 * remain/full;
* 100 * (charge - shutdown_pct) / (full_factor - shutdown_pct);
*/
- numer = (100 * remain - full * batt_host_shutdown_pct) * 1000;
- denom = full * (batt_host_full_factor - batt_host_shutdown_pct);
+ numer = (100 * remain - lfcc * batt_host_shutdown_pct) * 1000;
+ denom = lfcc * (100 - batt_host_shutdown_pct);
/* Rounding (instead of truncating) */
batt->display_charge = (numer + denom / 2) / denom;
}