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