Add chaostable from #1187, also enable netfilter modules for ixp4xx.
[openwrt.git] / target / linux / au1000-2.6 / patches / 006-mtx1_system_button.patch
1 diff -urN linux-2.6.16.7/arch/mips/au1000/mtx-1/irqmap.c linux-2.6.16.7.new/arch/mips/au1000/mtx-1/irqmap.c
2 --- linux-2.6.16.7/arch/mips/au1000/mtx-1/irqmap.c      2006-04-17 23:53:25.000000000 +0200
3 +++ linux-2.6.16.7.new/arch/mips/au1000/mtx-1/irqmap.c  2006-04-23 11:54:31.000000000 +0200
4 @@ -64,6 +64,7 @@
5         { AU1500_GPIO_202, INTC_INT_LOW_LEVEL, 0 },
6         { AU1500_GPIO_203, INTC_INT_LOW_LEVEL, 0 },
7         { AU1500_GPIO_205, INTC_INT_LOW_LEVEL, 0 },
8 +       { AU1500_GPIO_207, INTC_INT_RISE_AND_FALL_EDGE, 0 },
9  };
10  
11  int au1xxx_nr_irqs = sizeof(au1xxx_irq_map)/sizeof(au1xxx_irq_map_t);
12 diff -urN linux-2.6.16.7/arch/mips/au1000/mtx-1/Makefile linux-2.6.16.7.new/arch/mips/au1000/mtx-1/Makefile
13 --- linux-2.6.16.7/arch/mips/au1000/mtx-1/Makefile      2006-04-17 23:53:25.000000000 +0200
14 +++ linux-2.6.16.7.new/arch/mips/au1000/mtx-1/Makefile  2006-04-23 14:01:36.000000000 +0200
15 @@ -8,3 +8,4 @@
16  #
17  
18  lib-y := init.o board_setup.o irqmap.o
19 +obj-y := mtx-1_sysbtn.o
20 diff -urN linux-2.6.16.7/arch/mips/au1000/mtx-1/mtx-1_sysbtn.c linux-2.6.16.7.new/arch/mips/au1000/mtx-1/mtx-1_sysbtn.c
21 --- linux-2.6.16.7/arch/mips/au1000/mtx-1/mtx-1_sysbtn.c        1970-01-01 01:00:00.000000000 +0100
22 +++ linux-2.6.16.7.new/arch/mips/au1000/mtx-1/mtx-1_sysbtn.c    2006-04-23 14:01:17.000000000 +0200
23 @@ -0,0 +1,218 @@
24 +/*
25 + *      Driver for the MTX-1 System Button.
26 + *
27 + *      (c) Copyright 2005 4G Systems <info@4g-systems.biz>, All Rights Reserved.
28 + *                              http://www.4g-systems.biz
29 + *
30 + *      This program is free software; you can redistribute it and/or
31 + *      modify it under the terms of the GNU General Public License
32 + *      as published by the Free Software Foundation; either version
33 + *      2 of the License, or (at your option) any later version.
34 + *
35 + *      Neither Michael Stickel nor 4G Systeme GmbH admit liability nor provide
36 + *      warranty for any of this software. This material is provided
37 + *      "AS-IS" and at no charge.
38 + *
39 + *      (c) Copyright 2005    4G Systems <info@4g-systems.biz>
40 + *
41 + *      Release 0.01.
42 + *
43 + *      Author: Michael Stickel  michael.stickel@4g-systems.biz
44 + *
45 + *
46 + *      After the module is loaded there is a device /dev/misc/btn
47 + *      that can be read. It returns one char '1' if the button
48 + *      has been pressed an '0' if it has been released.
49 + */
50 +#include <linux/autoconf.h>
51 +#include <linux/module.h>
52 +#include <linux/version.h>
53 +#include <linux/types.h>
54 +#include <linux/errno.h>
55 +#include <linux/kernel.h>
56 +#include <linux/poll.h>
57 +#include <linux/sched.h>
58 +#include <linux/miscdevice.h>
59 +#include <linux/slab.h>
60 +#include <linux/init.h>
61 +#include <linux/irq.h>
62 +#include <linux/interrupt.h>
63 +
64 +#include <asm/uaccess.h>
65 +
66 +#include <asm/mach-au1x00/au1000.h>
67 +
68 +
69 +#ifndef FALSE
70 +# define FALSE (0)
71 +#endif
72 +
73 +#ifndef TRUE
74 +# define TRUE (!FALSE)
75 +#endif
76 +
77 +
78 +//---------[ declarations ]-----------------
79 +
80 +
81 +static DECLARE_WAIT_QUEUE_HEAD(mtx1btn_wait_queue);
82 +static char state_changed;
83 +static char last_value;
84 +static char is_inuse;
85 +
86 +
87 +//---------[ Hardware Functions ]-----------------
88 +
89 +// The MTX-1 Button is attached to GPIO207.
90 +#define MTX1_GPIO2_SYSBTN (7)
91 +#define MTX1_SYSBTN_IRQ   (AU1500_GPIO_207)
92 +
93 +
94 +static char mtx1_getbtn (int btnno)
95 +{
96 +  if (btnno==0) {
97 +    return (au_readl(GPIO2_PINSTATE) & (1<<MTX1_GPIO2_SYSBTN)) ? 0 : 1;
98 +  }
99 +  return 0;
100 +}
101 +
102 +static void mtx1_initbuttons (void)
103 +{
104 +  au_writel (au_readl(GPIO2_DIR) & ~(1<<MTX1_GPIO2_SYSBTN), GPIO2_DIR);
105 +}
106 +
107 +
108 +//---------[ Interrupt handling ]-----------------
109 +
110 +
111 +static void mtx1_btn_interrupt (int irq, void *private)
112 +{
113 +       char value = mtx1_getbtn(0);
114 +       if (last_value != value)
115 +       {
116 +               last_value = value;
117 +               state_changed = 1;
118 +               wake_up (&mtx1btn_wait_queue);
119 +       }
120 +//     kill_fasync(&async_queue, SIGIO, POLL_OUT);
121 +}
122 +
123 +
124 +static int mtx1_btn_startirq (void)
125 +{
126 +       if (!request_irq (MTX1_SYSBTN_IRQ, mtx1_btn_interrupt, 0 /* | SA_INTERRUPT */, "mtx1btn", (void *)&state_changed)) {
127 +               return 0;
128 +    }
129 +       return -1;
130 +}
131 +
132 +static int mtx1_btn_stopirq  (void)
133 +{
134 +       free_irq(MTX1_SYSBTN_IRQ, (void *)&state_changed);
135 +       return 0;
136 +}
137 +
138 +
139 +
140 +//---------[ File Functions ]-----------------
141 +
142 +
143 +static int mtx1sysbtn_minor = -1;
144 +
145 +
146 +static int mtx1sysbtn_open (struct inode *inode, struct file *file)
147 +{
148 +       if (MINOR(inode->i_rdev)!=mtx1sysbtn_minor) return -ENODEV;
149 +       if (is_inuse) return -EBUSY;
150 +       is_inuse=1;
151 +       last_value = mtx1_getbtn(0);
152 +       state_changed = 0;
153 +       return 0;
154 +}
155 +
156 +
157 +static int mtx1sysbtn_release (struct inode *inode, struct file *file) {
158 +       if (MINOR(inode->i_rdev)==mtx1sysbtn_minor) {
159 +               is_inuse=0;
160 +       }
161 +       return 0;
162 +}
163 +
164 +
165 +static ssize_t mtx1sysbtn_read (struct file *file, char *buf, size_t count, loff_t *ppos)
166 +{
167 +       if (count < 1)
168 +               return -EINVAL;
169 +       if (!state_changed)
170 +               interruptible_sleep_on (&mtx1btn_wait_queue);
171 +       state_changed = 0;
172 +       char c = last_value ? '1' : '0'; /* mtx1_getbtn(0) */
173 +       if(copy_to_user(buf, &c, 1))
174 +               return -EFAULT;
175 +       return 1;
176 +}
177 +
178 +
179 +static unsigned int mtx1sysbtn_poll (struct file *file, poll_table * wait)
180 +{
181 +  unsigned int mask = 0;
182 +
183 +  poll_wait (file, &mtx1btn_wait_queue, wait);
184 +
185 +  if (state_changed) // state changed since last time.
186 +    mask |= POLLIN | POLLRDNORM;
187 +
188 +  return mask;
189 +}
190 +
191 +
192 +static struct file_operations mtx1sysbtn_fops = {
193 +       .owner = THIS_MODULE,
194 +       .read = mtx1sysbtn_read,
195 +       .poll = mtx1sysbtn_poll,
196 +       .open = mtx1sysbtn_open,
197 +       .release = mtx1sysbtn_release
198 +};
199 +
200 +
201 +static struct miscdevice mtx1sysbtn_miscdev = {
202 +       MISC_DYNAMIC_MINOR /* SYSBTN_MINOR */ ,
203 +       "btn",
204 +       &mtx1sysbtn_fops
205 +};
206 +
207 +
208 +
209 +//---------[ Module Functions ]-----------------
210 +
211 +
212 +void __exit exit_mtx1_sysbtn (void)
213 +{
214 +       is_inuse = 1;
215 +       mtx1_btn_stopirq ();
216 +       misc_deregister(&mtx1sysbtn_miscdev);
217 +}
218 +
219 +
220 +static int __init init_mtx1_sysbtn (void)
221 +{
222 +       printk("MTX-1 System Button driver\n");
223 +       is_inuse = 1;
224 +       mtx1_initbuttons ();
225 +       if (misc_register (&mtx1sysbtn_miscdev) >= 0) {
226 +               mtx1sysbtn_minor = mtx1sysbtn_miscdev.minor;
227 +               if (mtx1_btn_startirq () == 0) {
228 +                       is_inuse=0;
229 +                       return 0;
230 +               }
231 +               misc_deregister(&mtx1sysbtn_miscdev);
232 +       }
233 +       return 1;
234 +}
235 +
236 +module_init(init_mtx1_sysbtn);
237 +module_exit(exit_mtx1_sysbtn);
238 +
239 +MODULE_AUTHOR("Michael Stickel");
240 +MODULE_DESCRIPTION("Driver for the MTX-1 system button");
241 +MODULE_LICENSE("GPL");