blob: f5c9d9901acce293c5d1fa9d22b9454ea298d2e7 [file] [log] [blame]
Marcus Junkerf9a8c892006-08-24 17:11:50 +02001/*
Samuel Tardieude710d62006-09-07 11:57:00 +02002 * w83697hf/hg WDT driver
Marcus Junkerf9a8c892006-08-24 17:11:50 +02003 *
Samuel Tardieu3fdee8d2006-09-07 11:57:00 +02004 * (c) Copyright 2006 Samuel Tardieu <sam@rfc1149.net>
Marcus Junkerf9a8c892006-08-24 17:11:50 +02005 * (c) Copyright 2006 Marcus Junker <junker@anduras.de>
6 *
Samuel Tardieude710d62006-09-07 11:57:00 +02007 * Based on w83627hf_wdt.c which is based on advantechwdt.c
8 * which is based on wdt.c.
Marcus Junkerf9a8c892006-08-24 17:11:50 +02009 * Original copyright messages:
10 *
Jan Engelhardt96de0e22007-10-19 23:21:04 +020011 * (c) Copyright 2003 Pádraig Brady <P@draigBrady.com>
Marcus Junkerf9a8c892006-08-24 17:11:50 +020012 *
13 * (c) Copyright 2000-2001 Marek Michalkiewicz <marekm@linux.org.pl>
14 *
Alan Cox29fa0582008-10-27 15:17:56 +000015 * (c) Copyright 1996 Alan Cox <alan@lxorguk.ukuu.org.uk>,
16 * All Rights Reserved.
Marcus Junkerf9a8c892006-08-24 17:11:50 +020017 *
18 * This program is free software; you can redistribute it and/or
19 * modify it under the terms of the GNU General Public License
20 * as published by the Free Software Foundation; either version
21 * 2 of the License, or (at your option) any later version.
22 *
23 * Neither Marcus Junker nor ANDURAS AG admit liability nor provide
24 * warranty for any of this software. This material is provided
25 * "AS-IS" and at no charge.
26 */
27
Joe Perches27c766a2012-02-15 15:06:19 -080028#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
29
Marcus Junkerf9a8c892006-08-24 17:11:50 +020030#include <linux/module.h>
31#include <linux/moduleparam.h>
32#include <linux/types.h>
33#include <linux/miscdevice.h>
34#include <linux/watchdog.h>
35#include <linux/fs.h>
36#include <linux/ioport.h>
37#include <linux/notifier.h>
38#include <linux/reboot.h>
39#include <linux/init.h>
Wim Van Sebroeckab9d4412006-09-02 18:50:20 +020040#include <linux/spinlock.h>
Alan Coxc1c8dd32008-05-19 14:09:23 +010041#include <linux/io.h>
42#include <linux/uaccess.h>
Marcus Junkerf9a8c892006-08-24 17:11:50 +020043
Marcus Junkerf9a8c892006-08-24 17:11:50 +020044#include <asm/system.h>
45
Samuel Tardieude710d62006-09-07 11:57:00 +020046#define WATCHDOG_NAME "w83697hf/hg WDT"
Marcus Junkerf9a8c892006-08-24 17:11:50 +020047#define WATCHDOG_TIMEOUT 60 /* 60 sec default timeout */
Samuel Tardieu6fd65602008-03-12 14:28:03 +010048#define WATCHDOG_EARLY_DISABLE 1 /* Disable until userland kicks in */
Marcus Junkerf9a8c892006-08-24 17:11:50 +020049
50static unsigned long wdt_is_open;
51static char expect_close;
Alexey Dobriyanc7dfd0c2007-11-01 16:27:08 -070052static DEFINE_SPINLOCK(io_lock);
Marcus Junkerf9a8c892006-08-24 17:11:50 +020053
54/* You must set this - there is no sane way to probe for this board. */
Samuel Tardieuc81b2992006-09-07 11:57:00 +020055static int wdt_io = 0x2e;
Marcus Junkerf9a8c892006-08-24 17:11:50 +020056module_param(wdt_io, int, 0);
Alan Coxc1c8dd32008-05-19 14:09:23 +010057MODULE_PARM_DESC(wdt_io,
58 "w83697hf/hg WDT io port (default 0x2e, 0 = autodetect)");
Marcus Junkerf9a8c892006-08-24 17:11:50 +020059
60static int timeout = WATCHDOG_TIMEOUT; /* in seconds */
61module_param(timeout, int, 0);
Alan Coxc1c8dd32008-05-19 14:09:23 +010062MODULE_PARM_DESC(timeout,
63 "Watchdog timeout in seconds. 1<= timeout <=255 (default="
64 __MODULE_STRING(WATCHDOG_TIMEOUT) ")");
Marcus Junkerf9a8c892006-08-24 17:11:50 +020065
Wim Van Sebroeck86a1e182012-03-05 16:51:11 +010066static bool nowayout = WATCHDOG_NOWAYOUT;
67module_param(nowayout, bool, 0);
Alan Coxc1c8dd32008-05-19 14:09:23 +010068MODULE_PARM_DESC(nowayout,
69 "Watchdog cannot be stopped once started (default="
70 __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
Marcus Junkerf9a8c892006-08-24 17:11:50 +020071
Samuel Tardieu6fd65602008-03-12 14:28:03 +010072static int early_disable = WATCHDOG_EARLY_DISABLE;
73module_param(early_disable, int, 0);
Alan Coxc1c8dd32008-05-19 14:09:23 +010074MODULE_PARM_DESC(early_disable,
75 "Watchdog gets disabled at boot time (default="
76 __MODULE_STRING(WATCHDOG_EARLY_DISABLE) ")");
Samuel Tardieu6fd65602008-03-12 14:28:03 +010077
Marcus Junkerf9a8c892006-08-24 17:11:50 +020078/*
79 * Kernel methods.
80 */
81
Alan Coxc1c8dd32008-05-19 14:09:23 +010082#define W83697HF_EFER (wdt_io + 0) /* Extended Function Enable Register */
83#define W83697HF_EFIR (wdt_io + 0) /* Extended Function Index Register
84 (same as EFER) */
85#define W83697HF_EFDR (wdt_io + 1) /* Extended Function Data Register */
Marcus Junkerf9a8c892006-08-24 17:11:50 +020086
Alan Coxc1c8dd32008-05-19 14:09:23 +010087static inline void w83697hf_unlock(void)
Marcus Junkerf9a8c892006-08-24 17:11:50 +020088{
Samuel Tardieu44d7d322006-09-07 11:57:00 +020089 outb_p(0x87, W83697HF_EFER); /* Enter extended function mode */
90 outb_p(0x87, W83697HF_EFER); /* Again according to manual */
Samuel Tardieuf7be3322006-09-07 11:57:00 +020091}
92
Alan Coxc1c8dd32008-05-19 14:09:23 +010093static inline void w83697hf_lock(void)
Samuel Tardieufe851eb2006-09-07 11:57:00 +020094{
95 outb_p(0xAA, W83697HF_EFER); /* Leave extended function mode */
96}
97
Samuel Tardieu0cd54472006-09-07 11:57:00 +020098/*
Samuel Tardieud46ab592006-09-07 11:57:00 +020099 * The three functions w83697hf_get_reg(), w83697hf_set_reg() and
100 * w83697hf_write_timeout() must be called with the device unlocked.
Samuel Tardieu0cd54472006-09-07 11:57:00 +0200101 */
102
Alan Coxc1c8dd32008-05-19 14:09:23 +0100103static unsigned char w83697hf_get_reg(unsigned char reg)
Samuel Tardieu0cd54472006-09-07 11:57:00 +0200104{
105 outb_p(reg, W83697HF_EFIR);
106 return inb_p(W83697HF_EFDR);
107}
108
Alan Coxc1c8dd32008-05-19 14:09:23 +0100109static void w83697hf_set_reg(unsigned char reg, unsigned char data)
Samuel Tardieu0cd54472006-09-07 11:57:00 +0200110{
111 outb_p(reg, W83697HF_EFIR);
112 outb_p(data, W83697HF_EFDR);
113}
114
Alan Coxc1c8dd32008-05-19 14:09:23 +0100115static void w83697hf_write_timeout(int timeout)
Samuel Tardieud46ab592006-09-07 11:57:00 +0200116{
Alan Coxc1c8dd32008-05-19 14:09:23 +0100117 /* Write Timeout counter to CRF4 */
118 w83697hf_set_reg(0xF4, timeout);
Samuel Tardieud46ab592006-09-07 11:57:00 +0200119}
120
Alan Coxc1c8dd32008-05-19 14:09:23 +0100121static void w83697hf_select_wdt(void)
Samuel Tardieua7933e02006-09-07 11:57:00 +0200122{
123 w83697hf_unlock();
124 w83697hf_set_reg(0x07, 0x08); /* Switch to logic device 8 (GPIO2) */
125}
126
Alan Coxc1c8dd32008-05-19 14:09:23 +0100127static inline void w83697hf_deselect_wdt(void)
Samuel Tardieua7933e02006-09-07 11:57:00 +0200128{
129 w83697hf_lock();
130}
131
Alan Coxc1c8dd32008-05-19 14:09:23 +0100132static void w83697hf_init(void)
Marcus Junkerf9a8c892006-08-24 17:11:50 +0200133{
Samuel Tardieub7b98682006-09-07 11:57:00 +0200134 unsigned char bbuf;
Marcus Junkerf9a8c892006-08-24 17:11:50 +0200135
Samuel Tardieufa69afd2006-09-07 11:57:00 +0200136 w83697hf_select_wdt();
137
Samuel Tardieub7b98682006-09-07 11:57:00 +0200138 bbuf = w83697hf_get_reg(0x29);
139 bbuf &= ~0x60;
140 bbuf |= 0x20;
Alan Coxc1c8dd32008-05-19 14:09:23 +0100141
142 /* Set pin 119 to WDTO# mode (= CR29, WDT0) */
143 w83697hf_set_reg(0x29, bbuf);
Marcus Junkerf9a8c892006-08-24 17:11:50 +0200144
Samuel Tardieub7b98682006-09-07 11:57:00 +0200145 bbuf = w83697hf_get_reg(0xF3);
146 bbuf &= ~0x04;
147 w83697hf_set_reg(0xF3, bbuf); /* Count mode is seconds */
Marcus Junkerf9a8c892006-08-24 17:11:50 +0200148
Samuel Tardieufa69afd2006-09-07 11:57:00 +0200149 w83697hf_deselect_wdt();
Marcus Junkerf9a8c892006-08-24 17:11:50 +0200150}
151
Alan Coxc1c8dd32008-05-19 14:09:23 +0100152static void wdt_ping(void)
Marcus Junkerf9a8c892006-08-24 17:11:50 +0200153{
Wim Van Sebroeckab9d4412006-09-02 18:50:20 +0200154 spin_lock(&io_lock);
Samuel Tardieua7933e02006-09-07 11:57:00 +0200155 w83697hf_select_wdt();
Marcus Junkerf9a8c892006-08-24 17:11:50 +0200156
Samuel Tardieud46ab592006-09-07 11:57:00 +0200157 w83697hf_write_timeout(timeout);
Marcus Junkerf9a8c892006-08-24 17:11:50 +0200158
Samuel Tardieua7933e02006-09-07 11:57:00 +0200159 w83697hf_deselect_wdt();
Wim Van Sebroeckab9d4412006-09-02 18:50:20 +0200160 spin_unlock(&io_lock);
Marcus Junkerf9a8c892006-08-24 17:11:50 +0200161}
162
Alan Coxc1c8dd32008-05-19 14:09:23 +0100163static void wdt_enable(void)
Marcus Junkerf9a8c892006-08-24 17:11:50 +0200164{
Samuel Tardieu089d8132006-09-07 11:57:00 +0200165 spin_lock(&io_lock);
166 w83697hf_select_wdt();
167
168 w83697hf_write_timeout(timeout);
169 w83697hf_set_reg(0x30, 1); /* Enable timer */
170
171 w83697hf_deselect_wdt();
172 spin_unlock(&io_lock);
Marcus Junkerf9a8c892006-08-24 17:11:50 +0200173}
174
Alan Coxc1c8dd32008-05-19 14:09:23 +0100175static void wdt_disable(void)
Marcus Junkerf9a8c892006-08-24 17:11:50 +0200176{
Samuel Tardieu089d8132006-09-07 11:57:00 +0200177 spin_lock(&io_lock);
178 w83697hf_select_wdt();
179
180 w83697hf_set_reg(0x30, 0); /* Disable timer */
181 w83697hf_write_timeout(0);
182
183 w83697hf_deselect_wdt();
184 spin_unlock(&io_lock);
Marcus Junkerf9a8c892006-08-24 17:11:50 +0200185}
186
Alan Coxc1c8dd32008-05-19 14:09:23 +0100187static unsigned char wdt_running(void)
Samuel Tardieu6fd65602008-03-12 14:28:03 +0100188{
189 unsigned char t;
190
191 spin_lock(&io_lock);
192 w83697hf_select_wdt();
193
194 t = w83697hf_get_reg(0xF4); /* Read timer */
195
196 w83697hf_deselect_wdt();
197 spin_unlock(&io_lock);
198
199 return t;
200}
201
Alan Coxc1c8dd32008-05-19 14:09:23 +0100202static int wdt_set_heartbeat(int t)
Marcus Junkerf9a8c892006-08-24 17:11:50 +0200203{
Alan Coxc1c8dd32008-05-19 14:09:23 +0100204 if (t < 1 || t > 255)
Marcus Junkerf9a8c892006-08-24 17:11:50 +0200205 return -EINVAL;
206
207 timeout = t;
208 return 0;
209}
210
Alan Coxc1c8dd32008-05-19 14:09:23 +0100211static ssize_t wdt_write(struct file *file, const char __user *buf,
212 size_t count, loff_t *ppos)
Marcus Junkerf9a8c892006-08-24 17:11:50 +0200213{
214 if (count) {
215 if (!nowayout) {
216 size_t i;
217
218 expect_close = 0;
219
220 for (i = 0; i != count; i++) {
221 char c;
Wim Van Sebroeck7944d3a2008-08-06 20:19:41 +0000222 if (get_user(c, buf + i))
Marcus Junkerf9a8c892006-08-24 17:11:50 +0200223 return -EFAULT;
224 if (c == 'V')
225 expect_close = 42;
226 }
227 }
228 wdt_ping();
229 }
230 return count;
231}
232
Alan Coxc1c8dd32008-05-19 14:09:23 +0100233static long wdt_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
Marcus Junkerf9a8c892006-08-24 17:11:50 +0200234{
235 void __user *argp = (void __user *)arg;
236 int __user *p = argp;
237 int new_timeout;
Alan Coxc1c8dd32008-05-19 14:09:23 +0100238 static const struct watchdog_info ident = {
239 .options = WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT
240 | WDIOF_MAGICCLOSE,
Marcus Junkerf9a8c892006-08-24 17:11:50 +0200241 .firmware_version = 1,
242 .identity = "W83697HF WDT",
243 };
244
245 switch (cmd) {
246 case WDIOC_GETSUPPORT:
Samuel Tardieudb165252006-09-07 11:57:00 +0200247 if (copy_to_user(argp, &ident, sizeof(ident)))
248 return -EFAULT;
249 break;
Marcus Junkerf9a8c892006-08-24 17:11:50 +0200250
251 case WDIOC_GETSTATUS:
252 case WDIOC_GETBOOTSTATUS:
Samuel Tardieudb165252006-09-07 11:57:00 +0200253 return put_user(0, p);
Marcus Junkerf9a8c892006-08-24 17:11:50 +0200254
Marcus Junkerf9a8c892006-08-24 17:11:50 +0200255 case WDIOC_SETOPTIONS:
256 {
Samuel Tardieudb165252006-09-07 11:57:00 +0200257 int options, retval = -EINVAL;
Marcus Junkerf9a8c892006-08-24 17:11:50 +0200258
Samuel Tardieudb165252006-09-07 11:57:00 +0200259 if (get_user(options, p))
260 return -EFAULT;
Marcus Junkerf9a8c892006-08-24 17:11:50 +0200261
Samuel Tardieudb165252006-09-07 11:57:00 +0200262 if (options & WDIOS_DISABLECARD) {
263 wdt_disable();
264 retval = 0;
265 }
Marcus Junkerf9a8c892006-08-24 17:11:50 +0200266
Samuel Tardieudb165252006-09-07 11:57:00 +0200267 if (options & WDIOS_ENABLECARD) {
Samuel Tardieu089d8132006-09-07 11:57:00 +0200268 wdt_enable();
Samuel Tardieudb165252006-09-07 11:57:00 +0200269 retval = 0;
270 }
Marcus Junkerf9a8c892006-08-24 17:11:50 +0200271
Samuel Tardieudb165252006-09-07 11:57:00 +0200272 return retval;
Marcus Junkerf9a8c892006-08-24 17:11:50 +0200273 }
274
Wim Van Sebroeck0c060902008-07-18 11:41:17 +0000275 case WDIOC_KEEPALIVE:
276 wdt_ping();
277 break;
278
279 case WDIOC_SETTIMEOUT:
280 if (get_user(new_timeout, p))
281 return -EFAULT;
282 if (wdt_set_heartbeat(new_timeout))
283 return -EINVAL;
284 wdt_ping();
285 /* Fall */
286
287 case WDIOC_GETTIMEOUT:
288 return put_user(timeout, p);
289
Marcus Junkerf9a8c892006-08-24 17:11:50 +0200290 default:
Samuel Tardieudb165252006-09-07 11:57:00 +0200291 return -ENOTTY;
Marcus Junkerf9a8c892006-08-24 17:11:50 +0200292 }
293 return 0;
294}
295
Alan Coxc1c8dd32008-05-19 14:09:23 +0100296static int wdt_open(struct inode *inode, struct file *file)
Marcus Junkerf9a8c892006-08-24 17:11:50 +0200297{
298 if (test_and_set_bit(0, &wdt_is_open))
299 return -EBUSY;
300 /*
301 * Activate
302 */
303
Samuel Tardieu089d8132006-09-07 11:57:00 +0200304 wdt_enable();
Marcus Junkerf9a8c892006-08-24 17:11:50 +0200305 return nonseekable_open(inode, file);
306}
307
Alan Coxc1c8dd32008-05-19 14:09:23 +0100308static int wdt_close(struct inode *inode, struct file *file)
Marcus Junkerf9a8c892006-08-24 17:11:50 +0200309{
Alan Coxc1c8dd32008-05-19 14:09:23 +0100310 if (expect_close == 42)
Marcus Junkerf9a8c892006-08-24 17:11:50 +0200311 wdt_disable();
Alan Coxc1c8dd32008-05-19 14:09:23 +0100312 else {
Joe Perches27c766a2012-02-15 15:06:19 -0800313 pr_crit("Unexpected close, not stopping watchdog!\n");
Marcus Junkerf9a8c892006-08-24 17:11:50 +0200314 wdt_ping();
315 }
316 expect_close = 0;
317 clear_bit(0, &wdt_is_open);
318 return 0;
319}
320
321/*
322 * Notifier for system down
323 */
324
Alan Coxc1c8dd32008-05-19 14:09:23 +0100325static int wdt_notify_sys(struct notifier_block *this, unsigned long code,
Marcus Junkerf9a8c892006-08-24 17:11:50 +0200326 void *unused)
327{
Wim Van Sebroeck7944d3a2008-08-06 20:19:41 +0000328 if (code == SYS_DOWN || code == SYS_HALT)
329 wdt_disable(); /* Turn the WDT off */
330
Marcus Junkerf9a8c892006-08-24 17:11:50 +0200331 return NOTIFY_DONE;
332}
333
334/*
335 * Kernel Interfaces
336 */
337
Arjan van de Ven2b8693c2007-02-12 00:55:32 -0800338static const struct file_operations wdt_fops = {
Marcus Junkerf9a8c892006-08-24 17:11:50 +0200339 .owner = THIS_MODULE,
340 .llseek = no_llseek,
341 .write = wdt_write,
Alan Coxc1c8dd32008-05-19 14:09:23 +0100342 .unlocked_ioctl = wdt_ioctl,
Marcus Junkerf9a8c892006-08-24 17:11:50 +0200343 .open = wdt_open,
344 .release = wdt_close,
345};
346
347static struct miscdevice wdt_miscdev = {
348 .minor = WATCHDOG_MINOR,
349 .name = "watchdog",
350 .fops = &wdt_fops,
351};
352
353/*
354 * The WDT needs to learn about soft shutdowns in order to
355 * turn the timebomb registers off.
356 */
357
358static struct notifier_block wdt_notifier = {
359 .notifier_call = wdt_notify_sys,
360};
361
Alan Coxc1c8dd32008-05-19 14:09:23 +0100362static int w83697hf_check_wdt(void)
Samuel Tardieuc81b2992006-09-07 11:57:00 +0200363{
364 if (!request_region(wdt_io, 2, WATCHDOG_NAME)) {
Joe Perches27c766a2012-02-15 15:06:19 -0800365 pr_err("I/O address 0x%x already in use\n", wdt_io);
Samuel Tardieuc81b2992006-09-07 11:57:00 +0200366 return -EIO;
367 }
368
Joe Perches27c766a2012-02-15 15:06:19 -0800369 pr_debug("Looking for watchdog at address 0x%x\n", wdt_io);
Samuel Tardieuc81b2992006-09-07 11:57:00 +0200370 w83697hf_unlock();
371 if (w83697hf_get_reg(0x20) == 0x60) {
Joe Perches27c766a2012-02-15 15:06:19 -0800372 pr_info("watchdog found at address 0x%x\n", wdt_io);
Samuel Tardieuc81b2992006-09-07 11:57:00 +0200373 w83697hf_lock();
374 return 0;
375 }
Alan Coxc1c8dd32008-05-19 14:09:23 +0100376 /* Reprotect in case it was a compatible device */
377 w83697hf_lock();
Samuel Tardieuc81b2992006-09-07 11:57:00 +0200378
Joe Perches27c766a2012-02-15 15:06:19 -0800379 pr_info("watchdog not found at address 0x%x\n", wdt_io);
Samuel Tardieuc81b2992006-09-07 11:57:00 +0200380 release_region(wdt_io, 2);
381 return -EIO;
382}
383
Wim Van Sebroecke223f012006-09-15 17:59:07 +0200384static int w83697hf_ioports[] = { 0x2e, 0x4e, 0x00 };
385
Alan Coxc1c8dd32008-05-19 14:09:23 +0100386static int __init wdt_init(void)
Marcus Junkerf9a8c892006-08-24 17:11:50 +0200387{
Wim Van Sebroecke223f012006-09-15 17:59:07 +0200388 int ret, i, found = 0;
Marcus Junkerf9a8c892006-08-24 17:11:50 +0200389
Joe Perches27c766a2012-02-15 15:06:19 -0800390 pr_info("WDT driver for W83697HF/HG initializing\n");
Marcus Junkerf9a8c892006-08-24 17:11:50 +0200391
Wim Van Sebroecke223f012006-09-15 17:59:07 +0200392 if (wdt_io == 0) {
393 /* we will autodetect the W83697HF/HG watchdog */
394 for (i = 0; ((!found) && (w83697hf_ioports[i] != 0)); i++) {
395 wdt_io = w83697hf_ioports[i];
Wim Van Sebroeckcde10ba2008-01-18 21:01:34 +0000396 if (!w83697hf_check_wdt())
Wim Van Sebroecke223f012006-09-15 17:59:07 +0200397 found++;
398 }
399 } else {
Samuel Tardieuc81b2992006-09-07 11:57:00 +0200400 if (!w83697hf_check_wdt())
Wim Van Sebroecke223f012006-09-15 17:59:07 +0200401 found++;
Samuel Tardieuc81b2992006-09-07 11:57:00 +0200402 }
403
Wim Van Sebroecke223f012006-09-15 17:59:07 +0200404 if (!found) {
Joe Perches27c766a2012-02-15 15:06:19 -0800405 pr_err("No W83697HF/HG could be found\n");
Wim Van Sebroecke223f012006-09-15 17:59:07 +0200406 ret = -EIO;
407 goto out;
408 }
Samuel Tardieuc81b2992006-09-07 11:57:00 +0200409
Samuel Tardieufa69afd2006-09-07 11:57:00 +0200410 w83697hf_init();
Samuel Tardieu6fd65602008-03-12 14:28:03 +0100411 if (early_disable) {
412 if (wdt_running())
Joe Perches27c766a2012-02-15 15:06:19 -0800413 pr_warn("Stopping previously enabled watchdog until userland kicks in\n");
Samuel Tardieu6fd65602008-03-12 14:28:03 +0100414 wdt_disable();
415 }
Samuel Tardieuc81b2992006-09-07 11:57:00 +0200416
Marcus Junkerf9a8c892006-08-24 17:11:50 +0200417 if (wdt_set_heartbeat(timeout)) {
418 wdt_set_heartbeat(WATCHDOG_TIMEOUT);
Joe Perches27c766a2012-02-15 15:06:19 -0800419 pr_info("timeout value must be 1 <= timeout <= 255, using %d\n",
420 WATCHDOG_TIMEOUT);
Marcus Junkerf9a8c892006-08-24 17:11:50 +0200421 }
422
Marcus Junkerf9a8c892006-08-24 17:11:50 +0200423 ret = register_reboot_notifier(&wdt_notifier);
424 if (ret != 0) {
Joe Perches27c766a2012-02-15 15:06:19 -0800425 pr_err("cannot register reboot notifier (err=%d)\n", ret);
Marcus Junkerf9a8c892006-08-24 17:11:50 +0200426 goto unreg_regions;
427 }
428
429 ret = misc_register(&wdt_miscdev);
430 if (ret != 0) {
Joe Perches27c766a2012-02-15 15:06:19 -0800431 pr_err("cannot register miscdev on minor=%d (err=%d)\n",
432 WATCHDOG_MINOR, ret);
Marcus Junkerf9a8c892006-08-24 17:11:50 +0200433 goto unreg_reboot;
434 }
435
Joe Perches27c766a2012-02-15 15:06:19 -0800436 pr_info("initialized. timeout=%d sec (nowayout=%d)\n",
Marcus Junkerf9a8c892006-08-24 17:11:50 +0200437 timeout, nowayout);
438
439out:
440 return ret;
441unreg_reboot:
442 unregister_reboot_notifier(&wdt_notifier);
443unreg_regions:
Samuel Tardieub41a9f52006-09-07 11:57:00 +0200444 release_region(wdt_io, 2);
Marcus Junkerf9a8c892006-08-24 17:11:50 +0200445 goto out;
446}
447
Alan Coxc1c8dd32008-05-19 14:09:23 +0100448static void __exit wdt_exit(void)
Marcus Junkerf9a8c892006-08-24 17:11:50 +0200449{
450 misc_deregister(&wdt_miscdev);
451 unregister_reboot_notifier(&wdt_notifier);
Samuel Tardieub41a9f52006-09-07 11:57:00 +0200452 release_region(wdt_io, 2);
Marcus Junkerf9a8c892006-08-24 17:11:50 +0200453}
454
455module_init(wdt_init);
456module_exit(wdt_exit);
457
458MODULE_LICENSE("GPL");
Wim Van Sebroeck143a2e52009-03-18 08:35:09 +0000459MODULE_AUTHOR("Marcus Junker <junker@anduras.de>, "
460 "Samuel Tardieu <sam@rfc1149.net>");
Samuel Tardieude710d62006-09-07 11:57:00 +0200461MODULE_DESCRIPTION("w83697hf/hg WDT driver");
Marcus Junkerf9a8c892006-08-24 17:11:50 +0200462MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);