2 +++ b/drivers/watchdog/ar2315-wtd.c
5 + * This program is free software; you can redistribute it and/or modify
6 + * it under the terms of the GNU General Public License as published by
7 + * the Free Software Foundation; either version 2 of the License, or
8 + * (at your option) any later version.
10 + * This program is distributed in the hope that it will be useful,
11 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 + * GNU General Public License for more details.
15 + * You should have received a copy of the GNU General Public License
16 + * along with this program; if not, write to the Free Software
17 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 + * Copyright (C) 2008 John Crispin <blogic@openwrt.org>
20 + * Based on EP93xx and ifxmips wdt driver
23 +#include <linux/interrupt.h>
24 +#include <linux/module.h>
25 +#include <linux/moduleparam.h>
26 +#include <linux/types.h>
27 +#include <linux/miscdevice.h>
28 +#include <linux/watchdog.h>
29 +#include <linux/fs.h>
30 +#include <linux/ioport.h>
31 +#include <linux/notifier.h>
32 +#include <linux/reboot.h>
33 +#include <linux/init.h>
34 +#include <linux/platform_device.h>
37 +#include <asm/uaccess.h>
38 +#include <asm/addrspace.h>
39 +#include <ar231x_platform.h>
40 +#include <ar2315_regs.h>
43 +#define CLOCK_RATE 40000000
44 +#define HEARTBEAT(x) (x < 1 || x > 90)?(20):(x)
46 +static int wdt_timeout = 20;
47 +static int started = 0;
48 +static int in_use = 0;
51 +ar2315_wdt_enable(void)
53 + ar231x_write_reg(AR2315_WD, wdt_timeout * CLOCK_RATE);
54 + ar231x_write_reg(AR2315_ISR, 0x80);
58 +ar2315_wdt_write(struct file *file, const char __user *data, size_t len, loff_t *ppos)
61 + ar2315_wdt_enable();
66 +ar2315_wdt_open(struct inode *inode, struct file *file)
70 + ar2315_wdt_enable();
71 + in_use = started = 1;
72 + return nonseekable_open(inode, file);
76 +ar2315_wdt_release(struct inode *inode, struct file *file)
83 +ar2315_wdt_interrupt(int irq, void *dev_id)
87 + printk(KERN_CRIT "watchdog expired, rebooting system\n");
88 + emergency_restart();
90 + ar231x_write_reg(AR2315_WDC, 0);
91 + ar231x_write_reg(AR2315_WD, 0);
92 + ar231x_write_reg(AR2315_ISR, 0x80);
97 +static struct watchdog_info ident = {
98 + .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING,
99 + .identity = "ar2315 Watchdog",
103 +ar2315_wdt_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
105 + int new_wdt_timeout;
106 + int ret = -ENOIOCTLCMD;
110 + case WDIOC_GETSUPPORT:
111 + ret = copy_to_user((struct watchdog_info __user *)arg, &ident, sizeof(ident)) ? -EFAULT : 0;
114 + case WDIOC_KEEPALIVE:
115 + ar2315_wdt_enable();
119 + case WDIOC_SETTIMEOUT:
120 + if((ret = get_user(new_wdt_timeout, (int __user *)arg)))
122 + wdt_timeout = HEARTBEAT(new_wdt_timeout);
123 + ar2315_wdt_enable();
126 + case WDIOC_GETTIMEOUT:
127 + ret = put_user(wdt_timeout, (int __user *)arg);
133 +static struct file_operations ar2315_wdt_fops = {
134 + .owner = THIS_MODULE,
135 + .llseek = no_llseek,
136 + .write = ar2315_wdt_write,
137 + .unlocked_ioctl = ar2315_wdt_ioctl,
138 + .open = ar2315_wdt_open,
139 + .release = ar2315_wdt_release,
142 +static struct miscdevice ar2315_wdt_miscdev = {
143 + .minor = WATCHDOG_MINOR,
144 + .name = "watchdog",
145 + .fops = &ar2315_wdt_fops,
149 +ar2315_wdt_probe(struct platform_device *dev)
153 + ar2315_wdt_enable();
154 + ret = request_irq(AR531X_MISC_IRQ_WATCHDOG, ar2315_wdt_interrupt, IRQF_DISABLED, "ar2315_wdt", NULL);
157 + printk(KERN_ERR "ar2315wdt: failed to register inetrrupt\n");
161 + ret = misc_register(&ar2315_wdt_miscdev);
163 + printk(KERN_ERR "ar2315wdt: failed to register miscdev\n");
170 +ar2315_wdt_remove(struct platform_device *dev)
172 + misc_deregister(&ar2315_wdt_miscdev);
173 + free_irq(AR531X_MISC_IRQ_WATCHDOG, NULL);
177 +static struct platform_driver ar2315_wdt_driver = {
178 + .probe = ar2315_wdt_probe,
179 + .remove = ar2315_wdt_remove,
181 + .name = "ar2315_wdt",
182 + .owner = THIS_MODULE,
187 +init_ar2315_wdt(void)
189 + int ret = platform_driver_register(&ar2315_wdt_driver);
191 + printk(KERN_INFO "ar2315_wdt: error registering platfom driver!");
196 +exit_ar2315_wdt(void)
198 + platform_driver_unregister(&ar2315_wdt_driver);
201 +module_init(init_ar2315_wdt);
202 +module_exit(exit_ar2315_wdt);
203 --- a/drivers/watchdog/Kconfig
204 +++ b/drivers/watchdog/Kconfig
205 @@ -1113,6 +1113,12 @@ config LANTIQ_WDT
207 Hardware driver for the Lantiq SoC Watchdog Timer.
210 + tristate "Atheros wisoc Watchdog Timer"
211 + depends on ATHEROS_AR231X
213 + Hardware driver for the Atheros wisoc Watchdog Timer.
215 # PARISC Architecture
217 # POWERPC Architecture
218 --- a/drivers/watchdog/Makefile
219 +++ b/drivers/watchdog/Makefile
220 @@ -131,6 +131,7 @@ obj-$(CONFIG_GPIO_WDT) += gpio_wdt.o
221 obj-$(CONFIG_PNX833X_WDT) += pnx833x_wdt.o
222 obj-$(CONFIG_SIBYTE_WDOG) += sb_wdog.o
223 obj-$(CONFIG_AR7_WDT) += ar7_wdt.o
224 +obj-$(CONFIG_ATHEROS_WDT) += ar2315-wtd.o
225 obj-$(CONFIG_TXX9_WDT) += txx9wdt.o
226 obj-$(CONFIG_OCTEON_WDT) += octeon-wdt.o
227 octeon-wdt-y := octeon-wdt-main.o octeon-wdt-nmi.o