diff options
author | Randall Spangler <rspangler@chromium.org> | 2013-03-14 16:17:18 -0700 |
---|---|---|
committer | ChromeBot <chrome-bot@google.com> | 2013-03-15 09:07:58 -0700 |
commit | 05f496759f3e8f87940d3f4f78ffee53b249f3f0 (patch) | |
tree | c435d86ef6106da4a72df0239a2e557781113c60 | |
parent | 744cada9d5a2edacf462c15febfc31fbf7f64a12 (diff) | |
download | chrome-ec-05f496759f3e8f87940d3f4f78ffee53b249f3f0.tar.gz |
Add external power present flag to charge_get_flags()
Modules that need to find out about charge/power state no longer need
to use the lower-level switch API.
(This will matter more in future CLs which handle conditions like
"external power present, but at low power so we're doing battery
assist" - that can simply be state=discharging,flags=external_power_present.
BUG=chrome-os-partner:18256
BRANCH=none
TEST=add AC power, UI shows charging indicator; remove AC, indicator goes away
Change-Id: I62130a4e089297fa47ab03f6a76082593c936761
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/45515
Reviewed-by: Vic Yang <victoryang@chromium.org>
-rw-r--r-- | common/charge_state.c | 10 | ||||
-rw-r--r-- | common/onewire_led.c | 7 | ||||
-rw-r--r-- | include/charge_state.h | 2 |
3 files changed, 14 insertions, 5 deletions
diff --git a/common/charge_state.c b/common/charge_state.c index 8c93595d15..808a93e477 100644 --- a/common/charge_state.c +++ b/common/charge_state.c @@ -144,7 +144,7 @@ static int state_common(struct power_state_context *ctx) curr->error = 0; /* Detect AC change */ - curr->ac = switch_get_ac_present(); + curr->ac = charge_get_flags() & CHARGE_FLAG_EXTERNAL_POWER; if (curr->ac != prev->ac) { if (curr->ac) { /* AC on @@ -579,6 +579,8 @@ uint32_t charge_get_flags(void) if (state_machine_force_idle) flags |= CHARGE_FLAG_FORCE_IDLE; + if (switch_get_ac_present()) + flags |= CHARGE_FLAG_EXTERNAL_POWER; return flags; } @@ -596,7 +598,11 @@ int charge_want_shutdown(void) static int enter_force_idle_mode(void) { - if (!switch_get_ac_present()) + /* + * Force-idle state is only meaningful if external power is present. + * If it's not present we can't charge anyway... + */ + if (!(charge_get_flags() & CHARGE_FLAG_EXTERNAL_POWER)) return EC_ERROR_UNKNOWN; state_machine_force_idle = 1; charger_post_init(); diff --git a/common/onewire_led.c b/common/onewire_led.c index 25af303421..07f4e73741 100644 --- a/common/onewire_led.c +++ b/common/onewire_led.c @@ -9,7 +9,6 @@ #include "console.h" #include "hooks.h" #include "onewire.h" -#include "switch.h" #include "timer.h" #include "util.h" @@ -95,11 +94,13 @@ static void powerled_tick(void) { static enum powerled_color current_color = POWERLED_COLOR_COUNT; static int tick_count; + enum powerled_color new_color = POWERLED_OFF; + uint32_t chflags = charge_get_flags(); tick_count++; - if (!switch_get_ac_present()) { + if (!(chflags & CHARGE_FLAG_EXTERNAL_POWER)) { /* AC isn't present, so the power LED on the AC plug is off */ current_color = POWERLED_OFF; return; @@ -108,7 +109,7 @@ static void powerled_tick(void) /* Translate charge state to LED color */ switch (charge_get_state()) { case PWR_STATE_IDLE: - if (charge_get_flags() & CHARGE_FLAG_FORCE_IDLE) + if (chflags & CHARGE_FLAG_FORCE_IDLE) new_color = ((tick_count & 1) ? POWERLED_GREEN : POWERLED_OFF); else diff --git a/include/charge_state.h b/include/charge_state.h index bf6404593e..e55a7c529c 100644 --- a/include/charge_state.h +++ b/include/charge_state.h @@ -65,6 +65,8 @@ enum power_state { /* Charge state flags */ /* Forcing idle state */ #define CHARGE_FLAG_FORCE_IDLE (1 << 0) +/* External (AC) power is present */ +#define CHARGE_FLAG_EXTERNAL_POWER (1 << 1) /* Debugging constants, in the same order as enum power_state. This string * table was moved here to sync with enum above. |