From 3f02192460f5c647f6539de161e36d5b4392567b Mon Sep 17 00:00:00 2001 From: "Vic (Chun-Ju) Yang" Date: Thu, 28 Nov 2013 12:08:40 +0800 Subject: mec1322: Check/save reset cause So far we can only reliably sense a watchdog reset, but this saving/checking reset cause will at least make 'ap-off' flag work. BUG=chrome-os-partner:24107 TEST='waitms 2000' and see reset cause = 'watchdog' TEST='reboot ap-off' and see reset cause includes 'ap-off' TEST='reboot preserve' and see previous reset cause is preserved. BRANCH=None Change-Id: Id47a72d615489c9d9cd0b8761cfa699f08c724df Signed-off-by: Vic (Chun-Ju) Yang Reviewed-on: https://chromium-review.googlesource.com/178277 Reviewed-by: Vincent Palatin --- chip/mec1322/system.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'chip/mec1322/system.c') diff --git a/chip/mec1322/system.c b/chip/mec1322/system.c index 62c08e028d..7425ccc30f 100644 --- a/chip/mec1322/system.c +++ b/chip/mec1322/system.c @@ -22,7 +22,25 @@ enum hibdata_index { HIBDATA_INDEX_SAVED_RESET_FLAGS /* Saved reset flags */ }; +static void check_reset_cause(void) +{ + uint32_t status = MEC1322_VBAT_STS; + uint32_t flags = 0; + + /* Clear the reset causes now that we've read them */ + MEC1322_VBAT_STS |= status; + + if (status & (1 << 7)) + flags |= RESET_FLAG_POWER_ON; + + if (status & (1 << 5)) + flags |= RESET_FLAG_WATCHDOG; + flags |= MEC1322_VBAT_RAM(HIBDATA_INDEX_SAVED_RESET_FLAGS); + MEC1322_VBAT_RAM(HIBDATA_INDEX_SAVED_RESET_FLAGS) = 0; + + system_set_reset_flags(flags); +} void system_pre_init(void) { @@ -31,13 +49,33 @@ void system_pre_init(void) /* Deassert nSIO_RESET */ MEC1322_PCR_PWR_RST_CTL &= ~(1 << 0); + + check_reset_cause(); } void system_reset(int flags) { + uint32_t save_flags = 0; + + /* Disable interrupts to avoid task swaps during reboot */ + interrupt_disable(); + + /* Save current reset reasons if necessary */ + if (flags & SYSTEM_RESET_PRESERVE_FLAGS) + save_flags = system_get_reset_flags() | RESET_FLAG_PRESERVED; + + if (flags & SYSTEM_RESET_LEAVE_AP_OFF) + save_flags |= RESET_FLAG_AP_OFF; + + MEC1322_VBAT_RAM(HIBDATA_INDEX_SAVED_RESET_FLAGS) = save_flags; + /* Trigger watchdog in 1ms */ MEC1322_WDG_LOAD = 1; MEC1322_WDG_CTL |= 1; + + /* Spin and wait for reboot; should never return */ + while (1) + ; } const char *system_get_chip_vendor(void) -- cgit v1.2.1