diff options
author | Wai-Hong Tam <waihong@google.com> | 2020-08-03 16:06:05 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-12-15 01:33:42 +0000 |
commit | dd7ad116cdf9cc5b6ac8e118c81e85655dd39cbf (patch) | |
tree | 4fc6613673e7b033dff99f615138c328ef941dbb | |
parent | 27c7dbf75c673d53c31c4513e21cf89f9a8f265e (diff) | |
download | chrome-ec-dd7ad116cdf9cc5b6ac8e118c81e85655dd39cbf.tar.gz |
battery: Simplify the compensation logic by using pointers
Simplify the logic by using pointers, instead of copying the values from
and to other variables. No behavior changes.
BRANCH=None
BUG=b:162604872
TEST=Checked the sysfs battery info.
Change-Id: I2dafd0c774354bbf563be121a8bf9d65f1d4dfd3
Signed-off-by: Wai-Hong Tam <waihong@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2335884
Reviewed-by: Jett Rink <jettrink@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3336666
Commit-Queue: Daisuke Nojiri <dnojiri@chromium.org>
Tested-by: Daisuke Nojiri <dnojiri@chromium.org>
-rw-r--r-- | common/battery.c | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/common/battery.c b/common/battery.c index 7563552143..2016e45680 100644 --- a/common/battery.c +++ b/common/battery.c @@ -572,15 +572,15 @@ DECLARE_HOOK(HOOK_INIT, battery_init, HOOK_PRIO_DEFAULT); void battery_compensate_params(struct batt_params *batt) { int numer, denom; - int remain = batt->remaining_capacity; - int full = batt->full_capacity; + 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)) return; - if (remain <= 0 || full <= 0) + if (*remain <= 0 || *full <= 0) return; /* full_factor != 100 isn't supported. EC and host are not able to @@ -589,21 +589,19 @@ void battery_compensate_params(struct batt_params *batt) return; /* full_factor is effectively disabled in powerd. */ - batt->full_capacity = full * batt_full_factor / 100; + *full = *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; - } + lfcc = *full; + if (*remain > lfcc) + *remain = lfcc; /* * Powerd uses the following equation to calculate display percentage: * charge = 100 * remain/full; * 100 * (charge - shutdown_pct) / (full_factor - shutdown_pct); */ - numer = (100 * remain - lfcc * batt_host_shutdown_pct) * 1000; + 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; |