10 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
12 #include <linux/module.h>
14 #include <linux/types.h>
16 #include <linux/watchdog.h>
19 #include <linux/reboot.h>
22 #include <linux/pci.h>
26 #define WATCHDOG_NAME "ALi_M1535"
27 #define WATCHDOG_TIMEOUT 60
30 static unsigned long ali_is_open;
31 static char ali_expect_release;
33 static u32 ali_timeout_bits;
40 "Watchdog timeout in seconds. (0 < timeout < 18000, default="
46 "Watchdog cannot be stopped once started (default="
56 static void ali_start(
void)
62 pci_read_config_dword(ali_pci, 0xCC, &val);
64 val |= (1 << 25) | ali_timeout_bits;
65 pci_write_config_dword(ali_pci, 0xCC, val);
67 spin_unlock(&ali_lock);
76 static void ali_stop(
void)
82 pci_read_config_dword(ali_pci, 0xCC, &val);
85 pci_write_config_dword(ali_pci, 0xCC, val);
87 spin_unlock(&ali_lock);
96 static void ali_keepalive(
void)
108 static int ali_settimer(
int t)
113 ali_timeout_bits = t|(1 << 6);
115 ali_timeout_bits = (t / 60)|(1 << 7);
117 ali_timeout_bits = (t / 300)|(1 << 6)|(1 << 7);
142 size_t len, loff_t *ppos)
151 ali_expect_release = 0;
155 for (i = 0; i != len; i++) {
160 ali_expect_release = 42;
180 static long ali_ioctl(
struct file *file,
unsigned int cmd,
unsigned long arg)
188 .firmware_version = 0,
189 .identity =
"ALi M1535 WatchDog Timer",
223 if (ali_settimer(new_timeout))
244 static int ali_open(
struct inode *
inode,
struct file *file)
264 static int ali_release(
struct inode *inode,
struct file *file)
269 if (ali_expect_release == 42)
272 pr_crit(
"Unexpected close, not stopping watchdog!\n");
276 ali_expect_release = 0;
318 static int __init ali_find_watchdog(
void)
346 pci_read_config_dword(pdev, 0xCC, &wdog);
351 wdog &= ~((1 << 27)|(1 << 26)|(1 << 25)|(1 << 24));
353 wdog &= ~((1 << 16)|(1 << 13)|(1 << 12)|(1 << 11)|(1 << 10)|(1 << 9));
355 pci_write_config_dword(pdev, 0xCC, wdog);
368 .unlocked_ioctl = ali_ioctl,
370 .release = ali_release,
380 .notifier_call = ali_notify_sys,
390 static int __init watchdog_init(
void)
395 if (ali_find_watchdog() != 0)
400 if (timeout < 1 || timeout >= 18000) {
402 pr_info(
"timeout value must be 0 < timeout < 18000, using %d\n",
407 ali_settimer(timeout);
411 pr_err(
"cannot register reboot notifier (err=%d)\n", ret);
417 pr_err(
"cannot register miscdev on minor=%d (err=%d)\n",
422 pr_info(
"initialized. timeout=%d sec (nowayout=%d)\n",
438 static void __exit watchdog_exit(
void)