Ok, try to make shfs work with 2.6.19, raw fixes, so might need better reading of...
[openwrt.git] / target / linux / au1000-2.6 / patches / 004-mtx1_watchdog.patch
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
4 @@ -460,6 +460,14 @@
5 timer expired and no process has written to /dev/watchdog during
6 that time.
7
8 +config MTX1_WATCHDOG
9 + tristate "MTX-1 Hardware Watchdog"
10 + depends on WATCHDOG && MIPS_MTX1
11 + help
12 + Hardware driver for the AccessCube MTX-1 watchdog. This is a
13 + watchdog timer that will reboot the machine after a 100 seconds
14 + timer expired.
15 +
16 # S390 Architecture
17
18 config ZVM_WATCHDOG
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
22 @@ -65,6 +65,7 @@
23
24 # MIPS Architecture
25 obj-$(CONFIG_INDYDOG) += indydog.o
26 +obj-$(CONFIG_MTX1_WATCHDOG) += mtx-1_watchdog.o
27
28 # S390 Architecture
29
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
33 @@ -0,0 +1,246 @@
34 +/*
35 + * Driver for the MTX-1 Watchdog.
36 + *
37 + * (c) Copyright 2005 4G Systems <info@4g-systems.biz>, All Rights Reserved.
38 + * http://www.4g-systems.biz
39 + *
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.
44 + *
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.
48 + *
49 + * (c) Copyright 2005 4G Systems <info@4g-systems.biz>
50 + *
51 + * Release 0.01.
52 + *
53 + * Author: Michael Stickel michael.stickel@4g-systems.biz
54 + *
55 + *
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.
59 + *
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.
63 + */
64 +#include <linux/autoconf.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>
77 +
78 +#include <asm/mach-au1x00/au1000.h>
79 +
80 +#ifndef FALSE
81 +# define FALSE (0)
82 +#endif
83 +
84 +#ifndef TRUE
85 +# define TRUE (!FALSE)
86 +#endif
87 +
88 +
89 +//---------[ Hardware Functions ]-----------------
90 +
91 +static void mtx1_trigger_wd (void)
92 +{
93 + /*
94 + * toggle GPIO2_15
95 + */
96 +
97 + u32 tmp = au_readl(GPIO2_DIR);
98 + tmp = (tmp & ~(1<<15)) | ((~tmp) & (1<<15));
99 + au_writel (tmp, GPIO2_DIR);
100 +}
101 +
102 +static void mtx1_enable_wd (void)
103 +{
104 + au_writel (au_readl(GPIO2_DIR) | (u32)(1<<15), GPIO2_DIR);
105 +}
106 +
107 +static void mtx1_disable_wd (void)
108 +{
109 + au_writel (au_readl(GPIO2_DIR) & ~((u32)(1<<15)), GPIO2_DIR);
110 +}
111 +
112 +
113 +//---------[ Timer Functions ]-----------------
114 +
115 +static struct timer_list wd_trigger_timer;
116 +static char timer_is_running = FALSE;
117 +
118 +static void wd_timer_callback (unsigned long data)
119 +{
120 + if (timer_is_running)
121 + mod_timer (&wd_trigger_timer, jiffies + 5 * HZ);
122 + mtx1_trigger_wd();
123 +}
124 +
125 +static void start_wd_timer (void)
126 +{
127 + if (!timer_is_running) {
128 + struct timer_list *t = &wd_trigger_timer;
129 +
130 + init_timer (t);
131 + t->function = wd_timer_callback;
132 + t->data = (unsigned long)0L;
133 + t->expires = jiffies + 5 * HZ; // 5 seconds.
134 + add_timer (t);
135 + timer_is_running = TRUE;
136 + }
137 +}
138 +
139 +
140 +
141 +static void stop_wd_timer (void)
142 +{
143 + if (timer_is_running) {
144 + del_timer(&wd_trigger_timer);
145 + timer_is_running = FALSE;
146 + }
147 +}
148 +
149 +
150 +//---------[ File Functions ]-----------------
151 +
152 +static char restart_after_close;
153 +
154 +static int mtx1wd_open (struct inode *inode, struct file *file)
155 +{
156 + if (MINOR(inode->i_rdev) != WATCHDOG_MINOR) return -ENODEV;
157 + //MOD_INC_USE_COUNT;
158 +
159 + // stop the timer, if it is running. It will not be
160 + // started again, until the module is loaded again.
161 + stop_wd_timer();
162 +
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);
166 +
167 + return 0;
168 +}
169 +
170 +
171 +static int mtx1wd_release (struct inode *inode, struct file *file) {
172 + if (MINOR(inode->i_rdev)==WATCHDOG_MINOR) {
173 + }
174 + if (restart_after_close)
175 + start_wd_timer();
176 + //MOD_DEC_USE_COUNT;
177 + return 0;
178 +}
179 +
180 +
181 +static ssize_t mtx1wd_write (struct file *file, const char *buf, size_t count, loff_t *ppos) {
182 +
183 + mtx1_trigger_wd ();
184 +
185 + if (count > 0) {
186 + char buffer[10];
187 + int n = (count>9)?9:count;
188 +
189 + if (copy_from_user (&buffer, buf, n))
190 + return -EFAULT;
191 + buffer[n]=0;
192 +
193 + if (count >= 4 && strncmp("auto", buffer, 4)==0)
194 + restart_after_close = 1;
195 +
196 + else if (count >= 6 && strncmp("manual", buffer, 6)==0)
197 + restart_after_close = 0;
198 +
199 + return n;
200 + }
201 +
202 + return 0;
203 +}
204 +
205 +static ssize_t mtx1wd_read (struct file *file, char *buf, size_t count, loff_t *ppos)
206 +{
207 + char * state = restart_after_close ? "auto\n" : "manual\n";
208 + int n = strlen(state)+1;
209 +
210 + if (file->f_pos >= n)
211 + return 0;
212 +
213 + if (count < n)
214 + return -EINVAL;
215 +
216 + if(copy_to_user(buf, state, n))
217 + return -EFAULT;
218 +
219 + file->f_pos += n;
220 +
221 + return n;
222 +}
223 +
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
230 +};
231 +
232 +
233 +static struct miscdevice mtx1wd_miscdev = {
234 + WATCHDOG_MINOR,
235 + "watchdog",
236 + &mtx1wd_fops
237 +};
238 +
239 +
240 +
241 +//---------[ Module Functions ]-----------------
242 +
243 +
244 +static int __init init_mtx1_watchdog(void)
245 +{
246 + printk("MTX-1 watchdog driver\n");
247 +
248 + misc_register(&mtx1wd_miscdev);
249 +
250 + restart_after_close = 0;
251 +
252 + mtx1_enable_wd ();
253 +
254 + //-- trigger it for the first time.
255 + //-- We do not exactly know how long it has not been triggered.
256 + mtx1_trigger_wd ();
257 +
258 + // start a timer, that calls mtx1_trigger_wd every 5 seconds.
259 + start_wd_timer();
260 +
261 + return 0;
262 +}
263 +
264 +static void __exit exit_mtx1_watchdog(void) {
265 +
266 + // stop the timer, if it is running.
267 + stop_wd_timer();
268 +
269 + misc_deregister(&mtx1wd_miscdev);
270 +
271 + mtx1_disable_wd();
272 +}
273 +
274 +module_init(init_mtx1_watchdog);
275 +module_exit(exit_mtx1_watchdog);
276 +
277 +MODULE_AUTHOR("Michael Stickel");
278 +MODULE_DESCRIPTION("Driver for the MTX-1 watchdog");
279 +MODULE_LICENSE("GPL");
This page took 0.053049 seconds and 5 git commands to generate.