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> 11abbab703STroy Kisky 12abbab703STroy Kisky struct watchdog_regs { 13abbab703STroy Kisky u16 wcr; /* Control */ 14abbab703STroy Kisky u16 wsr; /* Service */ 15abbab703STroy Kisky u16 wrsr; /* Reset Status */ 16abbab703STroy Kisky }; 17abbab703STroy Kisky 18abbab703STroy Kisky #define WCR_WDZST 0x01 19abbab703STroy Kisky #define WCR_WDBG 0x02 20abbab703STroy Kisky #define WCR_WDE 0x04 /* WDOG enable */ 21abbab703STroy Kisky #define WCR_WDT 0x08 22723ec69aSAnatolij Gustschin #define WCR_SRS 0x10 23abbab703STroy Kisky #define SET_WCR_WT(x) (x << 8) 24abbab703STroy Kisky 25abbab703STroy Kisky #ifdef CONFIG_IMX_WATCHDOG 26abbab703STroy Kisky void hw_watchdog_reset(void) 27abbab703STroy Kisky { 28abbab703STroy Kisky struct watchdog_regs *wdog = (struct watchdog_regs *)WDOG1_BASE_ADDR; 29abbab703STroy Kisky 30abbab703STroy Kisky writew(0x5555, &wdog->wsr); 31abbab703STroy Kisky writew(0xaaaa, &wdog->wsr); 32abbab703STroy Kisky } 33abbab703STroy Kisky 34abbab703STroy Kisky void hw_watchdog_init(void) 35abbab703STroy Kisky { 36abbab703STroy Kisky struct watchdog_regs *wdog = (struct watchdog_regs *)WDOG1_BASE_ADDR; 37abbab703STroy Kisky u16 timeout; 38abbab703STroy Kisky 39abbab703STroy Kisky /* 40abbab703STroy Kisky * The timer watchdog can be set between 41abbab703STroy Kisky * 0.5 and 128 Seconds. If not defined 42abbab703STroy Kisky * in configuration file, sets 128 Seconds 43abbab703STroy Kisky */ 44abbab703STroy Kisky #ifndef CONFIG_WATCHDOG_TIMEOUT_MSECS 45abbab703STroy Kisky #define CONFIG_WATCHDOG_TIMEOUT_MSECS 128000 46abbab703STroy Kisky #endif 47abbab703STroy Kisky timeout = (CONFIG_WATCHDOG_TIMEOUT_MSECS / 500) - 1; 48723ec69aSAnatolij Gustschin writew(WCR_WDZST | WCR_WDBG | WCR_WDE | WCR_WDT | WCR_SRS | 495cab8740SSebastian Siewior SET_WCR_WT(timeout), &wdog->wcr); 50abbab703STroy Kisky hw_watchdog_reset(); 51abbab703STroy Kisky } 52abbab703STroy Kisky #endif 53abbab703STroy Kisky 54abbab703STroy Kisky void reset_cpu(ulong addr) 55abbab703STroy Kisky { 56abbab703STroy Kisky struct watchdog_regs *wdog = (struct watchdog_regs *)WDOG1_BASE_ADDR; 57abbab703STroy Kisky 58*623d96e8SPeng Fan clrsetbits_le16(&wdog->wcr, 0, WCR_WDE); 59*623d96e8SPeng Fan 60abbab703STroy Kisky writew(0x5555, &wdog->wsr); 61abbab703STroy Kisky writew(0xaaaa, &wdog->wsr); /* load minimum 1/2 second timeout */ 62abbab703STroy Kisky while (1) { 63abbab703STroy Kisky /* 64abbab703STroy Kisky * spin for .5 seconds before reset 65abbab703STroy Kisky */ 66abbab703STroy Kisky } 67abbab703STroy Kisky } 68