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