31 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
33 #include <linux/module.h>
35 #include <linux/types.h>
37 #include <linux/watchdog.h>
46 #define DRV_NAME "advantechwdt"
47 #define WATCHDOG_NAME "Advantech WDT"
48 #define WATCHDOG_TIMEOUT 60
52 static unsigned long advwdt_is_open;
53 static char adv_expect_close;
66 static int wdt_stop = 0x443;
70 static int wdt_start = 0x443;
72 MODULE_PARM_DESC(wdt_start,
"Advantech WDT 'start' io port (default 0x443)");
77 "Watchdog timeout in seconds. 1<= timeout <=63, default="
83 "Watchdog cannot be stopped once started (default="
90 static void advwdt_ping(
void)
93 outb_p(timeout, wdt_start);
96 static void advwdt_disable(
void)
101 static int advwdt_set_heartbeat(
int t)
114 size_t count, loff_t *ppos)
120 adv_expect_close = 0;
122 for (i = 0; i !=
count; i++) {
127 adv_expect_close = 42;
135 static long advwdt_ioctl(
struct file *file,
unsigned int cmd,
unsigned long arg)
144 .firmware_version = 1,
181 if (advwdt_set_heartbeat(new_timeout))
193 static int advwdt_open(
struct inode *
inode,
struct file *file)
205 static int advwdt_close(
struct inode *inode,
struct file *file)
207 if (adv_expect_close == 42) {
210 pr_crit(
"Unexpected close, not stopping watchdog!\n");
214 adv_expect_close = 0;
225 .write = advwdt_write,
226 .unlocked_ioctl = advwdt_ioctl,
228 .release = advwdt_close,
234 .fops = &advwdt_fops,
245 if (wdt_stop != wdt_start) {
247 pr_err(
"I/O address 0x%04x already in use\n",
255 pr_err(
"I/O address 0x%04x already in use\n", wdt_start);
262 if (advwdt_set_heartbeat(timeout)) {
264 pr_info(
"timeout value must be 1<=x<=63, using %d\n", timeout);
269 pr_err(
"cannot register miscdev on minor=%d (err=%d)\n",
273 pr_info(
"initialized. timeout=%d sec (nowayout=%d)\n",
280 if (wdt_stop != wdt_start)
289 if (wdt_stop != wdt_start)
302 .probe = advwdt_probe,
304 .shutdown = advwdt_shutdown,
311 static int __init advwdt_init(
void)
315 pr_info(
"WDT driver for Advantech single board computer initialising\n");
321 advwdt_platform_device = platform_device_register_simple(
DRV_NAME,
323 if (IS_ERR(advwdt_platform_device)) {
324 err = PTR_ERR(advwdt_platform_device);
325 goto unreg_platform_driver;
330 unreg_platform_driver:
335 static void __exit advwdt_exit(
void)
339 pr_info(
"Watchdog Module Unloaded\n");