diff options
author | Jose Miguel Goncalves <jose.goncalves@inov.pt> | 2005-09-06 20:05:30 -0400 |
---|---|---|
committer | Wim Van Sebroeck <wim@iguana.be> | 2005-09-12 03:34:39 -0400 |
commit | b4cc4aa24ca47b6a2bdb9029020502cff7c6e774 (patch) | |
tree | 7b621a12b7266599b7ee54ef74f7040f8919e2e3 /drivers | |
parent | 3809ad384af43ad883f47ee22a6faa33cedd61bc (diff) |
[WATCHDOG] w83977f-watchdog-driver.patch
In a project for my company I've needed to use the watchdog device in a
PCM-5335 SBC from AAEON. The watchdog timer is from a Winbond's SuperIO
chip, the W83977F.
I've made this driver based on two others already on the kernel tree,
the w83877f_wdt and the wdt977.
Signed-off-by: Jose Goncalves <jose.goncalves@inov.pt>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/char/watchdog/Kconfig | 13 | ||||
-rw-r--r-- | drivers/char/watchdog/Makefile | 1 | ||||
-rw-r--r-- | drivers/char/watchdog/w83977f_wdt.c | 548 |
3 files changed, 562 insertions, 0 deletions
diff --git a/drivers/char/watchdog/Kconfig b/drivers/char/watchdog/Kconfig index e18a4102163f..2d78962b4de7 100644 --- a/drivers/char/watchdog/Kconfig +++ b/drivers/char/watchdog/Kconfig | |||
@@ -360,6 +360,19 @@ config W83877F_WDT | |||
360 | 360 | ||
361 | Most people will say N. | 361 | Most people will say N. |
362 | 362 | ||
363 | config W83977F_WDT | ||
364 | tristate "W83977F (PCM-5335) Watchdog Timer" | ||
365 | depends on WATCHDOG && X86 | ||
366 | ---help--- | ||
367 | This is the driver for the hardware watchdog on the W83977F I/O chip | ||
368 | as used in AAEON's PCM-5335 SBC (and likely others). This | ||
369 | watchdog simply watches your kernel to make sure it doesn't freeze, | ||
370 | and if it does, it reboots your computer after a certain amount of | ||
371 | time. | ||
372 | |||
373 | To compile this driver as a module, choose M here: the | ||
374 | module will be called w83977f_wdt. | ||
375 | |||
363 | config MACHZ_WDT | 376 | config MACHZ_WDT |
364 | tristate "ZF MachZ Watchdog" | 377 | tristate "ZF MachZ Watchdog" |
365 | depends on WATCHDOG && X86 | 378 | depends on WATCHDOG && X86 |
diff --git a/drivers/char/watchdog/Makefile b/drivers/char/watchdog/Makefile index c7f74026bd3c..3ca8a12a1510 100644 --- a/drivers/char/watchdog/Makefile +++ b/drivers/char/watchdog/Makefile | |||
@@ -49,6 +49,7 @@ obj-$(CONFIG_SBC8360_WDT) += sbc8360.o | |||
49 | obj-$(CONFIG_CPU5_WDT) += cpu5wdt.o | 49 | obj-$(CONFIG_CPU5_WDT) += cpu5wdt.o |
50 | obj-$(CONFIG_W83627HF_WDT) += w83627hf_wdt.o | 50 | obj-$(CONFIG_W83627HF_WDT) += w83627hf_wdt.o |
51 | obj-$(CONFIG_W83877F_WDT) += w83877f_wdt.o | 51 | obj-$(CONFIG_W83877F_WDT) += w83877f_wdt.o |
52 | obj-$(CONFIG_W83977F_WDT) += w83977f_wdt.o | ||
52 | obj-$(CONFIG_MACHZ_WDT) += machzwd.o | 53 | obj-$(CONFIG_MACHZ_WDT) += machzwd.o |
53 | 54 | ||
54 | # PowerPC Architecture | 55 | # PowerPC Architecture |
diff --git a/drivers/char/watchdog/w83977f_wdt.c b/drivers/char/watchdog/w83977f_wdt.c new file mode 100644 index 000000000000..366d47bca16e --- /dev/null +++ b/drivers/char/watchdog/w83977f_wdt.c | |||
@@ -0,0 +1,548 @@ | |||
1 | /* | ||
2 | * W83977F Watchdog Timer Driver for Winbond W83977F I/O Chip | ||
3 | * | ||
4 | * (c) Copyright 2005 Jose Goncalves <jose.goncalves@inov.pt> | ||
5 | * | ||
6 | * Based on w83877f_wdt.c by Scott Jennings, | ||
7 | * and wdt977.c by Woody Suwalski | ||
8 | * | ||
9 | * ----------------------- | ||
10 | * | ||
11 | * This program is free software; you can redistribute it and/or | ||
12 | * modify it under the terms of the GNU General Public License | ||
13 | * as published by the Free Software Foundation; either version | ||
14 | * 2 of the License, or (at your option) any later version. | ||
15 | * | ||
16 | */ | ||
17 | |||
18 | #include <linux/module.h> | ||
19 | #include <linux/moduleparam.h> | ||
20 | #include <linux/config.h> | ||
21 | #include <linux/types.h> | ||
22 | #include <linux/kernel.h> | ||
23 | #include <linux/fs.h> | ||
24 | #include <linux/miscdevice.h> | ||
25 | #include <linux/init.h> | ||
26 | #include <linux/ioport.h> | ||
27 | #include <linux/watchdog.h> | ||
28 | #include <linux/notifier.h> | ||
29 | #include <linux/reboot.h> | ||
30 | |||
31 | #include <asm/io.h> | ||
32 | #include <asm/system.h> | ||
33 | #include <asm/uaccess.h> | ||
34 | |||
35 | #define WATCHDOG_VERSION "1.00" | ||
36 | #define WATCHDOG_NAME "W83977F WDT" | ||
37 | #define PFX WATCHDOG_NAME ": " | ||
38 | #define DRIVER_VERSION WATCHDOG_NAME " driver, v" WATCHDOG_VERSION "\n" | ||
39 | |||
40 | #define IO_INDEX_PORT 0x3F0 | ||
41 | #define IO_DATA_PORT (IO_INDEX_PORT+1) | ||
42 | |||
43 | #define UNLOCK_DATA 0x87 | ||
44 | #define LOCK_DATA 0xAA | ||
45 | #define DEVICE_REGISTER 0x07 | ||
46 | |||
47 | #define DEFAULT_TIMEOUT 45 /* default timeout in seconds */ | ||
48 | |||
49 | static int timeout = DEFAULT_TIMEOUT; | ||
50 | static int timeoutW; /* timeout in watchdog counter units */ | ||
51 | static unsigned long timer_alive; | ||
52 | static int testmode; | ||
53 | static char expect_close; | ||
54 | static spinlock_t spinlock; | ||
55 | |||
56 | module_param(timeout, int, 0); | ||
57 | MODULE_PARM_DESC(timeout,"Watchdog timeout in seconds (15..7635), default=" __MODULE_STRING(DEFAULT_TIMEOUT) ")"); | ||
58 | module_param(testmode, int, 0); | ||
59 | MODULE_PARM_DESC(testmode,"Watchdog testmode (1 = no reboot), default=0"); | ||
60 | |||
61 | #ifdef CONFIG_WATCHDOG_NOWAYOUT | ||
62 | static int nowayout = 1; | ||
63 | #else | ||
64 | static int nowayout = 0; | ||
65 | #endif | ||
66 | |||
67 | module_param(nowayout, int, 0); | ||
68 | MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)"); | ||
69 | |||
70 | /* | ||
71 | * Start the watchdog | ||
72 | */ | ||
73 | |||
74 | static int wdt_start(void) | ||
75 | { | ||
76 | unsigned long flags; | ||
77 | |||
78 | spin_lock_irqsave(&spinlock, flags); | ||
79 | |||
80 | /* Unlock the SuperIO chip */ | ||
81 | outb_p(UNLOCK_DATA,IO_INDEX_PORT); | ||
82 | outb_p(UNLOCK_DATA,IO_INDEX_PORT); | ||
83 | |||
84 | /* | ||
85 | * Select device Aux2 (device=8) to set watchdog regs F2, F3 and F4. | ||
86 | * F2 has the timeout in watchdog counter units. | ||
87 | * F3 is set to enable watchdog LED blink at timeout. | ||
88 | * F4 is used to just clear the TIMEOUT'ed state (bit 0). | ||
89 | */ | ||
90 | outb_p(DEVICE_REGISTER,IO_INDEX_PORT); | ||
91 | outb_p(0x08,IO_DATA_PORT); | ||
92 | outb_p(0xF2,IO_INDEX_PORT); | ||
93 | outb_p(timeoutW,IO_DATA_PORT); | ||
94 | outb_p(0xF3,IO_INDEX_PORT); | ||
95 | outb_p(0x08,IO_DATA_PORT); | ||
96 | outb_p(0xF4,IO_INDEX_PORT); | ||
97 | outb_p(0x00,IO_DATA_PORT); | ||
98 | |||
99 | /* Set device Aux2 active */ | ||
100 | outb_p(0x30,IO_INDEX_PORT); | ||
101 | outb_p(0x01,IO_DATA_PORT); | ||
102 | |||
103 | /* | ||
104 | * Select device Aux1 (dev=7) to set GP16 as the watchdog output | ||
105 | * (in reg E6) and GP13 as the watchdog LED output (in reg E3). | ||
106 | * Map GP16 at pin 119. | ||
107 | * In test mode watch the bit 0 on F4 to indicate "triggered" or | ||
108 | * check watchdog LED on SBC. | ||
109 | */ | ||
110 | outb_p(DEVICE_REGISTER,IO_INDEX_PORT); | ||
111 | outb_p(0x07,IO_DATA_PORT); | ||
112 | if (!testmode) | ||
113 | { | ||
114 | unsigned pin_map; | ||
115 | |||
116 | outb_p(0xE6,IO_INDEX_PORT); | ||
117 | outb_p(0x0A,IO_DATA_PORT); | ||
118 | outb_p(0x2C,IO_INDEX_PORT); | ||
119 | pin_map = inb_p(IO_DATA_PORT); | ||
120 | pin_map |= 0x10; | ||
121 | pin_map &= ~(0x20); | ||
122 | outb_p(0x2C,IO_INDEX_PORT); | ||
123 | outb_p(pin_map,IO_DATA_PORT); | ||
124 | } | ||
125 | outb_p(0xE3,IO_INDEX_PORT); | ||
126 | outb_p(0x08,IO_DATA_PORT); | ||
127 | |||
128 | /* Set device Aux1 active */ | ||
129 | outb_p(0x30,IO_INDEX_PORT); | ||
130 | outb_p(0x01,IO_DATA_PORT); | ||
131 | |||
132 | /* Lock the SuperIO chip */ | ||
133 | outb_p(LOCK_DATA,IO_INDEX_PORT); | ||
134 | |||
135 | spin_unlock_irqrestore(&spinlock, flags); | ||
136 | |||
137 | printk(KERN_INFO PFX "activated.\n"); | ||
138 | |||
139 | return 0; | ||
140 | } | ||
141 | |||
142 | /* | ||
143 | * Stop the watchdog | ||
144 | */ | ||
145 | |||
146 | static int wdt_stop(void) | ||
147 | { | ||
148 | unsigned long flags; | ||
149 | |||
150 | spin_lock_irqsave(&spinlock, flags); | ||
151 | |||
152 | /* Unlock the SuperIO chip */ | ||
153 | outb_p(UNLOCK_DATA,IO_INDEX_PORT); | ||
154 | outb_p(UNLOCK_DATA,IO_INDEX_PORT); | ||
155 | |||
156 | /* | ||
157 | * Select device Aux2 (device=8) to set watchdog regs F2, F3 and F4. | ||
158 | * F2 is reset to its default value (watchdog timer disabled). | ||
159 | * F3 is reset to its default state. | ||
160 | * F4 clears the TIMEOUT'ed state (bit 0) - back to default. | ||
161 | */ | ||
162 | outb_p(DEVICE_REGISTER,IO_INDEX_PORT); | ||
163 | outb_p(0x08,IO_DATA_PORT); | ||
164 | outb_p(0xF2,IO_INDEX_PORT); | ||
165 | outb_p(0xFF,IO_DATA_PORT); | ||
166 | outb_p(0xF3,IO_INDEX_PORT); | ||
167 | outb_p(0x00,IO_DATA_PORT); | ||
168 | outb_p(0xF4,IO_INDEX_PORT); | ||
169 | outb_p(0x00,IO_DATA_PORT); | ||
170 | outb_p(0xF2,IO_INDEX_PORT); | ||
171 | outb_p(0x00,IO_DATA_PORT); | ||
172 | |||
173 | /* | ||
174 | * Select device Aux1 (dev=7) to set GP16 (in reg E6) and | ||
175 | * Gp13 (in reg E3) as inputs. | ||
176 | */ | ||
177 | outb_p(DEVICE_REGISTER,IO_INDEX_PORT); | ||
178 | outb_p(0x07,IO_DATA_PORT); | ||
179 | if (!testmode) | ||
180 | { | ||
181 | outb_p(0xE6,IO_INDEX_PORT); | ||
182 | outb_p(0x01,IO_DATA_PORT); | ||
183 | } | ||
184 | outb_p(0xE3,IO_INDEX_PORT); | ||
185 | outb_p(0x01,IO_DATA_PORT); | ||
186 | |||
187 | /* Lock the SuperIO chip */ | ||
188 | outb_p(LOCK_DATA,IO_INDEX_PORT); | ||
189 | |||
190 | spin_unlock_irqrestore(&spinlock, flags); | ||
191 | |||
192 | printk(KERN_INFO PFX "shutdown.\n"); | ||
193 | |||
194 | return 0; | ||
195 | } | ||
196 | |||
197 | /* | ||
198 | * Send a keepalive ping to the watchdog | ||
199 | * This is done by simply re-writing the timeout to reg. 0xF2 | ||
200 | */ | ||
201 | |||
202 | static int wdt_keepalive(void) | ||
203 | { | ||
204 | unsigned long flags; | ||
205 | |||
206 | spin_lock_irqsave(&spinlock, flags); | ||
207 | |||
208 | /* Unlock the SuperIO chip */ | ||
209 | outb_p(UNLOCK_DATA,IO_INDEX_PORT); | ||
210 | outb_p(UNLOCK_DATA,IO_INDEX_PORT); | ||
211 | |||
212 | /* Select device Aux2 (device=8) to kick watchdog reg F2 */ | ||
213 | outb_p(DEVICE_REGISTER,IO_INDEX_PORT); | ||
214 | outb_p(0x08,IO_DATA_PORT); | ||
215 | outb_p(0xF2,IO_INDEX_PORT); | ||
216 | outb_p(timeoutW,IO_DATA_PORT); | ||
217 | |||
218 | /* Lock the SuperIO chip */ | ||
219 | outb_p(LOCK_DATA,IO_INDEX_PORT); | ||
220 | |||
221 | spin_unlock_irqrestore(&spinlock, flags); | ||
222 | |||
223 | return 0; | ||
224 | } | ||
225 | |||
226 | /* | ||
227 | * Set the watchdog timeout value | ||
228 | */ | ||
229 | |||
230 | static int wdt_set_timeout(int t) | ||
231 | { | ||
232 | int tmrval; | ||
233 | |||
234 | /* | ||
235 | * Convert seconds to watchdog counter time units, rounding up. | ||
236 | * On PCM-5335 watchdog units are 30 seconds/step with 15 sec startup | ||
237 | * value. This information is supplied in the PCM-5335 manual and was | ||
238 | * checked by me on a real board. This is a bit strange because W83977f | ||
239 | * datasheet says counter unit is in minutes! | ||
240 | */ | ||
241 | if (t < 15) | ||
242 | return -EINVAL; | ||
243 | |||
244 | tmrval = ((t + 15) + 29) / 30; | ||
245 | |||
246 | if (tmrval > 255) | ||
247 | return -EINVAL; | ||
248 | |||
249 | /* | ||
250 | * timeout is the timeout in seconds, | ||
251 | * timeoutW is the timeout in watchdog counter units. | ||
252 | */ | ||
253 | timeoutW = tmrval; | ||
254 | timeout = (timeoutW * 30) - 15; | ||
255 | return 0; | ||
256 | } | ||
257 | |||
258 | /* | ||
259 | * Get the watchdog status | ||
260 | */ | ||
261 | |||
262 | static int wdt_get_status(int *status) | ||
263 | { | ||
264 | int new_status; | ||
265 | unsigned long flags; | ||
266 | |||
267 | spin_lock_irqsave(&spinlock, flags); | ||
268 | |||
269 | /* Unlock the SuperIO chip */ | ||
270 | outb_p(UNLOCK_DATA,IO_INDEX_PORT); | ||
271 | outb_p(UNLOCK_DATA,IO_INDEX_PORT); | ||
272 | |||
273 | /* Select device Aux2 (device=8) to read watchdog reg F4 */ | ||
274 | outb_p(DEVICE_REGISTER,IO_INDEX_PORT); | ||
275 | outb_p(0x08,IO_DATA_PORT); | ||
276 | outb_p(0xF4,IO_INDEX_PORT); | ||
277 | new_status = inb_p(IO_DATA_PORT); | ||
278 | |||
279 | /* Lock the SuperIO chip */ | ||
280 | outb_p(LOCK_DATA,IO_INDEX_PORT); | ||
281 | |||
282 | spin_unlock_irqrestore(&spinlock, flags); | ||
283 | |||
284 | *status = 0; | ||
285 | if (new_status & 1) | ||
286 | *status |= WDIOF_CARDRESET; | ||
287 | |||
288 | return 0; | ||
289 | } | ||
290 | |||
291 | |||
292 | /* | ||
293 | * /dev/watchdog handling | ||
294 | */ | ||
295 | |||
296 | static int wdt_open(struct inode *inode, struct file *file) | ||
297 | { | ||
298 | /* If the watchdog is alive we don't need to start it again */ | ||
299 | if( test_and_set_bit(0, &timer_alive) ) | ||
300 | return -EBUSY; | ||
301 | |||
302 | if (nowayout) | ||
303 | __module_get(THIS_MODULE); | ||
304 | |||
305 | wdt_start(); | ||
306 | return nonseekable_open(inode, file); | ||
307 | } | ||
308 | |||
309 | static int wdt_release(struct inode *inode, struct file *file) | ||
310 | { | ||
311 | /* | ||
312 | * Shut off the timer. | ||
313 | * Lock it in if it's a module and we set nowayout | ||
314 | */ | ||
315 | if (expect_close == 42) | ||
316 | { | ||
317 | wdt_stop(); | ||
318 | clear_bit(0, &timer_alive); | ||
319 | } else { | ||
320 | wdt_keepalive(); | ||
321 | printk(KERN_CRIT PFX "unexpected close, not stopping watchdog!\n"); | ||
322 | } | ||
323 | expect_close = 0; | ||
324 | return 0; | ||
325 | } | ||
326 | |||
327 | /* | ||
328 | * wdt_write: | ||
329 | * @file: file handle to the watchdog | ||
330 | * @buf: buffer to write (unused as data does not matter here | ||
331 | * @count: count of bytes | ||
332 | * @ppos: pointer to the position to write. No seeks allowed | ||
333 | * | ||
334 | * A write to a watchdog device is defined as a keepalive signal. Any | ||
335 | * write of data will do, as we we don't define content meaning. | ||
336 | */ | ||
337 | |||
338 | static ssize_t wdt_write(struct file *file, const char __user *buf, | ||
339 | size_t count, loff_t *ppos) | ||
340 | { | ||
341 | /* See if we got the magic character 'V' and reload the timer */ | ||
342 | if(count) | ||
343 | { | ||
344 | if (!nowayout) | ||
345 | { | ||
346 | size_t ofs; | ||
347 | |||
348 | /* note: just in case someone wrote the magic character long ago */ | ||
349 | expect_close = 0; | ||
350 | |||
351 | /* scan to see whether or not we got the magic character */ | ||
352 | for(ofs = 0; ofs != count; ofs++) | ||
353 | { | ||
354 | char c; | ||
355 | if (get_user(c, buf + ofs)) | ||
356 | return -EFAULT; | ||
357 | if (c == 'V') { | ||
358 | expect_close = 42; | ||
359 | } | ||
360 | } | ||
361 | } | ||
362 | |||
363 | /* someone wrote to us, we should restart timer */ | ||
364 | wdt_keepalive(); | ||
365 | } | ||
366 | return count; | ||
367 | } | ||
368 | |||
369 | /* | ||
370 | * wdt_ioctl: | ||
371 | * @inode: inode of the device | ||
372 | * @file: file handle to the device | ||
373 | * @cmd: watchdog command | ||
374 | * @arg: argument pointer | ||
375 | * | ||
376 | * The watchdog API defines a common set of functions for all watchdogs | ||
377 | * according to their available features. | ||
378 | */ | ||
379 | |||
380 | static struct watchdog_info ident = { | ||
381 | .options = WDIOF_SETTIMEOUT | WDIOF_MAGICCLOSE | WDIOF_KEEPALIVEPING, | ||
382 | .firmware_version = 1, | ||
383 | .identity = WATCHDOG_NAME, | ||
384 | }; | ||
385 | |||
386 | static int wdt_ioctl(struct inode *inode, struct file *file, | ||
387 | unsigned int cmd, unsigned long arg) | ||
388 | { | ||
389 | int status; | ||
390 | int new_options, retval = -EINVAL; | ||
391 | int new_timeout; | ||
392 | union { | ||
393 | struct watchdog_info __user *ident; | ||
394 | int __user *i; | ||
395 | } uarg; | ||
396 | |||
397 | uarg.i = (int __user *)arg; | ||
398 | |||
399 | switch(cmd) | ||
400 | { | ||
401 | default: | ||
402 | return -ENOIOCTLCMD; | ||
403 | |||
404 | case WDIOC_GETSUPPORT: | ||
405 | return copy_to_user(uarg.ident, &ident, sizeof(ident)) ? -EFAULT : 0; | ||
406 | |||
407 | case WDIOC_GETSTATUS: | ||
408 | wdt_get_status(&status); | ||
409 | return put_user(status, uarg.i); | ||
410 | |||
411 | case WDIOC_GETBOOTSTATUS: | ||
412 | return put_user(0, uarg.i); | ||
413 | |||
414 | case WDIOC_KEEPALIVE: | ||
415 | wdt_keepalive(); | ||
416 | return 0; | ||
417 | |||
418 | case WDIOC_SETOPTIONS: | ||
419 | if (get_user (new_options, uarg.i)) | ||
420 | return -EFAULT; | ||
421 | |||
422 | if (new_options & WDIOS_DISABLECARD) { | ||
423 | wdt_stop(); | ||
424 | retval = 0; | ||
425 | } | ||
426 | |||
427 | if (new_options & WDIOS_ENABLECARD) { | ||
428 | wdt_start(); | ||
429 | retval = 0; | ||
430 | } | ||
431 | |||
432 | return retval; | ||
433 | |||
434 | case WDIOC_SETTIMEOUT: | ||
435 | if (get_user(new_timeout, uarg.i)) | ||
436 | return -EFAULT; | ||
437 | |||
438 | if (wdt_set_timeout(new_timeout)) | ||
439 | return -EINVAL; | ||
440 | |||
441 | wdt_keepalive(); | ||
442 | /* Fall */ | ||
443 | |||
444 | case WDIOC_GETTIMEOUT: | ||
445 | return put_user(timeout, uarg.i); | ||
446 | |||
447 | } | ||
448 | } | ||
449 | |||
450 | static int wdt_notify_sys(struct notifier_block *this, unsigned long code, | ||
451 | void *unused) | ||
452 | { | ||
453 | if (code==SYS_DOWN || code==SYS_HALT) | ||
454 | wdt_stop(); | ||
455 | return NOTIFY_DONE; | ||
456 | } | ||
457 | |||
458 | static struct file_operations wdt_fops= | ||
459 | { | ||
460 | .owner = THIS_MODULE, | ||
461 | .llseek = no_llseek, | ||
462 | .write = wdt_write, | ||
463 | .ioctl = wdt_ioctl, | ||
464 | .open = wdt_open, | ||
465 | .release = wdt_release, | ||
466 | }; | ||
467 | |||
468 | static struct miscdevice wdt_miscdev= | ||
469 | { | ||
470 | .minor = WATCHDOG_MINOR, | ||
471 | .name = "watchdog", | ||
472 | .fops = &wdt_fops, | ||
473 | }; | ||
474 | |||
475 | static struct notifier_block wdt_notifier = { | ||
476 | .notifier_call = wdt_notify_sys, | ||
477 | }; | ||
478 | |||
479 | static int __init w83977f_wdt_init(void) | ||
480 | { | ||
481 | int rc; | ||
482 | |||
483 | printk(KERN_INFO PFX DRIVER_VERSION); | ||
484 | |||
485 | spin_lock_init(&spinlock); | ||
486 | |||
487 | /* | ||
488 | * Check that the timeout value is within it's range ; | ||
489 | * if not reset to the default | ||
490 | */ | ||
491 | if (wdt_set_timeout(timeout)) { | ||
492 | wdt_set_timeout(DEFAULT_TIMEOUT); | ||
493 | printk(KERN_INFO PFX "timeout value must be 15<=timeout<=7635, using %d\n", | ||
494 | DEFAULT_TIMEOUT); | ||
495 | } | ||
496 | |||
497 | if (!request_region(IO_INDEX_PORT, 2, WATCHDOG_NAME)) | ||
498 | { | ||
499 | printk(KERN_ERR PFX "I/O address 0x%04x already in use\n", | ||
500 | IO_INDEX_PORT); | ||
501 | rc = -EIO; | ||
502 | goto err_out; | ||
503 | } | ||
504 | |||
505 | rc = misc_register(&wdt_miscdev); | ||
506 | if (rc) | ||
507 | { | ||
508 | printk(KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n", | ||
509 | wdt_miscdev.minor, rc); | ||
510 | goto err_out_region; | ||
511 | } | ||
512 | |||
513 | rc = register_reboot_notifier(&wdt_notifier); | ||
514 | if (rc) | ||
515 | { | ||
516 | printk(KERN_ERR PFX "cannot register reboot notifier (err=%d)\n", | ||
517 | rc); | ||
518 | goto err_out_miscdev; | ||
519 | } | ||
520 | |||
521 | printk(KERN_INFO PFX "initialized. timeout=%d sec (nowayout=%d testmode=%d)\n", | ||
522 | timeout, nowayout, testmode); | ||
523 | |||
524 | return 0; | ||
525 | |||
526 | err_out_miscdev: | ||
527 | misc_deregister(&wdt_miscdev); | ||
528 | err_out_region: | ||
529 | release_region(IO_INDEX_PORT,2); | ||
530 | err_out: | ||
531 | return rc; | ||
532 | } | ||
533 | |||
534 | static void __exit w83977f_wdt_exit(void) | ||
535 | { | ||
536 | wdt_stop(); | ||
537 | misc_deregister(&wdt_miscdev); | ||
538 | unregister_reboot_notifier(&wdt_notifier); | ||
539 | release_region(IO_INDEX_PORT,2); | ||
540 | } | ||
541 | |||
542 | module_init(w83977f_wdt_init); | ||
543 | module_exit(w83977f_wdt_exit); | ||
544 | |||
545 | MODULE_AUTHOR("Jose Goncalves <jose.goncalves@inov.pt>"); | ||
546 | MODULE_DESCRIPTION("Driver for watchdog timer in W83977F I/O chip"); | ||
547 | MODULE_LICENSE("GPL"); | ||
548 | MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR); | ||