summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaisuke Nojiri <dnojiri@chromium.org>2021-06-29 10:33:02 -0700
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-09-09 23:54:41 +0000
commit8e68c7895a886b1a253d381f133e23618e5b217c (patch)
tree690dd1365aa492621f3586c143046ce4d7e55096
parent893c12faf5436dc68ff06f869e36a81c917df2a2 (diff)
downloadchrome-ec-firmware-zork-13434.B-master.tar.gz
Battery: Apply fake SoC to display chargefirmware-zork-13434.B-master
This patch makes the battfake command apply the fake SoC to the display SoC as well as the raw battery SoC. This patch also cleans up battery_compensate_params. BUG=None BRANCH=None TEST=Atlas Change-Id: Ifbdaa81204d27501df8a4f5e025c19a79d62feff Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2994748 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3880828
-rw-r--r--common/battery.c12
-rw-r--r--driver/battery/smart.c1
2 files changed, 7 insertions, 6 deletions
diff --git a/common/battery.c b/common/battery.c
index 000ff3a6af..0a2395edab 100644
--- a/common/battery.c
+++ b/common/battery.c
@@ -614,18 +614,18 @@ void battery_compensate_params(struct batt_params *batt)
{
int numer, denom;
int *remain = &(batt->remaining_capacity);
- int *full = &(batt->full_capacity);
+ int full = batt->full_capacity;
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;
/* Some batteries don't update full capacity as often. */
- if (*remain > *full)
- *remain = *full;
+ if (*remain > full)
+ *remain = full;
/*
* EC calculates the display SoC like how Powerd used to do. Powerd
@@ -648,8 +648,8 @@ void battery_compensate_params(struct batt_params *batt)
* = ----------------------------------- x 1000
* full x (full_factor - shutdown_pct)
*/
- numer = 1000 * ((100 * *remain) - (*full * batt_host_shutdown_pct));
- denom = *full * (batt_host_full_factor - 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)
diff --git a/driver/battery/smart.c b/driver/battery/smart.c
index b0ccec8de9..208e02f89b 100644
--- a/driver/battery/smart.c
+++ b/driver/battery/smart.c
@@ -356,6 +356,7 @@ static void apply_fake_state_of_charge(struct batt_params *batt)
batt->state_of_charge = fake_state_of_charge;
batt->remaining_capacity = full * fake_state_of_charge / 100;
+ battery_compensate_params(batt);
batt->flags &= ~BATT_FLAG_BAD_STATE_OF_CHARGE;
batt->flags &= ~BATT_FLAG_BAD_REMAINING_CAPACITY;
}