chgstv2: Move code waking up battery to sub-routine
This patch moves the code waking up a battery to wakeup_battery.
There is no functionality change.
BRANCH=None
TEST=buildall
@@ -1823,6 +1823,35 @@ static int get_desired_input_current(enum battery_present batt_present,
}
}
+static void wakeup_battery(int *need_static)
+{
+ if (battery_seems_to_be_dead || battery_is_cut_off()) {
+ /* It's dead, do nothing */
+ set_charge_state(ST_IDLE);
+ curr.requested_voltage = 0;
+ curr.requested_current = 0;
+ } else if (curr.state == ST_PRECHARGE
+ && (get_time().val > precharge_start_time.val +
+ PRECHARGE_TIMEOUT_US)) {
+ /* We've tried long enough, give up */
+ CPRINTS("battery seems to be dead");
+ battery_seems_to_be_dead = 1;
+ set_charge_state(ST_IDLE);
+ curr.requested_voltage = 0;
+ curr.requested_current = 0;
+ } else {
+ /* See if we can wake it up */
+ if (curr.state != ST_PRECHARGE) {
+ CPRINTS("try to wake battery");
+ precharge_start_time = get_time();
+ *need_static = 1;
+ }
+ set_charge_state(ST_PRECHARGE);
+ curr.requested_voltage = batt_info->voltage_max;
+ curr.requested_current = batt_info->precharge_current;
+ }
+}
+
/* Main loop */
void charger_task(void *u)
{
@@ -2035,35 +2064,10 @@ void charger_task(void *u)
/* If the battery is not responsive, try to wake it up. */
if (!(curr.batt.flags & BATT_FLAG_RESPONSIVE)) {
- if (battery_seems_to_be_dead || battery_is_cut_off()) {
- /* It's dead, do nothing */
- set_charge_state(ST_IDLE);
- curr.requested_voltage = 0;
- curr.requested_current = 0;
- } else if (curr.state == ST_PRECHARGE &&
- (get_time().val > precharge_start_time.val +
- PRECHARGE_TIMEOUT_US)) {
- /* We've tried long enough, give up */
- CPRINTS("battery seems to be dead");
- battery_seems_to_be_dead = 1;
- set_charge_state(ST_IDLE);
- curr.requested_voltage = 0;
- curr.requested_current = 0;
- } else {
- /* See if we can wake it up */
- if (curr.state != ST_PRECHARGE) {
- CPRINTS("try to wake battery");
- precharge_start_time = get_time();
- need_static = 1;
- }
- set_charge_state(ST_PRECHARGE);
- curr.requested_voltage =
- batt_info->voltage_max;
- curr.requested_current =
- batt_info->precharge_current;
- }
+ wakeup_battery(&need_static);
goto wait_for_it;
- } else {
+ }
+
/* The battery is responding. Yay. Try to use it. */
#ifdef CONFIG_BATTERY_REQUESTS_NIL_WHEN_DEAD
/*
@@ -2116,7 +2120,6 @@ void charger_task(void *u)
battery_seems_to_be_dead = battery_was_removed = 0;
set_charge_state(ST_CHARGE);
- }
wait_for_it:
if (IS_ENABLED(CONFIG_CHARGER_PROFILE_OVERRIDE)
