summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaviChandra Sadineni <ravisadineni@google.com>2018-08-22 17:28:17 -0700
committerchrome-bot <chrome-bot@chromium.org>2018-09-13 18:58:41 -0700
commit10b223dd62ca5178290a201a353e21bcd040b24d (patch)
tree39395acfc36316226aefddba15a5322f8008a736
parent26767c965ee02fe47d86a96a28117a4a61bf90b2 (diff)
downloadchrome-ec-10b223dd62ca5178290a201a353e21bcd040b24d.tar.gz
base_detect: Expose console command to force state.
In an effort to test wake sources on any given platform, this CL exposes console command to set the base state. This console command can then be invoked by autottests from the uart interface. We have two implementations for managing base status. One is interrupt driven while the other is a polling via a task. Boards current implementations then are: interrupts: lux, soraka, cheza polling task: nocturne, zoombini For forcing base connect and disconnect, interrupts: Disable interrupts and set forced base state. polling task: Stop periodic task and set forced base state. On reset, interrupts: Schedule deferred task immediately and enable interrupts. polling task: Clear forced base state and begin rescheduling periodic task. Signed-off-by: RaviChandra Sadineni <ravisadineni@google.com> BRANCH=poppy,nocturne BUG=chromium:820668, b:37223093 TEST=Tested on lux, soraka and nocturne basestate a : attaches the lid, reflected in ui. basestate d : detaches the lid, reflected in ui. basestate r : resets to the correct state. Wakes the device up on lux and nocturne and soraka. Change-Id: Iab698e103a50b8d22bf216a6f816998cb158e38a Reviewed-on: https://chromium-review.googlesource.com/1184172 Commit-Ready: Ravi Chandra Sadineni <ravisadineni@chromium.org> Tested-by: Ravi Chandra Sadineni <ravisadineni@chromium.org> Reviewed-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Furquan Shaikh <furquan@chromium.org> Reviewed-by: Nicolas Boichat <drinkcat@chromium.org> Reviewed-by: Todd Broch <tbroch@chromium.org>
-rw-r--r--board/cheza/base_detect.c17
-rw-r--r--board/cheza/board.h2
-rw-r--r--board/nocturne/base_detect.c33
-rw-r--r--board/nocturne/board.h2
-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--board/zoombini/base_detect.c29
-rw-r--r--board/zoombini/board.h4
-rw-r--r--common/base_state.c22
-rw-r--r--common/build.mk2
-rw-r--r--include/base_state.h7
-rw-r--r--include/config.h7
14 files changed, 156 insertions, 20 deletions
diff --git a/board/cheza/base_detect.c b/board/cheza/base_detect.c
index c14638b5ac..3999ad022f 100644
--- a/board/cheza/base_detect.c
+++ b/board/cheza/base_detect.c
@@ -197,3 +197,20 @@ static void base_init(void)
gpio_set_level(GPIO_EN_CC_LID_BASE_PULLDN, 1);
}
DECLARE_HOOK(HOOK_INIT, base_init, HOOK_PRIO_DEFAULT+1);
+
+void base_force_state(int state)
+{
+ if (state == 1) {
+ gpio_disable_interrupt(GPIO_CC_LID_BASE_ADC);
+ base_detect_change(BASE_CONNECTED);
+ CPRINTS("BD forced connected");
+ } else if (state == 0) {
+ gpio_disable_interrupt(GPIO_CC_LID_BASE_ADC);
+ base_detect_change(BASE_DISCONNECTED);
+ CPRINTS("BD forced disconnected");
+ } else {
+ hook_call_deferred(&base_detect_deferred_data, 0);
+ gpio_enable_interrupt(GPIO_CC_LID_BASE_ADC);
+ CPRINTS("BD forced reset");
+ }
+}
diff --git a/board/cheza/board.h b/board/cheza/board.h
index 990e83c670..92472ef864 100644
--- a/board/cheza/board.h
+++ b/board/cheza/board.h
@@ -40,6 +40,8 @@
#define CONFIG_PWM
#define CONFIG_PWM_DISPLIGHT
+#define CONFIG_DETACHABLE_BASE
+
#undef CONFIG_PECI
#define CONFIG_HOSTCMD_SPS
diff --git a/board/nocturne/base_detect.c b/board/nocturne/base_detect.c
index 9158fb26fb..406f06ef6a 100644
--- a/board/nocturne/base_detect.c
+++ b/board/nocturne/base_detect.c
@@ -53,11 +53,15 @@ enum base_detect_state {
BASE_ATTACHED_DEBOUNCE,
BASE_ATTACHED,
BASE_DETACHED_DEBOUNCE,
+ // Default for |forced_state|. Should be set only on |forced_state|.
+ BASE_NO_FORCED_STATE,
};
static int debug;
+static enum base_detect_state forced_state = BASE_NO_FORCED_STATE;
static enum base_detect_state state;
+
static void enable_base_interrupts(int enable)
{
int (*fn)(enum gpio_signal) = enable ? gpio_enable_interrupt :
@@ -160,6 +164,17 @@ static void base_detect_deferred(void)
int detach_reading;
int timeout = DEFAULT_POLL_TIMEOUT_US;
+ if (forced_state != BASE_NO_FORCED_STATE) {
+ if (state != forced_state) {
+ CPRINTS("BD forced %s",
+ forced_state == BASE_ATTACHED ?
+ "attached" : "detached");
+ set_state(forced_state);
+ base_detect_changed();
+ }
+ return;
+ }
+
attach_reading = adc_read_channel(ADC_BASE_ATTACH);
detach_reading = adc_read_channel(ADC_BASE_DETACH);
@@ -285,9 +300,23 @@ static int command_basedetectdebug(int argc, char **argv)
if ((argc > 1) && !parse_bool(argv[1], &debug))
return EC_ERROR_PARAM1;
- CPRINTS("BD: st%d", state);
-
+ CPRINTS("BD: %sst%d", forced_state != BASE_NO_FORCED_STATE ?
+ "forced " : "", state);
return EC_SUCCESS;
}
+
DECLARE_CONSOLE_COMMAND(basedebug, command_basedetectdebug, "[ena|dis]",
"En/Disable base detection debug");
+
+
+void base_force_state(int state)
+{
+ if (state == 1)
+ forced_state = BASE_ATTACHED;
+ else if (state == 0)
+ forced_state = BASE_DETACHED;
+ else
+ forced_state = BASE_NO_FORCED_STATE;
+
+ hook_call_deferred(&base_detect_deferred_data, 0);
+}
diff --git a/board/nocturne/board.h b/board/nocturne/board.h
index 629b8e444d..042a83f97e 100644
--- a/board/nocturne/board.h
+++ b/board/nocturne/board.h
@@ -44,6 +44,8 @@
#define CONFIG_VSTORE
#define CONFIG_VSTORE_SLOT_COUNT 1
+#define CONFIG_DETACHABLE_BASE
+
/* EC console commands */
#define CONFIG_CMD_ACCELS
#define CONFIG_CMD_ACCEL_INFO
diff --git a/board/poppy/base_detect_lux.c b/board/poppy/base_detect_lux.c
index a46fe2eac8..155243af0e 100644
--- a/board/poppy/base_detect_lux.c
+++ b/board/poppy/base_detect_lux.c
@@ -218,3 +218,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 61b990b7a2..20c57d6388 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 948f4ec7f8..358b83aaa1 100644
--- a/board/poppy/board.h
+++ b/board/poppy/board.h
@@ -20,6 +20,7 @@
#define CONFIG_BOARD_VERSION_CUSTOM
#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/board/zoombini/base_detect.c b/board/zoombini/base_detect.c
index 86df4a2c8b..b2c4490970 100644
--- a/board/zoombini/base_detect.c
+++ b/board/zoombini/base_detect.c
@@ -53,10 +53,13 @@ enum base_detect_state {
BASE_ATTACHED_DEBOUNCE,
BASE_ATTACHED,
BASE_DETACHED_DEBOUNCE,
+ // Default for |forced_state|. Should be set only on |forced_state|.
+ BASE_NO_FORCED_STATE,
};
static int debug;
static enum base_detect_state state;
+static enum base_detect_state forced_state = BASE_NO_FORCED_STATE;
static void base_power_enable(int enable)
{
@@ -161,6 +164,16 @@ static void base_detect_deferred(void)
attach_reading,
detach_reading);
+ if (forced_state != BASE_NO_FORCED_STATE) {
+ if (state != forced_state) {
+ CPRINTS("BD Forced %s",
+ forced_state == BASE_ATTACHED ?
+ "attached" : "detached");
+ set_state(forced_state);
+ }
+ return;
+ }
+
switch (state) {
case BASE_DETACHED:
/* Check to see if a base may be attached. */
@@ -271,9 +284,23 @@ static int command_basedetectdebug(int argc, char **argv)
if ((argc > 1) && !parse_bool(argv[1], &debug))
return EC_ERROR_PARAM1;
- CPRINTS("BD: st%d", state);
+ CPRINTS("BD: %sst%d", forced_state != BASE_NO_FORCED_STATE ?
+ "forced " : "", state);
return EC_SUCCESS;
}
DECLARE_CONSOLE_COMMAND(basedebug, command_basedetectdebug, "[ena|dis]",
"En/Disable base detection debug");
+
+
+void base_force_state(int state)
+{
+ if (state == 1)
+ forced_state = BASE_ATTACHED;
+ else if (state == 0)
+ forced_state = BASE_DETACHED;
+ else
+ forced_state = BASE_NO_FORCED_STATE;
+
+ hook_call_deferred(&base_detect_deferred_data, 0);
+}
diff --git a/board/zoombini/board.h b/board/zoombini/board.h
index 582412d9fb..8a2e99d5a4 100644
--- a/board/zoombini/board.h
+++ b/board/zoombini/board.h
@@ -80,6 +80,10 @@
#define CONFIG_BATTERY_PRESENT_GPIO GPIO_BAT_PRESENT_L
#ifdef BOARD_MEOWTH
+#define CONFIG_DETACHABLE_BASE
+#endif
+
+#ifdef BOARD_MEOWTH
#define CONFIG_BOARD_VERSION_CUSTOM
#else
#define CONFIG_BOARD_VERSION_GPIO
diff --git a/common/base_state.c b/common/base_state.c
index b0f352231d..053b6d4b23 100644
--- a/common/base_state.c
+++ b/common/base_state.c
@@ -10,6 +10,7 @@
#define CPRINTS(format, args...) cprints(CC_MOTION_LID, format, ## args)
+#ifdef CONFIG_BASE_ATTACHED_SWITCH
/* 1: base attached, 0: otherwise */
static int base_state;
@@ -30,3 +31,24 @@ void base_set_state(int state)
/* Notify host of mode change. This likely will wake it up. */
host_set_single_event(EC_HOST_EVENT_MODE_CHANGE);
}
+#endif
+
+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 fe644bf384..06557c3737 100644
--- a/common/build.mk
+++ b/common/build.mk
@@ -21,7 +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_DETACHABLE_BASE)+=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/include/base_state.h b/include/base_state.h
index 6ee0948e5f..6363ebdd7a 100644
--- a/include/base_state.h
+++ b/include/base_state.h
@@ -13,3 +13,10 @@ int base_get_state(void);
* and non-zero meaning attached.
*/
void base_set_state(int state);
+
+/**
+ * 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 179f7cfb51..cecf256b62 100644
--- a/include/config.h
+++ b/include/config.h
@@ -514,6 +514,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