40 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
43 #include <linux/module.h>
45 #include <linux/types.h>
47 #include <linux/watchdog.h>
51 #include <linux/reboot.h>
54 #include <linux/pci.h>
65 static unsigned long open_lock;
76 static int wd_heartbeat;
79 "Watchdog heartbeat in seconds. (0<heartbeat<65536, default="
85 "Watchdog cannot be stopped once started (default="
89 static int tachometer;
92 "PCI-WDT501 Fan Tachometer support (0=disable, default=0)");
94 static int type = 500;
97 "PCI-WDT501 Card type (500 or 501 , default=500)");
103 static void wdtpci_ctr_mode(
int ctr,
int mode)
112 static void wdtpci_ctr_load(
int ctr,
int val)
126 static int wdtpci_start(
void)
138 wdtpci_ctr_mode(2, 0);
154 wdtpci_ctr_mode(0, 3);
156 wdtpci_ctr_mode(1, 2);
158 wdtpci_ctr_mode(2, 1);
160 wdtpci_ctr_load(0, 20833);
161 wdtpci_ctr_load(1, wd_heartbeat);
166 spin_unlock_irqrestore(&wdtpci_lock, flags);
176 static int wdtpci_stop(
void)
184 wdtpci_ctr_load(2, 0);
185 spin_unlock_irqrestore(&wdtpci_lock, flags);
196 static int wdtpci_ping(
void)
204 wdtpci_ctr_mode(1, 2);
206 wdtpci_ctr_load(1, wd_heartbeat);
209 spin_unlock_irqrestore(&wdtpci_lock, flags);
221 static int wdtpci_set_heartbeat(
int t)
224 if (t < 1 || t > 65535)
228 wd_heartbeat = t * 100;
243 static int wdtpci_get_status(
int *
status)
245 unsigned char new_status;
250 spin_unlock_irqrestore(&wdtpci_lock, flags);
279 static int wdtpci_get_temperature(
int *
temperature)
286 spin_unlock_irqrestore(&wdtpci_lock, flags);
287 *temperature = (c * 11 / 15) + 7;
309 spin_lock(&wdtpci_lock);
314 pr_crit(
"status %d\n", status);
317 if (!(status & WDC_SR_TGOOD)) {
321 if (!(status & WDC_SR_PSUOVER))
323 if (!(status & WDC_SR_PSUUNDR))
324 pr_crit(
"PSU under voltage\n");
327 pr_crit(
"Possible fan fault\n");
331 #ifdef SOFTWARE_REBOOT
335 pr_crit(
"Initiating system reboot\n");
342 spin_unlock(&wdtpci_lock);
359 size_t count, loff_t *ppos)
368 for (i = 0; i !=
count; i++) {
392 static long wdtpci_ioctl(
struct file *file,
unsigned int cmd,
404 .firmware_version = 1,
405 .identity =
"PCI-WDT500/501",
421 wdtpci_get_status(&status);
431 if (wdtpci_set_heartbeat(new_heartbeat))
454 static int wdtpci_open(
struct inode *
inode,
struct file *file)
480 static int wdtpci_release(
struct inode *inode,
struct file *file)
482 if (expect_close == 42) {
485 pr_crit(
"Unexpected close, not stopping timer!\n");
504 static ssize_t wdtpci_temp_read(
struct file *file,
char __user *buf,
505 size_t count, loff_t *
ptr)
509 if (wdtpci_get_temperature(&temperature))
526 static int wdtpci_temp_open(
struct inode *inode,
struct file *file)
539 static int wdtpci_temp_release(
struct inode *inode,
struct file *file)
572 .write = wdtpci_write,
573 .unlocked_ioctl = wdtpci_ioctl,
575 .release = wdtpci_release,
581 .fops = &wdtpci_fops,
587 .read = wdtpci_temp_read,
588 .open = wdtpci_temp_open,
589 .release = wdtpci_temp_release,
594 .name =
"temperature",
595 .fops = &wdtpci_temp_fops,
615 pr_err(
"This driver only supports one device\n");
619 if (type != 500 && type != 501) {
620 pr_err(
"unknown card type '%d'\n", type);
625 pr_err(
"Not possible to enable PCI Device\n");
630 pr_err(
"No I/O-Address for card detected\n");
636 pr_err(
"I/O address 0x%llx already in use\n",
645 "wdt_pci", &wdtpci_miscdev)) {
646 pr_err(
"IRQ %d is not free\n", irq);
650 pr_info(
"PCI-WDT500/501 (PCI-WDG-CSM) driver 0.10 at 0x%llx (Interrupt %d)\n",
651 (
unsigned long long)
io, irq);
657 pr_info(
"heartbeat value must be 0 < heartbeat < 65536, using %d\n",
663 pr_err(
"cannot register reboot notifier (err=%d)\n", ret);
670 pr_err(
"cannot register miscdev on minor=%d (err=%d)\n",
678 pr_err(
"cannot register miscdev on minor=%d (err=%d)\n",
683 pr_info(
"initialized. heartbeat=%d sec (nowayout=%d)\n",
686 pr_info(
"Fan Tachometer is %s\n",
687 tachometer ?
"Enabled" :
"Disabled");
737 .id_table = wdtpci_pci_tbl,
738 .probe = wdtpci_init_one,