diff options
author | Jeffy Chen <jeffy.chen@rock-chips.com> | 2017-09-22 12:37:52 +0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2017-09-25 21:06:52 -0700 |
commit | 0ddaa7d9ebc722c56625d0ff800e83cf5d11d67b (patch) | |
tree | d1c295d0bc94a17f3f2e2e6bd235bba7fbbebc7f /common | |
parent | 13fb9ac539b9e85fd418b25da36e80a9be4aa292 (diff) | |
download | chrome-ec-0ddaa7d9ebc722c56625d0ff800e83cf5d11d67b.tar.gz |
virtual_battery: Avoid unexpected batt_mode_cache refreshing
Currently we are assuming batt_mode would never be zero, but that is not
always true. Some battery do report zero for batt_mode(bob for example).
So everytime the batt_mode_cache been set to zero, the virtual_battery
would consider it uninited, and tries to refresh the next time.
Use -1 as uninited batt_mode_cache to avoid that.
BUG=b:66555246
BRANCH=gru
TEST=Check on bob, the battery level is correct.
Change-Id: Ieb7ec9403f69a6b5bca93c6682ec6117fe95fe1e
Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>
Reviewed-on: https://chromium-review.googlesource.com/678135
Reviewed-by: Douglas Anderson <dianders@chromium.org>
Reviewed-by: Philip Chen <philipchen@chromium.org>
Reviewed-by: Shawn N <shawnn@chromium.org>
Diffstat (limited to 'common')
-rw-r--r-- | common/virtual_battery.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/common/virtual_battery.c b/common/virtual_battery.c index c9c600a745..7fdd92de1a 100644 --- a/common/virtual_battery.c +++ b/common/virtual_battery.c @@ -16,6 +16,8 @@ #define CPUTS(outstr) cputs(CC_I2C, outstr) #define CPRINTS(format, args...) cprints(CC_I2C, format, ## args) +#define BATT_MODE_UNINITIALIZED -1 + /* * The state machine used to parse smart battery command * to support virtual battery. @@ -182,7 +184,7 @@ int virtual_battery_operation(const uint8_t *batt_cmd_head, * Note that we don't update the cached capacity: We do a real-time * conversion and return the converted values. */ - static int batt_mode_cache; + static int batt_mode_cache = BATT_MODE_UNINITIALIZED; const struct batt_params *curr_batt; /* * Don't allow host reads into arbitrary memory space, most params @@ -197,7 +199,7 @@ int virtual_battery_operation(const uint8_t *batt_cmd_head, batt_mode_cache = batt_cmd_head[1] | (batt_cmd_head[2] << 8); } else if (read_len > 0) { - if (batt_mode_cache == 0) + if (batt_mode_cache == BATT_MODE_UNINITIALIZED) /* * Read the battery operational mode from * the battery to initialize batt_mode_cache. |