]> git.sur5r.net Git - u-boot/blob - drivers/watchdog/ftwdt010_wdt.c
SPDX: Convert all of our single license tags to Linux Kernel style
[u-boot] / drivers / watchdog / ftwdt010_wdt.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Watchdog driver for the FTWDT010 Watch Dog Driver
4  *
5  * (c) Copyright 2004 Faraday Technology Corp. (www.faraday-tech.com)
6  * Based on sa1100_wdt.c by Oleg Drokin <green@crimea.edu>
7  * Based on SoftDog driver by Alan Cox <alan@redhat.com>
8  *
9  * Copyright (C) 2011 Andes Technology Corporation
10  * Macpaul Lin, Andes Technology Corporation <macpaul@andestech.com>
11  *
12  * 27/11/2004 Initial release, Faraday.
13  * 12/01/2011 Port to u-boot, Macpaul Lin.
14  */
15
16 #include <common.h>
17 #include <watchdog.h>
18 #include <asm/io.h>
19 #include <faraday/ftwdt010_wdt.h>
20
21 /*
22  * Set the watchdog time interval.
23  * Counter is 32 bit.
24  */
25 int ftwdt010_wdt_settimeout(unsigned int timeout)
26 {
27         unsigned int reg;
28
29         struct ftwdt010_wdt *wd = (struct ftwdt010_wdt *)CONFIG_FTWDT010_BASE;
30
31         debug("Activating WDT..\n");
32
33         /* Check if disabled */
34         if (readl(&wd->wdcr) & ~FTWDT010_WDCR_ENABLE) {
35                 printf("sorry, watchdog is disabled\n");
36                 return -1;
37         }
38
39         /*
40          * In a 66MHz system,
41          * if you set WDLOAD as 0x03EF1480 (66000000)
42          * the reset timer is 1 second.
43          */
44         reg = FTWDT010_WDLOAD(timeout * FTWDT010_TIMEOUT_FACTOR);
45
46         writel(reg, &wd->wdload);
47
48         return 0;
49 }
50
51 void ftwdt010_wdt_reset(void)
52 {
53         struct ftwdt010_wdt *wd = (struct ftwdt010_wdt *)CONFIG_FTWDT010_BASE;
54
55         /* clear control register */
56         writel(0, &wd->wdcr);
57
58         /* Write Magic number */
59         writel(FTWDT010_WDRESTART_MAGIC, &wd->wdrestart);
60
61         /* Enable WDT */
62         writel((FTWDT010_WDCR_RST | FTWDT010_WDCR_ENABLE), &wd->wdcr);
63 }
64
65 void ftwdt010_wdt_disable(void)
66 {
67         struct ftwdt010_wdt *wd = (struct ftwdt010_wdt *)CONFIG_FTWDT010_BASE;
68
69         debug("Deactivating WDT..\n");
70
71         /*
72          * It was defined with CONFIG_WATCHDOG_NOWAYOUT in Linux
73          *
74          * Shut off the timer.
75          * Lock it in if it's a module and we defined ...NOWAYOUT
76          */
77         writel(0, &wd->wdcr);
78 }
79
80 #if defined(CONFIG_HW_WATCHDOG)
81 void hw_watchdog_reset(void)
82 {
83         ftwdt010_wdt_reset();
84 }
85
86 void hw_watchdog_init(void)
87 {
88         /* set timer in ms */
89         ftwdt010_wdt_settimeout(CONFIG_FTWDT010_HW_TIMEOUT * 1000);
90 }
91 #endif