Loading drivers/watchdog/wafer5823wdt.c +46 −34 Original line number Original line Diff line number Diff line Loading @@ -36,8 +36,8 @@ #include <linux/reboot.h> #include <linux/reboot.h> #include <linux/init.h> #include <linux/init.h> #include <linux/spinlock.h> #include <linux/spinlock.h> #include <asm/io.h> #include <linux/io.h> #include <asm/uaccess.h> #include <linux/uaccess.h> #define WATCHDOG_NAME "Wafer 5823 WDT" #define WATCHDOG_NAME "Wafer 5823 WDT" #define PFX WATCHDOG_NAME ": " #define PFX WATCHDOG_NAME ": " Loading @@ -61,11 +61,15 @@ static int wdt_start = 0x443; static int timeout = WD_TIMO; /* in seconds */ static int timeout = WD_TIMO; /* in seconds */ module_param(timeout, int, 0); module_param(timeout, int, 0); MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds. 1<= timeout <=255, default=" __MODULE_STRING(WD_TIMO) "."); MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds. 1 <= timeout <= 255, default=" __MODULE_STRING(WD_TIMO) "."); static int nowayout = WATCHDOG_NOWAYOUT; static int nowayout = WATCHDOG_NOWAYOUT; module_param(nowayout, int, 0); module_param(nowayout, int, 0); MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); static void wafwdt_ping(void) static void wafwdt_ping(void) { { Loading @@ -90,7 +94,8 @@ wafwdt_stop(void) inb_p(wdt_stop); inb_p(wdt_stop); } } static ssize_t wafwdt_write(struct file *file, const char __user *buf, size_t count, loff_t * ppos) static ssize_t wafwdt_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos) { { /* See if we got the magic character 'V' and reload the timer */ /* See if we got the magic character 'V' and reload the timer */ if (count) { if (count) { Loading @@ -100,7 +105,8 @@ static ssize_t wafwdt_write(struct file *file, const char __user *buf, size_t co /* In case it was set long ago */ /* In case it was set long ago */ expect_close = 0; expect_close = 0; /* scan to see whether or not we got the magic character */ /* scan to see whether or not we got the magic character */ for (i = 0; i != count; i++) { for (i = 0; i != count; i++) { char c; char c; if (get_user(c, buf + i)) if (get_user(c, buf + i)) Loading @@ -109,20 +115,22 @@ static ssize_t wafwdt_write(struct file *file, const char __user *buf, size_t co expect_close = 42; expect_close = 42; } } } } /* Well, anyhow someone wrote to us, we should return that favour */ /* Well, anyhow someone wrote to us, we should return that favour */ wafwdt_ping(); wafwdt_ping(); } } return count; return count; } } static int wafwdt_ioctl(struct inode *inode, struct file *file, unsigned int cmd, static long wafwdt_ioctl(struct file *file, unsigned int cmd, unsigned long arg) unsigned long arg) { { int new_timeout; int new_timeout; void __user *argp = (void __user *)arg; void __user *argp = (void __user *)arg; int __user *p = argp; int __user *p = argp; static struct watchdog_info ident = { static const struct watchdog_info ident = { .options = WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT | WDIOF_MAGICCLOSE, .options = WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT | WDIOF_MAGICCLOSE, .firmware_version = 1, .firmware_version = 1, .identity = "Wafer 5823 WDT", .identity = "Wafer 5823 WDT", }; }; Loading Loading @@ -194,10 +202,11 @@ static int wafwdt_open(struct inode *inode, struct file *file) static int static int wafwdt_close(struct inode *inode, struct file *file) wafwdt_close(struct inode *inode, struct file *file) { { if (expect_close == 42) { if (expect_close == 42) wafwdt_stop(); wafwdt_stop(); } else { else { printk(KERN_CRIT PFX "WDT device closed unexpectedly. WDT will not stop!\n"); printk(KERN_CRIT PFX "WDT device closed unexpectedly. WDT will not stop!\n"); wafwdt_ping(); wafwdt_ping(); } } clear_bit(0, &wafwdt_is_open); clear_bit(0, &wafwdt_is_open); Loading @@ -209,12 +218,11 @@ wafwdt_close(struct inode *inode, struct file *file) * Notifier for system down * Notifier for system down */ */ static int wafwdt_notify_sys(struct notifier_block *this, unsigned long code, void *unused) static int wafwdt_notify_sys(struct notifier_block *this, unsigned long code, void *unused) { { if (code == SYS_DOWN || code == SYS_HALT) { if (code == SYS_DOWN || code == SYS_HALT) /* Turn the WDT off */ wafwdt_stop(); wafwdt_stop(); } return NOTIFY_DONE; return NOTIFY_DONE; } } Loading @@ -226,7 +234,7 @@ static const struct file_operations wafwdt_fops = { .owner = THIS_MODULE, .owner = THIS_MODULE, .llseek = no_llseek, .llseek = no_llseek, .write = wafwdt_write, .write = wafwdt_write, .ioctl = wafwdt_ioctl, .unlocked_ioctl = wafwdt_ioctl, .open = wafwdt_open, .open = wafwdt_open, .release = wafwdt_close, .release = wafwdt_close, }; }; Loading @@ -250,17 +258,20 @@ static int __init wafwdt_init(void) { { int ret; int ret; printk(KERN_INFO "WDT driver for Wafer 5823 single board computer initialising.\n"); printk(KERN_INFO "WDT driver for Wafer 5823 single board computer initialising.\n"); if (timeout < 1 || timeout > 255) { if (timeout < 1 || timeout > 255) { timeout = WD_TIMO; timeout = WD_TIMO; printk (KERN_INFO PFX "timeout value must be 1<=x<=255, using %d\n", printk(KERN_INFO PFX "timeout value must be 1 <= x <= 255, using %d\n", timeout); timeout); } } if (wdt_stop != wdt_start) { if (wdt_stop != wdt_start) { if (!request_region(wdt_stop, 1, "Wafer 5823 WDT")) { if (!request_region(wdt_stop, 1, "Wafer 5823 WDT")) { printk (KERN_ERR PFX "I/O address 0x%04x already in use\n", printk(KERN_ERR PFX "I/O address 0x%04x already in use\n", wdt_stop); wdt_stop); ret = -EIO; ret = -EIO; goto error; goto error; Loading @@ -276,14 +287,15 @@ static int __init wafwdt_init(void) ret = register_reboot_notifier(&wafwdt_notifier); ret = register_reboot_notifier(&wafwdt_notifier); if (ret != 0) { if (ret != 0) { printk (KERN_ERR PFX "cannot register reboot notifier (err=%d)\n", printk(KERN_ERR PFX ret); "cannot register reboot notifier (err=%d)\n", ret); goto error3; goto error3; } } ret = misc_register(&wafwdt_miscdev); ret = misc_register(&wafwdt_miscdev); if (ret != 0) { if (ret != 0) { printk (KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n", printk(KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n", WATCHDOG_MINOR, ret); WATCHDOG_MINOR, ret); goto error4; goto error4; } } Loading Loading
drivers/watchdog/wafer5823wdt.c +46 −34 Original line number Original line Diff line number Diff line Loading @@ -36,8 +36,8 @@ #include <linux/reboot.h> #include <linux/reboot.h> #include <linux/init.h> #include <linux/init.h> #include <linux/spinlock.h> #include <linux/spinlock.h> #include <asm/io.h> #include <linux/io.h> #include <asm/uaccess.h> #include <linux/uaccess.h> #define WATCHDOG_NAME "Wafer 5823 WDT" #define WATCHDOG_NAME "Wafer 5823 WDT" #define PFX WATCHDOG_NAME ": " #define PFX WATCHDOG_NAME ": " Loading @@ -61,11 +61,15 @@ static int wdt_start = 0x443; static int timeout = WD_TIMO; /* in seconds */ static int timeout = WD_TIMO; /* in seconds */ module_param(timeout, int, 0); module_param(timeout, int, 0); MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds. 1<= timeout <=255, default=" __MODULE_STRING(WD_TIMO) "."); MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds. 1 <= timeout <= 255, default=" __MODULE_STRING(WD_TIMO) "."); static int nowayout = WATCHDOG_NOWAYOUT; static int nowayout = WATCHDOG_NOWAYOUT; module_param(nowayout, int, 0); module_param(nowayout, int, 0); MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); static void wafwdt_ping(void) static void wafwdt_ping(void) { { Loading @@ -90,7 +94,8 @@ wafwdt_stop(void) inb_p(wdt_stop); inb_p(wdt_stop); } } static ssize_t wafwdt_write(struct file *file, const char __user *buf, size_t count, loff_t * ppos) static ssize_t wafwdt_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos) { { /* See if we got the magic character 'V' and reload the timer */ /* See if we got the magic character 'V' and reload the timer */ if (count) { if (count) { Loading @@ -100,7 +105,8 @@ static ssize_t wafwdt_write(struct file *file, const char __user *buf, size_t co /* In case it was set long ago */ /* In case it was set long ago */ expect_close = 0; expect_close = 0; /* scan to see whether or not we got the magic character */ /* scan to see whether or not we got the magic character */ for (i = 0; i != count; i++) { for (i = 0; i != count; i++) { char c; char c; if (get_user(c, buf + i)) if (get_user(c, buf + i)) Loading @@ -109,20 +115,22 @@ static ssize_t wafwdt_write(struct file *file, const char __user *buf, size_t co expect_close = 42; expect_close = 42; } } } } /* Well, anyhow someone wrote to us, we should return that favour */ /* Well, anyhow someone wrote to us, we should return that favour */ wafwdt_ping(); wafwdt_ping(); } } return count; return count; } } static int wafwdt_ioctl(struct inode *inode, struct file *file, unsigned int cmd, static long wafwdt_ioctl(struct file *file, unsigned int cmd, unsigned long arg) unsigned long arg) { { int new_timeout; int new_timeout; void __user *argp = (void __user *)arg; void __user *argp = (void __user *)arg; int __user *p = argp; int __user *p = argp; static struct watchdog_info ident = { static const struct watchdog_info ident = { .options = WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT | WDIOF_MAGICCLOSE, .options = WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT | WDIOF_MAGICCLOSE, .firmware_version = 1, .firmware_version = 1, .identity = "Wafer 5823 WDT", .identity = "Wafer 5823 WDT", }; }; Loading Loading @@ -194,10 +202,11 @@ static int wafwdt_open(struct inode *inode, struct file *file) static int static int wafwdt_close(struct inode *inode, struct file *file) wafwdt_close(struct inode *inode, struct file *file) { { if (expect_close == 42) { if (expect_close == 42) wafwdt_stop(); wafwdt_stop(); } else { else { printk(KERN_CRIT PFX "WDT device closed unexpectedly. WDT will not stop!\n"); printk(KERN_CRIT PFX "WDT device closed unexpectedly. WDT will not stop!\n"); wafwdt_ping(); wafwdt_ping(); } } clear_bit(0, &wafwdt_is_open); clear_bit(0, &wafwdt_is_open); Loading @@ -209,12 +218,11 @@ wafwdt_close(struct inode *inode, struct file *file) * Notifier for system down * Notifier for system down */ */ static int wafwdt_notify_sys(struct notifier_block *this, unsigned long code, void *unused) static int wafwdt_notify_sys(struct notifier_block *this, unsigned long code, void *unused) { { if (code == SYS_DOWN || code == SYS_HALT) { if (code == SYS_DOWN || code == SYS_HALT) /* Turn the WDT off */ wafwdt_stop(); wafwdt_stop(); } return NOTIFY_DONE; return NOTIFY_DONE; } } Loading @@ -226,7 +234,7 @@ static const struct file_operations wafwdt_fops = { .owner = THIS_MODULE, .owner = THIS_MODULE, .llseek = no_llseek, .llseek = no_llseek, .write = wafwdt_write, .write = wafwdt_write, .ioctl = wafwdt_ioctl, .unlocked_ioctl = wafwdt_ioctl, .open = wafwdt_open, .open = wafwdt_open, .release = wafwdt_close, .release = wafwdt_close, }; }; Loading @@ -250,17 +258,20 @@ static int __init wafwdt_init(void) { { int ret; int ret; printk(KERN_INFO "WDT driver for Wafer 5823 single board computer initialising.\n"); printk(KERN_INFO "WDT driver for Wafer 5823 single board computer initialising.\n"); if (timeout < 1 || timeout > 255) { if (timeout < 1 || timeout > 255) { timeout = WD_TIMO; timeout = WD_TIMO; printk (KERN_INFO PFX "timeout value must be 1<=x<=255, using %d\n", printk(KERN_INFO PFX "timeout value must be 1 <= x <= 255, using %d\n", timeout); timeout); } } if (wdt_stop != wdt_start) { if (wdt_stop != wdt_start) { if (!request_region(wdt_stop, 1, "Wafer 5823 WDT")) { if (!request_region(wdt_stop, 1, "Wafer 5823 WDT")) { printk (KERN_ERR PFX "I/O address 0x%04x already in use\n", printk(KERN_ERR PFX "I/O address 0x%04x already in use\n", wdt_stop); wdt_stop); ret = -EIO; ret = -EIO; goto error; goto error; Loading @@ -276,14 +287,15 @@ static int __init wafwdt_init(void) ret = register_reboot_notifier(&wafwdt_notifier); ret = register_reboot_notifier(&wafwdt_notifier); if (ret != 0) { if (ret != 0) { printk (KERN_ERR PFX "cannot register reboot notifier (err=%d)\n", printk(KERN_ERR PFX ret); "cannot register reboot notifier (err=%d)\n", ret); goto error3; goto error3; } } ret = misc_register(&wafwdt_miscdev); ret = misc_register(&wafwdt_miscdev); if (ret != 0) { if (ret != 0) { printk (KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n", printk(KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n", WATCHDOG_MINOR, ret); WATCHDOG_MINOR, ret); goto error4; goto error4; } } Loading