1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2016 Freescale Semiconductor, Inc.
9 #include <asm/arch/imx-regs.h>
12 * MX7ULP WDOG Register Map
23 #ifndef CONFIG_WATCHDOG_TIMEOUT_MSECS
24 #define CONFIG_WATCHDOG_TIMEOUT_MSECS 0x1500
27 #define REFRESH_WORD0 0xA602 /* 1st refresh word */
28 #define REFRESH_WORD1 0xB480 /* 2nd refresh word */
30 #define UNLOCK_WORD0 0xC520 /* 1st unlock word */
31 #define UNLOCK_WORD1 0xD928 /* 2nd unlock word */
33 #define WDGCS1_WDGE (1<<7)
34 #define WDGCS1_WDGUPDATE (1<<5)
36 #define WDGCS2_FLG (1<<6)
38 #define WDG_BUS_CLK (0x0)
39 #define WDG_LPO_CLK (0x1)
40 #define WDG_32KHZ_CLK (0x2)
41 #define WDG_EXT_CLK (0x3)
43 void hw_watchdog_set_timeout(u16 val)
45 /* setting timeout value */
46 struct wdog_regs *wdog = (struct wdog_regs *)WDOG_BASE_ADDR;
48 writel(val, &wdog->toval);
51 void hw_watchdog_reset(void)
53 struct wdog_regs *wdog = (struct wdog_regs *)WDOG_BASE_ADDR;
55 writel(REFRESH_WORD0, &wdog->cnt);
56 writel(REFRESH_WORD1, &wdog->cnt);
59 void hw_watchdog_init(void)
62 struct wdog_regs *wdog = (struct wdog_regs *)WDOG_BASE_ADDR;
64 writel(UNLOCK_WORD0, &wdog->cnt);
65 writel(UNLOCK_WORD1, &wdog->cnt);
67 val = readb(&wdog->cs2);
69 writeb(val, &wdog->cs2);
71 hw_watchdog_set_timeout(CONFIG_WATCHDOG_TIMEOUT_MSECS);
72 writel(0, &wdog->win);
74 writeb(WDG_LPO_CLK, &wdog->cs2);/* setting 1-kHz clock source */
75 writeb((WDGCS1_WDGE | WDGCS1_WDGUPDATE), &wdog->cs1);/* enable counter running */
82 struct wdog_regs *wdog = (struct wdog_regs *)WDOG_BASE_ADDR;
84 writel(UNLOCK_WORD0, &wdog->cnt);
85 writel(UNLOCK_WORD1, &wdog->cnt);
87 hw_watchdog_set_timeout(5); /* 5ms timeout */
88 writel(0, &wdog->win);
90 writeb(WDG_LPO_CLK, &wdog->cs2);/* setting 1-kHz clock source */
91 writeb(WDGCS1_WDGE, &wdog->cs1);/* enable counter running */