sfc: Serialise tenxpress_special_reset() with statistics fetches
[linux-2.6/verdex.git] / drivers / watchdog / wdt285.c
blobdb362c34958bdf42e43ad1567eba11049795abbe
1 /*
2 * Intel 21285 watchdog driver
3 * Copyright (c) Phil Blundell <pb@nexus.co.uk>, 1998
5 * based on
7 * SoftDog 0.05: A Software Watchdog Device
9 * (c) Copyright 1996 Alan Cox <alan@redhat.com>, All Rights Reserved.
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version
14 * 2 of the License, or (at your option) any later version.
18 #include <linux/module.h>
19 #include <linux/moduleparam.h>
20 #include <linux/types.h>
21 #include <linux/kernel.h>
22 #include <linux/fs.h>
23 #include <linux/mm.h>
24 #include <linux/miscdevice.h>
25 #include <linux/watchdog.h>
26 #include <linux/reboot.h>
27 #include <linux/init.h>
28 #include <linux/interrupt.h>
29 #include <linux/uaccess.h>
30 #include <linux/irq.h>
31 #include <mach/hardware.h>
33 #include <asm/mach-types.h>
34 #include <asm/hardware/dec21285.h>
37 * Define this to stop the watchdog actually rebooting the machine.
39 #undef ONLY_TESTING
41 static unsigned int soft_margin = 60; /* in seconds */
42 static unsigned int reload;
43 static unsigned long timer_alive;
45 #ifdef ONLY_TESTING
47 * If the timer expires..
49 static void watchdog_fire(int irq, void *dev_id)
51 printk(KERN_CRIT "Watchdog: Would Reboot.\n");
52 *CSR_TIMER4_CNTL = 0;
53 *CSR_TIMER4_CLR = 0;
55 #endif
58 * Refresh the timer.
60 static void watchdog_ping(void)
62 *CSR_TIMER4_LOAD = reload;
66 * Allow only one person to hold it open
68 static int watchdog_open(struct inode *inode, struct file *file)
70 int ret;
72 if (*CSR_SA110_CNTL & (1 << 13))
73 return -EBUSY;
75 if (test_and_set_bit(1, &timer_alive))
76 return -EBUSY;
78 reload = soft_margin * (mem_fclk_21285 / 256);
80 *CSR_TIMER4_CLR = 0;
81 watchdog_ping();
82 *CSR_TIMER4_CNTL = TIMER_CNTL_ENABLE | TIMER_CNTL_AUTORELOAD
83 | TIMER_CNTL_DIV256;
85 #ifdef ONLY_TESTING
86 ret = request_irq(IRQ_TIMER4, watchdog_fire, 0, "watchdog", NULL);
87 if (ret) {
88 *CSR_TIMER4_CNTL = 0;
89 clear_bit(1, &timer_alive);
91 #else
93 * Setting this bit is irreversible; once enabled, there is
94 * no way to disable the watchdog.
96 *CSR_SA110_CNTL |= 1 << 13;
98 ret = 0;
99 #endif
100 nonseekable_open(inode, file);
101 return ret;
105 * Shut off the timer.
106 * Note: if we really have enabled the watchdog, there
107 * is no way to turn off.
109 static int watchdog_release(struct inode *inode, struct file *file)
111 #ifdef ONLY_TESTING
112 free_irq(IRQ_TIMER4, NULL);
113 clear_bit(1, &timer_alive);
114 #endif
115 return 0;
118 static ssize_t watchdog_write(struct file *file, const char *data,
119 size_t len, loff_t *ppos)
122 * Refresh the timer.
124 if (len)
125 watchdog_ping();
127 return len;
130 static const struct watchdog_info ident = {
131 .options = WDIOF_SETTIMEOUT,
132 .identity = "Footbridge Watchdog",
135 static long watchdog_ioctl(struct file *file, unsigned int cmd,
136 unsigned long arg)
138 unsigned int new_margin;
139 int ret = -ENOTTY;
141 switch (cmd) {
142 case WDIOC_GETSUPPORT:
143 ret = 0;
144 if (copy_to_user((void *)arg, &ident, sizeof(ident)))
145 ret = -EFAULT;
146 break;
148 case WDIOC_GETSTATUS:
149 case WDIOC_GETBOOTSTATUS:
150 ret = put_user(0, (int *)arg);
151 break;
153 case WDIOC_KEEPALIVE:
154 watchdog_ping();
155 ret = 0;
156 break;
158 case WDIOC_SETTIMEOUT:
159 ret = get_user(new_margin, (int *)arg);
160 if (ret)
161 break;
163 /* Arbitrary, can't find the card's limits */
164 if (new_margin < 0 || new_margin > 60) {
165 ret = -EINVAL;
166 break;
169 soft_margin = new_margin;
170 reload = soft_margin * (mem_fclk_21285 / 256);
171 watchdog_ping();
172 /* Fall */
173 case WDIOC_GETTIMEOUT:
174 ret = put_user(soft_margin, (int *)arg);
175 break;
177 return ret;
180 static const struct file_operations watchdog_fops = {
181 .owner = THIS_MODULE,
182 .llseek = no_llseek,
183 .write = watchdog_write,
184 .unlocked_ioctl = watchdog_ioctl,
185 .open = watchdog_open,
186 .release = watchdog_release,
189 static struct miscdevice watchdog_miscdev = {
190 .minor = WATCHDOG_MINOR,
191 .name = "watchdog",
192 .fops = &watchdog_fops,
195 static int __init footbridge_watchdog_init(void)
197 int retval;
199 if (machine_is_netwinder())
200 return -ENODEV;
202 retval = misc_register(&watchdog_miscdev);
203 if (retval < 0)
204 return retval;
206 printk(KERN_INFO
207 "Footbridge Watchdog Timer: 0.01, timer margin: %d sec\n",
208 soft_margin);
210 if (machine_is_cats())
211 printk(KERN_WARNING
212 "Warning: Watchdog reset may not work on this machine.\n");
213 return 0;
216 static void __exit footbridge_watchdog_exit(void)
218 misc_deregister(&watchdog_miscdev);
221 MODULE_AUTHOR("Phil Blundell <pb@nexus.co.uk>");
222 MODULE_DESCRIPTION("Footbridge watchdog driver");
223 MODULE_LICENSE("GPL");
224 MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
226 module_param(soft_margin, int, 0);
227 MODULE_PARM_DESC(soft_margin, "Watchdog timeout in seconds");
229 module_init(footbridge_watchdog_init);
230 module_exit(footbridge_watchdog_exit);