summaryrefslogtreecommitdiff
path: root/common/charge_state_v2.c
diff options
context:
space:
mode:
authorYuval Peress <peress@google.com>2022-11-08 03:14:01 -0700
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-11-08 18:59:14 +0000
commit31cf129cb7cb8ae61186ff276c7c68ded80660df (patch)
tree5b30d7a6aa80127c75417dfd5c7da815b87daf5b /common/charge_state_v2.c
parent9ab8139e10cac64e8f2c12ee75bcbf183fe4e294 (diff)
downloadchrome-ec-31cf129cb7cb8ae61186ff276c7c68ded80660df.tar.gz
test: verify common paths for charge_prevent_power_on
Check that pressing the power button and having enough charge will allow power-on, while having too little charge and going through the "auto-power-on" will not. This change required moving the static 'automatic_power_on' outside of the charge_prevent_power_on() function so it can be properly reset between tests. BRANCH=none BUG=none TEST=twister Signed-off-by: Yuval Peress <peress@google.com> Change-Id: Iff500728493ad8002fb1daf50845db85690a0a8d Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4011171 Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com> Reviewed-by: Al Semjonovs <asemjonovs@google.com> Commit-Queue: Al Semjonovs <asemjonovs@google.com>
Diffstat (limited to 'common/charge_state_v2.c')
-rw-r--r--common/charge_state_v2.c22
1 files changed, 12 insertions, 10 deletions
diff --git a/common/charge_state_v2.c b/common/charge_state_v2.c
index 54c49320c6..cd1b5988e2 100644
--- a/common/charge_state_v2.c
+++ b/common/charge_state_v2.c
@@ -2082,14 +2082,15 @@ int charge_want_shutdown(void)
(curr.batt.state_of_charge < battery_level_shutdown);
}
-int charge_prevent_power_on(int power_button_pressed)
+#ifdef CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON
+test_export_static int charge_prevent_power_on_automatic_power_on = 1;
+#endif
+
+bool charge_prevent_power_on(bool power_button_pressed)
{
int prevent_power_on = 0;
struct batt_params params;
struct batt_params *current_batt_params = &curr.batt;
-#ifdef CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON
- static int automatic_power_on = 1;
-#endif
/* If battery params seem uninitialized then retrieve them */
if (current_batt_params->is_present == BP_NOT_SURE) {
@@ -2104,7 +2105,7 @@ int charge_prevent_power_on(int power_button_pressed)
* power-ups are user-requested and non-automatic.
*/
if (power_button_pressed)
- automatic_power_on = 0;
+ charge_prevent_power_on_automatic_power_on = 0;
/*
* Require a minimum battery level to power on and ensure that the
* battery can provide power to the system.
@@ -2150,12 +2151,13 @@ int charge_prevent_power_on(int power_button_pressed)
* except when auto-power-on at EC startup and the battery
* is physically present.
*/
- prevent_power_on &=
- (system_is_locked() || (automatic_power_on
+ prevent_power_on &= (system_is_locked() ||
+ (charge_prevent_power_on_automatic_power_on
#ifdef CONFIG_BATTERY_HW_PRESENT_CUSTOM
- && battery_hw_present() == BP_YES
+
+ && battery_hw_present() == BP_YES
#endif
- ));
+ ));
#endif /* CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON */
#ifdef CONFIG_CHARGE_MANAGER
@@ -2189,7 +2191,7 @@ int charge_prevent_power_on(int power_button_pressed)
prevent_power_on = 1;
#endif /* CONFIG_SYSTEM_UNLOCKED */
- return prevent_power_on;
+ return prevent_power_on != 0;
}
static int battery_near_full(void)