diff options
author | Jett Rink <jettrink@chromium.org> | 2019-10-07 16:13:30 -0600 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2019-11-01 21:21:11 +0000 |
commit | 4d467cbea34a07c4a908e18ecb0cc3a250600ee0 (patch) | |
tree | c52bf72f9075dea4641984577dc78a3e96f025f1 | |
parent | 73948347d8d2faf4e5ce761c93614d238c5179d9 (diff) | |
download | chrome-ec-stabilize-12607.15.B.tar.gz |
tablet_mode: ensure that tablet mode is always initializedstabilize-quickfix-12607.83.Bstabilize-mtbf-12607.83.Bstabilize-12607.82.Bstabilize-12607.58.Bstabilize-12607.55.Bstabilize-12607.15.Bstabilize-12607.112.Brelease-R79-12607.B
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
TEST=put arcada at 200 degrees and see that tablet mode it initialized
correctly.
Change-Id: I4e23d3ba149f9add84f9667a5af676803cf50da5
Signed-off-by: Jett Rink <jettrink@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1845779
Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
(cherry picked from commit 9a133025d89a04a9f5afd6e57373f48564b40ed3)
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1893315
-rw-r--r-- | common/tablet_mode.c | 101 |
1 files changed, 54 insertions, 47 deletions
diff --git a/common/tablet_mode.c b/common/tablet_mode.c index b74dc5fc49..5486ffc668 100644 --- a/common/tablet_mode.c +++ b/common/tablet_mode.c @@ -9,35 +9,60 @@ #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; -/* 1: GMR sensor is reporting 360 degrees. */ -static int gmr_sensor_at_360; +/* True if GMR sensor is reporting 360 degrees. */ +static bool gmr_sensor_at_360; /* - * 1: all calls to tablet_set_mode are ignored and tablet_mode if forced to 0 - * 0: all calls to tablet_set_mode are honored + * 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 int disabled; +static bool disabled; int tablet_get_mode(void) { - if (forced_tablet_mode != -1) - return !!forced_tablet_mode; - return !!tablet_mode; + return tablet_mode; +} + +static void notify_tablet_mode_change(void) +{ + CPRINTS("tablet mode %sabled", tablet_mode ? "en" : "dis"); + hook_notify(HOOK_TABLET_MODE_CHANGE); + + /* + * 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); + } void tablet_set_mode(int mode) { - if (tablet_mode == mode) + /* If tablet_mode is forced via a console command, ignore set. */ + if (tablet_mode_forced) + return; + + if (tablet_mode == !!mode) return; if (disabled) { @@ -51,39 +76,15 @@ void tablet_set_mode(int mode) return; } - tablet_mode = mode; - - if (forced_tablet_mode != -1) - return; - - CPRINTS("tablet mode %sabled", mode ? "en" : "dis"); - hook_notify(HOOK_TABLET_MODE_CHANGE); - -#ifdef CONFIG_HOSTCMD_EVENTS - /* - * When tablet mode changes, send an event to ACPI to retrieve - * tablet mode value and send an event to the kernel. - */ - host_set_single_event(EC_HOST_EVENT_MODE_CHANGE); -#endif -} + tablet_mode = !!mode; -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); + notify_tablet_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 */ @@ -169,14 +170,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, |