summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2023-05-03 11:01:54 -0600
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2023-05-05 15:15:33 +0000
commit4896dd44bc8601d132ee4777f8a7afddbffbcd3e (patch)
tree01dc783a366b53472aac2a6e07b1f8e653ef36d1
parentd056bd5a65d3247bc1ff64cd0024eddcefce2db8 (diff)
downloadchrome-ec-4896dd44bc8601d132ee4777f8a7afddbffbcd3e.tar.gz
charger: Move base-external-power check into a function
Move this into a function to shorten the main loop and avoid an #ifdef in it. Use a condition check to call the function so that it is clear that it relates to the base. Unfortunately we still need the #ifdef in the function due to the base_responsive variable. This makes no functional change. BUG=b:218332694 TEST=zmake build dev-posix Change-Id: Ia2c689d5800daff43870dc017defa174f93ea38f Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4501287 Reviewed-by: Aaron Massey <aaronmassey@google.com> Commit-Queue: Simon Glass <sjg@chromium.org> Tested-by: Simon Glass <sjg@chromium.org>
-rw-r--r--common/charge_state_v2.c34
1 files changed, 20 insertions, 14 deletions
diff --git a/common/charge_state_v2.c b/common/charge_state_v2.c
index c0139748a0..1dcd046078 100644
--- a/common/charge_state_v2.c
+++ b/common/charge_state_v2.c
@@ -1680,6 +1680,24 @@ 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)
+{
+ /* This #ifdef protects access to vars that are otherwise unavailable */
+#ifdef CONFIG_EC_EC_COMM_BATTERY_CLIENT
+ /*
+ * When base is powering the system, make sure curr.ac stays 0.
+ * TODO(b:71723024): Fix extpower_is_present() in hardware instead.
+ */
+ if (base_responsive && prev_current_base < 0)
+ curr.ac = 0;
+
+ /* System is off: if AC gets connected, reset the base. */
+ if (chipset_in_state(CHIPSET_STATE_ANY_OFF) && !prev_ac && curr.ac)
+ board_base_reset();
+#endif
+}
+
/* Main loop */
void charger_task(void *u)
{
@@ -1700,20 +1718,8 @@ void charger_task(void *u)
problems_exist = 0;
battery_critical = 0;
curr.ac = extpower_is_present();
-#ifdef CONFIG_EC_EC_COMM_BATTERY_CLIENT
- /*
- * When base is powering the system, make sure curr.ac stays 0.
- * TODO(b:71723024): Fix extpower_is_present() in hardware
- * instead.
- */
- if (base_responsive && prev_current_base < 0)
- curr.ac = 0;
-
- /* System is off: if AC gets connected, reset the base. */
- if (chipset_in_state(CHIPSET_STATE_ANY_OFF) && !prev_ac &&
- curr.ac)
- board_base_reset();
-#endif
+ 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