diff options
-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 { |