watchdog: driver support for fsl-lsch2
[oweals/u-boot.git] / drivers / watchdog / imx_watchdog.c
1 /*
2  * watchdog.c - driver for i.mx on-chip watchdog
3  *
4  * Licensed under the GPL-2 or later.
5  */
6
7 #include <common.h>
8 #include <asm/io.h>
9 #include <watchdog.h>
10 #include <asm/arch/imx-regs.h>
11 #ifdef CONFIG_FSL_LSCH2
12 #include <asm/arch/immap_lsch2.h>
13 #endif
14 #include <fsl_wdog.h>
15
16 #ifdef CONFIG_IMX_WATCHDOG
17 void hw_watchdog_reset(void)
18 {
19         struct watchdog_regs *wdog = (struct watchdog_regs *)WDOG1_BASE_ADDR;
20
21         writew(0x5555, &wdog->wsr);
22         writew(0xaaaa, &wdog->wsr);
23 }
24
25 void hw_watchdog_init(void)
26 {
27         struct watchdog_regs *wdog = (struct watchdog_regs *)WDOG1_BASE_ADDR;
28         u16 timeout;
29
30         /*
31          * The timer watchdog can be set between
32          * 0.5 and 128 Seconds. If not defined
33          * in configuration file, sets 128 Seconds
34          */
35 #ifndef CONFIG_WATCHDOG_TIMEOUT_MSECS
36 #define CONFIG_WATCHDOG_TIMEOUT_MSECS 128000
37 #endif
38         timeout = (CONFIG_WATCHDOG_TIMEOUT_MSECS / 500) - 1;
39 #ifdef CONFIG_FSL_LSCH2
40         writew((WCR_WDA | WCR_SRS | WCR_WDE) << 8 | timeout, &wdog->wcr);
41 #else
42         writew(WCR_WDZST | WCR_WDBG | WCR_WDE | WCR_WDT | WCR_SRS |
43                 WCR_WDA | SET_WCR_WT(timeout), &wdog->wcr);
44 #endif /* CONFIG_FSL_LSCH2*/
45         hw_watchdog_reset();
46 }
47 #endif
48
49 void __attribute__((weak)) reset_cpu(ulong addr)
50 {
51         struct watchdog_regs *wdog = (struct watchdog_regs *)WDOG1_BASE_ADDR;
52
53         clrsetbits_le16(&wdog->wcr, WCR_WT_MSK, WCR_WDE);
54
55         writew(0x5555, &wdog->wsr);
56         writew(0xaaaa, &wdog->wsr);     /* load minimum 1/2 second timeout */
57         while (1) {
58                 /*
59                  * spin for .5 seconds before reset
60                  */
61         }
62 }