2 * Intel 21285 watchdog driver
3 * Copyright (c) Phil Blundell <pb@nexus.co.uk>, 1998
7 * SoftDog 0.05: A Software Watchdog Device
9 * (c) Copyright 1996 Alan Cox <alan@lxorguk.ukuu.org.uk>,
10 * All Rights Reserved.
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version
15 * 2 of the License, or (at your option) any later version.
19 #include <linux/module.h>
20 #include <linux/moduleparam.h>
21 #include <linux/types.h>
22 #include <linux/kernel.h>
25 #include <linux/miscdevice.h>
26 #include <linux/watchdog.h>
27 #include <linux/reboot.h>
28 #include <linux/init.h>
29 #include <linux/interrupt.h>
30 #include <linux/uaccess.h>
31 #include <linux/irq.h>
32 #include <mach/hardware.h>
34 #include <asm/mach-types.h>
35 #include <asm/hardware/dec21285.h>
38 * Define this to stop the watchdog actually rebooting the machine.
42 static unsigned int soft_margin = 60; /* in seconds */
43 static unsigned int reload;
44 static unsigned long timer_alive;
48 * If the timer expires..
50 static void watchdog_fire(int irq, void *dev_id)
52 printk(KERN_CRIT "Watchdog: Would Reboot.\n");
61 static void watchdog_ping(void)
63 *CSR_TIMER4_LOAD = reload;
67 * Allow only one person to hold it open
69 static int watchdog_open(struct inode *inode, struct file *file)
73 if (*CSR_SA110_CNTL & (1 << 13))
76 if (test_and_set_bit(1, &timer_alive))
79 reload = soft_margin * (mem_fclk_21285 / 256);
83 *CSR_TIMER4_CNTL = TIMER_CNTL_ENABLE | TIMER_CNTL_AUTORELOAD
87 ret = request_irq(IRQ_TIMER4, watchdog_fire, 0, "watchdog", NULL);
90 clear_bit(1, &timer_alive);
94 * Setting this bit is irreversible; once enabled, there is
95 * no way to disable the watchdog.
97 *CSR_SA110_CNTL |= 1 << 13;
101 nonseekable_open(inode, file);
106 * Shut off the timer.
107 * Note: if we really have enabled the watchdog, there
108 * is no way to turn off.
110 static int watchdog_release(struct inode *inode, struct file *file)
113 free_irq(IRQ_TIMER4, NULL);
114 clear_bit(1, &timer_alive);
119 static ssize_t watchdog_write(struct file *file, const char __user *data,
120 size_t len, loff_t *ppos)
131 static const struct watchdog_info ident = {
132 .options = WDIOF_SETTIMEOUT,
133 .identity = "Footbridge Watchdog",
136 static long watchdog_ioctl(struct file *file, unsigned int cmd,
139 unsigned int new_margin;
140 int __user *int_arg = (int __user *)arg;
144 case WDIOC_GETSUPPORT:
146 if (copy_to_user((void __user *)arg, &ident, sizeof(ident)))
150 case WDIOC_GETSTATUS:
151 case WDIOC_GETBOOTSTATUS:
152 ret = put_user(0, int_arg);
155 case WDIOC_KEEPALIVE:
160 case WDIOC_SETTIMEOUT:
161 ret = get_user(new_margin, int_arg);
165 /* Arbitrary, can't find the card's limits */
166 if (new_margin < 0 || new_margin > 60) {
171 soft_margin = new_margin;
172 reload = soft_margin * (mem_fclk_21285 / 256);
175 case WDIOC_GETTIMEOUT:
176 ret = put_user(soft_margin, int_arg);
182 static const struct file_operations watchdog_fops = {
183 .owner = THIS_MODULE,
185 .write = watchdog_write,
186 .unlocked_ioctl = watchdog_ioctl,
187 .open = watchdog_open,
188 .release = watchdog_release,
191 static struct miscdevice watchdog_miscdev = {
192 .minor = WATCHDOG_MINOR,
194 .fops = &watchdog_fops,
197 static int __init footbridge_watchdog_init(void)
201 if (machine_is_netwinder())
204 retval = misc_register(&watchdog_miscdev);
209 "Footbridge Watchdog Timer: 0.01, timer margin: %d sec\n",
212 if (machine_is_cats())
214 "Warning: Watchdog reset may not work on this machine.\n");
218 static void __exit footbridge_watchdog_exit(void)
220 misc_deregister(&watchdog_miscdev);
223 MODULE_AUTHOR("Phil Blundell <pb@nexus.co.uk>");
224 MODULE_DESCRIPTION("Footbridge watchdog driver");
225 MODULE_LICENSE("GPL");
226 MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
228 module_param(soft_margin, int, 0);
229 MODULE_PARM_DESC(soft_margin, "Watchdog timeout in seconds");
231 module_init(footbridge_watchdog_init);
232 module_exit(footbridge_watchdog_exit);