Portability cleanup as required by Linus.
[linux-2.6/linux-mips.git] / drivers / char / wdt285.c
blob6efdd7f764f2a1b7677d89ae2e12d6f945b9a21b
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@cymru.net>, All Rights Reserved.
10 * http://www.cymru.net
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/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>
30 #include <asm/irq.h>
31 #include <asm/uaccess.h>
32 #include <asm/hardware.h>
33 #include <asm/system.h>
34 #include <asm/dec21285.h>
37 * Define this to stop the watchdog actually rebooting the machine.
39 #undef ONLY_TESTING
41 #define TIMER_MARGIN 60 /* (secs) Default is 1 minute */
43 #define FCLK (50*1000*1000) /* 50MHz */
45 static int soft_margin = TIMER_MARGIN; /* in seconds */
46 static int timer_alive = 0;
48 #ifdef ONLY_TESTING
50 * If the timer expires..
53 static void watchdog_fire(int irq, void *dev_id, struct pt_regs *regs)
55 printk(KERN_CRIT "Watchdog: Would Reboot.\n");
56 *CSR_TIMER4_CNTL = 0;
57 *CSR_TIMER4_CLR = 0;
59 #endif
61 static void watchdog_ping(void)
64 * Refresh the timer.
66 *CSR_TIMER4_LOAD = soft_margin * (FCLK / 256);
70 * Allow only one person to hold it open
73 static int watchdog_open(struct inode *inode, struct file *file)
75 if(timer_alive)
76 return -EBUSY;
77 MOD_INC_USE_COUNT;
79 * Ahead watchdog factor ten, Mr Sulu
81 *CSR_TIMER4_CLR = 0;
82 watchdog_ping();
83 *CSR_TIMER4_CNTL = TIMER_CNTL_ENABLE | TIMER_CNTL_AUTORELOAD
84 | TIMER_CNTL_DIV256;
85 #ifdef ONLY_TESTING
86 request_irq(IRQ_TIMER4, watchdog_fire, 0, "watchdog", NULL);
87 #else
88 *CSR_SA110_CNTL |= 1 << 13;
89 #endif
90 timer_alive = 1;
91 return 0;
94 static int watchdog_release(struct inode *inode, struct file *file)
96 #ifdef ONLY_TESTING
97 free_irq(IRQ_TIMER4, NULL);
98 timer_alive = 0;
99 MOD_DEC_USE_COUNT;
100 #else
102 * It's irreversible!
104 #endif
105 return 0;
108 static ssize_t watchdog_write(struct file *file, const char *data, size_t len, loff_t *ppos)
110 /* Can't seek (pwrite) on this device */
111 if (ppos != &file->f_pos)
112 return -ESPIPE;
115 * Refresh the timer.
117 if(len)
119 watchdog_ping();
120 return 1;
122 return 0;
125 static int watchdog_ioctl(struct inode *inode, struct file *file,
126 unsigned int cmd, unsigned long arg)
128 int i;
129 static struct watchdog_info ident=
133 "Footbridge Watchdog"
135 switch(cmd)
137 default:
138 return -ENOIOCTLCMD;
139 case WDIOC_GETSUPPORT:
140 i = verify_area(VERIFY_WRITE, (void*) arg, sizeof(struct watchdog_info));
141 if (i)
142 return i;
143 else
144 return copy_to_user((struct watchdog_info *)arg, &ident, sizeof(ident));
145 case WDIOC_GETSTATUS:
146 case WDIOC_GETBOOTSTATUS:
147 return put_user(0,(int *)arg);
148 case WDIOC_KEEPALIVE:
149 watchdog_ping();
150 return 0;
154 static struct file_operations watchdog_fops=
156 write: watchdog_write,
157 ioctl: watchdog_ioctl,
158 open: watchdog_open,
159 release: watchdog_release,
162 static struct miscdevice watchdog_miscdev=
164 WATCHDOG_MINOR,
165 "watchdog",
166 &watchdog_fops
169 static int __init footbridge_watchdog_init(void)
171 if (machine_is_netwinder())
172 return -ENODEV;
174 misc_register(&watchdog_miscdev);
175 printk("Footbridge Watchdog Timer: 0.01, timer margin: %d sec\n",
176 soft_margin);
177 if (machine_is_cats())
178 printk("Warning: Watchdog reset may not work on this machine.\n");
179 return 0;
182 static void __exit footbridge_watchdog_exit(void)
184 misc_deregister(&watchdog_miscdev);
187 EXPORT_NO_SYMBOLS;
189 MODULE_AUTHOR("Phil Blundell <pb@nexus.co.uk>");
190 MODULE_DESCRIPTION("21285 watchdog driver");
192 MODULE_PARM(soft_margin,"i");
193 MODULE_PARM_DESC(soft_margin,"Watchdog timeout in seconds");
195 module_init(footbridge_watchdog_init);
196 module_exit(footbridge_watchdog_exit);