summaryrefslogtreecommitdiff
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
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>
-rw-r--r--common/battery.c34
-rw-r--r--driver/battery/smart.c3
-rw-r--r--include/config.h7
3 files changed, 27 insertions, 17 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;
}
diff --git a/driver/battery/smart.c b/driver/battery/smart.c
index 0598653768..758a60f546 100644
--- a/driver/battery/smart.c
+++ b/driver/battery/smart.c
@@ -396,7 +396,10 @@ void battery_get_params(struct batt_params *batt)
/* Force both to zero */
batt_new.desired_voltage = batt_new.desired_current = 0;
+#ifdef HAS_TASK_HOSTCMD
+ /* if there is no host, we don't care about compensation */
battery_compensate_params(&batt_new);
+#endif
/* Update visible battery parameters */
memcpy(batt, &batt_new, sizeof(*batt));
diff --git a/include/config.h b/include/config.h
index f29672af09..2ff47b6972 100644
--- a/include/config.h
+++ b/include/config.h
@@ -427,10 +427,15 @@
* will be equal to full_capacity eventually. This used to be done in ACPI.
*/
#define CONFIG_BATT_FULL_FACTOR 98
-#define CONFIG_BATT_HOST_FULL_FACTOR 94
#define CONFIG_BATT_HOST_SHUTDOWN_PERCENTAGE 4
/*
+ * Powerd's full_factor. It has to be 100(%) to get display battery percentage.
+ * Otherwise, display percentages will be always zero.
+ */
+#define CONFIG_BATT_HOST_FULL_FACTOR 94
+
+/*
* Expose some data when it is needed.
* For example, battery disconnect state
*/