2 * Copyright (C) 2013 Altera Corporation <www.altera.com>
4 * SPDX-License-Identifier: GPL-2.0+
10 #include <asm/utils.h>
12 #define DW_WDT_CR 0x00
13 #define DW_WDT_TORR 0x04
14 #define DW_WDT_CRR 0x0C
16 #define DW_WDT_CR_EN_OFFSET 0x00
17 #define DW_WDT_CR_RMOD_OFFSET 0x01
18 #define DW_WDT_CR_RMOD_VAL 0x00
19 #define DW_WDT_CRR_RESTART_VAL 0x76
22 * Set the watchdog time interval.
25 static int designware_wdt_settimeout(unsigned int timeout)
29 /* calculate the timeout range value */
30 i = (log_2_n_round_up(timeout * CONFIG_DW_WDT_CLOCK_KHZ)) - 16;
36 writel((i | (i << 4)), (CONFIG_DW_WDT_BASE + DW_WDT_TORR));
40 static void designware_wdt_enable(void)
42 writel(((DW_WDT_CR_RMOD_VAL << DW_WDT_CR_RMOD_OFFSET) |
43 (0x1 << DW_WDT_CR_EN_OFFSET)),
44 (CONFIG_DW_WDT_BASE + DW_WDT_CR));
47 static unsigned int designware_wdt_is_enabled(void)
50 val = readl((CONFIG_DW_WDT_BASE + DW_WDT_CR));
54 #if defined(CONFIG_HW_WATCHDOG)
55 void hw_watchdog_reset(void)
57 if (designware_wdt_is_enabled())
58 /* restart the watchdog counter */
59 writel(DW_WDT_CRR_RESTART_VAL,
60 (CONFIG_DW_WDT_BASE + DW_WDT_CRR));
63 void hw_watchdog_init(void)
65 /* reset to disable the watchdog */
67 /* set timer in miliseconds */
68 designware_wdt_settimeout(CONFIG_HW_WATCHDOG_TIMEOUT_MS);
69 /* enable the watchdog */
70 designware_wdt_enable();
71 /* reset the watchdog */