1 --- a/drivers/watchdog/Makefile
2 +++ b/drivers/watchdog/Makefile
3 @@ -113,6 +113,7 @@ obj-$(CONFIG_WDT_RM9K_GPI) += rm9k_wdt.o
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
11 --- a/drivers/watchdog/Kconfig
12 +++ b/drivers/watchdog/Kconfig
13 @@ -850,6 +850,16 @@ config TXX9_WDT
15 Hardware driver for the built-in watchdog timer on TXx9 MIPS SoCs.
18 + tristate "Broadcom BCM63xx hardware watchdog"
21 + Watchdog driver for the built in watchdog hardware in Broadcom
24 + To compile thi driver as a loadable module, choose M here.
25 + The module will be called bcm63xx_wdt.
29 # POWERPC Architecture
31 +++ b/drivers/watchdog/bcm63xx_wdt.c
34 + * Broadcom BCM63xx SoC watchdog driver
36 + * Copyright (C) 2007, Miguel Gaio <miguel.gaio@efixo.com>
37 + * Copyright (C) 2008, Florian Fainelli <florian@openwrt.org>
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.
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>
64 +#include <bcm63xx_cpu.h>
65 +#include <bcm63xx_io.h>
66 +#include <bcm63xx_regs.h>
67 +#include <bcm63xx_timer.h>
69 +#define PFX KBUILD_MODNAME
71 +#define WDT_HZ 50000000 /* Fclk */
72 +#define WDT_DEFAULT_TIME 30 /* seconds */
73 +#define WDT_MAX_TIME 256 /* seconds */
77 + struct timer_list timer;
79 + unsigned long inuse;
81 +} bcm63xx_wdt_device;
83 +static int expect_close;
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) ")");
92 +static void bcm63xx_wdt_hw_start(void)
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);
99 +static void bcm63xx_wdt_hw_stop(void)
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);
105 +static void bcm63xx_wdt_isr(void *data)
107 + struct pt_regs *regs = get_irq_regs();
109 + die(PFX " fire", regs);
112 +static void bcm63xx_timer_tick(unsigned long unused)
114 + if (!atomic_dec_and_test(&bcm63xx_wdt_device.ticks)) {
115 + bcm63xx_wdt_hw_start();
116 + mod_timer(&bcm63xx_wdt_device.timer, jiffies + HZ);
118 + printk(KERN_CRIT PFX ": watchdog will restart system\n");
121 +static void bcm63xx_wdt_pet(void)
123 + atomic_set(&bcm63xx_wdt_device.ticks, wdt_time);
126 +static void bcm63xx_wdt_start(void)
129 + bcm63xx_timer_tick(0);
132 +static void bcm63xx_wdt_pause(void)
134 + del_timer_sync(&bcm63xx_wdt_device.timer);
135 + bcm63xx_wdt_hw_stop();
138 +static int bcm63xx_wdt_settimeout(int new_time)
140 + if ((new_time <= 0) || (new_time > WDT_MAX_TIME))
143 + wdt_time = new_time;
148 +static int bcm63xx_wdt_open(struct inode *inode, struct file *file)
150 + if (test_and_set_bit(0, &bcm63xx_wdt_device.inuse))
153 + bcm63xx_wdt_start();
154 + return nonseekable_open(inode, file);
157 +static int bcm63xx_wdt_release(struct inode *inode, struct file *file)
159 + if (expect_close == 42)
160 + bcm63xx_wdt_pause();
162 + printk(KERN_CRIT PFX
163 + ": Unexpected close, not stopping watchdog!\n");
164 + bcm63xx_wdt_start();
166 + clear_bit(0, &bcm63xx_wdt_device.inuse);
171 +static ssize_t bcm63xx_wdt_write(struct file *file, const char *data,
172 + size_t len, loff_t *ppos)
178 + /* In case it was set long ago */
181 + for (i = 0; i != len; i++) {
183 + if (get_user(c, data + i))
194 +static struct watchdog_info bcm63xx_wdt_info = {
196 + .options = WDIOF_SETTIMEOUT |
197 + WDIOF_KEEPALIVEPING |
202 +static long bcm63xx_wdt_ioctl(struct file *file, unsigned int cmd,
205 + void __user *argp = (void __user *)arg;
206 + int __user *p = argp;
207 + int new_value, retval = -EINVAL;
210 + case WDIOC_GETSUPPORT:
211 + return copy_to_user(argp, &bcm63xx_wdt_info,
212 + sizeof(bcm63xx_wdt_info)) ? -EFAULT : 0;
214 + case WDIOC_GETSTATUS:
215 + case WDIOC_GETBOOTSTATUS:
216 + return put_user(0, p);
218 + case WDIOC_SETOPTIONS:
219 + if (get_user(new_value, p))
222 + if (new_value & WDIOS_DISABLECARD) {
223 + bcm63xx_wdt_pause();
226 + if (new_value & WDIOS_ENABLECARD) {
227 + bcm63xx_wdt_start();
233 + case WDIOC_KEEPALIVE:
237 + case WDIOC_SETTIMEOUT:
238 + if (get_user(new_value, p))
241 + if (bcm63xx_wdt_settimeout(new_value))
246 + case WDIOC_GETTIMEOUT:
247 + return put_user(wdt_time, p);
255 +static int bcm63xx_wdt_notify_sys(struct notifier_block *this,
256 + unsigned long code, void *unused)
258 + if (code == SYS_DOWN || code == SYS_HALT)
259 + bcm63xx_wdt_pause();
260 + return NOTIFY_DONE;
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,
272 +static struct miscdevice bcm63xx_wdt_miscdev = {
273 + .minor = WATCHDOG_MINOR,
274 + .name = "watchdog",
275 + .fops = &bcm63xx_wdt_fops,
278 +static struct notifier_block bcm63xx_wdt_notifier = {
279 + .notifier_call = bcm63xx_wdt_notify_sys,
283 +static int bcm63xx_wdt_probe(struct platform_device *pdev)
286 + struct resource *r;
288 + setup_timer(&bcm63xx_wdt_device.timer, bcm63xx_timer_tick, 0L);
290 + r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
292 + printk(KERN_ERR PFX
293 + "failed to retrieve resources\n");
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");
304 + ret = bcm63xx_timer_register(TIMER_WDT_ID, bcm63xx_wdt_isr, NULL);
306 + printk(KERN_ERR PFX
307 + "failed to register wdt timer isr\n");
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",
318 + ret = register_reboot_notifier(&bcm63xx_wdt_notifier);
320 + printk(KERN_ERR PFX
321 + "failed to register reboot_notifier\n");
322 + goto unregister_timer;
325 + ret = misc_register(&bcm63xx_wdt_miscdev);
327 + printk(KERN_ERR PFX
328 + "failed to register watchdog device\n");
329 + goto unregister_reboot_notifier;
332 + printk(KERN_INFO PFX " started, timer margin: %d sec\n", WDT_DEFAULT_TIME);
336 +unregister_reboot_notifier:
337 + unregister_reboot_notifier(&bcm63xx_wdt_notifier);
339 + bcm63xx_timer_unregister(TIMER_WDT_ID);
341 + iounmap(bcm63xx_wdt_device.regs);
345 +static int bcm63xx_wdt_remove(struct platform_device *pdev)
348 + bcm63xx_wdt_pause();
350 + misc_deregister(&bcm63xx_wdt_miscdev);
352 + iounmap(bcm63xx_wdt_device.regs);
354 + unregister_reboot_notifier(&bcm63xx_wdt_notifier);
355 + bcm63xx_timer_unregister(TIMER_WDT_ID);
360 +static struct platform_driver bcm63xx_wdt = {
361 + .probe = bcm63xx_wdt_probe,
362 + .remove = bcm63xx_wdt_remove,
364 + .name = "bcm63xx-wdt",
368 +static int __init bcm63xx_wdt_init(void)
370 + return platform_driver_register(&bcm63xx_wdt);
373 +static void __exit bcm63xx_wdt_exit(void)
375 + platform_driver_unregister(&bcm63xx_wdt);
378 +module_init(bcm63xx_wdt_init);
379 +module_exit(bcm63xx_wdt_exit);
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");