diff options
author | Daisuke Nojiri <dnojiri@chromium.org> | 2018-11-01 12:46:33 -0700 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2022-09-13 17:33:13 +0000 |
commit | 3abcd13ee3ed69af1517d29378137148a4a2a750 (patch) | |
tree | cef436d346e231864be127d660015c9b0584208b | |
parent | cee2ded0cbbe604f5876547845ed2068b4aa6214 (diff) | |
download | chrome-ec-3abcd13ee3ed69af1517d29378137148a4a2a750.tar.gz |
Battery: Apply full factor to full capacity
This change introduces CONFIG_BATT_HOST_FULL_FACTOR. If it's 100,
meaning no compensation, we multiply full capacity by
CONFIG_BATT_FULL_FACTOR. This makes the rest of the system see
consistent charge percentage behavior.
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 turns to full at the same time.
Change-Id: Ifb27c802b0cf04195ac5b426c13f9476189feb75
Reviewed-on: https://chromium-review.googlesource.com/1313468
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: Daisuke Nojiri <dnojiri@chromium.org>
Reviewed-by: Jett Rink <jettrink@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3872562
Auto-Submit: Daisuke Nojiri <dnojiri@chromium.org>
Commit-Queue: Daisuke Nojiri <dnojiri@chromium.org>
-rw-r--r-- | common/battery.c | 20 | ||||
-rw-r--r-- | include/config.h | 5 |
2 files changed, 14 insertions, 11 deletions
diff --git a/common/battery.c b/common/battery.c index 346b9207b8..f791545e20 100644 --- a/common/battery.c +++ b/common/battery.c @@ -21,11 +21,9 @@ #define CPRINTF(format, args...) cprintf(CC_CHARGER, format, ## args) #define CPRINTS(format, args...) cprints(CC_CHARGER, format, ## args) -/* - * See config.h for details. - * TODO: Allow host (powerd) to update it. - */ +/* 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; #ifdef CONFIG_BATTERY_V2 @@ -577,7 +575,15 @@ void battery_compensate_params(struct batt_params *batt) if (remain <= 0 || full <= 0) return; - if (remain * 100 > full * batt_full_factor) { + 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; return; @@ -585,11 +591,11 @@ void battery_compensate_params(struct batt_params *batt) /* * Powerd uses the following equation to calculate display percentage: - * charge = remain/full; + * charge = 100 * remain/full; * 100 * (charge - shutdown_pct) / (full_factor - shutdown_pct); */ numer = (100 * remain - full * batt_host_shutdown_pct) * 1000; - denom = full * (batt_full_factor - batt_host_shutdown_pct); + denom = full * (batt_host_full_factor - batt_host_shutdown_pct); /* Rounding (instead of truncating) */ batt->display_charge = (numer + denom / 2) / denom; } diff --git a/include/config.h b/include/config.h index 3b9a2e7695..712edde714 100644 --- a/include/config.h +++ b/include/config.h @@ -498,12 +498,9 @@ * Some batteries don't update full capacity timely or don't update it at all. * On such systems, compensation is required to guarantee remaining_capacity * will be equal to full_capacity eventually. This used to be done in ACPI. - * - * This number should match those used by powerd to evenly scale battery - * reading from 0 to 100%. These are default values, which are effective until - * the host boots. */ #define CONFIG_BATT_FULL_FACTOR 98 +#define CONFIG_BATT_HOST_FULL_FACTOR 94 #define CONFIG_BATT_HOST_SHUTDOWN_PERCENTAGE 4 /* |