19 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
25 #include <linux/module.h>
29 #include <linux/reboot.h>
30 #include <linux/types.h>
31 #include <linux/watchdog.h>
36 #define SBC7240_ENABLE_PORT 0x443
37 #define SBC7240_DISABLE_PORT 0x043
38 #define SBC7240_SET_TIMEOUT_PORT SBC7240_ENABLE_PORT
39 #define SBC7240_MAGIC_CHAR 'V'
41 #define SBC7240_TIMEOUT 30
42 #define SBC7240_MAX_TIMEOUT 255
53 #define SBC7240_OPEN_STATUS_BIT 0
54 #define SBC7240_ENABLED_STATUS_BIT 1
55 #define SBC7240_EXPECT_CLOSE_STATUS_BIT 2
56 static unsigned long wdt_status;
62 static void wdt_disable(
void)
67 pr_info(
"Watchdog timer is now disabled\n");
71 static void wdt_enable(
void)
76 pr_info(
"Watchdog timer is now enabled\n");
80 static int wdt_set_timeout(
int t)
83 pr_err(
"timeout value must be 1<=x<=%d\n", SBC7240_MAX_TIMEOUT);
89 pr_info(
"timeout set to %d seconds\n", t);
94 static inline void wdt_keepalive(
void)
104 size_t count, loff_t *ppos)
115 for (i = 0; i !=
count; i++) {
132 static int fop_open(
struct inode *
inode,
struct file *file)
142 static int fop_close(
struct inode *inode,
struct file *file)
148 pr_crit(
"Unexpected close, not stopping watchdog!\n");
160 .firmware_version = 1,
161 .identity =
"SBC7240",
165 static long fop_ioctl(
struct file *file,
unsigned int cmd,
unsigned long arg)
169 return copy_to_user((
void __user *)arg, &ident,
sizeof(ident))
173 return put_user(0, (
int __user *)arg);
179 if (
get_user(options, (
int __user *)arg))
201 if (
get_user(new_timeout, (
int __user *)arg))
204 if (wdt_set_timeout(new_timeout))
210 return put_user(timeout, (
int __user *)arg);
221 .release = fop_close,
222 .unlocked_ioctl = fop_ioctl,
244 .notifier_call = wdt_notify_sys,
247 static void __exit sbc7240_wdt_unload(
void)
249 pr_info(
"Removing watchdog\n");
256 static int __init sbc7240_wdt_init(
void)
261 pr_err(
"I/O address 0x%04x already in use\n",
271 if (timeout < 1 || timeout > SBC7240_MAX_TIMEOUT) {
273 pr_info(
"timeout value must be 1<=x<=%d, using %d\n",
274 SBC7240_MAX_TIMEOUT, timeout);
276 wdt_set_timeout(timeout);
281 pr_err(
"cannot register reboot notifier (err=%d)\n", rc);
287 pr_err(
"cannot register miscdev on minor=%d (err=%d)\n",
288 wdt_miscdev.
minor, rc);
289 goto err_out_reboot_notifier;
292 pr_info(
"Watchdog driver for SBC7240 initialised (nowayout=%d)\n",
297 err_out_reboot_notifier:
310 " computers EPIC Nano 7240 from iEi");