source: freewrt/package/broadcom-diag/diag_led.c@ 9036ea5

freewrt_1_0 freewrt_2_0
Last change on this file since 9036ea5 was db5651c, checked in by Waldemar Brodkorb <wbx@…>, 19 years ago

merge wbx-target-cleanup to trunk.

  • mk directory for some top level makefiles (build.mk,vars.mk)
  • add a separate configfs partition to all models, 128 kb big
  • add model and platform specific startup files and kernel configs
  • delete target/linux/package, add all addon kernel packages to packages
  • simplify target/linux/brcm-2.4/Makefile, abstraction to mk/ comes later
  • add target/image directory, place where the different images are created
  • default off for all extra packages, be sure that you enable all packages you need to get a dsl-capable router. snapshots will be created by a specific config which contains all needed stuff (iptables, pppoe, pptp, haserl, webif)

git-svn-id: svn://www.freewrt.org/trunk/freewrt@588 afb5a338-a214-0410-bd46-81f09a774fd1

  • Property mode set to 100644
File size: 7.0 KB
Line 
1/*
2 * diag_led.c - replacement diag module
3 *
4 * Copyright (C) 2004-2006 Mike Baker,
5 * Imre Kaloz <kaloz@dune.hu>,
6 * Felix Fietkau <nbd@openwrt.org>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 *
22 * $Id: 005-diag_led.patch 3355 2006-03-13 07:57:51Z nbd $
23 */
24
25/*
26 * ChangeLog:
27 * 2004/03/28 initial release
28 * 2004/08/26 asus & buffalo support added
29 * 2005/03/14 asus wl-500g deluxe and buffalo v2 support added
30 * 2005/04/13 added licensing informations
31 * 2005/04/18 base reset polarity off initial readings
32 */
33
34#include <linux/module.h>
35#include <linux/init.h>
36#include <linux/kernel.h>
37#include <linux/sysctl.h>
38#include <asm/io.h>
39#include <typedefs.h>
40#include <bcmdevs.h>
41#include <sbutils.h>
42
43extern char * nvram_get(const char *name);
44static void *sbh;
45
46// v2.x - - - - -
47#define BITS(n) ((1 << n) - 1)
48#define ISSET(n,b) ((n & (1 << b)) ? 1 : 0)
49#define DIAG_GPIO (1<<1)
50#define AOSS_GPIO (1<<6)
51#define DMZ_GPIO (1<<7)
52#define SES_GPIO ((1 << 2) | (1 << 3) | (1 << 5))
53
54static void set_gpio(uint32 mask, uint32 value) {
55 sb_gpiocontrol(sbh,mask,0);
56 sb_gpioouten(sbh,mask,mask);
57 sb_gpioout(sbh,mask,value);
58}
59
60static void v2_set_diag(u8 state) {
61 set_gpio(DIAG_GPIO,state);
62}
63static void v2_set_dmz(u8 state) {
64 set_gpio(DMZ_GPIO,state);
65}
66static void v2_set_aoss(u8 state) {
67 set_gpio(AOSS_GPIO,state);
68}
69static void v2_set_ses(u8 state) {
70 set_gpio(SES_GPIO, (ISSET(state, 0) << 2) | (ISSET(state, 1) << 3) | (ISSET(state, 2) << 5));
71}
72
73// v1.x - - - - -
74#define LED_DIAG 0x13
75#define LED_DMZ 0x12
76
77static void v1_set_diag(u8 state) {
78 if (!state) {
79 *(volatile u8*)(KSEG1ADDR(BCM4710_EUART)+LED_DIAG)=0xFF;
80 } else {
81 *(volatile u8*)(KSEG1ADDR(BCM4710_EUART)+LED_DIAG);
82 }
83}
84static void v1_set_dmz(u8 state) {
85 if (!state) {
86 *(volatile u8*)(KSEG1ADDR(BCM4710_EUART)+LED_DMZ)=0xFF;
87 } else {
88 *(volatile u8*)(KSEG1ADDR(BCM4710_EUART)+LED_DMZ);
89 }
90}
91
92// - - - - -
93static void ignore(u8 ignored) {};
94
95// - - - - -
96#define BIT_DMZ (1 << 0)
97#define BIT_DIAG (1 << 2)
98#define BIT_SES (BITS(3) << 3)
99
100void (*set_diag)(u8 state);
101void (*set_dmz)(u8 state);
102void (*set_ses)(u8 state);
103
104static unsigned int diag_reverse = 1;
105static unsigned int ses_reverse = 1;
106static unsigned int diag = 0;
107
108static void diag_change()
109{
110 set_diag(diag_reverse ? 0xFF : 0x00); // off
111 set_dmz(diag_reverse ? 0xFF : 0x00); // off
112 set_ses(ses_reverse ? 0xFF : 0x00); // off
113
114 if(diag & BIT_DIAG)
115 set_diag(diag_reverse ? 0x00 : 0xFF); // on
116 if(diag & BIT_DMZ)
117 set_dmz(diag_reverse ? 0x00 : 0xFF); // on
118 if(diag & BIT_SES)
119 set_ses(((ses_reverse ? ~diag : diag) >> 3) & BITS(3));
120}
121
122static int proc_diag(ctl_table *table, int write, struct file *filp,
123 void *buffer, size_t *lenp)
124{
125 int r;
126 r = proc_dointvec(table, write, filp, buffer, lenp);
127 if (write && !r) {
128 diag_change();
129 }
130 return r;
131}
132
133// - - - - -
134static unsigned char reset_gpio = 0;
135static unsigned char reset_polarity = 0;
136static unsigned int reset = 0;
137static unsigned char button_gpio = 0;
138static unsigned char button_polarity = 0;
139static unsigned int button = 0;
140
141
142static int read_gpio(int gpio, int polarity)
143{
144 int res;
145
146 if (gpio) {
147 sb_gpiocontrol(sbh,gpio,gpio);
148 sb_gpioouten(sbh,gpio,0);
149 res=!(sb_gpioin(sbh)&gpio);
150
151 return (polarity ? !res : res);
152 }
153
154 return 0;
155}
156
157static int proc_reset(ctl_table *table, int write, struct file *filp,
158 void *buffer, size_t *lenp)
159{
160 reset = read_gpio(reset_gpio, reset_polarity);
161
162 return proc_dointvec(table, write, filp, buffer, lenp);
163}
164
165static int proc_button(ctl_table *table, int write, struct file *filp,
166 void *buffer, size_t *lenp)
167{
168 button = read_gpio(button_gpio, button_polarity);
169
170 return proc_dointvec(table, write, filp, buffer, lenp);
171}
172
173// - - - - -
174static struct ctl_table_header *diag_sysctl_header;
175
176static ctl_table sys_diag[] = {
177 {
178 ctl_name: 2000,
179 procname: "diag",
180 data: &diag,
181 maxlen: sizeof(diag),
182 mode: 0644,
183 proc_handler: proc_diag
184 },
185 {
186 ctl_name: 2001,
187 procname: "reset",
188 data: &reset,
189 maxlen: sizeof(reset),
190 mode: 0444,
191 proc_handler: proc_reset
192 },
193 {
194 ctl_name: 2002,
195 procname: "button",
196 data: &button,
197 maxlen: sizeof(button),
198 mode: 0444,
199 proc_handler: proc_button
200 },
201 { 0 }
202};
203
204static int __init diag_init()
205{
206 char *buf;
207 u32 board_type;
208 sbh = sb_kattach();
209 sb_gpiosetcore(sbh);
210
211 board_type = sb_boardtype(sbh);
212 printk(KERN_INFO "diag boardtype: %08x\n",board_type);
213
214 set_diag=ignore;
215 set_dmz=ignore;
216 set_ses=ignore;
217
218 buf=nvram_get("pmon_ver") ?: "";
219 if (((board_type & 0xf00) == 0x400) && (strncmp(buf, "CFE", 3) != 0)) {
220 buf=nvram_get("boardtype")?:"";
221 if (!strcmp(buf,"bcm94710dev")) {
222 buf=nvram_get("boardnum")?:"";
223 if (!strcmp(buf,"42")) {
224 // wrt54g v1.x
225 set_diag=v1_set_diag;
226 set_dmz=v1_set_dmz;
227 reset_gpio=(1<<6);
228 }
229 if (!strcmp(buf,"asusX")) {
230 //asus wl-500g
231 reset_gpio=(1<<6);
232 }
233 }
234 if (!strcmp(buf,"bcm94710ap")) {
235 buf=nvram_get("boardnum")?:"";
236 if (!strcmp(buf,"42")) {
237 // buffalo
238 set_dmz=v2_set_dmz;
239 reset_gpio=(1<<4);
240 }
241 if (!strcmp(buf,"44")) {
242 //dell truemobile
243 set_dmz=v2_set_dmz;
244 reset_gpio=(1<<0);
245 }
246 }
247 } else {
248 buf=nvram_get("boardnum")?:"";
249 if (!strcmp(buf,"42")) {
250 //linksys
251 set_diag=v2_set_diag;
252 set_dmz=v2_set_dmz;
253 set_ses=v2_set_ses;
254
255 reset_gpio=(1<<6);
256 button_gpio=(1<<4);
257
258 if (!strcmp((nvram_get("boardtype")?:""), "0x0101")) // WRT54G3G
259 ses_reverse = 0;
260 else
261 ses_reverse = 1;
262 }
263 if (!strcmp(buf,"44")) {
264 //motorola
265 reset_gpio=(1<<5);
266 }
267 if (!strcmp(buf,"00")) {
268 //buffalo
269 diag_reverse = 0;
270 set_dmz=v2_set_diag;
271 set_diag=v2_set_aoss;
272 reset_gpio=(1<<7);
273 }
274 if (!strcmp(buf,"45")) {
275 //wl-500g deluxe
276 reset_gpio=(1<<6);
277 }
278 }
279
280 sb_gpiocontrol(sbh,reset_gpio,reset_gpio);
281 sb_gpioouten(sbh,reset_gpio,0);
282 reset_polarity=!(sb_gpioin(sbh)&reset_gpio);
283
284 if (button_gpio) {
285 sb_gpiocontrol(sbh,button_gpio,button_gpio);
286 sb_gpioouten(sbh,button_gpio,0);
287 button_polarity=!(sb_gpioin(sbh)&button_gpio);
288 } else {
289 // don't create /proc/button
290 sys_diag[2].ctl_name = 0;
291 }
292
293 diag_sysctl_header = register_sysctl_table(sys_diag, 0);
294 diag_change();
295
296 return 0;
297}
298
299static void __exit diag_exit()
300{
301 unregister_sysctl_table(diag_sysctl_header);
302}
303
304EXPORT_NO_SYMBOLS;
305MODULE_AUTHOR("openwrt.org");
306MODULE_LICENSE("GPL");
307
308module_init(diag_init);
309module_exit(diag_exit);
Note: See TracBrowser for help on using the repository browser.