ar71xx: fix a typo in the ar724x PCI code
[openwrt.git] / target / linux / brcm47xx / patches-2.6.30 / 815-watchdog.patch
1 This add watchdog driver for broadcom 47xx device.
2 It uses the ssb subsytem to access embeded watchdog device.
3
4 Because the watchdog timeout is very short (about 2s), a soft timer is used
5 to increase the watchdog period.
6
7 Note : A patch for exporting the ssb_watchdog_timer_set will
8 be submitted on next linux-mips merge. Without this patch it can't
9 be build as a module.
10
11 Signed-off-by: Aleksandar Radovanovic <biblbroks@sezampro.rs>
12 Signed-off-by: Matthieu CASTET <castet.matthieu@free.fr>
13 --- a/drivers/watchdog/Kconfig
14 +++ b/drivers/watchdog/Kconfig
15 @@ -764,6 +764,12 @@ config TXX9_WDT
16 help
17 Hardware driver for the built-in watchdog timer on TXx9 MIPS SoCs.
18
19 +config BCM47XX_WDT
20 + tristate "Broadcom BCM47xx Watchdog Timer"
21 + depends on BCM47XX
22 + help
23 + Hardware driver for the Broadcom BCM47xx Watchog Timer.
24 +
25 # PARISC Architecture
26
27 # POWERPC Architecture
28 --- a/drivers/watchdog/Makefile
29 +++ b/drivers/watchdog/Makefile
30 @@ -105,6 +105,7 @@ obj-$(CONFIG_WDT_RM9K_GPI) += rm9k_wdt.o
31 obj-$(CONFIG_SIBYTE_WDOG) += sb_wdog.o
32 obj-$(CONFIG_AR7_WDT) += ar7_wdt.o
33 obj-$(CONFIG_TXX9_WDT) += txx9wdt.o
34 +obj-$(CONFIG_BCM47XX_WDT) += bcm47xx_wdt.o
35
36 # PARISC Architecture
37
38 --- /dev/null
39 +++ b/drivers/watchdog/bcm47xx_wdt.c
40 @@ -0,0 +1,286 @@
41 +/*
42 + * Watchdog driver for Broadcom BCM47XX
43 + *
44 + * Copyright (C) 2008 Aleksandar Radovanovic <biblbroks@sezampro.rs>
45 + * Copyright (C) 2009 Matthieu CASTET <castet.matthieu@free.fr>
46 + *
47 + * This program is free software; you can redistribute it and/or
48 + * modify it under the terms of the GNU General Public License
49 + * as published by the Free Software Foundation; either version
50 + * 2 of the License, or (at your option) any later version.
51 + */
52 +
53 +#include <linux/bitops.h>
54 +#include <linux/errno.h>
55 +#include <linux/fs.h>
56 +#include <linux/init.h>
57 +#include <linux/kernel.h>
58 +#include <linux/miscdevice.h>
59 +#include <linux/module.h>
60 +#include <linux/moduleparam.h>
61 +#include <linux/reboot.h>
62 +#include <linux/types.h>
63 +#include <linux/uaccess.h>
64 +#include <linux/watchdog.h>
65 +#include <linux/timer.h>
66 +#include <linux/jiffies.h>
67 +#include <linux/ssb/ssb_embedded.h>
68 +#include <asm/mach-bcm47xx/bcm47xx.h>
69 +
70 +#define DRV_NAME "bcm47xx_wdt"
71 +
72 +#define WDT_DEFAULT_TIME 30 /* seconds */
73 +#define WDT_MAX_TIME 256 /* seconds */
74 +
75 +static int wdt_time = WDT_DEFAULT_TIME;
76 +static int nowayout = WATCHDOG_NOWAYOUT;
77 +
78 +module_param(wdt_time, int, 0);
79 +MODULE_PARM_DESC(wdt_time, "Watchdog time in seconds. (default="
80 + __MODULE_STRING(WDT_DEFAULT_TIME) ")");
81 +
82 +#ifdef CONFIG_WATCHDOG_NOWAYOUT
83 +module_param(nowayout, int, 0);
84 +MODULE_PARM_DESC(nowayout,
85 + "Watchdog cannot be stopped once started (default="
86 + __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
87 +#endif
88 +
89 +static unsigned long bcm47xx_wdt_busy;
90 +static char expect_release;
91 +static struct timer_list wdt_timer;
92 +static atomic_t ticks;
93 +
94 +static inline void bcm47xx_wdt_hw_start(void)
95 +{
96 + /* this is 2,5s on 100Mhz clock and 2s on 133 Mhz */
97 + ssb_watchdog_timer_set(&ssb_bcm47xx, 0xfffffff);
98 +}
99 +
100 +static inline int bcm47xx_wdt_hw_stop(void)
101 +{
102 + return ssb_watchdog_timer_set(&ssb_bcm47xx, 0);
103 +}
104 +
105 +static void bcm47xx_timer_tick(unsigned long unused)
106 +{
107 + if (!atomic_dec_and_test(&ticks)) {
108 + bcm47xx_wdt_hw_start();
109 + mod_timer(&wdt_timer, jiffies + HZ);
110 + } else {
111 + printk(KERN_CRIT DRV_NAME "Watchdog will fire soon!!!\n");
112 + }
113 +}
114 +
115 +static inline void bcm47xx_wdt_pet(void)
116 +{
117 + atomic_set(&ticks, wdt_time);
118 +}
119 +
120 +static void bcm47xx_wdt_start(void)
121 +{
122 + bcm47xx_wdt_pet();
123 + bcm47xx_timer_tick(0);
124 +}
125 +
126 +static void bcm47xx_wdt_pause(void)
127 +{
128 + del_timer_sync(&wdt_timer);
129 + bcm47xx_wdt_hw_stop();
130 +}
131 +
132 +static void bcm47xx_wdt_stop(void)
133 +{
134 + bcm47xx_wdt_pause();
135 +}
136 +
137 +static int bcm47xx_wdt_settimeout(int new_time)
138 +{
139 + if ((new_time <= 0) || (new_time > WDT_MAX_TIME))
140 + return -EINVAL;
141 +
142 + wdt_time = new_time;
143 + return 0;
144 +}
145 +
146 +static int bcm47xx_wdt_open(struct inode *inode, struct file *file)
147 +{
148 + if (test_and_set_bit(0, &bcm47xx_wdt_busy))
149 + return -EBUSY;
150 +
151 + bcm47xx_wdt_start();
152 + return nonseekable_open(inode, file);
153 +}
154 +
155 +static int bcm47xx_wdt_release(struct inode *inode, struct file *file)
156 +{
157 + if (expect_release == 42) {
158 + bcm47xx_wdt_stop();
159 + } else {
160 + printk(KERN_CRIT DRV_NAME
161 + ": Unexpected close, not stopping watchdog!\n");
162 + bcm47xx_wdt_start();
163 + }
164 +
165 + clear_bit(0, &bcm47xx_wdt_busy);
166 + expect_release = 0;
167 + return 0;
168 +}
169 +
170 +static ssize_t bcm47xx_wdt_write(struct file *file, const char __user *data,
171 + size_t len, loff_t *ppos)
172 +{
173 + if (len) {
174 + if (!nowayout) {
175 + size_t i;
176 +
177 + expect_release = 0;
178 +
179 + for (i = 0; i != len; i++) {
180 + char c;
181 + if (get_user(c, data + i))
182 + return -EFAULT;
183 + if (c == 'V')
184 + expect_release = 42;
185 + }
186 + }
187 + bcm47xx_wdt_pet();
188 + }
189 + return len;
190 +}
191 +
192 +static struct watchdog_info bcm47xx_wdt_info = {
193 + .identity = DRV_NAME,
194 + .options = WDIOF_SETTIMEOUT |
195 + WDIOF_KEEPALIVEPING |
196 + WDIOF_MAGICCLOSE,
197 +};
198 +
199 +static long bcm47xx_wdt_ioctl(struct file *file,
200 + unsigned int cmd, unsigned long arg)
201 +{
202 + void __user *argp = (void __user *)arg;
203 + int __user *p = argp;
204 + int new_value, retval = -EINVAL;;
205 +
206 + switch (cmd) {
207 + case WDIOC_GETSUPPORT:
208 + return copy_to_user(argp, &bcm47xx_wdt_info,
209 + sizeof(bcm47xx_wdt_info)) ? -EFAULT : 0;
210 +
211 + case WDIOC_GETSTATUS:
212 + case WDIOC_GETBOOTSTATUS:
213 + return put_user(0, p);
214 +
215 + case WDIOC_SETOPTIONS:
216 + if (get_user(new_value, p))
217 + return -EFAULT;
218 +
219 + if (new_value & WDIOS_DISABLECARD) {
220 + bcm47xx_wdt_stop();
221 + retval = 0;
222 + }
223 +
224 + if (new_value & WDIOS_ENABLECARD) {
225 + bcm47xx_wdt_start();
226 + retval = 0;
227 + }
228 +
229 + return retval;
230 +
231 + case WDIOC_KEEPALIVE:
232 + bcm47xx_wdt_pet();
233 + return 0;
234 +
235 + case WDIOC_SETTIMEOUT:
236 + if (get_user(new_value, p))
237 + return -EFAULT;
238 +
239 + if (bcm47xx_wdt_settimeout(new_value))
240 + return -EINVAL;
241 +
242 + bcm47xx_wdt_pet();
243 +
244 + case WDIOC_GETTIMEOUT:
245 + return put_user(wdt_time, p);
246 +
247 + default:
248 + return -ENOTTY;
249 + }
250 +}
251 +
252 +static int bcm47xx_wdt_notify_sys(struct notifier_block *this,
253 + unsigned long code, void *unused)
254 +{
255 + if (code == SYS_DOWN || code == SYS_HALT)
256 + bcm47xx_wdt_stop();
257 + return NOTIFY_DONE;
258 +}
259 +
260 +static const struct file_operations bcm47xx_wdt_fops = {
261 + .owner = THIS_MODULE,
262 + .llseek = no_llseek,
263 + .unlocked_ioctl = bcm47xx_wdt_ioctl,
264 + .open = bcm47xx_wdt_open,
265 + .release = bcm47xx_wdt_release,
266 + .write = bcm47xx_wdt_write,
267 +};
268 +
269 +static struct miscdevice bcm47xx_wdt_miscdev = {
270 + .minor = WATCHDOG_MINOR,
271 + .name = "watchdog",
272 + .fops = &bcm47xx_wdt_fops,
273 +};
274 +
275 +static struct notifier_block bcm47xx_wdt_notifier = {
276 + .notifier_call = bcm47xx_wdt_notify_sys,
277 +};
278 +
279 +static int __init bcm47xx_wdt_init(void)
280 +{
281 + int ret;
282 +
283 + if (bcm47xx_wdt_hw_stop() < 0)
284 + return -ENODEV;
285 +
286 + setup_timer(&wdt_timer, bcm47xx_timer_tick, 0L);
287 +
288 + if (bcm47xx_wdt_settimeout(wdt_time)) {
289 + bcm47xx_wdt_settimeout(WDT_DEFAULT_TIME);
290 + printk(KERN_INFO DRV_NAME
291 + ": wdt_time value must be 1 <= wdt_time <= 256, using %d\n",
292 + wdt_time);
293 + }
294 +
295 + ret = register_reboot_notifier(&bcm47xx_wdt_notifier);
296 + if (ret)
297 + return ret;
298 +
299 + ret = misc_register(&bcm47xx_wdt_miscdev);
300 + if (ret) {
301 + unregister_reboot_notifier(&bcm47xx_wdt_notifier);
302 + return ret;
303 + }
304 +
305 + printk(KERN_INFO "BCM47xx Watchdog Timer enabled (%d seconds%s)\n",
306 + wdt_time, nowayout ? ", nowayout" : "");
307 + return 0;
308 +}
309 +
310 +static void __exit bcm47xx_wdt_exit(void)
311 +{
312 + if (!nowayout)
313 + bcm47xx_wdt_stop();
314 +
315 + misc_deregister(&bcm47xx_wdt_miscdev);
316 +
317 + unregister_reboot_notifier(&bcm47xx_wdt_notifier);
318 +}
319 +
320 +module_init(bcm47xx_wdt_init);
321 +module_exit(bcm47xx_wdt_exit);
322 +
323 +MODULE_AUTHOR("Aleksandar Radovanovic");
324 +MODULE_DESCRIPTION("Watchdog driver for Broadcom BCM47xx");
325 +MODULE_LICENSE("GPL");
326 +MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
This page took 0.07802 seconds and 5 git commands to generate.