diff options
author | Rob Barnes <robbarnes@google.com> | 2022-02-28 16:03:18 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2022-03-01 23:54:33 +0000 |
commit | b135e45447ba42f276b6f5232e2573d166320b31 (patch) | |
tree | 2a41981ac8191e3a2ac89495771f02dfde8fb57d /common/battery.c | |
parent | 5130158262f9167cc8d4ef69f397a0a87968e996 (diff) | |
download | chrome-ec-b135e45447ba42f276b6f5232e2573d166320b31.tar.gz |
battery: Do not return display_soc if data is bad
If BATT_FLAG_BAD_FULL_CAPACITY or BATT_FLAG_BAD_REMAINING_CAPACITY
flags are set, then display_charge value is also bad.
Return UNAVALIABLE error rather than 0%.
BUG=b:217401040
BRANCH=guybrush
TEST=Force battery glitch, do not observe 0% battery in OS
Change-Id: Iea861582dde1f7db3d6a4c40e88169d7f74ca159
Signed-off-by: Rob Barnes <robbarnes@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3496464
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
Reviewed-by: Diana Z <dzigterman@chromium.org>
Diffstat (limited to 'common/battery.c')
-rw-r--r-- | common/battery.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/common/battery.c b/common/battery.c index 01478d5b52..b1baa1d485 100644 --- a/common/battery.c +++ b/common/battery.c @@ -545,6 +545,16 @@ void battery_compensate_params(struct batt_params *batt) static enum ec_status battery_display_soc(struct host_cmd_handler_args *args) { struct ec_response_display_soc *r = args->response; + const struct batt_params *batt = charger_current_battery_params(); + + /* + * BATT_FLAG_BAD_FULL_CAPACITY and BATT_FLAG_BAD_REMAINING_CAPACITY are + * used to derive display_soc, so if these are bad, display_soc is also + * bad. + */ + if ((batt->flags & BATT_FLAG_BAD_FULL_CAPACITY) || + (batt->flags & BATT_FLAG_BAD_REMAINING_CAPACITY)) + return EC_RES_UNAVAILABLE; r->display_soc = charge_get_display_charge(); r->full_factor = batt_host_full_factor * 10; |