summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--board/poppy/base_detect_lux.c18
-rw-r--r--board/poppy/base_detect_poppy.c16
-rw-r--r--board/poppy/board.c16
-rw-r--r--board/poppy/board.h1
-rw-r--r--common/base_state.c27
-rw-r--r--common/build.mk1
-rw-r--r--include/base_state.h11
-rw-r--r--include/config.h7
8 files changed, 81 insertions, 16 deletions
diff --git a/board/poppy/base_detect_lux.c b/board/poppy/base_detect_lux.c
index 48c4aa8929..3da86d5e27 100644
--- a/board/poppy/base_detect_lux.c
+++ b/board/poppy/base_detect_lux.c
@@ -210,3 +210,21 @@ static void base_init(void)
gpio_enable_interrupt(GPIO_BASE_DET_A);
}
DECLARE_HOOK(HOOK_INIT, base_init, HOOK_PRIO_DEFAULT+1);
+
+void base_force_state(int state)
+{
+ if (state == 1) {
+ gpio_disable_interrupt(GPIO_BASE_DET_A);
+ base_detect_change(BASE_CONNECTED);
+ CPRINTS("BD forced connected");
+ } else if (state == 0) {
+ gpio_disable_interrupt(GPIO_BASE_DET_A);
+ base_detect_change(BASE_DISCONNECTED);
+ CPRINTS("BD forced disconnected");
+ } else {
+ hook_call_deferred(&base_detect_deferred_data,
+ BASE_DETECT_DEBOUNCE_US);
+ gpio_enable_interrupt(GPIO_BASE_DET_A);
+ CPRINTS("BD forced reset");
+ }
+}
diff --git a/board/poppy/base_detect_poppy.c b/board/poppy/base_detect_poppy.c
index 83f395f43c..a049b41acd 100644
--- a/board/poppy/base_detect_poppy.c
+++ b/board/poppy/base_detect_poppy.c
@@ -238,3 +238,19 @@ static void base_init(void)
base_enable();
}
DECLARE_HOOK(HOOK_INIT, base_init, HOOK_PRIO_DEFAULT+1);
+
+void base_force_state(int state)
+{
+ if (state == 1) {
+ gpio_disable_interrupt(GPIO_BASE_DET_A);
+ base_detect_change(BASE_CONNECTED);
+ CPRINTS("BD forced connected");
+ } else if (state == 0) {
+ gpio_disable_interrupt(GPIO_BASE_DET_A);
+ base_detect_change(BASE_DISCONNECTED);
+ CPRINTS("BD forced disconnected");
+ } else {
+ base_enable();
+ CPRINTS("BD forced reset");
+ }
+}
diff --git a/board/poppy/board.c b/board/poppy/board.c
index c693e2374c..57224f3615 100644
--- a/board/poppy/board.c
+++ b/board/poppy/board.c
@@ -142,22 +142,6 @@ void anx74xx_cable_det_interrupt(enum gpio_signal signal)
}
#endif
-static int command_attach_base(int argc, char **argv)
-{
- tablet_set_mode(0);
- return EC_SUCCESS;
-}
-DECLARE_CONSOLE_COMMAND(attachbase, command_attach_base,
- NULL, "Simulate attach base");
-
-static int command_detach_base(int argc, char **argv)
-{
- tablet_set_mode(1);
- return EC_SUCCESS;
-}
-DECLARE_CONSOLE_COMMAND(detachbase, command_detach_base,
- NULL, "Simulate detach base");
-
#include "gpio_list.h"
/* power signal list. Must match order of enum power_signal. */
diff --git a/board/poppy/board.h b/board/poppy/board.h
index 6a5e12201d..562cf77223 100644
--- a/board/poppy/board.h
+++ b/board/poppy/board.h
@@ -15,6 +15,7 @@
#define CONFIG_BOARD_SPECIFIC_VERSION
#define CONFIG_BOARD_FORCE_RESET_PIN
#define CONFIG_BUTTON_TRIGGERED_RECOVERY
+#define CONFIG_DETACHABLE_BASE
#define CONFIG_DPTF
#define CONFIG_DPTF_DEVICE_ORIENTATION
#define CONFIG_EMULATED_SYSRQ
diff --git a/common/base_state.c b/common/base_state.c
new file mode 100644
index 0000000000..b35f6a6f4e
--- /dev/null
+++ b/common/base_state.c
@@ -0,0 +1,27 @@
+/* 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"
+
+static int command_setbasestate(int argc, char **argv)
+{
+ if (argc != 2)
+ return EC_ERROR_PARAM_COUNT;
+ if (argv[1][0] == 'a')
+ base_force_state(1);
+ else if (argv[1][0] == 'd')
+ base_force_state(0);
+ else if (argv[1][0] == 'r')
+ base_force_state(2);
+ else
+ return EC_ERROR_PARAM1;
+
+ return EC_SUCCESS;
+
+}
+DECLARE_CONSOLE_COMMAND(basestate, command_setbasestate,
+ "[attach | detach | reset]",
+ "Manually force base state to attached, detached or reset.");
diff --git a/common/build.mk b/common/build.mk
index e6b6a2da6c..c143082d2e 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_DETACHABLE_BASE)+=base_state.o
common-$(CONFIG_BATTERY)+=battery.o
common-$(CONFIG_BLUETOOTH_LE)+=bluetooth_le.o
common-$(CONFIG_BLUETOOTH_LE_STACK)+=btle_hci_controller.o btle_ll.o
diff --git a/include/base_state.h b/include/base_state.h
new file mode 100644
index 0000000000..fd19721bae
--- /dev/null
+++ b/include/base_state.h
@@ -0,0 +1,11 @@
+/* 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.
+ */
+
+/**
+ * Call board specific base_force_state function.
+ * Force the current state of the base, with 0 meaning detached,
+ * 1 meaning attached and 2 meaning reset to the original state.
+ */
+void base_force_state(int state);
diff --git a/include/config.h b/include/config.h
index f8bbae47ae..22780cf170 100644
--- a/include/config.h
+++ b/include/config.h
@@ -450,6 +450,13 @@
#undef CONFIG_BUTTON_TRIGGERED_RECOVERY
/*
+ * Compile detachable base support
+ *
+ * Enabled on all boards that have a detachable base.
+ */
+#undef CONFIG_DETACHABLE_BASE
+
+/*
* Indicates there is a dedicated recovery button. Note, that if there are
* volume buttons, a dedicated recovery button is not needed. This is intended
* because if a board has volume buttons, they can do everything a dedicated