1 diff -urN linux-2.6.16.7/drivers/char/watchdog/Kconfig linux-2.6.16.7.new/drivers/char/watchdog/Kconfig
2 --- linux-2.6.16.7/drivers/char/watchdog/Kconfig 2006-04-17 23:53:25.000000000 +0200
3 +++ linux-2.6.16.7.new/drivers/char/watchdog/Kconfig 2006-04-22 23:23:53.000000000 +0200
5 timer expired and no process has written to /dev/watchdog during
9 + tristate "MTX-1 Hardware Watchdog"
10 + depends on WATCHDOG && MIPS_MTX1
12 + Hardware driver for the AccessCube MTX-1 watchdog. This is a
13 + watchdog timer that will reboot the machine after a 100 seconds
19 diff -urN linux-2.6.16.7/drivers/char/watchdog/Makefile linux-2.6.16.7.new/drivers/char/watchdog/Makefile
20 --- linux-2.6.16.7/drivers/char/watchdog/Makefile 2006-04-17 23:53:25.000000000 +0200
21 +++ linux-2.6.16.7.new/drivers/char/watchdog/Makefile 2006-04-22 23:21:18.000000000 +0200
25 obj-$(CONFIG_INDYDOG) += indydog.o
26 +obj-$(CONFIG_MTX1_WATCHDOG) += mtx-1_watchdog.o
30 diff -urN linux-2.6.16.7/drivers/char/watchdog/mtx-1_watchdog.c linux-2.6.16.7.new/drivers/char/watchdog/mtx-1_watchdog.c
31 --- linux-2.6.16.7/drivers/char/watchdog/mtx-1_watchdog.c 1970-01-01 01:00:00.000000000 +0100
32 +++ linux-2.6.16.7.new/drivers/char/watchdog/mtx-1_watchdog.c 2006-04-22 23:20:53.000000000 +0200
35 + * Driver for the MTX-1 Watchdog.
37 + * (c) Copyright 2005 4G Systems <info@4g-systems.biz>, All Rights Reserved.
38 + * http://www.4g-systems.biz
40 + * This program is free software; you can redistribute it and/or
41 + * modify it under the terms of the GNU General Public License
42 + * as published by the Free Software Foundation; either version
43 + * 2 of the License, or (at your option) any later version.
45 + * Neither Michael Stickel nor 4G Systems admit liability nor provide
46 + * warranty for any of this software. This material is provided
47 + * "AS-IS" and at no charge.
49 + * (c) Copyright 2005 4G Systems <info@4g-systems.biz>
53 + * Author: Michael Stickel michael.stickel@4g-systems.biz
56 + * The Watchdog is configured to reset the MTX-1
57 + * if it is not triggered for 100 seconds.
58 + * It should not be triggered more often than 1.6 seconds.
60 + * A timer triggers the watchdog every 5 seconds, until
61 + * it is opened for the first time. After the first open
62 + * it MUST be triggered every 2..95 seconds.
64 +#include <linux/config.h>
65 +#include <linux/module.h>
66 +#include <linux/version.h>
67 +#include <linux/types.h>
68 +#include <linux/errno.h>
69 +#include <linux/kernel.h>
70 +#include <linux/sched.h>
71 +#include <linux/miscdevice.h>
72 +#include <linux/watchdog.h>
73 +#include <linux/slab.h>
74 +#include <linux/init.h>
75 +#include <asm/uaccess.h>
76 +#include <linux/fs.h>
78 +#include <asm/mach-au1x00/au1000.h>
85 +# define TRUE (!FALSE)
89 +//---------[ Hardware Functions ]-----------------
91 +static void mtx1_trigger_wd (void)
97 + u32 tmp = au_readl(GPIO2_DIR);
98 + tmp = (tmp & ~(1<<15)) | ((~tmp) & (1<<15));
99 + au_writel (tmp, GPIO2_DIR);
102 +static void mtx1_enable_wd (void)
104 + au_writel (au_readl(GPIO2_DIR) | (u32)(1<<15), GPIO2_DIR);
107 +static void mtx1_disable_wd (void)
109 + au_writel (au_readl(GPIO2_DIR) & ~((u32)(1<<15)), GPIO2_DIR);
113 +//---------[ Timer Functions ]-----------------
115 +static struct timer_list wd_trigger_timer;
116 +static char timer_is_running = FALSE;
118 +static void wd_timer_callback (unsigned long data)
120 + if (timer_is_running)
121 + mod_timer (&wd_trigger_timer, jiffies + 5 * HZ);
125 +static void start_wd_timer (void)
127 + if (!timer_is_running) {
128 + struct timer_list *t = &wd_trigger_timer;
131 + t->function = wd_timer_callback;
132 + t->data = (unsigned long)0L;
133 + t->expires = jiffies + 5 * HZ; // 5 seconds.
135 + timer_is_running = TRUE;
141 +static void stop_wd_timer (void)
143 + if (timer_is_running) {
144 + del_timer(&wd_trigger_timer);
145 + timer_is_running = FALSE;
150 +//---------[ File Functions ]-----------------
152 +static char restart_after_close;
154 +static int mtx1wd_open (struct inode *inode, struct file *file)
156 + if (MINOR(inode->i_rdev) != WATCHDOG_MINOR) return -ENODEV;
157 + //MOD_INC_USE_COUNT;
159 + // stop the timer, if it is running. It will not be
160 + // started again, until the module is loaded again.
163 + // sleep for 2 seconds, to ensure, that the wd is
164 + // not triggered more often than every 2 seconds.
165 + schedule_timeout (2 * HZ);
171 +static int mtx1wd_release (struct inode *inode, struct file *file) {
172 + if (MINOR(inode->i_rdev)==WATCHDOG_MINOR) {
174 + if (restart_after_close)
176 + //MOD_DEC_USE_COUNT;
181 +static ssize_t mtx1wd_write (struct file *file, const char *buf, size_t count, loff_t *ppos) {
183 + mtx1_trigger_wd ();
187 + int n = (count>9)?9:count;
189 + if (copy_from_user (&buffer, buf, n))
193 + if (count >= 4 && strncmp("auto", buffer, 4)==0)
194 + restart_after_close = 1;
196 + else if (count >= 6 && strncmp("manual", buffer, 6)==0)
197 + restart_after_close = 0;
205 +static ssize_t mtx1wd_read (struct file *file, char *buf, size_t count, loff_t *ppos)
207 + char * state = restart_after_close ? "auto\n" : "manual\n";
208 + int n = strlen(state)+1;
210 + if (file->f_pos >= n)
216 + if(copy_to_user(buf, state, n))
224 +static struct file_operations mtx1wd_fops = {
225 + .owner = THIS_MODULE,
226 + .read = mtx1wd_read,
227 + .write = mtx1wd_write,
228 + .open = mtx1wd_open,
229 + .release = mtx1wd_release
233 +static struct miscdevice mtx1wd_miscdev = {
241 +//---------[ Module Functions ]-----------------
244 +static int __init init_mtx1_watchdog(void)
246 + printk("MTX-1 watchdog driver\n");
248 + misc_register(&mtx1wd_miscdev);
250 + restart_after_close = 0;
254 + //-- trigger it for the first time.
255 + //-- We do not exactly know how long it has not been triggered.
256 + mtx1_trigger_wd ();
258 + // start a timer, that calls mtx1_trigger_wd every 5 seconds.
264 +static void __exit exit_mtx1_watchdog(void) {
266 + // stop the timer, if it is running.
269 + misc_deregister(&mtx1wd_miscdev);
274 +module_init(init_mtx1_watchdog);
275 +module_exit(exit_mtx1_watchdog);
277 +MODULE_AUTHOR("Michael Stickel");
278 +MODULE_DESCRIPTION("Driver for the MTX-1 watchdog");
279 +MODULE_LICENSE("GPL");