diff --git a/board/kevin/board.h b/board/kevin/board.h index a6e152b512..d249ed3764 100644 --- a/board/kevin/board.h +++ b/board/kevin/board.h @@ -184,6 +184,7 @@ /* Modules we want to exclude */ #undef CONFIG_CMD_BATTFAKE +#undef CONFIG_CMD_CRASH #undef CONFIG_CMD_FLASH #undef CONFIG_CMD_HASH #undef CONFIG_CMD_HCDEBUG diff --git a/board/nami/board.h b/board/nami/board.h index c15295ff21..8b9d4b33f1 100644 --- a/board/nami/board.h +++ b/board/nami/board.h @@ -140,6 +140,8 @@ #define CONFIG_TABLET_MODE #define CONFIG_TABLET_MODE_SWITCH +#define CONFIG_TABLET_SWITCH +#define TABLET_MODE_GPIO_L GPIO_TABLET_MODE_L /* USB */ #define CONFIG_USB_CHARGER diff --git a/board/nami/gpio.inc b/board/nami/gpio.inc index c12db6dceb..586c776de0 100644 --- a/board/nami/gpio.inc +++ b/board/nami/gpio.inc @@ -34,11 +34,11 @@ GPIO_INT(USB_C1_VBUS_WAKE_L, PIN(C, 5), GPIO_INT_BOTH | GPIO_PULL_UP,vbus1_evt) GPIO_INT(USB_C0_BC12_INT_L, PIN(D, 2), GPIO_INT_FALLING, usb0_evt) GPIO_INT(USB_C1_BC12_INT_L, PIN(D, 3), GPIO_INT_FALLING, usb1_evt) GPIO_INT(ACCELGYRO3_INT_L, PIN(3, 6), GPIO_INT_FALLING | GPIO_SEL_1P8V, bmi160_interrupt) +GPIO_INT(TABLET_MODE_L, PIN(7, 2), GPIO_INT_BOTH, tablet_mode_isr) /* Used to wake up system from deep S3. */ /* GPIO_INT(TP_INT_CONN, PIN(4, 2), GPIO_INT_BOTH, trackpad_connect) dnojiri: Revisit */ /* GPIO_INT(ALS_INT, PIN(3, 2),,) dnojiri: Revisit */ /* GPIO_INT(3AXIS_INT, PIN(9, 5),,) dnojiri: Revisit */ -/* GPIO_INT(TABLET_MODE_L, PIN(7, 2), GPIO_INT_BOTH, tablet_mode_interrupt) dnojiri: Revisit */ GPIO(ENABLE_BACKLIGHT_L, PIN(6, 7), GPIO_OUT_LOW) /* LCD backlight */ GPIO(PP3300_DX_WLAN, PIN(B, 1), GPIO_OUT_LOW) /* Enable WLAN 3.3V Power */ diff --git a/common/tablet_mode.c b/common/tablet_mode.c index 4a9a0b2364..d73140c4bf 100644 --- a/common/tablet_mode.c +++ b/common/tablet_mode.c @@ -3,9 +3,17 @@ * found in the LICENSE file. */ +#include "console.h" +#include "gpio.h" #include "hooks.h" +#include "lid_angle.h" +#include "tablet_mode.h" +#include "timer.h" -/* Return 1 if in tablet mode, 0 otherwise */ +#define CPRINTS(format, args...) cprints(CC_MOTION_LID, format, ## args) +#define CPRINTF(format, args...) cprintf(CC_MOTION_LID, format, ## args) + +/* 1: in tablet mode. 0: otherwise */ static int tablet_mode = 1; int tablet_get_mode(void) @@ -15,9 +23,47 @@ int tablet_get_mode(void) void tablet_set_mode(int mode) { - if (tablet_mode != mode) { - tablet_mode = mode; - hook_notify(HOOK_TABLET_MODE_CHANGE); - } + if (tablet_mode == mode) + return; + + tablet_mode = mode; + CPRINTS("tablet mode %sabled\n", mode ? "en" : "dis"); + hook_notify(HOOK_TABLET_MODE_CHANGE); } +/* This ifdef can be removed once we clean up past projects which do own init */ +#ifdef CONFIG_TABLET_SWITCH +#ifndef TABLET_MODE_GPIO_L +#error TABLET_MODE_GPIO_L must be defined +#endif +static void tablet_mode_debounce(void) +{ + /* We won't reach here on boards without a dedicated tablet switch */ + tablet_set_mode(!gpio_get_level(TABLET_MODE_GPIO_L)); + + /* 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_mode) + lid_angle_peripheral_enable(0); +} +DECLARE_DEFERRED(tablet_mode_debounce); + +#define TABLET_DEBOUNCE_US (30 * MSEC) /* Debounce time for tablet switch */ + +void tablet_mode_isr(enum gpio_signal signal) +{ + hook_call_deferred(&tablet_mode_debounce_data, TABLET_DEBOUNCE_US); +} + +static void tablet_mode_init(void) +{ + gpio_enable_interrupt(TABLET_MODE_GPIO_L); + /* Ensure tablet mode is initialized according to the hardware state + * so that the cached state reflects reality. */ + tablet_mode_debounce(); +} +DECLARE_HOOK(HOOK_INIT, tablet_mode_init, HOOK_PRIO_DEFAULT); +#endif diff --git a/include/config.h b/include/config.h index 9589ad7fb7..360e8ccc7e 100644 --- a/include/config.h +++ b/include/config.h @@ -2530,6 +2530,12 @@ */ #undef CONFIG_TABLET_MODE_SWITCH +/* + * Add a physical switch to indicate when we are in tablet mode. + * Define TABLET_MODE_GPIO_L and direct its interrupt hander to tablet_mode_isr + */ +#undef CONFIG_TABLET_SWITCH + /* * Microchip Trace FIFO Debug Port */ diff --git a/include/tablet_mode.h b/include/tablet_mode.h index 6f4ee95e1e..9c783ef1ff 100644 --- a/include/tablet_mode.h +++ b/include/tablet_mode.h @@ -9,4 +9,11 @@ int tablet_get_mode(void); void tablet_set_mode(int mode); - +/** + * Interrupt service routine for tablet switch. + * + * TABLET_MODE_GPIO_L must be defined. + * + * @param signal: GPIO signal + */ +void tablet_mode_isr(enum gpio_signal signal);