35 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
38 #include <linux/module.h>
40 #include <linux/types.h>
42 #include <linux/watchdog.h>
46 #include <linux/reboot.h>
53 static unsigned long wdt_is_open;
63 static int wd_heartbeat;
66 "Watchdog heartbeat in seconds. (0 < heartbeat < 65536, default="
72 "Watchdog cannot be stopped once started (default="
76 static int io = 0x240;
87 static int tachometer;
90 "WDT501-P Fan Tachometer support (0=disable, default=0)");
92 static int type = 500;
95 "WDT501-P Card type (500 or 501, default=500)");
101 static void wdt_ctr_mode(
int ctr,
int mode)
109 static void wdt_ctr_load(
int ctr,
int val)
121 static int wdt_start(
void)
132 wdt_ctr_load(0, 8948);
133 wdt_ctr_load(1, wd_heartbeat);
134 wdt_ctr_load(2, 65535);
136 spin_unlock_irqrestore(&wdt_lock, flags);
146 static int wdt_stop(
void)
153 spin_unlock_irqrestore(&wdt_lock, flags);
164 static void wdt_ping(
void)
172 wdt_ctr_load(1, wd_heartbeat);
174 spin_unlock_irqrestore(&wdt_lock, flags);
186 static int wdt_set_heartbeat(
int t)
188 if (t < 1 || t > 65535)
192 wd_heartbeat = t * 100;
206 static int wdt_get_status(
void)
208 unsigned char new_status;
214 spin_unlock_irqrestore(&wdt_lock, flags);
242 static int wdt_get_temperature(
void)
249 spin_unlock_irqrestore(&wdt_lock, flags);
250 return (c * 11 / 15) + 7;
253 static void wdt_decode_501(
int status)
255 if (!(status & WDC_SR_TGOOD))
257 if (!(status & WDC_SR_PSUOVER))
259 if (!(status & WDC_SR_PSUUNDR))
260 pr_crit(
"PSU under voltage\n");
281 spin_lock(&wdt_lock);
284 pr_crit(
"WDT status %d\n", status);
287 wdt_decode_501(status);
290 pr_crit(
"Possible fan fault\n");
294 #ifdef SOFTWARE_REBOOT
298 pr_crit(
"Initiating system reboot\n");
305 spin_unlock(&wdt_lock);
322 size_t count, loff_t *ppos)
331 for (i = 0; i !=
count; i++) {
355 static long wdt_ioctl(
struct file *file,
unsigned int cmd,
unsigned long arg)
366 .firmware_version = 1,
367 .identity =
"WDT500/501",
383 status = wdt_get_status();
393 if (wdt_set_heartbeat(new_heartbeat))
416 static int wdt_open(
struct inode *
inode,
struct file *file)
439 static int wdt_release(
struct inode *inode,
struct file *file)
441 if (expect_close == 42) {
445 pr_crit(
"WDT device closed unexpectedly. WDT will not stop!\n");
463 static ssize_t wdt_temp_read(
struct file *file,
char __user *buf,
464 size_t count, loff_t *
ptr)
482 static int wdt_temp_open(
struct inode *inode,
struct file *file)
495 static int wdt_temp_release(
struct inode *inode,
struct file *file)
529 .unlocked_ioctl = wdt_ioctl,
531 .release = wdt_release,
543 .read = wdt_temp_read,
544 .open = wdt_temp_open,
545 .release = wdt_temp_release,
550 .name =
"temperature",
551 .fops = &wdt_temp_fops,
573 static void __exit wdt_exit(
void)
595 if (type != 500 && type != 501) {
596 pr_err(
"unknown card type '%d'\n", type);
604 pr_info(
"heartbeat value must be 0 < heartbeat < 65536, using %d\n",
609 pr_err(
"I/O address 0x%04x already in use\n", io);
616 pr_err(
"IRQ %d is not free\n", irq);
622 pr_err(
"cannot register reboot notifier (err=%d)\n", ret);
629 pr_err(
"cannot register miscdev on minor=%d (err=%d)\n",
637 pr_err(
"cannot register miscdev on minor=%d (err=%d)\n",
642 pr_info(
"WDT500/501-P driver 0.10 at 0x%04x (Interrupt %d). heartbeat=%d sec (nowayout=%d)\n",
645 pr_info(
"Fan Tachometer is %s\n",
646 tachometer ?
"Enabled" :
"Disabled");