diff options
author | Ikjoon Jang <ikjn@chromium.org> | 2021-03-11 14:46:51 +0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-03-15 11:09:37 +0000 |
commit | ffbc67dcac2d03bc5967627ebd9dba37e7013e5a (patch) | |
tree | 730b4ba290df687a74842d20565e9193f8b0064b | |
parent | fd9ea2bfe6a9b0dbf40ad3aa36409063db15ce06 (diff) | |
download | chrome-ec-ffbc67dcac2d03bc5967627ebd9dba37e7013e5a.tar.gz |
virtual_battery: bug fix in reading SB_AVERAGE_CURRENT
Fix a bug from CL:2747559, virtual battery returns an error
for SB_AVERAGE_CURRENT. virtual battery handler should call
battery_get_avg_current(), not battery_get_avg_voltage().
BRANCH=none
BUG=b:170921599
TEST=read current_avg knob in kukui
Signed-off-by: Ikjoon Jang <ikjn@chromium.org>
Change-Id: I90c26a8e1d4fa6faccc0166b9f7b63fca9baef51
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2751320
Reviewed-by: Ting Shen <phoenixshen@chromium.org>
-rw-r--r-- | common/virtual_battery.c | 6 | ||||
-rw-r--r-- | driver/battery/smart.c | 4 | ||||
-rw-r--r-- | include/battery.h | 3 |
3 files changed, 8 insertions, 5 deletions
diff --git a/common/virtual_battery.c b/common/virtual_battery.c index c2ebd35afd..1caef535f6 100644 --- a/common/virtual_battery.c +++ b/common/virtual_battery.c @@ -246,9 +246,9 @@ int virtual_battery_operation(const uint8_t *batt_cmd_head, break; case SB_AVERAGE_CURRENT: /* This may cause an i2c transaction */ - val = battery_get_avg_voltage(); - if (val < 0) - return val; + if (curr_batt->flags & BATT_FLAG_BAD_AVERAGE_CURRENT) + return EC_ERROR_BUSY; + val = battery_get_avg_current(); memcpy(dest, &val, bounded_read_len); break; case SB_MAX_ERROR: diff --git a/driver/battery/smart.c b/driver/battery/smart.c index b0ccec8de9..1c2dcaf4c9 100644 --- a/driver/battery/smart.c +++ b/driver/battery/smart.c @@ -318,7 +318,6 @@ test_mockable int battery_device_chemistry(char *dest, int size) return sb_read_string(SB_DEVICE_CHEMISTRY, dest, size); } -#ifdef CONFIG_CMD_PWR_AVG int battery_get_avg_current(void) { int current; @@ -328,6 +327,7 @@ int battery_get_avg_current(void) return (int16_t)current; } +#ifdef CONFIG_CMD_PWR_AVG /* * Technically returns only the instantaneous reading, but tests showed that * for the majority of charge states above 3% this varies by less than 40mV @@ -386,6 +386,8 @@ void battery_get_params(struct batt_params *batt) else batt_new.current = (int16_t)v; + if (sb_read(SB_AVERAGE_CURRENT, &v)) + batt_new.flags |= BATT_FLAG_BAD_AVERAGE_CURRENT; if (sb_read(SB_CHARGING_VOLTAGE, &batt_new.desired_voltage)) batt_new.flags |= BATT_FLAG_BAD_DESIRED_VOLTAGE; diff --git a/include/battery.h b/include/battery.h index aed1e1c5cf..9df702cadf 100644 --- a/include/battery.h +++ b/include/battery.h @@ -120,8 +120,9 @@ int battery_get_avg_voltage(void); /* in mV */ #define BATT_FLAG_BAD_FULL_CAPACITY 0x00000200 #define BATT_FLAG_BAD_STATUS 0x00000400 #define BATT_FLAG_IMBALANCED_CELL 0x00000800 +#define BATT_FLAG_BAD_AVERAGE_CURRENT 0x00001000 /* All of the above BATT_FLAG_BAD_* bits */ -#define BATT_FLAG_BAD_ANY 0x000007fc +#define BATT_FLAG_BAD_ANY 0x000017fc /* Battery constants */ struct battery_info { |