1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2016 Freescale Semiconductor, Inc.
8 #include <asm/arch/imx-regs.h>
11 * MX7ULP WDOG Register Map
22 #ifndef CONFIG_WATCHDOG_TIMEOUT_MSECS
23 #define CONFIG_WATCHDOG_TIMEOUT_MSECS 0x1500
26 #define REFRESH_WORD0 0xA602 /* 1st refresh word */
27 #define REFRESH_WORD1 0xB480 /* 2nd refresh word */
29 #define UNLOCK_WORD0 0xC520 /* 1st unlock word */
30 #define UNLOCK_WORD1 0xD928 /* 2nd unlock word */
32 #define WDGCS1_WDGE (1<<7)
33 #define WDGCS1_WDGUPDATE (1<<5)
35 #define WDGCS2_FLG (1<<6)
37 #define WDG_BUS_CLK (0x0)
38 #define WDG_LPO_CLK (0x1)
39 #define WDG_32KHZ_CLK (0x2)
40 #define WDG_EXT_CLK (0x3)
42 void hw_watchdog_set_timeout(u16 val)
44 /* setting timeout value */
45 struct wdog_regs *wdog = (struct wdog_regs *)WDOG_BASE_ADDR;
47 writel(val, &wdog->toval);
50 void hw_watchdog_reset(void)
52 struct wdog_regs *wdog = (struct wdog_regs *)WDOG_BASE_ADDR;
54 writel(REFRESH_WORD0, &wdog->cnt);
55 writel(REFRESH_WORD1, &wdog->cnt);
58 void hw_watchdog_init(void)
61 struct wdog_regs *wdog = (struct wdog_regs *)WDOG_BASE_ADDR;
63 writel(UNLOCK_WORD0, &wdog->cnt);
64 writel(UNLOCK_WORD1, &wdog->cnt);
66 val = readb(&wdog->cs2);
68 writeb(val, &wdog->cs2);
70 hw_watchdog_set_timeout(CONFIG_WATCHDOG_TIMEOUT_MSECS);
71 writel(0, &wdog->win);
73 writeb(WDG_LPO_CLK, &wdog->cs2);/* setting 1-kHz clock source */
74 writeb((WDGCS1_WDGE | WDGCS1_WDGUPDATE), &wdog->cs1);/* enable counter running */
79 void reset_cpu(ulong addr)
81 struct wdog_regs *wdog = (struct wdog_regs *)WDOG_BASE_ADDR;
83 writel(UNLOCK_WORD0, &wdog->cnt);
84 writel(UNLOCK_WORD1, &wdog->cnt);
86 hw_watchdog_set_timeout(5); /* 5ms timeout */
87 writel(0, &wdog->win);
89 writeb(WDG_LPO_CLK, &wdog->cs2);/* setting 1-kHz clock source */
90 writeb(WDGCS1_WDGE, &wdog->cs1);/* enable counter running */