1abbab703STroy Kisky /* 2abbab703STroy Kisky * watchdog.c - driver for i.mx on-chip watchdog 3abbab703STroy Kisky * 4abbab703STroy Kisky * Licensed under the GPL-2 or later. 5abbab703STroy Kisky */ 6abbab703STroy Kisky 7abbab703STroy Kisky #include <common.h> 8abbab703STroy Kisky #include <asm/io.h> 9abbab703STroy Kisky #include <watchdog.h> 10abbab703STroy Kisky #include <asm/arch/imx-regs.h> 11005c1cf8SXiaoliang Yang #ifdef CONFIG_FSL_LSCH2 12005c1cf8SXiaoliang Yang #include <asm/arch/immap_lsch2.h> 13005c1cf8SXiaoliang Yang #endif 14f532727dSFabio Estevam #include <fsl_wdog.h> 15abbab703STroy Kisky 16abbab703STroy Kisky #ifdef CONFIG_IMX_WATCHDOG hw_watchdog_reset(void)17abbab703STroy Kiskyvoid hw_watchdog_reset(void) 18abbab703STroy Kisky { 19*da4918acSXiaoliang Yang #ifndef CONFIG_WATCHDOG_RESET_DISABLE 20abbab703STroy Kisky struct watchdog_regs *wdog = (struct watchdog_regs *)WDOG1_BASE_ADDR; 21abbab703STroy Kisky 22abbab703STroy Kisky writew(0x5555, &wdog->wsr); 23abbab703STroy Kisky writew(0xaaaa, &wdog->wsr); 24*da4918acSXiaoliang Yang #endif /* CONFIG_WATCHDOG_RESET_DISABLE*/ 25abbab703STroy Kisky } 26abbab703STroy Kisky hw_watchdog_init(void)27abbab703STroy Kiskyvoid hw_watchdog_init(void) 28abbab703STroy Kisky { 29abbab703STroy Kisky struct watchdog_regs *wdog = (struct watchdog_regs *)WDOG1_BASE_ADDR; 30abbab703STroy Kisky u16 timeout; 31abbab703STroy Kisky 32abbab703STroy Kisky /* 33abbab703STroy Kisky * The timer watchdog can be set between 34abbab703STroy Kisky * 0.5 and 128 Seconds. If not defined 35abbab703STroy Kisky * in configuration file, sets 128 Seconds 36abbab703STroy Kisky */ 37abbab703STroy Kisky #ifndef CONFIG_WATCHDOG_TIMEOUT_MSECS 38abbab703STroy Kisky #define CONFIG_WATCHDOG_TIMEOUT_MSECS 128000 39abbab703STroy Kisky #endif 40abbab703STroy Kisky timeout = (CONFIG_WATCHDOG_TIMEOUT_MSECS / 500) - 1; 41005c1cf8SXiaoliang Yang #ifdef CONFIG_FSL_LSCH2 42005c1cf8SXiaoliang Yang writew((WCR_WDA | WCR_SRS | WCR_WDE) << 8 | timeout, &wdog->wcr); 43005c1cf8SXiaoliang Yang #else 44723ec69aSAnatolij Gustschin writew(WCR_WDZST | WCR_WDBG | WCR_WDE | WCR_WDT | WCR_SRS | 459eeab572SRoss Parker WCR_WDA | SET_WCR_WT(timeout), &wdog->wcr); 46005c1cf8SXiaoliang Yang #endif /* CONFIG_FSL_LSCH2*/ 47abbab703STroy Kisky hw_watchdog_reset(); 48abbab703STroy Kisky } 49abbab703STroy Kisky #endif 50abbab703STroy Kisky reset_cpu(ulong addr)518b248c8cSStefan Agnervoid __attribute__((weak)) reset_cpu(ulong addr) 52abbab703STroy Kisky { 53abbab703STroy Kisky struct watchdog_regs *wdog = (struct watchdog_regs *)WDOG1_BASE_ADDR; 54abbab703STroy Kisky 55587c3f8eSAndrey Skvortsov clrsetbits_le16(&wdog->wcr, WCR_WT_MSK, WCR_WDE); 56623d96e8SPeng Fan 57abbab703STroy Kisky writew(0x5555, &wdog->wsr); 58abbab703STroy Kisky writew(0xaaaa, &wdog->wsr); /* load minimum 1/2 second timeout */ 59abbab703STroy Kisky while (1) { 60abbab703STroy Kisky /* 61abbab703STroy Kisky * spin for .5 seconds before reset 62abbab703STroy Kisky */ 63abbab703STroy Kisky } 64abbab703STroy Kisky } 65