From b72178b6ec7ed9213b687d837d87e78ff6f28f52 Mon Sep 17 00:00:00 2001 From: Mulin Chao Date: Fri, 19 May 2017 13:32:12 +0800 Subject: [PATCH] npcx: system: Fixed bug that ec received unexpected rtc interrupt In old system driver, ec clears "Predefined Time Occurred" (PTO) flag before setting a new alarm (PT field in WTC). If PT field is the same as the first 25 TTC bits at this moment, we might receive unexpected rtc interrupt again. This CL sets new alarm first then clears PTO flag to make sure rtc interrupt is issued from new alarm. BRANCH=none BUG=b:38310685 TEST=Duplicated the same symptom by the script in issue 38310685 on gru. No symptoms occurred with the same script for 3 hours by applying this CL. Change-Id: Ia6410d6aa4ef8e2acb7bfadf9192d619045bfa58 Signed-off-by: Mulin Chao Reviewed-on: https://chromium-review.googlesource.com/508572 Commit-Ready: Philip Chen Tested-by: Philip Chen Reviewed-by: Aseda Aboagye --- chip/npcx/system.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/chip/npcx/system.c b/chip/npcx/system.c index eda899d833..bce7b17e09 100644 --- a/chip/npcx/system.c +++ b/chip/npcx/system.c @@ -418,12 +418,15 @@ void system_set_rtc_alarm(uint32_t seconds, uint32_t microseconds) alarm_secs = cur_secs + seconds; alarm_secs = alarm_secs & MTC_ALARM_MASK; + /* + * We should set new alarm (first 25 bits of clock value) first before + * clearing PTO in case issue rtc interrupt immediately. + */ + NPCX_WTC = alarm_secs; + /* Reset alarm first */ system_reset_rtc_alarm(); - /* Set alarm, use first 25 bits of clock value */ - NPCX_WTC = alarm_secs; - /* Enable interrupt mode alarm */ SET_BIT(NPCX_WTC, NPCX_WTC_WIE);