summaryrefslogtreecommitdiff
path: root/common/device_state.c
diff options
context:
space:
mode:
authorMary Ruthven <mruthven@chromium.org>2016-08-18 18:35:45 -0700
committerMary Ruthven <mruthven@chromium.org>2016-09-22 18:04:57 +0000
commit96b7e491e80a4cd7a419fa4872dcf7146fc95cf3 (patch)
tree3fd5d717eba78c3d6e8c73bd8e2a4bbeed942e71 /common/device_state.c
parentb9f5a3d6baae84950f5ff0c4f7c588e55944818a (diff)
downloadchrome-ec-96b7e491e80a4cd7a419fa4872dcf7146fc95cf3.tar.gz
cr50: notify chipset hooks when the AP state changes
Cr50 monitors UART1 RX to sense the state of the AP. This signal can be used to tell if it is in S0. If the signal is pulled up then the AP is on. If it is not pulled up then the AP is not in S0. This change notifies HOOK_CHIPSET_SUSPEND when UART1 RX is not pulled up, and then notifies HOOK_CHIPSET_RESUME when the signal is high again. The AP usb can be disabled during suspend, so this change changes the hook that triggers disabling the AP usb to be attached to HOOK_CHIPSET_SUSPEND instead of HOOK_CHIPSET_RESUME. BUG=chrome-os-partner:55747 BRANCH=none TEST=buildall Change-Id: I47fb38a4bbcd72424ec2535d61e87f820cf1bcd7 Signed-off-by: Mary Ruthven <mruthven@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/383978 Reviewed-by: Bill Richardson <wfrichar@chromium.org>
Diffstat (limited to 'common/device_state.c')
-rw-r--r--common/device_state.c60
1 files changed, 6 insertions, 54 deletions
diff --git a/common/device_state.c b/common/device_state.c
index 0c4024880a..17c32a7054 100644
--- a/common/device_state.c
+++ b/common/device_state.c
@@ -7,8 +7,6 @@
#include "device_state.h"
#include "hooks.h"
-static int enabled = 1;
-
int device_get_state(enum device_type device)
{
return device_states[device].state;
@@ -19,6 +17,9 @@ void device_set_state(enum device_type device, enum device_state state)
if (device_states[device].state == state)
return;
+ if (state != DEVICE_STATE_UNKNOWN)
+ device_states[device].last_known_state = state;
+
device_states[device].state = state;
}
@@ -26,57 +27,11 @@ 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 != 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);
-}
-
-static void enable_interrupts(enum device_type device)
-{
- if (!device_has_interrupts(device))
- return;
-
- /* Enable gpio interrupts */
- gpio_enable_interrupt(device_states[device].detect);
-}
-
-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" :
@@ -87,12 +42,9 @@ 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);
+ for (i = 0; i < DEVICE_COUNT; i++)
+ print_state(device_states[i].name,
+ device_states[i].state);
return EC_SUCCESS;
}