Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * W83877F Computer Watchdog Timer driver |
| 3 | * |
| 4 | * Based on acquirewdt.c by Alan Cox, |
| 5 | * and sbc60xxwdt.c by Jakob Oestergaard <jakob@unthought.net> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License |
| 9 | * as published by the Free Software Foundation; either version |
| 10 | * 2 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | * The authors do NOT admit liability nor provide warranty for |
| 13 | * any of this software. This material is provided "AS-IS" in |
| 14 | * the hope that it may be useful for others. |
| 15 | * |
| 16 | * (c) Copyright 2001 Scott Jennings <linuxdrivers@oro.net> |
| 17 | * |
| 18 | * 4/19 - 2001 [Initial revision] |
| 19 | * 9/27 - 2001 Added spinlocking |
| 20 | * 4/12 - 2002 [rob@osinvestor.com] Eliminate extra comments |
| 21 | * Eliminate fop_read |
| 22 | * Eliminate extra spin_unlock |
| 23 | * Added KERN_* tags to printks |
| 24 | * add CONFIG_WATCHDOG_NOWAYOUT support |
| 25 | * fix possible wdt_is_open race |
Alan Cox | c1cfd1a | 2008-05-19 14:09:29 +0100 | [diff] [blame] | 26 | * changed watchdog_info to correctly reflect what |
| 27 | * the driver offers |
| 28 | * added WDIOC_GETSTATUS, WDIOC_GETBOOTSTATUS, |
| 29 | * WDIOC_SETTIMEOUT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | * WDIOC_GETTIMEOUT, and WDIOC_SETOPTIONS ioctls |
| 31 | * 09/8 - 2003 [wim@iguana.be] cleanup of trailing spaces |
| 32 | * added extra printk's for startup problems |
| 33 | * use module_param |
Alan Cox | c1cfd1a | 2008-05-19 14:09:29 +0100 | [diff] [blame] | 34 | * made timeout (the emulated heartbeat) a |
| 35 | * module_param |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | * made the keepalive ping an internal subroutine |
| 37 | * |
| 38 | * This WDT driver is different from most other Linux WDT |
| 39 | * drivers in that the driver will ping the watchdog by itself, |
| 40 | * because this particular WDT has a very short timeout (1.6 |
| 41 | * seconds) and it would be insane to count on any userspace |
| 42 | * daemon always getting scheduled within that time frame. |
| 43 | */ |
| 44 | |
Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 45 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 46 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | #include <linux/module.h> |
| 48 | #include <linux/moduleparam.h> |
| 49 | #include <linux/types.h> |
| 50 | #include <linux/timer.h> |
| 51 | #include <linux/jiffies.h> |
| 52 | #include <linux/miscdevice.h> |
| 53 | #include <linux/watchdog.h> |
| 54 | #include <linux/fs.h> |
| 55 | #include <linux/ioport.h> |
| 56 | #include <linux/notifier.h> |
| 57 | #include <linux/reboot.h> |
| 58 | #include <linux/init.h> |
Alan Cox | c1cfd1a | 2008-05-19 14:09:29 +0100 | [diff] [blame] | 59 | #include <linux/io.h> |
| 60 | #include <linux/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | |
| 62 | #define OUR_NAME "w83877f_wdt" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | |
| 64 | #define ENABLE_W83877F_PORT 0x3F0 |
| 65 | #define ENABLE_W83877F 0x87 |
| 66 | #define DISABLE_W83877F 0xAA |
| 67 | #define WDT_PING 0x443 |
| 68 | #define WDT_REGISTER 0x14 |
| 69 | #define WDT_ENABLE 0x9C |
| 70 | #define WDT_DISABLE 0x8C |
| 71 | |
| 72 | /* |
| 73 | * The W83877F seems to be fixed at 1.6s timeout (at least on the |
| 74 | * EMACS PC-104 board I'm using). If we reset the watchdog every |
| 75 | * ~250ms we should be safe. */ |
| 76 | |
| 77 | #define WDT_INTERVAL (HZ/4+1) |
| 78 | |
| 79 | /* |
| 80 | * We must not require too good response from the userspace daemon. |
| 81 | * Here we require the userspace daemon to send us a heartbeat |
| 82 | * char to /dev/watchdog every 30 seconds. |
| 83 | */ |
| 84 | |
| 85 | #define WATCHDOG_TIMEOUT 30 /* 30 sec default timeout */ |
Alan Cox | c1cfd1a | 2008-05-19 14:09:29 +0100 | [diff] [blame] | 86 | /* in seconds, will be multiplied by HZ to get seconds to wait for a ping */ |
| 87 | static int timeout = WATCHDOG_TIMEOUT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | module_param(timeout, int, 0); |
Alan Cox | c1cfd1a | 2008-05-19 14:09:29 +0100 | [diff] [blame] | 89 | MODULE_PARM_DESC(timeout, |
| 90 | "Watchdog timeout in seconds. (1<=timeout<=3600, default=" |
| 91 | __MODULE_STRING(WATCHDOG_TIMEOUT) ")"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | |
| 93 | |
Wim Van Sebroeck | 86a1e18 | 2012-03-05 16:51:11 +0100 | [diff] [blame] | 94 | static bool nowayout = WATCHDOG_NOWAYOUT; |
| 95 | module_param(nowayout, bool, 0); |
Alan Cox | c1cfd1a | 2008-05-19 14:09:29 +0100 | [diff] [blame] | 96 | MODULE_PARM_DESC(nowayout, |
| 97 | "Watchdog cannot be stopped once started (default=" |
| 98 | __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | |
| 100 | static void wdt_timer_ping(unsigned long); |
Jiri Slaby | 82eb7c5 | 2007-02-08 18:39:36 +0100 | [diff] [blame] | 101 | static DEFINE_TIMER(timer, wdt_timer_ping, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | static unsigned long next_heartbeat; |
| 103 | static unsigned long wdt_is_open; |
| 104 | static char wdt_expect_close; |
Alexey Dobriyan | c7dfd0c | 2007-11-01 16:27:08 -0700 | [diff] [blame] | 105 | static DEFINE_SPINLOCK(wdt_spinlock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | |
| 107 | /* |
| 108 | * Whack the dog |
| 109 | */ |
| 110 | |
| 111 | static void wdt_timer_ping(unsigned long data) |
| 112 | { |
| 113 | /* If we got a heartbeat pulse within the WDT_US_INTERVAL |
| 114 | * we agree to ping the WDT |
| 115 | */ |
Alan Cox | c1cfd1a | 2008-05-19 14:09:29 +0100 | [diff] [blame] | 116 | if (time_before(jiffies, next_heartbeat)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | /* Ping the WDT */ |
| 118 | spin_lock(&wdt_spinlock); |
| 119 | |
| 120 | /* Ping the WDT by reading from WDT_PING */ |
| 121 | inb_p(WDT_PING); |
| 122 | |
| 123 | /* Re-set the timer interval */ |
Jiri Slaby | 82eb7c5 | 2007-02-08 18:39:36 +0100 | [diff] [blame] | 124 | mod_timer(&timer, jiffies + WDT_INTERVAL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | |
| 126 | spin_unlock(&wdt_spinlock); |
| 127 | |
Alan Cox | c1cfd1a | 2008-05-19 14:09:29 +0100 | [diff] [blame] | 128 | } else |
Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 129 | pr_warn("Heartbeat lost! Will not ping the watchdog\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | /* |
| 133 | * Utility routines |
| 134 | */ |
| 135 | |
| 136 | static void wdt_change(int writeval) |
| 137 | { |
| 138 | unsigned long flags; |
| 139 | spin_lock_irqsave(&wdt_spinlock, flags); |
| 140 | |
| 141 | /* buy some time */ |
| 142 | inb_p(WDT_PING); |
| 143 | |
| 144 | /* make W83877F available */ |
| 145 | outb_p(ENABLE_W83877F, ENABLE_W83877F_PORT); |
| 146 | outb_p(ENABLE_W83877F, ENABLE_W83877F_PORT); |
| 147 | |
| 148 | /* enable watchdog */ |
| 149 | outb_p(WDT_REGISTER, ENABLE_W83877F_PORT); |
| 150 | outb_p(writeval, ENABLE_W83877F_PORT+1); |
| 151 | |
| 152 | /* lock the W8387FF away */ |
| 153 | outb_p(DISABLE_W83877F, ENABLE_W83877F_PORT); |
| 154 | |
| 155 | spin_unlock_irqrestore(&wdt_spinlock, flags); |
| 156 | } |
| 157 | |
| 158 | static void wdt_startup(void) |
| 159 | { |
| 160 | next_heartbeat = jiffies + (timeout * HZ); |
| 161 | |
| 162 | /* Start the timer */ |
Jiri Slaby | 82eb7c5 | 2007-02-08 18:39:36 +0100 | [diff] [blame] | 163 | mod_timer(&timer, jiffies + WDT_INTERVAL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | |
| 165 | wdt_change(WDT_ENABLE); |
| 166 | |
Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 167 | pr_info("Watchdog timer is now enabled\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | static void wdt_turnoff(void) |
| 171 | { |
| 172 | /* Stop the timer */ |
| 173 | del_timer(&timer); |
| 174 | |
| 175 | wdt_change(WDT_DISABLE); |
| 176 | |
Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 177 | pr_info("Watchdog timer is now disabled...\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | static void wdt_keepalive(void) |
| 181 | { |
| 182 | /* user land ping */ |
| 183 | next_heartbeat = jiffies + (timeout * HZ); |
| 184 | } |
| 185 | |
| 186 | /* |
| 187 | * /dev/watchdog handling |
| 188 | */ |
| 189 | |
Alan Cox | c1cfd1a | 2008-05-19 14:09:29 +0100 | [diff] [blame] | 190 | static ssize_t fop_write(struct file *file, const char __user *buf, |
| 191 | size_t count, loff_t *ppos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | { |
| 193 | /* See if we got the magic character 'V' and reload the timer */ |
Alan Cox | c1cfd1a | 2008-05-19 14:09:29 +0100 | [diff] [blame] | 194 | if (count) { |
| 195 | if (!nowayout) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | size_t ofs; |
| 197 | |
Alan Cox | c1cfd1a | 2008-05-19 14:09:29 +0100 | [diff] [blame] | 198 | /* note: just in case someone wrote the magic |
| 199 | character five months ago... */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | wdt_expect_close = 0; |
| 201 | |
Alan Cox | c1cfd1a | 2008-05-19 14:09:29 +0100 | [diff] [blame] | 202 | /* scan to see whether or not we got the |
| 203 | magic character */ |
| 204 | for (ofs = 0; ofs != count; ofs++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | char c; |
| 206 | if (get_user(c, buf + ofs)) |
| 207 | return -EFAULT; |
| 208 | if (c == 'V') |
| 209 | wdt_expect_close = 42; |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | /* someone wrote to us, we should restart timer */ |
| 214 | wdt_keepalive(); |
| 215 | } |
| 216 | return count; |
| 217 | } |
| 218 | |
Alan Cox | c1cfd1a | 2008-05-19 14:09:29 +0100 | [diff] [blame] | 219 | static int fop_open(struct inode *inode, struct file *file) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | { |
| 221 | /* Just in case we're already talking to someone... */ |
Alan Cox | c1cfd1a | 2008-05-19 14:09:29 +0100 | [diff] [blame] | 222 | if (test_and_set_bit(0, &wdt_is_open)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | return -EBUSY; |
| 224 | |
| 225 | /* Good, fire up the show */ |
| 226 | wdt_startup(); |
| 227 | return nonseekable_open(inode, file); |
| 228 | } |
| 229 | |
Alan Cox | c1cfd1a | 2008-05-19 14:09:29 +0100 | [diff] [blame] | 230 | static int fop_close(struct inode *inode, struct file *file) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | { |
Alan Cox | c1cfd1a | 2008-05-19 14:09:29 +0100 | [diff] [blame] | 232 | if (wdt_expect_close == 42) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | wdt_turnoff(); |
| 234 | else { |
| 235 | del_timer(&timer); |
Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 236 | pr_crit("device file closed unexpectedly. Will not stop the WDT!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | } |
| 238 | clear_bit(0, &wdt_is_open); |
| 239 | wdt_expect_close = 0; |
| 240 | return 0; |
| 241 | } |
| 242 | |
Alan Cox | c1cfd1a | 2008-05-19 14:09:29 +0100 | [diff] [blame] | 243 | static long fop_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | { |
| 245 | void __user *argp = (void __user *)arg; |
| 246 | int __user *p = argp; |
Alan Cox | c1cfd1a | 2008-05-19 14:09:29 +0100 | [diff] [blame] | 247 | static const struct watchdog_info ident = { |
| 248 | .options = WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT |
| 249 | | WDIOF_MAGICCLOSE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | .firmware_version = 1, |
| 251 | .identity = "W83877F", |
| 252 | }; |
| 253 | |
Alan Cox | c1cfd1a | 2008-05-19 14:09:29 +0100 | [diff] [blame] | 254 | switch (cmd) { |
Alan Cox | c1cfd1a | 2008-05-19 14:09:29 +0100 | [diff] [blame] | 255 | case WDIOC_GETSUPPORT: |
| 256 | return copy_to_user(argp, &ident, sizeof(ident)) ? -EFAULT : 0; |
| 257 | case WDIOC_GETSTATUS: |
| 258 | case WDIOC_GETBOOTSTATUS: |
| 259 | return put_user(0, p); |
Alan Cox | c1cfd1a | 2008-05-19 14:09:29 +0100 | [diff] [blame] | 260 | case WDIOC_SETOPTIONS: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | { |
Alan Cox | c1cfd1a | 2008-05-19 14:09:29 +0100 | [diff] [blame] | 262 | int new_options, retval = -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | |
Alan Cox | c1cfd1a | 2008-05-19 14:09:29 +0100 | [diff] [blame] | 264 | if (get_user(new_options, p)) |
| 265 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | |
Alan Cox | c1cfd1a | 2008-05-19 14:09:29 +0100 | [diff] [blame] | 267 | if (new_options & WDIOS_DISABLECARD) { |
| 268 | wdt_turnoff(); |
| 269 | retval = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | |
Alan Cox | c1cfd1a | 2008-05-19 14:09:29 +0100 | [diff] [blame] | 272 | if (new_options & WDIOS_ENABLECARD) { |
| 273 | wdt_startup(); |
| 274 | retval = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | } |
Alan Cox | c1cfd1a | 2008-05-19 14:09:29 +0100 | [diff] [blame] | 276 | |
| 277 | return retval; |
| 278 | } |
Wim Van Sebroeck | 0c06090 | 2008-07-18 11:41:17 +0000 | [diff] [blame] | 279 | case WDIOC_KEEPALIVE: |
| 280 | wdt_keepalive(); |
| 281 | return 0; |
Alan Cox | c1cfd1a | 2008-05-19 14:09:29 +0100 | [diff] [blame] | 282 | case WDIOC_SETTIMEOUT: |
| 283 | { |
| 284 | int new_timeout; |
| 285 | |
| 286 | if (get_user(new_timeout, p)) |
| 287 | return -EFAULT; |
| 288 | |
| 289 | /* arbitrary upper limit */ |
| 290 | if (new_timeout < 1 || new_timeout > 3600) |
| 291 | return -EINVAL; |
| 292 | |
| 293 | timeout = new_timeout; |
| 294 | wdt_keepalive(); |
| 295 | /* Fall through */ |
| 296 | } |
| 297 | case WDIOC_GETTIMEOUT: |
| 298 | return put_user(timeout, p); |
Wim Van Sebroeck | 0c06090 | 2008-07-18 11:41:17 +0000 | [diff] [blame] | 299 | default: |
| 300 | return -ENOTTY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | } |
| 302 | } |
| 303 | |
Arjan van de Ven | 62322d2 | 2006-07-03 00:24:21 -0700 | [diff] [blame] | 304 | static const struct file_operations wdt_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | .owner = THIS_MODULE, |
| 306 | .llseek = no_llseek, |
| 307 | .write = fop_write, |
| 308 | .open = fop_open, |
| 309 | .release = fop_close, |
Alan Cox | c1cfd1a | 2008-05-19 14:09:29 +0100 | [diff] [blame] | 310 | .unlocked_ioctl = fop_ioctl, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | }; |
| 312 | |
| 313 | static struct miscdevice wdt_miscdev = { |
| 314 | .minor = WATCHDOG_MINOR, |
| 315 | .name = "watchdog", |
| 316 | .fops = &wdt_fops, |
| 317 | }; |
| 318 | |
| 319 | /* |
| 320 | * Notifier for system down |
| 321 | */ |
| 322 | |
| 323 | static int wdt_notify_sys(struct notifier_block *this, unsigned long code, |
| 324 | void *unused) |
| 325 | { |
Alan Cox | c1cfd1a | 2008-05-19 14:09:29 +0100 | [diff] [blame] | 326 | if (code == SYS_DOWN || code == SYS_HALT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | wdt_turnoff(); |
| 328 | return NOTIFY_DONE; |
| 329 | } |
| 330 | |
| 331 | /* |
| 332 | * The WDT needs to learn about soft shutdowns in order to |
| 333 | * turn the timebomb registers off. |
| 334 | */ |
| 335 | |
Alan Cox | c1cfd1a | 2008-05-19 14:09:29 +0100 | [diff] [blame] | 336 | static struct notifier_block wdt_notifier = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | .notifier_call = wdt_notify_sys, |
| 338 | }; |
| 339 | |
| 340 | static void __exit w83877f_wdt_unload(void) |
| 341 | { |
| 342 | wdt_turnoff(); |
| 343 | |
| 344 | /* Deregister */ |
| 345 | misc_deregister(&wdt_miscdev); |
| 346 | |
| 347 | unregister_reboot_notifier(&wdt_notifier); |
Alan Cox | c1cfd1a | 2008-05-19 14:09:29 +0100 | [diff] [blame] | 348 | release_region(WDT_PING, 1); |
| 349 | release_region(ENABLE_W83877F_PORT, 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | static int __init w83877f_wdt_init(void) |
| 353 | { |
| 354 | int rc = -EBUSY; |
| 355 | |
Alan Cox | c1cfd1a | 2008-05-19 14:09:29 +0100 | [diff] [blame] | 356 | if (timeout < 1 || timeout > 3600) { /* arbitrary upper limit */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | timeout = WATCHDOG_TIMEOUT; |
Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 358 | pr_info("timeout value must be 1 <= x <= 3600, using %d\n", |
| 359 | timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | } |
| 361 | |
Alan Cox | c1cfd1a | 2008-05-19 14:09:29 +0100 | [diff] [blame] | 362 | if (!request_region(ENABLE_W83877F_PORT, 2, "W83877F WDT")) { |
Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 363 | pr_err("I/O address 0x%04x already in use\n", |
| 364 | ENABLE_W83877F_PORT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | rc = -EIO; |
| 366 | goto err_out; |
| 367 | } |
| 368 | |
Alan Cox | c1cfd1a | 2008-05-19 14:09:29 +0100 | [diff] [blame] | 369 | if (!request_region(WDT_PING, 1, "W8387FF WDT")) { |
Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 370 | pr_err("I/O address 0x%04x already in use\n", WDT_PING); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | rc = -EIO; |
| 372 | goto err_out_region1; |
| 373 | } |
| 374 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | rc = register_reboot_notifier(&wdt_notifier); |
Alan Cox | c1cfd1a | 2008-05-19 14:09:29 +0100 | [diff] [blame] | 376 | if (rc) { |
Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 377 | pr_err("cannot register reboot notifier (err=%d)\n", rc); |
Wim Van Sebroeck | c6cb13a | 2007-12-26 20:32:51 +0000 | [diff] [blame] | 378 | goto err_out_region2; |
| 379 | } |
| 380 | |
| 381 | rc = misc_register(&wdt_miscdev); |
Alan Cox | c1cfd1a | 2008-05-19 14:09:29 +0100 | [diff] [blame] | 382 | if (rc) { |
Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 383 | pr_err("cannot register miscdev on minor=%d (err=%d)\n", |
| 384 | wdt_miscdev.minor, rc); |
Wim Van Sebroeck | c6cb13a | 2007-12-26 20:32:51 +0000 | [diff] [blame] | 385 | goto err_out_reboot; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | } |
| 387 | |
Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 388 | pr_info("WDT driver for W83877F initialised. timeout=%d sec (nowayout=%d)\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | timeout, nowayout); |
| 390 | |
| 391 | return 0; |
| 392 | |
Wim Van Sebroeck | c6cb13a | 2007-12-26 20:32:51 +0000 | [diff] [blame] | 393 | err_out_reboot: |
| 394 | unregister_reboot_notifier(&wdt_notifier); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | err_out_region2: |
Alan Cox | c1cfd1a | 2008-05-19 14:09:29 +0100 | [diff] [blame] | 396 | release_region(WDT_PING, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | err_out_region1: |
Alan Cox | c1cfd1a | 2008-05-19 14:09:29 +0100 | [diff] [blame] | 398 | release_region(ENABLE_W83877F_PORT, 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | err_out: |
| 400 | return rc; |
| 401 | } |
| 402 | |
| 403 | module_init(w83877f_wdt_init); |
| 404 | module_exit(w83877f_wdt_unload); |
| 405 | |
| 406 | MODULE_AUTHOR("Scott and Bill Jennings"); |
| 407 | MODULE_DESCRIPTION("Driver for watchdog timer in w83877f chip"); |
| 408 | MODULE_LICENSE("GPL"); |