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, see <http://www.gnu.org/licenses/>.
18 + * Copyright (C) 2008 John Crispin <blogic@openwrt.org>
19 + * Based on EP93xx and ifxmips wdt driver
22 +#include <linux/interrupt.h>
23 +#include <linux/module.h>
24 +#include <linux/moduleparam.h>
25 +#include <linux/types.h>
26 +#include <linux/miscdevice.h>
27 +#include <linux/watchdog.h>
28 +#include <linux/fs.h>
29 +#include <linux/ioport.h>
30 +#include <linux/notifier.h>
31 +#include <linux/reboot.h>
32 +#include <linux/init.h>
33 +#include <linux/platform_device.h>
34 +#include <linux/io.h>
35 +#include <linux/uaccess.h>
37 +#define DRIVER_NAME "ar2315-wdt"
39 +#define CLOCK_RATE 40000000
40 +#define HEARTBEAT(x) (x < 1 || x > 90 ? 20 : x)
42 +#define WDT_REG_TIMER 0x00
43 +#define WDT_REG_CTRL 0x04
45 +#define WDT_CTRL_ACT_NONE 0x00000000 /* No action */
46 +#define WDT_CTRL_ACT_NMI 0x00000001 /* NMI on watchdog */
47 +#define WDT_CTRL_ACT_RESET 0x00000002 /* reset on watchdog */
49 +static int wdt_timeout = 20;
52 +static void __iomem *wdt_base;
54 +static inline void ar2315_wdt_wr(unsigned reg, u32 val)
56 + iowrite32(val, wdt_base + reg);
60 +ar2315_wdt_enable(void)
62 + ar2315_wdt_wr(WDT_REG_TIMER, wdt_timeout * CLOCK_RATE);
66 +ar2315_wdt_write(struct file *file, const char __user *data, size_t len,
70 + ar2315_wdt_enable();
75 +ar2315_wdt_open(struct inode *inode, struct file *file)
79 + ar2315_wdt_enable();
80 + in_use = started = 1;
81 + return nonseekable_open(inode, file);
85 +ar2315_wdt_release(struct inode *inode, struct file *file)
92 +ar2315_wdt_interrupt(int irq, void *dev)
94 + struct platform_device *pdev = (struct platform_device *)dev;
97 + dev_crit(&pdev->dev, "watchdog expired, rebooting system\n");
98 + emergency_restart();
100 + ar2315_wdt_wr(WDT_REG_CTRL, 0);
101 + ar2315_wdt_wr(WDT_REG_TIMER, 0);
103 + return IRQ_HANDLED;
106 +static struct watchdog_info ident = {
107 + .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING,
108 + .identity = "ar2315 Watchdog",
112 +ar2315_wdt_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
114 + int new_wdt_timeout;
115 + int ret = -ENOIOCTLCMD;
118 + case WDIOC_GETSUPPORT:
119 + ret = copy_to_user((void __user *)arg, &ident, sizeof(ident)) ?
122 + case WDIOC_KEEPALIVE:
123 + ar2315_wdt_enable();
126 + case WDIOC_SETTIMEOUT:
127 + ret = get_user(new_wdt_timeout, (int __user *)arg);
130 + wdt_timeout = HEARTBEAT(new_wdt_timeout);
131 + ar2315_wdt_enable();
133 + case WDIOC_GETTIMEOUT:
134 + ret = put_user(wdt_timeout, (int __user *)arg);
140 +static const struct file_operations ar2315_wdt_fops = {
141 + .owner = THIS_MODULE,
142 + .llseek = no_llseek,
143 + .write = ar2315_wdt_write,
144 + .unlocked_ioctl = ar2315_wdt_ioctl,
145 + .open = ar2315_wdt_open,
146 + .release = ar2315_wdt_release,
149 +static struct miscdevice ar2315_wdt_miscdev = {
150 + .minor = WATCHDOG_MINOR,
151 + .name = "watchdog",
152 + .fops = &ar2315_wdt_fops,
156 +ar2315_wdt_probe(struct platform_device *dev)
158 + struct resource *mem_res, *irq_res;
164 + irq_res = platform_get_resource(dev, IORESOURCE_IRQ, 0);
166 + dev_err(&dev->dev, "no IRQ resource\n");
170 + mem_res = platform_get_resource(dev, IORESOURCE_MEM, 0);
171 + wdt_base = devm_ioremap_resource(&dev->dev, mem_res);
172 + if (IS_ERR(wdt_base))
173 + return PTR_ERR(wdt_base);
175 + ret = devm_request_irq(&dev->dev, irq_res->start, ar2315_wdt_interrupt,
176 + IRQF_DISABLED, DRIVER_NAME, dev);
178 + dev_err(&dev->dev, "failed to register inetrrupt\n");
182 + ret = misc_register(&ar2315_wdt_miscdev);
184 + dev_err(&dev->dev, "failed to register miscdev\n");
191 +ar2315_wdt_remove(struct platform_device *dev)
193 + misc_deregister(&ar2315_wdt_miscdev);
197 +static struct platform_driver ar2315_wdt_driver = {
198 + .probe = ar2315_wdt_probe,
199 + .remove = ar2315_wdt_remove,
201 + .name = DRIVER_NAME,
202 + .owner = THIS_MODULE,
206 +module_platform_driver(ar2315_wdt_driver);
208 +MODULE_DESCRIPTION("Atheros AR2315 hardware watchdog driver");
209 +MODULE_AUTHOR("John Crispin <blogic@openwrt.org>");
210 +MODULE_LICENSE("GPL");
211 +MODULE_ALIAS("platform:" DRIVER_NAME);
212 --- a/drivers/watchdog/Kconfig
213 +++ b/drivers/watchdog/Kconfig
214 @@ -1202,6 +1202,13 @@ config RALINK_WDT
216 Hardware driver for the Ralink SoC Watchdog Timer.
219 + tristate "Atheros AR2315+ WiSoCs Watchdog Timer"
220 + depends on ATHEROS_AR231X
222 + Hardware driver for the built-in watchdog timer on the Atheros
223 + AR2315/AR2316 WiSoCs.
225 # PARISC Architecture
227 # POWERPC Architecture
228 --- a/drivers/watchdog/Makefile
229 +++ b/drivers/watchdog/Makefile
230 @@ -134,6 +134,7 @@ obj-$(CONFIG_GPIO_WDT) += old_gpio_wdt.o
231 obj-$(CONFIG_PNX833X_WDT) += pnx833x_wdt.o
232 obj-$(CONFIG_SIBYTE_WDOG) += sb_wdog.o
233 obj-$(CONFIG_AR7_WDT) += ar7_wdt.o
234 +obj-$(CONFIG_AR2315_WDT) += ar2315-wtd.o
235 obj-$(CONFIG_TXX9_WDT) += txx9wdt.o
236 obj-$(CONFIG_OCTEON_WDT) += octeon-wdt.o
237 octeon-wdt-y := octeon-wdt-main.o octeon-wdt-nmi.o