summaryrefslogtreecommitdiff
path: root/common/device_state.c
diff options
context:
space:
mode:
authorMary Ruthven <mruthven@chromium.org>2016-06-24 15:49:28 -0700
committerchrome-bot <chrome-bot@chromium.org>2016-07-12 22:34:56 -0700
commit49312e06cdb93091b20ac3249fccb4dd711996b6 (patch)
treeaad434ac48eaeda17750ae6138146f95c138bd19 /common/device_state.c
parent9146e44c7d14ce73061b949373b4787483c39ad8 (diff)
downloadchrome-ec-49312e06cdb93091b20ac3249fccb4dd711996b6.tar.gz
cr50: disable device monitoring when not in ccd
When cr50 is not trying to do ccd, we dont need to monitor the devices. Disable device state detection interrupts and the AP and EC UARTs. BUG=none BRANCH=none TEST=gru and kevin monitor devices correctly when ccd is enabled, and dont monitor anything when it is disabled. Change-Id: Ic3f5974320486ff6dd0147c490a1c294cc2f6a76 Signed-off-by: Mary Ruthven <mruthven@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/356770 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
Diffstat (limited to 'common/device_state.c')
-rw-r--r--common/device_state.c76
1 files changed, 76 insertions, 0 deletions
diff --git a/common/device_state.c b/common/device_state.c
index 2b3f969d4c..650e2671ef 100644
--- a/common/device_state.c
+++ b/common/device_state.c
@@ -3,9 +3,12 @@
* found in the LICENSE file.
*/
+#include "console.h"
#include "device_state.h"
#include "hooks.h"
+static int enabled = 1;
+
int device_get_state(enum device_type device)
{
return device_states[device].state;
@@ -23,7 +26,80 @@ static void check_device_state(void)
{
int i;
+ if (!enabled)
+ return;
+
for (i = 0; i < DEVICE_COUNT; i++)
board_update_device_state(i);
}
DECLARE_HOOK(HOOK_SECOND, check_device_state, HOOK_PRIO_DEFAULT);
+
+static int device_has_interrupts(enum device_type device)
+{
+ return (device_states[device].deferred &&
+ device_states[device].detect_on != GPIO_COUNT &&
+ device_states[device].detect_off != GPIO_COUNT);
+}
+
+static void disable_interrupts(enum device_type device)
+{
+ if (!device_has_interrupts(device))
+ return;
+
+ /* Cancel any deferred callbacks */
+ hook_call_deferred(device_states[device].deferred, -1);
+
+ /* Disable gpio interrupts */
+ gpio_disable_interrupt(device_states[device].detect_on);
+ gpio_disable_interrupt(device_states[device].detect_off);
+}
+
+static void enable_interrupts(enum device_type device)
+{
+ if (!device_has_interrupts(device))
+ return;
+
+ /* Enable gpio interrupts */
+ gpio_enable_interrupt(device_states[device].detect_on);
+ gpio_enable_interrupt(device_states[device].detect_off);
+}
+
+void device_detect_state_enable(int enable)
+{
+ int i;
+
+ enabled = enable;
+ for (i = 0; i < DEVICE_COUNT; i++) {
+ if (enabled) {
+ enable_interrupts(i);
+ board_update_device_state(i);
+ } else {
+ disable_interrupts(i);
+ device_set_state(i, DEVICE_STATE_UNKNOWN);
+ }
+ }
+}
+
+static void print_state(const char *name, enum device_state state)
+{
+ ccprintf("%-9s %s\n", name, state == DEVICE_STATE_ON ? "on" :
+ state == DEVICE_STATE_OFF ? "off" : "unknown");
+}
+
+static int command_devices(int argc, char **argv)
+{
+ int i;
+
+ if (!enabled)
+ ccprintf("Device monitoring disabled\n");
+ else
+ for (i = 0; i < DEVICE_COUNT; i++)
+ print_state(device_states[i].name,
+ device_states[i].state);
+
+ return EC_SUCCESS;
+}
+DECLARE_CONSOLE_COMMAND(devices, command_devices,
+ "",
+ "Get the device states",
+ NULL);