From c0f6ac5e02cdb7a25f593af6dce7b0eea71d996d Mon Sep 17 00:00:00 2001 From: Mary Ruthven Date: Thu, 14 Jul 2016 18:43:12 -0700 Subject: [PATCH] g: disable usb wakeup when debug accessory is disconnected USB is only used for CCD. USB should not be enabled as a wakeup source unless a debug accessory is detected, because that is the only USB traffic we care about. The rest may be from other sources like the HID interface or something else using those signals. This change disables the utmi wake source when the debug accessory is attached and enables it when it is connected. BUG=chrome-os-partner:54796 BRANCH=none TEST=manual The SPI_CS_L pin still gets triggered and will wake up cr50 before usb so disable wake up pins as a wakeup source. Verify Cr50 goes to sleep and plugging in a SuzyQ will wake it up and after removing it Cr50 will go back to sleep. Change-Id: Ib97244016b0af244c340259915def9f4d8f97569 Signed-off-by: Mary Ruthven Reviewed-on: https://chromium-review.googlesource.com/360693 Reviewed-by: Aseda Aboagye Reviewed-by: Bill Richardson --- board/cr50/rdd.c | 12 +++++++++++- chip/g/idle.c | 14 +++++++++++++- chip/g/rdd.h | 7 +++++++ 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/board/cr50/rdd.c b/board/cr50/rdd.c index 2aab5be6a3..40a3cb08b7 100644 --- a/board/cr50/rdd.c +++ b/board/cr50/rdd.c @@ -14,7 +14,7 @@ #define CPRINTS(format, args...) cprints(CC_USB, format, ## args) -static int uart_enabled; +static int uart_enabled, enable_usb_wakeup; struct uart_config { const char *name; @@ -32,6 +32,12 @@ static int ccd_is_enabled(void) return !gpio_get_level(GPIO_CCD_MODE_L); } +int is_utmi_wakeup_allowed(void) +{ + return enable_usb_wakeup; +} + + /* If the UART TX is enabled the pinmux select will have a non-zero value */ int uartn_enabled(int uart) { @@ -89,6 +95,8 @@ void rdd_attached(void) /* Enable CCD */ ccd_set_mode(CCD_MODE_ENABLED); + enable_usb_wakeup = 1; + /* Enable device state monitoring */ device_detect_state_enable(1); } @@ -109,6 +117,8 @@ void rdd_detached(void) /* Done with case-closed debug mode */ gpio_set_level(GPIO_CCD_MODE_L, 1); + enable_usb_wakeup = 0; + /* Disable CCD */ ccd_set_mode(CCD_MODE_DISABLED); } diff --git a/chip/g/idle.c b/chip/g/idle.c index dc003d3eef..68e2e16678 100644 --- a/chip/g/idle.c +++ b/chip/g/idle.c @@ -5,6 +5,7 @@ #include "common.h" #include "console.h" +#include "rdd.h" #include "registers.h" #include "system.h" #include "task.h" @@ -47,6 +48,14 @@ DECLARE_CONSOLE_COMMAND(idle, command_idle, "Set or show the idle action: wfi, sleep, deep sleep", NULL); +static int utmi_wakeup_is_enabled(void) +{ +#ifdef CONFIG_RDD + return is_utmi_wakeup_allowed(); +#endif + return 1; +} + static void prepare_to_sleep(void) { /* No task switching! */ @@ -55,11 +64,14 @@ static void prepare_to_sleep(void) /* Enable all possible internal wake sources */ GR_PMU_EXITPD_MASK = GC_PMU_EXITPD_MASK_PIN_PD_EXIT_MASK | - GC_PMU_EXITPD_MASK_UTMI_SUSPEND_N_MASK | GC_PMU_EXITPD_MASK_RDD0_PD_EXIT_TIMER_MASK | GC_PMU_EXITPD_MASK_TIMELS0_PD_EXIT_TIMER0_MASK | GC_PMU_EXITPD_MASK_TIMELS0_PD_EXIT_TIMER1_MASK; + if (utmi_wakeup_is_enabled()) + GR_PMU_EXITPD_MASK |= + GC_PMU_EXITPD_MASK_UTMI_SUSPEND_N_MASK; + /* Which rails should we turn off? */ GR_PMU_LOW_POWER_DIS = GC_PMU_LOW_POWER_DIS_VDDIOF_MASK | diff --git a/chip/g/rdd.h b/chip/g/rdd.h index 53dd687a16..1f19ee9b3e 100644 --- a/chip/g/rdd.h +++ b/chip/g/rdd.h @@ -11,4 +11,11 @@ void rdd_detached(void); /* Attach to debug cable */ void rdd_attached(void); + +/* + * USB is only used for CCD, so only enable UTMI wakeups when RDD detects that + * a debug accessory is attached and disable it as a wakeup source when the + * cable is detached. + */ +int is_utmi_wakeup_allowed(void); #endif /* __CROS_RDD_H */