summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRandall Spangler <rspangler@chromium.org>2012-10-12 11:19:58 -0700
committerRong Chang <rongchang@chromium.org>2012-10-16 01:01:04 -0700
commit4e01894a53b62428df08c24302412566408eac5a (patch)
tree7c0fd10a4c30370ec73013455cb442679c9ba971
parent491649b344b8f6af7d156084947958476490ce5a (diff)
downloadchrome-ec-4e01894a53b62428df08c24302412566408eac5a.tar.gz
link: Ignore keyboard when lid is closed
The lid is flexible enough that it's possible to press keys by squeezing the laptop. To keep this from waking the device from suspend or powering it on, don't scan the keyboard or power button when the lid is closed. BUG=chrome-os-partner:15252 BRANCH=link TEST=manual - boot system - use a magnet near the search key to trigger the lid-closed switch - press space, then power. neither one should trigger resume - remove magnet. system resumes - space and power should work as expected again - log out - use magnet to trigger lid-closed switch (looking at EC console output is handy here). system should shut down - pressing power should not boot the system - remove magnet; system will boot - pressing power should work as expected again Original-Change-Id: I92080237b0a2f21774301df3d8e866878697b793 Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/35425 Reviewed-by: Bill Richardson <wfrichar@chromium.org> (cherry picked from commit 8c742b2fc33a7182034fad6166a4953b79161052) Change-Id: I4bebaa77e83e718e5911a60f4d4296fcbd5e6952 Reviewed-on: https://gerrit.chromium.org/gerrit/35676 Reviewed-by: Rong Chang <rongchang@chromium.org> Tested-by: Rong Chang <rongchang@chromium.org>
-rw-r--r--chip/lm4/keyboard_scan.c14
-rw-r--r--chip/lm4/power_button.c28
2 files changed, 28 insertions, 14 deletions
diff --git a/chip/lm4/keyboard_scan.c b/chip/lm4/keyboard_scan.c
index 33c894e8c1..ef7dfd6b94 100644
--- a/chip/lm4/keyboard_scan.c
+++ b/chip/lm4/keyboard_scan.c
@@ -102,6 +102,12 @@ static void enter_polling_mode(void)
lm4_select_column(COLUMN_TRI_STATE_ALL);
}
+static int is_scanning_enabled(void)
+{
+ /* Scan only if enabled AND lid is open. */
+ return lm4_get_scanning_enabled() && power_lid_open_debounced();
+}
+
/**
* Read the raw keyboard matrix state.
*
@@ -311,7 +317,7 @@ static int check_keys_changed(uint8_t *state)
any_change = 1;
/* Inform keyboard module if scanning is enabled */
- if (lm4_get_scanning_enabled())
+ if (is_scanning_enabled())
keyboard_state_changed(i, c, new_mask ? 1 : 0);
}
}
@@ -453,13 +459,13 @@ void keyboard_scan_task(void)
* starting to pay attention to edges.
*/
if ((lm4_read_raw_row_state() == 0xff) ||
- !lm4_get_scanning_enabled())
+ !is_scanning_enabled())
task_wait_event(-1);
- } while (!lm4_get_scanning_enabled());
+ } while (!is_scanning_enabled());
enter_polling_mode();
/* Busy polling keyboard state. */
- while (lm4_get_scanning_enabled()) {
+ while (is_scanning_enabled()) {
/* Check for keys down */
if (check_keys_changed(debounced_state)) {
key_press_timer = 0;
diff --git a/chip/lm4/power_button.c b/chip/lm4/power_button.c
index 3407d7e701..a928f4895b 100644
--- a/chip/lm4/power_button.c
+++ b/chip/lm4/power_button.c
@@ -130,25 +130,33 @@ static void set_pwrbtn_to_pch(int high)
gpio_set_level(GPIO_PCH_PWRBTNn, high);
}
+/**
+ * Get raw lid switch state.
+ *
+ * @return 1 if lid is open, 0 if closed.
+ */
+static int get_lid_open(void)
+{
+ return gpio_get_level(GPIO_LID_SWITCHn) ? 1 : 0;
+}
-/* Get raw power button signal state; 1 if power button is pressed, 0 if not
- * pressed. */
+/**
+ * Get raw power button signal state.
+ *
+ * @return 1 if power button is pressed, 0 if not pressed.
+ */
static int get_power_button_pressed(void)
{
if (simulate_power_pressed)
return 1;
- return gpio_get_level(GPIO_POWER_BUTTONn) ? 0 : 1;
-}
+ /* Ignore power button if lid is closed */
+ if (!get_lid_open())
+ return 0;
-
-/* Get raw lid switch state; 1 if lid is open, 0 if closed. */
-static int get_lid_open(void)
-{
- return gpio_get_level(GPIO_LID_SWITCHn) ? 1 : 0;
+ return gpio_get_level(GPIO_POWER_BUTTONn) ? 0 : 1;
}
-
static void update_backlight(void)
{
/* Only enable the backlight if the lid is open */