diff options
author | Simon Glass <sjg@chromium.org> | 2012-07-17 09:44:42 +0100 |
---|---|---|
committer | Gerrit <chrome-bot@google.com> | 2012-07-17 23:14:11 -0700 |
commit | 73b042f3dce25f471003a459b72ba727b0d90181 (patch) | |
tree | 8f66ba9f02137e84cb00c58db5f41aff9fc216cc | |
parent | 698ae9f5ad77325de6c694391eb35202a10b8e69 (diff) | |
download | chrome-ec-73b042f3dce25f471003a459b72ba727b0d90181.tar.gz |
gaia_power: Allow AP power to be controlled
Enhance the power command to support turning power on/off.
Do this by requesting the state of the main power control loop,
rather than hacking in new states or flags.
BUG=chrome-os-partner:11427
TEST=manual
Try 'power on' and 'power off' and see that it obeys.
Change-Id: Ie6db41dda16176818510f8902ab803e165494424
Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/27654
Reviewed-by: David Hendricks <dhendrix@chromium.org>
-rw-r--r-- | common/gaia_power.c | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/common/gaia_power.c b/common/gaia_power.c index c8d439946b..7f4b4eb474 100644 --- a/common/gaia_power.c +++ b/common/gaia_power.c @@ -108,6 +108,16 @@ static timestamp_t pwron_deadline; /* force AP power on (used for recovery keypress) */ static int auto_power_on; +enum power_request_t { + POWER_REQ_NONE, + POWER_REQ_OFF, + POWER_REQ_ON, + + POWER_REQ_COUNT, +}; + +static enum power_request_t power_request; + /* * Wait for GPIO "signal" to reach level "value". * Returns EC_ERROR_TIMEOUT if timeout before reaching the desired state. @@ -185,6 +195,12 @@ static int check_for_power_off_event(void) /* XPSHOLD released by AP : shutdown immediately */ if (pwron_released && gpio_get_level(GPIO_SOC1V8_XPSHOLD) == 0) return 3; + + if (power_request == POWER_REQ_OFF) { + power_request = POWER_REQ_NONE; + return 4; + } + return 0; } @@ -305,6 +321,11 @@ static int check_for_power_on_event(void) return 1; } + if (power_request == POWER_REQ_ON) { + power_request = POWER_REQ_NONE; + return 4; + } + return 0; } @@ -480,6 +501,12 @@ DECLARE_CONSOLE_COMMAND(forcepower, command_force_power, "Force power on", NULL); +static const char *power_req_name[POWER_REQ_COUNT] = { + "none", + "off", + "on", +}; + /* Power states that we can report */ enum power_state_t { PSTATE_UNKNOWN, @@ -514,10 +541,18 @@ static int command_power(int argc, char **argv) return EC_SUCCESS; } + if (0 == strcasecmp(argv[1], "on")) + power_request = POWER_REQ_ON; + else if (0 == strcasecmp(argv[1], "off")) + power_request = POWER_REQ_OFF; + + ccprintf("Requesting power %s\n", power_req_name[power_request]); + task_wake(TASK_ID_GAIAPOWER); + ccputs("Invalid args\n"); return EC_ERROR_INVAL; } DECLARE_CONSOLE_COMMAND(power, command_power, - NULL, - "Check AP power state", + "on/off", + "Turn AP power on/off", NULL); |