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