summaryrefslogtreecommitdiff
path: root/common/charge_state_v2.c
diff options
context:
space:
mode:
authorDaisuke Nojiri <dnojiri@chromium.org>2021-05-28 12:08:03 -0700
committerCommit Bot <commit-bot@chromium.org>2021-07-16 15:16:30 +0000
commit0a8364fe0b5ffeaaf96a9aae1e4576cf7faedfdb (patch)
tree9709da827ac7f1d932e5f9437977643f315b73e2 /common/charge_state_v2.c
parent2c71fa9450c41b8ade2142c34753981cc358ea43 (diff)
downloadchrome-ec-0a8364fe0b5ffeaaf96a9aae1e4576cf7faedfdb.tar.gz
chgstv2: Move battery revival code to sub-routine
This patch moves battery revival code to revive_battery. It also uses IS_ENABLED to increase readability. There is no functional change. BUG=None BRANCH=None TEST=buildall Change-Id: I9c2689cdc3bcb843a5916f78c1f5e01948eff477 Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2929343 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Diffstat (limited to 'common/charge_state_v2.c')
-rw-r--r--common/charge_state_v2.c76
1 files changed, 36 insertions, 40 deletions
diff --git a/common/charge_state_v2.c b/common/charge_state_v2.c
index 6f1cc833c5..b4dccd1f35 100644
--- a/common/charge_state_v2.c
+++ b/common/charge_state_v2.c
@@ -1852,6 +1852,41 @@ static void wakeup_battery(int *need_static)
}
}
+static void revive_battery(int *need_static)
+{
+ if (IS_ENABLED(CONFIG_BATTERY_REQUESTS_NIL_WHEN_DEAD)
+ && curr.requested_voltage == 0
+ && curr.requested_current == 0
+ && curr.batt.state_of_charge == 0) {
+ /*
+ * Battery is dead, give precharge current
+ * TODO (crosbug.com/p/29467): remove this workaround
+ * for dead battery that requests no voltage/current
+ */
+ curr.requested_voltage = batt_info->voltage_max;
+ curr.requested_current = batt_info->precharge_current;
+ } else if (IS_ENABLED(CONFIG_BATTERY_REVIVE_DISCONNECT)
+ && curr.requested_voltage == 0
+ && curr.requested_current == 0
+ && battery_seems_disconnected) {
+ /*
+ * Battery is in disconnect state. Apply a
+ * current to kick it out of this state.
+ */
+ CPRINTS("found battery in disconnect state");
+ curr.requested_voltage = batt_info->voltage_max;
+ curr.requested_current = batt_info->precharge_current;
+ } else if (curr.state == ST_PRECHARGE
+ || battery_seems_dead || battery_was_removed) {
+ CPRINTS("battery woke up");
+ /* Update the battery-specific values */
+ batt_info = battery_get_info();
+ *need_static = 1;
+ }
+
+ battery_seems_dead = battery_was_removed = 0;
+}
+
/* Main loop */
void charger_task(void *u)
{
@@ -2078,47 +2113,8 @@ void charger_task(void *u)
battery_seems_disconnected =
battery_get_disconnect_state() == BATTERY_DISCONNECTED;
-#ifdef CONFIG_BATTERY_REQUESTS_NIL_WHEN_DEAD
- /*
- * TODO (crosbug.com/p/29467): remove this workaround
- * for dead battery that requests no voltage/current
- */
- if (curr.requested_voltage == 0 &&
- curr.requested_current == 0 &&
- curr.batt.state_of_charge == 0) {
- /* Battery is dead, give precharge current */
- curr.requested_voltage =
- batt_info->voltage_max;
- curr.requested_current =
- batt_info->precharge_current;
- } else
-#endif
-#ifdef CONFIG_BATTERY_REVIVE_DISCONNECT
- if (curr.requested_voltage == 0 &&
- curr.requested_current == 0 &&
- battery_seems_disconnected) {
- /*
- * Battery is in disconnect state. Apply a
- * current to kick it out of this state.
- */
- CPRINTS("found battery in disconnect state");
- curr.requested_voltage =
- batt_info->voltage_max;
- curr.requested_current =
- batt_info->precharge_current;
- } else
-#endif
- if (curr.state == ST_PRECHARGE ||
- battery_seems_dead ||
- battery_was_removed) {
- CPRINTS("battery woke up");
-
- /* Update the battery-specific values */
- batt_info = battery_get_info();
- need_static = 1;
- }
+ revive_battery(&need_static);
- battery_seems_dead = battery_was_removed = 0;
set_charge_state(ST_CHARGE);
wait_for_it: