]> pilppa.org Git - familiar-h63xx-build.git/blob - org.handhelds.familiar/packages/linux/linux-mtx-1-2.4.27/21-mtx-1-watchdog.diff
OE tree imported from monotone branch org.openembedded.oz354fam083 at revision 8b12e3...
[familiar-h63xx-build.git] / org.handhelds.familiar / packages / linux / linux-mtx-1-2.4.27 / 21-mtx-1-watchdog.diff
1 diff -Nurb linux/arch/mips/au1000/mtx-1/Makefile linux.wd/arch/mips/au1000/mtx-1/Makefile
2 --- linux/arch/mips/au1000/mtx-1/Makefile       2004-11-24 12:11:54.000000000 +0100
3 +++ linux.wd/arch/mips/au1000/mtx-1/Makefile    2005-03-09 17:58:40.000000000 +0100
4 @@ -15,6 +15,6 @@
5  
6  O_TARGET := mtx-1.o
7  
8 -obj-y := init.o board_setup.o irqmap.o
9 +obj-y := init.o board_setup.o irqmap.o mtx-1_watchdog.o
10  
11  include $(TOPDIR)/Rules.make
12 diff -Nurb linux/arch/mips/au1000/mtx-1/mtx-1_watchdog.c linux.wd/arch/mips/au1000/mtx-1/mtx-1_watchdog.c
13 --- linux/arch/mips/au1000/mtx-1/mtx-1_watchdog.c       1970-01-01 01:00:00.000000000 +0100
14 +++ linux.wd/arch/mips/au1000/mtx-1/mtx-1_watchdog.c    2005-03-09 18:28:06.000000000 +0100
15 @@ -0,0 +1,216 @@
16 +/*
17 + *      Driver for the MTX-1 Watchdog.
18 + *
19 + *      (c) Copyright 2005 4G Systems <info@4g-systems.biz>, All Rights Reserved.
20 + *                              http://www.4g-systems.biz
21 + *
22 + *      This program is free software; you can redistribute it and/or
23 + *      modify it under the terms of the GNU General Public License
24 + *      as published by the Free Software Foundation; either version
25 + *      2 of the License, or (at your option) any later version.
26 + *
27 + *      Neither Michael Stickel nor 4G Systems admit liability nor provide
28 + *      warranty for any of this software. This material is provided
29 + *      "AS-IS" and at no charge.
30 + *
31 + *      (c) Copyright 2005    4G Systems <info@4g-systems.biz>
32 + *
33 + *      Release 0.01.
34 + *
35 + *      Author: Michael Stickel  michael.stickel@4g-systems.biz
36 + *
37 + *
38 + *      The Watchdog is configured to reset the MTX-1
39 + *      if it is not triggered for 100 seconds.
40 + *      It should not be triggered more often than 1.6 seconds.
41 + *
42 + *      A timer triggers the watchdog every 5 seconds, until
43 + *      it is opened for the first time. After the first open
44 + *      it MUST be triggered every 2..95 seconds.
45 + */
46 +#include <linux/config.h>
47 +#include <linux/module.h>
48 +#include <linux/version.h>
49 +#include <linux/types.h>
50 +#include <linux/errno.h>
51 +#include <linux/kernel.h>
52 +#include <linux/sched.h>
53 +#include <linux/miscdevice.h>
54 +#include <linux/watchdog.h>
55 +#include <linux/slab.h>
56 +#include <linux/init.h>
57 +
58 +#include <asm/au1000.h>
59 +
60 +
61 +#ifndef FALSE
62 +# define FALSE (0)
63 +#endif
64 +
65 +#ifndef TRUE
66 +# define TRUE (!FALSE)
67 +#endif
68 +
69 +
70 +//---------[ Hardware Functions ]-----------------
71 +
72 +static void mtx1_trigger_wd (void)
73 +{
74 +       /*
75 +        * toggle GPIO2_15
76 +        */
77 +
78 +       u32 tmp = au_readl(GPIO2_DIR);
79 +       tmp = (tmp & ~(1<<15)) | ((~tmp) & (1<<15));
80 +       au_writel (tmp, GPIO2_DIR);
81 +}
82 +
83 +static void mtx1_enable_wd (void)
84 +{
85 +       au_writel (au_readl(GPIO2_DIR) | (u32)(1<<15), GPIO2_DIR);
86 +}
87 +
88 +static void mtx1_disable_wd (void)
89 +{
90 +       au_writel (au_readl(GPIO2_DIR) & ~((u32)(1<<15)), GPIO2_DIR);
91 +}
92 +
93 +
94 +//---------[ Timer Functions ]-----------------
95 +
96 +static struct timer_list   wd_trigger_timer;
97 +static char                timer_is_running = FALSE;
98 +
99 +static void wd_timer_callback (unsigned long data)
100 +{
101 +       if (timer_is_running)
102 +               mod_timer (&wd_trigger_timer, jiffies + 5 * HZ);
103 +       mtx1_trigger_wd ();
104 +}
105 +
106 +static void start_wd_timer (void)
107 +{
108 +       if (!timer_is_running) {
109 +               struct timer_list *t = &wd_trigger_timer;
110 +               
111 +               init_timer (t);
112 +               t->function = wd_timer_callback;
113 +               t->data     = (unsigned long)0L;
114 +               t->expires  = jiffies + 5 * HZ;   // 5 seconds.
115 +               add_timer (t);
116 +               timer_is_running = TRUE;
117 +       }
118 +}
119 +
120 +
121 +
122 +static void stop_wd_timer (void)
123 +{
124 +       if (timer_is_running) {
125 +               del_timer(&wd_trigger_timer);
126 +               timer_is_running = FALSE;
127 +       }
128 +}
129 +
130 +
131 +//---------[ File Functions ]-----------------
132 +
133 +static int mtx1wd_open (struct inode *inode, struct file *file)
134 +{
135 +       if (MINOR(inode->i_rdev)!=WATCHDOG_MINOR) return -ENODEV;
136 +       MOD_INC_USE_COUNT;
137 +
138 +       // stop the timer, if it is running. It will not be
139 +       // started again, until the module is loaded again.
140 +       stop_wd_timer();
141 +
142 +       // sleep for 2 seconds, to ensure, that the wd is
143 +       // not triggered more often than every 2 seconds.
144 +       schedule_timeout (2 * HZ);
145 +
146 +       return 0;
147 +}
148 +
149 +
150 +static int mtx1wd_release (struct inode *inode, struct file *file) {
151 +       if (MINOR(inode->i_rdev)==WATCHDOG_MINOR) {
152 +       }
153 +       MOD_DEC_USE_COUNT;
154 +       return 0;
155 +}
156 +
157 +
158 +static ssize_t mtx1wd_write (struct file *file, const char *buf, size_t count, loff_t *ppos) {
159 +       if (ppos!=&file->f_pos)
160 +               return -ESPIPE;
161 +
162 +       if (count) {
163 +               mtx1_trigger_wd ();
164 +               return 1;
165 +       }
166 +       return 0;
167 +}
168 +
169 +
170 +
171 +static struct file_operations mtx1wd_fops = {
172 +       .owner = THIS_MODULE,
173 +       .llseek = NULL,
174 +       .read = NULL,
175 +       .write = mtx1wd_write,
176 +       .readdir = NULL,
177 +       .poll = NULL,
178 +       .ioctl = NULL,
179 +       .mmap = NULL,
180 +       .open = mtx1wd_open,
181 +       .flush = NULL,
182 +       .release = mtx1wd_release
183 +};
184 +
185 +
186 +static struct miscdevice mtx1wd_miscdev = {
187 +       WATCHDOG_MINOR,
188 +       "watchdog",
189 +       &mtx1wd_fops
190 +};
191 +
192 +
193 +
194 +//---------[ Module Functions ]-----------------
195 +
196 +
197 +void cleanup_module (void)
198 +{
199 +       // stop the timer, if it is running.
200 +       stop_wd_timer();
201 +
202 +       misc_deregister(&mtx1wd_miscdev);
203 +
204 +       mtx1_disable_wd ();
205 +}
206 +
207 +
208 +int __init init_mtx1_watchdog (void)
209 +{
210 +       printk("MTX-1 watchdog driver\n");
211 +
212 +       mtx1_enable_wd ();
213 +
214 +       //-- trigger it for the first time.
215 +       //-- We do not exactly know how long it has not been triggered.
216 +       mtx1_trigger_wd ();
217 +
218 +       misc_register (&mtx1wd_miscdev);
219 +
220 +       // start a timer, that calls mtx1_trigger_wd every 5 seconds.
221 +       start_wd_timer();
222 +
223 +       return 0;
224 +}
225 +
226 +__initcall(init_mtx1_watchdog);
227 +
228 +MODULE_AUTHOR("Michael Stickel");
229 +MODULE_DESCRIPTION("Driver for the MTX-1 watchdog");
230 +MODULE_LICENSE("GPL");
231 +EXPORT_NO_SYMBOLS;