summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAseda Aboagye <aaboagye@google.com>2018-05-03 15:48:12 -0700
committerchrome-bot <chrome-bot@chromium.org>2018-05-03 21:27:59 -0700
commitbe54bb9a9c2be4ab926f7ca9bd4fe7303aea5c98 (patch)
treef2bc0a5ff9bc3391cd330d36673e19bf70f2f267
parent0a8afe10c2ba566f35a9360aeb3b302669126ad5 (diff)
downloadchrome-ec-be54bb9a9c2be4ab926f7ca9bd4fe7303aea5c98.tar.gz
nocturne: Only power base when AP is on.
BUG=None BRANCH=None TEST=make -j BOARD=nocturne Change-Id: I4492498b710e4e0f4a1682e4353f993013131c7f Signed-off-by: Aseda Aboagye <aaboagye@google.com> Reviewed-on: https://chromium-review.googlesource.com/1043346 Commit-Ready: Aseda Aboagye <aaboagye@chromium.org> Tested-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Furquan Shaikh <furquan@chromium.org>
-rw-r--r--board/nocturne/base_detect.c62
1 files changed, 46 insertions, 16 deletions
diff --git a/board/nocturne/base_detect.c b/board/nocturne/base_detect.c
index a75aba5cbd..8e3ac022e0 100644
--- a/board/nocturne/base_detect.c
+++ b/board/nocturne/base_detect.c
@@ -17,6 +17,7 @@
*/
#include "adc.h"
+#include "chipset.h"
#include "common.h"
#include "console.h"
#include "gpio.h"
@@ -57,13 +58,23 @@ enum base_detect_state {
static int debug;
static enum base_detect_state state;
-static void base_detect_changed(void)
+static void base_power_enable(int enable)
{
- switch (state) {
- case BASE_DETACHED:
- /* Indicate that we are in tablet mode. */
- tablet_set_mode(1);
+ /* Nothing to do if the state is the same. */
+ if (gpio_get_level(GPIO_BASE_PWR_EN) == enable)
+ return;
+ if (enable) {
+ /* Apply power to the base only if the AP is on or sleeping. */
+ if (chipset_in_state(CHIPSET_STATE_ON |
+ CHIPSET_STATE_ANY_SUSPEND)) {
+ gpio_set_level(GPIO_BASE_PWR_EN, 1);
+ /* Allow time for the fault line to rise. */
+ msleep(1);
+ /* Monitor for base power faults. */
+ gpio_enable_interrupt(GPIO_BASE_PWR_FAULT_ODL);
+ }
+ } else {
/*
* Disable power fault interrupt. It will read low when base
* power is removed.
@@ -71,6 +82,18 @@ static void base_detect_changed(void)
gpio_disable_interrupt(GPIO_BASE_PWR_FAULT_ODL);
/* Now, remove power to the base. */
gpio_set_level(GPIO_BASE_PWR_EN, 0);
+ }
+
+ CPRINTS("BP: %d", enable);
+}
+
+static void base_detect_changed(void)
+{
+ switch (state) {
+ case BASE_DETACHED:
+ /* Indicate that we are in tablet mode. */
+ tablet_set_mode(1);
+ base_power_enable(0);
break;
case BASE_ATTACHED:
@@ -79,13 +102,7 @@ static void base_detect_changed(void)
* now, but we may have to revisit this.
*/
tablet_set_mode(0);
-
- /* Apply power to the base. */
- gpio_set_level(GPIO_BASE_PWR_EN, 1);
- /* Allow time for the fault line to rise. */
- msleep(1);
- /* Monitor for base power faults. */
- gpio_enable_interrupt(GPIO_BASE_PWR_FAULT_ODL);
+ base_power_enable(1);
break;
default:
@@ -188,11 +205,24 @@ static void base_detect_deferred(void)
break;
};
- /* Check again in the appropriate time. */
- hook_call_deferred(&base_detect_deferred_data, timeout);
+ /* Check again in the appropriate time only if the AP is on. */
+ if (chipset_in_state(CHIPSET_STATE_ON | CHIPSET_STATE_ANY_SUSPEND))
+ hook_call_deferred(&base_detect_deferred_data, timeout);
};
DECLARE_HOOK(HOOK_INIT, base_detect_deferred, HOOK_PRIO_INIT_ADC + 1);
+static void power_on_base(void)
+{
+ hook_call_deferred(&base_detect_deferred_data, 0);
+}
+DECLARE_HOOK(HOOK_CHIPSET_STARTUP, power_on_base, HOOK_PRIO_DEFAULT);
+
+static void power_off_base(void)
+{
+ base_power_enable(0);
+}
+DECLARE_HOOK(HOOK_CHIPSET_SHUTDOWN, power_off_base, HOOK_PRIO_DEFAULT);
+
static uint8_t base_power_on_attempts;
static void clear_base_power_on_attempts_deferred(void)
{
@@ -207,7 +237,7 @@ static void check_and_reapply_base_power_deferred(void)
if (base_power_on_attempts < POWER_FAULT_MAX_RETRIES) {
CPRINTS("Reapply base pwr");
- gpio_set_level(GPIO_BASE_PWR_EN, 1);
+ base_power_enable(1);
base_power_on_attempts++;
hook_call_deferred(&clear_base_power_on_attempts_deferred_data,
@@ -225,7 +255,7 @@ void base_pwr_fault_interrupt(enum gpio_signal s)
if (fault_detected) {
/* Turn off base power. */
CPRINTS("Base Pwr Flt!");
- gpio_set_level(GPIO_BASE_PWR_EN, 0);
+ base_power_enable(0);
/*
* Try and apply power in a bit if maybe it was just a temporary