Loading...
1/*
2 * 60xx Single Board Computer Watchdog Timer driver for Linux 2.2.x
3 *
4 * Based on acquirewdt.c by Alan Cox.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 *
11 * The author does NOT admit liability nor provide warranty for
12 * any of this software. This material is provided "AS-IS" in
13 * the hope that it may be useful for others.
14 *
15 * (c) Copyright 2000 Jakob Oestergaard <jakob@unthought.net>
16 *
17 * 12/4 - 2000 [Initial revision]
18 * 25/4 - 2000 Added /dev/watchdog support
19 * 09/5 - 2001 [smj@oro.net] fixed fop_write to "return 1"
20 * on success
21 * 12/4 - 2002 [rob@osinvestor.com] eliminate fop_read
22 * fix possible wdt_is_open race
23 * add CONFIG_WATCHDOG_NOWAYOUT support
24 * remove lock_kernel/unlock_kernel pairs
25 * added KERN_* to printk's
26 * got rid of extraneous comments
27 * changed watchdog_info to correctly reflect what
28 * the driver offers
29 * added WDIOC_GETSTATUS, WDIOC_GETBOOTSTATUS,
30 * WDIOC_SETTIMEOUT, WDIOC_GETTIMEOUT, and
31 * WDIOC_SETOPTIONS ioctls
32 * 09/8 - 2003 [wim@iguana.be] cleanup of trailing spaces
33 * use module_param
34 * made timeout (the emulated heartbeat) a
35 * module_param
36 * made the keepalive ping an internal subroutine
37 * made wdt_stop and wdt_start module params
38 * added extra printk's for startup problems
39 * added MODULE_AUTHOR and MODULE_DESCRIPTION info
40 *
41 *
42 * This WDT driver is different from the other Linux WDT
43 * drivers in the following ways:
44 * *) The driver will ping the watchdog by itself, because this
45 * particular WDT has a very short timeout (one second) and it
46 * would be insane to count on any userspace daemon always
47 * getting scheduled within that time frame.
48 *
49 */
50
51#include <linux/module.h>
52#include <linux/moduleparam.h>
53#include <linux/types.h>
54#include <linux/timer.h>
55#include <linux/jiffies.h>
56#include <linux/miscdevice.h>
57#include <linux/watchdog.h>
58#include <linux/fs.h>
59#include <linux/ioport.h>
60#include <linux/notifier.h>
61#include <linux/reboot.h>
62#include <linux/init.h>
63#include <linux/io.h>
64#include <linux/uaccess.h>
65
66#include <asm/system.h>
67
68#define OUR_NAME "sbc60xxwdt"
69#define PFX OUR_NAME ": "
70
71/*
72 * You must set these - The driver cannot probe for the settings
73 */
74
75static int wdt_stop = 0x45;
76module_param(wdt_stop, int, 0);
77MODULE_PARM_DESC(wdt_stop, "SBC60xx WDT 'stop' io port (default 0x45)");
78
79static int wdt_start = 0x443;
80module_param(wdt_start, int, 0);
81MODULE_PARM_DESC(wdt_start, "SBC60xx WDT 'start' io port (default 0x443)");
82
83/*
84 * The 60xx board can use watchdog timeout values from one second
85 * to several minutes. The default is one second, so if we reset
86 * the watchdog every ~250ms we should be safe.
87 */
88
89#define WDT_INTERVAL (HZ/4+1)
90
91/*
92 * We must not require too good response from the userspace daemon.
93 * Here we require the userspace daemon to send us a heartbeat
94 * char to /dev/watchdog every 30 seconds.
95 * If the daemon pulses us every 25 seconds, we can still afford
96 * a 5 second scheduling delay on the (high priority) daemon. That
97 * should be sufficient for a box under any load.
98 */
99
100#define WATCHDOG_TIMEOUT 30 /* 30 sec default timeout */
101static int timeout = WATCHDOG_TIMEOUT; /* in seconds, multiplied by HZ to
102 get seconds to wait for a ping */
103module_param(timeout, int, 0);
104MODULE_PARM_DESC(timeout,
105 "Watchdog timeout in seconds. (1<=timeout<=3600, default="
106 __MODULE_STRING(WATCHDOG_TIMEOUT) ")");
107
108static int nowayout = WATCHDOG_NOWAYOUT;
109module_param(nowayout, int, 0);
110MODULE_PARM_DESC(nowayout,
111 "Watchdog cannot be stopped once started (default="
112 __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
113
114static void wdt_timer_ping(unsigned long);
115static DEFINE_TIMER(timer, wdt_timer_ping, 0, 0);
116static unsigned long next_heartbeat;
117static unsigned long wdt_is_open;
118static char wdt_expect_close;
119
120/*
121 * Whack the dog
122 */
123
124static void wdt_timer_ping(unsigned long data)
125{
126 /* If we got a heartbeat pulse within the WDT_US_INTERVAL
127 * we agree to ping the WDT
128 */
129 if (time_before(jiffies, next_heartbeat)) {
130 /* Ping the WDT by reading from wdt_start */
131 inb_p(wdt_start);
132 /* Re-set the timer interval */
133 mod_timer(&timer, jiffies + WDT_INTERVAL);
134 } else
135 printk(KERN_WARNING PFX
136 "Heartbeat lost! Will not ping the watchdog\n");
137}
138
139/*
140 * Utility routines
141 */
142
143static void wdt_startup(void)
144{
145 next_heartbeat = jiffies + (timeout * HZ);
146
147 /* Start the timer */
148 mod_timer(&timer, jiffies + WDT_INTERVAL);
149 printk(KERN_INFO PFX "Watchdog timer is now enabled.\n");
150}
151
152static void wdt_turnoff(void)
153{
154 /* Stop the timer */
155 del_timer(&timer);
156 inb_p(wdt_stop);
157 printk(KERN_INFO PFX "Watchdog timer is now disabled...\n");
158}
159
160static void wdt_keepalive(void)
161{
162 /* user land ping */
163 next_heartbeat = jiffies + (timeout * HZ);
164}
165
166/*
167 * /dev/watchdog handling
168 */
169
170static ssize_t fop_write(struct file *file, const char __user *buf,
171 size_t count, loff_t *ppos)
172{
173 /* See if we got the magic character 'V' and reload the timer */
174 if (count) {
175 if (!nowayout) {
176 size_t ofs;
177
178 /* note: just in case someone wrote the
179 magic character five months ago... */
180 wdt_expect_close = 0;
181
182 /* scan to see whether or not we got the
183 magic character */
184 for (ofs = 0; ofs != count; ofs++) {
185 char c;
186 if (get_user(c, buf + ofs))
187 return -EFAULT;
188 if (c == 'V')
189 wdt_expect_close = 42;
190 }
191 }
192
193 /* Well, anyhow someone wrote to us, we should
194 return that favour */
195 wdt_keepalive();
196 }
197 return count;
198}
199
200static int fop_open(struct inode *inode, struct file *file)
201{
202 /* Just in case we're already talking to someone... */
203 if (test_and_set_bit(0, &wdt_is_open))
204 return -EBUSY;
205
206 if (nowayout)
207 __module_get(THIS_MODULE);
208
209 /* Good, fire up the show */
210 wdt_startup();
211 return nonseekable_open(inode, file);
212}
213
214static int fop_close(struct inode *inode, struct file *file)
215{
216 if (wdt_expect_close == 42)
217 wdt_turnoff();
218 else {
219 del_timer(&timer);
220 printk(KERN_CRIT PFX
221 "device file closed unexpectedly. Will not stop the WDT!\n");
222 }
223 clear_bit(0, &wdt_is_open);
224 wdt_expect_close = 0;
225 return 0;
226}
227
228static long fop_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
229{
230 void __user *argp = (void __user *)arg;
231 int __user *p = argp;
232 static const struct watchdog_info ident = {
233 .options = WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT |
234 WDIOF_MAGICCLOSE,
235 .firmware_version = 1,
236 .identity = "SBC60xx",
237 };
238
239 switch (cmd) {
240 case WDIOC_GETSUPPORT:
241 return copy_to_user(argp, &ident, sizeof(ident)) ? -EFAULT : 0;
242 case WDIOC_GETSTATUS:
243 case WDIOC_GETBOOTSTATUS:
244 return put_user(0, p);
245 case WDIOC_SETOPTIONS:
246 {
247 int new_options, retval = -EINVAL;
248 if (get_user(new_options, p))
249 return -EFAULT;
250 if (new_options & WDIOS_DISABLECARD) {
251 wdt_turnoff();
252 retval = 0;
253 }
254 if (new_options & WDIOS_ENABLECARD) {
255 wdt_startup();
256 retval = 0;
257 }
258 return retval;
259 }
260 case WDIOC_KEEPALIVE:
261 wdt_keepalive();
262 return 0;
263 case WDIOC_SETTIMEOUT:
264 {
265 int new_timeout;
266 if (get_user(new_timeout, p))
267 return -EFAULT;
268 /* arbitrary upper limit */
269 if (new_timeout < 1 || new_timeout > 3600)
270 return -EINVAL;
271
272 timeout = new_timeout;
273 wdt_keepalive();
274 /* Fall through */
275 }
276 case WDIOC_GETTIMEOUT:
277 return put_user(timeout, p);
278 default:
279 return -ENOTTY;
280 }
281}
282
283static const struct file_operations wdt_fops = {
284 .owner = THIS_MODULE,
285 .llseek = no_llseek,
286 .write = fop_write,
287 .open = fop_open,
288 .release = fop_close,
289 .unlocked_ioctl = fop_ioctl,
290};
291
292static struct miscdevice wdt_miscdev = {
293 .minor = WATCHDOG_MINOR,
294 .name = "watchdog",
295 .fops = &wdt_fops,
296};
297
298/*
299 * Notifier for system down
300 */
301
302static int wdt_notify_sys(struct notifier_block *this, unsigned long code,
303 void *unused)
304{
305 if (code == SYS_DOWN || code == SYS_HALT)
306 wdt_turnoff();
307 return NOTIFY_DONE;
308}
309
310/*
311 * The WDT needs to learn about soft shutdowns in order to
312 * turn the timebomb registers off.
313 */
314
315static struct notifier_block wdt_notifier = {
316 .notifier_call = wdt_notify_sys,
317};
318
319static void __exit sbc60xxwdt_unload(void)
320{
321 wdt_turnoff();
322
323 /* Deregister */
324 misc_deregister(&wdt_miscdev);
325
326 unregister_reboot_notifier(&wdt_notifier);
327 if ((wdt_stop != 0x45) && (wdt_stop != wdt_start))
328 release_region(wdt_stop, 1);
329 release_region(wdt_start, 1);
330}
331
332static int __init sbc60xxwdt_init(void)
333{
334 int rc = -EBUSY;
335
336 if (timeout < 1 || timeout > 3600) { /* arbitrary upper limit */
337 timeout = WATCHDOG_TIMEOUT;
338 printk(KERN_INFO PFX
339 "timeout value must be 1 <= x <= 3600, using %d\n",
340 timeout);
341 }
342
343 if (!request_region(wdt_start, 1, "SBC 60XX WDT")) {
344 printk(KERN_ERR PFX "I/O address 0x%04x already in use\n",
345 wdt_start);
346 rc = -EIO;
347 goto err_out;
348 }
349
350 /* We cannot reserve 0x45 - the kernel already has! */
351 if (wdt_stop != 0x45 && wdt_stop != wdt_start) {
352 if (!request_region(wdt_stop, 1, "SBC 60XX WDT")) {
353 printk(KERN_ERR PFX
354 "I/O address 0x%04x already in use\n",
355 wdt_stop);
356 rc = -EIO;
357 goto err_out_region1;
358 }
359 }
360
361 rc = register_reboot_notifier(&wdt_notifier);
362 if (rc) {
363 printk(KERN_ERR PFX
364 "cannot register reboot notifier (err=%d)\n", rc);
365 goto err_out_region2;
366 }
367
368 rc = misc_register(&wdt_miscdev);
369 if (rc) {
370 printk(KERN_ERR PFX
371 "cannot register miscdev on minor=%d (err=%d)\n",
372 wdt_miscdev.minor, rc);
373 goto err_out_reboot;
374 }
375 printk(KERN_INFO PFX
376 "WDT driver for 60XX single board computer initialised. "
377 "timeout=%d sec (nowayout=%d)\n", timeout, nowayout);
378
379 return 0;
380
381err_out_reboot:
382 unregister_reboot_notifier(&wdt_notifier);
383err_out_region2:
384 if (wdt_stop != 0x45 && wdt_stop != wdt_start)
385 release_region(wdt_stop, 1);
386err_out_region1:
387 release_region(wdt_start, 1);
388err_out:
389 return rc;
390}
391
392module_init(sbc60xxwdt_init);
393module_exit(sbc60xxwdt_unload);
394
395MODULE_AUTHOR("Jakob Oestergaard <jakob@unthought.net>");
396MODULE_DESCRIPTION("60xx Single Board Computer Watchdog Timer driver");
397MODULE_LICENSE("GPL");
398MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * 60xx Single Board Computer Watchdog Timer driver for Linux 2.2.x
4 *
5 * Based on acquirewdt.c by Alan Cox.
6 *
7 * The author does NOT admit liability nor provide warranty for
8 * any of this software. This material is provided "AS-IS" in
9 * the hope that it may be useful for others.
10 *
11 * (c) Copyright 2000 Jakob Oestergaard <jakob@unthought.net>
12 *
13 * 12/4 - 2000 [Initial revision]
14 * 25/4 - 2000 Added /dev/watchdog support
15 * 09/5 - 2001 [smj@oro.net] fixed fop_write to "return 1"
16 * on success
17 * 12/4 - 2002 [rob@osinvestor.com] eliminate fop_read
18 * fix possible wdt_is_open race
19 * add CONFIG_WATCHDOG_NOWAYOUT support
20 * remove lock_kernel/unlock_kernel pairs
21 * added KERN_* to printk's
22 * got rid of extraneous comments
23 * changed watchdog_info to correctly reflect what
24 * the driver offers
25 * added WDIOC_GETSTATUS, WDIOC_GETBOOTSTATUS,
26 * WDIOC_SETTIMEOUT, WDIOC_GETTIMEOUT, and
27 * WDIOC_SETOPTIONS ioctls
28 * 09/8 - 2003 [wim@iguana.be] cleanup of trailing spaces
29 * use module_param
30 * made timeout (the emulated heartbeat) a
31 * module_param
32 * made the keepalive ping an internal subroutine
33 * made wdt_stop and wdt_start module params
34 * added extra printk's for startup problems
35 * added MODULE_AUTHOR and MODULE_DESCRIPTION info
36 *
37 * This WDT driver is different from the other Linux WDT
38 * drivers in the following ways:
39 * *) The driver will ping the watchdog by itself, because this
40 * particular WDT has a very short timeout (one second) and it
41 * would be insane to count on any userspace daemon always
42 * getting scheduled within that time frame.
43 */
44
45#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
46
47#include <linux/module.h>
48#include <linux/moduleparam.h>
49#include <linux/types.h>
50#include <linux/timer.h>
51#include <linux/jiffies.h>
52#include <linux/miscdevice.h>
53#include <linux/watchdog.h>
54#include <linux/fs.h>
55#include <linux/ioport.h>
56#include <linux/notifier.h>
57#include <linux/reboot.h>
58#include <linux/init.h>
59#include <linux/io.h>
60#include <linux/uaccess.h>
61
62
63#define OUR_NAME "sbc60xxwdt"
64#define PFX OUR_NAME ": "
65
66/*
67 * You must set these - The driver cannot probe for the settings
68 */
69
70static int wdt_stop = 0x45;
71module_param(wdt_stop, int, 0);
72MODULE_PARM_DESC(wdt_stop, "SBC60xx WDT 'stop' io port (default 0x45)");
73
74static int wdt_start = 0x443;
75module_param(wdt_start, int, 0);
76MODULE_PARM_DESC(wdt_start, "SBC60xx WDT 'start' io port (default 0x443)");
77
78/*
79 * The 60xx board can use watchdog timeout values from one second
80 * to several minutes. The default is one second, so if we reset
81 * the watchdog every ~250ms we should be safe.
82 */
83
84#define WDT_INTERVAL (HZ/4+1)
85
86/*
87 * We must not require too good response from the userspace daemon.
88 * Here we require the userspace daemon to send us a heartbeat
89 * char to /dev/watchdog every 30 seconds.
90 * If the daemon pulses us every 25 seconds, we can still afford
91 * a 5 second scheduling delay on the (high priority) daemon. That
92 * should be sufficient for a box under any load.
93 */
94
95#define WATCHDOG_TIMEOUT 30 /* 30 sec default timeout */
96static int timeout = WATCHDOG_TIMEOUT; /* in seconds, multiplied by HZ to
97 get seconds to wait for a ping */
98module_param(timeout, int, 0);
99MODULE_PARM_DESC(timeout,
100 "Watchdog timeout in seconds. (1<=timeout<=3600, default="
101 __MODULE_STRING(WATCHDOG_TIMEOUT) ")");
102
103static bool nowayout = WATCHDOG_NOWAYOUT;
104module_param(nowayout, bool, 0);
105MODULE_PARM_DESC(nowayout,
106 "Watchdog cannot be stopped once started (default="
107 __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
108
109static void wdt_timer_ping(struct timer_list *);
110static DEFINE_TIMER(timer, wdt_timer_ping);
111static unsigned long next_heartbeat;
112static unsigned long wdt_is_open;
113static char wdt_expect_close;
114
115/*
116 * Whack the dog
117 */
118
119static void wdt_timer_ping(struct timer_list *unused)
120{
121 /* If we got a heartbeat pulse within the WDT_US_INTERVAL
122 * we agree to ping the WDT
123 */
124 if (time_before(jiffies, next_heartbeat)) {
125 /* Ping the WDT by reading from wdt_start */
126 inb_p(wdt_start);
127 /* Re-set the timer interval */
128 mod_timer(&timer, jiffies + WDT_INTERVAL);
129 } else
130 pr_warn("Heartbeat lost! Will not ping the watchdog\n");
131}
132
133/*
134 * Utility routines
135 */
136
137static void wdt_startup(void)
138{
139 next_heartbeat = jiffies + (timeout * HZ);
140
141 /* Start the timer */
142 mod_timer(&timer, jiffies + WDT_INTERVAL);
143 pr_info("Watchdog timer is now enabled\n");
144}
145
146static void wdt_turnoff(void)
147{
148 /* Stop the timer */
149 del_timer(&timer);
150 inb_p(wdt_stop);
151 pr_info("Watchdog timer is now disabled...\n");
152}
153
154static void wdt_keepalive(void)
155{
156 /* user land ping */
157 next_heartbeat = jiffies + (timeout * HZ);
158}
159
160/*
161 * /dev/watchdog handling
162 */
163
164static ssize_t fop_write(struct file *file, const char __user *buf,
165 size_t count, loff_t *ppos)
166{
167 /* See if we got the magic character 'V' and reload the timer */
168 if (count) {
169 if (!nowayout) {
170 size_t ofs;
171
172 /* note: just in case someone wrote the
173 magic character five months ago... */
174 wdt_expect_close = 0;
175
176 /* scan to see whether or not we got the
177 magic character */
178 for (ofs = 0; ofs != count; ofs++) {
179 char c;
180 if (get_user(c, buf + ofs))
181 return -EFAULT;
182 if (c == 'V')
183 wdt_expect_close = 42;
184 }
185 }
186
187 /* Well, anyhow someone wrote to us, we should
188 return that favour */
189 wdt_keepalive();
190 }
191 return count;
192}
193
194static int fop_open(struct inode *inode, struct file *file)
195{
196 /* Just in case we're already talking to someone... */
197 if (test_and_set_bit(0, &wdt_is_open))
198 return -EBUSY;
199
200 if (nowayout)
201 __module_get(THIS_MODULE);
202
203 /* Good, fire up the show */
204 wdt_startup();
205 return stream_open(inode, file);
206}
207
208static int fop_close(struct inode *inode, struct file *file)
209{
210 if (wdt_expect_close == 42)
211 wdt_turnoff();
212 else {
213 del_timer(&timer);
214 pr_crit("device file closed unexpectedly. Will not stop the WDT!\n");
215 }
216 clear_bit(0, &wdt_is_open);
217 wdt_expect_close = 0;
218 return 0;
219}
220
221static long fop_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
222{
223 void __user *argp = (void __user *)arg;
224 int __user *p = argp;
225 static const struct watchdog_info ident = {
226 .options = WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT |
227 WDIOF_MAGICCLOSE,
228 .firmware_version = 1,
229 .identity = "SBC60xx",
230 };
231
232 switch (cmd) {
233 case WDIOC_GETSUPPORT:
234 return copy_to_user(argp, &ident, sizeof(ident)) ? -EFAULT : 0;
235 case WDIOC_GETSTATUS:
236 case WDIOC_GETBOOTSTATUS:
237 return put_user(0, p);
238 case WDIOC_SETOPTIONS:
239 {
240 int new_options, retval = -EINVAL;
241 if (get_user(new_options, p))
242 return -EFAULT;
243 if (new_options & WDIOS_DISABLECARD) {
244 wdt_turnoff();
245 retval = 0;
246 }
247 if (new_options & WDIOS_ENABLECARD) {
248 wdt_startup();
249 retval = 0;
250 }
251 return retval;
252 }
253 case WDIOC_KEEPALIVE:
254 wdt_keepalive();
255 return 0;
256 case WDIOC_SETTIMEOUT:
257 {
258 int new_timeout;
259 if (get_user(new_timeout, p))
260 return -EFAULT;
261 /* arbitrary upper limit */
262 if (new_timeout < 1 || new_timeout > 3600)
263 return -EINVAL;
264
265 timeout = new_timeout;
266 wdt_keepalive();
267 }
268 /* Fall through */
269 case WDIOC_GETTIMEOUT:
270 return put_user(timeout, p);
271 default:
272 return -ENOTTY;
273 }
274}
275
276static const struct file_operations wdt_fops = {
277 .owner = THIS_MODULE,
278 .llseek = no_llseek,
279 .write = fop_write,
280 .open = fop_open,
281 .release = fop_close,
282 .unlocked_ioctl = fop_ioctl,
283};
284
285static struct miscdevice wdt_miscdev = {
286 .minor = WATCHDOG_MINOR,
287 .name = "watchdog",
288 .fops = &wdt_fops,
289};
290
291/*
292 * Notifier for system down
293 */
294
295static int wdt_notify_sys(struct notifier_block *this, unsigned long code,
296 void *unused)
297{
298 if (code == SYS_DOWN || code == SYS_HALT)
299 wdt_turnoff();
300 return NOTIFY_DONE;
301}
302
303/*
304 * The WDT needs to learn about soft shutdowns in order to
305 * turn the timebomb registers off.
306 */
307
308static struct notifier_block wdt_notifier = {
309 .notifier_call = wdt_notify_sys,
310};
311
312static void __exit sbc60xxwdt_unload(void)
313{
314 wdt_turnoff();
315
316 /* Deregister */
317 misc_deregister(&wdt_miscdev);
318
319 unregister_reboot_notifier(&wdt_notifier);
320 if ((wdt_stop != 0x45) && (wdt_stop != wdt_start))
321 release_region(wdt_stop, 1);
322 release_region(wdt_start, 1);
323}
324
325static int __init sbc60xxwdt_init(void)
326{
327 int rc = -EBUSY;
328
329 if (timeout < 1 || timeout > 3600) { /* arbitrary upper limit */
330 timeout = WATCHDOG_TIMEOUT;
331 pr_info("timeout value must be 1 <= x <= 3600, using %d\n",
332 timeout);
333 }
334
335 if (!request_region(wdt_start, 1, "SBC 60XX WDT")) {
336 pr_err("I/O address 0x%04x already in use\n", wdt_start);
337 rc = -EIO;
338 goto err_out;
339 }
340
341 /* We cannot reserve 0x45 - the kernel already has! */
342 if (wdt_stop != 0x45 && wdt_stop != wdt_start) {
343 if (!request_region(wdt_stop, 1, "SBC 60XX WDT")) {
344 pr_err("I/O address 0x%04x already in use\n", wdt_stop);
345 rc = -EIO;
346 goto err_out_region1;
347 }
348 }
349
350 rc = register_reboot_notifier(&wdt_notifier);
351 if (rc) {
352 pr_err("cannot register reboot notifier (err=%d)\n", rc);
353 goto err_out_region2;
354 }
355
356 rc = misc_register(&wdt_miscdev);
357 if (rc) {
358 pr_err("cannot register miscdev on minor=%d (err=%d)\n",
359 wdt_miscdev.minor, rc);
360 goto err_out_reboot;
361 }
362 pr_info("WDT driver for 60XX single board computer initialised. timeout=%d sec (nowayout=%d)\n",
363 timeout, nowayout);
364
365 return 0;
366
367err_out_reboot:
368 unregister_reboot_notifier(&wdt_notifier);
369err_out_region2:
370 if (wdt_stop != 0x45 && wdt_stop != wdt_start)
371 release_region(wdt_stop, 1);
372err_out_region1:
373 release_region(wdt_start, 1);
374err_out:
375 return rc;
376}
377
378module_init(sbc60xxwdt_init);
379module_exit(sbc60xxwdt_unload);
380
381MODULE_AUTHOR("Jakob Oestergaard <jakob@unthought.net>");
382MODULE_DESCRIPTION("60xx Single Board Computer Watchdog Timer driver");
383MODULE_LICENSE("GPL");