chip/stm32/clock: Wakeup AP when rtc alarm goes off

BUG=b:63908519
BRANCH=none
TEST='powerd_dbus_suspend --wakeup_timeout=10' and see
AP do S0->S3(10 secs)->S0

Change-Id: I35e248627e2f3b68b0ed3f27d6bae65eb73a745b
Signed-off-by: Philip Chen <philipchen@google.com>
Reviewed-on: https://chromium-review.googlesource.com/674054
Commit-Ready: Philip Chen <philipchen@chromium.org>
Tested-by: Philip Chen <philipchen@chromium.org>
Reviewed-by: Shawn N <shawnn@chromium.org>
This commit is contained in:
Philip Chen
2017-09-19 19:05:49 -07:00
committed by chrome-bot
parent c781609bfd
commit 78f485465f
2 changed files with 21 additions and 0 deletions

View File

@@ -72,6 +72,8 @@ static uint32_t sec_to_rtc_tr(uint32_t sec)
}
#ifdef CONFIG_HOSTCMD_RTC
static uint8_t host_rtc_alarm_set;
static uint32_t rtc_dr_to_sec(uint32_t rtc_dr)
{
struct calendar_date time;
@@ -247,6 +249,13 @@ void __rtc_alarm_irq(void)
struct rtc_time_reg rtc;
reset_rtc_alarm(&rtc);
#ifdef CONFIG_HOSTCMD_RTC
/* Do not wake up the host if the alarm was not set by the host */
if (host_rtc_alarm_set) {
host_set_events(EC_HOST_EVENT_MASK(EC_HOST_EVENT_RTC));
host_rtc_alarm_set = 0;
}
#endif
}
DECLARE_IRQ(STM32_IRQ_RTC_ALARM, __rtc_alarm_irq, 1);
@@ -392,6 +401,7 @@ static int system_rtc_set_alarm(struct host_cmd_handler_args *args)
struct rtc_time_reg rtc;
const struct ec_params_rtc *p = args->params;
host_rtc_alarm_set = 1;
set_rtc_alarm(p->time, 0, &rtc);
return EC_RES_SUCCESS;
}

View File

@@ -313,6 +313,17 @@ void __idle(void)
next_delay = __hw_clock_event_get() - t0.le.lo;
if (DEEP_SLEEP_ALLOWED &&
#ifdef CONFIG_HOSTCMD_RTC
/*
* Don't go to deep sleep mode when the host is using
* RTC alarm otherwise the wake point for the host
* would be overwritten.
*
* TODO(chromium:769503): Find a smart way to enable deep
* sleep mode even when the host is using stm32 rtc alarm.
*/
!(STM32_RTC_CR & STM32_RTC_CR_ALRAE) &&
#endif
(next_delay > (STOP_MODE_LATENCY + SET_RTC_MATCH_DELAY))) {
/* deep-sleep in STOP mode */
idle_dsleep_cnt++;