diff options
-rw-r--r-- | common/battery_precharge.c | 6 | ||||
-rw-r--r-- | common/charge_state.c | 50 | ||||
-rw-r--r-- | include/charge_state.h | 2 |
3 files changed, 28 insertions, 30 deletions
diff --git a/common/battery_precharge.c b/common/battery_precharge.c index 4109fcc6e3..22c60d878f 100644 --- a/common/battery_precharge.c +++ b/common/battery_precharge.c @@ -9,7 +9,6 @@ #include "battery_pack.h" #include "charge_state.h" #include "charger.h" -#include "power_led.h" #include "smart_battery.h" #include "timer.h" #include "uart.h" @@ -101,11 +100,6 @@ enum power_state trickle_charge(struct power_state_context *ctx) const struct charger_info *cinfo = ctx->charger; const struct battery_info *binfo = ctx->battery; - /* If battery is nearly full and we are trickle charging, we should - * change the power led to green. */ - if (batt->state_of_charge >= POWERLED_GREEN_THRESHOLD) - curr->led_color = POWERLED_GREEN; - /* Clear trickle charging duration on AC change */ if (curr->ac != ctx->prev.ac) { ctx->trickle_charging_time.val = 0; diff --git a/common/charge_state.c b/common/charge_state.c index 177eaeedba..130f2a8d3a 100644 --- a/common/charge_state.c +++ b/common/charge_state.c @@ -280,9 +280,6 @@ static int state_common(struct power_state_context *ctx) */ static enum power_state state_init(struct power_state_context *ctx) { - /* Set LED to green first, other states should change it as desired. */ - ctx->curr.led_color = POWERLED_GREEN; - /* Stop charger, unconditionally */ charger_set_current(0); charger_set_voltage(0); @@ -315,14 +312,8 @@ static enum power_state state_idle(struct power_state_context *ctx) const struct charger_info *c_info = ctx->charger; /* If we are forcing idle mode, then just stay in IDLE. */ - if (state_machine_force_idle) { - if (ctx->prev.led_color == POWERLED_GREEN) - ctx->curr.led_color = POWERLED_OFF; - else - ctx->curr.led_color = POWERLED_GREEN; + if (state_machine_force_idle) return PWR_STATE_UNCHANGE; - } - ctx->curr.led_color = POWERLED_GREEN; if (!ctx->curr.ac) return PWR_STATE_INIT; @@ -373,8 +364,6 @@ static enum power_state state_charge(struct power_state_context *ctx) int debounce = 0; timestamp_t now; - curr->led_color = POWERLED_YELLOW; - if (curr->error) return PWR_STATE_ERROR; @@ -434,9 +423,6 @@ static enum power_state state_charge(struct power_state_context *ctx) static enum power_state state_discharge(struct power_state_context *ctx) { struct batt_params *batt = &ctx->curr.batt; - - ctx->curr.led_color = POWERLED_OFF; - if (ctx->curr.ac) return PWR_STATE_INIT; @@ -462,8 +448,6 @@ static enum power_state state_error(struct power_state_context *ctx) { static int logged_error; - ctx->curr.led_color = POWERLED_RED; - if (!ctx->curr.error) { logged_error = 0; return PWR_STATE_INIT; @@ -544,6 +528,16 @@ static int exit_force_idle_mode(void) return EC_SUCCESS; } +static enum powerled_color force_idle_led_blink(void) +{ + static enum powerled_color last = POWERLED_GREEN; + if (last == POWERLED_GREEN) + last = POWERLED_OFF; + else + last = POWERLED_GREEN; + return last; +} + /* Battery charging task */ void charge_state_machine_task(void) { @@ -552,12 +546,11 @@ void charge_state_machine_task(void) int sleep_usec = POLL_PERIOD_SHORT, diff_usec, sleep_next; enum power_state new_state; uint8_t batt_flags; + enum powerled_color led_color = POWERLED_OFF; int rv_setled = 0; ctx->prev.state = PWR_STATE_INIT; ctx->curr.state = PWR_STATE_INIT; - ctx->prev.led_color = POWERLED_OFF; - ctx->curr.led_color = POWERLED_OFF; ctx->trickle_charging_time.val = 0; ctx->battery = battery_get_info(); ctx->charger = charger_get_info(); @@ -610,9 +603,6 @@ void charge_state_machine_task(void) state_name[new_state]); } - if ((ctx->curr.led_color != ctx->prev.led_color || rv_setled) && - new_state != PWR_STATE_DISCHARGE) - rv_setled = powerled_set(ctx->curr.led_color); switch (new_state) { case PWR_STATE_IDLE: @@ -621,6 +611,10 @@ void charge_state_machine_task(void) batt_flags &= ~EC_BATT_FLAG_DISCHARGING; *ctx->memmap_batt_flags = batt_flags; + /* Charge done */ + led_color = POWERLED_GREEN; + rv_setled = powerled_set(POWERLED_GREEN); + sleep_usec = POLL_PERIOD_LONG; break; case PWR_STATE_DISCHARGE: @@ -636,13 +630,25 @@ void charge_state_machine_task(void) batt_flags &= ~EC_BATT_FLAG_DISCHARGING; *ctx->memmap_batt_flags = batt_flags; + /* Charging */ + led_color = POWERLED_YELLOW; + rv_setled = powerled_set(POWERLED_YELLOW); + sleep_usec = POLL_PERIOD_CHARGE; break; case PWR_STATE_ERROR: + /* Error */ + led_color = POWERLED_RED; + rv_setled = powerled_set(POWERLED_RED); + sleep_usec = POLL_PERIOD_CHARGE; break; case PWR_STATE_UNCHANGE: /* Don't change sleep duration */ + if (state_machine_force_idle) + powerled_set(force_idle_led_blink()); + else if (rv_setled) + rv_setled = powerled_set(led_color); break; default: /* Other state; poll quickly and hope it goes away */ diff --git a/include/charge_state.h b/include/charge_state.h index 277525ac4c..d5c80ff0e0 100644 --- a/include/charge_state.h +++ b/include/charge_state.h @@ -4,7 +4,6 @@ * */ -#include "power_led.h" #include "timer.h" #ifndef __CROS_EC_CHARGE_STATE_H @@ -81,7 +80,6 @@ struct power_state_data { enum power_state state; uint32_t error; timestamp_t ts; - enum powerled_color led_color; }; /* State context |