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/resource.h>
60 +#include <linux/platform_device.h>
62 +#include <bcm63xx_cpu.h>
63 +#include <bcm63xx_io.h>
64 +#include <bcm63xx_regs.h>
66 +#define PFX KBUILD_MODNAME
68 +#define WDT_HZ 50000000 /* Fclk */
69 +#define WDT_DEFAULT_TIME 30 /* seconds */
70 +#define WDT_MAX_TIME 256 /* seconds */
74 + struct timer_list timer;
76 + unsigned long inuse;
78 +} bcm63xx_wdt_device;
80 +static int expect_close;
83 +static int wdt_time = WDT_DEFAULT_TIME;
84 +static int nowayout = WATCHDOG_NOWAYOUT;
85 +module_param(nowayout, int, 0);
86 +MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
87 + __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
90 +static void bcm63xx_wdt_hw_start(void)
92 + bcm_writel(0xfffffffe, bcm63xx_wdt_device.regs + WDT_DEFVAL_REG);
93 + bcm_writel(WDT_START_1, bcm63xx_wdt_device.regs + WDT_CTL_REG);
94 + bcm_writel(WDT_START_2, bcm63xx_wdt_device.regs + WDT_CTL_REG);
97 +static void bcm63xx_wdt_hw_stop(void)
99 + bcm_writel(WDT_STOP_1, bcm63xx_wdt_device.regs + WDT_CTL_REG);
100 + bcm_writel(WDT_STOP_2, bcm63xx_wdt_device.regs + WDT_CTL_REG);
103 +static void bcm63xx_timer_tick(unsigned long unused)
105 + if (!atomic_dec_and_test(&bcm63xx_wdt_device.ticks)) {
106 + bcm63xx_wdt_hw_start();
107 + mod_timer(&bcm63xx_wdt_device.timer, jiffies + HZ);
109 + printk(KERN_CRIT PFX ": watchdog will restart system\n");
112 +static void bcm63xx_wdt_pet(void)
114 + atomic_set(&bcm63xx_wdt_device.ticks, wdt_time);
117 +static void bcm63xx_wdt_start(void)
120 + bcm63xx_timer_tick(0);
123 +static void bcm63xx_wdt_pause(void)
125 + del_timer_sync(&bcm63xx_wdt_device.timer);
126 + bcm63xx_wdt_hw_stop();
129 +static int bcm63xx_wdt_settimeout(int new_time)
131 + if ((new_time <= 0) || (new_time > WDT_MAX_TIME))
134 + wdt_time = new_time;
139 +static int bcm63xx_wdt_open(struct inode *inode, struct file *file)
141 + if (test_and_set_bit(0, &bcm63xx_wdt_device.inuse))
144 + bcm63xx_wdt_start();
145 + return nonseekable_open(inode, file);
148 +static int bcm63xx_wdt_release(struct inode *inode, struct file *file)
150 + if (expect_close == 42)
151 + bcm63xx_wdt_pause();
153 + printk(KERN_CRIT PFX
154 + ": Unexpected close, not stopping watchdog!\n");
155 + bcm63xx_wdt_start();
157 + clear_bit(0, &bcm63xx_wdt_device.inuse);
162 +static ssize_t bcm63xx_wdt_write(struct file *file, const char *data,
163 + size_t len, loff_t *ppos)
169 + /* In case it was set long ago */
172 + for (i = 0; i != len; i++) {
174 + if (get_user(c, data + i))
185 +static struct watchdog_info bcm63xx_wdt_info = {
187 + .options = WDIOF_SETTIMEOUT |
188 + WDIOF_KEEPALIVEPING |
193 +static long bcm63xx_wdt_ioctl(struct file *file, unsigned int cmd,
196 + void __user *argp = (void __user *)arg;
197 + int __user *p = argp;
198 + int new_value, retval = -EINVAL;
201 + case WDIOC_GETSUPPORT:
202 + return copy_to_user(argp, &bcm63xx_wdt_info,
203 + sizeof(bcm63xx_wdt_info)) ? -EFAULT : 0;
205 + case WDIOC_GETSTATUS:
206 + case WDIOC_GETBOOTSTATUS:
207 + return put_user(0, p);
209 + case WDIOC_SETOPTIONS:
210 + if (get_user(new_value, p))
213 + if (new_value & WDIOS_DISABLECARD) {
214 + bcm63xx_wdt_pause();
217 + if (new_value & WDIOS_ENABLECARD) {
218 + bcm63xx_wdt_start();
224 + case WDIOC_KEEPALIVE:
228 + case WDIOC_SETTIMEOUT:
229 + if (get_user(new_value, p))
232 + if (bcm63xx_wdt_settimeout(new_value))
237 + case WDIOC_GETTIMEOUT:
238 + return put_user(wdt_time, p);
246 +static int bcm63xx_wdt_notify_sys(struct notifier_block *this,
247 + unsigned long code, void *unused)
249 + if (code == SYS_DOWN || code == SYS_HALT)
250 + bcm63xx_wdt_pause();
251 + return NOTIFY_DONE;
254 +static const struct file_operations bcm63xx_wdt_fops = {
255 + .owner = THIS_MODULE,
256 + .llseek = no_llseek,
257 + .write = bcm63xx_wdt_write,
258 + .unlocked_ioctl = bcm63xx_wdt_ioctl,
259 + .open = bcm63xx_wdt_open,
260 + .release = bcm63xx_wdt_release,
263 +static struct miscdevice bcm63xx_wdt_miscdev = {
264 + .minor = WATCHDOG_MINOR,
265 + .name = "watchdog",
266 + .fops = &bcm63xx_wdt_fops,
269 +static struct notifier_block bcm63xx_wdt_notifier = {
270 + .notifier_call = bcm63xx_wdt_notify_sys,
274 +static int bcm63xx_wdt_probe(struct platform_device *pdev)
277 + struct resource *r;
279 + setup_timer(&bcm63xx_wdt_device.timer, bcm63xx_timer_tick, 0L);
281 + r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
283 + printk(KERN_ERR PFX
284 + "failed to retrieve resources\n");
288 + bcm63xx_wdt_device.regs = ioremap_nocache(r->start, r->end - r->start);
289 + if (!bcm63xx_wdt_device.regs) {
290 + printk(KERN_ERR PFX
291 + "failed to remap I/O resources\n");
295 + if (bcm63xx_wdt_settimeout(wdt_time)) {
296 + bcm63xx_wdt_settimeout(WDT_DEFAULT_TIME);
297 + printk(KERN_INFO PFX
298 + ": wdt_time value must be 1 <= wdt_time <= 256, using %d\n",
302 + ret = register_reboot_notifier(&bcm63xx_wdt_notifier);
304 + printk(KERN_ERR PFX
305 + "failed to register reboot_notifier\n");
309 + ret = misc_register(&bcm63xx_wdt_miscdev);
311 + printk(KERN_ERR PFX
312 + "failed to register watchdog device\n");
316 + printk(KERN_INFO PFX " started, timer margin: %d sec\n", WDT_DEFAULT_TIME);
321 + unregister_reboot_notifier(&bcm63xx_wdt_notifier);
322 + iounmap(bcm63xx_wdt_device.regs);
326 +static int bcm63xx_wdt_remove(struct platform_device *pdev)
329 + bcm63xx_wdt_pause();
331 + misc_deregister(&bcm63xx_wdt_miscdev);
333 + iounmap(bcm63xx_wdt_device.regs);
335 + unregister_reboot_notifier(&bcm63xx_wdt_notifier);
340 +static struct platform_driver bcm63xx_wdt = {
341 + .probe = bcm63xx_wdt_probe,
342 + .remove = bcm63xx_wdt_remove,
344 + .name = "bcm63xx-wdt",
348 +static int __init bcm63xx_wdt_init(void)
350 + return platform_driver_register(&bcm63xx_wdt);
353 +static void __exit bcm63xx_wdt_exit(void)
355 + platform_driver_unregister(&bcm63xx_wdt);
358 +module_init(bcm63xx_wdt_init);
359 +module_exit(bcm63xx_wdt_exit);
361 +MODULE_AUTHOR("Miguel Gaio <miguel.gaio@efixo.com>");
362 +MODULE_AUTHOR("Florian Fainelli <florian@openwrt.org>");
363 +MODULE_DESCRIPTION("Driver for the Broadcom BCM63xx SoC watchdog");
364 +MODULE_LICENSE("GPL");
365 +MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
366 +MODULE_ALIAS("platform:bcm63xx-wdt");