1 This add watchdog driver for broadcom 47xx device.
2 It uses the ssb subsytem to access embeded watchdog device.
4 Because the watchdog timeout is very short (about 2s), a soft timer is used
5 to increase the watchdog period.
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
11 Signed-off-by: Aleksandar Radovanovic <biblbroks@sezampro.rs>
12 Signed-off-by: Matthieu CASTET <castet.matthieu@free.fr>
13 Index: linux-2.6/drivers/watchdog/Kconfig
14 ===================================================================
15 --- linux-2.6.orig/drivers/watchdog/Kconfig 2009-05-25 22:22:02.000000000 +0200
16 +++ linux-2.6/drivers/watchdog/Kconfig 2009-06-05 22:05:19.000000000 +0200
19 Hardware driver for the built-in watchdog timer on TXx9 MIPS SoCs.
22 + tristate "Broadcom BCM47xx Watchdog Timer"
25 + Hardware driver for the Broadcom BCM47xx Watchog Timer.
29 # POWERPC Architecture
30 Index: linux-2.6/drivers/watchdog/Makefile
31 ===================================================================
32 --- linux-2.6.orig/drivers/watchdog/Makefile 2009-05-25 22:22:02.000000000 +0200
33 +++ linux-2.6/drivers/watchdog/Makefile 2009-05-25 23:02:27.000000000 +0200
35 obj-$(CONFIG_SIBYTE_WDOG) += sb_wdog.o
36 obj-$(CONFIG_AR7_WDT) += ar7_wdt.o
37 obj-$(CONFIG_TXX9_WDT) += txx9wdt.o
38 +obj-$(CONFIG_BCM47XX_WDT) += bcm47xx_wdt.o
42 Index: linux-2.6/drivers/watchdog/bcm47xx_wdt.c
43 ===================================================================
44 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
45 +++ linux-2.6/drivers/watchdog/bcm47xx_wdt.c 2009-06-05 22:25:37.000000000 +0200
48 + * Watchdog driver for Broadcom BCM47XX
50 + * Copyright (C) 2008 Aleksandar Radovanovic <biblbroks@sezampro.rs>
51 + * Copyright (C) 2009 Matthieu CASTET <castet.matthieu@free.fr>
53 + * This program is free software; you can redistribute it and/or
54 + * modify it under the terms of the GNU General Public License
55 + * as published by the Free Software Foundation; either version
56 + * 2 of the License, or (at your option) any later version.
59 +#include <linux/bitops.h>
60 +#include <linux/errno.h>
61 +#include <linux/fs.h>
62 +#include <linux/init.h>
63 +#include <linux/kernel.h>
64 +#include <linux/miscdevice.h>
65 +#include <linux/module.h>
66 +#include <linux/moduleparam.h>
67 +#include <linux/reboot.h>
68 +#include <linux/types.h>
69 +#include <linux/uaccess.h>
70 +#include <linux/watchdog.h>
71 +#include <linux/timer.h>
72 +#include <linux/jiffies.h>
73 +#include <linux/ssb/ssb_embedded.h>
74 +#include <asm/mach-bcm47xx/bcm47xx.h>
76 +#define DRV_NAME "bcm47xx_wdt"
78 +#define WDT_DEFAULT_TIME 30 /* seconds */
79 +#define WDT_MAX_TIME 256 /* seconds */
81 +static int wdt_time = WDT_DEFAULT_TIME;
82 +static int nowayout = WATCHDOG_NOWAYOUT;
84 +module_param(wdt_time, int, 0);
85 +MODULE_PARM_DESC(wdt_time, "Watchdog time in seconds. (default="
86 + __MODULE_STRING(WDT_DEFAULT_TIME) ")");
88 +#ifdef CONFIG_WATCHDOG_NOWAYOUT
89 +module_param(nowayout, int, 0);
90 +MODULE_PARM_DESC(nowayout,
91 + "Watchdog cannot be stopped once started (default="
92 + __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
95 +static unsigned long bcm47xx_wdt_busy;
96 +static char expect_release;
97 +static struct timer_list wdt_timer;
98 +static atomic_t ticks;
100 +static inline void bcm47xx_wdt_hw_start(void)
102 + /* this is 2,5s on 100Mhz clock and 2s on 133 Mhz */
103 + ssb_watchdog_timer_set(&ssb_bcm47xx, 0xfffffff);
106 +static inline int bcm47xx_wdt_hw_stop(void)
108 + return ssb_watchdog_timer_set(&ssb_bcm47xx, 0);
111 +static void bcm47xx_timer_tick(unsigned long unused)
113 + if (!atomic_dec_and_test(&ticks)) {
114 + bcm47xx_wdt_hw_start();
115 + mod_timer(&wdt_timer, jiffies + HZ);
117 + printk(KERN_CRIT DRV_NAME "Watchdog will fire soon!!!\n");
121 +static inline void bcm47xx_wdt_pet(void)
123 + atomic_set(&ticks, wdt_time);
126 +static void bcm47xx_wdt_start(void)
129 + bcm47xx_timer_tick(0);
132 +static void bcm47xx_wdt_pause(void)
134 + del_timer_sync(&wdt_timer);
135 + bcm47xx_wdt_hw_stop();
138 +static void bcm47xx_wdt_stop(void)
140 + bcm47xx_wdt_pause();
143 +static int bcm47xx_wdt_settimeout(int new_time)
145 + if ((new_time <= 0) || (new_time > WDT_MAX_TIME))
148 + wdt_time = new_time;
152 +static int bcm47xx_wdt_open(struct inode *inode, struct file *file)
154 + if (test_and_set_bit(0, &bcm47xx_wdt_busy))
157 + bcm47xx_wdt_start();
158 + return nonseekable_open(inode, file);
161 +static int bcm47xx_wdt_release(struct inode *inode, struct file *file)
163 + if (expect_release == 42) {
164 + bcm47xx_wdt_stop();
166 + printk(KERN_CRIT DRV_NAME
167 + ": Unexpected close, not stopping watchdog!\n");
168 + bcm47xx_wdt_start();
171 + clear_bit(0, &bcm47xx_wdt_busy);
172 + expect_release = 0;
176 +static ssize_t bcm47xx_wdt_write(struct file *file, const char __user *data,
177 + size_t len, loff_t *ppos)
183 + expect_release = 0;
185 + for (i = 0; i != len; i++) {
187 + if (get_user(c, data + i))
190 + expect_release = 42;
198 +static struct watchdog_info bcm47xx_wdt_info = {
199 + .identity = DRV_NAME,
200 + .options = WDIOF_SETTIMEOUT |
201 + WDIOF_KEEPALIVEPING |
205 +static long bcm47xx_wdt_ioctl(struct file *file,
206 + unsigned int cmd, unsigned long arg)
208 + void __user *argp = (void __user *)arg;
209 + int __user *p = argp;
210 + int new_value, retval = -EINVAL;;
213 + case WDIOC_GETSUPPORT:
214 + return copy_to_user(argp, &bcm47xx_wdt_info,
215 + sizeof(bcm47xx_wdt_info)) ? -EFAULT : 0;
217 + case WDIOC_GETSTATUS:
218 + case WDIOC_GETBOOTSTATUS:
219 + return put_user(0, p);
221 + case WDIOC_SETOPTIONS:
222 + if (get_user(new_value, p))
225 + if (new_value & WDIOS_DISABLECARD) {
226 + bcm47xx_wdt_stop();
230 + if (new_value & WDIOS_ENABLECARD) {
231 + bcm47xx_wdt_start();
237 + case WDIOC_KEEPALIVE:
241 + case WDIOC_SETTIMEOUT:
242 + if (get_user(new_value, p))
245 + if (bcm47xx_wdt_settimeout(new_value))
250 + case WDIOC_GETTIMEOUT:
251 + return put_user(wdt_time, p);
258 +static int bcm47xx_wdt_notify_sys(struct notifier_block *this,
259 + unsigned long code, void *unused)
261 + if (code == SYS_DOWN || code == SYS_HALT)
262 + bcm47xx_wdt_stop();
263 + return NOTIFY_DONE;
266 +static const struct file_operations bcm47xx_wdt_fops = {
267 + .owner = THIS_MODULE,
268 + .llseek = no_llseek,
269 + .unlocked_ioctl = bcm47xx_wdt_ioctl,
270 + .open = bcm47xx_wdt_open,
271 + .release = bcm47xx_wdt_release,
272 + .write = bcm47xx_wdt_write,
275 +static struct miscdevice bcm47xx_wdt_miscdev = {
276 + .minor = WATCHDOG_MINOR,
277 + .name = "watchdog",
278 + .fops = &bcm47xx_wdt_fops,
281 +static struct notifier_block bcm47xx_wdt_notifier = {
282 + .notifier_call = bcm47xx_wdt_notify_sys,
285 +static int __init bcm47xx_wdt_init(void)
289 + if (bcm47xx_wdt_hw_stop() < 0)
292 + setup_timer(&wdt_timer, bcm47xx_timer_tick, 0L);
294 + if (bcm47xx_wdt_settimeout(wdt_time)) {
295 + bcm47xx_wdt_settimeout(WDT_DEFAULT_TIME);
296 + printk(KERN_INFO DRV_NAME
297 + ": wdt_time value must be 1 <= wdt_time <= 256, using %d\n",
301 + ret = register_reboot_notifier(&bcm47xx_wdt_notifier);
305 + ret = misc_register(&bcm47xx_wdt_miscdev);
307 + unregister_reboot_notifier(&bcm47xx_wdt_notifier);
311 + printk(KERN_INFO "BCM47xx Watchdog Timer enabled (%d seconds%s)\n",
312 + wdt_time, nowayout ? ", nowayout" : "");
316 +static void __exit bcm47xx_wdt_exit(void)
319 + bcm47xx_wdt_stop();
321 + misc_deregister(&bcm47xx_wdt_miscdev);
323 + unregister_reboot_notifier(&bcm47xx_wdt_notifier);
326 +module_init(bcm47xx_wdt_init);
327 +module_exit(bcm47xx_wdt_exit);
329 +MODULE_AUTHOR("Aleksandar Radovanovic");
330 +MODULE_DESCRIPTION("Watchdog driver for Broadcom BCM47xx");
331 +MODULE_LICENSE("GPL");
332 +MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);