diff options
-rw-r--r-- | common/tablet_mode.c | 37 | ||||
-rw-r--r-- | include/host_command.h | 2 |
2 files changed, 37 insertions, 2 deletions
diff --git a/common/tablet_mode.c b/common/tablet_mode.c index 7773ba84d6..5da4db7821 100644 --- a/common/tablet_mode.c +++ b/common/tablet_mode.c @@ -17,6 +17,7 @@ /* 1: in tablet mode; 0: notebook mode; -1: uninitialized */ static int tablet_mode = -1; +static int forced_tablet_mode = -1; /* 1: hall sensor is reporting 360 degrees. */ static int hall_sensor_at_360; @@ -29,6 +30,8 @@ static int disabled; int tablet_get_mode(void) { + if (forced_tablet_mode != -1) + return !!forced_tablet_mode; return !!tablet_mode; } @@ -48,6 +51,10 @@ void tablet_set_mode(int mode) } tablet_mode = mode; + + if (forced_tablet_mode != -1) + return; + CPRINTS("tablet mode %sabled", mode ? "en" : "dis"); hook_notify(HOOK_TABLET_MODE_CHANGE); @@ -60,6 +67,18 @@ void tablet_set_mode(int mode) #endif } +static void tabletmode_force_state(int mode) +{ + if (forced_tablet_mode == mode) + return; + + forced_tablet_mode = mode; + + hook_notify(HOOK_TABLET_MODE_CHANGE); + if (IS_ENABLED(CONFIG_HOSTCMD_EVENTS)) + host_set_single_event(EC_HOST_EVENT_MODE_CHANGE); +} + void tablet_disable(void) { tablet_mode = 0; @@ -144,3 +163,21 @@ void hall_sensor_disable(void) tablet_disable(); } #endif + +static int command_settabletmode(int argc, char **argv) +{ + if (argc != 2) + return EC_ERROR_PARAM_COUNT; + if (argv[1][0] == 'o' && argv[1][1] == 'n') + tabletmode_force_state(1); + else if (argv[1][0] == 'o' && argv[1][1] == 'f') + tabletmode_force_state(0); + else if (argv[1][0] == 'r') + tabletmode_force_state(-1); + else + return EC_ERROR_PARAM1; + return EC_SUCCESS; +} +DECLARE_CONSOLE_COMMAND(tabletmode, command_settabletmode, + "[on | off | reset]", + "Manually force tablet mode to on, off or reset."); diff --git a/include/host_command.h b/include/host_command.h index fbb2639175..3aa0d54d03 100644 --- a/include/host_command.h +++ b/include/host_command.h @@ -155,7 +155,6 @@ uint8_t *host_get_memmap(int offset); */ uint16_t host_command_process(struct host_cmd_handler_args *args); -#ifdef CONFIG_HOSTCMD_EVENTS /** * Set a single host event. * @@ -205,7 +204,6 @@ int get_lazy_wake_mask(enum power_state state, host_event_t *mask); */ uint8_t lpc_is_active_wm_set_by_host(void); #endif -#endif /** * Send a response to the relevant driver for transmission |