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