xref: /openbmc/u-boot/drivers/watchdog/imx_watchdog.c (revision 587c3f8ebe356b558f1876414885c1b4a31294ab)
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>
11f532727dSFabio Estevam #include <fsl_wdog.h>
12abbab703STroy Kisky 
13abbab703STroy Kisky #ifdef CONFIG_IMX_WATCHDOG
14abbab703STroy Kisky void hw_watchdog_reset(void)
15abbab703STroy Kisky {
16abbab703STroy Kisky 	struct watchdog_regs *wdog = (struct watchdog_regs *)WDOG1_BASE_ADDR;
17abbab703STroy Kisky 
18abbab703STroy Kisky 	writew(0x5555, &wdog->wsr);
19abbab703STroy Kisky 	writew(0xaaaa, &wdog->wsr);
20abbab703STroy Kisky }
21abbab703STroy Kisky 
22abbab703STroy Kisky void hw_watchdog_init(void)
23abbab703STroy Kisky {
24abbab703STroy Kisky 	struct watchdog_regs *wdog = (struct watchdog_regs *)WDOG1_BASE_ADDR;
25abbab703STroy Kisky 	u16 timeout;
26abbab703STroy Kisky 
27abbab703STroy Kisky 	/*
28abbab703STroy Kisky 	 * The timer watchdog can be set between
29abbab703STroy Kisky 	 * 0.5 and 128 Seconds. If not defined
30abbab703STroy Kisky 	 * in configuration file, sets 128 Seconds
31abbab703STroy Kisky 	 */
32abbab703STroy Kisky #ifndef CONFIG_WATCHDOG_TIMEOUT_MSECS
33abbab703STroy Kisky #define CONFIG_WATCHDOG_TIMEOUT_MSECS 128000
34abbab703STroy Kisky #endif
35abbab703STroy Kisky 	timeout = (CONFIG_WATCHDOG_TIMEOUT_MSECS / 500) - 1;
36723ec69aSAnatolij Gustschin 	writew(WCR_WDZST | WCR_WDBG | WCR_WDE | WCR_WDT | WCR_SRS |
375cab8740SSebastian Siewior 		SET_WCR_WT(timeout), &wdog->wcr);
38abbab703STroy Kisky 	hw_watchdog_reset();
39abbab703STroy Kisky }
40abbab703STroy Kisky #endif
41abbab703STroy Kisky 
42abbab703STroy Kisky void reset_cpu(ulong addr)
43abbab703STroy Kisky {
44abbab703STroy Kisky 	struct watchdog_regs *wdog = (struct watchdog_regs *)WDOG1_BASE_ADDR;
45abbab703STroy Kisky 
46*587c3f8eSAndrey Skvortsov 	clrsetbits_le16(&wdog->wcr, WCR_WT_MSK, WCR_WDE);
47623d96e8SPeng Fan 
48abbab703STroy Kisky 	writew(0x5555, &wdog->wsr);
49abbab703STroy Kisky 	writew(0xaaaa, &wdog->wsr);	/* load minimum 1/2 second timeout */
50abbab703STroy Kisky 	while (1) {
51abbab703STroy Kisky 		/*
52abbab703STroy Kisky 		 * spin for .5 seconds before reset
53abbab703STroy Kisky 		 */
54abbab703STroy Kisky 	}
55abbab703STroy Kisky }
56