[kernel] kmod-usb-core is buildin on etrax target
[openwrt.git] / target / linux / brcm63xx / patches-2.6.33 / 020-watchdog.patch
1 --- a/drivers/watchdog/Makefile
2 +++ b/drivers/watchdog/Makefile
3 @@ -112,6 +112,7 @@ obj-$(CONFIG_PNX833X_WDT) += pnx833x_wdt
4 obj-$(CONFIG_SIBYTE_WDOG) += sb_wdog.o
5 obj-$(CONFIG_AR7_WDT) += ar7_wdt.o
6 obj-$(CONFIG_TXX9_WDT) += txx9wdt.o
7 +obj-$(CONFIG_BCM63XX_WDT) += bcm63xx_wdt.o
8
9 # PARISC Architecture
10
11 --- a/drivers/watchdog/Kconfig
12 +++ b/drivers/watchdog/Kconfig
13 @@ -840,6 +840,16 @@ config TXX9_WDT
14 help
15 Hardware driver for the built-in watchdog timer on TXx9 MIPS SoCs.
16
17 +config BCM63XX_WDT
18 + tristate "Broadcom BCM63xx hardware watchdog"
19 + depends on BCM63XX
20 + help
21 + Watchdog driver for the built in watchdog hardware in Broadcom
22 + BCM63xx SoC.
23 +
24 + To compile thi driver as a loadable module, choose M here.
25 + The module will be called bcm63xx_wdt.
26 +
27 # PARISC Architecture
28
29 # POWERPC Architecture
30 --- /dev/null
31 +++ b/drivers/watchdog/bcm63xx_wdt.c
32 @@ -0,0 +1,354 @@
33 +/*
34 + * Broadcom BCM63xx SoC watchdog driver
35 + *
36 + * Copyright (C) 2007, Miguel Gaio <miguel.gaio@efixo.com>
37 + * Copyright (C) 2008, Florian Fainelli <florian@openwrt.org>
38 + *
39 + * This program is free software; you can redistribute it and/or
40 + * modify it under the terms of the GNU General Public License
41 + * as published by the Free Software Foundation; either version
42 + * 2 of the License, or (at your option) any later version.
43 + */
44 +
45 +#include <linux/bitops.h>
46 +#include <linux/errno.h>
47 +#include <linux/fs.h>
48 +#include <linux/init.h>
49 +#include <linux/kernel.h>
50 +#include <linux/miscdevice.h>
51 +#include <linux/module.h>
52 +#include <linux/moduleparam.h>
53 +#include <linux/reboot.h>
54 +#include <linux/types.h>
55 +#include <linux/uaccess.h>
56 +#include <linux/watchdog.h>
57 +#include <linux/timer.h>
58 +#include <linux/jiffies.h>
59 +#include <linux/interrupt.h>
60 +#include <linux/ptrace.h>
61 +#include <linux/resource.h>
62 +#include <linux/platform_device.h>
63 +
64 +#include <bcm63xx_cpu.h>
65 +#include <bcm63xx_io.h>
66 +#include <bcm63xx_regs.h>
67 +#include <bcm63xx_timer.h>
68 +
69 +#define PFX KBUILD_MODNAME
70 +
71 +#define WDT_HZ 50000000 /* Fclk */
72 +#define WDT_DEFAULT_TIME 30 /* seconds */
73 +#define WDT_MAX_TIME 256 /* seconds */
74 +
75 +static struct {
76 + void __iomem *regs;
77 + struct timer_list timer;
78 + int default_ticks;
79 + unsigned long inuse;
80 + atomic_t ticks;
81 +} bcm63xx_wdt_device;
82 +
83 +static int expect_close;
84 +
85 +static int wdt_time = WDT_DEFAULT_TIME;
86 +static int nowayout = WATCHDOG_NOWAYOUT;
87 +module_param(nowayout, int, 0);
88 +MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
89 + __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
90 +
91 +/* HW functions */
92 +static void bcm63xx_wdt_hw_start(void)
93 +{
94 + bcm_writel(0xfffffffe, bcm63xx_wdt_device.regs + WDT_DEFVAL_REG);
95 + bcm_writel(WDT_START_1, bcm63xx_wdt_device.regs + WDT_CTL_REG);
96 + bcm_writel(WDT_START_2, bcm63xx_wdt_device.regs + WDT_CTL_REG);
97 +}
98 +
99 +static void bcm63xx_wdt_hw_stop(void)
100 +{
101 + bcm_writel(WDT_STOP_1, bcm63xx_wdt_device.regs + WDT_CTL_REG);
102 + bcm_writel(WDT_STOP_2, bcm63xx_wdt_device.regs + WDT_CTL_REG);
103 +}
104 +
105 +static void bcm63xx_wdt_isr(void *data)
106 +{
107 + struct pt_regs *regs = get_irq_regs();
108 +
109 + die(PFX " fire", regs);
110 +}
111 +
112 +static void bcm63xx_timer_tick(unsigned long unused)
113 +{
114 + if (!atomic_dec_and_test(&bcm63xx_wdt_device.ticks)) {
115 + bcm63xx_wdt_hw_start();
116 + mod_timer(&bcm63xx_wdt_device.timer, jiffies + HZ);
117 + } else
118 + printk(KERN_CRIT PFX ": watchdog will restart system\n");
119 +}
120 +
121 +static void bcm63xx_wdt_pet(void)
122 +{
123 + atomic_set(&bcm63xx_wdt_device.ticks, wdt_time);
124 +}
125 +
126 +static void bcm63xx_wdt_start(void)
127 +{
128 + bcm63xx_wdt_pet();
129 + bcm63xx_timer_tick(0);
130 +}
131 +
132 +static void bcm63xx_wdt_pause(void)
133 +{
134 + del_timer_sync(&bcm63xx_wdt_device.timer);
135 + bcm63xx_wdt_hw_stop();
136 +}
137 +
138 +static int bcm63xx_wdt_settimeout(int new_time)
139 +{
140 + if ((new_time <= 0) || (new_time > WDT_MAX_TIME))
141 + return -EINVAL;
142 +
143 + wdt_time = new_time;
144 +
145 + return 0;
146 +}
147 +
148 +static int bcm63xx_wdt_open(struct inode *inode, struct file *file)
149 +{
150 + if (test_and_set_bit(0, &bcm63xx_wdt_device.inuse))
151 + return -EBUSY;
152 +
153 + bcm63xx_wdt_start();
154 + return nonseekable_open(inode, file);
155 +}
156 +
157 +static int bcm63xx_wdt_release(struct inode *inode, struct file *file)
158 +{
159 + if (expect_close == 42)
160 + bcm63xx_wdt_pause();
161 + else {
162 + printk(KERN_CRIT PFX
163 + ": Unexpected close, not stopping watchdog!\n");
164 + bcm63xx_wdt_start();
165 + }
166 + clear_bit(0, &bcm63xx_wdt_device.inuse);
167 + expect_close = 0;
168 + return 0;
169 +}
170 +
171 +static ssize_t bcm63xx_wdt_write(struct file *file, const char *data,
172 + size_t len, loff_t *ppos)
173 +{
174 + if (len) {
175 + if (!nowayout) {
176 + size_t i;
177 +
178 + /* In case it was set long ago */
179 + expect_close = 0;
180 +
181 + for (i = 0; i != len; i++) {
182 + char c;
183 + if (get_user(c, data + i))
184 + return -EFAULT;
185 + if (c == 'V')
186 + expect_close = 42;
187 + }
188 + }
189 + bcm63xx_wdt_pet();
190 + }
191 + return len;
192 +}
193 +
194 +static struct watchdog_info bcm63xx_wdt_info = {
195 + .identity = PFX,
196 + .options = WDIOF_SETTIMEOUT |
197 + WDIOF_KEEPALIVEPING |
198 + WDIOF_MAGICCLOSE,
199 +};
200 +
201 +
202 +static long bcm63xx_wdt_ioctl(struct file *file, unsigned int cmd,
203 + unsigned long arg)
204 +{
205 + void __user *argp = (void __user *)arg;
206 + int __user *p = argp;
207 + int new_value, retval = -EINVAL;
208 +
209 + switch (cmd) {
210 + case WDIOC_GETSUPPORT:
211 + return copy_to_user(argp, &bcm63xx_wdt_info,
212 + sizeof(bcm63xx_wdt_info)) ? -EFAULT : 0;
213 +
214 + case WDIOC_GETSTATUS:
215 + case WDIOC_GETBOOTSTATUS:
216 + return put_user(0, p);
217 +
218 + case WDIOC_SETOPTIONS:
219 + if (get_user(new_value, p))
220 + return -EFAULT;
221 +
222 + if (new_value & WDIOS_DISABLECARD) {
223 + bcm63xx_wdt_pause();
224 + retval = 0;
225 + }
226 + if (new_value & WDIOS_ENABLECARD) {
227 + bcm63xx_wdt_start();
228 + retval = 0;
229 + }
230 +
231 + return retval;
232 +
233 + case WDIOC_KEEPALIVE:
234 + bcm63xx_wdt_pet();
235 + return 0;
236 +
237 + case WDIOC_SETTIMEOUT:
238 + if (get_user(new_value, p))
239 + return -EFAULT;
240 +
241 + if (bcm63xx_wdt_settimeout(new_value))
242 + return -EINVAL;
243 +
244 + bcm63xx_wdt_pet();
245 +
246 + case WDIOC_GETTIMEOUT:
247 + return put_user(wdt_time, p);
248 +
249 + default:
250 + return -ENOTTY;
251 +
252 + }
253 +}
254 +
255 +static int bcm63xx_wdt_notify_sys(struct notifier_block *this,
256 + unsigned long code, void *unused)
257 +{
258 + if (code == SYS_DOWN || code == SYS_HALT)
259 + bcm63xx_wdt_pause();
260 + return NOTIFY_DONE;
261 +}
262 +
263 +static const struct file_operations bcm63xx_wdt_fops = {
264 + .owner = THIS_MODULE,
265 + .llseek = no_llseek,
266 + .write = bcm63xx_wdt_write,
267 + .unlocked_ioctl = bcm63xx_wdt_ioctl,
268 + .open = bcm63xx_wdt_open,
269 + .release = bcm63xx_wdt_release,
270 +};
271 +
272 +static struct miscdevice bcm63xx_wdt_miscdev = {
273 + .minor = WATCHDOG_MINOR,
274 + .name = "watchdog",
275 + .fops = &bcm63xx_wdt_fops,
276 +};
277 +
278 +static struct notifier_block bcm63xx_wdt_notifier = {
279 + .notifier_call = bcm63xx_wdt_notify_sys,
280 +};
281 +
282 +
283 +static int bcm63xx_wdt_probe(struct platform_device *pdev)
284 +{
285 + int ret;
286 + struct resource *r;
287 +
288 + setup_timer(&bcm63xx_wdt_device.timer, bcm63xx_timer_tick, 0L);
289 +
290 + r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
291 + if (!r) {
292 + printk(KERN_ERR PFX
293 + "failed to retrieve resources\n");
294 + return -ENODEV;
295 + }
296 +
297 + bcm63xx_wdt_device.regs = ioremap_nocache(r->start, r->end - r->start);
298 + if (!bcm63xx_wdt_device.regs) {
299 + printk(KERN_ERR PFX
300 + "failed to remap I/O resources\n");
301 + return -ENXIO;
302 + }
303 +
304 + ret = bcm63xx_timer_register(TIMER_WDT_ID, bcm63xx_wdt_isr, NULL);
305 + if (ret < 0) {
306 + printk(KERN_ERR PFX
307 + "failed to register wdt timer isr\n");
308 + goto unmap;
309 + }
310 +
311 + if (bcm63xx_wdt_settimeout(wdt_time)) {
312 + bcm63xx_wdt_settimeout(WDT_DEFAULT_TIME);
313 + printk(KERN_INFO PFX
314 + ": wdt_time value must be 1 <= wdt_time <= 256, using %d\n",
315 + wdt_time);
316 + }
317 +
318 + ret = register_reboot_notifier(&bcm63xx_wdt_notifier);
319 + if (ret) {
320 + printk(KERN_ERR PFX
321 + "failed to register reboot_notifier\n");
322 + goto unregister_timer;
323 + }
324 +
325 + ret = misc_register(&bcm63xx_wdt_miscdev);
326 + if (ret < 0) {
327 + printk(KERN_ERR PFX
328 + "failed to register watchdog device\n");
329 + goto unregister_reboot_notifier;
330 + }
331 +
332 + printk(KERN_INFO PFX " started, timer margin: %d sec\n", WDT_DEFAULT_TIME);
333 +
334 + return 0;
335 +
336 +unregister_reboot_notifier:
337 + unregister_reboot_notifier(&bcm63xx_wdt_notifier);
338 +unregister_timer:
339 + bcm63xx_timer_unregister(TIMER_WDT_ID);
340 +unmap:
341 + iounmap(bcm63xx_wdt_device.regs);
342 + return ret;
343 +}
344 +
345 +static int bcm63xx_wdt_remove(struct platform_device *pdev)
346 +{
347 + if (!nowayout)
348 + bcm63xx_wdt_pause();
349 +
350 + misc_deregister(&bcm63xx_wdt_miscdev);
351 +
352 + iounmap(bcm63xx_wdt_device.regs);
353 +
354 + unregister_reboot_notifier(&bcm63xx_wdt_notifier);
355 + bcm63xx_timer_unregister(TIMER_WDT_ID);
356 +
357 + return 0;
358 +}
359 +
360 +static struct platform_driver bcm63xx_wdt = {
361 + .probe = bcm63xx_wdt_probe,
362 + .remove = bcm63xx_wdt_remove,
363 + .driver = {
364 + .name = "bcm63xx-wdt",
365 + }
366 +};
367 +
368 +static int __init bcm63xx_wdt_init(void)
369 +{
370 + return platform_driver_register(&bcm63xx_wdt);
371 +}
372 +
373 +static void __exit bcm63xx_wdt_exit(void)
374 +{
375 + platform_driver_unregister(&bcm63xx_wdt);
376 +}
377 +
378 +module_init(bcm63xx_wdt_init);
379 +module_exit(bcm63xx_wdt_exit);
380 +
381 +MODULE_AUTHOR("Miguel Gaio <miguel.gaio@efixo.com>");
382 +MODULE_AUTHOR("Florian Fainelli <florian@openwrt.org>");
383 +MODULE_DESCRIPTION("Driver for the Broadcom BCM63xx SoC watchdog");
384 +MODULE_LICENSE("GPL");
385 +MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
386 +MODULE_ALIAS("platform:bcm63xx-wdt");
This page took 0.056059 seconds and 5 git commands to generate.