mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2026-01-07 16:11:43 +00:00
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>
This commit is contained in:
committed by
ChromeBot
parent
744cada9d5
commit
05f496759f
@@ -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();
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user