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