blob: 5212e68c6b016593a0b94180e7af4fc1f877c093 [file] [log] [blame]
Thomas Gleixner2874c5f2019-05-27 08:55:01 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Jose Miguel Goncalvesb4cc4aa2005-09-06 17:05:30 -07002/*
3 * W83977F Watchdog Timer Driver for Winbond W83977F I/O Chip
4 *
5 * (c) Copyright 2005 Jose Goncalves <jose.goncalves@inov.pt>
6 *
7 * Based on w83877f_wdt.c by Scott Jennings,
8 * and wdt977.c by Woody Suwalski
9 *
10 * -----------------------
Jose Miguel Goncalvesb4cc4aa2005-09-06 17:05:30 -070011 */
12
Joe Perches27c766a2012-02-15 15:06:19 -080013#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
14
Jose Miguel Goncalvesb4cc4aa2005-09-06 17:05:30 -070015#include <linux/module.h>
16#include <linux/moduleparam.h>
Jose Miguel Goncalvesb4cc4aa2005-09-06 17:05:30 -070017#include <linux/types.h>
18#include <linux/kernel.h>
19#include <linux/fs.h>
20#include <linux/miscdevice.h>
21#include <linux/init.h>
22#include <linux/ioport.h>
23#include <linux/watchdog.h>
24#include <linux/notifier.h>
25#include <linux/reboot.h>
Alan Cox84af4012008-05-19 14:09:34 +010026#include <linux/uaccess.h>
27#include <linux/io.h>
Jose Miguel Goncalvesb4cc4aa2005-09-06 17:05:30 -070028
Jose Miguel Goncalvesb4cc4aa2005-09-06 17:05:30 -070029
30#define WATCHDOG_VERSION "1.00"
31#define WATCHDOG_NAME "W83977F WDT"
Jose Miguel Goncalvesb4cc4aa2005-09-06 17:05:30 -070032
33#define IO_INDEX_PORT 0x3F0
34#define IO_DATA_PORT (IO_INDEX_PORT+1)
35
36#define UNLOCK_DATA 0x87
37#define LOCK_DATA 0xAA
38#define DEVICE_REGISTER 0x07
39
40#define DEFAULT_TIMEOUT 45 /* default timeout in seconds */
41
42static int timeout = DEFAULT_TIMEOUT;
43static int timeoutW; /* timeout in watchdog counter units */
44static unsigned long timer_alive;
45static int testmode;
46static char expect_close;
Alexey Dobriyanc7dfd0c2007-11-01 16:27:08 -070047static DEFINE_SPINLOCK(spinlock);
Jose Miguel Goncalvesb4cc4aa2005-09-06 17:05:30 -070048
49module_param(timeout, int, 0);
Alan Cox84af4012008-05-19 14:09:34 +010050MODULE_PARM_DESC(timeout,
51 "Watchdog timeout in seconds (15..7635), default="
52 __MODULE_STRING(DEFAULT_TIMEOUT) ")");
Jose Miguel Goncalvesb4cc4aa2005-09-06 17:05:30 -070053module_param(testmode, int, 0);
Alan Cox84af4012008-05-19 14:09:34 +010054MODULE_PARM_DESC(testmode, "Watchdog testmode (1 = no reboot), default=0");
Jose Miguel Goncalvesb4cc4aa2005-09-06 17:05:30 -070055
Wim Van Sebroeck86a1e182012-03-05 16:51:11 +010056static bool nowayout = WATCHDOG_NOWAYOUT;
57module_param(nowayout, bool, 0);
Alan Cox84af4012008-05-19 14:09:34 +010058MODULE_PARM_DESC(nowayout,
59 "Watchdog cannot be stopped once started (default="
60 __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
Jose Miguel Goncalvesb4cc4aa2005-09-06 17:05:30 -070061
62/*
63 * Start the watchdog
64 */
65
66static int wdt_start(void)
67{
68 unsigned long flags;
69
70 spin_lock_irqsave(&spinlock, flags);
71
72 /* Unlock the SuperIO chip */
Alan Cox84af4012008-05-19 14:09:34 +010073 outb_p(UNLOCK_DATA, IO_INDEX_PORT);
74 outb_p(UNLOCK_DATA, IO_INDEX_PORT);
Jose Miguel Goncalvesb4cc4aa2005-09-06 17:05:30 -070075
76 /*
77 * Select device Aux2 (device=8) to set watchdog regs F2, F3 and F4.
78 * F2 has the timeout in watchdog counter units.
79 * F3 is set to enable watchdog LED blink at timeout.
80 * F4 is used to just clear the TIMEOUT'ed state (bit 0).
81 */
Alan Cox84af4012008-05-19 14:09:34 +010082 outb_p(DEVICE_REGISTER, IO_INDEX_PORT);
83 outb_p(0x08, IO_DATA_PORT);
84 outb_p(0xF2, IO_INDEX_PORT);
85 outb_p(timeoutW, IO_DATA_PORT);
86 outb_p(0xF3, IO_INDEX_PORT);
87 outb_p(0x08, IO_DATA_PORT);
88 outb_p(0xF4, IO_INDEX_PORT);
89 outb_p(0x00, IO_DATA_PORT);
Jose Miguel Goncalvesb4cc4aa2005-09-06 17:05:30 -070090
91 /* Set device Aux2 active */
Alan Cox84af4012008-05-19 14:09:34 +010092 outb_p(0x30, IO_INDEX_PORT);
93 outb_p(0x01, IO_DATA_PORT);
Jose Miguel Goncalvesb4cc4aa2005-09-06 17:05:30 -070094
Alan Cox84af4012008-05-19 14:09:34 +010095 /*
Jose Miguel Goncalvesb4cc4aa2005-09-06 17:05:30 -070096 * Select device Aux1 (dev=7) to set GP16 as the watchdog output
97 * (in reg E6) and GP13 as the watchdog LED output (in reg E3).
98 * Map GP16 at pin 119.
99 * In test mode watch the bit 0 on F4 to indicate "triggered" or
100 * check watchdog LED on SBC.
101 */
Alan Cox84af4012008-05-19 14:09:34 +0100102 outb_p(DEVICE_REGISTER, IO_INDEX_PORT);
103 outb_p(0x07, IO_DATA_PORT);
104 if (!testmode) {
Jose Miguel Goncalvesb4cc4aa2005-09-06 17:05:30 -0700105 unsigned pin_map;
106
Alan Cox84af4012008-05-19 14:09:34 +0100107 outb_p(0xE6, IO_INDEX_PORT);
108 outb_p(0x0A, IO_DATA_PORT);
109 outb_p(0x2C, IO_INDEX_PORT);
Jose Miguel Goncalvesb4cc4aa2005-09-06 17:05:30 -0700110 pin_map = inb_p(IO_DATA_PORT);
111 pin_map |= 0x10;
112 pin_map &= ~(0x20);
Alan Cox84af4012008-05-19 14:09:34 +0100113 outb_p(0x2C, IO_INDEX_PORT);
114 outb_p(pin_map, IO_DATA_PORT);
Jose Miguel Goncalvesb4cc4aa2005-09-06 17:05:30 -0700115 }
Alan Cox84af4012008-05-19 14:09:34 +0100116 outb_p(0xE3, IO_INDEX_PORT);
117 outb_p(0x08, IO_DATA_PORT);
Jose Miguel Goncalvesb4cc4aa2005-09-06 17:05:30 -0700118
119 /* Set device Aux1 active */
Alan Cox84af4012008-05-19 14:09:34 +0100120 outb_p(0x30, IO_INDEX_PORT);
121 outb_p(0x01, IO_DATA_PORT);
Jose Miguel Goncalvesb4cc4aa2005-09-06 17:05:30 -0700122
123 /* Lock the SuperIO chip */
Alan Cox84af4012008-05-19 14:09:34 +0100124 outb_p(LOCK_DATA, IO_INDEX_PORT);
Jose Miguel Goncalvesb4cc4aa2005-09-06 17:05:30 -0700125
126 spin_unlock_irqrestore(&spinlock, flags);
127
Joe Perches27c766a2012-02-15 15:06:19 -0800128 pr_info("activated\n");
Jose Miguel Goncalvesb4cc4aa2005-09-06 17:05:30 -0700129
130 return 0;
131}
132
133/*
134 * Stop the watchdog
135 */
136
137static int wdt_stop(void)
138{
139 unsigned long flags;
140
141 spin_lock_irqsave(&spinlock, flags);
142
143 /* Unlock the SuperIO chip */
Alan Cox84af4012008-05-19 14:09:34 +0100144 outb_p(UNLOCK_DATA, IO_INDEX_PORT);
145 outb_p(UNLOCK_DATA, IO_INDEX_PORT);
Jose Miguel Goncalvesb4cc4aa2005-09-06 17:05:30 -0700146
Alan Cox84af4012008-05-19 14:09:34 +0100147 /*
Jose Miguel Goncalvesb4cc4aa2005-09-06 17:05:30 -0700148 * Select device Aux2 (device=8) to set watchdog regs F2, F3 and F4.
149 * F2 is reset to its default value (watchdog timer disabled).
150 * F3 is reset to its default state.
151 * F4 clears the TIMEOUT'ed state (bit 0) - back to default.
152 */
Alan Cox84af4012008-05-19 14:09:34 +0100153 outb_p(DEVICE_REGISTER, IO_INDEX_PORT);
154 outb_p(0x08, IO_DATA_PORT);
155 outb_p(0xF2, IO_INDEX_PORT);
156 outb_p(0xFF, IO_DATA_PORT);
157 outb_p(0xF3, IO_INDEX_PORT);
158 outb_p(0x00, IO_DATA_PORT);
159 outb_p(0xF4, IO_INDEX_PORT);
160 outb_p(0x00, IO_DATA_PORT);
161 outb_p(0xF2, IO_INDEX_PORT);
162 outb_p(0x00, IO_DATA_PORT);
Jose Miguel Goncalvesb4cc4aa2005-09-06 17:05:30 -0700163
164 /*
Alan Cox84af4012008-05-19 14:09:34 +0100165 * Select device Aux1 (dev=7) to set GP16 (in reg E6) and
Jose Miguel Goncalvesb4cc4aa2005-09-06 17:05:30 -0700166 * Gp13 (in reg E3) as inputs.
167 */
Alan Cox84af4012008-05-19 14:09:34 +0100168 outb_p(DEVICE_REGISTER, IO_INDEX_PORT);
169 outb_p(0x07, IO_DATA_PORT);
170 if (!testmode) {
171 outb_p(0xE6, IO_INDEX_PORT);
172 outb_p(0x01, IO_DATA_PORT);
Jose Miguel Goncalvesb4cc4aa2005-09-06 17:05:30 -0700173 }
Alan Cox84af4012008-05-19 14:09:34 +0100174 outb_p(0xE3, IO_INDEX_PORT);
175 outb_p(0x01, IO_DATA_PORT);
Jose Miguel Goncalvesb4cc4aa2005-09-06 17:05:30 -0700176
177 /* Lock the SuperIO chip */
Alan Cox84af4012008-05-19 14:09:34 +0100178 outb_p(LOCK_DATA, IO_INDEX_PORT);
Jose Miguel Goncalvesb4cc4aa2005-09-06 17:05:30 -0700179
180 spin_unlock_irqrestore(&spinlock, flags);
181
Joe Perches27c766a2012-02-15 15:06:19 -0800182 pr_info("shutdown\n");
Jose Miguel Goncalvesb4cc4aa2005-09-06 17:05:30 -0700183
184 return 0;
185}
186
187/*
188 * Send a keepalive ping to the watchdog
189 * This is done by simply re-writing the timeout to reg. 0xF2
190 */
191
192static int wdt_keepalive(void)
193{
194 unsigned long flags;
195
196 spin_lock_irqsave(&spinlock, flags);
197
198 /* Unlock the SuperIO chip */
Alan Cox84af4012008-05-19 14:09:34 +0100199 outb_p(UNLOCK_DATA, IO_INDEX_PORT);
200 outb_p(UNLOCK_DATA, IO_INDEX_PORT);
Jose Miguel Goncalvesb4cc4aa2005-09-06 17:05:30 -0700201
202 /* Select device Aux2 (device=8) to kick watchdog reg F2 */
Alan Cox84af4012008-05-19 14:09:34 +0100203 outb_p(DEVICE_REGISTER, IO_INDEX_PORT);
204 outb_p(0x08, IO_DATA_PORT);
205 outb_p(0xF2, IO_INDEX_PORT);
206 outb_p(timeoutW, IO_DATA_PORT);
Jose Miguel Goncalvesb4cc4aa2005-09-06 17:05:30 -0700207
208 /* Lock the SuperIO chip */
Alan Cox84af4012008-05-19 14:09:34 +0100209 outb_p(LOCK_DATA, IO_INDEX_PORT);
Jose Miguel Goncalvesb4cc4aa2005-09-06 17:05:30 -0700210
211 spin_unlock_irqrestore(&spinlock, flags);
212
213 return 0;
214}
215
216/*
217 * Set the watchdog timeout value
218 */
219
220static int wdt_set_timeout(int t)
221{
Dan Carpenter62ed8532015-11-06 12:56:31 +0300222 unsigned int tmrval;
Jose Miguel Goncalvesb4cc4aa2005-09-06 17:05:30 -0700223
224 /*
225 * Convert seconds to watchdog counter time units, rounding up.
Alan Cox84af4012008-05-19 14:09:34 +0100226 * On PCM-5335 watchdog units are 30 seconds/step with 15 sec startup
Jose Miguel Goncalvesb4cc4aa2005-09-06 17:05:30 -0700227 * value. This information is supplied in the PCM-5335 manual and was
228 * checked by me on a real board. This is a bit strange because W83977f
229 * datasheet says counter unit is in minutes!
230 */
231 if (t < 15)
232 return -EINVAL;
233
234 tmrval = ((t + 15) + 29) / 30;
235
236 if (tmrval > 255)
237 return -EINVAL;
238
239 /*
Alan Cox84af4012008-05-19 14:09:34 +0100240 * timeout is the timeout in seconds,
Jose Miguel Goncalvesb4cc4aa2005-09-06 17:05:30 -0700241 * timeoutW is the timeout in watchdog counter units.
242 */
243 timeoutW = tmrval;
244 timeout = (timeoutW * 30) - 15;
245 return 0;
246}
247
248/*
249 * Get the watchdog status
250 */
251
252static int wdt_get_status(int *status)
253{
254 int new_status;
255 unsigned long flags;
256
257 spin_lock_irqsave(&spinlock, flags);
258
259 /* Unlock the SuperIO chip */
Alan Cox84af4012008-05-19 14:09:34 +0100260 outb_p(UNLOCK_DATA, IO_INDEX_PORT);
261 outb_p(UNLOCK_DATA, IO_INDEX_PORT);
Jose Miguel Goncalvesb4cc4aa2005-09-06 17:05:30 -0700262
263 /* Select device Aux2 (device=8) to read watchdog reg F4 */
Alan Cox84af4012008-05-19 14:09:34 +0100264 outb_p(DEVICE_REGISTER, IO_INDEX_PORT);
265 outb_p(0x08, IO_DATA_PORT);
266 outb_p(0xF4, IO_INDEX_PORT);
Jose Miguel Goncalvesb4cc4aa2005-09-06 17:05:30 -0700267 new_status = inb_p(IO_DATA_PORT);
268
269 /* Lock the SuperIO chip */
Alan Cox84af4012008-05-19 14:09:34 +0100270 outb_p(LOCK_DATA, IO_INDEX_PORT);
Jose Miguel Goncalvesb4cc4aa2005-09-06 17:05:30 -0700271
272 spin_unlock_irqrestore(&spinlock, flags);
273
274 *status = 0;
275 if (new_status & 1)
276 *status |= WDIOF_CARDRESET;
277
278 return 0;
279}
280
281
282/*
283 * /dev/watchdog handling
284 */
285
286static int wdt_open(struct inode *inode, struct file *file)
287{
288 /* If the watchdog is alive we don't need to start it again */
Alan Cox84af4012008-05-19 14:09:34 +0100289 if (test_and_set_bit(0, &timer_alive))
Jose Miguel Goncalvesb4cc4aa2005-09-06 17:05:30 -0700290 return -EBUSY;
291
292 if (nowayout)
293 __module_get(THIS_MODULE);
294
295 wdt_start();
Kirill Smelkovc5bf68f2019-03-26 23:51:19 +0300296 return stream_open(inode, file);
Jose Miguel Goncalvesb4cc4aa2005-09-06 17:05:30 -0700297}
298
299static int wdt_release(struct inode *inode, struct file *file)
300{
301 /*
302 * Shut off the timer.
303 * Lock it in if it's a module and we set nowayout
304 */
Alan Cox84af4012008-05-19 14:09:34 +0100305 if (expect_close == 42) {
Jose Miguel Goncalvesb4cc4aa2005-09-06 17:05:30 -0700306 wdt_stop();
307 clear_bit(0, &timer_alive);
308 } else {
309 wdt_keepalive();
Joe Perches27c766a2012-02-15 15:06:19 -0800310 pr_crit("unexpected close, not stopping watchdog!\n");
Jose Miguel Goncalvesb4cc4aa2005-09-06 17:05:30 -0700311 }
312 expect_close = 0;
313 return 0;
314}
315
316/*
317 * wdt_write:
318 * @file: file handle to the watchdog
319 * @buf: buffer to write (unused as data does not matter here
320 * @count: count of bytes
321 * @ppos: pointer to the position to write. No seeks allowed
322 *
323 * A write to a watchdog device is defined as a keepalive signal. Any
324 * write of data will do, as we we don't define content meaning.
325 */
326
327static ssize_t wdt_write(struct file *file, const char __user *buf,
328 size_t count, loff_t *ppos)
329{
330 /* See if we got the magic character 'V' and reload the timer */
Alan Cox84af4012008-05-19 14:09:34 +0100331 if (count) {
332 if (!nowayout) {
Jose Miguel Goncalvesb4cc4aa2005-09-06 17:05:30 -0700333 size_t ofs;
334
Alan Cox84af4012008-05-19 14:09:34 +0100335 /* note: just in case someone wrote the
336 magic character long ago */
Jose Miguel Goncalvesb4cc4aa2005-09-06 17:05:30 -0700337 expect_close = 0;
338
Alan Cox84af4012008-05-19 14:09:34 +0100339 /* scan to see whether or not we got the
340 magic character */
341 for (ofs = 0; ofs != count; ofs++) {
Jose Miguel Goncalvesb4cc4aa2005-09-06 17:05:30 -0700342 char c;
343 if (get_user(c, buf + ofs))
344 return -EFAULT;
Alan Cox84af4012008-05-19 14:09:34 +0100345 if (c == 'V')
Jose Miguel Goncalvesb4cc4aa2005-09-06 17:05:30 -0700346 expect_close = 42;
Jose Miguel Goncalvesb4cc4aa2005-09-06 17:05:30 -0700347 }
348 }
349
350 /* someone wrote to us, we should restart timer */
351 wdt_keepalive();
352 }
353 return count;
354}
355
356/*
357 * wdt_ioctl:
358 * @inode: inode of the device
359 * @file: file handle to the device
360 * @cmd: watchdog command
361 * @arg: argument pointer
362 *
363 * The watchdog API defines a common set of functions for all watchdogs
364 * according to their available features.
365 */
366
Wim Van Sebroeck42747d72009-12-26 18:55:22 +0000367static const struct watchdog_info ident = {
Jose Miguel Goncalvesb4cc4aa2005-09-06 17:05:30 -0700368 .options = WDIOF_SETTIMEOUT | WDIOF_MAGICCLOSE | WDIOF_KEEPALIVEPING,
369 .firmware_version = 1,
370 .identity = WATCHDOG_NAME,
371};
372
Alan Cox84af4012008-05-19 14:09:34 +0100373static long wdt_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
Jose Miguel Goncalvesb4cc4aa2005-09-06 17:05:30 -0700374{
375 int status;
376 int new_options, retval = -EINVAL;
377 int new_timeout;
378 union {
379 struct watchdog_info __user *ident;
380 int __user *i;
381 } uarg;
382
383 uarg.i = (int __user *)arg;
384
Alan Cox84af4012008-05-19 14:09:34 +0100385 switch (cmd) {
Jose Miguel Goncalvesb4cc4aa2005-09-06 17:05:30 -0700386 case WDIOC_GETSUPPORT:
Alan Cox84af4012008-05-19 14:09:34 +0100387 return copy_to_user(uarg.ident, &ident,
388 sizeof(ident)) ? -EFAULT : 0;
Jose Miguel Goncalvesb4cc4aa2005-09-06 17:05:30 -0700389
390 case WDIOC_GETSTATUS:
391 wdt_get_status(&status);
392 return put_user(status, uarg.i);
393
394 case WDIOC_GETBOOTSTATUS:
395 return put_user(0, uarg.i);
396
Jose Miguel Goncalvesb4cc4aa2005-09-06 17:05:30 -0700397 case WDIOC_SETOPTIONS:
Alan Cox84af4012008-05-19 14:09:34 +0100398 if (get_user(new_options, uarg.i))
Jose Miguel Goncalvesb4cc4aa2005-09-06 17:05:30 -0700399 return -EFAULT;
400
401 if (new_options & WDIOS_DISABLECARD) {
402 wdt_stop();
403 retval = 0;
404 }
405
406 if (new_options & WDIOS_ENABLECARD) {
407 wdt_start();
408 retval = 0;
409 }
410
411 return retval;
412
Wim Van Sebroeck0c060902008-07-18 11:41:17 +0000413 case WDIOC_KEEPALIVE:
414 wdt_keepalive();
415 return 0;
416
Jose Miguel Goncalvesb4cc4aa2005-09-06 17:05:30 -0700417 case WDIOC_SETTIMEOUT:
418 if (get_user(new_timeout, uarg.i))
419 return -EFAULT;
420
421 if (wdt_set_timeout(new_timeout))
Wim Van Sebroeck143a2e52009-03-18 08:35:09 +0000422 return -EINVAL;
Jose Miguel Goncalvesb4cc4aa2005-09-06 17:05:30 -0700423
424 wdt_keepalive();
Gustavo A. R. Silva3ff07512018-03-27 14:30:41 -0500425 /* Fall through */
Jose Miguel Goncalvesb4cc4aa2005-09-06 17:05:30 -0700426
427 case WDIOC_GETTIMEOUT:
428 return put_user(timeout, uarg.i);
429
Wim Van Sebroeck0c060902008-07-18 11:41:17 +0000430 default:
431 return -ENOTTY;
432
Jose Miguel Goncalvesb4cc4aa2005-09-06 17:05:30 -0700433 }
434}
435
436static int wdt_notify_sys(struct notifier_block *this, unsigned long code,
437 void *unused)
438{
Alan Cox84af4012008-05-19 14:09:34 +0100439 if (code == SYS_DOWN || code == SYS_HALT)
Jose Miguel Goncalvesb4cc4aa2005-09-06 17:05:30 -0700440 wdt_stop();
441 return NOTIFY_DONE;
442}
443
Alan Cox84af4012008-05-19 14:09:34 +0100444static const struct file_operations wdt_fops = {
Jose Miguel Goncalvesb4cc4aa2005-09-06 17:05:30 -0700445 .owner = THIS_MODULE,
446 .llseek = no_llseek,
447 .write = wdt_write,
Alan Cox84af4012008-05-19 14:09:34 +0100448 .unlocked_ioctl = wdt_ioctl,
Arnd Bergmannb6dfb242019-06-03 14:23:09 +0200449 .compat_ioctl = compat_ptr_ioctl,
Jose Miguel Goncalvesb4cc4aa2005-09-06 17:05:30 -0700450 .open = wdt_open,
451 .release = wdt_release,
452};
453
Alan Cox84af4012008-05-19 14:09:34 +0100454static struct miscdevice wdt_miscdev = {
Jose Miguel Goncalvesb4cc4aa2005-09-06 17:05:30 -0700455 .minor = WATCHDOG_MINOR,
456 .name = "watchdog",
457 .fops = &wdt_fops,
458};
459
460static struct notifier_block wdt_notifier = {
461 .notifier_call = wdt_notify_sys,
462};
463
464static int __init w83977f_wdt_init(void)
465{
466 int rc;
467
Joe Perches27c766a2012-02-15 15:06:19 -0800468 pr_info("driver v%s\n", WATCHDOG_VERSION);
Jose Miguel Goncalvesb4cc4aa2005-09-06 17:05:30 -0700469
Jose Miguel Goncalvesb4cc4aa2005-09-06 17:05:30 -0700470 /*
Alan Cox84af4012008-05-19 14:09:34 +0100471 * Check that the timeout value is within it's range;
Jose Miguel Goncalvesb4cc4aa2005-09-06 17:05:30 -0700472 * if not reset to the default
473 */
474 if (wdt_set_timeout(timeout)) {
475 wdt_set_timeout(DEFAULT_TIMEOUT);
Joe Perches27c766a2012-02-15 15:06:19 -0800476 pr_info("timeout value must be 15 <= timeout <= 7635, using %d\n",
477 DEFAULT_TIMEOUT);
Jose Miguel Goncalvesb4cc4aa2005-09-06 17:05:30 -0700478 }
479
Alan Cox84af4012008-05-19 14:09:34 +0100480 if (!request_region(IO_INDEX_PORT, 2, WATCHDOG_NAME)) {
Joe Perches27c766a2012-02-15 15:06:19 -0800481 pr_err("I/O address 0x%04x already in use\n", IO_INDEX_PORT);
Jose Miguel Goncalvesb4cc4aa2005-09-06 17:05:30 -0700482 rc = -EIO;
483 goto err_out;
484 }
485
Jose Miguel Goncalvesb4cc4aa2005-09-06 17:05:30 -0700486 rc = register_reboot_notifier(&wdt_notifier);
Alan Cox84af4012008-05-19 14:09:34 +0100487 if (rc) {
Joe Perches27c766a2012-02-15 15:06:19 -0800488 pr_err("cannot register reboot notifier (err=%d)\n", rc);
Wim Van Sebroeckc6cb13a2007-12-26 20:32:51 +0000489 goto err_out_region;
490 }
491
492 rc = misc_register(&wdt_miscdev);
Alan Cox84af4012008-05-19 14:09:34 +0100493 if (rc) {
Joe Perches27c766a2012-02-15 15:06:19 -0800494 pr_err("cannot register miscdev on minor=%d (err=%d)\n",
495 wdt_miscdev.minor, rc);
Wim Van Sebroeckc6cb13a2007-12-26 20:32:51 +0000496 goto err_out_reboot;
Jose Miguel Goncalvesb4cc4aa2005-09-06 17:05:30 -0700497 }
498
Joe Perches27c766a2012-02-15 15:06:19 -0800499 pr_info("initialized. timeout=%d sec (nowayout=%d testmode=%d)\n",
500 timeout, nowayout, testmode);
Jose Miguel Goncalvesb4cc4aa2005-09-06 17:05:30 -0700501
502 return 0;
503
Wim Van Sebroeckc6cb13a2007-12-26 20:32:51 +0000504err_out_reboot:
505 unregister_reboot_notifier(&wdt_notifier);
Jose Miguel Goncalvesb4cc4aa2005-09-06 17:05:30 -0700506err_out_region:
Alan Cox84af4012008-05-19 14:09:34 +0100507 release_region(IO_INDEX_PORT, 2);
Jose Miguel Goncalvesb4cc4aa2005-09-06 17:05:30 -0700508err_out:
509 return rc;
510}
511
512static void __exit w83977f_wdt_exit(void)
513{
514 wdt_stop();
515 misc_deregister(&wdt_miscdev);
516 unregister_reboot_notifier(&wdt_notifier);
Alan Cox84af4012008-05-19 14:09:34 +0100517 release_region(IO_INDEX_PORT, 2);
Jose Miguel Goncalvesb4cc4aa2005-09-06 17:05:30 -0700518}
519
520module_init(w83977f_wdt_init);
521module_exit(w83977f_wdt_exit);
522
523MODULE_AUTHOR("Jose Goncalves <jose.goncalves@inov.pt>");
524MODULE_DESCRIPTION("Driver for watchdog timer in W83977F I/O chip");
525MODULE_LICENSE("GPL");