From 4e94a3264d66a67f69740441f71f86f06ecff614 Mon Sep 17 00:00:00 2001 From: Daisuke Nojiri Date: Mon, 29 Oct 2018 14:12:07 -0700 Subject: chgstv2: Notify on display percentage change This patch makes the charger task v2 notify HOOK_BATTERY_SOC_CHANGE handlers when the display charge percentage changes. This allows EC to update LEDs synchronously to the number on the display. Signed-off-by: Daisuke Nojiri BUG=b:109954565,b:80270446 BRANCH=none TEST=Verify charge LED changes to white (full) on Sona synchronously to the display percentage. TEST=Verify charge LED changes to blinking white (low) on Sona within 30 seconds synchronously to the display percentage. Change-Id: Ib2c587ad3307fe62b268a25a93344c88c6c137f3 Reviewed-on: https://chromium-review.googlesource.com/1309034 Commit-Ready: Daisuke Nojiri Tested-by: Daisuke Nojiri Reviewed-by: Jett Rink Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3869321 Auto-Submit: Daisuke Nojiri Commit-Queue: Daisuke Nojiri --- common/charge_state_v2.c | 21 ++++++++++++++++----- include/charge_state.h | 5 +++++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/common/charge_state_v2.c b/common/charge_state_v2.c index 4291e5f9bc..64fc7332ac 100644 --- a/common/charge_state_v2.c +++ b/common/charge_state_v2.c @@ -79,7 +79,7 @@ static int charge_request(int voltage, int current); static const struct battery_info *batt_info; static struct charge_state_data curr; static enum charge_state_v2 prev_state; -static int prev_ac, prev_charge, prev_full; +static int prev_ac, prev_charge, prev_full, prev_disp_charge; static enum battery_present prev_bp; static int is_full; /* battery not accepting current */ static enum ec_charge_control_mode chg_ctl_mode; @@ -1146,13 +1146,17 @@ static void show_charging_progress(void) #endif if (rv) - CPRINTS("Battery %d%% / ??h:?? %s%s", + CPRINTS("Battery %d%% (Display %d.%d %%) / ??h:?? %s%s", curr.batt.state_of_charge, + curr.batt.display_charge / 10, + curr.batt.display_charge % 10, to_full ? "to full" : "to empty", is_full ? ", not accepting current" : ""); else - CPRINTS("Battery %d%% / %dh:%d %s%s", + CPRINTS("Battery %d%% (Display %d.%d %%) / %dh:%d %s%s", curr.batt.state_of_charge, + curr.batt.display_charge / 10, + curr.batt.display_charge % 10, minutes / 60, minutes % 60, to_full ? "to full" : "to empty", is_full ? ", not accepting current" : ""); @@ -1572,7 +1576,7 @@ void charger_task(void *u) /* Get the battery-specific values */ batt_info = battery_get_info(); - prev_ac = prev_charge = -1; + prev_ac = prev_charge = prev_disp_charge = -1; chg_ctl_mode = CHARGE_CONTROL_NORMAL; shutdown_warning_time.val = 0UL; battery_seems_to_be_dead = 0; @@ -1875,9 +1879,11 @@ wait_for_it: (charge_base != prev_charge_base) || #endif (is_full != prev_full) || - (curr.state != prev_state)) { + (curr.state != prev_state) || + (curr.batt.display_charge != prev_disp_charge)) { show_charging_progress(); prev_charge = curr.batt.state_of_charge; + prev_disp_charge = curr.batt.display_charge; #ifdef CONFIG_EC_EC_COMM_BATTERY_MASTER prev_charge_base = charge_base; #endif @@ -2180,6 +2186,11 @@ int charge_get_percent(void) return is_full ? 100 : curr.batt.state_of_charge; } +int charge_get_display_charge(void) +{ + return curr.batt.display_charge; +} + int charge_get_battery_temp(int idx, int *temp_ptr) { if (curr.batt.flags & BATT_FLAG_BAD_TEMPERATURE) diff --git a/include/charge_state.h b/include/charge_state.h index 4ac41cbe4d..7d71c68cd2 100644 --- a/include/charge_state.h +++ b/include/charge_state.h @@ -98,6 +98,11 @@ int charge_get_percent(void); int board_get_battery_soc(void); #endif +/** + * Return current display charge in 10ths of a percent (e.g. 1000 = 100.0%) + */ +int charge_get_display_charge(void); + /** * Check if board is consuming full input current * -- cgit v1.2.1