blob: c9b8e863f70fcf123c4e97335aad9161b35a41bb [file] [log] [blame]
Thomas Gleixner2874c5f2019-05-27 08:55:01 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
Woody Suwalski4dab06f2006-01-08 01:00:31 -08003 * Wdt977 0.04: A Watchdog Device for Netwinder W83977AF chip
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
5 * (c) Copyright 1998 Rebel.com (Woody Suwalski <woody@netwinder.org>)
6 *
7 * -----------------------
8 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 * -----------------------
10 * 14-Dec-2001 Matt Domsch <Matt_Domsch@dell.com>
11 * Added nowayout module option to override CONFIG_WATCHDOG_NOWAYOUT
12 * 19-Dec-2001 Woody Suwalski: Netwinder fixes, ioctl interface
13 * 06-Jan-2002 Woody Suwalski: For compatibility, convert all timeouts
14 * from minutes to seconds.
15 * 07-Jul-2003 Daniele Bellucci: Audit return code of misc_register in
16 * nwwatchdog_init.
Woody Suwalski4dab06f2006-01-08 01:00:31 -080017 * 25-Oct-2005 Woody Suwalski: Convert addresses to #defs, add spinlocks
Alan Coxf2b79c62008-05-19 14:09:57 +010018 * remove limitiation to be used on
19 * Netwinders only
Linus Torvalds1da177e2005-04-16 15:20:36 -070020 */
21
Joe Perches27c766a2012-02-15 15:06:19 -080022#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
23
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <linux/module.h>
25#include <linux/moduleparam.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <linux/types.h>
27#include <linux/kernel.h>
28#include <linux/fs.h>
29#include <linux/miscdevice.h>
30#include <linux/init.h>
Woody Suwalski4dab06f2006-01-08 01:00:31 -080031#include <linux/ioport.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <linux/watchdog.h>
33#include <linux/notifier.h>
34#include <linux/reboot.h>
Alan Coxf2b79c62008-05-19 14:09:57 +010035#include <linux/io.h>
36#include <linux/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
Linus Torvalds1da177e2005-04-16 15:20:36 -070038#include <asm/mach-types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
Woody Suwalski4dab06f2006-01-08 01:00:31 -080040#define WATCHDOG_VERSION "0.04"
41#define WATCHDOG_NAME "Wdt977"
Woody Suwalski4dab06f2006-01-08 01:00:31 -080042
43#define IO_INDEX_PORT 0x370 /* on some systems it can be 0x3F0 */
Alan Coxf2b79c62008-05-19 14:09:57 +010044#define IO_DATA_PORT (IO_INDEX_PORT + 1)
Woody Suwalski4dab06f2006-01-08 01:00:31 -080045
46#define UNLOCK_DATA 0x87
47#define LOCK_DATA 0xAA
48#define DEVICE_REGISTER 0x07
49
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
51#define DEFAULT_TIMEOUT 60 /* default timeout in seconds */
52
53static int timeout = DEFAULT_TIMEOUT;
54static int timeoutM; /* timeout in minutes */
55static unsigned long timer_alive;
56static int testmode;
57static char expect_close;
Alexey Dobriyanc7dfd0c2007-11-01 16:27:08 -070058static DEFINE_SPINLOCK(spinlock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
60module_param(timeout, int, 0);
Randy Dunlap76550d32010-05-01 09:46:15 -070061MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds (60..15300, default="
Alan Coxf2b79c62008-05-19 14:09:57 +010062 __MODULE_STRING(DEFAULT_TIMEOUT) ")");
Linus Torvalds1da177e2005-04-16 15:20:36 -070063module_param(testmode, int, 0);
Alan Coxf2b79c62008-05-19 14:09:57 +010064MODULE_PARM_DESC(testmode, "Watchdog testmode (1 = no reboot), default=0");
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
Wim Van Sebroeck86a1e182012-03-05 16:51:11 +010066static bool nowayout = WATCHDOG_NOWAYOUT;
67module_param(nowayout, bool, 0);
Alan Coxf2b79c62008-05-19 14:09:57 +010068MODULE_PARM_DESC(nowayout,
69 "Watchdog cannot be stopped once started (default="
70 __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
72/*
73 * Start the watchdog
74 */
75
76static int wdt977_start(void)
77{
Woody Suwalski4dab06f2006-01-08 01:00:31 -080078 unsigned long flags;
79
80 spin_lock_irqsave(&spinlock, flags);
81
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 /* unlock the SuperIO chip */
Woody Suwalski4dab06f2006-01-08 01:00:31 -080083 outb_p(UNLOCK_DATA, IO_INDEX_PORT);
84 outb_p(UNLOCK_DATA, IO_INDEX_PORT);
Linus Torvalds1da177e2005-04-16 15:20:36 -070085
86 /* select device Aux2 (device=8) and set watchdog regs F2, F3 and F4
87 * F2 has the timeout in minutes
88 * F3 could be set to the POWER LED blink (with GP17 set to PowerLed)
89 * at timeout, and to reset timer on kbd/mouse activity (not impl.)
90 * F4 is used to just clear the TIMEOUT'ed state (bit 0)
91 */
Woody Suwalski4dab06f2006-01-08 01:00:31 -080092 outb_p(DEVICE_REGISTER, IO_INDEX_PORT);
93 outb_p(0x08, IO_DATA_PORT);
94 outb_p(0xF2, IO_INDEX_PORT);
95 outb_p(timeoutM, IO_DATA_PORT);
96 outb_p(0xF3, IO_INDEX_PORT);
Alan Coxf2b79c62008-05-19 14:09:57 +010097 outb_p(0x00, IO_DATA_PORT); /* another setting is 0E for
98 kbd/mouse/LED */
Woody Suwalski4dab06f2006-01-08 01:00:31 -080099 outb_p(0xF4, IO_INDEX_PORT);
100 outb_p(0x00, IO_DATA_PORT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101
Alan Coxf2b79c62008-05-19 14:09:57 +0100102 /* At last select device Aux1 (dev=7) and set GP16 as a
103 * watchdog output. In test mode watch the bit 1 on F4 to
104 * indicate "triggered"
105 */
106 if (!testmode) {
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800107 outb_p(DEVICE_REGISTER, IO_INDEX_PORT);
108 outb_p(0x07, IO_DATA_PORT);
109 outb_p(0xE6, IO_INDEX_PORT);
110 outb_p(0x08, IO_DATA_PORT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 }
112
113 /* lock the SuperIO chip */
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800114 outb_p(LOCK_DATA, IO_INDEX_PORT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800116 spin_unlock_irqrestore(&spinlock, flags);
Joe Perches27c766a2012-02-15 15:06:19 -0800117 pr_info("activated\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
119 return 0;
120}
121
122/*
123 * Stop the watchdog
124 */
125
126static int wdt977_stop(void)
127{
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800128 unsigned long flags;
129 spin_lock_irqsave(&spinlock, flags);
130
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 /* unlock the SuperIO chip */
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800132 outb_p(UNLOCK_DATA, IO_INDEX_PORT);
133 outb_p(UNLOCK_DATA, IO_INDEX_PORT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
135 /* select device Aux2 (device=8) and set watchdog regs F2,F3 and F4
136 * F3 is reset to its default state
137 * F4 can clear the TIMEOUT'ed state (bit 0) - back to default
138 * We can not use GP17 as a PowerLed, as we use its usage as a RedLed
139 */
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800140 outb_p(DEVICE_REGISTER, IO_INDEX_PORT);
141 outb_p(0x08, IO_DATA_PORT);
142 outb_p(0xF2, IO_INDEX_PORT);
143 outb_p(0xFF, IO_DATA_PORT);
144 outb_p(0xF3, IO_INDEX_PORT);
145 outb_p(0x00, IO_DATA_PORT);
146 outb_p(0xF4, IO_INDEX_PORT);
147 outb_p(0x00, IO_DATA_PORT);
148 outb_p(0xF2, IO_INDEX_PORT);
149 outb_p(0x00, IO_DATA_PORT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150
Alan Coxf2b79c62008-05-19 14:09:57 +0100151 /* at last select device Aux1 (dev=7) and set
152 GP16 as a watchdog output */
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800153 outb_p(DEVICE_REGISTER, IO_INDEX_PORT);
154 outb_p(0x07, IO_DATA_PORT);
155 outb_p(0xE6, IO_INDEX_PORT);
156 outb_p(0x08, IO_DATA_PORT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157
158 /* lock the SuperIO chip */
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800159 outb_p(LOCK_DATA, IO_INDEX_PORT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800161 spin_unlock_irqrestore(&spinlock, flags);
Joe Perches27c766a2012-02-15 15:06:19 -0800162 pr_info("shutdown\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163
164 return 0;
165}
166
167/*
168 * Send a keepalive ping to the watchdog
169 * This is done by simply re-writing the timeout to reg. 0xF2
170 */
171
172static int wdt977_keepalive(void)
173{
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800174 unsigned long flags;
175 spin_lock_irqsave(&spinlock, flags);
176
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 /* unlock the SuperIO chip */
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800178 outb_p(UNLOCK_DATA, IO_INDEX_PORT);
179 outb_p(UNLOCK_DATA, IO_INDEX_PORT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180
181 /* select device Aux2 (device=8) and kicks watchdog reg F2 */
182 /* F2 has the timeout in minutes */
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800183 outb_p(DEVICE_REGISTER, IO_INDEX_PORT);
184 outb_p(0x08, IO_DATA_PORT);
185 outb_p(0xF2, IO_INDEX_PORT);
186 outb_p(timeoutM, IO_DATA_PORT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187
188 /* lock the SuperIO chip */
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800189 outb_p(LOCK_DATA, IO_INDEX_PORT);
190 spin_unlock_irqrestore(&spinlock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191
192 return 0;
193}
194
195/*
196 * Set the watchdog timeout value
197 */
198
199static int wdt977_set_timeout(int t)
200{
201 int tmrval;
202
203 /* convert seconds to minutes, rounding up */
204 tmrval = (t + 59) / 60;
205
206 if (machine_is_netwinder()) {
Alan Coxf2b79c62008-05-19 14:09:57 +0100207 /* we have a hw bug somewhere, so each 977 minute is actually
208 * only 30sec. This limits the max timeout to half of device
209 * max of 255 minutes...
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 */
211 tmrval += tmrval;
212 }
213
Alan Coxf2b79c62008-05-19 14:09:57 +0100214 if (tmrval < 1 || tmrval > 255)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 return -EINVAL;
216
Alan Coxf2b79c62008-05-19 14:09:57 +0100217 /* timeout is the timeout in seconds, timeoutM is
218 the timeout in minutes) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 timeout = t;
220 timeoutM = tmrval;
221 return 0;
222}
223
224/*
225 * Get the watchdog status
226 */
227
228static int wdt977_get_status(int *status)
229{
230 int new_status;
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800231 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800233 spin_lock_irqsave(&spinlock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234
235 /* unlock the SuperIO chip */
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800236 outb_p(UNLOCK_DATA, IO_INDEX_PORT);
237 outb_p(UNLOCK_DATA, IO_INDEX_PORT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238
239 /* select device Aux2 (device=8) and read watchdog reg F4 */
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800240 outb_p(DEVICE_REGISTER, IO_INDEX_PORT);
241 outb_p(0x08, IO_DATA_PORT);
242 outb_p(0xF4, IO_INDEX_PORT);
243 new_status = inb_p(IO_DATA_PORT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244
245 /* lock the SuperIO chip */
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800246 outb_p(LOCK_DATA, IO_INDEX_PORT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800248 spin_unlock_irqrestore(&spinlock, flags);
249
Alan Coxf2b79c62008-05-19 14:09:57 +0100250 *status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 if (new_status & 1)
252 *status |= WDIOF_CARDRESET;
253
254 return 0;
255}
256
257
258/*
259 * /dev/watchdog handling
260 */
261
262static int wdt977_open(struct inode *inode, struct file *file)
263{
264 /* If the watchdog is alive we don't need to start it again */
Alan Coxf2b79c62008-05-19 14:09:57 +0100265 if (test_and_set_bit(0, &timer_alive))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 return -EBUSY;
267
268 if (nowayout)
269 __module_get(THIS_MODULE);
270
271 wdt977_start();
Kirill Smelkovc5bf68f2019-03-26 23:51:19 +0300272 return stream_open(inode, file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273}
274
275static int wdt977_release(struct inode *inode, struct file *file)
276{
277 /*
278 * Shut off the timer.
Wim Van Sebroeck5f3b2752011-02-23 20:04:38 +0000279 * Lock it in if it's a module and we set nowayout
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 */
Alan Coxf2b79c62008-05-19 14:09:57 +0100281 if (expect_close == 42) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 wdt977_stop();
Alan Coxf2b79c62008-05-19 14:09:57 +0100283 clear_bit(0, &timer_alive);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 wdt977_keepalive();
Joe Perches27c766a2012-02-15 15:06:19 -0800286 pr_crit("Unexpected close, not stopping watchdog!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 }
288 expect_close = 0;
289 return 0;
290}
291
292
293/*
294 * wdt977_write:
295 * @file: file handle to the watchdog
296 * @buf: buffer to write (unused as data does not matter here
297 * @count: count of bytes
298 * @ppos: pointer to the position to write. No seeks allowed
299 *
300 * A write to a watchdog device is defined as a keepalive signal. Any
301 * write of data will do, as we we don't define content meaning.
302 */
303
304static ssize_t wdt977_write(struct file *file, const char __user *buf,
305 size_t count, loff_t *ppos)
306{
Alan Coxf2b79c62008-05-19 14:09:57 +0100307 if (count) {
308 if (!nowayout) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 size_t i;
310
311 /* In case it was set long ago */
312 expect_close = 0;
313
Alan Coxf2b79c62008-05-19 14:09:57 +0100314 for (i = 0; i != count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 char c;
316 if (get_user(c, buf + i))
317 return -EFAULT;
318 if (c == 'V')
319 expect_close = 42;
320 }
321 }
322
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800323 /* someone wrote to us, we should restart timer */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 wdt977_keepalive();
325 }
326 return count;
327}
328
Alan Coxf2b79c62008-05-19 14:09:57 +0100329static const struct watchdog_info ident = {
330 .options = WDIOF_SETTIMEOUT |
331 WDIOF_MAGICCLOSE |
332 WDIOF_KEEPALIVEPING,
333 .firmware_version = 1,
334 .identity = WATCHDOG_NAME,
335};
336
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337/*
338 * wdt977_ioctl:
339 * @inode: inode of the device
340 * @file: file handle to the device
341 * @cmd: watchdog command
342 * @arg: argument pointer
343 *
344 * The watchdog API defines a common set of functions for all watchdogs
345 * according to their available features.
346 */
347
Alan Coxf2b79c62008-05-19 14:09:57 +0100348static long wdt977_ioctl(struct file *file, unsigned int cmd,
349 unsigned long arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350{
351 int status;
352 int new_options, retval = -EINVAL;
353 int new_timeout;
354 union {
355 struct watchdog_info __user *ident;
356 int __user *i;
357 } uarg;
358
359 uarg.i = (int __user *)arg;
360
Alan Coxf2b79c62008-05-19 14:09:57 +0100361 switch (cmd) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 case WDIOC_GETSUPPORT:
363 return copy_to_user(uarg.ident, &ident,
364 sizeof(ident)) ? -EFAULT : 0;
365
366 case WDIOC_GETSTATUS:
367 wdt977_get_status(&status);
368 return put_user(status, uarg.i);
369
370 case WDIOC_GETBOOTSTATUS:
371 return put_user(0, uarg.i);
372
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 case WDIOC_SETOPTIONS:
Alan Coxf2b79c62008-05-19 14:09:57 +0100374 if (get_user(new_options, uarg.i))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 return -EFAULT;
376
377 if (new_options & WDIOS_DISABLECARD) {
378 wdt977_stop();
379 retval = 0;
380 }
381
382 if (new_options & WDIOS_ENABLECARD) {
383 wdt977_start();
384 retval = 0;
385 }
386
387 return retval;
388
Wim Van Sebroeck0c060902008-07-18 11:41:17 +0000389 case WDIOC_KEEPALIVE:
390 wdt977_keepalive();
391 return 0;
392
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 case WDIOC_SETTIMEOUT:
394 if (get_user(new_timeout, uarg.i))
395 return -EFAULT;
396
397 if (wdt977_set_timeout(new_timeout))
Wim Van Sebroeck143a2e52009-03-18 08:35:09 +0000398 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399
400 wdt977_keepalive();
Gustavo A. R. Silvabd490f82020-07-07 12:11:21 -0500401 fallthrough;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402
403 case WDIOC_GETTIMEOUT:
404 return put_user(timeout, uarg.i);
405
Wim Van Sebroeck0c060902008-07-18 11:41:17 +0000406 default:
407 return -ENOTTY;
408
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 }
410}
411
412static int wdt977_notify_sys(struct notifier_block *this, unsigned long code,
413 void *unused)
414{
Alan Coxf2b79c62008-05-19 14:09:57 +0100415 if (code == SYS_DOWN || code == SYS_HALT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 wdt977_stop();
417 return NOTIFY_DONE;
418}
419
Alan Coxf2b79c62008-05-19 14:09:57 +0100420static const struct file_operations wdt977_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 .owner = THIS_MODULE,
422 .llseek = no_llseek,
423 .write = wdt977_write,
Alan Coxf2b79c62008-05-19 14:09:57 +0100424 .unlocked_ioctl = wdt977_ioctl,
Arnd Bergmannb6dfb242019-06-03 14:23:09 +0200425 .compat_ioctl = compat_ptr_ioctl,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 .open = wdt977_open,
427 .release = wdt977_release,
428};
429
Alan Coxf2b79c62008-05-19 14:09:57 +0100430static struct miscdevice wdt977_miscdev = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 .minor = WATCHDOG_MINOR,
432 .name = "watchdog",
433 .fops = &wdt977_fops,
434};
435
436static struct notifier_block wdt977_notifier = {
437 .notifier_call = wdt977_notify_sys,
438};
439
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800440static int __init wd977_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441{
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800442 int rc;
443
Joe Perches27c766a2012-02-15 15:06:19 -0800444 pr_info("driver v%s\n", WATCHDOG_VERSION);
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800445
Alan Coxf2b79c62008-05-19 14:09:57 +0100446 /* Check that the timeout value is within its range;
447 if not reset to the default */
448 if (wdt977_set_timeout(timeout)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 wdt977_set_timeout(DEFAULT_TIMEOUT);
Joe Perches27c766a2012-02-15 15:06:19 -0800450 pr_info("timeout value must be 60 < timeout < 15300, using %d\n",
451 DEFAULT_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 }
453
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800454 /* on Netwinder the IOports are already reserved by
455 * arch/arm/mach-footbridge/netwinder-hw.c
456 */
Alan Coxf2b79c62008-05-19 14:09:57 +0100457 if (!machine_is_netwinder()) {
458 if (!request_region(IO_INDEX_PORT, 2, WATCHDOG_NAME)) {
Joe Perches27c766a2012-02-15 15:06:19 -0800459 pr_err("I/O address 0x%04x already in use\n",
460 IO_INDEX_PORT);
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800461 rc = -EIO;
462 goto err_out;
463 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 }
465
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800466 rc = register_reboot_notifier(&wdt977_notifier);
Alan Coxf2b79c62008-05-19 14:09:57 +0100467 if (rc) {
Joe Perches27c766a2012-02-15 15:06:19 -0800468 pr_err("cannot register reboot notifier (err=%d)\n", rc);
Wim Van Sebroeckc6cb13a2007-12-26 20:32:51 +0000469 goto err_out_region;
470 }
471
472 rc = misc_register(&wdt977_miscdev);
Alan Coxf2b79c62008-05-19 14:09:57 +0100473 if (rc) {
Joe Perches27c766a2012-02-15 15:06:19 -0800474 pr_err("cannot register miscdev on minor=%d (err=%d)\n",
475 wdt977_miscdev.minor, rc);
Wim Van Sebroeckc6cb13a2007-12-26 20:32:51 +0000476 goto err_out_reboot;
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800477 }
478
Joe Perches27c766a2012-02-15 15:06:19 -0800479 pr_info("initialized. timeout=%d sec (nowayout=%d, testmode=%i)\n",
480 timeout, nowayout, testmode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481
482 return 0;
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800483
Wim Van Sebroeckc6cb13a2007-12-26 20:32:51 +0000484err_out_reboot:
485 unregister_reboot_notifier(&wdt977_notifier);
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800486err_out_region:
487 if (!machine_is_netwinder())
Alan Coxf2b79c62008-05-19 14:09:57 +0100488 release_region(IO_INDEX_PORT, 2);
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800489err_out:
490 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491}
492
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800493static void __exit wd977_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494{
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800495 wdt977_stop();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 misc_deregister(&wdt977_miscdev);
497 unregister_reboot_notifier(&wdt977_notifier);
Alan Coxf2b79c62008-05-19 14:09:57 +0100498 release_region(IO_INDEX_PORT, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499}
500
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800501module_init(wd977_init);
502module_exit(wd977_exit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503
Woody Suwalski4dab06f2006-01-08 01:00:31 -0800504MODULE_AUTHOR("Woody Suwalski <woodys@xandros.com>");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505MODULE_DESCRIPTION("W83977AF Watchdog driver");
506MODULE_LICENSE("GPL");