atheros[ar2315-wdt]: update initialization
[openwrt/openwrt.git] / target / linux / atheros / patches-3.10 / 130-watchdog.patch
1 --- /dev/null
2 +++ b/drivers/watchdog/ar2315-wtd.c
3 @@ -0,0 +1,189 @@
4 +/*
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.
9 + *
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.
14 + *
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
18 + *
19 + * Copyright (C) 2008 John Crispin <blogic@openwrt.org>
20 + * Based on EP93xx and ifxmips wdt driver
21 + */
22 +
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>
35 +#include <linux/io.h>
36 +#include <linux/uaccess.h>
37 +
38 +#include <ar231x_platform.h>
39 +#include <ar2315_regs.h>
40 +#include <ar231x.h>
41 +
42 +#define DRIVER_NAME "ar2315-wdt"
43 +
44 +#define CLOCK_RATE 40000000
45 +#define HEARTBEAT(x) (x < 1 || x > 90 ? 20 : x)
46 +
47 +static int wdt_timeout = 20;
48 +static int started;
49 +static int in_use;
50 +
51 +static void
52 +ar2315_wdt_enable(void)
53 +{
54 + ar231x_write_reg(AR2315_WD, wdt_timeout * CLOCK_RATE);
55 + ar231x_write_reg(AR2315_ISR, 0x80);
56 +}
57 +
58 +static ssize_t
59 +ar2315_wdt_write(struct file *file, const char __user *data, size_t len,
60 + loff_t *ppos)
61 +{
62 + if (len)
63 + ar2315_wdt_enable();
64 + return len;
65 +}
66 +
67 +static int
68 +ar2315_wdt_open(struct inode *inode, struct file *file)
69 +{
70 + if (in_use)
71 + return -EBUSY;
72 + ar2315_wdt_enable();
73 + in_use = started = 1;
74 + return nonseekable_open(inode, file);
75 +}
76 +
77 +static int
78 +ar2315_wdt_release(struct inode *inode, struct file *file)
79 +{
80 + in_use = 0;
81 + return 0;
82 +}
83 +
84 +static irqreturn_t
85 +ar2315_wdt_interrupt(int irq, void *dev)
86 +{
87 + struct platform_device *pdev = (struct platform_device *)dev;
88 +
89 + if (started) {
90 + dev_crit(&pdev->dev, "watchdog expired, rebooting system\n");
91 + emergency_restart();
92 + } else {
93 + ar231x_write_reg(AR2315_WDC, 0);
94 + ar231x_write_reg(AR2315_WD, 0);
95 + ar231x_write_reg(AR2315_ISR, 0x80);
96 + }
97 + return IRQ_HANDLED;
98 +}
99 +
100 +static struct watchdog_info ident = {
101 + .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING,
102 + .identity = "ar2315 Watchdog",
103 +};
104 +
105 +static long
106 +ar2315_wdt_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
107 +{
108 + int new_wdt_timeout;
109 + int ret = -ENOIOCTLCMD;
110 +
111 + switch (cmd) {
112 + case WDIOC_GETSUPPORT:
113 + ret = copy_to_user((void __user *)arg, &ident, sizeof(ident)) ?
114 + -EFAULT : 0;
115 + break;
116 + case WDIOC_KEEPALIVE:
117 + ar2315_wdt_enable();
118 + ret = 0;
119 + break;
120 + case WDIOC_SETTIMEOUT:
121 + ret = get_user(new_wdt_timeout, (int __user *)arg);
122 + if (ret)
123 + break;
124 + wdt_timeout = HEARTBEAT(new_wdt_timeout);
125 + ar2315_wdt_enable();
126 + break;
127 + case WDIOC_GETTIMEOUT:
128 + ret = put_user(wdt_timeout, (int __user *)arg);
129 + break;
130 + }
131 + return ret;
132 +}
133 +
134 +static const struct file_operations ar2315_wdt_fops = {
135 + .owner = THIS_MODULE,
136 + .llseek = no_llseek,
137 + .write = ar2315_wdt_write,
138 + .unlocked_ioctl = ar2315_wdt_ioctl,
139 + .open = ar2315_wdt_open,
140 + .release = ar2315_wdt_release,
141 +};
142 +
143 +static struct miscdevice ar2315_wdt_miscdev = {
144 + .minor = WATCHDOG_MINOR,
145 + .name = "watchdog",
146 + .fops = &ar2315_wdt_fops,
147 +};
148 +
149 +static int
150 +ar2315_wdt_probe(struct platform_device *dev)
151 +{
152 + int ret = 0;
153 +
154 + ar2315_wdt_enable();
155 + ret = request_irq(AR531X_MISC_IRQ_WATCHDOG, ar2315_wdt_interrupt,
156 + IRQF_DISABLED, DRIVER_NAME, dev);
157 + if (ret) {
158 + dev_err(&dev->dev, "failed to register inetrrupt\n");
159 + goto out;
160 + }
161 +
162 + ret = misc_register(&ar2315_wdt_miscdev);
163 + if (ret)
164 + dev_err(&dev->dev, "failed to register miscdev\n");
165 +
166 +out:
167 + return ret;
168 +}
169 +
170 +static int
171 +ar2315_wdt_remove(struct platform_device *dev)
172 +{
173 + misc_deregister(&ar2315_wdt_miscdev);
174 + free_irq(AR531X_MISC_IRQ_WATCHDOG, NULL);
175 + return 0;
176 +}
177 +
178 +static struct platform_driver ar2315_wdt_driver = {
179 + .probe = ar2315_wdt_probe,
180 + .remove = ar2315_wdt_remove,
181 + .driver = {
182 + .name = DRIVER_NAME,
183 + .owner = THIS_MODULE,
184 + },
185 +};
186 +
187 +module_platform_driver(ar2315_wdt_driver);
188 +
189 +MODULE_DESCRIPTION("Atheros AR2315 hardware watchdog driver");
190 +MODULE_AUTHOR("John Crispin <blogic@openwrt.org>");
191 +MODULE_LICENSE("GPL");
192 +MODULE_ALIAS("platform:" DRIVER_NAME);
193 --- a/drivers/watchdog/Kconfig
194 +++ b/drivers/watchdog/Kconfig
195 @@ -1113,6 +1113,12 @@ config LANTIQ_WDT
196 help
197 Hardware driver for the Lantiq SoC Watchdog Timer.
198
199 +config ATHEROS_WDT
200 + tristate "Atheros wisoc Watchdog Timer"
201 + depends on ATHEROS_AR231X
202 + help
203 + Hardware driver for the Atheros wisoc Watchdog Timer.
204 +
205 # PARISC Architecture
206
207 # POWERPC Architecture
208 --- a/drivers/watchdog/Makefile
209 +++ b/drivers/watchdog/Makefile
210 @@ -131,6 +131,7 @@ obj-$(CONFIG_GPIO_WDT) += gpio_wdt.o
211 obj-$(CONFIG_PNX833X_WDT) += pnx833x_wdt.o
212 obj-$(CONFIG_SIBYTE_WDOG) += sb_wdog.o
213 obj-$(CONFIG_AR7_WDT) += ar7_wdt.o
214 +obj-$(CONFIG_ATHEROS_WDT) += ar2315-wtd.o
215 obj-$(CONFIG_TXX9_WDT) += txx9wdt.o
216 obj-$(CONFIG_OCTEON_WDT) += octeon-wdt.o
217 octeon-wdt-y := octeon-wdt-main.o octeon-wdt-nmi.o