2 * SBC EPX C3 0.1 A Hardware Watchdog Device for the Winsystems EPX-C3
3 * single board computer
5 * (c) Copyright 2006 Calin A. Culianu <calin@ajvar.org>, All Rights
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version
11 * 2 of the License, or (at your option) any later version.
13 * based on softdog.c by Alan Cox <alan@redhat.com>
16 #include <linux/module.h>
17 #include <linux/moduleparam.h>
18 #include <linux/config.h>
19 #include <linux/types.h>
20 #include <linux/kernel.h>
23 #include <linux/miscdevice.h>
24 #include <linux/watchdog.h>
25 #include <linux/notifier.h>
26 #include <linux/reboot.h>
27 #include <linux/init.h>
28 #include <asm/uaccess.h>
31 #define PFX "epx_c3: "
32 static int epx_c3_alive
;
34 #define WATCHDOG_TIMEOUT 1 /* 1 sec default timeout */
36 static int nowayout
= WATCHDOG_NOWAYOUT
;
37 module_param(nowayout
, int, 0);
38 MODULE_PARM_DESC(nowayout
, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)");
40 #define EPXC3_WATCHDOG_CTL_REG 0x1ee /* write 1 to enable, 0 to disable */
41 #define EPXC3_WATCHDOG_PET_REG 0x1ef /* write anything to pet once enabled */
43 static void epx_c3_start(void)
45 outb(1, EPXC3_WATCHDOG_CTL_REG
);
48 static void epx_c3_stop(void)
51 outb(0, EPXC3_WATCHDOG_CTL_REG
);
53 printk(KERN_INFO PFX
"Stopped watchdog timer.\n");
56 static void epx_c3_pet(void)
58 outb(1, EPXC3_WATCHDOG_PET_REG
);
62 * Allow only one person to hold it open
64 static int epx_c3_open(struct inode
*inode
, struct file
*file
)
70 __module_get(THIS_MODULE
);
77 printk(KERN_INFO
"Started watchdog timer.\n");
79 return nonseekable_open(inode
, file
);
82 static int epx_c3_release(struct inode
*inode
, struct file
*file
)
84 /* Shut off the timer.
85 * Lock it in if it's a module and we defined ...NOWAYOUT */
87 epx_c3_stop(); /* Turn the WDT off */
94 static ssize_t
epx_c3_write(struct file
*file
, const char *data
,
95 size_t len
, loff_t
*ppos
)
97 /* Refresh the timer. */
103 static int epx_c3_ioctl(struct inode
*inode
, struct file
*file
,
104 unsigned int cmd
, unsigned long arg
)
106 int options
, retval
= -EINVAL
;
107 static struct watchdog_info ident
= {
108 .options
= WDIOF_KEEPALIVEPING
|
110 .firmware_version
= 0,
111 .identity
= "Winsystems EPX-C3 H/W Watchdog",
115 case WDIOC_GETSUPPORT
:
116 if (copy_to_user((struct watchdog_info
*)arg
,
117 &ident
, sizeof(ident
)))
120 case WDIOC_GETSTATUS
:
121 case WDIOC_GETBOOTSTATUS
:
122 return put_user(0,(int *)arg
);
123 case WDIOC_KEEPALIVE
:
126 case WDIOC_GETTIMEOUT
:
127 return put_user(WATCHDOG_TIMEOUT
,(int *)arg
);
128 case WDIOC_SETOPTIONS
: {
129 if (get_user(options
, (int *)arg
))
132 if (options
& WDIOS_DISABLECARD
) {
137 if (options
& WDIOS_ENABLECARD
) {
149 static int epx_c3_notify_sys(struct notifier_block
*this, unsigned long code
,
152 if (code
== SYS_DOWN
|| code
== SYS_HALT
)
153 epx_c3_stop(); /* Turn the WDT off */
158 static struct file_operations epx_c3_fops
= {
159 .owner
= THIS_MODULE
,
161 .write
= epx_c3_write
,
162 .ioctl
= epx_c3_ioctl
,
164 .release
= epx_c3_release
,
167 static struct miscdevice epx_c3_miscdev
= {
168 .minor
= WATCHDOG_MINOR
,
170 .fops
= &epx_c3_fops
,
173 static struct notifier_block epx_c3_notifier
= {
174 .notifier_call
= epx_c3_notify_sys
,
177 static const char banner
[] __initdata
=
178 KERN_INFO PFX
"Hardware Watchdog Timer for Winsystems EPX-C3 SBC: 0.1\n";
180 static int __init
watchdog_init(void)
184 ret
= register_reboot_notifier(&epx_c3_notifier
);
186 printk(KERN_ERR PFX
"cannot register reboot notifier "
191 ret
= misc_register(&epx_c3_miscdev
);
193 printk(KERN_ERR PFX
"cannot register miscdev on minor=%d "
194 "(err=%d)\n", WATCHDOG_MINOR
, ret
);
195 unregister_reboot_notifier(&epx_c3_notifier
);
204 static void __exit
watchdog_exit(void)
206 misc_deregister(&epx_c3_miscdev
);
207 unregister_reboot_notifier(&epx_c3_notifier
);
210 module_init(watchdog_init
);
211 module_exit(watchdog_exit
);
213 MODULE_AUTHOR("Calin A. Culianu <calin@ajvar.org>");
214 MODULE_DESCRIPTION("Hardware Watchdog Device for Winsystems EPX-C3 SBC. Note that there is no way to probe for this device -- so only use it if you are *sure* you are runnning on this specific SBC system from Winsystems! It writes to IO ports 0x1ee and 0x1ef!");
215 MODULE_LICENSE("GPL");
216 MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR
);