summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Torokhov <dtor@chromium.org>2018-08-15 17:16:35 -0700
committerchrome-bot <chrome-bot@chromium.org>2018-08-22 00:10:42 -0700
commitf70528e53dfbdc1f33508d157b05c608934a660f (patch)
tree214ba254482057090389c2e3170447fd51ef3f4b
parentb8489de98f1cf3e32fbcbe4b6f6163dff4a55c78 (diff)
downloadchrome-ec-f70528e53dfbdc1f33508d157b05c608934a660f.tar.gz
common: add API to expose detachable "base" state
On some detachables, when base is attached, we know right away that the device should transition from tablet to clamshell mode. However on other detachables we need additional information (i.e. base position) before we decide whether to transition in/out of tablet mode. For such detachables let's allow them to signal a new "base attached" switch event, so that the rest of the stack is not confused. BUG=b:73133611 BRANCH=nocturne TEST=Build and boot Change-Id: I9be3450cba52bf9f0bad8333402f68b0c7903090 Signed-off-by: Dmitry Torokhov <dtor@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1176801 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
-rw-r--r--common/base_state.c32
-rw-r--r--common/build.mk1
-rw-r--r--common/keyboard_mkbp.c14
-rw-r--r--include/base_state.h15
-rw-r--r--include/config.h6
-rw-r--r--include/ec_commands.h3
6 files changed, 70 insertions, 1 deletions
diff --git a/common/base_state.c b/common/base_state.c
new file mode 100644
index 0000000000..b0f352231d
--- /dev/null
+++ b/common/base_state.c
@@ -0,0 +1,32 @@
+/* Copyright 2018 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "base_state.h"
+#include "console.h"
+#include "host_command.h"
+#include "hooks.h"
+
+#define CPRINTS(format, args...) cprints(CC_MOTION_LID, format, ## args)
+
+/* 1: base attached, 0: otherwise */
+static int base_state;
+
+int base_get_state(void)
+{
+ return base_state;
+}
+
+void base_set_state(int state)
+{
+ if (base_state == !!state)
+ return;
+
+ base_state = !!state;
+ CPRINTS("base state: %stached", state ? "at" : "de");
+ hook_notify(HOOK_BASE_ATTACHED_CHANGE);
+
+ /* Notify host of mode change. This likely will wake it up. */
+ host_set_single_event(EC_HOST_EVENT_MODE_CHANGE);
+}
diff --git a/common/build.mk b/common/build.mk
index 9530586e41..1b3cf67e98 100644
--- a/common/build.mk
+++ b/common/build.mk
@@ -21,6 +21,7 @@ common-$(HAS_TASK_ALS)+=als.o
common-$(CONFIG_AP_HANG_DETECT)+=ap_hang_detect.o
common-$(CONFIG_BACKLIGHT_LID)+=backlight_lid.o
common-$(CONFIG_BASE32)+=base32.o
+common-$(CONFIG_BASE_ATTACHED_SWITCH)+=base_state.o
common-$(CONFIG_BATTERY)+=battery.o
common-$(CONFIG_BATTERY_FUEL_GAUGE)+=battery_fuel_gauge.o
common-$(CONFIG_BLUETOOTH_LE)+=bluetooth_le.o
diff --git a/common/keyboard_mkbp.c b/common/keyboard_mkbp.c
index ffe5aefa92..efd86f2e10 100644
--- a/common/keyboard_mkbp.c
+++ b/common/keyboard_mkbp.c
@@ -6,6 +6,7 @@
*/
#include "atomic.h"
+#include "base_state.h"
#include "button.h"
#include "chipset.h"
#include "common.h"
@@ -264,6 +265,16 @@ DECLARE_HOOK(HOOK_TABLET_MODE_CHANGE, mkbp_tablet_mode_change, HOOK_PRIO_LAST);
DECLARE_HOOK(HOOK_INIT, mkbp_tablet_mode_change, HOOK_PRIO_INIT_LID+1);
#endif
+#ifdef CONFIG_BASE_ATTACHED_SWITCH
+static void mkbp_base_attached_change(void)
+{
+ mkbp_update_switches(EC_MKBP_BASE_ATTACHED, base_get_state());
+}
+DECLARE_HOOK(HOOK_BASE_ATTACHED_CHANGE, mkbp_base_attached_change,
+ HOOK_PRIO_LAST);
+DECLARE_HOOK(HOOK_INIT, mkbp_base_attached_change, HOOK_PRIO_INIT_LID+1);
+#endif
+
void keyboard_update_button(enum keyboard_button_type button, int is_pressed)
{
switch (button) {
@@ -430,6 +441,9 @@ static uint32_t get_supported_switches(void)
#ifdef CONFIG_TABLET_MODE_SWITCH
val |= (1 << EC_MKBP_TABLET_MODE);
#endif
+#ifdef CONFIG_BASE_ATTACHED_SWITCH
+ val |= (1 << EC_MKBP_BASE_ATTACHED);
+#endif
return val;
}
diff --git a/include/base_state.h b/include/base_state.h
new file mode 100644
index 0000000000..6ee0948e5f
--- /dev/null
+++ b/include/base_state.h
@@ -0,0 +1,15 @@
+/* Copyright 2018 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/**
+ * Return 1 if base attached, 0 otherwise.
+ */
+int base_get_state(void);
+
+/**
+ * Sets the current state of the base, with 0 meaning detached,
+ * and non-zero meaning attached.
+ */
+void base_set_state(int state);
diff --git a/include/config.h b/include/config.h
index 84f3b0ad65..c5a79901c4 100644
--- a/include/config.h
+++ b/include/config.h
@@ -2751,6 +2751,12 @@
#undef CONFIG_TABLET_SWITCH
/*
+ * Add a virtual switch to indicate when detachable device has
+ * base attached.
+ */
+#undef CONFIG_BASE_ATTACHED_SWITCH
+
+/*
* Microchip Trace FIFO Debug Port
*/
#undef CONFIG_MCHP_TFDP
diff --git a/include/ec_commands.h b/include/ec_commands.h
index 30b02024d7..e45e56911c 100644
--- a/include/ec_commands.h
+++ b/include/ec_commands.h
@@ -596,7 +596,7 @@ enum host_event_code {
/* EC desires to change state of host-controlled USB mux */
EC_HOST_EVENT_USB_MUX = 28,
- /* TABLET/LAPTOP mode event*/
+ /* TABLET/LAPTOP mode or detachable base attach/detach event */
EC_HOST_EVENT_MODE_CHANGE = 29,
/* Keyboard recovery combo with hardware reinitialization */
@@ -3285,6 +3285,7 @@ struct __ec_align1 ec_response_get_next_event_v1 {
/* Switches */
#define EC_MKBP_LID_OPEN 0
#define EC_MKBP_TABLET_MODE 1
+#define EC_MKBP_BASE_ATTACHED 2
/* Run keyboard factory test scanning */
#define EC_CMD_KEYBOARD_FACTORY_TEST 0x0068