unify gcc 3.4 fixes, move flash chip drivers to generic patches, move diag_led driver...
[openwrt/svn-archive/archive.git] / openwrt / target / linux / linux-2.4 / patches / brcm / 004-diag_led.patch
1 diff -Nur linux-2.4.30/drivers/net/diag/Makefile linux-2.4.30.openwrt/drivers/net/diag/Makefile
2 --- linux-2.4.30/drivers/net/diag/Makefile 1970-01-01 01:00:00.000000000 +0100
3 +++ linux-2.4.30.openwrt/drivers/net/diag/Makefile 2005-06-28 11:35:26.000000000 +0200
4 @@ -0,0 +1,13 @@
5 +#$Id$
6 +
7 +EXTRA_CFLAGS := -I$(TOPDIR)/arch/mips/bcm947xx/include -DBCMDRIVER
8 +
9 +O_TARGET := diag.o
10 +
11 +MAC_OBJS := diag_led.o
12 +
13 +export-objs :=
14 +obj-y := $(MAC_OBJS)
15 +obj-m := $(O_TARGET)
16 +
17 +include $(TOPDIR)/Rules.make
18 diff -Nur linux-2.4.30/drivers/net/diag/diag_led.c linux-2.4.30.openwrt/drivers/net/diag/diag_led.c
19 --- linux-2.4.30/drivers/net/diag/diag_led.c 1970-01-01 01:00:00.000000000 +0100
20 +++ linux-2.4.30.openwrt/drivers/net/diag/diag_led.c 2005-06-28 11:35:26.000000000 +0200
21 @@ -0,0 +1,244 @@
22 +/*
23 + * diag_led.c - replacement diag module
24 + *
25 + * Copyright (C) 2004 Mike Baker,
26 + * Imre Kaloz <kaloz@dune.hu>
27 + *
28 + * This program is free software; you can redistribute it and/or
29 + * modify it under the terms of the GNU General Public License
30 + * as published by the Free Software Foundation; either version 2
31 + * of the License, or (at your option) any later version.
32 + *
33 + * This program is distributed in the hope that it will be useful,
34 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
35 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36 + * GNU General Public License for more details.
37 + *
38 + * You should have received a copy of the GNU General Public License
39 + * along with this program; if not, write to the Free Software
40 + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
41 + *
42 + * $Id: diag_led.c,v 1.5 2005/04/18 09:05:24 mbm Exp $
43 + */
44 +
45 +/*
46 + * ChangeLog:
47 + * 2004/03/28 initial release
48 + * 2004/08/26 asus & buffalo support added
49 + * 2005/03/14 asus wl-500g deluxe and buffalo v2 support added
50 + * 2005/04/13 added licensing informations
51 + * 2005/04/18 base reset polarity off initial readings
52 + */
53 +
54 +#include <linux/module.h>
55 +#include <linux/init.h>
56 +#include <linux/kernel.h>
57 +#include <linux/sysctl.h>
58 +#include <asm/io.h>
59 +#include <typedefs.h>
60 +#include <bcmdevs.h>
61 +#include <sbutils.h>
62 +
63 +extern char * nvram_get(const char *name);
64 +static void *sbh;
65 +
66 +// v2.x - - - - -
67 +#define DIAG_GPIO (1<<1)
68 +#define DMZ_GPIO (1<<7)
69 +
70 +static void set_gpio(uint32 mask, uint32 value) {
71 + sb_gpiocontrol(sbh,mask,0);
72 + sb_gpioouten(sbh,mask,mask);
73 + sb_gpioout(sbh,mask,value);
74 +}
75 +
76 +static void v2_set_diag(u8 state) {
77 + set_gpio(DIAG_GPIO,state);
78 +}
79 +static void v2_set_dmz(u8 state) {
80 + set_gpio(DMZ_GPIO,state);
81 +}
82 +
83 +// v1.x - - - - -
84 +#define LED_DIAG 0x13
85 +#define LED_DMZ 0x12
86 +
87 +static void v1_set_diag(u8 state) {
88 + if (!state) {
89 + *(volatile u8*)(KSEG1ADDR(BCM4710_EUART)+LED_DIAG)=0xFF;
90 + } else {
91 + *(volatile u8*)(KSEG1ADDR(BCM4710_EUART)+LED_DIAG);
92 + }
93 +}
94 +static void v1_set_dmz(u8 state) {
95 + if (!state) {
96 + *(volatile u8*)(KSEG1ADDR(BCM4710_EUART)+LED_DMZ)=0xFF;
97 + } else {
98 + *(volatile u8*)(KSEG1ADDR(BCM4710_EUART)+LED_DMZ);
99 + }
100 +}
101 +
102 +// - - - - -
103 +static void ignore(u8 ignored) {};
104 +
105 +// - - - - -
106 +#define BIT_DMZ 0x01
107 +#define BIT_DIAG 0x04
108 +
109 +void (*set_diag)(u8 state);
110 +void (*set_dmz)(u8 state);
111 +
112 +static unsigned int diag = 0;
113 +
114 +static void diag_change()
115 +{
116 + set_diag(0xFF); // off
117 + set_dmz(0xFF); // off
118 +
119 + if(diag & BIT_DIAG)
120 + set_diag(0x00); // on
121 + if(diag & BIT_DMZ)
122 + set_dmz(0x00); // on
123 +}
124 +
125 +static int proc_diag(ctl_table *table, int write, struct file *filp,
126 + void *buffer, size_t *lenp)
127 +{
128 + int r;
129 + r = proc_dointvec(table, write, filp, buffer, lenp);
130 + if (write && !r) {
131 + diag_change();
132 + }
133 + return r;
134 +}
135 +
136 +// - - - - -
137 +static unsigned char reset_gpio = 0;
138 +static unsigned char reset_polarity = 0;
139 +static unsigned int reset = 0;
140 +
141 +static int proc_reset(ctl_table *table, int write, struct file *filp,
142 + void *buffer, size_t *lenp)
143 +{
144 +
145 + if (reset_gpio) {
146 + sb_gpiocontrol(sbh,reset_gpio,reset_gpio);
147 + sb_gpioouten(sbh,reset_gpio,0);
148 + reset=!(sb_gpioin(sbh)&reset_gpio);
149 +
150 + if (reset_polarity) reset=!reset;
151 + } else {
152 + reset=0;
153 + }
154 +
155 + return proc_dointvec(table, write, filp, buffer, lenp);
156 +}
157 +
158 +// - - - - -
159 +static struct ctl_table_header *diag_sysctl_header;
160 +
161 +static ctl_table sys_diag[] = {
162 + {
163 + ctl_name: 2000,
164 + procname: "diag",
165 + data: &diag,
166 + maxlen: sizeof(diag),
167 + mode: 0644,
168 + proc_handler: proc_diag
169 + },
170 + {
171 + ctl_name: 2001,
172 + procname: "reset",
173 + data: &reset,
174 + maxlen: sizeof(reset),
175 + mode: 0444,
176 + proc_handler: proc_reset
177 + },
178 + { 0 }
179 +};
180 +
181 +static int __init diag_init()
182 +{
183 + char *buf;
184 + u32 board_type;
185 + sbh = sb_kattach();
186 + sb_gpiosetcore(sbh);
187 +
188 + board_type = sb_boardtype(sbh);
189 + printk(KERN_INFO "diag boardtype: %08x\n",board_type);
190 +
191 + set_diag=ignore;
192 + set_dmz=ignore;
193 +
194 + if ((board_type & 0xf00) == 0x400) {
195 + buf=nvram_get("boardtype")?:"";
196 + if (!strcmp(buf,"bcm94710dev")) {
197 + buf=nvram_get("boardnum")?:"";
198 + if (!strcmp(buf,"42")) {
199 + // wrt54g v1.x
200 + set_diag=v1_set_diag;
201 + set_dmz=v1_set_dmz;
202 + reset_gpio=(1<<6);
203 + }
204 + if (!strcmp(buf,"asusX")) {
205 + //asus wl-500g
206 + reset_gpio=(1<<6);
207 + }
208 + }
209 + if (!strcmp(buf,"bcm94710ap")) {
210 + buf=nvram_get("boardnum")?:"";
211 + if (!strcmp(buf,"42")) {
212 + // buffalo
213 + set_dmz=v2_set_dmz;
214 + reset_gpio=(1<<4);
215 + }
216 + if (!strcmp(buf,"44")) {
217 + //dell truemobile
218 + set_dmz=v2_set_dmz;
219 + reset_gpio=(1<<0);
220 + }
221 + }
222 + } else {
223 + buf=nvram_get("boardnum")?:"";
224 + if (!strcmp(buf,"42")) {
225 + //linksys
226 + set_diag=v2_set_diag;
227 + set_dmz=v2_set_dmz;
228 + reset_gpio=(1<<6);
229 + }
230 + if (!strcmp(buf,"44")) {
231 + //motorola
232 + reset_gpio=(1<<5);
233 + }
234 + if (!strcmp(buf,"00")) {
235 + //buffalo
236 + reset_gpio=(1<<7);
237 + }
238 + if (!strcmp(buf,"45")) {
239 + //wl-500g deluxe
240 + reset_gpio=(1<<6);
241 + }
242 + }
243 +
244 +
245 + sb_gpiocontrol(sbh,reset_gpio,reset_gpio);
246 + sb_gpioouten(sbh,reset_gpio,0);
247 + reset_polarity=!(sb_gpioin(sbh)&reset_gpio);
248 +
249 + diag_sysctl_header = register_sysctl_table(sys_diag, 0);
250 + diag_change();
251 +
252 + return 0;
253 +}
254 +
255 +static void __exit diag_exit()
256 +{
257 + unregister_sysctl_table(diag_sysctl_header);
258 +}
259 +
260 +EXPORT_NO_SYMBOLS;
261 +MODULE_AUTHOR("openwrt.org");
262 +MODULE_LICENSE("GPL");
263 +
264 +module_init(diag_init);
265 +module_exit(diag_exit);