Blame view

drivers/watchdog/w83697hf_wdt.c 9.95 KB
f9a8c8913   Marcus Junker   [WATCHDOG] w83697...
1
  /*
de710d687   Samuel Tardieu   [WATCHDOG] w83697...
2
   *	w83697hf/hg WDT driver
f9a8c8913   Marcus Junker   [WATCHDOG] w83697...
3
   *
3fdee8db0   Samuel Tardieu   [WATCHDOG] w83697...
4
   *	(c) Copyright 2006 Samuel Tardieu <sam@rfc1149.net>
f9a8c8913   Marcus Junker   [WATCHDOG] w83697...
5
6
   *	(c) Copyright 2006 Marcus Junker <junker@anduras.de>
   *
de710d687   Samuel Tardieu   [WATCHDOG] w83697...
7
8
   *	Based on w83627hf_wdt.c which is based on advantechwdt.c
   *	which is based on wdt.c.
f9a8c8913   Marcus Junker   [WATCHDOG] w83697...
9
10
   *	Original copyright messages:
   *
96de0e252   Jan Engelhardt   Convert files to ...
11
   *	(c) Copyright 2003 Pádraig Brady <P@draigBrady.com>
f9a8c8913   Marcus Junker   [WATCHDOG] w83697...
12
13
14
   *
   *	(c) Copyright 2000-2001 Marek Michalkiewicz <marekm@linux.org.pl>
   *
29fa0586d   Alan Cox   [PATCH] Switch al...
15
16
   *	(c) Copyright 1996 Alan Cox <alan@lxorguk.ukuu.org.uk>,
   *						All Rights Reserved.
f9a8c8913   Marcus Junker   [WATCHDOG] w83697...
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
   *
   *	This program is free software; you can redistribute it and/or
   *	modify it under the terms of the GNU General Public License
   *	as published by the Free Software Foundation; either version
   *	2 of the License, or (at your option) any later version.
   *
   *	Neither Marcus Junker nor ANDURAS AG admit liability nor provide
   *	warranty for any of this software. This material is provided
   *	"AS-IS" and at no charge.
   */
  
  #include <linux/module.h>
  #include <linux/moduleparam.h>
  #include <linux/types.h>
  #include <linux/miscdevice.h>
  #include <linux/watchdog.h>
  #include <linux/fs.h>
  #include <linux/ioport.h>
  #include <linux/notifier.h>
  #include <linux/reboot.h>
  #include <linux/init.h>
ab9d44142   Wim Van Sebroeck   [WATCHDOG] w836?7...
38
  #include <linux/spinlock.h>
c1c8dd39f   Alan Cox   [WATCHDOG 50/57] ...
39
40
  #include <linux/io.h>
  #include <linux/uaccess.h>
f9a8c8913   Marcus Junker   [WATCHDOG] w83697...
41

f9a8c8913   Marcus Junker   [WATCHDOG] w83697...
42
  #include <asm/system.h>
de710d687   Samuel Tardieu   [WATCHDOG] w83697...
43
  #define WATCHDOG_NAME "w83697hf/hg WDT"
f9a8c8913   Marcus Junker   [WATCHDOG] w83697...
44
45
  #define PFX WATCHDOG_NAME ": "
  #define WATCHDOG_TIMEOUT 60		/* 60 sec default timeout */
6fd656012   Samuel Tardieu   [WATCHDOG] Add w8...
46
  #define WATCHDOG_EARLY_DISABLE 1	/* Disable until userland kicks in */
f9a8c8913   Marcus Junker   [WATCHDOG] w83697...
47
48
49
  
  static unsigned long wdt_is_open;
  static char expect_close;
c7dfd0cca   Alexey Dobriyan   [WATCHDOG] spin_l...
50
  static DEFINE_SPINLOCK(io_lock);
f9a8c8913   Marcus Junker   [WATCHDOG] w83697...
51
52
  
  /* You must set this - there is no sane way to probe for this board. */
