31 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
33 #include <linux/module.h>
35 #include <linux/types.h>
39 #include <linux/watchdog.h>
43 #include <linux/reboot.h>
50 #define ZF_IOBASE 0x218
57 #define ZFL_VERSION 0x02
60 #define COUNTER_1 0x0C
61 #define COUNTER_2 0x0E
62 #define PULSE_LEN 0x0F
65 #define ENABLE_WD1 0x0001
66 #define ENABLE_WD2 0x0002
67 #define RESET_WD1 0x0010
68 #define RESET_WD2 0x0020
69 #define GEN_SCI 0x0100
70 #define GEN_NMI 0x0200
71 #define GEN_SMI 0x0400
72 #define GEN_RESET 0x0800
80 #define zf_writew(port, data) { outb(port, INDEX); outw(data, DATA_W); }
81 #define zf_writeb(port, data) { outb(port, INDEX); outb(data, DATA_B); }
82 #define zf_get_ZFL_version() zf_readw(ZFL_VERSION)
85 static unsigned short zf_readw(
unsigned char port)
100 "Watchdog cannot be stopped once started (default="
103 #define PFX "machzwd"
107 .firmware_version = 1,
108 .identity =
"ZF-Logic watchdog",
123 "0 = RESET(*) 1 = SMI 2 = NMI 3 = SCI");
125 static void zf_ping(
unsigned long data);
128 static unsigned long zf_is_open;
129 static char zf_expect_close;
136 #define ZF_USER_TIMEO (HZ*10)
139 #define ZF_HW_TIMEO (HZ/2)
142 #define ZF_CTIMEOUT 0xffff
145 #define dprintk(format, args...)
147 #define dprintk(format, args...) \
148 pr_debug(":%s:%d: " format, __func__, __LINE__ , ## args)
152 static inline void zf_set_status(
unsigned char new)
160 static inline unsigned short zf_get_control(
void)
165 static inline void zf_set_control(
unsigned short new)
176 static inline void zf_set_timer(
unsigned short new,
unsigned char n)
191 static void zf_timer_off(
void)
201 ctrl_reg = zf_get_control();
204 zf_set_control(ctrl_reg);
205 spin_unlock_irqrestore(&zf_port_lock, flags);
207 pr_info(
"Watchdog timer is now disabled\n");
214 static void zf_timer_on(
void)
232 ctrl_reg = zf_get_control();
234 zf_set_control(ctrl_reg);
235 spin_unlock_irqrestore(&zf_port_lock, flags);
237 pr_info(
"Watchdog timer is now enabled\n");
241 static void zf_ping(
unsigned long data)
249 dprintk(
"time_before: %ld\n", next_heartbeat - jiffies);
256 ctrl_reg = zf_get_control();
258 zf_set_control(ctrl_reg);
262 zf_set_control(ctrl_reg);
263 spin_unlock_irqrestore(&zf_port_lock, flags);
267 pr_crit(
"I will reset your machine\n");
288 for (ofs = 0; ofs !=
count; ofs++) {
293 zf_expect_close = 42;
294 dprintk(
"zf_expect_close = 42\n");
304 dprintk(
"user ping at %ld\n", jiffies);
309 static long zf_ioctl(
struct file *file,
unsigned int cmd,
unsigned long arg)
330 static int zf_open(
struct inode *
inode,
struct file *file)
340 static int zf_close(
struct inode *inode,
struct file *file)
342 if (zf_expect_close == 42)
346 pr_err(
"device file closed unexpectedly. Will not stop the WDT!\n");
369 .unlocked_ioctl = zf_ioctl,
386 .notifier_call = zf_notify_sys,
389 static void __init zf_show_action(
int act)
391 static const char *
const str[] = {
"RESET",
"SMI",
"NMI",
"SCI" };
393 pr_info(
"Watchdog using action = %s\n", str[act]);
396 static int __init zf_init(
void)
400 pr_info(
"MachZ ZF-Logic Watchdog driver initializing\n");
403 if (!ret || ret == 0xffff) {
404 pr_warn(
"no ZF-Logic found\n");
409 zf_action = zf_action >>
action;
413 zf_show_action(action);
423 pr_err(
"can't register reboot notifier (err=%d)\n", ret);
447 static void __exit zf_exit(
void)