diff options
author | Wai-Hong Tam <waihong@google.com> | 2020-08-01 08:08:51 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-12-15 01:33:54 +0000 |
commit | 9c6087a318a1a0ae887468b859445e0490acb06d (patch) | |
tree | e4281fa0cdafcb2bea2b40fda5ec7effb1b7b3ae | |
parent | 032be5e78a553977223001f4598aaa696f81989b (diff) | |
download | chrome-ec-9c6087a318a1a0ae887468b859445e0490acb06d.tar.gz |
battery: Calculate the display charge percentage
It doesn't require the powerd's full factory to be 100%. Also refine the
comment on the powerd's equation to make it more understandable.
BRANCH=None
BUG=b:162604872
TEST=With the follower CL which updates the powerd's full factor value,
checked EC showing the same Display percentage as the UI.
Change-Id: I50ae7c38c423722188d892f91f4fc93d4d5f84e1
Signed-off-by: Wai-Hong Tam <waihong@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2335886
Reviewed-by: Jett Rink <jettrink@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3336668
Commit-Queue: Daisuke Nojiri <dnojiri@chromium.org>
Tested-by: Daisuke Nojiri <dnojiri@chromium.org>
-rw-r--r-- | common/battery.c | 22 | ||||
-rw-r--r-- | include/config.h | 3 |
2 files changed, 14 insertions, 11 deletions
diff --git a/common/battery.c b/common/battery.c index 16c00c063a..117bbbb111 100644 --- a/common/battery.c +++ b/common/battery.c @@ -582,11 +582,6 @@ void battery_compensate_params(struct batt_params *batt) if (*remain <= 0 || *full <= 0) return; - /* 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. */ *full = *full * batt_full_factor / 100; if (*remain > *full) @@ -594,15 +589,24 @@ void battery_compensate_params(struct batt_params *batt) /* * Powerd uses the following equation to calculate display percentage: - * charge = 100 * remain/full; - * 100 * (charge - shutdown_pct) / (full_factor - shutdown_pct); + * charge = 100 * remain / full + * display = 100 * (charge - shutdown_pct) / + * (full_factor - shutdown_pct) + * = 100 * ((100 * remain / full) - shutdown_pct) / + * (full_factor - shutdown_pct) + * = 100 * ((100 * remain) - (full * shutdown_pct)) / + * (full * (full_factor - shutdown_pct)) + * + * The unit of the following batt->display_charge is 0.1%. */ - numer = (100 * *remain - *full * batt_host_shutdown_pct) * 1000; - denom = *full * (100 - batt_host_shutdown_pct); + numer = 1000 * ((100 * *remain) - (*full * 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; if (batt->display_charge < 0) batt->display_charge = 0; + if (batt->display_charge > 1000) + batt->display_charge = 1000; } __overridable void board_battery_compensate_params(struct batt_params *batt) diff --git a/include/config.h b/include/config.h index ecf2d02293..86cfb58898 100644 --- a/include/config.h +++ b/include/config.h @@ -484,8 +484,7 @@ #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. + * Powerd's full_factor. */ #define CONFIG_BATT_HOST_FULL_FACTOR 94 |