c81b29962   Samuel Tardieu   [WATCHDOG] w83697...
53
  static int wdt_io = 0x2e;
f9a8c8913   Marcus Junker   [WATCHDOG] w83697...
54
  module_param(wdt_io, int, 0);
c1c8dd39f   Alan Cox   [WATCHDOG 50/57] ...
55
56
  MODULE_PARM_DESC(wdt_io,
  		"w83697hf/hg WDT io port (default 0x2e, 0 = autodetect)");
f9a8c8913   Marcus Junker   [WATCHDOG] w83697...
57
58
59
  
  static int timeout = WATCHDOG_TIMEOUT;	/* in seconds */
  module_param(timeout, int, 0);
c1c8dd39f   Alan Cox   [WATCHDOG 50/57] ...
60
61
62
  MODULE_PARM_DESC(timeout,
  	"Watchdog timeout in seconds. 1<= timeout <=255 (default="
  				__MODULE_STRING(WATCHDOG_TIMEOUT) ")");
f9a8c8913   Marcus Junker   [WATCHDOG] w83697...
63
64
65
  
  static int nowayout = WATCHDOG_NOWAYOUT;
  module_param(nowayout, int, 0);
c1c8dd39f   Alan Cox   [WATCHDOG 50/57] ...
66
67
68
  MODULE_PARM_DESC(nowayout,
  	"Watchdog cannot be stopped once started (default="
  				__MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
f9a8c8913   Marcus Junker   [WATCHDOG] w83697...
69

6fd656012   Samuel Tardieu   [WATCHDOG] Add w8...
70
71
  static int early_disable = WATCHDOG_EARLY_DISABLE;
  module_param(early_disable, int, 0);
c1c8dd39f   Alan Cox   [WATCHDOG 50/57] ...
72
73
74
  MODULE_PARM_DESC(early_disable,
  	"Watchdog gets disabled at boot time (default="
  				__MODULE_STRING(WATCHDOG_EARLY_DISABLE) ")");
6fd656012   Samuel Tardieu   [WATCHDOG] Add w8...
75

f9a8c8913   Marcus Junker   [WATCHDOG] w83697...
76
77
78
  /*
   *	Kernel methods.
   */
c1c8dd39f   Alan Cox   [WATCHDOG 50/57] ...
79
80
81
82
  #define W83697HF_EFER (wdt_io + 0)  /* Extended Function Enable Register */
  #define W83697HF_EFIR (wdt_io + 0)  /* Extended Function Index Register
  							(same as EFER) */
  #define W83697HF_EFDR (wdt_io + 1)  /* Extended Function Data Register */
f9a8c8913   Marcus Junker   [WATCHDOG] w83697...
83

c1c8dd39f   Alan Cox   [WATCHDOG 50/57] ...
84
  static inline void w83697hf_unlock(void)
f9a8c8913   Marcus Junker   [WATCHDOG] w83697...
85
  {
44d7d3282   Samuel Tardieu   [WATCHDOG] w83697...
86
87
  	outb_p(0x87, W83697HF_EFER);	/* Enter extended function mode */
  	outb_p(0x87, W83697HF_EFER);	/* Again according to manual */
f7be3328b   Samuel Tardieu   [WATCHDOG] w83697...
88
  }
c1c8dd39f   Alan Cox   [WATCHDOG 50/57] ...
89
  static inline void w83697hf_lock(void)
fe851ebad   Samuel Tardieu   [WATCHDOG] w83697...
90
91
92
  {
  	outb_p(0xAA, W83697HF_EFER);	/* Leave extended function mode */
  }
0cd544763   Samuel Tardieu   [WATCHDOG] w83697...
93
  /*
d46ab596e   Samuel Tardieu   [WATCHDOG] w83697...
94
95
   *	The three functions w83697hf_get_reg(), w83697hf_set_reg() and
   *	w83697hf_write_timeout() must be called with the device unlocked.
0cd544763   Samuel Tardieu   [WATCHDOG] w83697...
96
   */
c1c8dd39f   Alan Cox   [WATCHDOG 50/57] ...
97
  static unsigned char w83697hf_get_reg(unsigned char reg)
0cd544763   Samuel Tardieu   [WATCHDOG] w83697...
98
99
100
101
  {
  	outb_p(reg, W83697HF_EFIR);
  	return inb_p(W83697HF_EFDR);
  }
c1c8dd39f   Alan Cox   [WATCHDOG 50/57] ...
102
  static void w83697hf_set_reg(unsigned char reg, unsigned char data)
0cd544763   Samuel Tardieu   [WATCHDOG] w83697...
103
104
105
106
  {
  	outb_p(reg, W83697HF_EFIR);
  	outb_p(data, W83697HF_EFDR);
  }
c1c8dd39f   Alan Cox   [WATCHDOG 50/57] ...
107
  static void w83697hf_write_timeout(int timeout)
d46ab596e   Samuel Tardieu   [WATCHDOG] w83697...
108
  {
c1c8dd39f   Alan Cox   [WATCHDOG 50/57] ...
109
110
  	/* Write Timeout counter to CRF4 */
  	w83697hf_set_reg(0xF4, timeout);
d46ab596e   Samuel Tardieu   [WATCHDOG] w83697...
111
  }
c1c8dd39f   Alan Cox   [WATCHDOG 50/57] ...
112
  static void w83697hf_select_wdt(void)
a7933e05d   Samuel Tardieu   [WATCHDOG] w83697...
113
114
115
116
  {
  	w83697hf_unlock();
  	w83697hf_set_reg(0x07, 0x08);	/* Switch to logic device 8 (GPIO2) */
  }
c1c8dd39f   Alan Cox   [WATCHDOG 50/57] ...
117
  static inline void w83697hf_deselect_wdt(void)
a7933e05d   Samuel Tardieu   [WATCHDOG] w83697...
118
119
120
  {
  	w83697hf_lock();
  }
c1c8dd39f   Alan Cox   [WATCHDOG 50/57] ...
121
  static void w83697hf_init(void)
f9a8c8913   Marcus Junker   [WATCHDOG] w83697...
122
  {
b7b9868ba   Samuel Tardieu   [WATCHDOG] w83697...
123
  	unsigned char bbuf;
f9a8c8913   Marcus Junker   [WATCHDOG] w83697...
124

fa69afd3c   Samuel Tardieu   [WATCHDOG] w83697...
125
  	w83697hf_select_wdt();
b7b9868ba   Samuel Tardieu   [WATCHDOG] w83697...
126
127
128
  	bbuf = w83697hf_get_reg(0x29);
  	bbuf &= ~0x60;
  	bbuf |= 0x20;
c1c8dd39f   Alan Cox   [WATCHDOG 50/57] ...
129
130
131
  
  	/* Set pin 119 to WDTO# mode (= CR29, WDT0) */
  	w83697hf_set_reg(0x29, bbuf);
f9a8c8913   Marcus Junker   [WATCHDOG] w83697...
132

b7b9868ba   Samuel Tardieu   [WATCHDOG] w83697...
133
134
135
  	bbuf = w83697hf_get_reg(0xF3);
  	bbuf &= ~0x04;
  	w83697hf_set_reg(0xF3, bbuf);	/* Count mode is seconds */
f9a8c8913   Marcus Junker   [WATCHDOG] w83697...
136

fa69afd3c   Samuel Tardieu   [WATCHDOG] w83697...
137
  	w83697hf_deselect_wdt();
f9a8c8913   Marcus Junker   [WATCHDOG] w83697...
138
  }
c1c8dd39f   Alan Cox   [WATCHDOG 50/57] ...
139
  static void wdt_ping(void)
f9a8c8913   Marcus Junker   [WATCHDOG] w83697...
140
  {
ab9d44142   Wim Van Sebroeck   [WATCHDOG] w836?7...
141
  	spin_lock(&io_lock);
a7933e05d   Samuel Tardieu   [WATCHDOG] w83697...
142
  	w83697hf_select_wdt();
f9a8c8913   Marcus Junker   [WATCHDOG] w83697...
143

d46ab596e   Samuel Tardieu   [WATCHDOG] w83697...
144
  	w83697hf_write_timeout(timeout);
f9a8c8913   Marcus Junker   [WATCHDOG] w83697...
145

a7933e05d   Samuel Tardieu   [WATCHDOG] w83697...
146
  	w83697hf_deselect_wdt();
ab9d44142   Wim Van Sebroeck   [WATCHDOG] w836?7...
147
  	spin_unlock(&io_lock);
f9a8c8913   Marcus Junker   [WATCHDOG] w83697...
148
  }
c1c8dd39f   Alan Cox   [WATCHDOG 50/57] ...
149
  static void wdt_enable(void)
f9a8c8913   Marcus Junker   [WATCHDOG] w83697...
150
  {
089d8139f   Samuel Tardieu   [WATCHDOG] w83697...
151
152
153
154
155
156
157
158
  	spin_lock(&io_lock);
  	w83697hf_select_wdt();
  
  	w83697hf_write_timeout(timeout);
  	w83697hf_set_reg(0x30, 1);	/* Enable timer */
  
  	w83697hf_deselect_wdt();
  	spin_unlock(&io_lock);
f9a8c8913   Marcus Junker   [WATCHDOG] w83697...
159
  }
c1c8dd39f   Alan Cox   [WATCHDOG 50/57] ...
160
  static void wdt_disable(void)
f9a8c8913   Marcus Junker   [WATCHDOG] w83697...
161
  {
089d8139f   Samuel Tardieu   [WATCHDOG] w83697...
162
163
164
165
166
167
168
169
  	spin_lock(&io_lock);
  	w83697hf_select_wdt();
  
  	w83697hf_set_reg(0x30, 0);	/* Disable timer */
  	w83697hf_write_timeout(0);
  
  	w83697hf_deselect_wdt();
  	spin_unlock(&io_lock);
f9a8c8913   Marcus Junker   [WATCHDOG] w83697...
170
  }
c1c8dd39f   Alan Cox   [WATCHDOG 50/57] ...
171
  static unsigned char wdt_running(void)
6fd656012   Samuel Tardieu   [WATCHDOG] Add w8...
172
173
174
175
176
177
178
179
180
181
182
183
184
  {
  	unsigned char t;
  
  	spin_lock(&io_lock);
  	w83697hf_select_wdt();
  
  	t = w83697hf_get_reg(0xF4);	/* Read timer */
  
  	w83697hf_deselect_wdt();
  	spin_unlock(&io_lock);
  
  	return t;
  }
c1c8dd39f   Alan Cox   [WATCHDOG 50/57] ...
185
  static int wdt_set_heartbeat(int t)
f9a8c8913   Marcus Junker   [WATCHDOG] w83697...
186
  {
c1c8dd39f   Alan Cox   [WATCHDOG 50/57] ...
187
  	if (t < 1 || t > 255)
f9a8c8913   Marcus Junker   [WATCHDOG] w83697...
188
189
190
191
192
  		return -EINVAL;
  
  	timeout = t;
  	return 0;
  }
c1c8dd39f   Alan Cox   [WATCHDOG 50/57] ...
193
194
  static ssize_t wdt_write(struct file *file, const char __user *buf,
  						size_t count, loff_t *ppos)
f9a8c8913   Marcus Junker   [WATCHDOG] w83697...
195
196
197
198
199
200
201
202
203
  {
  	if (count) {
  		if (!nowayout) {
  			size_t i;
  
  			expect_close = 0;
  
  			for (i = 0; i != count; i++) {
  				char c;
7944d3a5a   Wim Van Sebroeck   [WATCHDOG] more c...
204
  				if (get_user(c, buf + i))
f9a8c8913   Marcus Junker   [WATCHDOG] w83697...
205
206
207
208
209
210
211
212
213
  					return -EFAULT;
  				if (c == 'V')
  					expect_close = 42;
  			}
  		}
  		wdt_ping();
  	}
  	return count;
  }
c1c8dd39f   Alan Cox   [WATCHDOG 50/57] ...
214
  static long wdt_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
f9a8c8913   Marcus Junker   [WATCHDOG] w83697...
215
216
217
218
  {
  	void __user *argp = (void __user *)arg;
  	int __user *p = argp;
  	int new_timeout;
c1c8dd39f   Alan Cox   [WATCHDOG 50/57] ...
219
220
221
  	static const struct watchdog_info ident = {
  		.options = WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT
  							| WDIOF_MAGICCLOSE,
f9a8c8913   Marcus Junker   [WATCHDOG] w83697...
222
223
224
225
226
227
  		.firmware_version = 1,
  		.identity = "W83697HF WDT",
  	};
  
  	switch (cmd) {
  	case WDIOC_GETSUPPORT:
db16525e6   Samuel Tardieu   [WATCHDOG] w83697...
228
229
230
  		if (copy_to_user(argp, &ident, sizeof(ident)))
  			return -EFAULT;
  		break;
f9a8c8913   Marcus Junker   [WATCHDOG] w83697...
231
232
233
  
  	case WDIOC_GETSTATUS:
  	case WDIOC_GETBOOTSTATUS:
db16525e6   Samuel Tardieu   [WATCHDOG] w83697...
234
  		return put_user(0, p);
f9a8c8913   Marcus Junker   [WATCHDOG] w83697...
235

f9a8c8913   Marcus Junker   [WATCHDOG] w83697...
236
237
  	case WDIOC_SETOPTIONS:
  	{
db16525e6   Samuel Tardieu   [WATCHDOG] w83697...
238
  		int options, retval = -EINVAL;
f9a8c8913   Marcus Junker   [WATCHDOG] w83697...
239

db16525e6   Samuel Tardieu   [WATCHDOG] w83697...
240
241
  		if (get_user(options, p))
  			return -EFAULT;
f9a8c8913   Marcus Junker   [WATCHDOG] w83697...
242

db16525e6   Samuel Tardieu   [WATCHDOG] w83697...
243
244
245
246
  		if (options & WDIOS_DISABLECARD) {
  			wdt_disable();
  			retval = 0;
  		}
f9a8c8913   Marcus Junker   [WATCHDOG] w83697...
247

db16525e6   Samuel Tardieu   [WATCHDOG] w83697...
248
  		if (options & WDIOS_ENABLECARD) {
089d8139f   Samuel Tardieu   [WATCHDOG] w83697...
249
  			wdt_enable();
db16525e6   Samuel Tardieu   [WATCHDOG] w83697...
250
251
  			retval = 0;
  		}
f9a8c8913   Marcus Junker   [WATCHDOG] w83697...
252

db16525e6   Samuel Tardieu   [WATCHDOG] w83697...
253
  		return retval;
f9a8c8913   Marcus Junker   [WATCHDOG] w83697...
254
  	}
0c06090c9   Wim Van Sebroeck   [WATCHDOG] Coding...
255
256
257
258
259
260
261
262
263
264
265
266
267
268
  	case WDIOC_KEEPALIVE:
  		wdt_ping();
  		break;
  
  	case WDIOC_SETTIMEOUT:
  		if (get_user(new_timeout, p))
  			return -EFAULT;
  		if (wdt_set_heartbeat(new_timeout))
  			return -EINVAL;
  		wdt_ping();
  		/* Fall */
  
  	case WDIOC_GETTIMEOUT:
  		return put_user(timeout, p);
f9a8c8913   Marcus Junker   [WATCHDOG] w83697...
269
  	default:
db16525e6   Samuel Tardieu   [WATCHDOG] w83697...
270
  		return -ENOTTY;
f9a8c8913   Marcus Junker   [WATCHDOG] w83697...
271
272
273
  	}
  	return 0;
  }
c1c8dd39f   Alan Cox   [WATCHDOG 50/57] ...
274
  static int wdt_open(struct inode *inode, struct file *file)
f9a8c8913   Marcus Junker   [WATCHDOG] w83697...
275
276
277
278
279
280
  {
  	if (test_and_set_bit(0, &wdt_is_open))
  		return -EBUSY;
  	/*
  	 *	Activate
  	 */
089d8139f   Samuel Tardieu   [WATCHDOG] w83697...
281
  	wdt_enable();
f9a8c8913   Marcus Junker   [WATCHDOG] w83697...
282
283
  	return nonseekable_open(inode, file);
  }
c1c8dd39f   Alan Cox   [WATCHDOG 50/57] ...
284
  static int wdt_close(struct inode *inode, struct file *file)
f9a8c8913   Marcus Junker   [WATCHDOG] w83697...
285
  {
c1c8dd39f   Alan Cox   [WATCHDOG 50/57] ...
286
  	if (expect_close == 42)
f9a8c8913   Marcus Junker   [WATCHDOG] w83697...
287
  		wdt_disable();
c1c8dd39f   Alan Cox   [WATCHDOG 50/57] ...
288
289
290
291
  	else {
  		printk(KERN_CRIT PFX
  			"Unexpected close, not stopping watchdog!
  ");
f9a8c8913   Marcus Junker   [WATCHDOG] w83697...
292
293
294
295
296
297
298
299
300
301
  		wdt_ping();
  	}
  	expect_close = 0;
  	clear_bit(0, &wdt_is_open);
  	return 0;
  }
  
  /*
   *	Notifier for system down
   */
c1c8dd39f   Alan Cox   [WATCHDOG 50/57] ...
302
  static int wdt_notify_sys(struct notifier_block *this, unsigned long code,
f9a8c8913   Marcus Junker   [WATCHDOG] w83697...
303
304
  	void *unused)
  {
7944d3a5a   Wim Van Sebroeck   [WATCHDOG] more c...
305
306
  	if (code == SYS_DOWN || code == SYS_HALT)
  		wdt_disable();	/* Turn the WDT off */
f9a8c8913   Marcus Junker   [WATCHDOG] w83697...
307
308
309
310
311
312
  	return NOTIFY_DONE;
  }
  
  /*
   *	Kernel Interfaces
   */
2b8693c06   Arjan van de Ven   [PATCH] mark stru...
313
  static const struct file_operations wdt_fops = {
f9a8c8913   Marcus Junker   [WATCHDOG] w83697...
314
315
316
  	.owner		= THIS_MODULE,
  	.llseek		= no_llseek,
  	.write		= wdt_write,
c1c8dd39f   Alan Cox   [WATCHDOG 50/57] ...
317
  	.unlocked_ioctl	= wdt_ioctl,
f9a8c8913   Marcus Junker   [WATCHDOG] w83697...
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
  	.open		= wdt_open,
  	.release	= wdt_close,
  };
  
  static struct miscdevice wdt_miscdev = {
  	.minor = WATCHDOG_MINOR,
  	.name = "watchdog",
  	.fops = &wdt_fops,
  };
  
  /*
   *	The WDT needs to learn about soft shutdowns in order to
   *	turn the timebomb registers off.
   */
  
  static struct notifier_block wdt_notifier = {
  	.notifier_call = wdt_notify_sys,
  };
c1c8dd39f   Alan Cox   [WATCHDOG 50/57] ...
336
  static int w83697hf_check_wdt(void)
c81b29962   Samuel Tardieu   [WATCHDOG] w83697...
337
338
  {
  	if (!request_region(wdt_io, 2, WATCHDOG_NAME)) {
c1c8dd39f   Alan Cox   [WATCHDOG 50/57] ...
339
340
341
  		printk(KERN_ERR PFX
  			"I/O address 0x%x already in use
  ", wdt_io);
c81b29962   Samuel Tardieu   [WATCHDOG] w83697...
342
343
  		return -EIO;
  	}
c1c8dd39f   Alan Cox   [WATCHDOG 50/57] ...
344
345
346
  	printk(KERN_DEBUG PFX
  			"Looking for watchdog at address 0x%x
  ", wdt_io);
c81b29962   Samuel Tardieu   [WATCHDOG] w83697...
347
348
  	w83697hf_unlock();
  	if (w83697hf_get_reg(0x20) == 0x60) {
c1c8dd39f   Alan Cox   [WATCHDOG 50/57] ...
349
350
351
  		printk(KERN_INFO PFX
  			"watchdog found at address 0x%x
  ", wdt_io);
c81b29962   Samuel Tardieu   [WATCHDOG] w83697...
352
353
354
  		w83697hf_lock();
  		return 0;
  	}
c1c8dd39f   Alan Cox   [WATCHDOG 50/57] ...
355
356
  	/* Reprotect in case it was a compatible device */
  	w83697hf_lock();
c81b29962   Samuel Tardieu   [WATCHDOG] w83697...
357

c1c8dd39f   Alan Cox   [WATCHDOG 50/57] ...
358
359
  	printk(KERN_INFO PFX "watchdog not found at address 0x%x
  ", wdt_io);
c81b29962   Samuel Tardieu   [WATCHDOG] w83697...
360
361
362
  	release_region(wdt_io, 2);
  	return -EIO;
  }
e223f01a8   Wim Van Sebroeck   [WATCHDOG] w83697...
363
  static int w83697hf_ioports[] = { 0x2e, 0x4e, 0x00 };
c1c8dd39f   Alan Cox   [WATCHDOG 50/57] ...
364
  static int __init wdt_init(void)
f9a8c8913   Marcus Junker   [WATCHDOG] w83697...
365
  {
e223f01a8   Wim Van Sebroeck   [WATCHDOG] w83697...
366
  	int ret, i, found = 0;
f9a8c8913   Marcus Junker   [WATCHDOG] w83697...
367

c1c8dd39f   Alan Cox   [WATCHDOG 50/57] ...
368
369
  	printk(KERN_INFO PFX "WDT driver for W83697HF/HG initializing
  ");
f9a8c8913   Marcus Junker   [WATCHDOG] w83697...
370

e223f01a8   Wim Van Sebroeck   [WATCHDOG] w83697...
371
372
373
374
  	if (wdt_io == 0) {
  		/* we will autodetect the W83697HF/HG watchdog */
  		for (i = 0; ((!found) && (w83697hf_ioports[i] != 0)); i++) {
  			wdt_io = w83697hf_ioports[i];
cde10ba3b   Wim Van Sebroeck   [WATCHDOG] Revert...
375
  			if (!w83697hf_check_wdt())
e223f01a8   Wim Van Sebroeck   [WATCHDOG] w83697...
376
377
378
  				found++;
  		}
  	} else {
c81b29962   Samuel Tardieu   [WATCHDOG] w83697...
379
  		if (!w83697hf_check_wdt())
e223f01a8   Wim Van Sebroeck   [WATCHDOG] w83697...
380
  			found++;
c81b29962   Samuel Tardieu   [WATCHDOG] w83697...
381
  	}
e223f01a8   Wim Van Sebroeck   [WATCHDOG] w83697...
382
  	if (!found) {
c1c8dd39f   Alan Cox   [WATCHDOG 50/57] ...
383
384
  		printk(KERN_ERR PFX "No W83697HF/HG could be found
  ");
e223f01a8   Wim Van Sebroeck   [WATCHDOG] w83697...
385
386
387
  		ret = -EIO;
  		goto out;
  	}
c81b29962   Samuel Tardieu   [WATCHDOG] w83697...
388

fa69afd3c   Samuel Tardieu   [WATCHDOG] w83697...
389
  	w83697hf_init();
6fd656012   Samuel Tardieu   [WATCHDOG] Add w8...
390
391
  	if (early_disable) {
  		if (wdt_running())
a77dba7e4   Wim Van Sebroeck   [WATCHDOG] Some m...
392
393
394
  			printk(KERN_WARNING PFX "Stopping previously enabled "
  					"watchdog until userland kicks in
  ");
6fd656012   Samuel Tardieu   [WATCHDOG] Add w8...
395
396
  		wdt_disable();
  	}
c81b29962   Samuel Tardieu   [WATCHDOG] w83697...
397

f9a8c8913   Marcus Junker   [WATCHDOG] w83697...
398
399
  	if (wdt_set_heartbeat(timeout)) {
  		wdt_set_heartbeat(WATCHDOG_TIMEOUT);
c1c8dd39f   Alan Cox   [WATCHDOG 50/57] ...
400
401
402
403
  		printk(KERN_INFO PFX
  		     "timeout value must be 1 <= timeout <= 255, using %d
  ",
  							WATCHDOG_TIMEOUT);
f9a8c8913   Marcus Junker   [WATCHDOG] w83697...
404
  	}
f9a8c8913   Marcus Junker   [WATCHDOG] w83697...
405
406
  	ret = register_reboot_notifier(&wdt_notifier);
  	if (ret != 0) {
c1c8dd39f   Alan Cox   [WATCHDOG 50/57] ...
407
408
409
  		printk(KERN_ERR PFX
  			"cannot register reboot notifier (err=%d)
  ", ret);
f9a8c8913   Marcus Junker   [WATCHDOG] w83697...
410
411
412
413
414
  		goto unreg_regions;
  	}
  
  	ret = misc_register(&wdt_miscdev);
  	if (ret != 0) {
c1c8dd39f   Alan Cox   [WATCHDOG 50/57] ...
415
416
417
418
  		printk(KERN_ERR PFX
  			"cannot register miscdev on minor=%d (err=%d)
  ",
  						WATCHDOG_MINOR, ret);
f9a8c8913   Marcus Junker   [WATCHDOG] w83697...
419
420
  		goto unreg_reboot;
  	}
c1c8dd39f   Alan Cox   [WATCHDOG 50/57] ...
421
422
  	printk(KERN_INFO PFX "initialized. timeout=%d sec (nowayout=%d)
  ",
f9a8c8913   Marcus Junker   [WATCHDOG] w83697...
423
424
425
426
427
428
429
  		timeout, nowayout);
  
  out:
  	return ret;
  unreg_reboot:
  	unregister_reboot_notifier(&wdt_notifier);
  unreg_regions:
b41a9f59d   Samuel Tardieu   [WATCHDOG] w83697...
430
  	release_region(wdt_io, 2);
f9a8c8913   Marcus Junker   [WATCHDOG] w83697...
431
432
  	goto out;
  }
c1c8dd39f   Alan Cox   [WATCHDOG 50/57] ...
433
  static void __exit wdt_exit(void)
f9a8c8913   Marcus Junker   [WATCHDOG] w83697...
434
435
436
  {
  	misc_deregister(&wdt_miscdev);
  	unregister_reboot_notifier(&wdt_notifier);
b41a9f59d   Samuel Tardieu   [WATCHDOG] w83697...
437
  	release_region(wdt_io, 2);
f9a8c8913   Marcus Junker   [WATCHDOG] w83697...
438
439
440
441
442
443
  }
  
  module_init(wdt_init);
  module_exit(wdt_exit);
  
  MODULE_LICENSE("GPL");
143a2e54b   Wim Van Sebroeck   [WATCHDOG] More c...
444
445
  MODULE_AUTHOR("Marcus Junker <junker@anduras.de>, "
  		"Samuel Tardieu <sam@rfc1149.net>");
de710d687   Samuel Tardieu   [WATCHDOG] w83697...
446
  MODULE_DESCRIPTION("w83697hf/hg WDT driver");
f9a8c8913   Marcus Junker   [WATCHDOG] w83697...
447
  MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);