summaryrefslogtreecommitdiff
path: root/common/battery.c
diff options
context:
space:
mode:
Diffstat (limited to 'common/battery.c')
-rw-r--r--common/battery.c18
1 files changed, 8 insertions, 10 deletions
diff --git a/common/battery.c b/common/battery.c
index 621bb14c0f..ab9a1a359b 100644
--- a/common/battery.c
+++ b/common/battery.c
@@ -565,15 +565,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
@@ -582,21 +582,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;