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