blob: a2f01c9f5c341af0e27079185fb0094adca3a539 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Woody Suwalski4dab06f2006-01-08 01:00:31 -08002 * Wdt977 0.04: A Watchdog Device for Netwinder W83977AF chip
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
4 * (c) Copyright 1998 Rebel.com (Woody Suwalski <woody@netwinder.org>)
5 *
6 * -----------------------
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version
11 * 2 of the License, or (at your option) any later version.
12 *
13 * -----------------------
14 * 14-Dec-2001 Matt Domsch <Matt_Domsch@dell.com>
15 * Added nowayout module option to override CONFIG_WATCHDOG_NOWAYOUT
16 * 19-Dec-2001 Woody Suwalski: Netwinder fixes, ioctl interface
17 * 06-Jan-2002 Woody Suwalski: For compatibility, convert all timeouts
18 * from minutes to seconds.
19 * 07-Jul-2003 Daniele Bellucci: Audit return code of misc_register in
20 * nwwatchdog_init.
Woody Suwalski4dab06f2006-01-08 01:00:31 -080021 * 25-Oct-2005 Woody Suwalski: Convert addresses to #defs, add spinlocks
Alan Coxf2b79c62008-05-19 14:09:57 +010022 * remove limitiation to be used on
23 * Netwinders only
Linus Torvalds1da177e2005-04-16 15:20:36 -070024 */
25
26#include <linux/module.h>
27#include <linux/moduleparam.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <linux/types.h>
29#include <linux/kernel.h>
30#include <linux/fs.h>
31#include <linux/miscdevice.h>
32#include <linux/init.h>
Woody Suwalski4dab06f2006-01-08 01:00:31 -080033#include <linux/ioport.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include <linux/watchdog.h>
35#include <linux/notifier.h>
36#include <linux/reboot.h>
Alan Coxf2b79c62008-05-19 14:09:57 +010037#include <linux/io.h>
38#include <linux/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#include <asm/system.h>
41#include <asm/mach-types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
Woody Suwalski4dab06f2006-01-08 01:00:31 -080043#define WATCHDOG_VERSION "0.04"
44#define WATCHDOG_NAME "Wdt977"
45#define PFX WATCHDOG_NAME ": "
46#define DRIVER_VERSION WATCHDOG_NAME " driver, v" WATCHDOG_VERSION "\n"
47
48#define IO_INDEX_PORT 0x370 /* on some systems it can be 0x3F0 */
Alan Coxf2b79c62008-05-19 14:09:57 +010049#define IO_DATA_PORT (IO_INDEX_PORT + 1)
Woody Suwalski4dab06f2006-01-08 01:00:31 -080050
51#define UNLOCK_DATA 0x87
52#define LOCK_DATA 0xAA
53#define DEVICE_REGISTER 0x07
54
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
56#define DEFAULT_TIMEOUT 60 /* default timeout in seconds */
57
58static int timeout = DEFAULT_TIMEOUT;
59static int timeoutM; /* timeout in minutes */
60static unsigned long timer_alive;
61static int testmode;
62static char expect_close;
Alexey Dobriyanc7dfd0c2007-11-01 16:27:08 -070063static DEFINE_SPINLOCK(spinlock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
65module_param(timeout, int, 0);
Randy Dunlap76550d32010-05-01 09:46:15 -070066MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds (60..15300, default="
Alan Coxf2b79c62008-05-19 14:09:57 +010067 __MODULE_STRING(DEFAULT_TIMEOUT) ")");
Linus Torvalds1da177e2005-04-16 15:20:36 -070068module_param(testmode, int, 0);
Alan Coxf2b79c62008-05-19 14:09:57 +010069MODULE_PARM_DESC(testmode, "Watchdog testmode (1 = no reboot), default=0");
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
Andrey Panin4bfdf372005-07-27 11:43:58 -070071static int nowayout = WATCHDOG_NOWAYOUT;
Linus Torvalds1da177e2005-04-16 15:20:36 -070072module_param(nowayout, int, 0);
Alan Coxf2b79c62008-05-19 14:09:57 +010073MODULE_PARM_DESC(nowayout,
74 "Watchdog cannot be stopped once started (default="
75 __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
77/*
78 * Start the watchdog
79 */
80
81static int wdt977_start(void)
82{
Woody Suwalski4dab06f2006-01-08 01:00:31 -080083 unsigned long flags;
84
85 spin_lock_irqsave(&spinlock, flags);
86
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 /* unlock the SuperIO chip */
Woody Suwalski4dab06f2006-01-08 01:00:31 -080088 outb_p(UNLOCK_DATA, IO_INDEX_PORT);
89 outb_p(UNLOCK_DATA, IO_INDEX_PORT);
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
91 /* select device Aux2 (device=8) and set watchdog regs F2, F3 and F4
92 * F2 has the timeout in minutes
93 * F3 could be set to the POWER LED blink (with GP17 set to PowerLed)
94 * at timeout, and to reset timer on kbd/mouse activity (not impl.)
95 * F4 is used to just clear the TIMEOUT'ed state (bit 0)
96 */
Woody Suwalski4dab06f2006-01-08 01:00:31 -080097 outb_p(DEVICE_REGISTER, IO_INDEX_PORT);
98 outb_p(0x08, IO_DATA_PORT);
99 outb_p(0xF2, IO_INDEX_PORT);
100 outb_p(timeoutM, IO_DATA_PORT);
101 outb_p(0xF3, IO_INDEX_PORT);
Alan Coxf2b79c62008-05-19 14:09:57 +0100102 outb_p(0x00, IO_DATA_PORT); /* another setting is 0E for
103 kbd/mouse/LED */
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800104 outb_p(0xF4, IO_INDEX_PORT);
105 outb_p(0x00, IO_DATA_PORT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106
Alan Coxf2b79c62008-05-19 14:09:57 +0100107 /* At last select device Aux1 (dev=7) and set GP16 as a
108 * watchdog output. In test mode watch the bit 1 on F4 to
109 * indicate "triggered"
110 */
111 if (!testmode) {
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800112 outb_p(DEVICE_REGISTER, IO_INDEX_PORT);
113 outb_p(0x07, IO_DATA_PORT);
114 outb_p(0xE6, IO_INDEX_PORT);
115 outb_p(0x08, IO_DATA_PORT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 }
117
118 /* lock the SuperIO chip */
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800119 outb_p(LOCK_DATA, IO_INDEX_PORT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800121 spin_unlock_irqrestore(&spinlock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 printk(KERN_INFO PFX "activated.\n");
123
124 return 0;
125}
126
127/*
128 * Stop the watchdog
129 */
130
131static int wdt977_stop(void)
132{
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800133 unsigned long flags;
134 spin_lock_irqsave(&spinlock, flags);
135
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 /* unlock the SuperIO chip */
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800137 outb_p(UNLOCK_DATA, IO_INDEX_PORT);
138 outb_p(UNLOCK_DATA, IO_INDEX_PORT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139
140 /* select device Aux2 (device=8) and set watchdog regs F2,F3 and F4
141 * F3 is reset to its default state
142 * F4 can clear the TIMEOUT'ed state (bit 0) - back to default
143 * We can not use GP17 as a PowerLed, as we use its usage as a RedLed
144 */
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800145 outb_p(DEVICE_REGISTER, IO_INDEX_PORT);
146 outb_p(0x08, IO_DATA_PORT);
147 outb_p(0xF2, IO_INDEX_PORT);
148 outb_p(0xFF, IO_DATA_PORT);
149 outb_p(0xF3, IO_INDEX_PORT);
150 outb_p(0x00, IO_DATA_PORT);
151 outb_p(0xF4, IO_INDEX_PORT);
152 outb_p(0x00, IO_DATA_PORT);
153 outb_p(0xF2, IO_INDEX_PORT);
154 outb_p(0x00, IO_DATA_PORT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155
Alan Coxf2b79c62008-05-19 14:09:57 +0100156 /* at last select device Aux1 (dev=7) and set
157 GP16 as a watchdog output */
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800158 outb_p(DEVICE_REGISTER, IO_INDEX_PORT);
159 outb_p(0x07, IO_DATA_PORT);
160 outb_p(0xE6, IO_INDEX_PORT);
161 outb_p(0x08, IO_DATA_PORT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162
163 /* lock the SuperIO chip */
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800164 outb_p(LOCK_DATA, IO_INDEX_PORT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800166 spin_unlock_irqrestore(&spinlock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 printk(KERN_INFO PFX "shutdown.\n");
168
169 return 0;
170}
171
172/*
173 * Send a keepalive ping to the watchdog
174 * This is done by simply re-writing the timeout to reg. 0xF2
175 */
176
177static int wdt977_keepalive(void)
178{
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800179 unsigned long flags;
180 spin_lock_irqsave(&spinlock, flags);
181
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 /* unlock the SuperIO chip */
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800183 outb_p(UNLOCK_DATA, IO_INDEX_PORT);
184 outb_p(UNLOCK_DATA, IO_INDEX_PORT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185
186 /* select device Aux2 (device=8) and kicks watchdog reg F2 */
187 /* F2 has the timeout in minutes */
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800188 outb_p(DEVICE_REGISTER, IO_INDEX_PORT);
189 outb_p(0x08, IO_DATA_PORT);
190 outb_p(0xF2, IO_INDEX_PORT);
191 outb_p(timeoutM, IO_DATA_PORT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192
193 /* lock the SuperIO chip */
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800194 outb_p(LOCK_DATA, IO_INDEX_PORT);
195 spin_unlock_irqrestore(&spinlock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196
197 return 0;
198}
199
200/*
201 * Set the watchdog timeout value
202 */
203
204static int wdt977_set_timeout(int t)
205{
206 int tmrval;
207
208 /* convert seconds to minutes, rounding up */
209 tmrval = (t + 59) / 60;
210
211 if (machine_is_netwinder()) {
Alan Coxf2b79c62008-05-19 14:09:57 +0100212 /* we have a hw bug somewhere, so each 977 minute is actually
213 * only 30sec. This limits the max timeout to half of device
214 * max of 255 minutes...
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 */
216 tmrval += tmrval;
217 }
218
Alan Coxf2b79c62008-05-19 14:09:57 +0100219 if (tmrval < 1 || tmrval > 255)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 return -EINVAL;
221
Alan Coxf2b79c62008-05-19 14:09:57 +0100222 /* timeout is the timeout in seconds, timeoutM is
223 the timeout in minutes) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 timeout = t;
225 timeoutM = tmrval;
226 return 0;
227}
228
229/*
230 * Get the watchdog status
231 */
232
233static int wdt977_get_status(int *status)
234{
235 int new_status;
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800236 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800238 spin_lock_irqsave(&spinlock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239
240 /* unlock the SuperIO chip */
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800241 outb_p(UNLOCK_DATA, IO_INDEX_PORT);
242 outb_p(UNLOCK_DATA, IO_INDEX_PORT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243
244 /* select device Aux2 (device=8) and read watchdog reg F4 */
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800245 outb_p(DEVICE_REGISTER, IO_INDEX_PORT);
246 outb_p(0x08, IO_DATA_PORT);
247 outb_p(0xF4, IO_INDEX_PORT);
248 new_status = inb_p(IO_DATA_PORT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249
250 /* lock the SuperIO chip */
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800251 outb_p(LOCK_DATA, IO_INDEX_PORT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800253 spin_unlock_irqrestore(&spinlock, flags);
254
Alan Coxf2b79c62008-05-19 14:09:57 +0100255 *status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 if (new_status & 1)
257 *status |= WDIOF_CARDRESET;
258
259 return 0;
260}
261
262
263/*
264 * /dev/watchdog handling
265 */
266
267static int wdt977_open(struct inode *inode, struct file *file)
268{
269 /* If the watchdog is alive we don't need to start it again */
Alan Coxf2b79c62008-05-19 14:09:57 +0100270 if (test_and_set_bit(0, &timer_alive))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 return -EBUSY;
272
273 if (nowayout)
274 __module_get(THIS_MODULE);
275
276 wdt977_start();
277 return nonseekable_open(inode, file);
278}
279
280static int wdt977_release(struct inode *inode, struct file *file)
281{
282 /*
283 * Shut off the timer.
Wim Van Sebroeck5f3b2752011-02-23 20:04:38 +0000284 * Lock it in if it's a module and we set nowayout
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 */
Alan Coxf2b79c62008-05-19 14:09:57 +0100286 if (expect_close == 42) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 wdt977_stop();
Alan Coxf2b79c62008-05-19 14:09:57 +0100288 clear_bit(0, &timer_alive);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 wdt977_keepalive();
Alan Coxf2b79c62008-05-19 14:09:57 +0100291 printk(KERN_CRIT PFX
292 "Unexpected close, not stopping watchdog!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 }
294 expect_close = 0;
295 return 0;
296}
297
298
299/*
300 * wdt977_write:
301 * @file: file handle to the watchdog
302 * @buf: buffer to write (unused as data does not matter here
303 * @count: count of bytes
304 * @ppos: pointer to the position to write. No seeks allowed
305 *
306 * A write to a watchdog device is defined as a keepalive signal. Any
307 * write of data will do, as we we don't define content meaning.
308 */
309
310static ssize_t wdt977_write(struct file *file, const char __user *buf,
311 size_t count, loff_t *ppos)
312{
Alan Coxf2b79c62008-05-19 14:09:57 +0100313 if (count) {
314 if (!nowayout) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 size_t i;
316
317 /* In case it was set long ago */
318 expect_close = 0;
319
Alan Coxf2b79c62008-05-19 14:09:57 +0100320 for (i = 0; i != count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321 char c;
322 if (get_user(c, buf + i))
323 return -EFAULT;
324 if (c == 'V')
325 expect_close = 42;
326 }
327 }
328
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800329 /* someone wrote to us, we should restart timer */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 wdt977_keepalive();
331 }
332 return count;
333}
334
Alan Coxf2b79c62008-05-19 14:09:57 +0100335static const struct watchdog_info ident = {
336 .options = WDIOF_SETTIMEOUT |
337 WDIOF_MAGICCLOSE |
338 WDIOF_KEEPALIVEPING,
339 .firmware_version = 1,
340 .identity = WATCHDOG_NAME,
341};
342
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343/*
344 * wdt977_ioctl:
345 * @inode: inode of the device
346 * @file: file handle to the device
347 * @cmd: watchdog command
348 * @arg: argument pointer
349 *
350 * The watchdog API defines a common set of functions for all watchdogs
351 * according to their available features.
352 */
353
Alan Coxf2b79c62008-05-19 14:09:57 +0100354static long wdt977_ioctl(struct file *file, unsigned int cmd,
355 unsigned long arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356{
357 int status;
358 int new_options, retval = -EINVAL;
359 int new_timeout;
360 union {
361 struct watchdog_info __user *ident;
362 int __user *i;
363 } uarg;
364
365 uarg.i = (int __user *)arg;
366
Alan Coxf2b79c62008-05-19 14:09:57 +0100367 switch (cmd) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 case WDIOC_GETSUPPORT:
369 return copy_to_user(uarg.ident, &ident,
370 sizeof(ident)) ? -EFAULT : 0;
371
372 case WDIOC_GETSTATUS:
373 wdt977_get_status(&status);
374 return put_user(status, uarg.i);
375
376 case WDIOC_GETBOOTSTATUS:
377 return put_user(0, uarg.i);
378
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 case WDIOC_SETOPTIONS:
Alan Coxf2b79c62008-05-19 14:09:57 +0100380 if (get_user(new_options, uarg.i))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 return -EFAULT;
382
383 if (new_options & WDIOS_DISABLECARD) {
384 wdt977_stop();
385 retval = 0;
386 }
387
388 if (new_options & WDIOS_ENABLECARD) {
389 wdt977_start();
390 retval = 0;
391 }
392
393 return retval;
394
Wim Van Sebroeck0c060902008-07-18 11:41:17 +0000395 case WDIOC_KEEPALIVE:
396 wdt977_keepalive();
397 return 0;
398
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 case WDIOC_SETTIMEOUT:
400 if (get_user(new_timeout, uarg.i))
401 return -EFAULT;
402
403 if (wdt977_set_timeout(new_timeout))
Wim Van Sebroeck143a2e52009-03-18 08:35:09 +0000404 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405
406 wdt977_keepalive();
407 /* Fall */
408
409 case WDIOC_GETTIMEOUT:
410 return put_user(timeout, uarg.i);
411
Wim Van Sebroeck0c060902008-07-18 11:41:17 +0000412 default:
413 return -ENOTTY;
414
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 }
416}
417
418static int wdt977_notify_sys(struct notifier_block *this, unsigned long code,
419 void *unused)
420{
Alan Coxf2b79c62008-05-19 14:09:57 +0100421 if (code == SYS_DOWN || code == SYS_HALT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 wdt977_stop();
423 return NOTIFY_DONE;
424}
425
Alan Coxf2b79c62008-05-19 14:09:57 +0100426static const struct file_operations wdt977_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 .owner = THIS_MODULE,
428 .llseek = no_llseek,
429 .write = wdt977_write,
Alan Coxf2b79c62008-05-19 14:09:57 +0100430 .unlocked_ioctl = wdt977_ioctl,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 .open = wdt977_open,
432 .release = wdt977_release,
433};
434
Alan Coxf2b79c62008-05-19 14:09:57 +0100435static struct miscdevice wdt977_miscdev = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 .minor = WATCHDOG_MINOR,
437 .name = "watchdog",
438 .fops = &wdt977_fops,
439};
440
441static struct notifier_block wdt977_notifier = {
442 .notifier_call = wdt977_notify_sys,
443};
444
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800445static int __init wd977_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446{
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800447 int rc;
448
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800449 printk(KERN_INFO PFX DRIVER_VERSION);
450
Alan Coxf2b79c62008-05-19 14:09:57 +0100451 /* Check that the timeout value is within its range;
452 if not reset to the default */
453 if (wdt977_set_timeout(timeout)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 wdt977_set_timeout(DEFAULT_TIMEOUT);
Alan Coxf2b79c62008-05-19 14:09:57 +0100455 printk(KERN_INFO PFX
456 "timeout value must be 60 < timeout < 15300, using %d\n",
457 DEFAULT_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 }
459
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800460 /* on Netwinder the IOports are already reserved by
461 * arch/arm/mach-footbridge/netwinder-hw.c
462 */
Alan Coxf2b79c62008-05-19 14:09:57 +0100463 if (!machine_is_netwinder()) {
464 if (!request_region(IO_INDEX_PORT, 2, WATCHDOG_NAME)) {
465 printk(KERN_ERR PFX
466 "I/O address 0x%04x already in use\n",
467 IO_INDEX_PORT);
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800468 rc = -EIO;
469 goto err_out;
470 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 }
472
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800473 rc = register_reboot_notifier(&wdt977_notifier);
Alan Coxf2b79c62008-05-19 14:09:57 +0100474 if (rc) {
475 printk(KERN_ERR PFX
476 "cannot register reboot notifier (err=%d)\n", rc);
Wim Van Sebroeckc6cb13a2007-12-26 20:32:51 +0000477 goto err_out_region;
478 }
479
480 rc = misc_register(&wdt977_miscdev);
Alan Coxf2b79c62008-05-19 14:09:57 +0100481 if (rc) {
482 printk(KERN_ERR PFX
483 "cannot register miscdev on minor=%d (err=%d)\n",
484 wdt977_miscdev.minor, rc);
Wim Van Sebroeckc6cb13a2007-12-26 20:32:51 +0000485 goto err_out_reboot;
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800486 }
487
Alan Coxf2b79c62008-05-19 14:09:57 +0100488 printk(KERN_INFO PFX
489 "initialized. timeout=%d sec (nowayout=%d, testmode=%i)\n",
490 timeout, nowayout, testmode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491
492 return 0;
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800493
Wim Van Sebroeckc6cb13a2007-12-26 20:32:51 +0000494err_out_reboot:
495 unregister_reboot_notifier(&wdt977_notifier);
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800496err_out_region:
497 if (!machine_is_netwinder())
Alan Coxf2b79c62008-05-19 14:09:57 +0100498 release_region(IO_INDEX_PORT, 2);
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800499err_out:
500 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501}
502
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800503static void __exit wd977_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504{
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800505 wdt977_stop();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 misc_deregister(&wdt977_miscdev);
507 unregister_reboot_notifier(&wdt977_notifier);
Alan Coxf2b79c62008-05-19 14:09:57 +0100508 release_region(IO_INDEX_PORT, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509}
510
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800511module_init(wd977_init);
512module_exit(wd977_exit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800514MODULE_AUTHOR("Woody Suwalski <woodys@xandros.com>");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515MODULE_DESCRIPTION("W83977AF Watchdog driver");
516MODULE_LICENSE("GPL");
517MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);