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