blob: c9cb53ed4f132c13ca7a9c065c460e5e0a695ec1 [file] [log] [blame]
Macpaul Lin182d9752011-01-26 18:46:28 +08001/*
2 * Watchdog driver for the FTWDT010 Watch Dog Driver
3 *
4 * (c) Copyright 2004 Faraday Technology Corp. (www.faraday-tech.com)
5 * Based on sa1100_wdt.c by Oleg Drokin <green@crimea.edu>
6 * Based on SoftDog driver by Alan Cox <alan@redhat.com>
7 *
8 * Copyright (C) 2011 Andes Technology Corporation
9 * Macpaul Lin, Andes Technology Corporation <macpaul@andestech.com>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 *
25 * 27/11/2004 Initial release, Faraday.
26 * 12/01/2011 Port to u-boot, Macpaul Lin.
27 */
28
29#include <common.h>
30#include <watchdog.h>
31#include <asm/io.h>
Macpaul Linb5a85ec2011-04-12 13:04:02 +080032#include <faraday/ftwdt010_wdt.h>
Macpaul Lin182d9752011-01-26 18:46:28 +080033
34/*
35 * Set the watchdog time interval.
36 * Counter is 32 bit.
37 */
Macpaul Linb5a85ec2011-04-12 13:04:02 +080038int ftwdt010_wdt_settimeout(unsigned int timeout)
Macpaul Lin182d9752011-01-26 18:46:28 +080039{
40 unsigned int reg;
41
42 struct ftwdt010_wdt *wd = (struct ftwdt010_wdt *)CONFIG_FTWDT010_BASE;
43
44 debug("Activating WDT..\n");
45
46 /* Check if disabled */
47 if (readl(&wd->wdcr) & ~FTWDT010_WDCR_ENABLE) {
48 printf("sorry, watchdog is disabled\n");
49 return -1;
50 }
51
52 /*
53 * In a 66MHz system,
54 * if you set WDLOAD as 0x03EF1480 (66000000)
55 * the reset timer is 1 second.
56 */
57 reg = FTWDT010_WDLOAD(timeout * FTWDT010_TIMEOUT_FACTOR);
58
59 writel(reg, &wd->wdload);
60
61 return 0;
62}
63
Macpaul Linb5a85ec2011-04-12 13:04:02 +080064void ftwdt010_wdt_reset(void)
Macpaul Lin182d9752011-01-26 18:46:28 +080065{
66 struct ftwdt010_wdt *wd = (struct ftwdt010_wdt *)CONFIG_FTWDT010_BASE;
67
68 /* clear control register */
69 writel(0, &wd->wdcr);
70
71 /* Write Magic number */
72 writel(FTWDT010_WDRESTART_MAGIC, &wd->wdrestart);
73
74 /* Enable WDT */
75 writel((FTWDT010_WDCR_RST | FTWDT010_WDCR_ENABLE), &wd->wdcr);
76}
77
Macpaul Linb5a85ec2011-04-12 13:04:02 +080078void ftwdt010_wdt_disable(void)
Macpaul Lin182d9752011-01-26 18:46:28 +080079{
80 struct ftwdt010_wdt *wd = (struct ftwdt010_wdt *)CONFIG_FTWDT010_BASE;
81
82 debug("Deactivating WDT..\n");
83
84 /*
85 * It was defined with CONFIG_WATCHDOG_NOWAYOUT in Linux
86 *
87 * Shut off the timer.
88 * Lock it in if it's a module and we defined ...NOWAYOUT
89 */
90 writel(0, &wd->wdcr);
91}
92
Macpaul Linb5a85ec2011-04-12 13:04:02 +080093#if defined(CONFIG_HW_WATCHDOG)
94void hw_watchdog_reset(void)
Macpaul Lin182d9752011-01-26 18:46:28 +080095{
96 ftwdt010_wdt_reset();
97}
98
99void hw_watchdog_init(void)
100{
101 /* set timer in ms */
102 ftwdt010_wdt_settimeout(CONFIG_FTWDT010_HW_TIMEOUT * 1000);
103}
Macpaul Linb5a85ec2011-04-12 13:04:02 +0800104#endif