summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSiyu Qin <qinsiyu@huaqin.corp-partner.google.com>2022-03-04 10:55:54 +0800
committerCommit Bot <commit-bot@chromium.org>2022-03-09 09:53:48 +0000
commit08f62670fa6ef87212ccaf6fc13cc947e26976e4 (patch)
treec0bc601ba4ce4534732fda6bafc638a4d0f83b24
parentc755fffea0e2e05733e61ea254d820612e869b7a (diff)
downloadchrome-ec-08f62670fa6ef87212ccaf6fc13cc947e26976e4.tar.gz
mrbland: Disable lid detect when the base is detached
According to the OEM requirement, the lid detection should be closed when the folio keyboard is detached. BUG=b:198509824 BRANCH=trogdor TEST=make BOARD=mrbland -j Change-Id: I5c595a9a85dff1107aea7b3008165c46cc6fb51f Signed-off-by: Siyu Qin <qinsiyu@huaqin.corp-partner.google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3499778 Reviewed-by: wen zhang <zhangwen6@huaqin.corp-partner.google.com> Reviewed-by: Wai-Hong Tam <waihong@google.com> Reviewed-by: Ting Shen <phoenixshen@chromium.org>
-rw-r--r--board/mrbland/base_detect.c31
-rw-r--r--common/lid_switch.c15
-rw-r--r--include/lid_switch.h8
3 files changed, 45 insertions, 9 deletions
diff --git a/board/mrbland/base_detect.c b/board/mrbland/base_detect.c
index 85bc04c4c2..70217868ea 100644
--- a/board/mrbland/base_detect.c
+++ b/board/mrbland/base_detect.c
@@ -14,6 +14,7 @@
#include "gpio.h"
#include "hooks.h"
#include "host_command.h"
+#include "lid_switch.h"
#include "system.h"
#include "tablet_mode.h"
#include "timer.h"
@@ -67,27 +68,39 @@ enum base_status {
};
static enum base_status current_base_status;
+static bool current_base_enable_allow;
/*
* This function is called whenever there is a change in the base detect
* status. Actions taken include:
- * 1. Change in power to base
+ * 1. Change in power to base after chipset startup, and disable the base
+ * power at chipset shutdown.
* 2. Indicate mode change to host.
* 3. Indicate tablet mode to host. Current assumption is that if base is
* disconnected then the system is in tablet mode, else if the base is
* connected, then the system is not in tablet mode.
+ * 4. Change lid dectect according to base status.
*/
static void base_detect_change(enum base_status status)
{
int connected = (status == BASE_CONNECTED);
+ bool base_enable_allow =
+ !chipset_in_or_transitioning_to_state(CHIPSET_STATE_ANY_OFF);
- if (current_base_status == status)
+ if ((current_base_status == status) &&
+ (current_base_enable_allow == base_enable_allow))
return;
- gpio_set_level(GPIO_EN_BASE, connected);
+ if (base_enable_allow)
+ gpio_set_level(GPIO_EN_BASE, connected);
+ else
+ gpio_set_level(GPIO_EN_BASE, 0);
+
tablet_set_mode(!connected, TABLET_TRIGGER_BASE);
base_set_state(connected);
current_base_status = status;
+ current_base_enable_allow = base_enable_allow;
+ enable_lid_detect(connected);
}
/* Measure detection pin pulse duration (used to wake AP from deep S3). */
@@ -119,7 +132,8 @@ static void base_detect_deferred(void)
print_base_detect_value(v, tmp_pulse_width);
if (v >= BASE_DETECT_MIN_MV && v <= BASE_DETECT_MAX_MV) {
- if (current_base_status != BASE_CONNECTED) {
+ if ((current_base_status != BASE_CONNECTED) ||
+ (current_base_enable_allow != true)) {
base_detect_change(BASE_CONNECTED);
} else if (tmp_pulse_width >= BASE_DETECT_PULSE_MIN_US &&
tmp_pulse_width <= BASE_DETECT_PULSE_MAX_US) {
@@ -197,12 +211,11 @@ DECLARE_HOOK(HOOK_CHIPSET_STARTUP, base_enable, HOOK_PRIO_DEFAULT);
static void base_disable(void)
{
/*
- * Disable base detection interrupt and disable power to base.
- * Set the state UNKNOWN so the next startup will initialize a
- * correct state and notify AP.
+ * Disable power to base and update the base dectect status,
+ * so the next startup will initialize a correct state
+ * and notify AP.
*/
- gpio_disable_interrupt(GPIO_BASE_DET_L);
- base_detect_change(BASE_UNKNOWN);
+ base_detect_change(current_base_status);
}
DECLARE_HOOK(HOOK_CHIPSET_SHUTDOWN, base_disable, HOOK_PRIO_DEFAULT);
diff --git a/common/lid_switch.c b/common/lid_switch.c
index 2528e00092..f8e1708f94 100644
--- a/common/lid_switch.c
+++ b/common/lid_switch.c
@@ -120,6 +120,21 @@ void lid_interrupt(enum gpio_signal signal)
hook_call_deferred(&lid_change_deferred_data, LID_DEBOUNCE_US);
}
+void enable_lid_detect(bool enable)
+{
+ CPRINTS("lid detect %sabled", enable ? "en" : "dis");
+ if (enable) {
+#define LID_GPIO(gpio) gpio_enable_interrupt(gpio);
+ CONFIG_LID_SWITCH_GPIO_LIST
+#undef LID_GPIO
+ } else {
+#define LID_GPIO(gpio) gpio_disable_interrupt(gpio);
+ CONFIG_LID_SWITCH_GPIO_LIST
+#undef LID_GPIO
+ lid_switch_open();
+ }
+}
+
static int command_lidopen(int argc, char **argv)
{
lid_switch_open();
diff --git a/include/lid_switch.h b/include/lid_switch.h
index a999abdda7..627a41d62c 100644
--- a/include/lid_switch.h
+++ b/include/lid_switch.h
@@ -9,6 +9,7 @@
#define __CROS_EC_LID_SWITCH_H
#include "common.h"
+#include "stdbool.h"
/**
* Return non-zero if lid is open.
@@ -24,4 +25,11 @@ int lid_is_open(void);
*/
void lid_interrupt(enum gpio_signal signal);
+/**
+ * Disable lid interrupt and set the lid open, when base is disconnected.
+ *
+ * @param enable Flag that enables or disables lid interrupt.
+ */
+void enable_lid_detect(bool enable);
+
#endif /* __CROS_EC_LID_SWITCH_H */