From 30353d0ae74f59dc407c297f507af80d35de0b10 Mon Sep 17 00:00:00 2001 From: Vic Yang Date: Sat, 27 Apr 2013 01:17:10 +0800 Subject: Add new TPS65090 charge state REINIT and BAD_COND Currently INIT state can mean different things. This change introduces two new states to demultiplex INIT. Now, REINIT means charge state machine is deciding the next state. BAD_COND means it's waiting for acceptable charging condition. Note that the three states are doing the same thing so there is no functional change. BUG=chrome-os-partner:18914 TEST=none BRANCH=spring CQ-DEPEND=CL:49430 Original-Change-Id: Ia783e76cf27e28103ef44fe7b8a43674dadccc54 Signed-off-by: Vic Yang Reviewed-on: https://gerrit.chromium.org/gerrit/49326 Reviewed-by: Vincent Palatin (cherry picked from commit 92bd863d8dcd1d006d39b9f95547af5c7347c254) Change-Id: I51a25fcf6350eb4d00bb93241545a58b0f821722 Signed-off-by: Vic Yang Reviewed-on: https://gerrit.chromium.org/gerrit/49429 --- common/pmu_tps65090_charger.c | 45 ++++++++++++++++++++++++------------------- include/pmu_tpschrome.h | 2 ++ 2 files changed, 27 insertions(+), 20 deletions(-) diff --git a/common/pmu_tps65090_charger.c b/common/pmu_tps65090_charger.c index e961fed066..db23c77dcf 100644 --- a/common/pmu_tps65090_charger.c +++ b/common/pmu_tps65090_charger.c @@ -48,6 +48,8 @@ static const char * const state_list[] = { "idle", + "reinit", + "bad cond", "pre-charging", "charging", "charging error", @@ -58,7 +60,7 @@ static const char * const state_list[] = { static timestamp_t last_waken; /* Initialized to 0 */ static int has_pending_event; -static enum charging_state current_state = ST_IDLE; +static enum charging_state current_state = ST_REINIT; static void enable_charging(int enable) { @@ -110,7 +112,7 @@ static int system_off(void) gpio_set_level(GPIO_EN_PP5000, 0); } - return ST_IDLE; + return ST_REINIT; } /* @@ -195,6 +197,8 @@ static int calc_next_state(int state) int batt_temp, alarm, capacity, charge; switch (state) { + case ST_REINIT: + case ST_BAD_COND: case ST_IDLE: /* Check AC and chiset state */ if (!board_get_ac()) { @@ -205,12 +209,12 @@ static int calc_next_state(int state) /* Stay in idle mode if charger overtemp */ if (pmu_is_charger_alarm()) - return ST_IDLE; + return ST_BAD_COND; /* Enable charging when battery doesn't respond */ if (battery_temperature(&batt_temp)) { if (config_low_current_charging(0)) - return ST_IDLE; + return ST_BAD_COND; return ST_PRE_CHARGING; } @@ -218,11 +222,11 @@ static int calc_next_state(int state) * of the start charging range. */ if (!battery_start_charging_range(batt_temp)) - return ST_IDLE; + return ST_BAD_COND; /* Turn off charger on battery charging alarm */ if (battery_status(&alarm) || (alarm & ALARM_CHARGING)) - return ST_IDLE; + return ST_BAD_COND; /* Start charging only when battery charge lower than 100% */ if (!battery_state_of_charge(&charge)) { @@ -235,18 +239,18 @@ static int calc_next_state(int state) case ST_PRE_CHARGING: if (!board_get_ac()) - return ST_IDLE; + return ST_REINIT; /* If the battery goes online after enable the charger, * go into charging state. */ if (battery_temperature(&batt_temp) == EC_SUCCESS) { if (!battery_start_charging_range(batt_temp)) - return ST_IDLE; + return ST_REINIT; if (!battery_state_of_charge(&charge)) { config_low_current_charging(charge); if (charge >= 100) - return ST_IDLE; + return ST_REINIT; } return ST_CHARGING; } @@ -256,7 +260,7 @@ static int calc_next_state(int state) case ST_CHARGING: /* Go back to idle state when AC is unplugged */ if (!board_get_ac()) - return ST_IDLE; + return ST_REINIT; /* * Disable charging on battery access error, or charging @@ -265,7 +269,7 @@ static int calc_next_state(int state) if (battery_temperature(&batt_temp)) { CPUTS("[pmu] charging: unable to get battery " "temperature\n"); - return ST_IDLE; + return ST_REINIT; } else if (!battery_charging_range(batt_temp)) { CPRINTF("[pmu] charging: temperature out of range " "%dC\n", @@ -279,13 +283,13 @@ static int calc_next_state(int state) * - over current */ if (battery_status(&alarm)) - return ST_IDLE; + return ST_REINIT; if (alarm & ALARM_CHARGING) { CPUTS("[pmu] charging: battery alarm\n"); if (alarm & ALARM_OVER_TEMP) return ST_CHARGING_ERROR; - return ST_IDLE; + return ST_REINIT; } /* @@ -295,7 +299,7 @@ static int calc_next_state(int state) */ if (pmu_is_charger_alarm()) { CPUTS("[pmu] charging: charger alarm\n"); - return ST_IDLE; + return ST_REINIT; } return ST_CHARGING; @@ -324,17 +328,17 @@ static int calc_next_state(int state) return ST_CHARGING; } - return ST_IDLE; + return ST_REINIT; case ST_DISCHARGING: /* Go back to idle state when AC is plugged */ if (board_get_ac()) - return ST_IDLE; + return ST_REINIT; /* Prepare EC sleep after system stopped discharging */ if (chipset_in_state(CHIPSET_STATE_ANY_OFF)) - return ST_IDLE; + return ST_REINIT; /* Check battery discharging temperature range */ if (battery_temperature(&batt_temp) == 0) { @@ -358,8 +362,7 @@ static int calc_next_state(int state) * Moving average is rounded to integer. */ if (rsoc_moving_average(capacity) < 3) { - system_off(); - return ST_IDLE; + return system_off(); } else if (capacity < 10) { notify_battery_low(); } @@ -368,7 +371,7 @@ static int calc_next_state(int state) return ST_DISCHARGING; } - return ST_IDLE; + return ST_REINIT; } /* TODO: Merge charge_state.h and unify charge interface */ @@ -473,6 +476,8 @@ void pmu_charger_task(void) enable_charging(1); break; case ST_IDLE: + case ST_REINIT: + case ST_BAD_COND: case ST_DISCHARGING: enable_charging(0); /* Ignore charger error when discharging */ diff --git a/include/pmu_tpschrome.h b/include/pmu_tpschrome.h index 57ba4c0a7e..71c78e0355 100644 --- a/include/pmu_tpschrome.h +++ b/include/pmu_tpschrome.h @@ -13,6 +13,8 @@ /* Non-SBS charging states */ enum charging_state { ST_IDLE, + ST_REINIT, + ST_BAD_COND, ST_PRE_CHARGING, ST_CHARGING, ST_CHARGING_ERROR, -- cgit v1.2.1