]>
Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
04bedfa5 | 2 | * Industrial Computer Source WDT501 driver |
1da177e4 | 3 | * |
29fa0586 AC |
4 | * (c) Copyright 1996-1997 Alan Cox <alan@lxorguk.ukuu.org.uk>, |
5 | * All Rights Reserved. | |
1da177e4 LT |
6 | * |
7 | * This program is free software; you can redistribute it and/or | |
8 | * modify it under the terms of the GNU General Public License | |
9 | * as published by the Free Software Foundation; either version | |
10 | * 2 of the License, or (at your option) any later version. | |
11 | * | |
12 | * Neither Alan Cox nor CymruNet Ltd. admit liability nor provide | |
13 | * warranty for any of this software. This material is provided | |
14 | * "AS-IS" and at no charge. | |
15 | * | |
16 | * (c) Copyright 1995 Alan Cox <alan@lxorguk.ukuu.org.uk> | |
17 | * | |
18 | * Release 0.10. | |
19 | * | |
20 | * Fixes | |
21 | * Dave Gregorich : Modularisation and minor bugs | |
22 | * Alan Cox : Added the watchdog ioctl() stuff | |
23 | * Alan Cox : Fixed the reboot problem (as noted by | |
24 | * Matt Crocker). | |
25 | * Alan Cox : Added wdt= boot option | |
26 | * Alan Cox : Cleaned up copy/user stuff | |
9f2d1f0d AC |
27 | * Tim Hockin : Added insmod parameters, comment |
28 | * cleanup, parameterized timeout | |
29 | * Tigran Aivazian : Restructured wdt_init() to handle | |
30 | * failures | |
1da177e4 LT |
31 | * Joel Becker : Added WDIOC_GET/SETTIMEOUT |
32 | * Matt Domsch : Added nowayout module option | |
33 | */ | |
34 | ||
27c766aa JP |
35 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
36 | ||
1da177e4 LT |
37 | #include <linux/interrupt.h> |
38 | #include <linux/module.h> | |
39 | #include <linux/moduleparam.h> | |
40 | #include <linux/types.h> | |
41 | #include <linux/miscdevice.h> | |
42 | #include <linux/watchdog.h> | |
43 | #include <linux/fs.h> | |
44 | #include <linux/ioport.h> | |
45 | #include <linux/notifier.h> | |
46 | #include <linux/reboot.h> | |
47 | #include <linux/init.h> | |
9f2d1f0d AC |
48 | #include <linux/io.h> |
49 | #include <linux/uaccess.h> | |
1da177e4 | 50 | |
1da177e4 LT |
51 | #include <asm/system.h> |
52 | #include "wd501p.h" | |
53 | ||
54 | static unsigned long wdt_is_open; | |
55 | static char expect_close; | |
56 | ||
57 | /* | |
58 | * Module parameters | |
59 | */ | |
60 | ||
61 | #define WD_TIMO 60 /* Default heartbeat = 60 seconds */ | |
62 | ||
63 | static int heartbeat = WD_TIMO; | |
64 | static int wd_heartbeat; | |
65 | module_param(heartbeat, int, 0); | |
9f2d1f0d AC |
66 | MODULE_PARM_DESC(heartbeat, |
67 | "Watchdog heartbeat in seconds. (0 < heartbeat < 65536, default=" | |
68 | __MODULE_STRING(WD_TIMO) ")"); | |
1da177e4 | 69 | |
4bfdf378 | 70 | static int nowayout = WATCHDOG_NOWAYOUT; |
1da177e4 | 71 | module_param(nowayout, int, 0); |
9f2d1f0d AC |
72 | MODULE_PARM_DESC(nowayout, |
73 | "Watchdog cannot be stopped once started (default=" | |
74 | __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); | |
1da177e4 LT |
75 | |
76 | /* You must set these - there is no sane way to probe for this board. */ | |
9f2d1f0d AC |
77 | static int io = 0x240; |
78 | static int irq = 11; | |
1da177e4 | 79 | |
01c785dc AC |
80 | static DEFINE_SPINLOCK(wdt_lock); |
81 | ||
1da177e4 LT |
82 | module_param(io, int, 0); |
83 | MODULE_PARM_DESC(io, "WDT io port (default=0x240)"); | |
84 | module_param(irq, int, 0); | |
85 | MODULE_PARM_DESC(irq, "WDT irq (default=11)"); | |
86 | ||
1da177e4 LT |
87 | /* Support for the Fan Tachometer on the WDT501-P */ |
88 | static int tachometer; | |
1da177e4 | 89 | module_param(tachometer, int, 0); |
9f2d1f0d AC |
90 | MODULE_PARM_DESC(tachometer, |
91 | "WDT501-P Fan Tachometer support (0=disable, default=0)"); | |
04bedfa5 AC |
92 | |
93 | static int type = 500; | |
94 | module_param(type, int, 0); | |
95 | MODULE_PARM_DESC(type, | |
4724ba57 | 96 | "WDT501-P Card type (500 or 501, default=500)"); |
1da177e4 LT |
97 | |
98 | /* | |
99 | * Programming support | |
100 | */ | |
101 | ||
102 | static void wdt_ctr_mode(int ctr, int mode) | |
103 | { | |
9f2d1f0d AC |
104 | ctr <<= 6; |
105 | ctr |= 0x30; | |
106 | ctr |= (mode << 1); | |
1da177e4 LT |
107 | outb_p(ctr, WDT_CR); |
108 | } | |
109 | ||
110 | static void wdt_ctr_load(int ctr, int val) | |
111 | { | |
112 | outb_p(val&0xFF, WDT_COUNT0+ctr); | |
113 | outb_p(val>>8, WDT_COUNT0+ctr); | |
114 | } | |
115 | ||
116 | /** | |
117 | * wdt_start: | |
118 | * | |
119 | * Start the watchdog driver. | |
120 | */ | |
121 | ||
122 | static int wdt_start(void) | |
123 | { | |
01c785dc AC |
124 | unsigned long flags; |
125 | spin_lock_irqsave(&wdt_lock, flags); | |
1da177e4 | 126 | inb_p(WDT_DC); /* Disable watchdog */ |
9f2d1f0d AC |
127 | wdt_ctr_mode(0, 3); /* Program CTR0 for Mode 3: |
128 | Square Wave Generator */ | |
129 | wdt_ctr_mode(1, 2); /* Program CTR1 for Mode 2: | |
130 | Rate Generator */ | |
131 | wdt_ctr_mode(2, 0); /* Program CTR2 for Mode 0: | |
132 | Pulse on Terminal Count */ | |
1da177e4 | 133 | wdt_ctr_load(0, 8948); /* Count at 100Hz */ |
9f2d1f0d AC |
134 | wdt_ctr_load(1, wd_heartbeat); /* Heartbeat */ |
135 | wdt_ctr_load(2, 65535); /* Length of reset pulse */ | |
1da177e4 | 136 | outb_p(0, WDT_DC); /* Enable watchdog */ |
01c785dc | 137 | spin_unlock_irqrestore(&wdt_lock, flags); |
1da177e4 LT |
138 | return 0; |
139 | } | |
140 | ||
141 | /** | |
142 | * wdt_stop: | |
143 | * | |
144 | * Stop the watchdog driver. | |
145 | */ | |
146 | ||
9f2d1f0d | 147 | static int wdt_stop(void) |
1da177e4 | 148 | { |
01c785dc AC |
149 | unsigned long flags; |
150 | spin_lock_irqsave(&wdt_lock, flags); | |
1da177e4 LT |
151 | /* Turn the card off */ |
152 | inb_p(WDT_DC); /* Disable watchdog */ | |
9f2d1f0d | 153 | wdt_ctr_load(2, 0); /* 0 length reset pulses now */ |
01c785dc | 154 | spin_unlock_irqrestore(&wdt_lock, flags); |
1da177e4 LT |
155 | return 0; |
156 | } | |
157 | ||
158 | /** | |
159 | * wdt_ping: | |
160 | * | |
9f2d1f0d AC |
161 | * Reload counter one with the watchdog heartbeat. We don't bother |
162 | * reloading the cascade counter. | |
1da177e4 LT |
163 | */ |
164 | ||
04bedfa5 | 165 | static void wdt_ping(void) |
1da177e4 | 166 | { |
01c785dc AC |
167 | unsigned long flags; |
168 | spin_lock_irqsave(&wdt_lock, flags); | |
1da177e4 LT |
169 | /* Write a watchdog value */ |
170 | inb_p(WDT_DC); /* Disable watchdog */ | |
9f2d1f0d AC |
171 | wdt_ctr_mode(1, 2); /* Re-Program CTR1 for Mode 2: |
172 | Rate Generator */ | |
173 | wdt_ctr_load(1, wd_heartbeat); /* Heartbeat */ | |
1da177e4 | 174 | outb_p(0, WDT_DC); /* Enable watchdog */ |
01c785dc | 175 | spin_unlock_irqrestore(&wdt_lock, flags); |
1da177e4 LT |
176 | } |
177 | ||
178 | /** | |
179 | * wdt_set_heartbeat: | |
180 | * @t: the new heartbeat value that needs to be set. | |
181 | * | |
9f2d1f0d AC |
182 | * Set a new heartbeat value for the watchdog device. If the heartbeat |
183 | * value is incorrect we keep the old value and return -EINVAL. If | |
184 | * successful we return 0. | |
1da177e4 | 185 | */ |
9f2d1f0d | 186 | |
1da177e4 LT |
187 | static int wdt_set_heartbeat(int t) |
188 | { | |
9f2d1f0d | 189 | if (t < 1 || t > 65535) |
1da177e4 LT |
190 | return -EINVAL; |
191 | ||
192 | heartbeat = t; | |
193 | wd_heartbeat = t * 100; | |
194 | return 0; | |
195 | } | |
196 | ||
197 | /** | |
198 | * wdt_get_status: | |
1da177e4 LT |
199 | * |
200 | * Extract the status information from a WDT watchdog device. There are | |
201 | * several board variants so we have to know which bits are valid. Some | |
202 | * bits default to one and some to zero in order to be maximally painful. | |
203 | * | |
204 | * we then map the bits onto the status ioctl flags. | |
205 | */ | |
206 | ||
04bedfa5 | 207 | static int wdt_get_status(void) |
1da177e4 | 208 | { |
01c785dc | 209 | unsigned char new_status; |
04bedfa5 | 210 | int status = 0; |
01c785dc AC |
211 | unsigned long flags; |
212 | ||
213 | spin_lock_irqsave(&wdt_lock, flags); | |
214 | new_status = inb_p(WDT_SR); | |
215 | spin_unlock_irqrestore(&wdt_lock, flags); | |
1da177e4 | 216 | |
1da177e4 | 217 | if (new_status & WDC_SR_ISOI0) |
04bedfa5 | 218 | status |= WDIOF_EXTERN1; |
1da177e4 | 219 | if (new_status & WDC_SR_ISII1) |
04bedfa5 AC |
220 | status |= WDIOF_EXTERN2; |
221 | if (type == 501) { | |
222 | if (!(new_status & WDC_SR_TGOOD)) | |
223 | status |= WDIOF_OVERHEAT; | |
224 | if (!(new_status & WDC_SR_PSUOVER)) | |
225 | status |= WDIOF_POWEROVER; | |
226 | if (!(new_status & WDC_SR_PSUUNDR)) | |
227 | status |= WDIOF_POWERUNDER; | |
228 | if (tachometer) { | |
229 | if (!(new_status & WDC_SR_FANGOOD)) | |
230 | status |= WDIOF_FANFAULT; | |
231 | } | |
1da177e4 | 232 | } |
04bedfa5 | 233 | return status; |
1da177e4 LT |
234 | } |
235 | ||
1da177e4 LT |
236 | /** |
237 | * wdt_get_temperature: | |
238 | * | |
239 | * Reports the temperature in degrees Fahrenheit. The API is in | |
240 | * farenheit. It was designed by an imperial measurement luddite. | |
241 | */ | |
242 | ||
04bedfa5 | 243 | static int wdt_get_temperature(void) |
1da177e4 | 244 | { |
01c785dc AC |
245 | unsigned short c; |
246 | unsigned long flags; | |
1da177e4 | 247 | |
01c785dc AC |
248 | spin_lock_irqsave(&wdt_lock, flags); |
249 | c = inb_p(WDT_RT); | |
250 | spin_unlock_irqrestore(&wdt_lock, flags); | |
04bedfa5 AC |
251 | return (c * 11 / 15) + 7; |
252 | } | |
253 | ||
254 | static void wdt_decode_501(int status) | |
255 | { | |
256 | if (!(status & WDC_SR_TGOOD)) | |
27c766aa | 257 | pr_crit("Overheat alarm (%d)\n", inb_p(WDT_RT)); |
04bedfa5 | 258 | if (!(status & WDC_SR_PSUOVER)) |
27c766aa | 259 | pr_crit("PSU over voltage\n"); |
04bedfa5 | 260 | if (!(status & WDC_SR_PSUUNDR)) |
27c766aa | 261 | pr_crit("PSU under voltage\n"); |
1da177e4 | 262 | } |
1da177e4 LT |
263 | |
264 | /** | |
265 | * wdt_interrupt: | |
266 | * @irq: Interrupt number | |
267 | * @dev_id: Unused as we don't allow multiple devices. | |
1da177e4 LT |
268 | * |
269 | * Handle an interrupt from the board. These are raised when the status | |
270 | * map changes in what the board considers an interesting way. That means | |
271 | * a failure condition occurring. | |
272 | */ | |
273 | ||
7d12e780 | 274 | static irqreturn_t wdt_interrupt(int irq, void *dev_id) |
1da177e4 LT |
275 | { |
276 | /* | |
277 | * Read the status register see what is up and | |
278 | * then printk it. | |
279 | */ | |
01c785dc AC |
280 | unsigned char status; |
281 | ||
282 | spin_lock(&wdt_lock); | |
283 | status = inb_p(WDT_SR); | |
1da177e4 | 284 | |
27c766aa | 285 | pr_crit("WDT status %d\n", status); |
1da177e4 | 286 | |
04bedfa5 AC |
287 | if (type == 501) { |
288 | wdt_decode_501(status); | |
289 | if (tachometer) { | |
290 | if (!(status & WDC_SR_FANGOOD)) | |
27c766aa | 291 | pr_crit("Possible fan fault\n"); |
04bedfa5 | 292 | } |
1da177e4 | 293 | } |
59338d4c | 294 | if (!(status & WDC_SR_WCCR)) { |
1da177e4 LT |
295 | #ifdef SOFTWARE_REBOOT |
296 | #ifdef ONLY_TESTING | |
27c766aa | 297 | pr_crit("Would Reboot\n"); |
1da177e4 | 298 | #else |
27c766aa | 299 | pr_crit("Initiating system reboot\n"); |
f82567e5 | 300 | emergency_restart(); |
1da177e4 LT |
301 | #endif |
302 | #else | |
27c766aa | 303 | pr_crit("Reset in 5ms\n"); |
1da177e4 | 304 | #endif |
59338d4c | 305 | } |
01c785dc | 306 | spin_unlock(&wdt_lock); |
1da177e4 LT |
307 | return IRQ_HANDLED; |
308 | } | |
309 | ||
310 | ||
311 | /** | |
312 | * wdt_write: | |
313 | * @file: file handle to the watchdog | |
314 | * @buf: buffer to write (unused as data does not matter here | |
315 | * @count: count of bytes | |
316 | * @ppos: pointer to the position to write. No seeks allowed | |
317 | * | |
318 | * A write to a watchdog device is defined as a keepalive signal. Any | |
319 | * write of data will do, as we we don't define content meaning. | |
320 | */ | |
321 | ||
9f2d1f0d AC |
322 | static ssize_t wdt_write(struct file *file, const char __user *buf, |
323 | size_t count, loff_t *ppos) | |
1da177e4 | 324 | { |
9f2d1f0d | 325 | if (count) { |
1da177e4 LT |
326 | if (!nowayout) { |
327 | size_t i; | |
328 | ||
329 | /* In case it was set long ago */ | |
330 | expect_close = 0; | |
331 | ||
332 | for (i = 0; i != count; i++) { | |
333 | char c; | |
334 | if (get_user(c, buf + i)) | |
335 | return -EFAULT; | |
336 | if (c == 'V') | |
337 | expect_close = 42; | |
338 | } | |
339 | } | |
340 | wdt_ping(); | |
341 | } | |
342 | return count; | |
343 | } | |
344 | ||
345 | /** | |
346 | * wdt_ioctl: | |
1da177e4 LT |
347 | * @file: file handle to the device |
348 | * @cmd: watchdog command | |
349 | * @arg: argument pointer | |
350 | * | |
351 | * The watchdog API defines a common set of functions for all watchdogs | |
352 | * according to their available features. We only actually usefully support | |
353 | * querying capabilities and current status. | |
354 | */ | |
355 | ||
9f2d1f0d | 356 | static long wdt_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
1da177e4 LT |
357 | { |
358 | void __user *argp = (void __user *)arg; | |
359 | int __user *p = argp; | |
360 | int new_heartbeat; | |
361 | int status; | |
362 | ||
c1bf3acf | 363 | struct watchdog_info ident = { |
1da177e4 LT |
364 | .options = WDIOF_SETTIMEOUT| |
365 | WDIOF_MAGICCLOSE| | |
366 | WDIOF_KEEPALIVEPING, | |
367 | .firmware_version = 1, | |
368 | .identity = "WDT500/501", | |
369 | }; | |
370 | ||
371 | /* Add options according to the card we have */ | |
372 | ident.options |= (WDIOF_EXTERN1|WDIOF_EXTERN2); | |
04bedfa5 AC |
373 | if (type == 501) { |
374 | ident.options |= (WDIOF_OVERHEAT|WDIOF_POWERUNDER| | |
375 | WDIOF_POWEROVER); | |
376 | if (tachometer) | |
377 | ident.options |= WDIOF_FANFAULT; | |
378 | } | |
1da177e4 | 379 | |
9f2d1f0d | 380 | switch (cmd) { |
9f2d1f0d AC |
381 | case WDIOC_GETSUPPORT: |
382 | return copy_to_user(argp, &ident, sizeof(ident)) ? -EFAULT : 0; | |
383 | case WDIOC_GETSTATUS: | |
04bedfa5 | 384 | status = wdt_get_status(); |
9f2d1f0d AC |
385 | return put_user(status, p); |
386 | case WDIOC_GETBOOTSTATUS: | |
387 | return put_user(0, p); | |
388 | case WDIOC_KEEPALIVE: | |
389 | wdt_ping(); | |
390 | return 0; | |
391 | case WDIOC_SETTIMEOUT: | |
392 | if (get_user(new_heartbeat, p)) | |
393 | return -EFAULT; | |
394 | if (wdt_set_heartbeat(new_heartbeat)) | |
395 | return -EINVAL; | |
396 | wdt_ping(); | |
397 | /* Fall */ | |
398 | case WDIOC_GETTIMEOUT: | |
399 | return put_user(heartbeat, p); | |
0c06090c WVS |
400 | default: |
401 | return -ENOTTY; | |
1da177e4 LT |
402 | } |
403 | } | |
404 | ||
405 | /** | |
406 | * wdt_open: | |
407 | * @inode: inode of device | |
408 | * @file: file handle to device | |
409 | * | |
410 | * The watchdog device has been opened. The watchdog device is single | |
411 | * open and on opening we load the counters. Counter zero is a 100Hz | |
412 | * cascade, into counter 1 which downcounts to reboot. When the counter | |
413 | * triggers counter 2 downcounts the length of the reset pulse which | |
414 | * set set to be as long as possible. | |
415 | */ | |
416 | ||
417 | static int wdt_open(struct inode *inode, struct file *file) | |
418 | { | |
9f2d1f0d | 419 | if (test_and_set_bit(0, &wdt_is_open)) |
1da177e4 LT |
420 | return -EBUSY; |
421 | /* | |
422 | * Activate | |
423 | */ | |
424 | wdt_start(); | |
425 | return nonseekable_open(inode, file); | |
426 | } | |
427 | ||
428 | /** | |
429 | * wdt_release: | |
430 | * @inode: inode to board | |
431 | * @file: file handle to board | |
432 | * | |
433 | * The watchdog has a configurable API. There is a religious dispute | |
434 | * between people who want their watchdog to be able to shut down and | |
435 | * those who want to be sure if the watchdog manager dies the machine | |
436 | * reboots. In the former case we disable the counters, in the latter | |
437 | * case you have to open it again very soon. | |
438 | */ | |
439 | ||
440 | static int wdt_release(struct inode *inode, struct file *file) | |
441 | { | |
442 | if (expect_close == 42) { | |
443 | wdt_stop(); | |
444 | clear_bit(0, &wdt_is_open); | |
445 | } else { | |
27c766aa | 446 | pr_crit("WDT device closed unexpectedly. WDT will not stop!\n"); |
1da177e4 LT |
447 | wdt_ping(); |
448 | } | |
449 | expect_close = 0; | |
450 | return 0; | |
451 | } | |
452 | ||
1da177e4 LT |
453 | /** |
454 | * wdt_temp_read: | |
455 | * @file: file handle to the watchdog board | |
456 | * @buf: buffer to write 1 byte into | |
457 | * @count: length of buffer | |
458 | * @ptr: offset (no seek allowed) | |
459 | * | |
460 | * Temp_read reports the temperature in degrees Fahrenheit. The API is in | |
461 | * farenheit. It was designed by an imperial measurement luddite. | |
462 | */ | |
463 | ||
9f2d1f0d AC |
464 | static ssize_t wdt_temp_read(struct file *file, char __user *buf, |
465 | size_t count, loff_t *ptr) | |
1da177e4 | 466 | { |
04bedfa5 | 467 | int temperature = wdt_get_temperature(); |
1da177e4 | 468 | |
9f2d1f0d | 469 | if (copy_to_user(buf, &temperature, 1)) |
1da177e4 LT |
470 | return -EFAULT; |
471 | ||
472 | return 1; | |
473 | } | |
474 | ||
475 | /** | |
476 | * wdt_temp_open: | |
477 | * @inode: inode of device | |
478 | * @file: file handle to device | |
479 | * | |
480 | * The temperature device has been opened. | |
481 | */ | |
482 | ||
483 | static int wdt_temp_open(struct inode *inode, struct file *file) | |
484 | { | |
485 | return nonseekable_open(inode, file); | |
486 | } | |
487 | ||
488 | /** | |
489 | * wdt_temp_release: | |
490 | * @inode: inode to board | |
491 | * @file: file handle to board | |
492 | * | |
493 | * The temperature device has been closed. | |
494 | */ | |
495 | ||
496 | static int wdt_temp_release(struct inode *inode, struct file *file) | |
497 | { | |
498 | return 0; | |
499 | } | |
1da177e4 LT |
500 | |
501 | /** | |
502 | * notify_sys: | |
503 | * @this: our notifier block | |
504 | * @code: the event being reported | |
505 | * @unused: unused | |
506 | * | |
507 | * Our notifier is called on system shutdowns. We want to turn the card | |
508 | * off at reboot otherwise the machine will reboot again during memory | |
509 | * test or worse yet during the following fsck. This would suck, in fact | |
510 | * trust me - if it happens it does suck. | |
511 | */ | |
512 | ||
513 | static int wdt_notify_sys(struct notifier_block *this, unsigned long code, | |
514 | void *unused) | |
515 | { | |
9f2d1f0d | 516 | if (code == SYS_DOWN || code == SYS_HALT) |
1da177e4 | 517 | wdt_stop(); |
1da177e4 LT |
518 | return NOTIFY_DONE; |
519 | } | |
520 | ||
521 | /* | |
522 | * Kernel Interfaces | |
523 | */ | |
524 | ||
525 | ||
62322d25 | 526 | static const struct file_operations wdt_fops = { |
1da177e4 LT |
527 | .owner = THIS_MODULE, |
528 | .llseek = no_llseek, | |
529 | .write = wdt_write, | |
9f2d1f0d | 530 | .unlocked_ioctl = wdt_ioctl, |
1da177e4 LT |
531 | .open = wdt_open, |
532 | .release = wdt_release, | |
533 | }; | |
534 | ||
535 | static struct miscdevice wdt_miscdev = { | |
536 | .minor = WATCHDOG_MINOR, | |
537 | .name = "watchdog", | |
538 | .fops = &wdt_fops, | |
539 | }; | |
540 | ||
62322d25 | 541 | static const struct file_operations wdt_temp_fops = { |
1da177e4 LT |
542 | .owner = THIS_MODULE, |
543 | .llseek = no_llseek, | |
544 | .read = wdt_temp_read, | |
545 | .open = wdt_temp_open, | |
546 | .release = wdt_temp_release, | |
547 | }; | |
548 | ||
549 | static struct miscdevice temp_miscdev = { | |
550 | .minor = TEMP_MINOR, | |
551 | .name = "temperature", | |
552 | .fops = &wdt_temp_fops, | |
553 | }; | |
1da177e4 LT |
554 | |
555 | /* | |
556 | * The WDT card needs to learn about soft shutdowns in order to | |
557 | * turn the timebomb registers off. | |
558 | */ | |
559 | ||
560 | static struct notifier_block wdt_notifier = { | |
561 | .notifier_call = wdt_notify_sys, | |
562 | }; | |
563 | ||
564 | /** | |
565 | * cleanup_module: | |
566 | * | |
567 | * Unload the watchdog. You cannot do this with any file handles open. | |
568 | * If your watchdog is set to continue ticking on close and you unload | |
569 | * it, well it keeps ticking. We won't get the interrupt but the board | |
570 | * will not touch PC memory so all is fine. You just have to load a new | |
571 | * module in 60 seconds or reboot. | |
572 | */ | |
573 | ||
574 | static void __exit wdt_exit(void) | |
575 | { | |
576 | misc_deregister(&wdt_miscdev); | |
04bedfa5 AC |
577 | if (type == 501) |
578 | misc_deregister(&temp_miscdev); | |
1da177e4 LT |
579 | unregister_reboot_notifier(&wdt_notifier); |
580 | free_irq(irq, NULL); | |
9f2d1f0d | 581 | release_region(io, 8); |
1da177e4 LT |
582 | } |
583 | ||
584 | /** | |
5f3b2756 | 585 | * wdt_init: |
1da177e4 LT |
586 | * |
587 | * Set up the WDT watchdog board. All we have to do is grab the | |
588 | * resources we require and bitch if anyone beat us to them. | |
589 | * The open() function will actually kick the board off. | |
590 | */ | |
591 | ||
592 | static int __init wdt_init(void) | |
593 | { | |
594 | int ret; | |
595 | ||
04bedfa5 | 596 | if (type != 500 && type != 501) { |
27c766aa | 597 | pr_err("unknown card type '%d'\n", type); |
04bedfa5 AC |
598 | return -ENODEV; |
599 | } | |
600 | ||
9f2d1f0d AC |
601 | /* Check that the heartbeat value is within it's range; |
602 | if not reset to the default */ | |
1da177e4 LT |
603 | if (wdt_set_heartbeat(heartbeat)) { |
604 | wdt_set_heartbeat(WD_TIMO); | |
27c766aa JP |
605 | pr_info("heartbeat value must be 0 < heartbeat < 65536, using %d\n", |
606 | WD_TIMO); | |
1da177e4 LT |
607 | } |
608 | ||
609 | if (!request_region(io, 8, "wdt501p")) { | |
27c766aa | 610 | pr_err("I/O address 0x%04x already in use\n", io); |
1da177e4 LT |
611 | ret = -EBUSY; |
612 | goto out; | |
613 | } | |
614 | ||
86b59128 | 615 | ret = request_irq(irq, wdt_interrupt, 0, "wdt501p", NULL); |
9f2d1f0d | 616 | if (ret) { |
27c766aa | 617 | pr_err("IRQ %d is not free\n", irq); |
1da177e4 LT |
618 | goto outreg; |
619 | } | |
620 | ||
621 | ret = register_reboot_notifier(&wdt_notifier); | |
9f2d1f0d | 622 | if (ret) { |
27c766aa | 623 | pr_err("cannot register reboot notifier (err=%d)\n", ret); |
1da177e4 LT |
624 | goto outirq; |
625 | } | |
626 | ||
04bedfa5 AC |
627 | if (type == 501) { |
628 | ret = misc_register(&temp_miscdev); | |
629 | if (ret) { | |
27c766aa JP |
630 | pr_err("cannot register miscdev on minor=%d (err=%d)\n", |
631 | TEMP_MINOR, ret); | |
04bedfa5 AC |
632 | goto outrbt; |
633 | } | |
1da177e4 | 634 | } |
1da177e4 LT |
635 | |
636 | ret = misc_register(&wdt_miscdev); | |
637 | if (ret) { | |
27c766aa JP |
638 | pr_err("cannot register miscdev on minor=%d (err=%d)\n", |
639 | WATCHDOG_MINOR, ret); | |
1da177e4 LT |
640 | goto outmisc; |
641 | } | |
642 | ||
27c766aa | 643 | pr_info("WDT500/501-P driver 0.10 at 0x%04x (Interrupt %d). heartbeat=%d sec (nowayout=%d)\n", |
1da177e4 | 644 | io, irq, heartbeat, nowayout); |
04bedfa5 | 645 | if (type == 501) |
27c766aa JP |
646 | pr_info("Fan Tachometer is %s\n", |
647 | tachometer ? "Enabled" : "Disabled"); | |
04bedfa5 | 648 | return 0; |
1da177e4 LT |
649 | |
650 | outmisc: | |
04bedfa5 AC |
651 | if (type == 501) |
652 | misc_deregister(&temp_miscdev); | |
1da177e4 | 653 | outrbt: |
1da177e4 LT |
654 | unregister_reboot_notifier(&wdt_notifier); |
655 | outirq: | |
656 | free_irq(irq, NULL); | |
657 | outreg: | |
9f2d1f0d | 658 | release_region(io, 8); |
04bedfa5 AC |
659 | out: |
660 | return ret; | |
1da177e4 LT |
661 | } |
662 | ||
663 | module_init(wdt_init); | |
664 | module_exit(wdt_exit); | |
665 | ||
666 | MODULE_AUTHOR("Alan Cox"); | |
667 | MODULE_DESCRIPTION("Driver for ISA ICS watchdog cards (WDT500/501)"); | |
668 | MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR); | |
669 | MODULE_ALIAS_MISCDEV(TEMP_MINOR); | |
670 | MODULE_LICENSE("GPL"); |