From f7c4bd08c294d9ae3e5bd58c25b3136d314bf2f7 Mon Sep 17 00:00:00 2001 From: Jett Rink Date: Mon, 7 Oct 2019 16:13:30 -0600 Subject: tablet_mode: ensure that tablet mode is always initialized The board init should ensure that tablet_mode is always set so the rest of the subsystems can rely on this. We assume notebook mode if we don't have any input from the GSR 360 hall sensor. That matches the default up in AP firmware as well. BRANCH=none BUG=b:141494453,chromium:1010343 BUG=b:160981170 TEST=put arcada at 200 degrees and see that tablet mode it initialized correctly. Change-Id: I4e23d3ba149f9add84f9667a5af676803cf50da5 Signed-off-by: Jett Rink Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1845779 Reviewed-by: Jack Rosenthal Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2294633 Tested-by: Marco Chen Reviewed-by: Marco Chen Commit-Queue: Marco Chen --- common/tablet_mode.c | 87 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 53 insertions(+), 34 deletions(-) diff --git a/common/tablet_mode.c b/common/tablet_mode.c index ab954cff0a..7f5d28b50d 100644 --- a/common/tablet_mode.c +++ b/common/tablet_mode.c @@ -8,60 +8,73 @@ #include "hooks.h" #include "host_command.h" #include "lid_angle.h" +#include "stdbool.h" #include "tablet_mode.h" #include "timer.h" #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: notebook mode; -1: uninitialized */ -static int tablet_mode = -1; -static int forced_tablet_mode = -1; +/* + * Other code modules assume that notebook mode (i.e. tablet_mode = false) at + * startup + */ +static bool tablet_mode; + +/* + * Console command can force the value of tablet_mode. If tablet_mode_force is + * true, the all external set call for tablet_mode are ignored. + */ +static bool tablet_mode_forced; -static int disabled; +/* + * True: all calls to tablet_set_mode are ignored and tablet_mode if forced to 0 + * False: all calls to tablet_set_mode are honored + */ +static bool disabled; int tablet_get_mode(void) { - if (forced_tablet_mode != -1) - return !!forced_tablet_mode; - return !!tablet_mode; + return tablet_mode; } -void tablet_set_mode(int mode) +static void notify_tablet_mode_change(void) { - if (tablet_mode == mode) - return; + CPRINTS("tablet mode %sabled", tablet_mode ? "en" : "dis"); + hook_notify(HOOK_TABLET_MODE_CHANGE); - if (disabled) { - CPRINTS("Tablet mode set while disabled (ignoring)!"); - return; - } + /* + * When tablet mode changes, send an event to ACPI to retrieve + * tablet mode value and send an event to the kernel. + */ + if (IS_ENABLED(CONFIG_HOSTCMD_EVENTS)) + host_set_single_event(EC_HOST_EVENT_MODE_CHANGE); - tablet_mode = mode; +} - if (forced_tablet_mode != -1) +void tablet_set_mode(int mode) +{ + /* If tablet_mode is forced via a console command, ignore set. */ + if (tablet_mode_forced) return; - CPRINTS("tablet mode %sabled", mode ? "en" : "dis"); - hook_notify(HOOK_TABLET_MODE_CHANGE); -} + if (tablet_mode == !!mode) + return; -static void tabletmode_force_state(int mode) -{ - if (forced_tablet_mode == mode) + if (disabled) { + CPRINTS("Tablet mode set while disabled (ignoring)!"); return; + } - forced_tablet_mode = mode; + 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; - disabled = 1; + tablet_mode = false; + disabled = true; } /* This ifdef can be removed once we clean up past projects which do own init */ @@ -133,14 +146,20 @@ 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 + + if (argv[1][0] == 'o' && argv[1][1] == 'n') { + tablet_mode = true; + tablet_mode_forced = true; + } else if (argv[1][0] == 'o' && argv[1][1] == 'f') { + tablet_mode = false; + tablet_mode_forced = true; + } else if (argv[1][0] == 'r') { + tablet_mode_forced = false; + } else { return EC_ERROR_PARAM1; + } + + notify_tablet_mode_change(); return EC_SUCCESS; } DECLARE_CONSOLE_COMMAND(tabletmode, command_settabletmode, -- cgit v1.2.1