summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/charge_state.c10
-rw-r--r--common/onewire_led.c7
-rw-r--r--include/charge_state.h2
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.