22 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
24 #include <linux/module.h>
26 #include <linux/types.h>
29 #include <linux/watchdog.h>
32 #include <linux/reboot.h>
35 #include <linux/pci.h>
40 #define WDT_ENABLE 0x9C
41 #define WDT_DISABLE 0x8C
43 #define ALI_7101_WDT 0x92
44 #define ALI_7101_GPIO 0x7D
45 #define ALI_7101_GPIO_O 0x7E
46 #define ALI_WDT_ARM 0x01
52 #define WDT_INTERVAL (HZ/4+1)
60 #define WATCHDOG_TIMEOUT 30
65 "Watchdog timeout in seconds. (1<=timeout<=3600, default="
71 "Use the gpio watchdog (required by old cobalt boards).");
73 static void wdt_timer_ping(
unsigned long);
75 static unsigned long next_heartbeat;
76 static unsigned long wdt_is_open;
77 static char wdt_expect_close;
78 static struct pci_dev *alim7101_pmu;
83 "Watchdog cannot be stopped once started (default="
90 static void wdt_timer_ping(
unsigned long data)
99 pci_read_config_byte(alim7101_pmu, 0x92, &tmp);
100 pci_write_config_byte(alim7101_pmu,
102 pci_write_config_byte(alim7101_pmu,
105 pci_read_config_byte(alim7101_pmu,
107 pci_write_config_byte(alim7101_pmu,
109 pci_write_config_byte(alim7101_pmu,
113 pr_warn(
"Heartbeat lost! Will not ping the watchdog\n");
129 pci_write_config_byte(alim7101_pmu,
132 pci_read_config_byte(alim7101_pmu,
134 pci_write_config_byte(alim7101_pmu,
139 pci_write_config_byte(alim7101_pmu,
142 pci_read_config_byte(alim7101_pmu,
144 pci_write_config_byte(alim7101_pmu,
150 static void wdt_startup(
void)
162 pr_info(
"Watchdog timer is now enabled\n");
165 static void wdt_turnoff(
void)
170 pr_info(
"Watchdog timer is now disabled...\n");
173 static void wdt_keepalive(
void)
184 size_t count, loff_t *ppos)
193 wdt_expect_close = 0;
196 for (ofs = 0; ofs !=
count; ofs++) {
201 wdt_expect_close = 42;
210 static int fop_open(
struct inode *
inode,
struct file *file)
220 static int fop_close(
struct inode *inode,
struct file *file)
222 if (wdt_expect_close == 42)
226 pr_crit(
"device file closed unexpectedly. Will not stop the WDT!\n");
229 wdt_expect_close = 0;
233 static long fop_ioctl(
struct file *file,
unsigned int cmd,
unsigned long arg)
240 .firmware_version = 1,
241 .identity =
"ALiM7101",
276 if (new_timeout < 1 || new_timeout > 3600)
294 .release = fop_close,
295 .unlocked_ioctl = fop_ioctl,
321 pr_info(
"Watchdog timer is now enabled with no heartbeat - should reboot in ~1 second\n");
332 .notifier_call = wdt_notify_sys,
335 static void __exit alim7101_wdt_unload(
void)
344 static int __init alim7101_wdt_init(
void)
354 pr_info(
"ALi M7101 PMU not present - WDT not set\n");
359 pci_write_config_byte(alim7101_pmu,
ALI_7101_WDT, 0x02);
363 if (!ali1543_south) {
364 pr_info(
"ALi 1543 South-Bridge not present - WDT not set\n");
367 pci_read_config_byte(ali1543_south, 0x5e, &tmp);
369 if ((tmp & 0x1e) == 0x00) {
371 pr_info(
"Detected old alim7101 revision 'a1d'. If this is a cobalt board, set the 'use_gpio' module parameter.\n");
375 }
else if ((tmp & 0x1e) != 0x12 && (tmp & 0x1e) != 0x00) {
376 pr_info(
"ALi 1543 South-Bridge does not have the correct revision number (???1001?) - WDT not set\n");
380 if (timeout < 1 || timeout > 3600) {
383 pr_info(
"timeout value must be 1 <= x <= 3600, using %d\n",
389 pr_err(
"cannot register reboot notifier (err=%d)\n", rc);
395 pr_err(
"cannot register miscdev on minor=%d (err=%d)\n",
396 wdt_miscdev.
minor, rc);
403 pr_info(
"WDT driver for ALi M7101 initialised. timeout=%d sec (nowayout=%d)\n",