summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Hendricks <dhendrix@chromium.org>2012-07-02 14:36:58 -0700
committerGerrit <chrome-bot@google.com>2012-07-07 19:34:53 -0700
commitdef3a85e9e4c2843774db13a166a300e50a78315 (patch)
tree57ae2e1a9082255467c47cbb96b26203ac672a6a
parent41a55ba8acbdf9f1ba5cf22700260fe5d648b44c (diff)
downloadchrome-ec-def3a85e9e4c2843774db13a166a300e50a78315.tar.gz
gaia: add lid switch functionality to power states
This adds a small interrupt handler for lid open/close event which updates a state variable and wakes up the power task to decide if action must be taken. For the suspend mode path, it will determine which state to set the power LED in. BUG=chrome-os-partner:9708 TEST=Lid open turns on Snow, suspend mode to be tested separately Signed-off-by: David Hendricks <dhendrix@chromium.org> Change-Id: Ib8bb682affc5b9f6d729eb5f05d23098074e1a77 Reviewed-on: https://gerrit.chromium.org/gerrit/26647 Reviewed-by: David Hendricks <dhendrix@chromium.org> Tested-by: David Hendricks <dhendrix@chromium.org> Commit-Ready: David Hendricks <dhendrix@chromium.org>
-rw-r--r--common/gaia_power.c48
1 files changed, 40 insertions, 8 deletions
diff --git a/common/gaia_power.c b/common/gaia_power.c
index 6f392adf78..c0ae8cc8c6 100644
--- a/common/gaia_power.c
+++ b/common/gaia_power.c
@@ -72,6 +72,9 @@
/* debounce time to prevent accidental power-on after keyboard power off */
#define KB_PWR_ON_DEBOUNCE 250 /* 250us */
+/* debounce time to prevent accidental power event after lid open/close */
+#define LID_SWITCH_DEBOUNCE 250 /* 250us */
+
/* PMIC fails to set the LDO2 output */
#define PMIC_TIMEOUT 100000 /* 100ms */
@@ -90,6 +93,9 @@ static int force_value;
/* 1 if the power button was pressed last time we checked */
static char power_button_was_pressed;
+/* 1 if a change in lid switch state has been detected */
+static char lid_changed;
+
/* time where we will power off, if power button still held down */
static timestamp_t power_off_deadline;
@@ -189,8 +195,14 @@ void gaia_suspend_event(enum gpio_signal signal)
ap_suspended = !gpio_get_level(GPIO_SUSPEND_L);
- powerled_set_state(ap_suspended ?
- POWERLED_STATE_SUSPEND : POWERLED_STATE_ON);
+ if (ap_suspended) {
+ if (gpio_get_level(GPIO_LID_OPEN))
+ powerled_set_state(POWERLED_STATE_SUSPEND);
+ else
+ powerled_set_state(POWERLED_STATE_OFF);
+ } else {
+ powerled_set_state(POWERLED_STATE_ON);
+ }
}
void gaia_power_event(enum gpio_signal signal)
@@ -199,10 +211,18 @@ void gaia_power_event(enum gpio_signal signal)
task_wake(TASK_ID_GAIAPOWER);
}
+void gaia_lid_event(enum gpio_signal signal)
+{
+ /* inform power task that lid switch has changed */
+ lid_changed = 1;
+ task_wake(TASK_ID_GAIAPOWER);
+}
+
int gaia_power_init(void)
{
/* Enable interrupts for our GPIOs */
gpio_enable_interrupt(GPIO_KB_PWR_ON_L);
+ gpio_enable_interrupt(GPIO_LID_OPEN);
gpio_enable_interrupt(GPIO_PP1800_LDO2);
gpio_enable_interrupt(GPIO_SOC1V8_XPSHOLD);
@@ -245,8 +265,8 @@ void chipset_exit_hard_off(void)
/**
* Check if there has been a power-on event
*
- * This waits for the power button to be pressed, then returns whether it
- * is still pressed, after a debounce period
+ * This checks all power-on event signals and returns boolean 0 or 1 to
+ * indicate if any have been triggered (with debounce taken into account).
*
* @return 1 if there has been a power-on event, 0 if not
*/
@@ -262,11 +282,23 @@ static int check_for_power_on_event(void)
return 1;
}
- /* wait for Power button press */
- wait_in_signal(GPIO_KB_PWR_ON_L, 0, -1);
+ /* to avoid false positives, check lid only if a change was detected */
+ if (lid_changed) {
+ udelay(LID_SWITCH_DEBOUNCE);
+ if (gpio_get_level(GPIO_LID_OPEN) == 1) {
+ lid_changed = 0;
+ return 1;
+ }
+ }
+
+ /* check for power button press */
+ if (gpio_get_level(GPIO_KB_PWR_ON_L) == 0) {
+ udelay(KB_PWR_ON_DEBOUNCE);
+ if (gpio_get_level(GPIO_KB_PWR_ON_L) == 0)
+ return 1;
+ }
- udelay(KB_PWR_ON_DEBOUNCE);
- return gpio_get_level(GPIO_KB_PWR_ON_L) == 0;
+ return 0;
}
/**