Blame view
drivers/watchdog/pc87413_wdt.c
14.7 KB
789fc0adb
|
1 2 3 |
/* * NS pc87413-wdt Watchdog Timer driver for Linux 2.6.x.x * |
00b3b3e66
|
4 |
* This code is based on wdt.c with original copyright. |
789fc0adb
|
5 |
* |
00b3b3e66
|
6 7 |
* (C) Copyright 2006 Sven Anders, <anders@anduras.de> * and Marcus Junker, <junker@anduras.de> |
789fc0adb
|
8 9 10 11 12 13 |
* * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version * 2 of the License, or (at your option) any later version. * |
00b3b3e66
|
14 |
* Neither Sven Anders, Marcus Junker nor ANDURAS AG |
789fc0adb
|
15 16 17 |
* admit liability nor provide warranty for any of this software. * This material is provided "AS-IS" and at no charge. * |
00b3b3e66
|
18 |
* Release 1.1 |
789fc0adb
|
19 |
*/ |
789fc0adb
|
20 21 22 23 24 25 26 27 28 29 30 31 |
#include <linux/module.h> #include <linux/types.h> #include <linux/miscdevice.h> #include <linux/watchdog.h> #include <linux/ioport.h> #include <linux/delay.h> #include <linux/notifier.h> #include <linux/fs.h> #include <linux/reboot.h> #include <linux/init.h> #include <linux/spinlock.h> #include <linux/moduleparam.h> |
aee334c23
|
32 33 |
#include <linux/io.h> #include <linux/uaccess.h> |
789fc0adb
|
34 |
|
789fc0adb
|
35 |
#include <asm/system.h> |
00b3b3e66
|
36 |
/* #define DEBUG 1 */ |
789fc0adb
|
37 |
|
7944d3a5a
|
38 |
#define DEFAULT_TIMEOUT 1 /* 1 minute */ |
00b3b3e66
|
39 |
#define MAX_TIMEOUT 255 |
789fc0adb
|
40 |
|
00b3b3e66
|
41 42 43 44 |
#define VERSION "1.1" #define MODNAME "pc87413 WDT" #define PFX MODNAME ": " #define DPFX MODNAME " - DEBUG: " |
789fc0adb
|
45 |
|
7944d3a5a
|
46 |
#define WDT_INDEX_IO_PORT (io+0) /* I/O port base (index register) */ |
00b3b3e66
|
47 48 |
#define WDT_DATA_IO_PORT (WDT_INDEX_IO_PORT+1) #define SWC_LDN 0x04 |
7944d3a5a
|
49 50 51 52 |
#define SIOCFG2 0x22 /* Serial IO register */ #define WDCTL 0x10 /* Watchdog-Timer-Controll-Register */ #define WDTO 0x11 /* Watchdog timeout register */ #define WDCFG 0x12 /* Watchdog config register */ |
789fc0adb
|
53 |
|
76550d329
|
54 55 56 |
#define IO_DEFAULT 0x2E /* Address used on Portwell Boards */ static int io = IO_DEFAULT; |
789fc0adb
|
57 |
|
7944d3a5a
|
58 |
static int timeout = DEFAULT_TIMEOUT; /* timeout value */ |
aee334c23
|
59 |
static unsigned long timer_enabled; /* is the timer enabled? */ |
789fc0adb
|
60 |
|
aee334c23
|
61 |
static char expect_close; /* is the close expected? */ |
789fc0adb
|
62 |
|
aee334c23
|
63 |
static DEFINE_SPINLOCK(io_lock); /* to guard us from io races */ |
789fc0adb
|
64 |
|
00b3b3e66
|
65 |
static int nowayout = WATCHDOG_NOWAYOUT; |
789fc0adb
|
66 |
|
00b3b3e66
|
67 |
/* -- Low level function ----------------------------------------*/ |
789fc0adb
|
68 |
|
00b3b3e66
|
69 |
/* Select pins for Watchdog output */ |
789fc0adb
|
70 |
|
aee334c23
|
71 |
static inline void pc87413_select_wdt_out(void) |
789fc0adb
|
72 |
{ |
00b3b3e66
|
73 |
unsigned int cr_data = 0; |
789fc0adb
|
74 |
|
00b3b3e66
|
75 |
/* Step 1: Select multiple pin,pin55,as WDT output */ |
789fc0adb
|
76 77 |
outb_p(SIOCFG2, WDT_INDEX_IO_PORT); |
aee334c23
|
78 |
cr_data = inb(WDT_DATA_IO_PORT); |
789fc0adb
|
79 80 81 82 83 |
cr_data |= 0x80; /* Set Bit7 to 1*/ outb_p(SIOCFG2, WDT_INDEX_IO_PORT); outb_p(cr_data, WDT_DATA_IO_PORT); |
00b3b3e66
|
84 |
#ifdef DEBUG |
aee334c23
|
85 86 87 88 |
printk(KERN_INFO DPFX "Select multiple pin,pin55,as WDT output: Bit7 to 1: %d ", cr_data); |
00b3b3e66
|
89 |
#endif |
789fc0adb
|
90 |
} |
00b3b3e66
|
91 |
/* Enable SWC functions */ |
789fc0adb
|
92 |
|
00b3b3e66
|
93 94 |
static inline void pc87413_enable_swc(void) { |
aee334c23
|
95 |
unsigned int cr_data = 0; |
789fc0adb
|
96 97 |
/* Step 2: Enable SWC functions */ |
7944d3a5a
|
98 |
outb_p(0x07, WDT_INDEX_IO_PORT); /* Point SWC_LDN (LDN=4) */ |
789fc0adb
|
99 |
outb_p(SWC_LDN, WDT_DATA_IO_PORT); |
7944d3a5a
|
100 |
outb_p(0x30, WDT_INDEX_IO_PORT); /* Read Index 0x30 First */ |
00b3b3e66
|
101 |
cr_data = inb(WDT_DATA_IO_PORT); |
7944d3a5a
|
102 |
cr_data |= 0x01; /* Set Bit0 to 1 */ |
789fc0adb
|
103 |
outb_p(0x30, WDT_INDEX_IO_PORT); |
7944d3a5a
|
104 |
outb_p(cr_data, WDT_DATA_IO_PORT); /* Index0x30_bit0P1 */ |
789fc0adb
|
105 |
|
00b3b3e66
|
106 |
#ifdef DEBUG |
789fc0adb
|
107 108 |
printk(KERN_INFO DPFX "pc87413 - Enable SWC functions "); |
00b3b3e66
|
109 |
#endif |
789fc0adb
|
110 |
} |
00b3b3e66
|
111 112 113 |
/* Read SWC I/O base address */ static inline unsigned int pc87413_get_swc_base(void) |
789fc0adb
|
114 |
{ |
00b3b3e66
|
115 116 |
unsigned int swc_base_addr = 0; unsigned char addr_l, addr_h = 0; |
789fc0adb
|
117 118 |
/* Step 3: Read SWC I/O Base Address */ |
7944d3a5a
|
119 |
outb_p(0x60, WDT_INDEX_IO_PORT); /* Read Index 0x60 */ |
00b3b3e66
|
120 |
addr_h = inb(WDT_DATA_IO_PORT); |
789fc0adb
|
121 |
|
7944d3a5a
|
122 |
outb_p(0x61, WDT_INDEX_IO_PORT); /* Read Index 0x61 */ |
789fc0adb
|
123 |
|
00b3b3e66
|
124 |
addr_l = inb(WDT_DATA_IO_PORT); |
789fc0adb
|
125 126 |
swc_base_addr = (addr_h << 8) + addr_l; |
00b3b3e66
|
127 |
#ifdef DEBUG |
aee334c23
|
128 129 130 131 |
printk(KERN_INFO DPFX "Read SWC I/O Base Address: low %d, high %d, res %d ", addr_l, addr_h, swc_base_addr); |
00b3b3e66
|
132 |
#endif |
789fc0adb
|
133 134 |
return swc_base_addr; } |
00b3b3e66
|
135 136 137 |
/* Select Bank 3 of SWC */ static inline void pc87413_swc_bank3(unsigned int swc_base_addr) |
789fc0adb
|
138 139 |
{ /* Step 4: Select Bank3 of SWC */ |
00b3b3e66
|
140 |
outb_p(inb(swc_base_addr + 0x0f) | 0x03, swc_base_addr + 0x0f); |
00b3b3e66
|
141 |
#ifdef DEBUG |
789fc0adb
|
142 143 |
printk(KERN_INFO DPFX "Select Bank3 of SWC "); |
00b3b3e66
|
144 |
#endif |
789fc0adb
|
145 |
} |
00b3b3e66
|
146 147 148 149 |
/* Set watchdog timeout to x minutes */ static inline void pc87413_programm_wdto(unsigned int swc_base_addr, char pc87413_time) |
789fc0adb
|
150 151 |
{ /* Step 5: Programm WDTO, Twd. */ |
00b3b3e66
|
152 |
outb_p(pc87413_time, swc_base_addr + WDTO); |
00b3b3e66
|
153 |
#ifdef DEBUG |
789fc0adb
|
154 155 |
printk(KERN_INFO DPFX "Set WDTO to %d minutes ", pc87413_time); |
00b3b3e66
|
156 |
#endif |
789fc0adb
|
157 |
} |
00b3b3e66
|
158 159 160 |
/* Enable WDEN */ static inline void pc87413_enable_wden(unsigned int swc_base_addr) |
789fc0adb
|
161 162 |
{ /* Step 6: Enable WDEN */ |
aee334c23
|
163 |
outb_p(inb(swc_base_addr + WDCTL) | 0x01, swc_base_addr + WDCTL); |
00b3b3e66
|
164 |
#ifdef DEBUG |
789fc0adb
|
165 166 |
printk(KERN_INFO DPFX "Enable WDEN "); |
00b3b3e66
|
167 |
#endif |
789fc0adb
|
168 |
} |
00b3b3e66
|
169 170 |
/* Enable SW_WD_TREN */ static inline void pc87413_enable_sw_wd_tren(unsigned int swc_base_addr) |
789fc0adb
|
171 172 |
{ /* Enable SW_WD_TREN */ |
aee334c23
|
173 |
outb_p(inb(swc_base_addr + WDCFG) | 0x80, swc_base_addr + WDCFG); |
00b3b3e66
|
174 |
#ifdef DEBUG |
789fc0adb
|
175 176 |
printk(KERN_INFO DPFX "Enable SW_WD_TREN "); |
00b3b3e66
|
177 |
#endif |
789fc0adb
|
178 |
} |
00b3b3e66
|
179 180 181 |
/* Disable SW_WD_TREN */ static inline void pc87413_disable_sw_wd_tren(unsigned int swc_base_addr) |
789fc0adb
|
182 183 |
{ /* Disable SW_WD_TREN */ |
aee334c23
|
184 |
outb_p(inb(swc_base_addr + WDCFG) & 0x7f, swc_base_addr + WDCFG); |
00b3b3e66
|
185 |
#ifdef DEBUG |
789fc0adb
|
186 187 |
printk(KERN_INFO DPFX "pc87413 - Disable SW_WD_TREN "); |
00b3b3e66
|
188 |
#endif |
789fc0adb
|
189 |
} |
00b3b3e66
|
190 |
/* Enable SW_WD_TRG */ |
789fc0adb
|
191 |
|
00b3b3e66
|
192 |
static inline void pc87413_enable_sw_wd_trg(unsigned int swc_base_addr) |
789fc0adb
|
193 |
{ |
789fc0adb
|
194 |
/* Enable SW_WD_TRG */ |
aee334c23
|
195 |
outb_p(inb(swc_base_addr + WDCTL) | 0x80, swc_base_addr + WDCTL); |
00b3b3e66
|
196 |
#ifdef DEBUG |
789fc0adb
|
197 198 |
printk(KERN_INFO DPFX "pc87413 - Enable SW_WD_TRG "); |
00b3b3e66
|
199 |
#endif |
789fc0adb
|
200 |
} |
00b3b3e66
|
201 |
/* Disable SW_WD_TRG */ |
789fc0adb
|
202 |
|
00b3b3e66
|
203 204 |
static inline void pc87413_disable_sw_wd_trg(unsigned int swc_base_addr) { |
789fc0adb
|
205 |
/* Disable SW_WD_TRG */ |
aee334c23
|
206 |
outb_p(inb(swc_base_addr + WDCTL) & 0x7f, swc_base_addr + WDCTL); |
00b3b3e66
|
207 |
#ifdef DEBUG |
789fc0adb
|
208 209 |
printk(KERN_INFO DPFX "Disable SW_WD_TRG "); |
00b3b3e66
|
210 |
#endif |
789fc0adb
|
211 |
} |
00b3b3e66
|
212 |
/* -- Higher level functions ------------------------------------*/ |
789fc0adb
|
213 |
|
00b3b3e66
|
214 |
/* Enable the watchdog */ |
789fc0adb
|
215 |
|
00b3b3e66
|
216 |
static void pc87413_enable(void) |
789fc0adb
|
217 |
{ |
00b3b3e66
|
218 219 220 |
unsigned int swc_base_addr; spin_lock(&io_lock); |
789fc0adb
|
221 222 223 224 225 |
pc87413_select_wdt_out(); pc87413_enable_swc(); swc_base_addr = pc87413_get_swc_base(); pc87413_swc_bank3(swc_base_addr); |
00b3b3e66
|
226 227 228 229 230 231 |
pc87413_programm_wdto(swc_base_addr, timeout); pc87413_enable_wden(swc_base_addr); pc87413_enable_sw_wd_tren(swc_base_addr); pc87413_enable_sw_wd_trg(swc_base_addr); spin_unlock(&io_lock); |
789fc0adb
|
232 |
} |
00b3b3e66
|
233 |
/* Disable the watchdog */ |
789fc0adb
|
234 |
|
00b3b3e66
|
235 |
static void pc87413_disable(void) |
789fc0adb
|
236 |
{ |
00b3b3e66
|
237 238 239 |
unsigned int swc_base_addr; spin_lock(&io_lock); |
789fc0adb
|
240 241 242 243 244 245 246 |
pc87413_select_wdt_out(); pc87413_enable_swc(); swc_base_addr = pc87413_get_swc_base(); pc87413_swc_bank3(swc_base_addr); pc87413_disable_sw_wd_tren(swc_base_addr); pc87413_disable_sw_wd_trg(swc_base_addr); |
00b3b3e66
|
247 248 249 |
pc87413_programm_wdto(swc_base_addr, 0); spin_unlock(&io_lock); |
789fc0adb
|
250 |
} |
00b3b3e66
|
251 |
/* Refresh the watchdog */ |
789fc0adb
|
252 |
|
00b3b3e66
|
253 |
static void pc87413_refresh(void) |
789fc0adb
|
254 |
{ |
00b3b3e66
|
255 256 257 |
unsigned int swc_base_addr; spin_lock(&io_lock); |
789fc0adb
|
258 259 260 261 262 |
pc87413_select_wdt_out(); pc87413_enable_swc(); swc_base_addr = pc87413_get_swc_base(); pc87413_swc_bank3(swc_base_addr); |
00b3b3e66
|
263 264 265 |
pc87413_disable_sw_wd_tren(swc_base_addr); pc87413_disable_sw_wd_trg(swc_base_addr); pc87413_programm_wdto(swc_base_addr, timeout); |
789fc0adb
|
266 267 268 |
pc87413_enable_wden(swc_base_addr); pc87413_enable_sw_wd_tren(swc_base_addr); pc87413_enable_sw_wd_trg(swc_base_addr); |
00b3b3e66
|
269 |
spin_unlock(&io_lock); |
789fc0adb
|
270 |
} |
00b3b3e66
|
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 |
/* -- File operations -------------------------------------------*/ /** * pc87413_open: * @inode: inode of device * @file: file handle to device * */ static int pc87413_open(struct inode *inode, struct file *file) { /* /dev/watchdog can only be opened once */ if (test_and_set_bit(0, &timer_enabled)) return -EBUSY; if (nowayout) __module_get(THIS_MODULE); |
789fc0adb
|
289 |
|
00b3b3e66
|
290 291 |
/* Reload and activate timer */ pc87413_refresh(); |
789fc0adb
|
292 |
|
aee334c23
|
293 294 295 |
printk(KERN_INFO MODNAME "Watchdog enabled. Timeout set to %d minute(s). ", timeout); |
00b3b3e66
|
296 297 298 |
return nonseekable_open(inode, file); } |
789fc0adb
|
299 300 |
/** |
00b3b3e66
|
301 302 303 |
* pc87413_release: * @inode: inode to board * @file: file handle to board |
789fc0adb
|
304 |
* |
00b3b3e66
|
305 306 307 308 309 |
* The watchdog has a configurable API. There is a religious dispute * between people who want their watchdog to be able to shut down and * those who want to be sure if the watchdog manager dies the machine * reboots. In the former case we disable the counters, in the latter * case you have to open it again very soon. |
789fc0adb
|
310 |
*/ |
00b3b3e66
|
311 |
static int pc87413_release(struct inode *inode, struct file *file) |
789fc0adb
|
312 |
{ |
00b3b3e66
|
313 314 315 316 |
/* Shut off the timer. */ if (expect_close == 42) { pc87413_disable(); |
aee334c23
|
317 318 319 |
printk(KERN_INFO MODNAME "Watchdog disabled, sleeping again... "); |
00b3b3e66
|
320 |
} else { |
aee334c23
|
321 322 323 |
printk(KERN_CRIT MODNAME "Unexpected close, not stopping watchdog! "); |
00b3b3e66
|
324 325 |
pc87413_refresh(); } |
00b3b3e66
|
326 327 |
clear_bit(0, &timer_enabled); expect_close = 0; |
00b3b3e66
|
328 |
return 0; |
789fc0adb
|
329 |
} |
00b3b3e66
|
330 331 332 333 334 335 336 337 |
/** * pc87413_status: * * return, if the watchdog is enabled (timeout is set...) */ static int pc87413_status(void) |
789fc0adb
|
338 |
{ |
0835caa2b
|
339 |
return 0; /* currently not supported */ |
789fc0adb
|
340 341 342 343 344 |
} /** * pc87413_write: * @file: file handle to the watchdog |
00b3b3e66
|
345 346 |
* @data: data buffer to write * @len: length in bytes |
789fc0adb
|
347 348 349 350 351 |
* @ppos: pointer to the position to write. No seeks allowed * * A write to a watchdog device is defined as a keepalive signal. Any * write of data will do, as we we don't define content meaning. */ |
00b3b3e66
|
352 353 |
static ssize_t pc87413_write(struct file *file, const char __user *data, size_t len, loff_t *ppos) |
789fc0adb
|
354 |
{ |
00b3b3e66
|
355 356 357 358 359 360 361 |
/* See if we got the magic character 'V' and reload the timer */ if (len) { if (!nowayout) { size_t i; /* reset expect flag */ expect_close = 0; |
aee334c23
|
362 363 |
/* scan to see whether or not we got the magic character */ |
00b3b3e66
|
364 365 |
for (i = 0; i != len; i++) { char c; |
7944d3a5a
|
366 |
if (get_user(c, data + i)) |
00b3b3e66
|
367 368 369 370 371 372 373 374 |
return -EFAULT; if (c == 'V') expect_close = 42; } } /* someone wrote to us, we should reload the timer */ pc87413_refresh(); |
789fc0adb
|
375 |
} |
00b3b3e66
|
376 |
return len; |
789fc0adb
|
377 |
} |
00b3b3e66
|
378 |
/** |
789fc0adb
|
379 |
* pc87413_ioctl: |
789fc0adb
|
380 381 382 383 384 385 386 387 |
* @file: file handle to the device * @cmd: watchdog command * @arg: argument pointer * * The watchdog API defines a common set of functions for all watchdogs * according to their available features. We only actually usefully support * querying capabilities and current status. */ |
aee334c23
|
388 389 |
static long pc87413_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
789fc0adb
|
390 |
{ |
00b3b3e66
|
391 392 393 394 395 396 |
int new_timeout; union { struct watchdog_info __user *ident; int __user *i; } uarg; |
42747d712
|
397 |
static const struct watchdog_info ident = { |
00b3b3e66
|
398 |
.options = WDIOF_KEEPALIVEPING | |
aee334c23
|
399 400 |
WDIOF_SETTIMEOUT | WDIOF_MAGICCLOSE, |
00b3b3e66
|
401 |
.firmware_version = 1, |
7944d3a5a
|
402 |
.identity = "PC87413(HF/F) watchdog", |
789fc0adb
|
403 |
}; |
00b3b3e66
|
404 |
uarg.i = (int __user *)arg; |
789fc0adb
|
405 |
|
aee334c23
|
406 407 408 409 410 411 412 413 |
switch (cmd) { case WDIOC_GETSUPPORT: return copy_to_user(uarg.ident, &ident, sizeof(ident)) ? -EFAULT : 0; case WDIOC_GETSTATUS: return put_user(pc87413_status(), uarg.i); case WDIOC_GETBOOTSTATUS: return put_user(0, uarg.i); |
0c06090c9
|
414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 |
case WDIOC_SETOPTIONS: { int options, retval = -EINVAL; if (get_user(options, uarg.i)) return -EFAULT; if (options & WDIOS_DISABLECARD) { pc87413_disable(); retval = 0; } if (options & WDIOS_ENABLECARD) { pc87413_enable(); retval = 0; } return retval; } |
aee334c23
|
429 430 |
case WDIOC_KEEPALIVE: pc87413_refresh(); |
00b3b3e66
|
431 |
#ifdef DEBUG |
aee334c23
|
432 433 |
printk(KERN_INFO DPFX "keepalive "); |
00b3b3e66
|
434 |
#endif |
aee334c23
|
435 436 437 438 439 440 441 442 443 444 445 446 447 448 |
return 0; case WDIOC_SETTIMEOUT: if (get_user(new_timeout, uarg.i)) return -EFAULT; /* the API states this is given in secs */ new_timeout /= 60; if (new_timeout < 0 || new_timeout > MAX_TIMEOUT) return -EINVAL; timeout = new_timeout; pc87413_refresh(); /* fall through and return the new timeout... */ case WDIOC_GETTIMEOUT: new_timeout = timeout * 60; return put_user(new_timeout, uarg.i); |
aee334c23
|
449 450 |
default: return -ENOTTY; |
789fc0adb
|
451 |
} |
789fc0adb
|
452 |
} |
00b3b3e66
|
453 |
/* -- Notifier funtions -----------------------------------------*/ |
789fc0adb
|
454 455 456 457 458 459 460 461 462 463 464 |
/** * notify_sys: * @this: our notifier block * @code: the event being reported * @unused: unused * * Our notifier is called on system shutdowns. We want to turn the card * off at reboot otherwise the machine will reboot again during memory * test or worse yet during the following fsck. This would suck, in fact * trust me - if it happens it does suck. */ |
00b3b3e66
|
465 466 467 |
static int pc87413_notify_sys(struct notifier_block *this, unsigned long code, void *unused) |
789fc0adb
|
468 |
{ |
00b3b3e66
|
469 |
if (code == SYS_DOWN || code == SYS_HALT) |
789fc0adb
|
470 471 |
/* Turn the card off */ pc87413_disable(); |
789fc0adb
|
472 473 |
return NOTIFY_DONE; } |
00b3b3e66
|
474 |
/* -- Module's structures ---------------------------------------*/ |
789fc0adb
|
475 |
|
2b8693c06
|
476 |
static const struct file_operations pc87413_fops = { |
789fc0adb
|
477 |
.owner = THIS_MODULE, |
00b3b3e66
|
478 |
.llseek = no_llseek, |
789fc0adb
|
479 |
.write = pc87413_write, |
aee334c23
|
480 |
.unlocked_ioctl = pc87413_ioctl, |
789fc0adb
|
481 482 483 |
.open = pc87413_open, .release = pc87413_release, }; |
aee334c23
|
484 |
static struct notifier_block pc87413_notifier = { |
00b3b3e66
|
485 |
.notifier_call = pc87413_notify_sys, |
789fc0adb
|
486 |
}; |
aee334c23
|
487 |
static struct miscdevice pc87413_miscdev = { |
00b3b3e66
|
488 489 |
.minor = WATCHDOG_MINOR, .name = "watchdog", |
7944d3a5a
|
490 |
.fops = &pc87413_fops, |
789fc0adb
|
491 |
}; |
00b3b3e66
|
492 |
/* -- Module init functions -------------------------------------*/ |
789fc0adb
|
493 494 |
/** |
5f3b27569
|
495 |
* pc87413_init: module's "constructor" |
789fc0adb
|
496 497 498 499 500 |
* * Set up the WDT watchdog board. All we have to do is grab the * resources we require and bitch if anyone beat us to them. * The open() function will actually kick the board off. */ |
00b3b3e66
|
501 |
static int __init pc87413_init(void) |
789fc0adb
|
502 503 |
{ int ret; |
aee334c23
|
504 505 506 |
printk(KERN_INFO PFX "Version " VERSION " at io 0x%X ", WDT_INDEX_IO_PORT); |
789fc0adb
|
507 508 |
/* request_region(io, 2, "pc87413"); */ |
789fc0adb
|
509 510 |
ret = register_reboot_notifier(&pc87413_notifier); if (ret != 0) { |
aee334c23
|
511 512 513 |
printk(KERN_ERR PFX "cannot register reboot notifier (err=%d) ", ret); |
789fc0adb
|
514 |
} |
789fc0adb
|
515 |
ret = misc_register(&pc87413_miscdev); |
789fc0adb
|
516 |
if (ret != 0) { |
143a2e54b
|
517 518 519 |
printk(KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d) ", |
00b3b3e66
|
520 |
WATCHDOG_MINOR, ret); |
789fc0adb
|
521 522 523 |
unregister_reboot_notifier(&pc87413_notifier); return ret; } |
00b3b3e66
|
524 525 |
printk(KERN_INFO PFX "initialized. timeout=%d min ", timeout); |
00b3b3e66
|
526 |
pc87413_enable(); |
789fc0adb
|
527 528 |
return 0; } |
00b3b3e66
|
529 530 531 532 533 534 535 536 537 538 539 540 541 |
/** * pc87413_exit: module's "destructor" * * Unload the watchdog. You cannot do this with any file handles open. * If your watchdog is set to continue ticking on close and you unload * it, well it keeps ticking. We won't get the interrupt but the board * will not touch PC memory so all is fine. You just have to load a new * module in 60 seconds or reboot. */ static void __exit pc87413_exit(void) { /* Stop the timer before we leave */ |
aee334c23
|
542 |
if (!nowayout) { |
00b3b3e66
|
543 544 545 546 547 548 549 |
pc87413_disable(); printk(KERN_INFO MODNAME "Watchdog disabled. "); } misc_deregister(&pc87413_miscdev); unregister_reboot_notifier(&pc87413_notifier); |
7944d3a5a
|
550 |
/* release_region(io, 2); */ |
00b3b3e66
|
551 |
|
7944d3a5a
|
552 553 |
printk(KERN_INFO MODNAME " watchdog component driver removed. "); |
00b3b3e66
|
554 |
} |
789fc0adb
|
555 556 557 |
module_init(pc87413_init); module_exit(pc87413_exit); |
143a2e54b
|
558 559 |
MODULE_AUTHOR("Sven Anders <anders@anduras.de>, " "Marcus Junker <junker@anduras.de>,"); |
789fc0adb
|
560 |
MODULE_DESCRIPTION("PC87413 WDT driver"); |
00b3b3e66
|
561 |
MODULE_LICENSE("GPL"); |
789fc0adb
|
562 |
MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR); |
00b3b3e66
|
563 |
module_param(io, int, 0); |
76550d329
|
564 565 |
MODULE_PARM_DESC(io, MODNAME " I/O port (default: " __MODULE_STRING(IO_DEFAULT) ")."); |
00b3b3e66
|
566 567 |
module_param(timeout, int, 0); |
aee334c23
|
568 569 |
MODULE_PARM_DESC(timeout, "Watchdog timeout in minutes (default=" |
76550d329
|
570 |
__MODULE_STRING(DEFAULT_TIMEOUT) ")."); |
00b3b3e66
|
571 572 |
module_param(nowayout, int, 0); |
aee334c23
|
573 574 575 |
MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); |
00b3b3e66
|
576 |