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 */