summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2023-05-05 12:09:30 -0600
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2023-05-09 22:29:37 +0000
commit81eeda15fbe097e92c36962e7f954c4677c9b22d (patch)
tree07a6715e1e0ea1bb64a5e3d3d5d7de34e93a7cdc
parent5e2d3b14dc9359d052a18f844fe906b8fffee110 (diff)
downloadchrome-ec-81eeda15fbe097e92c36962e7f954c4677c9b22d.tar.gz
charger: Avoid accessing curr.ac in base_check_extpower()
We want to move this function into its own file where it will not have access to the 'curr' state. Pass in the ac value and use the return value to indicate whether it should be zeroed. Pass in prev_ac as well, for the same reason. This changes the ordering of curr.ac being set to 0, so it happens after board_base_reset() has been called. From what I can tell, this does not matter, although there is a lot of code what could be affected by the base_detect_deferred hook or the call to base_detect_change(). So this makes no functional change. BUG=b:218332694 TEST=zmake build dev-posix Check size on lux: *** 69552 bytes in flash and 1152 bytes in RAM lux RO **** *** 69448 bytes in flash and 1120 bytes in RAM lux RW **** Change-Id: Ie2171016b692d233fda4f7bd527e74cbb965702e Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4510243 Commit-Queue: Simon Glass <sjg@chromium.org> Reviewed-by: Tomasz Michalec <tmichalec@google.com> Tested-by: Simon Glass <sjg@chromium.org>
-rw-r--r--common/charge_state_v2.c30
1 files changed, 22 insertions, 8 deletions
diff --git a/common/charge_state_v2.c b/common/charge_state_v2.c
index 880756e384..41cb86753b 100644
--- a/common/charge_state_v2.c
+++ b/common/charge_state_v2.c
@@ -1724,21 +1724,33 @@ static void charger_setup(const struct charger_info *info)
battery_level_shutdown = board_set_battery_level_shutdown();
}
-/* Check base external-power settings and react as needed */
-static void base_check_extpower(void)
+/*
+ * Check base external-power settings and react as needed
+ *
+ * @param ac Current ac value from struct charge_state_data
+ * @param prev_ac Previous value of ac
+ * Returns true if ac should be zeroed, false to leave it along
+ */
+static bool base_check_extpower(int ac, int prev_ac)
{
/* This #ifdef protects access to vars that are otherwise unavailable */
#ifdef CONFIG_EC_EC_COMM_BATTERY_CLIENT
+ bool zero_ac = false;
+
/*
- * When base is powering the system, make sure curr.ac stays 0.
+ * When base is powering the system, make sure ac stays 0.
* TODO(b:71723024): Fix extpower_is_present() in hardware instead.
*/
- if (base_responsive && prev_current_base < 0)
- curr.ac = 0;
+ if (base_responsive && prev_current_base < 0) {
+ ac = 0;
+ zero_ac = true;
+ }
/* System is off: if AC gets connected, reset the base. */
- if (chipset_in_state(CHIPSET_STATE_ANY_OFF) && !prev_ac && curr.ac)
+ if (chipset_in_state(CHIPSET_STATE_ANY_OFF) && !prev_ac && ac)
board_base_reset();
+
+ return zero_ac;
#endif
}
@@ -2084,8 +2096,10 @@ int calculate_sleep_dur(int battery_critical, int sleep_usec)
static void check_extpower(int chgnum)
{
curr.ac = extpower_is_present();
- if (IS_ENABLED(CONFIG_EC_EC_COMM_BATTERY_CLIENT))
- base_check_extpower();
+ if (IS_ENABLED(CONFIG_EC_EC_COMM_BATTERY_CLIENT)) {
+ if (base_check_extpower(curr.ac, prev_ac))
+ curr.ac = 0;
+ }
if (curr.ac != prev_ac)
process_ac_change(chgnum);