Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * National Semiconductor PC87307/PC97307 (ala SC1200) WDT driver |
| 3 | * (c) Copyright 2002 Zwane Mwaikambo <zwane@commfireservices.com>, |
| 4 | * All Rights Reserved. |
| 5 | * Based on wdt.c and wdt977.c by Alan Cox and Woody Suwalski respectively. |
| 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 author(s) of this software shall not be held liable for damages |
| 13 | * of any nature resulting due to the use of this software. This |
| 14 | * software is provided AS-IS with no warranties. |
| 15 | * |
| 16 | * Changelog: |
| 17 | * 20020220 Zwane Mwaikambo Code based on datasheet, no hardware. |
Alan Cox | 103a1d5 | 2008-08-04 17:56:28 +0100 | [diff] [blame^] | 18 | * 20020221 Zwane Mwaikambo Cleanups as suggested by Jeff Garzik |
| 19 | * and Alan Cox. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | * 20020222 Zwane Mwaikambo Added probing. |
| 21 | * 20020225 Zwane Mwaikambo Added ISAPNP support. |
| 22 | * 20020412 Rob Radez Broke out start/stop functions |
Alan Cox | 103a1d5 | 2008-08-04 17:56:28 +0100 | [diff] [blame^] | 23 | * <rob@osinvestor.com> Return proper status instead of |
| 24 | * temperature warning |
| 25 | * Add WDIOC_GETBOOTSTATUS and |
| 26 | * WDIOC_SETOPTIONS ioctls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | * Fix CONFIG_WATCHDOG_NOWAYOUT |
Alan Cox | 103a1d5 | 2008-08-04 17:56:28 +0100 | [diff] [blame^] | 28 | * 20020530 Joel Becker Add Matt Domsch's nowayout module |
| 29 | * option |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | * 20030116 Adam Belay Updated to the latest pnp code |
| 31 | * |
| 32 | */ |
| 33 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #include <linux/module.h> |
| 35 | #include <linux/moduleparam.h> |
| 36 | #include <linux/miscdevice.h> |
| 37 | #include <linux/watchdog.h> |
| 38 | #include <linux/ioport.h> |
| 39 | #include <linux/spinlock.h> |
| 40 | #include <linux/notifier.h> |
| 41 | #include <linux/reboot.h> |
| 42 | #include <linux/init.h> |
| 43 | #include <linux/pnp.h> |
| 44 | #include <linux/fs.h> |
Matthew Wilcox | 6188e10 | 2008-04-18 22:21:05 -0400 | [diff] [blame] | 45 | #include <linux/semaphore.h> |
Alan Cox | 103a1d5 | 2008-08-04 17:56:28 +0100 | [diff] [blame^] | 46 | #include <linux/io.h> |
| 47 | #include <linux/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | |
| 49 | #define SC1200_MODULE_VER "build 20020303" |
| 50 | #define SC1200_MODULE_NAME "sc1200wdt" |
| 51 | #define PFX SC1200_MODULE_NAME ": " |
| 52 | |
| 53 | #define MAX_TIMEOUT 255 /* 255 minutes */ |
| 54 | #define PMIR (io) /* Power Management Index Register */ |
| 55 | #define PMDR (io+1) /* Power Management Data Register */ |
| 56 | |
| 57 | /* Data Register indexes */ |
| 58 | #define FER1 0x00 /* Function enable register 1 */ |
| 59 | #define FER2 0x01 /* Function enable register 2 */ |
| 60 | #define PMC1 0x02 /* Power Management Ctrl 1 */ |
| 61 | #define PMC2 0x03 /* Power Management Ctrl 2 */ |
| 62 | #define PMC3 0x04 /* Power Management Ctrl 3 */ |
| 63 | #define WDTO 0x05 /* Watchdog timeout register */ |
| 64 | #define WDCF 0x06 /* Watchdog config register */ |
| 65 | #define WDST 0x07 /* Watchdog status register */ |
| 66 | |
| 67 | /* WDCF bitfields - which devices assert WDO */ |
| 68 | #define KBC_IRQ 0x01 /* Keyboard Controller */ |
| 69 | #define MSE_IRQ 0x02 /* Mouse */ |
| 70 | #define UART1_IRQ 0x03 /* Serial0 */ |
| 71 | #define UART2_IRQ 0x04 /* Serial1 */ |
| 72 | /* 5 -7 are reserved */ |
| 73 | |
| 74 | static char banner[] __initdata = KERN_INFO PFX SC1200_MODULE_VER; |
| 75 | static int timeout = 1; |
| 76 | static int io = -1; |
| 77 | static int io_len = 2; /* for non plug and play */ |
Alan Cox | 103a1d5 | 2008-08-04 17:56:28 +0100 | [diff] [blame^] | 78 | static unsigned long open_flag; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | static char expect_close; |
Alexey Dobriyan | c7dfd0c | 2007-11-01 16:27:08 -0700 | [diff] [blame] | 80 | static DEFINE_SPINLOCK(sc1200wdt_lock); /* io port access serialisation */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | |
| 82 | #if defined CONFIG_PNP |
| 83 | static int isapnp = 1; |
| 84 | static struct pnp_dev *wdt_dev; |
| 85 | |
| 86 | module_param(isapnp, int, 0); |
Alan Cox | 103a1d5 | 2008-08-04 17:56:28 +0100 | [diff] [blame^] | 87 | MODULE_PARM_DESC(isapnp, |
| 88 | "When set to 0 driver ISA PnP support will be disabled"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | #endif |
| 90 | |
| 91 | module_param(io, int, 0); |
| 92 | MODULE_PARM_DESC(io, "io port"); |
| 93 | module_param(timeout, int, 0); |
| 94 | MODULE_PARM_DESC(timeout, "range is 0-255 minutes, default is 1"); |
| 95 | |
Andrey Panin | 4bfdf37 | 2005-07-27 11:43:58 -0700 | [diff] [blame] | 96 | static int nowayout = WATCHDOG_NOWAYOUT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | module_param(nowayout, int, 0); |
Alan Cox | 103a1d5 | 2008-08-04 17:56:28 +0100 | [diff] [blame^] | 98 | MODULE_PARM_DESC(nowayout, |
| 99 | "Watchdog cannot be stopped once started (default=" |
| 100 | __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | |
| 102 | |
| 103 | |
| 104 | /* Read from Data Register */ |
Alan Cox | 103a1d5 | 2008-08-04 17:56:28 +0100 | [diff] [blame^] | 105 | static inline void __sc1200wdt_read_data(unsigned char index, |
| 106 | unsigned char *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | outb_p(index, PMIR); |
| 109 | *data = inb(PMDR); |
Alan Cox | 103a1d5 | 2008-08-04 17:56:28 +0100 | [diff] [blame^] | 110 | } |
| 111 | |
| 112 | static void sc1200wdt_read_data(unsigned char index, unsigned char *data) |
| 113 | { |
| 114 | spin_lock(&sc1200wdt_lock); |
| 115 | __sc1200wdt_read_data(index, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | spin_unlock(&sc1200wdt_lock); |
| 117 | } |
| 118 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | /* Write to Data Register */ |
Alan Cox | 103a1d5 | 2008-08-04 17:56:28 +0100 | [diff] [blame^] | 120 | static inline void __sc1200wdt_write_data(unsigned char index, |
| 121 | unsigned char data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | outb_p(index, PMIR); |
| 124 | outb(data, PMDR); |
Alan Cox | 103a1d5 | 2008-08-04 17:56:28 +0100 | [diff] [blame^] | 125 | } |
| 126 | |
| 127 | static inline void sc1200wdt_write_data(unsigned char index, |
| 128 | unsigned char data) |
| 129 | { |
| 130 | spin_lock(&sc1200wdt_lock); |
| 131 | __sc1200wdt_write_data(index, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | spin_unlock(&sc1200wdt_lock); |
| 133 | } |
| 134 | |
| 135 | |
| 136 | static void sc1200wdt_start(void) |
| 137 | { |
| 138 | unsigned char reg; |
Alan Cox | 103a1d5 | 2008-08-04 17:56:28 +0100 | [diff] [blame^] | 139 | spin_lock(&sc1200wdt_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | |
Alan Cox | 103a1d5 | 2008-08-04 17:56:28 +0100 | [diff] [blame^] | 141 | __sc1200wdt_read_data(WDCF, ®); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | /* assert WDO when any of the following interrupts are triggered too */ |
| 143 | reg |= (KBC_IRQ | MSE_IRQ | UART1_IRQ | UART2_IRQ); |
Alan Cox | 103a1d5 | 2008-08-04 17:56:28 +0100 | [diff] [blame^] | 144 | __sc1200wdt_write_data(WDCF, reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | /* set the timeout and get the ball rolling */ |
Alan Cox | 103a1d5 | 2008-08-04 17:56:28 +0100 | [diff] [blame^] | 146 | __sc1200wdt_write_data(WDTO, timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | |
Alan Cox | 103a1d5 | 2008-08-04 17:56:28 +0100 | [diff] [blame^] | 148 | spin_unlock(&sc1200wdt_lock); |
| 149 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | |
| 151 | static void sc1200wdt_stop(void) |
| 152 | { |
| 153 | sc1200wdt_write_data(WDTO, 0); |
| 154 | } |
| 155 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | /* This returns the status of the WDO signal, inactive high. */ |
| 157 | static inline int sc1200wdt_status(void) |
| 158 | { |
| 159 | unsigned char ret; |
| 160 | |
| 161 | sc1200wdt_read_data(WDST, &ret); |
| 162 | /* If the bit is inactive, the watchdog is enabled, so return |
| 163 | * KEEPALIVEPING which is a bit of a kludge because there's nothing |
| 164 | * else for enabled/disabled status |
| 165 | */ |
Alan Cox | 103a1d5 | 2008-08-04 17:56:28 +0100 | [diff] [blame^] | 166 | return (ret & 0x01) ? 0 : WDIOF_KEEPALIVEPING; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | } |
| 168 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | static int sc1200wdt_open(struct inode *inode, struct file *file) |
| 170 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | /* allow one at a time */ |
Alan Cox | 103a1d5 | 2008-08-04 17:56:28 +0100 | [diff] [blame^] | 172 | if (test_and_set_bit(0, &open_flag)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | return -EBUSY; |
| 174 | |
| 175 | if (timeout > MAX_TIMEOUT) |
| 176 | timeout = MAX_TIMEOUT; |
| 177 | |
| 178 | sc1200wdt_start(); |
| 179 | printk(KERN_INFO PFX "Watchdog enabled, timeout = %d min(s)", timeout); |
| 180 | |
Wim Van Sebroeck | 6abe78b | 2007-07-24 21:38:37 +0000 | [diff] [blame] | 181 | return nonseekable_open(inode, file); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | |
Alan Cox | 103a1d5 | 2008-08-04 17:56:28 +0100 | [diff] [blame^] | 185 | static long sc1200wdt_ioctl(struct file *file, unsigned int cmd, |
| 186 | unsigned long arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | { |
| 188 | int new_timeout; |
| 189 | void __user *argp = (void __user *)arg; |
| 190 | int __user *p = argp; |
Alan Cox | 103a1d5 | 2008-08-04 17:56:28 +0100 | [diff] [blame^] | 191 | static const struct watchdog_info ident = { |
| 192 | .options = WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT | |
| 193 | WDIOF_MAGICCLOSE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | .firmware_version = 0, |
| 195 | .identity = "PC87307/PC97307", |
| 196 | }; |
| 197 | |
| 198 | switch (cmd) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | |
Alan Cox | 103a1d5 | 2008-08-04 17:56:28 +0100 | [diff] [blame^] | 200 | case WDIOC_GETSUPPORT: |
| 201 | if (copy_to_user(argp, &ident, sizeof ident)) |
| 202 | return -EFAULT; |
| 203 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | |
Alan Cox | 103a1d5 | 2008-08-04 17:56:28 +0100 | [diff] [blame^] | 205 | case WDIOC_GETSTATUS: |
| 206 | return put_user(sc1200wdt_status(), p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | |
Alan Cox | 103a1d5 | 2008-08-04 17:56:28 +0100 | [diff] [blame^] | 208 | case WDIOC_GETBOOTSTATUS: |
| 209 | return put_user(0, p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | |
Alan Cox | 103a1d5 | 2008-08-04 17:56:28 +0100 | [diff] [blame^] | 211 | case WDIOC_KEEPALIVE: |
| 212 | sc1200wdt_write_data(WDTO, timeout); |
| 213 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | |
Alan Cox | 103a1d5 | 2008-08-04 17:56:28 +0100 | [diff] [blame^] | 215 | case WDIOC_SETTIMEOUT: |
| 216 | if (get_user(new_timeout, p)) |
| 217 | return -EFAULT; |
| 218 | /* the API states this is given in secs */ |
| 219 | new_timeout /= 60; |
| 220 | if (new_timeout < 0 || new_timeout > MAX_TIMEOUT) |
| 221 | return -EINVAL; |
| 222 | timeout = new_timeout; |
| 223 | sc1200wdt_write_data(WDTO, timeout); |
| 224 | /* fall through and return the new timeout */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | |
Alan Cox | 103a1d5 | 2008-08-04 17:56:28 +0100 | [diff] [blame^] | 226 | case WDIOC_GETTIMEOUT: |
| 227 | return put_user(timeout * 60, p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | |
Alan Cox | 103a1d5 | 2008-08-04 17:56:28 +0100 | [diff] [blame^] | 229 | case WDIOC_SETOPTIONS: |
| 230 | { |
| 231 | int options, retval = -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | |
Alan Cox | 103a1d5 | 2008-08-04 17:56:28 +0100 | [diff] [blame^] | 233 | if (get_user(options, p)) |
| 234 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | |
Alan Cox | 103a1d5 | 2008-08-04 17:56:28 +0100 | [diff] [blame^] | 236 | if (options & WDIOS_DISABLECARD) { |
| 237 | sc1200wdt_stop(); |
| 238 | retval = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | } |
Alan Cox | 103a1d5 | 2008-08-04 17:56:28 +0100 | [diff] [blame^] | 240 | |
| 241 | if (options & WDIOS_ENABLECARD) { |
| 242 | sc1200wdt_start(); |
| 243 | retval = 0; |
| 244 | } |
| 245 | |
| 246 | return retval; |
| 247 | } |
| 248 | default: |
| 249 | return -ENOTTY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | } |
| 251 | } |
| 252 | |
| 253 | |
| 254 | static int sc1200wdt_release(struct inode *inode, struct file *file) |
| 255 | { |
| 256 | if (expect_close == 42) { |
| 257 | sc1200wdt_stop(); |
| 258 | printk(KERN_INFO PFX "Watchdog disabled\n"); |
| 259 | } else { |
| 260 | sc1200wdt_write_data(WDTO, timeout); |
Alan Cox | 103a1d5 | 2008-08-04 17:56:28 +0100 | [diff] [blame^] | 261 | printk(KERN_CRIT PFX |
| 262 | "Unexpected close!, timeout = %d min(s)\n", timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | } |
Alan Cox | 103a1d5 | 2008-08-04 17:56:28 +0100 | [diff] [blame^] | 264 | clear_bit(0, &open_flag); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | expect_close = 0; |
| 266 | |
| 267 | return 0; |
| 268 | } |
| 269 | |
| 270 | |
Alan Cox | 103a1d5 | 2008-08-04 17:56:28 +0100 | [diff] [blame^] | 271 | static ssize_t sc1200wdt_write(struct file *file, const char __user *data, |
| 272 | size_t len, loff_t *ppos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | { |
| 274 | if (len) { |
| 275 | if (!nowayout) { |
| 276 | size_t i; |
| 277 | |
| 278 | expect_close = 0; |
| 279 | |
| 280 | for (i = 0; i != len; i++) { |
| 281 | char c; |
| 282 | |
| 283 | if (get_user(c, data+i)) |
| 284 | return -EFAULT; |
| 285 | if (c == 'V') |
| 286 | expect_close = 42; |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | sc1200wdt_write_data(WDTO, timeout); |
| 291 | return len; |
| 292 | } |
| 293 | |
| 294 | return 0; |
| 295 | } |
| 296 | |
| 297 | |
Alan Cox | 103a1d5 | 2008-08-04 17:56:28 +0100 | [diff] [blame^] | 298 | static int sc1200wdt_notify_sys(struct notifier_block *this, |
| 299 | unsigned long code, void *unused) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | { |
| 301 | if (code == SYS_DOWN || code == SYS_HALT) |
| 302 | sc1200wdt_stop(); |
| 303 | |
| 304 | return NOTIFY_DONE; |
| 305 | } |
| 306 | |
| 307 | |
Alan Cox | 103a1d5 | 2008-08-04 17:56:28 +0100 | [diff] [blame^] | 308 | static struct notifier_block sc1200wdt_notifier = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | .notifier_call = sc1200wdt_notify_sys, |
| 310 | }; |
| 311 | |
Alan Cox | 103a1d5 | 2008-08-04 17:56:28 +0100 | [diff] [blame^] | 312 | static const struct file_operations sc1200wdt_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | .owner = THIS_MODULE, |
| 314 | .llseek = no_llseek, |
| 315 | .write = sc1200wdt_write, |
Alan Cox | 103a1d5 | 2008-08-04 17:56:28 +0100 | [diff] [blame^] | 316 | .unlocked_ioctl = sc1200wdt_ioctl, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | .open = sc1200wdt_open, |
| 318 | .release = sc1200wdt_release, |
| 319 | }; |
| 320 | |
Alan Cox | 103a1d5 | 2008-08-04 17:56:28 +0100 | [diff] [blame^] | 321 | static struct miscdevice sc1200wdt_miscdev = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | .minor = WATCHDOG_MINOR, |
| 323 | .name = "watchdog", |
| 324 | .fops = &sc1200wdt_fops, |
| 325 | }; |
| 326 | |
| 327 | |
| 328 | static int __init sc1200wdt_probe(void) |
| 329 | { |
| 330 | /* The probe works by reading the PMC3 register's default value of 0x0e |
| 331 | * there is one caveat, if the device disables the parallel port or any |
| 332 | * of the UARTs we won't be able to detect it. |
Alan Cox | 103a1d5 | 2008-08-04 17:56:28 +0100 | [diff] [blame^] | 333 | * NB. This could be done with accuracy by reading the SID registers, |
| 334 | * but we don't have access to those io regions. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | */ |
| 336 | |
| 337 | unsigned char reg; |
| 338 | |
| 339 | sc1200wdt_read_data(PMC3, ®); |
Alan Cox | 103a1d5 | 2008-08-04 17:56:28 +0100 | [diff] [blame^] | 340 | reg &= 0x0f; /* we don't want the UART busy bits */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | return (reg == 0x0e) ? 0 : -ENODEV; |
| 342 | } |
| 343 | |
| 344 | |
| 345 | #if defined CONFIG_PNP |
| 346 | |
| 347 | static struct pnp_device_id scl200wdt_pnp_devices[] = { |
| 348 | /* National Semiconductor PC87307/PC97307 watchdog component */ |
| 349 | {.id = "NSC0800", .driver_data = 0}, |
| 350 | {.id = ""}, |
| 351 | }; |
| 352 | |
Alan Cox | 103a1d5 | 2008-08-04 17:56:28 +0100 | [diff] [blame^] | 353 | static int scl200wdt_pnp_probe(struct pnp_dev *dev, |
| 354 | const struct pnp_device_id *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | { |
| 356 | /* this driver only supports one card at a time */ |
| 357 | if (wdt_dev || !isapnp) |
| 358 | return -EBUSY; |
| 359 | |
| 360 | wdt_dev = dev; |
| 361 | io = pnp_port_start(wdt_dev, 0); |
| 362 | io_len = pnp_port_len(wdt_dev, 0); |
| 363 | |
| 364 | if (!request_region(io, io_len, SC1200_MODULE_NAME)) { |
| 365 | printk(KERN_ERR PFX "Unable to register IO port %#x\n", io); |
| 366 | return -EBUSY; |
| 367 | } |
| 368 | |
Alan Cox | 103a1d5 | 2008-08-04 17:56:28 +0100 | [diff] [blame^] | 369 | printk(KERN_INFO "scl200wdt: PnP device found at io port %#x/%d\n", |
| 370 | io, io_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | return 0; |
| 372 | } |
| 373 | |
Alan Cox | 103a1d5 | 2008-08-04 17:56:28 +0100 | [diff] [blame^] | 374 | static void scl200wdt_pnp_remove(struct pnp_dev *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | { |
Alan Cox | 103a1d5 | 2008-08-04 17:56:28 +0100 | [diff] [blame^] | 376 | if (wdt_dev) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | release_region(io, io_len); |
| 378 | wdt_dev = NULL; |
| 379 | } |
| 380 | } |
| 381 | |
| 382 | static struct pnp_driver scl200wdt_pnp_driver = { |
| 383 | .name = "scl200wdt", |
| 384 | .id_table = scl200wdt_pnp_devices, |
| 385 | .probe = scl200wdt_pnp_probe, |
| 386 | .remove = scl200wdt_pnp_remove, |
| 387 | }; |
| 388 | |
| 389 | #endif /* CONFIG_PNP */ |
| 390 | |
| 391 | |
| 392 | static int __init sc1200wdt_init(void) |
| 393 | { |
| 394 | int ret; |
| 395 | |
Dave Jones | 7071e52 | 2006-04-03 16:04:48 -0700 | [diff] [blame] | 396 | printk("%s\n", banner); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | #if defined CONFIG_PNP |
| 399 | if (isapnp) { |
| 400 | ret = pnp_register_driver(&scl200wdt_pnp_driver); |
| 401 | if (ret) |
| 402 | goto out_clean; |
| 403 | } |
| 404 | #endif |
| 405 | |
| 406 | if (io == -1) { |
| 407 | printk(KERN_ERR PFX "io parameter must be specified\n"); |
| 408 | ret = -EINVAL; |
Akinobu Mita | 150ed8e | 2006-10-29 03:43:19 +0900 | [diff] [blame] | 409 | goto out_pnp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | } |
| 411 | |
| 412 | #if defined CONFIG_PNP |
| 413 | /* now that the user has specified an IO port and we haven't detected |
| 414 | * any devices, disable pnp support */ |
| 415 | isapnp = 0; |
| 416 | pnp_unregister_driver(&scl200wdt_pnp_driver); |
| 417 | #endif |
| 418 | |
| 419 | if (!request_region(io, io_len, SC1200_MODULE_NAME)) { |
| 420 | printk(KERN_ERR PFX "Unable to register IO port %#x\n", io); |
| 421 | ret = -EBUSY; |
Akinobu Mita | 150ed8e | 2006-10-29 03:43:19 +0900 | [diff] [blame] | 422 | goto out_pnp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | } |
| 424 | |
| 425 | ret = sc1200wdt_probe(); |
| 426 | if (ret) |
| 427 | goto out_io; |
| 428 | |
| 429 | ret = register_reboot_notifier(&sc1200wdt_notifier); |
| 430 | if (ret) { |
Alan Cox | 103a1d5 | 2008-08-04 17:56:28 +0100 | [diff] [blame^] | 431 | printk(KERN_ERR PFX |
| 432 | "Unable to register reboot notifier err = %d\n", ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | goto out_io; |
| 434 | } |
| 435 | |
| 436 | ret = misc_register(&sc1200wdt_miscdev); |
| 437 | if (ret) { |
Alan Cox | 103a1d5 | 2008-08-04 17:56:28 +0100 | [diff] [blame^] | 438 | printk(KERN_ERR PFX |
| 439 | "Unable to register miscdev on minor %d\n", |
| 440 | WATCHDOG_MINOR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | goto out_rbt; |
| 442 | } |
| 443 | |
| 444 | /* ret = 0 */ |
| 445 | |
| 446 | out_clean: |
| 447 | return ret; |
| 448 | |
| 449 | out_rbt: |
| 450 | unregister_reboot_notifier(&sc1200wdt_notifier); |
| 451 | |
| 452 | out_io: |
| 453 | release_region(io, io_len); |
| 454 | |
Akinobu Mita | 150ed8e | 2006-10-29 03:43:19 +0900 | [diff] [blame] | 455 | out_pnp: |
| 456 | #if defined CONFIG_PNP |
| 457 | if (isapnp) |
| 458 | pnp_unregister_driver(&scl200wdt_pnp_driver); |
| 459 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | goto out_clean; |
| 461 | } |
| 462 | |
| 463 | |
| 464 | static void __exit sc1200wdt_exit(void) |
| 465 | { |
| 466 | misc_deregister(&sc1200wdt_miscdev); |
| 467 | unregister_reboot_notifier(&sc1200wdt_notifier); |
| 468 | |
| 469 | #if defined CONFIG_PNP |
Alan Cox | 103a1d5 | 2008-08-04 17:56:28 +0100 | [diff] [blame^] | 470 | if (isapnp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | pnp_unregister_driver(&scl200wdt_pnp_driver); |
| 472 | else |
| 473 | #endif |
| 474 | release_region(io, io_len); |
| 475 | } |
| 476 | |
| 477 | module_init(sc1200wdt_init); |
| 478 | module_exit(sc1200wdt_exit); |
| 479 | |
| 480 | MODULE_AUTHOR("Zwane Mwaikambo <zwane@commfireservices.com>"); |
| 481 | MODULE_DESCRIPTION("Driver for National Semiconductor PC87307/PC97307 watchdog component"); |
| 482 | MODULE_LICENSE("GPL"); |
| 483 | MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR); |