diff options
author | Vijay Hiremath <vijay.p.hiremath@intel.com> | 2017-01-05 23:17:37 -0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2017-01-06 20:39:22 -0800 |
commit | 7db78001c2c262f332f5e00fdf6d86cf05ff897e (patch) | |
tree | edb0aa802cac17d52414579861bb8958a17e3363 | |
parent | 4fa1c8b9e3dd89bb069ce0d2478dc12b542ba66b (diff) | |
download | chrome-ec-7db78001c2c262f332f5e00fdf6d86cf05ff897e.tar.gz |
charge_state_v2: Correct Smart battery charging/discharging status
AverageTimeToFull() and AverageTimeToEmpty() are the predicted time based
on the AverageCurrent(), these do not reflect the instant time of charging
or discharging. Hence we observe huge number of time (1092h because
register has 65535) to full time when battery starts accepting current
upon reaching 100%. To overcome this issue, explicitly checking if the
AverageTimeToFull() and AverageTimeToEmpty() register values are updated
with the valid data.
BUG=chrome-os-partner:60802
BRANCH=none
TEST=Manually tested on Reef. Charge the battery to 100%, once the
battery starts accepting current again observed time to full
is not huge number.
Change-Id: I6d6c21b72ab824dbe47e44e1e77f1c5319ac2720
Signed-off-by: Vijay Hiremath <vijay.p.hiremath@intel.com>
Reviewed-on: https://chromium-review.googlesource.com/425324
Commit-Ready: Vijay P Hiremath <vijay.p.hiremath@intel.com>
Tested-by: Vijay P Hiremath <vijay.p.hiremath@intel.com>
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
-rw-r--r-- | common/charge_state_v2.c | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/common/charge_state_v2.c b/common/charge_state_v2.c index 94dd210972..bd1404be11 100644 --- a/common/charge_state_v2.c +++ b/common/charge_state_v2.c @@ -314,8 +314,31 @@ static void dump_charge_state(void) static void show_charging_progress(void) { - int rv, minutes, to_full; + int rv = 0, minutes, to_full; +#ifdef CONFIG_BATTERY_SMART + /* + * Predicted remaining battery capacity based on AverageCurrent(). + * 65535 = Battery is not being discharged. + */ + if (!battery_time_to_empty(&minutes) && minutes != 65535) + to_full = 0; + /* + * Predicted time-to-full charge based on AverageCurrent(). + * 65535 = Battery is not being discharged. + */ + else if (!battery_time_to_full(&minutes) && minutes != 65535) + to_full = 1; + /* + * If both time to empty and time to full have invalid data, consider + * measured current from the coulomb counter and ac present status to + * decide whether battery is about to full or empty. + */ + else { + to_full = curr.batt_is_charging; + rv = EC_ERROR_UNKNOWN; + } +#else if (!curr.batt_is_charging) { rv = battery_time_to_empty(&minutes); to_full = 0; @@ -323,6 +346,7 @@ static void show_charging_progress(void) rv = battery_time_to_full(&minutes); to_full = 1; } +#endif if (rv) CPRINTS("Battery %d%% / ??h:?? %s%s", |