summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJett Rink <jettrink@chromium.org>2019-10-07 16:13:30 -0600
committerCommit Bot <commit-bot@chromium.org>2020-07-14 05:20:58 +0000
commitf7c4bd08c294d9ae3e5bd58c25b3136d314bf2f7 (patch)
treeb22daa41528a5915a55e1259bea72066f40f7f5e
parentf3dcccf9f362082a85fb77274ed23170e43413b8 (diff)
downloadchrome-ec-f7c4bd08c294d9ae3e5bd58c25b3136d314bf2f7.tar.gz
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 <jettrink@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1845779 Reviewed-by: Jack Rosenthal <jrosenth@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2294633 Tested-by: Marco Chen <marcochen@chromium.org> Reviewed-by: Marco Chen <marcochen@chromium.org> Commit-Queue: Marco Chen <marcochen@chromium.org>
-rw-r--r--common/tablet_mode.c87
1 files 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,