summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2023-05-04 15:33:06 -0600
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2023-05-08 22:19:05 +0000
commitf330c0d353c5f978907d8bbe4df4fd7a7a5c03f8 (patch)
treecdba91e6bb9ccab6205c886f7b2c85987d0bb6dc
parent8ee0ea15c200f35695492581de44063e5cb42bab (diff)
downloadchrome-ec-f330c0d353c5f978907d8bbe4df4fd7a7a5c03f8.tar.gz
charger: Move charge-state handling into a function
Move this related code into a separate function, to reduce the side of the charger_task() function. This makes no functional change. BUG=b:218332694 TEST=zmake build dev-posix Change-Id: I20632ed822df5cc2799959b251c29cb160eabcf7 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4508347 Commit-Queue: Simon Glass <sjg@chromium.org> Tested-by: Simon Glass <sjg@chromium.org> Reviewed-by: Abe Levkoy <alevkoy@chromium.org>
-rw-r--r--common/charge_state_v2.c70
1 files changed, 39 insertions, 31 deletions
diff --git a/common/charge_state_v2.c b/common/charge_state_v2.c
index f9a1e190a8..f3127c4330 100644
--- a/common/charge_state_v2.c
+++ b/common/charge_state_v2.c
@@ -2049,6 +2049,44 @@ static void check_extpower(int chgnum)
process_ac_change(chgnum);
}
+/* processing for new charge state, returning updated sleep_usec */
+static int process_charge_state(int *need_staticp, int sleep_usec)
+{
+ if (IS_ENABLED(CONFIG_CHARGER_PROFILE_OVERRIDE) &&
+ get_chg_ctrl_mode() == CHARGE_CONTROL_NORMAL) {
+ sleep_usec = charger_profile_override(&curr);
+ if (sleep_usec < 0)
+ charge_problem(PR_CUSTOM, sleep_usec);
+ }
+
+ if (IS_ENABLED(CONFIG_BATTERY_CHECK_CHARGE_TEMP_LIMITS) &&
+ battery_outside_charging_temperature()) {
+ curr.requested_current = 0;
+ curr.requested_voltage = 0;
+ curr.batt.flags &= ~BATT_FLAG_WANT_CHARGE;
+ if (curr.state != ST_DISCHARGE)
+ curr.state = ST_IDLE;
+ }
+
+ if (IS_ENABLED(CONFIG_CHARGE_MANAGER) &&
+ curr.batt.state_of_charge >=
+ CONFIG_CHARGE_MANAGER_BAT_PCT_SAFE_MODE_EXIT &&
+ !battery_seems_disconnected)
+ charge_manager_leave_safe_mode();
+
+ /* Keep the AP informed */
+ if (*need_staticp)
+ *need_staticp = update_static_battery_info();
+
+ /* Wait on the dynamic info until the static info is good. */
+ if (!*need_staticp)
+ update_dynamic_battery_info();
+ notify_host_of_low_battery_charge();
+ notify_host_of_low_battery_voltage();
+
+ return sleep_usec;
+}
+
/* Main loop */
void charger_task(void *u)
{
@@ -2090,37 +2128,7 @@ void charger_task(void *u)
notify_host_of_over_current(&curr.batt);
decide_charge_state(&need_static, &battery_critical);
-
- if (IS_ENABLED(CONFIG_CHARGER_PROFILE_OVERRIDE) &&
- get_chg_ctrl_mode() == CHARGE_CONTROL_NORMAL) {
- sleep_usec = charger_profile_override(&curr);
- if (sleep_usec < 0)
- charge_problem(PR_CUSTOM, sleep_usec);
- }
-
- if (IS_ENABLED(CONFIG_BATTERY_CHECK_CHARGE_TEMP_LIMITS) &&
- battery_outside_charging_temperature()) {
- curr.requested_current = 0;
- curr.requested_voltage = 0;
- curr.batt.flags &= ~BATT_FLAG_WANT_CHARGE;
- if (curr.state != ST_DISCHARGE)
- curr.state = ST_IDLE;
- }
-
- if (IS_ENABLED(CONFIG_CHARGE_MANAGER) &&
- curr.batt.state_of_charge >=
- CONFIG_CHARGE_MANAGER_BAT_PCT_SAFE_MODE_EXIT &&
- !battery_seems_disconnected)
- charge_manager_leave_safe_mode();
-
- /* Keep the AP informed */
- if (need_static)
- need_static = update_static_battery_info();
- /* Wait on the dynamic info until the static info is good. */
- if (!need_static)
- update_dynamic_battery_info();
- notify_host_of_low_battery_charge();
- notify_host_of_low_battery_voltage();
+ sleep_usec = process_charge_state(&need_static, sleep_usec);
/* And the EC console */
is_full = calc_is_full();