summaryrefslogtreecommitdiff
path: root/board
diff options
context:
space:
mode:
authorBruce <Bruce.Wan@quantatw.com>2016-12-08 12:45:56 +0800
committerchrome-bot <chrome-bot@chromium.org>2016-12-08 16:38:36 -0800
commit80121352b0d37fe939bbb74ab05c23debb0525fb (patch)
tree555b5839e46bc43e52ba295fe55ba0971a9374d3 /board
parent0175c4b812b9eefd1bf4ff02e0f2f24f0632b0b8 (diff)
downloadchrome-ec-80121352b0d37fe939bbb74ab05c23debb0525fb.tar.gz
pyro/snappy: Disable keyboard and trackpad in tablet mode
(Original CL: https://chromium-review.googlesource.com/#/c/411395/) Enabling/Dislabling keyboard and touchpad is required to prevent EC from waking up the system from S3 in tablet mode. This change disables the keyboard and the trackpad when the lid goes beyond 180 degree. Keyboard and touchpad are also enabled/disabled by the tablet switch. When the lid reaches 360 position, keyboard and touchpad are disabled. And they stay disabled as long as the lid stays at 360 position. This prevents keyboard and touchpad from turning on by the (faulty) lid angle calculation. BUG=none BRANCH=none TEST=make buildall Change-Id: I919f44bae4a13aa4d9e6072e96e46bb90c08ec22 Signed-off-by: Bruce.Wan <Bruce.Wan@quantatw.com> Reviewed-on: https://chromium-review.googlesource.com/417643 Commit-Ready: Daisuke Nojiri <dnojiri@chromium.org> Tested-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Aaron Durbin <adurbin@chromium.org>
Diffstat (limited to 'board')
-rw-r--r--board/pyro/board.c44
-rw-r--r--board/pyro/board.h3
-rw-r--r--board/pyro/gpio.inc5
-rw-r--r--board/snappy/board.c44
-rw-r--r--board/snappy/board.h3
-rw-r--r--board/snappy/gpio.inc5
6 files changed, 70 insertions, 34 deletions
diff --git a/board/pyro/board.c b/board/pyro/board.c
index 759ff8fb54..dc239746eb 100644
--- a/board/pyro/board.c
+++ b/board/pyro/board.c
@@ -31,6 +31,7 @@
#include "host_command.h"
#include "i2c.h"
#include "keyboard_scan.h"
+#include "lid_angle.h"
#include "lid_switch.h"
#include "math_util.h"
#include "motion_sense.h"
@@ -42,6 +43,7 @@
#include "spi.h"
#include "switch.h"
#include "system.h"
+#include "tablet_mode.h"
#include "task.h"
#include "temp_sensor.h"
#include "thermistor.h"
@@ -104,9 +106,10 @@ void anx74xx_cable_det_interrupt(enum gpio_signal signal)
static void enable_input_devices(void);
DECLARE_DEFERRED(enable_input_devices);
+#define LID_DEBOUNCE_US (30 * MSEC) /* Debounce time for lid switch */
void tablet_mode_interrupt(enum gpio_signal signal)
{
- hook_call_deferred(&enable_input_devices_data, 0);
+ hook_call_deferred(&enable_input_devices_data, LID_DEBOUNCE_US);
}
#include "gpio_list.h"
@@ -490,8 +493,7 @@ DECLARE_HOOK(HOOK_CHIPSET_PRE_INIT, chipset_pre_init, HOOK_PRIO_DEFAULT);
/* Initialize board. */
static void board_init(void)
{
- /* FIXME: Handle tablet mode */
- /* gpio_enable_interrupt(GPIO_TABLET_MODE_L); */
+ gpio_enable_interrupt(GPIO_TABLET_MODE_L);
/* Enable charger interrupts */
gpio_enable_interrupt(GPIO_CHARGER_INT_L);
@@ -633,22 +635,36 @@ int board_is_vbus_too_low(enum chg_ramp_vbus_state ramp_state)
return charger_get_vbus_level() < BD9995X_BC12_MIN_VOLTAGE;
}
-/* Enable or disable input devices, based upon chipset state and tablet mode */
static void enable_input_devices(void)
{
- int kb_enable = 1;
- int tp_enable = 1;
-
- /* Disable KB & TP if chipset is off */
- if (chipset_in_state(CHIPSET_STATE_ANY_OFF)) {
- kb_enable = 0;
- tp_enable = 0;
- }
+ /* We need to turn on tablet mode for motion sense */
+ tablet_set_mode(!gpio_get_level(GPIO_TABLET_MODE_L));
- keyboard_scan_enable(kb_enable, KB_SCAN_DISABLE_LID_ANGLE);
+ /*
+ * Then, we disable peripherals only when the lid reaches 360 position.
+ * (It's probably already disabled by motion_sense_task.)
+ * We deliberately do not enable peripherals when the lid is leaving
+ * 360 position. Instead, we let motion_sense_task enable it once it
+ * reaches laptop zone (180 or less).
+ */
+ if (tablet_get_mode())
+ lid_angle_peripheral_enable(0);
+}
- gpio_set_level(GPIO_EN_P3300_TRACKPAD_ODL, !tp_enable);
+/* Enable or disable input devices, based on chipset state and tablet mode */
+#ifndef TEST_BUILD
+void lid_angle_peripheral_enable(int enable)
+{
+ /*
+ * If the lid is in 360 position, ignore the lid angle,
+ * which might be faulty. Disable keyboard and touchpad.
+ */
+ if (tablet_get_mode() || chipset_in_state(CHIPSET_STATE_ANY_OFF))
+ enable = 0;
+ keyboard_scan_enable(enable, KB_SCAN_DISABLE_LID_ANGLE);
+ gpio_set_level(GPIO_EN_P3300_TRACKPAD_ODL, !enable);
}
+#endif
/* Called on AP S5 -> S3 transition */
static void board_chipset_startup(void)
diff --git a/board/pyro/board.h b/board/pyro/board.h
index 4662aae1a6..b7c77a2ce2 100644
--- a/board/pyro/board.h
+++ b/board/pyro/board.h
@@ -75,6 +75,8 @@
#define GPIO_USB_ILIM_SEL GPIO_USB_A_CHARGE_EN_L
#define GPIO_USB_CTL1 GPIO_EN_PP5000
+#define CONFIG_TABLET_MODE
+
/* USB PD config */
#define CONFIG_CASE_CLOSED_DEBUG_EXTERNAL
#define CONFIG_CMD_PD_CONTROL
@@ -194,6 +196,7 @@
#define OPT3001_I2C_ADDR OPT3001_I2C_ADDR1
#define CONFIG_BARO_BMP280
#define CONFIG_LID_ANGLE
+#define CONFIG_LID_ANGLE_UPDATE
#define CONFIG_LID_ANGLE_SENSOR_BASE BASE_ACCEL
#define CONFIG_LID_ANGLE_SENSOR_LID LID_ACCEL
diff --git a/board/pyro/gpio.inc b/board/pyro/gpio.inc
index bd8aa788a3..e280955a52 100644
--- a/board/pyro/gpio.inc
+++ b/board/pyro/gpio.inc
@@ -32,14 +32,13 @@ GPIO_INT(POWER_BUTTON_L, PIN(0, 4), GPIO_INT_BOTH, power_button_interrupt) /* M
GPIO_INT(LID_OPEN, PIN(6, 7), GPIO_INT_BOTH, lid_interrupt)
GPIO_INT(EC_VOLDN_BTN_ODL, PIN(8, 3), GPIO_INT_BOTH | GPIO_PULL_UP, button_interrupt)
GPIO_INT(EC_VOLUP_BTN_ODL, PIN(8, 2), GPIO_INT_BOTH | GPIO_PULL_UP, button_interrupt)
-GPIO_INT(TABLET_MODE, PIN(3, 6), GPIO_INT_BOTH, tablet_mode_interrupt)
+/* Tablet switch is active-low. L: lid is attached (360 position) H: detached */
+GPIO_INT(TABLET_MODE_L, PIN(3, 6), GPIO_INT_BOTH, tablet_mode_interrupt)
GPIO_INT(WP_L, PIN(4, 0), GPIO_INT_BOTH | GPIO_SEL_1P8V, switch_interrupt) /* EC_WP_ODL */
-/* FIXME(dhendrix): Implement interrupt handlers for lid, tablet mode, etc. */
GPIO_INT(BASE_SIXAXIS_INT_L, PIN(9, 3), GPIO_INT_FALLING | GPIO_SEL_1P8V,
bmi160_interrupt)
-//GPIO_INT(LID_ACCEL_INT_L, PIN(C, 7), GPIO_INT_LOW | GPIO_SEL_1P8V, lid_interrupt)
GPIO(LID_ACCEL_INT_L, PIN(C, 7), GPIO_INPUT | GPIO_SEL_1P8V)
/* I2C GPIOs will be set to alt. function later. */
diff --git a/board/snappy/board.c b/board/snappy/board.c
index 3b473a5ce0..820572d8c4 100644
--- a/board/snappy/board.c
+++ b/board/snappy/board.c
@@ -31,6 +31,7 @@
#include "host_command.h"
#include "i2c.h"
#include "keyboard_scan.h"
+#include "lid_angle.h"
#include "lid_switch.h"
#include "math_util.h"
#include "motion_sense.h"
@@ -42,6 +43,7 @@
#include "spi.h"
#include "switch.h"
#include "system.h"
+#include "tablet_mode.h"
#include "task.h"
#include "temp_sensor.h"
#include "thermistor.h"
@@ -104,9 +106,10 @@ void anx74xx_cable_det_interrupt(enum gpio_signal signal)
static void enable_input_devices(void);
DECLARE_DEFERRED(enable_input_devices);
+#define LID_DEBOUNCE_US (30 * MSEC) /* Debounce time for lid switch */
void tablet_mode_interrupt(enum gpio_signal signal)
{
- hook_call_deferred(&enable_input_devices_data, 0);
+ hook_call_deferred(&enable_input_devices_data, LID_DEBOUNCE_US);
}
#include "gpio_list.h"
@@ -489,8 +492,7 @@ DECLARE_HOOK(HOOK_CHIPSET_PRE_INIT, chipset_pre_init, HOOK_PRIO_DEFAULT);
/* Initialize board. */
static void board_init(void)
{
- /* FIXME: Handle tablet mode */
- /* gpio_enable_interrupt(GPIO_TABLET_MODE_L); */
+ gpio_enable_interrupt(GPIO_TABLET_MODE_L);
/* Enable charger interrupts */
gpio_enable_interrupt(GPIO_CHARGER_INT_L);
@@ -632,22 +634,36 @@ int board_is_vbus_too_low(enum chg_ramp_vbus_state ramp_state)
return charger_get_vbus_level() < BD9995X_BC12_MIN_VOLTAGE;
}
-/* Enable or disable input devices, based upon chipset state and tablet mode */
static void enable_input_devices(void)
{
- int kb_enable = 1;
- int tp_enable = 1;
-
- /* Disable KB & TP if chipset is off */
- if (chipset_in_state(CHIPSET_STATE_ANY_OFF)) {
- kb_enable = 0;
- tp_enable = 0;
- }
+ /* We need to turn on tablet mode for motion sense */
+ tablet_set_mode(!gpio_get_level(GPIO_TABLET_MODE_L));
- keyboard_scan_enable(kb_enable, KB_SCAN_DISABLE_LID_ANGLE);
+ /*
+ * Then, we disable peripherals only when the lid reaches 360 position.
+ * (It's probably already disabled by motion_sense_task.)
+ * We deliberately do not enable peripherals when the lid is leaving
+ * 360 position. Instead, we let motion_sense_task enable it once it
+ * reaches laptop zone (180 or less).
+ */
+ if (tablet_get_mode())
+ lid_angle_peripheral_enable(0);
+}
- gpio_set_level(GPIO_EN_P3300_TRACKPAD_ODL, !tp_enable);
+/* Enable or disable input devices, based on chipset state and tablet mode */
+#ifndef TEST_BUILD
+void lid_angle_peripheral_enable(int enable)
+{
+ /*
+ * If the lid is in 360 position, ignore the lid angle,
+ * which might be faulty. Disable keyboard and touchpad.
+ */
+ if (tablet_get_mode() || chipset_in_state(CHIPSET_STATE_ANY_OFF))
+ enable = 0;
+ keyboard_scan_enable(enable, KB_SCAN_DISABLE_LID_ANGLE);
+ gpio_set_level(GPIO_EN_P3300_TRACKPAD_ODL, !enable);
}
+#endif
/* Called on AP S5 -> S3 transition */
static void board_chipset_startup(void)
diff --git a/board/snappy/board.h b/board/snappy/board.h
index 708f5635e9..29a044a44b 100644
--- a/board/snappy/board.h
+++ b/board/snappy/board.h
@@ -74,6 +74,8 @@
#define GPIO_USB_ILIM_SEL GPIO_USB_A_CHARGE_EN_L
#define GPIO_USB_CTL1 GPIO_EN_PP5000
+#define CONFIG_TABLET_MODE
+
/* USB PD config */
#define CONFIG_CASE_CLOSED_DEBUG_EXTERNAL
#define CONFIG_CMD_PD_CONTROL
@@ -193,6 +195,7 @@
#define OPT3001_I2C_ADDR OPT3001_I2C_ADDR1
#define CONFIG_BARO_BMP280
#define CONFIG_LID_ANGLE
+#define CONFIG_LID_ANGLE_UPDATE
#define CONFIG_LID_ANGLE_SENSOR_BASE BASE_ACCEL
#define CONFIG_LID_ANGLE_SENSOR_LID LID_ACCEL
diff --git a/board/snappy/gpio.inc b/board/snappy/gpio.inc
index 9797919d74..ffa246faab 100644
--- a/board/snappy/gpio.inc
+++ b/board/snappy/gpio.inc
@@ -32,14 +32,13 @@ GPIO_INT(POWER_BUTTON_L, PIN(0, 4), GPIO_INT_BOTH, power_button_interrupt) /* M
GPIO_INT(LID_OPEN, PIN(6, 7), GPIO_INT_BOTH, lid_interrupt)
GPIO_INT(EC_VOLDN_BTN_ODL, PIN(8, 3), GPIO_INT_BOTH | GPIO_PULL_UP, button_interrupt)
GPIO_INT(EC_VOLUP_BTN_ODL, PIN(8, 2), GPIO_INT_BOTH | GPIO_PULL_UP, button_interrupt)
-GPIO_INT(TABLET_MODE, PIN(3, 6), GPIO_INT_BOTH, tablet_mode_interrupt)
+/* Tablet switch is active-low. L: lid is attached (360 position) H: detached */
+GPIO_INT(TABLET_MODE_L, PIN(3, 6), GPIO_INT_BOTH, tablet_mode_interrupt)
GPIO_INT(WP_L, PIN(4, 0), GPIO_INT_BOTH | GPIO_SEL_1P8V, switch_interrupt) /* EC_WP_ODL */
-/* FIXME(dhendrix): Implement interrupt handlers for lid, tablet mode, etc. */
GPIO_INT(BASE_SIXAXIS_INT_L, PIN(9, 3), GPIO_INT_FALLING | GPIO_SEL_1P8V,
bmi160_interrupt)
-//GPIO_INT(LID_ACCEL_INT_L, PIN(C, 7), GPIO_INT_LOW | GPIO_SEL_1P8V, lid_interrupt)
GPIO(LID_ACCEL_INT_L, PIN(C, 7), GPIO_INPUT | GPIO_SEL_1P8V)
/* I2C GPIOs will be set to alt. function later. */