diff options
author | Simon Glass <sjg@chromium.org> | 2023-05-03 13:31:37 -0600 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2023-05-05 15:16:14 +0000 |
commit | 12b5ad2a32b631e9b65307861e495dc515d110f6 (patch) | |
tree | 59d6523b2c0141674c3b454a7ecb967892e5759e | |
parent | 1612a1ad427ec5929748fa6b94fb58b9bb8dd171 (diff) | |
download | chrome-ec-12b5ad2a32b631e9b65307861e495dc515d110f6.tar.gz |
charger: Move processing of AC change into a function
Split this code out into its own function, called if a change is
detected.
Tweak a comment while we are here.
This makes no functional change.
BUG=b:218332694
TEST=zmake build dev-posix
Change-Id: Iabcc117a28004a24a0069b2205e87c92c7807f4b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4500686
Reviewed-by: Tristan Honscheid <honscheid@google.com>
Commit-Queue: Simon Glass <sjg@chromium.org>
Tested-by: Simon Glass <sjg@chromium.org>
-rw-r--r-- | common/charge_state_v2.c | 82 |
1 files changed, 40 insertions, 42 deletions
diff --git a/common/charge_state_v2.c b/common/charge_state_v2.c index ff9a752695..91f548166d 100644 --- a/common/charge_state_v2.c +++ b/common/charge_state_v2.c @@ -1723,6 +1723,44 @@ void check_battery_change_soc(void) } } +/* We've noticed a change in AC presence, let the board know */ +static void process_ac_change(const int chgnum) +{ + board_check_extpower(); + if (curr.ac) { + /* + * Some chargers are unpowered when the AC is off, so we'll + * reinitialize it when AC comes back and set the input current + * limit. Try again if it fails. + */ + int rv = charger_post_init(); + + if (rv != EC_SUCCESS) { + charge_problem(PR_POST_INIT, rv); + } else if (curr.desired_input_current != + CHARGE_CURRENT_UNINITIALIZED) { + rv = charger_set_input_current_limit( + chgnum, curr.desired_input_current); + if (rv != EC_SUCCESS) + charge_problem(PR_SET_INPUT_CURR, rv); + } + + if (rv == EC_SUCCESS) + prev_ac = curr.ac; + } else { + /* Some things are only meaningful on AC */ + set_chg_ctrl_mode(CHARGE_CONTROL_NORMAL); + battery_seems_dead = 0; + prev_ac = curr.ac; + + /* + * b/187967523, we should clear charge current, otherwise it + * will affect typeC output. This should be ok for all chargers. + */ + charger_set_current(chgnum, 0); + } +} + /* Main loop */ void charger_task(void *u) { @@ -1745,49 +1783,9 @@ void charger_task(void *u) curr.ac = extpower_is_present(); if (IS_ENABLED(CONFIG_EC_EC_COMM_BATTERY_CLIENT)) base_check_extpower(); - if (curr.ac != prev_ac) { - /* - * We've noticed a change in AC presence, let the board - * know. - */ - board_check_extpower(); - if (curr.ac) { - /* - * Some chargers are unpowered when the AC is - * off, so we'll reinitialize it when AC - * comes back and set the input current limit. - * Try again if it fails. - */ - int rv = charger_post_init(); - - if (rv != EC_SUCCESS) { - charge_problem(PR_POST_INIT, rv); - } else if (curr.desired_input_current != - CHARGE_CURRENT_UNINITIALIZED) { - rv = charger_set_input_current_limit( - chgnum, - curr.desired_input_current); - if (rv != EC_SUCCESS) - charge_problem( - PR_SET_INPUT_CURR, rv); - } - - if (rv == EC_SUCCESS) - prev_ac = curr.ac; - } else { - /* Some things are only meaningful on AC */ - set_chg_ctrl_mode(CHARGE_CONTROL_NORMAL); - battery_seems_dead = 0; - prev_ac = curr.ac; - /* - * b/187967523, we should clear charge current, - * otherwise it will effect typeC output.this - * should be ok for all chargers. - */ - charger_set_current(chgnum, 0); - } - } + if (curr.ac != prev_ac) + process_ac_change(chgnum); if (IS_ENABLED(CONFIG_EC_EC_COMM_BATTERY_CLIENT)) base_update_battery_info(); |