1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52#include <linux/module.h>
53#include <linux/moduleparam.h>
54#include <linux/types.h>
55#include <linux/errno.h>
56#include <linux/kernel.h>
57#include <linux/delay.h>
58#include <linux/timer.h>
59#include <linux/jiffies.h>
60#include <linux/miscdevice.h>
61#include <linux/watchdog.h>
62#include <linux/reboot.h>
63#include <linux/init.h>
64#include <linux/fs.h>
65#include <linux/isa.h>
66#include <linux/ioport.h>
67#include <linux/spinlock.h>
68
69#include <asm/uaccess.h>
70#include <asm/io.h>
71
72
73#define WATCHDOG_VERSION "1.20"
74#define WATCHDOG_DATE "18 Feb 2007"
75#define WATCHDOG_DRIVER_NAME "ISA-PC Watchdog"
76#define WATCHDOG_NAME "pcwd"
77#define PFX WATCHDOG_NAME ": "
78#define DRIVER_VERSION WATCHDOG_DRIVER_NAME " driver, v" WATCHDOG_VERSION " (" WATCHDOG_DATE ")\n"
79#define WD_VER WATCHDOG_VERSION " (" WATCHDOG_DATE ")"
80
81
82
83
84
85
86
87
88#define PCWD_REVISION_A 1
89#define PCWD_REVISION_C 2
90
91
92
93
94
95
96
97#define PCWD_ISA_NR_CARDS 3
98static int pcwd_ioports[] = { 0x270, 0x350, 0x370, 0x000 };
99
100
101
102
103
104
105#define WD_WDRST 0x01
106#define WD_T110 0x02
107#define WD_HRTBT 0x04
108#define WD_RLY2 0x08
109#define WD_SRLY2 0x80
110
111#define WD_REVC_WTRP 0x01
112#define WD_REVC_HRBT 0x02
113#define WD_REVC_TTRP 0x04
114#define WD_REVC_RL2A 0x08
115#define WD_REVC_RL1A 0x10
116#define WD_REVC_R2DS 0x40
117#define WD_REVC_RLY2 0x80
118
119#define WD_WDIS 0x10
120#define WD_ENTP 0x20
121#define WD_SSEL 0x40
122#define WD_WCMD 0x80
123
124
125
126#define ISA_COMMAND_TIMEOUT 1000
127
128
129#define CMD_ISA_IDLE 0x00
130#define CMD_ISA_VERSION_INTEGER 0x01
131#define CMD_ISA_VERSION_TENTH 0x02
132#define CMD_ISA_VERSION_HUNDRETH 0x03
133#define CMD_ISA_VERSION_MINOR 0x04
134#define CMD_ISA_SWITCH_SETTINGS 0x05
135#define CMD_ISA_RESET_PC 0x06
136#define CMD_ISA_ARM_0 0x07
137#define CMD_ISA_ARM_30 0x08
138#define CMD_ISA_ARM_60 0x09
139#define CMD_ISA_DELAY_TIME_2SECS 0x0A
140#define CMD_ISA_DELAY_TIME_4SECS 0x0B
141#define CMD_ISA_DELAY_TIME_8SECS 0x0C
142#define CMD_ISA_RESET_RELAYS 0x0D
143
144
145static const int heartbeat_tbl [] = {
146 20,
147 40,
148 60,
149 300,
150 600,
151 1800,
152 3600,
153 7200,
154};
155
156
157
158
159
160
161
162#define WDT_INTERVAL (HZ/2+1)
163
164
165static int cards_found;
166
167
168static atomic_t open_allowed = ATOMIC_INIT(1);
169static char expect_close;
170static int temp_panic;
171static struct {
172 char fw_ver_str[6];
173 int revision;
174 int supports_temp;
175 int command_mode;
176 int boot_status;
177 int io_addr;
178 spinlock_t io_lock;
179 struct timer_list timer;
180 unsigned long next_heartbeat;
181} pcwd_private;
182
183
184#define QUIET 0
185#define VERBOSE 1
186#define DEBUG 2
187static int debug = QUIET;
188module_param(debug, int, 0);
189MODULE_PARM_DESC(debug, "Debug level: 0=Quiet, 1=Verbose, 2=Debug (default=0)");
190
191#define WATCHDOG_HEARTBEAT 0
192static int heartbeat = WATCHDOG_HEARTBEAT;
193module_param(heartbeat, int, 0);
194MODULE_PARM_DESC(heartbeat, "Watchdog heartbeat in seconds. (2<=heartbeat<=7200 or 0=delay-time from dip-switches, default=" __MODULE_STRING(WATCHDOG_HEARTBEAT) ")");
195
196static int nowayout = WATCHDOG_NOWAYOUT;
197module_param(nowayout, int, 0);
198MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
199
200
201
202
203
204static int send_isa_command(int cmd)
205{
206 int i;
207 int control_status;
208 int port0, last_port0;
209
210 if (debug >= DEBUG)
211 printk(KERN_DEBUG PFX "sending following data cmd=0x%02x\n",
212 cmd);
213
214
215 control_status = (cmd & 0x0F) | WD_WCMD;
216 outb_p(control_status, pcwd_private.io_addr + 2);
217 udelay(ISA_COMMAND_TIMEOUT);
218
219 port0 = inb_p(pcwd_private.io_addr);
220 for (i = 0; i < 25; ++i) {
221 last_port0 = port0;
222 port0 = inb_p(pcwd_private.io_addr);
223
224 if (port0 == last_port0)
225 break;
226
227 udelay (250);
228 }
229
230 if (debug >= DEBUG)
231 printk(KERN_DEBUG PFX "received following data for cmd=0x%02x: port0=0x%02x last_port0=0x%02x\n",
232 cmd, port0, last_port0);
233
234 return port0;
235}
236
237static int set_command_mode(void)
238{
239 int i, found=0, count=0;
240
241
242 spin_lock(&pcwd_private.io_lock);
243 while ((!found) && (count < 3)) {
244 i = send_isa_command(CMD_ISA_IDLE);
245
246 if (i == 0x00)
247 found = 1;
248 else if (i == 0xF3) {
249
250 outb_p(0x00, pcwd_private.io_addr + 2);
251 udelay(1200);
252 outb_p(0x00, pcwd_private.io_addr + 2);
253 udelay(ISA_COMMAND_TIMEOUT);
254 }
255 count++;
256 }
257 spin_unlock(&pcwd_private.io_lock);
258 pcwd_private.command_mode = found;
259
260 if (debug >= DEBUG)
261 printk(KERN_DEBUG PFX "command_mode=%d\n",
262 pcwd_private.command_mode);
263
264 return(found);
265}
266
267static void unset_command_mode(void)
268{
269
270 spin_lock(&pcwd_private.io_lock);
271 outb_p(0x00, pcwd_private.io_addr + 2);
272 udelay(ISA_COMMAND_TIMEOUT);
273 spin_unlock(&pcwd_private.io_lock);
274
275 pcwd_private.command_mode = 0;
276
277 if (debug >= DEBUG)
278 printk(KERN_DEBUG PFX "command_mode=%d\n",
279 pcwd_private.command_mode);
280}
281
282static inline void pcwd_check_temperature_support(void)
283{
284 if (inb(pcwd_private.io_addr) != 0xF0)
285 pcwd_private.supports_temp = 1;
286}
287
288static inline void pcwd_get_firmware(void)
289{
290 int one, ten, hund, minor;
291
292 strcpy(pcwd_private.fw_ver_str, "ERROR");
293
294 if (set_command_mode()) {
295 one = send_isa_command(CMD_ISA_VERSION_INTEGER);
296 ten = send_isa_command(CMD_ISA_VERSION_TENTH);
297 hund = send_isa_command(CMD_ISA_VERSION_HUNDRETH);
298 minor = send_isa_command(CMD_ISA_VERSION_MINOR);
299 sprintf(pcwd_private.fw_ver_str, "%c.%c%c%c", one, ten, hund, minor);
300 }
301 unset_command_mode();
302
303 return;
304}
305
306static inline int pcwd_get_option_switches(void)
307{
308 int option_switches=0;
309
310 if (set_command_mode()) {
311
312 option_switches = send_isa_command(CMD_ISA_SWITCH_SETTINGS);
313 }
314
315 unset_command_mode();
316 return(option_switches);
317}
318
319static void pcwd_show_card_info(void)
320{
321 int option_switches;
322
323
324 if (pcwd_private.revision == PCWD_REVISION_A)
325 printk(KERN_INFO PFX "ISA-PC Watchdog (REV.A) detected at port 0x%04x\n", pcwd_private.io_addr);
326 else if (pcwd_private.revision == PCWD_REVISION_C) {
327 pcwd_get_firmware();
328 printk(KERN_INFO PFX "ISA-PC Watchdog (REV.C) detected at port 0x%04x (Firmware version: %s)\n",
329 pcwd_private.io_addr, pcwd_private.fw_ver_str);
330 option_switches = pcwd_get_option_switches();
331 printk(KERN_INFO PFX "Option switches (0x%02x): Temperature Reset Enable=%s, Power On Delay=%s\n",
332 option_switches,
333 ((option_switches & 0x10) ? "ON" : "OFF"),
334 ((option_switches & 0x08) ? "ON" : "OFF"));
335
336
337 if (set_command_mode()) {
338 send_isa_command(CMD_ISA_DELAY_TIME_2SECS);
339 unset_command_mode();
340 }
341 }
342
343 if (pcwd_private.supports_temp)
344 printk(KERN_INFO PFX "Temperature Option Detected\n");
345
346 if (pcwd_private.boot_status & WDIOF_CARDRESET)
347 printk(KERN_INFO PFX "Previous reboot was caused by the card\n");
348
349 if (pcwd_private.boot_status & WDIOF_OVERHEAT) {
350 printk(KERN_EMERG PFX "Card senses a CPU Overheat. Panicking!\n");
351 printk(KERN_EMERG PFX "CPU Overheat\n");
352 }
353
354 if (pcwd_private.boot_status == 0)
355 printk(KERN_INFO PFX "No previous trip detected - Cold boot or reset\n");
356}
357
358static void pcwd_timer_ping(unsigned long data)
359{
360 int wdrst_stat;
361
362
363
364 if(time_before(jiffies, pcwd_private.next_heartbeat)) {
365
366 spin_lock(&pcwd_private.io_lock);
367 if (pcwd_private.revision == PCWD_REVISION_A) {
368
369 wdrst_stat = inb_p(pcwd_private.io_addr);
370 wdrst_stat &= 0x0F;
371 wdrst_stat |= WD_WDRST;
372
373 outb_p(wdrst_stat, pcwd_private.io_addr + 1);
374 } else {
375
376 outb_p(0x00, pcwd_private.io_addr);
377 }
378
379
380 mod_timer(&pcwd_private.timer, jiffies + WDT_INTERVAL);
381
382 spin_unlock(&pcwd_private.io_lock);
383 } else {
384 printk(KERN_WARNING PFX "Heartbeat lost! Will not ping the watchdog\n");
385 }
386}
387
388static int pcwd_start(void)
389{
390 int stat_reg;
391
392 pcwd_private.next_heartbeat = jiffies + (heartbeat * HZ);
393
394
395 mod_timer(&pcwd_private.timer, jiffies + WDT_INTERVAL);
396
397
398 if (pcwd_private.revision == PCWD_REVISION_C) {
399 spin_lock(&pcwd_private.io_lock);
400 outb_p(0x00, pcwd_private.io_addr + 3);
401 udelay(ISA_COMMAND_TIMEOUT);
402 stat_reg = inb_p(pcwd_private.io_addr + 2);
403 spin_unlock(&pcwd_private.io_lock);
404 if (stat_reg & WD_WDIS) {
405 printk(KERN_INFO PFX "Could not start watchdog\n");
406 return -EIO;
407 }
408 }
409
410 if (debug >= VERBOSE)
411 printk(KERN_DEBUG PFX "Watchdog started\n");
412
413 return 0;
414}
415
416static int pcwd_stop(void)
417{
418 int stat_reg;
419
420
421 del_timer(&pcwd_private.timer);
422
423
424 if (pcwd_private.revision == PCWD_REVISION_C) {
425 spin_lock(&pcwd_private.io_lock);
426 outb_p(0xA5, pcwd_private.io_addr + 3);
427 udelay(ISA_COMMAND_TIMEOUT);
428 outb_p(0xA5, pcwd_private.io_addr + 3);
429 udelay(ISA_COMMAND_TIMEOUT);
430 stat_reg = inb_p(pcwd_private.io_addr + 2);
431 spin_unlock(&pcwd_private.io_lock);
432 if ((stat_reg & WD_WDIS) == 0) {
433 printk(KERN_INFO PFX "Could not stop watchdog\n");
434 return -EIO;
435 }
436 }
437
438 if (debug >= VERBOSE)
439 printk(KERN_DEBUG PFX "Watchdog stopped\n");
440
441 return 0;
442}
443
444static int pcwd_keepalive(void)
445{
446
447 pcwd_private.next_heartbeat = jiffies + (heartbeat * HZ);
448
449 if (debug >= DEBUG)
450 printk(KERN_DEBUG PFX "Watchdog keepalive signal send\n");
451
452 return 0;
453}
454
455static int pcwd_set_heartbeat(int t)
456{
457 if ((t < 2) || (t > 7200))
458 return -EINVAL;
459
460 heartbeat = t;
461
462 if (debug >= VERBOSE)
463 printk(KERN_DEBUG PFX "New heartbeat: %d\n",
464 heartbeat);
465
466 return 0;
467}
468
469static int pcwd_get_status(int *status)
470{
471 int control_status;
472
473 *status=0;
474 spin_lock(&pcwd_private.io_lock);
475 if (pcwd_private.revision == PCWD_REVISION_A)
476
477
478
479 control_status = inb(pcwd_private.io_addr);
480 else {
481
482
483
484
485
486 control_status = inb(pcwd_private.io_addr + 1);
487 }
488 spin_unlock(&pcwd_private.io_lock);
489
490 if (pcwd_private.revision == PCWD_REVISION_A) {
491 if (control_status & WD_WDRST)
492 *status |= WDIOF_CARDRESET;
493
494 if (control_status & WD_T110) {
495 *status |= WDIOF_OVERHEAT;
496 if (temp_panic) {
497 printk(KERN_INFO PFX "Temperature overheat trip!\n");
498 kernel_power_off();
499
500 }
501 }
502 } else {
503 if (control_status & WD_REVC_WTRP)
504 *status |= WDIOF_CARDRESET;
505
506 if (control_status & WD_REVC_TTRP) {
507 *status |= WDIOF_OVERHEAT;
508 if (temp_panic) {
509 printk(KERN_INFO PFX "Temperature overheat trip!\n");
510 kernel_power_off();
511
512 }
513 }
514 }
515
516 return 0;
517}
518
519static int pcwd_clear_status(void)
520{
521 int control_status;
522
523 if (pcwd_private.revision == PCWD_REVISION_C) {
524 spin_lock(&pcwd_private.io_lock);
525
526 if (debug >= VERBOSE)
527 printk(KERN_INFO PFX "clearing watchdog trip status\n");
528
529 control_status = inb_p(pcwd_private.io_addr + 1);
530
531 if (debug >= DEBUG) {
532 printk(KERN_DEBUG PFX "status was: 0x%02x\n", control_status);
533 printk(KERN_DEBUG PFX "sending: 0x%02x\n",
534 (control_status & WD_REVC_R2DS));
535 }
536
537
538 outb_p((control_status & WD_REVC_R2DS), pcwd_private.io_addr + 1);
539
540 spin_unlock(&pcwd_private.io_lock);
541 }
542 return 0;
543}
544
545static int pcwd_get_temperature(int *temperature)
546{
547
548 if (pcwd_private.command_mode)
549 return -1;
550
551 *temperature = 0;
552 if (!pcwd_private.supports_temp)
553 return -ENODEV;
554
555
556
557
558
559 spin_lock(&pcwd_private.io_lock);
560 *temperature = ((inb(pcwd_private.io_addr)) * 9 / 5) + 32;
561 spin_unlock(&pcwd_private.io_lock);
562
563 if (debug >= DEBUG) {
564 printk(KERN_DEBUG PFX "temperature is: %d F\n",
565 *temperature);
566 }
567
568 return 0;
569}
570
571
572
573
574
575static int pcwd_ioctl(struct inode *inode, struct file *file,
576 unsigned int cmd, unsigned long arg)
577{
578 int rv;
579 int status;
580 int temperature;
581 int new_heartbeat;
582 int __user *argp = (int __user *)arg;
583 static struct watchdog_info ident = {
584 .options = WDIOF_OVERHEAT |
585 WDIOF_CARDRESET |
586 WDIOF_KEEPALIVEPING |
587 WDIOF_SETTIMEOUT |
588 WDIOF_MAGICCLOSE,
589 .firmware_version = 1,
590 .identity = "PCWD",
591 };
592
593 switch(cmd) {
594 default:
595 return -ENOTTY;
596
597 case WDIOC_GETSUPPORT:
598 if(copy_to_user(argp, &ident, sizeof(ident)))
599 return -EFAULT;
600 return 0;
601
602 case WDIOC_GETSTATUS:
603 pcwd_get_status(&status);
604 return put_user(status, argp);
605
606 case WDIOC_GETBOOTSTATUS:
607 return put_user(pcwd_private.boot_status, argp);
608
609 case WDIOC_GETTEMP:
610 if (pcwd_get_temperature(&temperature))
611 return -EFAULT;
612
613 return put_user(temperature, argp);
614
615 case WDIOC_SETOPTIONS:
616 if (pcwd_private.revision == PCWD_REVISION_C)
617 {
618 if(copy_from_user(&rv, argp, sizeof(int)))
619 return -EFAULT;
620
621 if (rv & WDIOS_DISABLECARD)
622 {
623 return pcwd_stop();
624 }
625
626 if (rv & WDIOS_ENABLECARD)
627 {
628 return pcwd_start();
629 }
630
631 if (rv & WDIOS_TEMPPANIC)
632 {
633 temp_panic = 1;
634 }
635 }
636 return -EINVAL;
637
638 case WDIOC_KEEPALIVE:
639 pcwd_keepalive();
640 return 0;
641
642 case WDIOC_SETTIMEOUT:
643 if (get_user(new_heartbeat, argp))
644 return -EFAULT;
645
646 if (pcwd_set_heartbeat(new_heartbeat))
647 return -EINVAL;
648
649 pcwd_keepalive();
650
651
652 case WDIOC_GETTIMEOUT:
653 return put_user(heartbeat, argp);
654 }
655
656 return 0;
657}
658
659static ssize_t pcwd_write(struct file *file, const char __user *buf, size_t len,
660 loff_t *ppos)
661{
662 if (len) {
663 if (!nowayout) {
664 size_t i;
665
666
667 expect_close = 0;
668
669 for (i = 0; i != len; i++) {
670 char c;
671
672 if (get_user(c, buf + i))
673 return -EFAULT;
674 if (c == 'V')
675 expect_close = 42;
676 }
677 }
678 pcwd_keepalive();
679 }
680 return len;
681}
682
683static int pcwd_open(struct inode *inode, struct file *file)
684{
685 if (!atomic_dec_and_test(&open_allowed) ) {
686 if (debug >= VERBOSE)
687 printk(KERN_ERR PFX "Attempt to open already opened device.\n");
688 atomic_inc( &open_allowed );
689 return -EBUSY;
690 }
691
692 if (nowayout)
693 __module_get(THIS_MODULE);
694
695
696 pcwd_start();
697 pcwd_keepalive();
698 return nonseekable_open(inode, file);
699}
700
701static int pcwd_close(struct inode *inode, struct file *file)
702{
703 if (expect_close == 42) {
704 pcwd_stop();
705 } else {
706 printk(KERN_CRIT PFX "Unexpected close, not stopping watchdog!\n");
707 pcwd_keepalive();
708 }
709 expect_close = 0;
710 atomic_inc( &open_allowed );
711 return 0;
712}
713
714
715
716
717
718static ssize_t pcwd_temp_read(struct file *file, char __user *buf, size_t count,
719 loff_t *ppos)
720{
721 int temperature;
722
723 if (pcwd_get_temperature(&temperature))
724 return -EFAULT;
725
726 if (copy_to_user(buf, &temperature, 1))
727 return -EFAULT;
728
729 return 1;
730}
731
732static int pcwd_temp_open(struct inode *inode, struct file *file)
733{
734 if (!pcwd_private.supports_temp)
735 return -ENODEV;
736
737 return nonseekable_open(inode, file);
738}
739
740static int pcwd_temp_close(struct inode *inode, struct file *file)
741{
742 return 0;
743}
744
745
746
747
748
749static const struct file_operations pcwd_fops = {
750 .owner = THIS_MODULE,
751 .llseek = no_llseek,
752 .write = pcwd_write,
753 .ioctl = pcwd_ioctl,
754 .open = pcwd_open,
755 .release = pcwd_close,
756};
757
758static struct miscdevice pcwd_miscdev = {
759 .minor = WATCHDOG_MINOR,
760 .name = "watchdog",
761 .fops = &pcwd_fops,
762};
763
764static const struct file_operations pcwd_temp_fops = {
765 .owner = THIS_MODULE,
766 .llseek = no_llseek,
767 .read = pcwd_temp_read,
768 .open = pcwd_temp_open,
769 .release = pcwd_temp_close,
770};
771
772static struct miscdevice temp_miscdev = {
773 .minor = TEMP_MINOR,
774 .name = "temperature",
775 .fops = &pcwd_temp_fops,
776};
777
778
779
780
781
782static inline int get_revision(void)
783{
784 int r = PCWD_REVISION_C;
785
786 spin_lock(&pcwd_private.io_lock);
787
788
789 if ((inb(pcwd_private.io_addr + 2) == 0xFF) ||
790 (inb(pcwd_private.io_addr + 3) == 0xFF))
791 r=PCWD_REVISION_A;
792 spin_unlock(&pcwd_private.io_lock);
793
794 return r;
795}
796
797
798
799
800
801
802
803
804static int __devinit pcwd_isa_match(struct device *dev, unsigned int id)
805{
806 int base_addr=pcwd_ioports[id];
807 int port0, last_port0;
808 int port1, last_port1;
809 int i;
810 int retval;
811
812 if (debug >= DEBUG)
813 printk(KERN_DEBUG PFX "pcwd_isa_match id=%d\n",
814 id);
815
816 if (!request_region (base_addr, 4, "PCWD")) {
817 printk(KERN_INFO PFX "Port 0x%04x unavailable\n", base_addr);
818 return 0;
819 }
820
821 retval = 0;
822
823 port0 = inb_p(base_addr);
824 port1 = inb_p(base_addr + 1);
825 if (port0 != 0xff || port1 != 0xff) {
826
827 for (i = 0; i < 4; ++i) {
828
829 msleep(500);
830
831 last_port0 = port0;
832 last_port1 = port1;
833
834 port0 = inb_p(base_addr);
835 port1 = inb_p(base_addr + 1);
836
837
838 if ((port0 ^ last_port0) & WD_HRTBT ||
839 (port1 ^ last_port1) & WD_REVC_HRBT) {
840 retval = 1;
841 break;
842 }
843 }
844 }
845 release_region (base_addr, 4);
846
847 return retval;
848}
849
850static int __devinit pcwd_isa_probe(struct device *dev, unsigned int id)
851{
852 int ret;
853
854 if (debug >= DEBUG)
855 printk(KERN_DEBUG PFX "pcwd_isa_probe id=%d\n",
856 id);
857
858 cards_found++;
859 if (cards_found == 1)
860 printk(KERN_INFO PFX "v%s Ken Hollis (kenji@bitgate.com)\n", WD_VER);
861
862 if (cards_found > 1) {
863 printk(KERN_ERR PFX "This driver only supports 1 device\n");
864 return -ENODEV;
865 }
866
867 if (pcwd_ioports[id] == 0x0000) {
868 printk(KERN_ERR PFX "No I/O-Address for card detected\n");
869 return -ENODEV;
870 }
871 pcwd_private.io_addr = pcwd_ioports[id];
872
873 spin_lock_init(&pcwd_private.io_lock);
874
875
876 pcwd_private.revision = get_revision();
877
878 if (!request_region(pcwd_private.io_addr, (pcwd_private.revision == PCWD_REVISION_A) ? 2 : 4, "PCWD")) {
879 printk(KERN_ERR PFX "I/O address 0x%04x already in use\n",
880 pcwd_private.io_addr);
881 ret=-EIO;
882 goto error_request_region;
883 }
884
885
886 pcwd_private.supports_temp = 0;
887 temp_panic = 0;
888 pcwd_private.boot_status = 0x0000;
889
890
891 pcwd_get_status(&pcwd_private.boot_status);
892
893
894 pcwd_clear_status();
895
896 setup_timer(&pcwd_private.timer, pcwd_timer_ping, 0);
897
898
899 pcwd_stop();
900
901
902 pcwd_check_temperature_support();
903
904
905 pcwd_show_card_info();
906
907
908 if (heartbeat == 0)
909 heartbeat = heartbeat_tbl[(pcwd_get_option_switches() & 0x07)];
910
911
912 if (pcwd_set_heartbeat(heartbeat)) {
913 pcwd_set_heartbeat(WATCHDOG_HEARTBEAT);
914 printk(KERN_INFO PFX "heartbeat value must be 2<=heartbeat<=7200, using %d\n",
915 WATCHDOG_HEARTBEAT);
916 }
917
918 if (pcwd_private.supports_temp) {
919 ret = misc_register(&temp_miscdev);
920 if (ret) {
921 printk(KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n",
922 TEMP_MINOR, ret);
923 goto error_misc_register_temp;
924 }
925 }
926
927 ret = misc_register(&pcwd_miscdev);
928 if (ret) {
929 printk(KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n",
930 WATCHDOG_MINOR, ret);
931 goto error_misc_register_watchdog;
932 }
933
934 printk(KERN_INFO PFX "initialized. heartbeat=%d sec (nowayout=%d)\n",
935 heartbeat, nowayout);
936
937 return 0;
938
939error_misc_register_watchdog:
940 if (pcwd_private.supports_temp)
941 misc_deregister(&temp_miscdev);
942error_misc_register_temp:
943 release_region(pcwd_private.io_addr, (pcwd_private.revision == PCWD_REVISION_A) ? 2 : 4);
944error_request_region:
945 pcwd_private.io_addr = 0x0000;
946 cards_found--;
947 return ret;
948}
949
950static int __devexit pcwd_isa_remove(struct device *dev, unsigned int id)
951{
952 if (debug >= DEBUG)
953 printk(KERN_DEBUG PFX "pcwd_isa_remove id=%d\n",
954 id);
955
956 if (!pcwd_private.io_addr)
957 return 1;
958
959
960 if (!nowayout)
961 pcwd_stop();
962
963
964 misc_deregister(&pcwd_miscdev);
965 if (pcwd_private.supports_temp)
966 misc_deregister(&temp_miscdev);
967 release_region(pcwd_private.io_addr, (pcwd_private.revision == PCWD_REVISION_A) ? 2 : 4);
968 pcwd_private.io_addr = 0x0000;
969 cards_found--;
970
971 return 0;
972}
973
974static void pcwd_isa_shutdown(struct device *dev, unsigned int id)
975{
976 if (debug >= DEBUG)
977 printk(KERN_DEBUG PFX "pcwd_isa_shutdown id=%d\n",
978 id);
979
980 pcwd_stop();
981}
982
983static struct isa_driver pcwd_isa_driver = {
984 .match = pcwd_isa_match,
985 .probe = pcwd_isa_probe,
986 .remove = __devexit_p(pcwd_isa_remove),
987 .shutdown = pcwd_isa_shutdown,
988 .driver = {
989 .owner = THIS_MODULE,
990 .name = WATCHDOG_NAME,
991 },
992};
993
994static int __init pcwd_init_module(void)
995{
996 return isa_register_driver(&pcwd_isa_driver, PCWD_ISA_NR_CARDS);
997}
998
999static void __exit pcwd_cleanup_module(void)
1000{
1001 isa_unregister_driver(&pcwd_isa_driver);
1002 printk(KERN_INFO PFX "Watchdog Module Unloaded.\n");
1003}
1004
1005module_init(pcwd_init_module);
1006module_exit(pcwd_cleanup_module);
1007
1008MODULE_AUTHOR("Ken Hollis <kenji@bitgate.com>, Wim Van Sebroeck <wim@iguana.be>");
1009MODULE_DESCRIPTION("Berkshire ISA-PC Watchdog driver");
1010MODULE_VERSION(WATCHDOG_VERSION);
1011MODULE_LICENSE("GPL");
1012MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
1013MODULE_ALIAS_MISCDEV(TEMP_MINOR);
1014