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 --- a/drivers/watchdog/Kconfig
14 +++ b/drivers/watchdog/Kconfig
15 @@ -764,6 +764,12 @@ config TXX9_WDT
17 Hardware driver for the built-in watchdog timer on TXx9 MIPS SoCs.
20 + tristate "Broadcom BCM47xx Watchdog Timer"
23 + Hardware driver for the Broadcom BCM47xx Watchog Timer.
27 # POWERPC Architecture
28 --- a/drivers/watchdog/Makefile
29 +++ b/drivers/watchdog/Makefile
30 @@ -105,6 +105,7 @@ obj-$(CONFIG_WDT_RM9K_GPI) += rm9k_wdt.o
31 obj-$(CONFIG_SIBYTE_WDOG) += sb_wdog.o
32 obj-$(CONFIG_AR7_WDT) += ar7_wdt.o
33 obj-$(CONFIG_TXX9_WDT) += txx9wdt.o
34 +obj-$(CONFIG_BCM47XX_WDT) += bcm47xx_wdt.o
39 +++ b/drivers/watchdog/bcm47xx_wdt.c
42 + * Watchdog driver for Broadcom BCM47XX
44 + * Copyright (C) 2008 Aleksandar Radovanovic <biblbroks@sezampro.rs>
45 + * Copyright (C) 2009 Matthieu CASTET <castet.matthieu@free.fr>
47 + * This program is free software; you can redistribute it and/or
48 + * modify it under the terms of the GNU General Public License
49 + * as published by the Free Software Foundation; either version
50 + * 2 of the License, or (at your option) any later version.
53 +#include <linux/bitops.h>
54 +#include <linux/errno.h>
55 +#include <linux/fs.h>
56 +#include <linux/init.h>
57 +#include <linux/kernel.h>
58 +#include <linux/miscdevice.h>
59 +#include <linux/module.h>
60 +#include <linux/moduleparam.h>
61 +#include <linux/reboot.h>
62 +#include <linux/types.h>
63 +#include <linux/uaccess.h>
64 +#include <linux/watchdog.h>
65 +#include <linux/timer.h>
66 +#include <linux/jiffies.h>
67 +#include <linux/ssb/ssb_embedded.h>
68 +#include <asm/mach-bcm47xx/bcm47xx.h>
70 +#define DRV_NAME "bcm47xx_wdt"
72 +#define WDT_DEFAULT_TIME 30 /* seconds */
73 +#define WDT_MAX_TIME 256 /* seconds */
75 +static int wdt_time = WDT_DEFAULT_TIME;
76 +static int nowayout = WATCHDOG_NOWAYOUT;
78 +module_param(wdt_time, int, 0);
79 +MODULE_PARM_DESC(wdt_time, "Watchdog time in seconds. (default="
80 + __MODULE_STRING(WDT_DEFAULT_TIME) ")");
82 +#ifdef CONFIG_WATCHDOG_NOWAYOUT
83 +module_param(nowayout, int, 0);
84 +MODULE_PARM_DESC(nowayout,
85 + "Watchdog cannot be stopped once started (default="
86 + __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
89 +static unsigned long bcm47xx_wdt_busy;
90 +static char expect_release;
91 +static struct timer_list wdt_timer;
92 +static atomic_t ticks;
94 +static inline void bcm47xx_wdt_hw_start(void)
96 + /* this is 2,5s on 100Mhz clock and 2s on 133 Mhz */
97 + ssb_watchdog_timer_set(&ssb_bcm47xx, 0xfffffff);
100 +static inline int bcm47xx_wdt_hw_stop(void)
102 + return ssb_watchdog_timer_set(&ssb_bcm47xx, 0);
105 +static void bcm47xx_timer_tick(unsigned long unused)
107 + if (!atomic_dec_and_test(&ticks)) {
108 + bcm47xx_wdt_hw_start();
109 + mod_timer(&wdt_timer, jiffies + HZ);
111 + printk(KERN_CRIT DRV_NAME "Watchdog will fire soon!!!\n");
115 +static inline void bcm47xx_wdt_pet(void)
117 + atomic_set(&ticks, wdt_time);
120 +static void bcm47xx_wdt_start(void)
123 + bcm47xx_timer_tick(0);
126 +static void bcm47xx_wdt_pause(void)
128 + del_timer_sync(&wdt_timer);
129 + bcm47xx_wdt_hw_stop();
132 +static void bcm47xx_wdt_stop(void)
134 + bcm47xx_wdt_pause();
137 +static int bcm47xx_wdt_settimeout(int new_time)
139 + if ((new_time <= 0) || (new_time > WDT_MAX_TIME))
142 + wdt_time = new_time;
146 +static int bcm47xx_wdt_open(struct inode *inode, struct file *file)
148 + if (test_and_set_bit(0, &bcm47xx_wdt_busy))
151 + bcm47xx_wdt_start();
152 + return nonseekable_open(inode, file);
155 +static int bcm47xx_wdt_release(struct inode *inode, struct file *file)
157 + if (expect_release == 42) {
158 + bcm47xx_wdt_stop();
160 + printk(KERN_CRIT DRV_NAME
161 + ": Unexpected close, not stopping watchdog!\n");
162 + bcm47xx_wdt_start();
165 + clear_bit(0, &bcm47xx_wdt_busy);
166 + expect_release = 0;
170 +static ssize_t bcm47xx_wdt_write(struct file *file, const char __user *data,
171 + size_t len, loff_t *ppos)
177 + expect_release = 0;
179 + for (i = 0; i != len; i++) {
181 + if (get_user(c, data + i))
184 + expect_release = 42;
192 +static struct watchdog_info bcm47xx_wdt_info = {
193 + .identity = DRV_NAME,
194 + .options = WDIOF_SETTIMEOUT |
195 + WDIOF_KEEPALIVEPING |
199 +static long bcm47xx_wdt_ioctl(struct file *file,
200 + unsigned int cmd, unsigned long arg)
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, &bcm47xx_wdt_info,
209 + sizeof(bcm47xx_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 + bcm47xx_wdt_stop();
224 + if (new_value & WDIOS_ENABLECARD) {
225 + bcm47xx_wdt_start();
231 + case WDIOC_KEEPALIVE:
235 + case WDIOC_SETTIMEOUT:
236 + if (get_user(new_value, p))
239 + if (bcm47xx_wdt_settimeout(new_value))
244 + case WDIOC_GETTIMEOUT:
245 + return put_user(wdt_time, p);
252 +static int bcm47xx_wdt_notify_sys(struct notifier_block *this,
253 + unsigned long code, void *unused)
255 + if (code == SYS_DOWN || code == SYS_HALT)
256 + bcm47xx_wdt_stop();
257 + return NOTIFY_DONE;
260 +static const struct file_operations bcm47xx_wdt_fops = {
261 + .owner = THIS_MODULE,
262 + .llseek = no_llseek,
263 + .unlocked_ioctl = bcm47xx_wdt_ioctl,
264 + .open = bcm47xx_wdt_open,
265 + .release = bcm47xx_wdt_release,
266 + .write = bcm47xx_wdt_write,
269 +static struct miscdevice bcm47xx_wdt_miscdev = {
270 + .minor = WATCHDOG_MINOR,
271 + .name = "watchdog",
272 + .fops = &bcm47xx_wdt_fops,
275 +static struct notifier_block bcm47xx_wdt_notifier = {
276 + .notifier_call = bcm47xx_wdt_notify_sys,
279 +static int __init bcm47xx_wdt_init(void)
283 + if (bcm47xx_wdt_hw_stop() < 0)
286 + setup_timer(&wdt_timer, bcm47xx_timer_tick, 0L);
288 + if (bcm47xx_wdt_settimeout(wdt_time)) {
289 + bcm47xx_wdt_settimeout(WDT_DEFAULT_TIME);
290 + printk(KERN_INFO DRV_NAME
291 + ": wdt_time value must be 1 <= wdt_time <= 256, using %d\n",
295 + ret = register_reboot_notifier(&bcm47xx_wdt_notifier);
299 + ret = misc_register(&bcm47xx_wdt_miscdev);
301 + unregister_reboot_notifier(&bcm47xx_wdt_notifier);
305 + printk(KERN_INFO "BCM47xx Watchdog Timer enabled (%d seconds%s)\n",
306 + wdt_time, nowayout ? ", nowayout" : "");
310 +static void __exit bcm47xx_wdt_exit(void)
313 + bcm47xx_wdt_stop();
315 + misc_deregister(&bcm47xx_wdt_miscdev);
317 + unregister_reboot_notifier(&bcm47xx_wdt_notifier);
320 +module_init(bcm47xx_wdt_init);
321 +module_exit(bcm47xx_wdt_exit);
323 +MODULE_AUTHOR("Aleksandar Radovanovic");
324 +MODULE_DESCRIPTION("Watchdog driver for Broadcom BCM47xx");
325 +MODULE_LICENSE("GPL");
326 +MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);