diff options
author | Daisuke Nojiri <dnojiri@chromium.org> | 2018-05-02 16:11:55 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-05-09 14:40:08 -0700 |
commit | c7559fea4ea0e2bfbb9d7ce0006ff37dea01cc4b (patch) | |
tree | 96b31d73443dbe400be6a9ed824eafec2a2f59a8 /common/tablet_mode.c | |
parent | 50ba7ef146aea95baa5ac74d6ac0ccf140568a6d (diff) | |
download | chrome-ec-c7559fea4ea0e2bfbb9d7ce0006ff37dea01cc4b.tar.gz |
tablet_mode: Define common interrupt handler for tablet switch
This patch adds an interrupt handler for a tablet switch and an init
hook to enable the interrupt.
The handler does the typical tasks for convertible devices: 1. sets
tablet mode then 2. disables peripherals if tablet mode is on.
Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org>
BUG=b:77298177
BRANCH=none
TEST=buildall. Verify on Nami.
Change-Id: If7fb5ea15f388d2b6084d800d2bc05efafd1945e
Reviewed-on: https://chromium-review.googlesource.com/1043057
Commit-Ready: Daisuke Nojiri <dnojiri@chromium.org>
Tested-by: Daisuke Nojiri <dnojiri@chromium.org>
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
Diffstat (limited to 'common/tablet_mode.c')
-rw-r--r-- | common/tablet_mode.c | 56 |
1 files changed, 51 insertions, 5 deletions
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 |