blob: 65a402344933952176170de888311d72fe0bd157 [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
Joe Perches27c766a2012-02-15 15:06:19 -080026#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
27
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <linux/module.h>
29#include <linux/moduleparam.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <linux/types.h>
31#include <linux/kernel.h>
32#include <linux/fs.h>
33#include <linux/miscdevice.h>
34#include <linux/init.h>
Woody Suwalski4dab06f2006-01-08 01:00:31 -080035#include <linux/ioport.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <linux/watchdog.h>
37#include <linux/notifier.h>
38#include <linux/reboot.h>
Alan Coxf2b79c62008-05-19 14:09:57 +010039#include <linux/io.h>
40#include <linux/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#include <asm/mach-types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
Woody Suwalski4dab06f2006-01-08 01:00:31 -080044#define WATCHDOG_VERSION "0.04"
45#define WATCHDOG_NAME "Wdt977"
Woody Suwalski4dab06f2006-01-08 01:00:31 -080046
47#define IO_INDEX_PORT 0x370 /* on some systems it can be 0x3F0 */
Alan Coxf2b79c62008-05-19 14:09:57 +010048#define IO_DATA_PORT (IO_INDEX_PORT + 1)
Woody Suwalski4dab06f2006-01-08 01:00:31 -080049
50#define UNLOCK_DATA 0x87
51#define LOCK_DATA 0xAA
52#define DEVICE_REGISTER 0x07
53
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
55#define DEFAULT_TIMEOUT 60 /* default timeout in seconds */
56
57static int timeout = DEFAULT_TIMEOUT;
58static int timeoutM; /* timeout in minutes */
59static unsigned long timer_alive;
60static int testmode;
61static char expect_close;
Alexey Dobriyanc7dfd0c2007-11-01 16:27:08 -070062static DEFINE_SPINLOCK(spinlock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
64module_param(timeout, int, 0);
Randy Dunlap76550d32010-05-01 09:46:15 -070065MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds (60..15300, default="
Alan Coxf2b79c62008-05-19 14:09:57 +010066 __MODULE_STRING(DEFAULT_TIMEOUT) ")");
Linus Torvalds1da177e2005-04-16 15:20:36 -070067module_param(testmode, int, 0);
Alan Coxf2b79c62008-05-19 14:09:57 +010068MODULE_PARM_DESC(testmode, "Watchdog testmode (1 = no reboot), default=0");
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
Wim Van Sebroeck86a1e182012-03-05 16:51:11 +010070static bool nowayout = WATCHDOG_NOWAYOUT;
71module_param(nowayout, bool, 0);
Alan Coxf2b79c62008-05-19 14:09:57 +010072MODULE_PARM_DESC(nowayout,
73 "Watchdog cannot be stopped once started (default="
74 __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
76/*
77 * Start the watchdog
78 */
79
80static int wdt977_start(void)
81{
Woody Suwalski4dab06f2006-01-08 01:00:31 -080082 unsigned long flags;
83
84 spin_lock_irqsave(&spinlock, flags);
85
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 /* unlock the SuperIO chip */
Woody Suwalski4dab06f2006-01-08 01:00:31 -080087 outb_p(UNLOCK_DATA, IO_INDEX_PORT);
88 outb_p(UNLOCK_DATA, IO_INDEX_PORT);
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
90 /* select device Aux2 (device=8) and set watchdog regs F2, F3 and F4
91 * F2 has the timeout in minutes
92 * F3 could be set to the POWER LED blink (with GP17 set to PowerLed)
93 * at timeout, and to reset timer on kbd/mouse activity (not impl.)
94 * F4 is used to just clear the TIMEOUT'ed state (bit 0)
95 */
Woody Suwalski4dab06f2006-01-08 01:00:31 -080096 outb_p(DEVICE_REGISTER, IO_INDEX_PORT);
97 outb_p(0x08, IO_DATA_PORT);
98 outb_p(0xF2, IO_INDEX_PORT);
99 outb_p(timeoutM, IO_DATA_PORT);
100 outb_p(0xF3, IO_INDEX_PORT);
Alan Coxf2b79c62008-05-19 14:09:57 +0100101 outb_p(0x00, IO_DATA_PORT); /* another setting is 0E for
102 kbd/mouse/LED */
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800103 outb_p(0xF4, IO_INDEX_PORT);
104 outb_p(0x00, IO_DATA_PORT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105
Alan Coxf2b79c62008-05-19 14:09:57 +0100106 /* At last select device Aux1 (dev=7) and set GP16 as a
107 * watchdog output. In test mode watch the bit 1 on F4 to
108 * indicate "triggered"
109 */
110 if (!testmode) {
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800111 outb_p(DEVICE_REGISTER, IO_INDEX_PORT);
112 outb_p(0x07, IO_DATA_PORT);
113 outb_p(0xE6, IO_INDEX_PORT);
114 outb_p(0x08, IO_DATA_PORT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 }
116
117 /* lock the SuperIO chip */
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800118 outb_p(LOCK_DATA, IO_INDEX_PORT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800120 spin_unlock_irqrestore(&spinlock, flags);
Joe Perches27c766a2012-02-15 15:06:19 -0800121 pr_info("activated\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
123 return 0;
124}
125
126/*
127 * Stop the watchdog
128 */
129
130static int wdt977_stop(void)
131{
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800132 unsigned long flags;
133 spin_lock_irqsave(&spinlock, flags);
134
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 /* unlock the SuperIO chip */
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800136 outb_p(UNLOCK_DATA, IO_INDEX_PORT);
137 outb_p(UNLOCK_DATA, IO_INDEX_PORT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138
139 /* select device Aux2 (device=8) and set watchdog regs F2,F3 and F4
140 * F3 is reset to its default state
141 * F4 can clear the TIMEOUT'ed state (bit 0) - back to default
142 * We can not use GP17 as a PowerLed, as we use its usage as a RedLed
143 */
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800144 outb_p(DEVICE_REGISTER, IO_INDEX_PORT);
145 outb_p(0x08, IO_DATA_PORT);
146 outb_p(0xF2, IO_INDEX_PORT);
147 outb_p(0xFF, IO_DATA_PORT);
148 outb_p(0xF3, IO_INDEX_PORT);
149 outb_p(0x00, IO_DATA_PORT);
150 outb_p(0xF4, IO_INDEX_PORT);
151 outb_p(0x00, IO_DATA_PORT);
152 outb_p(0xF2, IO_INDEX_PORT);
153 outb_p(0x00, IO_DATA_PORT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154
Alan Coxf2b79c62008-05-19 14:09:57 +0100155 /* at last select device Aux1 (dev=7) and set
156 GP16 as a watchdog output */
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800157 outb_p(DEVICE_REGISTER, IO_INDEX_PORT);
158 outb_p(0x07, IO_DATA_PORT);
159 outb_p(0xE6, IO_INDEX_PORT);
160 outb_p(0x08, IO_DATA_PORT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161
162 /* lock the SuperIO chip */
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800163 outb_p(LOCK_DATA, IO_INDEX_PORT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800165 spin_unlock_irqrestore(&spinlock, flags);
Joe Perches27c766a2012-02-15 15:06:19 -0800166 pr_info("shutdown\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167
168 return 0;
169}
170
171/*
172 * Send a keepalive ping to the watchdog
173 * This is done by simply re-writing the timeout to reg. 0xF2
174 */
175
176static int wdt977_keepalive(void)
177{
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800178 unsigned long flags;
179 spin_lock_irqsave(&spinlock, flags);
180
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 /* unlock the SuperIO chip */
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800182 outb_p(UNLOCK_DATA, IO_INDEX_PORT);
183 outb_p(UNLOCK_DATA, IO_INDEX_PORT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184
185 /* select device Aux2 (device=8) and kicks watchdog reg F2 */
186 /* F2 has the timeout in minutes */
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800187 outb_p(DEVICE_REGISTER, IO_INDEX_PORT);
188 outb_p(0x08, IO_DATA_PORT);
189 outb_p(0xF2, IO_INDEX_PORT);
190 outb_p(timeoutM, IO_DATA_PORT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191
192 /* lock the SuperIO chip */
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800193 outb_p(LOCK_DATA, IO_INDEX_PORT);
194 spin_unlock_irqrestore(&spinlock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195
196 return 0;
197}
198
199/*
200 * Set the watchdog timeout value
201 */
202
203static int wdt977_set_timeout(int t)
204{
205 int tmrval;
206
207 /* convert seconds to minutes, rounding up */
208 tmrval = (t + 59) / 60;
209
210 if (machine_is_netwinder()) {
Alan Coxf2b79c62008-05-19 14:09:57 +0100211 /* we have a hw bug somewhere, so each 977 minute is actually
212 * only 30sec. This limits the max timeout to half of device
213 * max of 255 minutes...
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 */
215 tmrval += tmrval;
216 }
217
Alan Coxf2b79c62008-05-19 14:09:57 +0100218 if (tmrval < 1 || tmrval > 255)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 return -EINVAL;
220
Alan Coxf2b79c62008-05-19 14:09:57 +0100221 /* timeout is the timeout in seconds, timeoutM is
222 the timeout in minutes) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 timeout = t;
224 timeoutM = tmrval;
225 return 0;
226}
227
228/*
229 * Get the watchdog status
230 */
231
232static int wdt977_get_status(int *status)
233{
234 int new_status;
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800235 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800237 spin_lock_irqsave(&spinlock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238
239 /* unlock the SuperIO chip */
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800240 outb_p(UNLOCK_DATA, IO_INDEX_PORT);
241 outb_p(UNLOCK_DATA, IO_INDEX_PORT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242
243 /* select device Aux2 (device=8) and read watchdog reg F4 */
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800244 outb_p(DEVICE_REGISTER, IO_INDEX_PORT);
245 outb_p(0x08, IO_DATA_PORT);
246 outb_p(0xF4, IO_INDEX_PORT);
247 new_status = inb_p(IO_DATA_PORT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248
249 /* lock the SuperIO chip */
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800250 outb_p(LOCK_DATA, IO_INDEX_PORT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800252 spin_unlock_irqrestore(&spinlock, flags);
253
Alan Coxf2b79c62008-05-19 14:09:57 +0100254 *status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 if (new_status & 1)
256 *status |= WDIOF_CARDRESET;
257
258 return 0;
259}
260
261
262/*
263 * /dev/watchdog handling
264 */
265
266static int wdt977_open(struct inode *inode, struct file *file)
267{
268 /* If the watchdog is alive we don't need to start it again */
Alan Coxf2b79c62008-05-19 14:09:57 +0100269 if (test_and_set_bit(0, &timer_alive))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 return -EBUSY;
271
272 if (nowayout)
273 __module_get(THIS_MODULE);
274
275 wdt977_start();
276 return nonseekable_open(inode, file);
277}
278
279static int wdt977_release(struct inode *inode, struct file *file)
280{
281 /*
282 * Shut off the timer.
Wim Van Sebroeck5f3b2752011-02-23 20:04:38 +0000283 * Lock it in if it's a module and we set nowayout
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 */
Alan Coxf2b79c62008-05-19 14:09:57 +0100285 if (expect_close == 42) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 wdt977_stop();
Alan Coxf2b79c62008-05-19 14:09:57 +0100287 clear_bit(0, &timer_alive);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 wdt977_keepalive();
Joe Perches27c766a2012-02-15 15:06:19 -0800290 pr_crit("Unexpected close, not stopping watchdog!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 }
292 expect_close = 0;
293 return 0;
294}
295
296
297/*
298 * wdt977_write:
299 * @file: file handle to the watchdog
300 * @buf: buffer to write (unused as data does not matter here
301 * @count: count of bytes
302 * @ppos: pointer to the position to write. No seeks allowed
303 *
304 * A write to a watchdog device is defined as a keepalive signal. Any
305 * write of data will do, as we we don't define content meaning.
306 */
307
308static ssize_t wdt977_write(struct file *file, const char __user *buf,
309 size_t count, loff_t *ppos)
310{
Alan Coxf2b79c62008-05-19 14:09:57 +0100311 if (count) {
312 if (!nowayout) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 size_t i;
314
315 /* In case it was set long ago */
316 expect_close = 0;
317
Alan Coxf2b79c62008-05-19 14:09:57 +0100318 for (i = 0; i != count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 char c;
320 if (get_user(c, buf + i))
321 return -EFAULT;
322 if (c == 'V')
323 expect_close = 42;
324 }
325 }
326
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800327 /* someone wrote to us, we should restart timer */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 wdt977_keepalive();
329 }
330 return count;
331}
332
Alan Coxf2b79c62008-05-19 14:09:57 +0100333static const struct watchdog_info ident = {
334 .options = WDIOF_SETTIMEOUT |
335 WDIOF_MAGICCLOSE |
336 WDIOF_KEEPALIVEPING,
337 .firmware_version = 1,
338 .identity = WATCHDOG_NAME,
339};
340
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341/*
342 * wdt977_ioctl:
343 * @inode: inode of the device
344 * @file: file handle to the device
345 * @cmd: watchdog command
346 * @arg: argument pointer
347 *
348 * The watchdog API defines a common set of functions for all watchdogs
349 * according to their available features.
350 */
351
Alan Coxf2b79c62008-05-19 14:09:57 +0100352static long wdt977_ioctl(struct file *file, unsigned int cmd,
353 unsigned long arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354{
355 int status;
356 int new_options, retval = -EINVAL;
357 int new_timeout;
358 union {
359 struct watchdog_info __user *ident;
360 int __user *i;
361 } uarg;
362
363 uarg.i = (int __user *)arg;
364
Alan Coxf2b79c62008-05-19 14:09:57 +0100365 switch (cmd) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 case WDIOC_GETSUPPORT:
367 return copy_to_user(uarg.ident, &ident,
368 sizeof(ident)) ? -EFAULT : 0;
369
370 case WDIOC_GETSTATUS:
371 wdt977_get_status(&status);
372 return put_user(status, uarg.i);
373
374 case WDIOC_GETBOOTSTATUS:
375 return put_user(0, uarg.i);
376
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 case WDIOC_SETOPTIONS:
Alan Coxf2b79c62008-05-19 14:09:57 +0100378 if (get_user(new_options, uarg.i))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 return -EFAULT;
380
381 if (new_options & WDIOS_DISABLECARD) {
382 wdt977_stop();
383 retval = 0;
384 }
385
386 if (new_options & WDIOS_ENABLECARD) {
387 wdt977_start();
388 retval = 0;
389 }
390
391 return retval;
392
Wim Van Sebroeck0c06090c2008-07-18 11:41:17 +0000393 case WDIOC_KEEPALIVE:
394 wdt977_keepalive();
395 return 0;
396
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 case WDIOC_SETTIMEOUT:
398 if (get_user(new_timeout, uarg.i))
399 return -EFAULT;
400
401 if (wdt977_set_timeout(new_timeout))
Wim Van Sebroeck143a2e52009-03-18 08:35:09 +0000402 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403
404 wdt977_keepalive();
405 /* Fall */
406
407 case WDIOC_GETTIMEOUT:
408 return put_user(timeout, uarg.i);
409
Wim Van Sebroeck0c06090c2008-07-18 11:41:17 +0000410 default:
411 return -ENOTTY;
412
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 }
414}
415
416static int wdt977_notify_sys(struct notifier_block *this, unsigned long code,
417 void *unused)
418{
Alan Coxf2b79c62008-05-19 14:09:57 +0100419 if (code == SYS_DOWN || code == SYS_HALT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 wdt977_stop();
421 return NOTIFY_DONE;
422}
423
Alan Coxf2b79c62008-05-19 14:09:57 +0100424static const struct file_operations wdt977_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 .owner = THIS_MODULE,
426 .llseek = no_llseek,
427 .write = wdt977_write,
Alan Coxf2b79c62008-05-19 14:09:57 +0100428 .unlocked_ioctl = wdt977_ioctl,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 .open = wdt977_open,
430 .release = wdt977_release,
431};
432
Alan Coxf2b79c62008-05-19 14:09:57 +0100433static struct miscdevice wdt977_miscdev = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 .minor = WATCHDOG_MINOR,
435 .name = "watchdog",
436 .fops = &wdt977_fops,
437};
438
439static struct notifier_block wdt977_notifier = {
440 .notifier_call = wdt977_notify_sys,
441};
442
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800443static int __init wd977_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444{
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800445 int rc;
446
Joe Perches27c766a2012-02-15 15:06:19 -0800447 pr_info("driver v%s\n", WATCHDOG_VERSION);
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800448
Alan Coxf2b79c62008-05-19 14:09:57 +0100449 /* Check that the timeout value is within its range;
450 if not reset to the default */
451 if (wdt977_set_timeout(timeout)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 wdt977_set_timeout(DEFAULT_TIMEOUT);
Joe Perches27c766a2012-02-15 15:06:19 -0800453 pr_info("timeout value must be 60 < timeout < 15300, using %d\n",
454 DEFAULT_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 }
456
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800457 /* on Netwinder the IOports are already reserved by
458 * arch/arm/mach-footbridge/netwinder-hw.c
459 */
Alan Coxf2b79c62008-05-19 14:09:57 +0100460 if (!machine_is_netwinder()) {
461 if (!request_region(IO_INDEX_PORT, 2, WATCHDOG_NAME)) {
Joe Perches27c766a2012-02-15 15:06:19 -0800462 pr_err("I/O address 0x%04x already in use\n",
463 IO_INDEX_PORT);
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800464 rc = -EIO;
465 goto err_out;
466 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 }
468
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800469 rc = register_reboot_notifier(&wdt977_notifier);
Alan Coxf2b79c62008-05-19 14:09:57 +0100470 if (rc) {
Joe Perches27c766a2012-02-15 15:06:19 -0800471 pr_err("cannot register reboot notifier (err=%d)\n", rc);
Wim Van Sebroeckc6cb13a2007-12-26 20:32:51 +0000472 goto err_out_region;
473 }
474
475 rc = misc_register(&wdt977_miscdev);
Alan Coxf2b79c62008-05-19 14:09:57 +0100476 if (rc) {
Joe Perches27c766a2012-02-15 15:06:19 -0800477 pr_err("cannot register miscdev on minor=%d (err=%d)\n",
478 wdt977_miscdev.minor, rc);
Wim Van Sebroeckc6cb13a2007-12-26 20:32:51 +0000479 goto err_out_reboot;
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800480 }
481
Joe Perches27c766a2012-02-15 15:06:19 -0800482 pr_info("initialized. timeout=%d sec (nowayout=%d, testmode=%i)\n",
483 timeout, nowayout, testmode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484
485 return 0;
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800486
Wim Van Sebroeckc6cb13a2007-12-26 20:32:51 +0000487err_out_reboot:
488 unregister_reboot_notifier(&wdt977_notifier);
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800489err_out_region:
490 if (!machine_is_netwinder())
Alan Coxf2b79c62008-05-19 14:09:57 +0100491 release_region(IO_INDEX_PORT, 2);
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800492err_out:
493 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494}
495
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800496static void __exit wd977_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497{
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800498 wdt977_stop();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 misc_deregister(&wdt977_miscdev);
500 unregister_reboot_notifier(&wdt977_notifier);
Alan Coxf2b79c62008-05-19 14:09:57 +0100501 release_region(IO_INDEX_PORT, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502}
503
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800504module_init(wd977_init);
505module_exit(wd977_exit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800507MODULE_AUTHOR("Woody Suwalski <woodys@xandros.com>");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508MODULE_DESCRIPTION("W83977AF Watchdog driver");
509MODULE_LICENSE("GPL");
510MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);