1 Index: linux-2.6.32.9/drivers/watchdog/Makefile
2 ===================================================================
3 --- linux-2.6.32.9.orig/drivers/watchdog/Makefile 2010-02-23 16:38:51.000000000 +0100
4 +++ linux-2.6.32.9/drivers/watchdog/Makefile 2010-02-28 18:13:51.000000000 +0100
6 obj-$(CONFIG_SIBYTE_WDOG) += sb_wdog.o
7 obj-$(CONFIG_AR7_WDT) += ar7_wdt.o
8 obj-$(CONFIG_TXX9_WDT) += txx9wdt.o
9 +obj-$(CONFIG_BCM63XX_WDT) += bcm63xx_wdt.o
13 Index: linux-2.6.32.9/drivers/watchdog/Kconfig
14 ===================================================================
15 --- linux-2.6.32.9.orig/drivers/watchdog/Kconfig 2010-02-23 16:38:51.000000000 +0100
16 +++ linux-2.6.32.9/drivers/watchdog/Kconfig 2010-02-28 18:13:51.000000000 +0100
19 Hardware driver for the built-in watchdog timer on TXx9 MIPS SoCs.
22 + tristate "Broadcom BCM63xx hardware watchdog"
25 + Watchdog driver for the built in watchdog hardware in Broadcom
28 + To compile thi driver as a loadable module, choose M here.
29 + The module will be called bcm63xx_wdt.
33 # POWERPC Architecture
34 Index: linux-2.6.32.9/drivers/watchdog/bcm63xx_wdt.c
35 ===================================================================
36 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
37 +++ linux-2.6.32.9/drivers/watchdog/bcm63xx_wdt.c 2010-02-28 18:17:15.000000000 +0100
40 + * Broadcom BCM63xx SoC watchdog driver
42 + * Copyright (C) 2007, Miguel Gaio <miguel.gaio@efixo.com>
43 + * Copyright (C) 2008, Florian Fainelli <florian@openwrt.org>
45 + * This program is free software; you can redistribute it and/or
46 + * modify it under the terms of the GNU General Public License
47 + * as published by the Free Software Foundation; either version
48 + * 2 of the License, or (at your option) any later version.
51 +#include <linux/bitops.h>
52 +#include <linux/errno.h>
53 +#include <linux/fs.h>
54 +#include <linux/init.h>
55 +#include <linux/kernel.h>
56 +#include <linux/miscdevice.h>
57 +#include <linux/module.h>
58 +#include <linux/moduleparam.h>
59 +#include <linux/reboot.h>
60 +#include <linux/types.h>
61 +#include <linux/uaccess.h>
62 +#include <linux/watchdog.h>
63 +#include <linux/timer.h>
64 +#include <linux/jiffies.h>
65 +#include <linux/resource.h>
66 +#include <linux/platform_device.h>
68 +#include <bcm63xx_cpu.h>
69 +#include <bcm63xx_io.h>
70 +#include <bcm63xx_regs.h>
72 +#define PFX KBUILD_MODNAME
74 +#define WDT_HZ 50000000 /* Fclk */
75 +#define WDT_DEFAULT_TIME 30 /* seconds */
76 +#define WDT_MAX_TIME 256 /* seconds */
80 + struct timer_list timer;
82 + unsigned long inuse;
84 +} bcm63xx_wdt_device;
86 +static int expect_close;
89 +static int wdt_time = WDT_DEFAULT_TIME;
90 +static int nowayout = WATCHDOG_NOWAYOUT;
91 +module_param(nowayout, int, 0);
92 +MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
93 + __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
96 +static void bcm63xx_wdt_hw_start(void)
98 + bcm_writel(0xfffffffe, bcm63xx_wdt_device.regs + WDT_DEFVAL_REG);
99 + bcm_writel(WDT_START_1, bcm63xx_wdt_device.regs + WDT_CTL_REG);
100 + bcm_writel(WDT_START_2, bcm63xx_wdt_device.regs + WDT_CTL_REG);
103 +static void bcm63xx_wdt_hw_stop(void)
105 + bcm_writel(WDT_STOP_1, bcm63xx_wdt_device.regs + WDT_CTL_REG);
106 + bcm_writel(WDT_STOP_2, bcm63xx_wdt_device.regs + WDT_CTL_REG);
109 +static void bcm63xx_timer_tick(unsigned long unused)
111 + if (!atomic_dec_and_test(&bcm63xx_wdt_device.ticks)) {
112 + bcm63xx_wdt_hw_start();
113 + mod_timer(&bcm63xx_wdt_device.timer, jiffies + HZ);
115 + printk(KERN_CRIT PFX ": watchdog will restart system\n");
118 +static void bcm63xx_wdt_pet(void)
120 + atomic_set(&bcm63xx_wdt_device.ticks, wdt_time);
123 +static void bcm63xx_wdt_start(void)
126 + bcm63xx_timer_tick(0);
129 +static void bcm63xx_wdt_pause(void)
131 + del_timer_sync(&bcm63xx_wdt_device.timer);
132 + bcm63xx_wdt_hw_stop();
135 +static int bcm63xx_wdt_settimeout(int new_time)
137 + if ((new_time <= 0) || (new_time > WDT_MAX_TIME))
140 + wdt_time = new_time;
145 +static int bcm63xx_wdt_open(struct inode *inode, struct file *file)
147 + if (test_and_set_bit(0, &bcm63xx_wdt_device.inuse))
150 + bcm63xx_wdt_start();
151 + return nonseekable_open(inode, file);
154 +static int bcm63xx_wdt_release(struct inode *inode, struct file *file)
156 + if (expect_close == 42)
157 + bcm63xx_wdt_pause();
159 + printk(KERN_CRIT PFX
160 + ": Unexpected close, not stopping watchdog!\n");
161 + bcm63xx_wdt_start();
163 + clear_bit(0, &bcm63xx_wdt_device.inuse);
168 +static ssize_t bcm63xx_wdt_write(struct file *file, const char *data,
169 + size_t len, loff_t *ppos)
175 + /* In case it was set long ago */
178 + for (i = 0; i != len; i++) {
180 + if (get_user(c, data + i))
191 +static struct watchdog_info bcm63xx_wdt_info = {
193 + .options = WDIOF_SETTIMEOUT |
194 + WDIOF_KEEPALIVEPING |
199 +static long bcm63xx_wdt_ioctl(struct file *file, unsigned int cmd,
202 + void __user *argp = (void __user *)arg;
203 + int __user *p = argp;
204 + int new_value, retval = -EINVAL;
207 + case WDIOC_GETSUPPORT:
208 + return copy_to_user(argp, &bcm63xx_wdt_info,
209 + sizeof(bcm63xx_wdt_info)) ? -EFAULT : 0;
211 + case WDIOC_GETSTATUS:
212 + case WDIOC_GETBOOTSTATUS:
213 + return put_user(0, p);
215 + case WDIOC_SETOPTIONS:
216 + if (get_user(new_value, p))
219 + if (new_value & WDIOS_DISABLECARD) {
220 + bcm63xx_wdt_pause();
223 + if (new_value & WDIOS_ENABLECARD) {
224 + bcm63xx_wdt_start();
230 + case WDIOC_KEEPALIVE:
234 + case WDIOC_SETTIMEOUT:
235 + if (get_user(new_value, p))
238 + if (bcm63xx_wdt_settimeout(new_value))
243 + case WDIOC_GETTIMEOUT:
244 + return put_user(wdt_time, p);
252 +static int bcm63xx_wdt_notify_sys(struct notifier_block *this,
253 + unsigned long code, void *unused)
255 + if (code == SYS_DOWN || code == SYS_HALT)
256 + bcm63xx_wdt_pause();
257 + return NOTIFY_DONE;
260 +static const struct file_operations bcm63xx_wdt_fops = {
261 + .owner = THIS_MODULE,
262 + .llseek = no_llseek,
263 + .write = bcm63xx_wdt_write,
264 + .unlocked_ioctl = bcm63xx_wdt_ioctl,
265 + .open = bcm63xx_wdt_open,
266 + .release = bcm63xx_wdt_release,
269 +static struct miscdevice bcm63xx_wdt_miscdev = {
270 + .minor = WATCHDOG_MINOR,
271 + .name = "watchdog",
272 + .fops = &bcm63xx_wdt_fops,
275 +static struct notifier_block bcm63xx_wdt_notifier = {
276 + .notifier_call = bcm63xx_wdt_notify_sys,
280 +static int bcm63xx_wdt_probe(struct platform_device *pdev)
283 + struct resource *r;
285 + setup_timer(&bcm63xx_wdt_device.timer, bcm63xx_timer_tick, 0L);
287 + r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
289 + printk(KERN_ERR PFX
290 + "failed to retrieve resources\n");
294 + bcm63xx_wdt_device.regs = ioremap_nocache(r->start, r->end - r->start);
295 + if (!bcm63xx_wdt_device.regs) {
296 + printk(KERN_ERR PFX
297 + "failed to remap I/O resources\n");
301 + if (bcm63xx_wdt_settimeout(wdt_time)) {
302 + bcm63xx_wdt_settimeout(WDT_DEFAULT_TIME);
303 + printk(KERN_INFO PFX
304 + ": wdt_time value must be 1 <= wdt_time <= 256, using %d\n",
308 + ret = register_reboot_notifier(&bcm63xx_wdt_notifier);
310 + printk(KERN_ERR PFX
311 + "failed to register reboot_notifier\n");
315 + ret = misc_register(&bcm63xx_wdt_miscdev);
317 + printk(KERN_ERR PFX
318 + "failed to register watchdog device\n");
322 + printk(KERN_INFO PFX " started, timer margin: %d sec\n", WDT_DEFAULT_TIME);
327 + unregister_reboot_notifier(&bcm63xx_wdt_notifier);
328 + iounmap(bcm63xx_wdt_device.regs);
332 +static int bcm63xx_wdt_remove(struct platform_device *pdev)
335 + bcm63xx_wdt_pause();
337 + misc_deregister(&bcm63xx_wdt_miscdev);
339 + iounmap(bcm63xx_wdt_device.regs);
341 + unregister_reboot_notifier(&bcm63xx_wdt_notifier);
346 +static struct platform_driver bcm63xx_wdt = {
347 + .probe = bcm63xx_wdt_probe,
348 + .remove = bcm63xx_wdt_remove,
350 + .name = "bcm63xx-wdt",
354 +static int __init bcm63xx_wdt_init(void)
356 + return platform_driver_register(&bcm63xx_wdt);
359 +static void __exit bcm63xx_wdt_exit(void)
361 + platform_driver_unregister(&bcm63xx_wdt);
364 +module_init(bcm63xx_wdt_init);
365 +module_exit(bcm63xx_wdt_exit);
367 +MODULE_AUTHOR("Miguel Gaio <miguel.gaio@efixo.com>");
368 +MODULE_AUTHOR("Florian Fainelli <florian@openwrt.org>");
369 +MODULE_DESCRIPTION("Driver for the Broadcom BCM63xx SoC watchdog");
370 +MODULE_LICENSE("GPL");
371 +MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
372 +MODULE_ALIAS("platform:bcm63xx-wdt");