don't pad aruba images - unnecessary with the jffs2 hack
[openwrt.git] / target / linux / ar7-2.4 / patches / 002-led_driver.patch
1 diff -urN linux.dev/drivers/char/Config.in linux.dev2/drivers/char/Config.in
2 --- linux.dev/drivers/char/Config.in 2005-10-21 17:02:20.199991500 +0200
3 +++ linux.dev2/drivers/char/Config.in 2005-10-21 18:03:44.541778750 +0200
4 @@ -133,6 +133,10 @@
5 fi
6 fi
7 fi
8 +if [ "$CONFIG_AR7" = "y" ]; then
9 + bool 'Enable LED support' CONFIG_AR7_LED
10 +fi
11 +
12 if [ "$CONFIG_EXPERIMENTAL" = "y" -a "$CONFIG_ZORRO" = "y" ]; then
13 tristate 'Commodore A2232 serial support (EXPERIMENTAL)' CONFIG_A2232
14 fi
15 diff -urN linux.dev/drivers/char/Makefile linux.dev2/drivers/char/Makefile
16 --- linux.dev/drivers/char/Makefile 2005-10-21 17:02:20.199991500 +0200
17 +++ linux.dev2/drivers/char/Makefile 2005-10-21 18:03:44.541778750 +0200
18 @@ -190,6 +190,12 @@
19 obj-$(CONFIG_PCI) += keyboard.o $(KEYMAP)
20 endif
21
22 +#
23 +# Texas Intruments LED driver
24 +#
25 +obj-$(CONFIG_AR7_LED) += avalanche_led/avalanche_led.o
26 +subdir-$(CONFIG_AR7_LED) += avalanche_led
27 +
28 obj-$(CONFIG_HIL) += hp_keyb.o
29 obj-$(CONFIG_MAGIC_SYSRQ) += sysrq.o
30 obj-$(CONFIG_ATARI_DSP56K) += dsp56k.o
31 diff -urN linux.dev/drivers/char/avalanche_led/Makefile linux.dev2/drivers/char/avalanche_led/Makefile
32 --- linux.dev/drivers/char/avalanche_led/Makefile 1970-01-01 01:00:00.000000000 +0100
33 +++ linux.dev2/drivers/char/avalanche_led/Makefile 2005-10-21 18:03:44.513777000 +0200
34 @@ -0,0 +1,23 @@
35 +# File: drivers/char/avalanche_led/Makefile
36 +#
37 +# Makefile for the Linux LED device driver.
38 +#
39 +
40 +
41 +O_TARGET := avalanche_led.o
42 +obj-m := avalanche_led.o
43 +list-multi := avalanche_led.o
44 +
45 +EXTRA_CFLAGS := -I$(TOPDIR)/include/asm/ar7
46 +
47 +export-objs := ledmod.o leds.o
48 +
49 +avalanche_led-objs := ledmod.o gpio.o uartled.o leds.o
50 +
51 +include $(TOPDIR)/Rules.make
52 +
53 +avalanche_led.o: $(avalanche_led-objs)
54 + $(LD) -r -o $@ $(avalanche_led-objs)
55 +
56 +clean:
57 + rm -f core *.o *.a *.s
58 diff -urN linux.dev/drivers/char/avalanche_led/gpio.c linux.dev2/drivers/char/avalanche_led/gpio.c
59 --- linux.dev/drivers/char/avalanche_led/gpio.c 1970-01-01 01:00:00.000000000 +0100
60 +++ linux.dev2/drivers/char/avalanche_led/gpio.c 2005-10-21 18:03:44.513777000 +0200
61 @@ -0,0 +1,382 @@
62 +#include <linux/kernel.h>
63 +#include <asm/uaccess.h>
64 +#include <linux/spinlock.h>
65 +#include <linux/proc_fs.h>
66 +#include <linux/fs.h>
67 +#include <linux/timer.h>
68 +#include <linux/module.h>
69 +
70 +#include <asm/ar7/tnetd73xx_err.h>
71 +#include <asm/ar7/tnetd73xx_misc.h>
72 +#include <asm/ar7/ledapp.h>
73 +
74 +#define TRUE 1
75 +#define FALSE 0
76 +
77 +#if defined CONFIG_AR7WRD || defined CONFIG_AR7RD
78 +
79 +#define AR7_RESET_FILE "led_mod/ar7reset"
80 +#define AR7_VERSION_FILE "led_mod/hardware_version"
81 +#define AR7_RESET_GPIO 11
82 +#define RESET_POLL_TIME 1
83 +#define RESET_HOLD_TIME 4
84 +#define NO_OF_LEDS
85 +
86 +static struct proc_dir_entry *reset_file;
87 +static int res_state = 0;
88 +static int count;
89 +static struct timer_list *pTimer = NULL;
90 +static ssize_t proc_read_reset_fops(struct file *filp,
91 + char *buf,size_t count , loff_t *offp);
92 +
93 +static ssize_t proc_read_hwversion_fops(struct file *filp,
94 + char *buf,size_t count , loff_t *offp);
95 +
96 +struct file_operations reset_fops = {
97 + read: proc_read_reset_fops
98 + };
99 +struct file_operations hardware_version_fops = {
100 + read: proc_read_hwversion_fops
101 + };
102 +#endif
103 +
104 +static spinlock_t device_lock;
105 +led_reg_t temp[15];
106 +
107 +static void gpio_led_on( unsigned long param )
108 +{
109 + unsigned int flags;
110 +
111 + spin_lock_irqsave(&device_lock, flags);
112 +
113 + tnetd73xx_gpio_out(param,FALSE);
114 + spin_unlock_irqrestore(&device_lock, flags);
115 +}
116 +
117 +static void gpio_led_off ( unsigned long param )
118 +{
119 + unsigned int flags = 0x00;
120 +
121 + spin_lock_irqsave(&device_lock, flags);
122 +
123 + tnetd73xx_gpio_out(param,TRUE);
124 + spin_unlock_irqrestore(&device_lock, flags);
125 +}
126 +
127 +static void gpio_led_init( unsigned long param)
128 +{
129 + tnetd73xx_gpio_ctrl(param,GPIO_PIN,GPIO_OUTPUT_PIN);
130 +}
131 +
132 +static void board_gpio_reset(void)
133 +{
134 + /* Initialize the link mask */
135 + device_lock = SPIN_LOCK_UNLOCKED;
136 + return;
137 +}
138 +
139 +#if defined CONFIG_AR7WRD || defined CONFIG_AR7RD
140 +
141 +static ssize_t proc_read_hwversion_fops(struct file *filp, char *buf,
142 + size_t count, loff_t *offp)
143 +{
144 + char line[8];
145 + int len = 0;
146 + if( *offp != 0 )
147 + return 0;
148 +
149 + len = sprintf(line, "%d%d.%d%d%d%d\n", tnetd73xx_gpio_in(20),
150 + tnetd73xx_gpio_in(21), tnetd73xx_gpio_in(22),
151 + tnetd73xx_gpio_in(23), tnetd73xx_gpio_in(24),
152 + tnetd73xx_gpio_in(25));
153 +
154 + copy_to_user(buf, line, len);
155 + *offp = len;
156 + return len;
157 +}
158 +
159 +static ssize_t proc_read_reset_fops(struct file *filp,
160 + char *buf,size_t count , loff_t *offp)
161 +{
162 + char * pdata = NULL;
163 + char line[3];
164 + int len = 0;
165 + if( *offp != 0 )
166 + return 0;
167 +
168 + pdata = buf;
169 + len = sprintf(line,"%d\n", res_state );
170 +//wwzh
171 +// res_state = 0;
172 + copy_to_user(buf,line,len );
173 + *offp = len;
174 + return len;
175 +}
176 +
177 +static void reset_timer_func(unsigned long data)
178 +{
179 +//wwzh
180 +#if 0
181 + count = (tnetd73xx_gpio_in(AR7_RESET_GPIO) == 0) ? count + 1: 0;
182 + if( count >= RESET_HOLD_TIME/RESET_POLL_TIME )
183 +#endif
184 + if (tnetd73xx_gpio_in(AR7_RESET_GPIO) == 0)
185 + res_state = 1;
186 + else
187 + res_state = 0;
188 + pTimer->expires = jiffies + HZ*RESET_POLL_TIME;
189 + add_timer (pTimer);
190 + return;
191 +}
192 +
193 +static void hardware_version_init(void)
194 +{
195 + static struct proc_dir_entry *hardware_version_file;
196 + hardware_version_file = create_proc_entry(AR7_VERSION_FILE, 0777, NULL);
197 + if(hardware_version_file == NULL)
198 + return;
199 +
200 + hardware_version_file->owner = THIS_MODULE;
201 + hardware_version_file->proc_fops = &hardware_version_fops;
202 +
203 + tnetd73xx_gpio_ctrl(20,GPIO_PIN,GPIO_INPUT_PIN);
204 + tnetd73xx_gpio_ctrl(21,GPIO_PIN,GPIO_INPUT_PIN);
205 + tnetd73xx_gpio_ctrl(22,GPIO_PIN,GPIO_INPUT_PIN);
206 + tnetd73xx_gpio_ctrl(23,GPIO_PIN,GPIO_INPUT_PIN);
207 + tnetd73xx_gpio_ctrl(24,GPIO_PIN,GPIO_INPUT_PIN);
208 + tnetd73xx_gpio_ctrl(25,GPIO_PIN,GPIO_INPUT_PIN);
209 +
210 + return;
211 +}
212 +
213 +static void reset_init(void)
214 +{
215 + /* Create board reset proc file */
216 + reset_file = create_proc_entry( AR7_RESET_FILE, 0777, NULL);
217 + if( reset_file == NULL)
218 + goto reset_file;
219 + reset_file->owner = THIS_MODULE;
220 + reset_file->proc_fops = &reset_fops;
221 +
222 + /* Initialise GPIO 11 for input */
223 + tnetd73xx_gpio_ctrl(AR7_RESET_GPIO,GPIO_PIN,GPIO_INPUT_PIN);
224 +
225 + /* Create a timer which fires every seconds */
226 + pTimer = kmalloc(sizeof(struct timer_list),GFP_KERNEL);
227 + init_timer( pTimer );
228 + pTimer->function = reset_timer_func;
229 + pTimer->data = 0;
230 + /* Start the timer */
231 + reset_timer_func(0);
232 + return ;
233 +
234 + reset_file:
235 + remove_proc_entry("AR7_RESET_FILE",NULL);
236 + return;
237 +}
238 +#endif
239 +/*************wwzh****************/
240 +#if 1
241 +extern unsigned int sys_mod_state;
242 +extern unsigned int wan_mod_state;
243 +extern unsigned int wlan_mod_state;
244 +void sys_led_init(void)
245 +{
246 + tnetd73xx_gpio_ctrl(4, GPIO_PIN, GPIO_OUTPUT_PIN);
247 + tnetd73xx_gpio_ctrl(5, GPIO_PIN, GPIO_OUTPUT_PIN);
248 + tnetd73xx_gpio_ctrl(8, GPIO_PIN, GPIO_OUTPUT_PIN);
249 +
250 + tnetd73xx_gpio_out(4, FALSE);
251 + tnetd73xx_gpio_out(5, TRUE);
252 + tnetd73xx_gpio_out(8, TRUE);
253 +
254 +
255 + sys_mod_state = 2;
256 +
257 +}
258 +void wan_led_init(void)
259 +{
260 +
261 + tnetd73xx_gpio_ctrl(2, GPIO_PIN, GPIO_OUTPUT_PIN);
262 + tnetd73xx_gpio_ctrl(3, GPIO_PIN, GPIO_OUTPUT_PIN);
263 +
264 + tnetd73xx_gpio_out(2, FALSE);
265 + tnetd73xx_gpio_out(3, FALSE);
266 +
267 + wan_mod_state = 1;
268 +}
269 +//wwzh wireless
270 +#if 0
271 +void wlan_led_init(void)
272 +{
273 + //unsigned long i = 0;
274 + tnetd73xx_gpio_ctrl(12, GPIO_PIN, GPIO_OUTPUT_PIN);
275 + tnetd73xx_gpio_ctrl(13, GPIO_PIN, GPIO_OUTPUT_PIN);
276 +
277 + tnetd73xx_gpio_out(12, FALSE);
278 + tnetd73xx_gpio_out(13, TRUE);
279 + //for (i = 0; i < 0x20000000; i++);
280 + wlan_mod_state = 1;
281 +}
282 +#endif
283 +
284 +#endif
285 +/*************end ****************/
286 +
287 +void board_gpio_init(void)
288 +{
289 +
290 + board_gpio_reset();
291 +/**************wwzh*************/
292 + sys_led_init();
293 + wan_led_init();
294 +
295 + //junzhao 2004.3.15
296 + hardware_version_init();
297 +
298 + //wlan_led_init();
299 +
300 + /* Register Device MAX_LED_ID + 1 for reset to factory default */
301 + temp[0].param = 0;
302 + temp[0].init = reset_init;
303 + temp[0].onfunc = 0;
304 + temp[0].offfunc = 0;
305 + register_led_drv( MAX_LED_ID + 1 , &temp[0]);
306 +//wwzh for wireless led
307 +#if 1
308 + /* Register led 12 WiFi 6 */
309 + temp[1].param = 6;
310 + temp[1].init = gpio_led_init;
311 + temp[1].onfunc = gpio_led_on;
312 + temp[1].offfunc = gpio_led_off;
313 + register_led_drv( 12 , &temp[1]);
314 +
315 +#endif
316 +
317 +#if 0
318 +/**************end ************/
319 +#if defined(CONFIG_AR5D01)
320 + /* Register led 1 GPIO0 */
321 + temp[0].param = GPIO_0;
322 + temp[0].init = gpio_led_init;
323 + temp[0].onfunc = gpio_led_on;
324 + temp[0].offfunc = gpio_led_off;
325 + register_led_drv( 1 , &temp[0]);
326 +
327 + /* Register led 2 EINT1 */
328 + temp[1].param = EINT_1;
329 + temp[1].init = gpio_led_init;
330 + temp[1].onfunc = gpio_led_on;
331 + temp[1].offfunc = gpio_led_off;
332 + register_led_drv( 2 , &temp[1]);
333 +
334 + /* Register led 5 EINT1 */
335 + temp[2].param = GPIO_1;
336 + temp[2].init = gpio_led_init;
337 + temp[2].onfunc = gpio_led_on;
338 + temp[2].offfunc = gpio_led_off;
339 + register_led_drv( 5 , &temp[2]);
340 +#endif
341 +
342 +#if defined(CONFIG_AR5W01)
343 + /* Register led 5 GPIO_1 */
344 + temp[0].param = GPIO_1;
345 + temp[0].init = gpio_led_init;
346 + temp[0].onfunc = gpio_led_on;
347 + temp[0].offfunc = gpio_led_off;
348 + register_led_drv( 5 , &temp[0]);
349 +
350 + /* Register led 7 GPIO_0 */
351 + temp[1].param = GPIO_0;
352 + temp[1].init = gpio_led_init;
353 + temp[1].onfunc = gpio_led_on;
354 + temp[1].offfunc = gpio_led_off;
355 + register_led_drv( 7 , &temp[1]);
356 +#endif
357 +
358 +//wwzh #if defined(CONFIG_AR7RD)
359 +#if defined CONFIG_AR7WRD || defined CONFIG_AR7RD
360 + /* Register led 5 Green PPPOE GPIO 13 */
361 + temp[0].param = 13;
362 + temp[0].init = gpio_led_init;
363 + temp[0].onfunc = gpio_led_on;
364 + temp[0].offfunc = gpio_led_off;
365 + register_led_drv( 5 , &temp[0]);
366 +
367 + /* Register led 7 Green USB GPIO 12 */
368 + temp[1].param = 12;
369 + temp[1].init = gpio_led_init;
370 + temp[1].onfunc = gpio_led_on;
371 + temp[1].offfunc = gpio_led_off;
372 + register_led_drv( 7 , &temp[1]);
373 +
374 + /* Register Device MAX_LED_ID + 1 for reset to factory default */
375 + temp[2].param = 0;
376 + temp[2].init = reset_init;
377 + temp[2].onfunc = 0;
378 + temp[2].offfunc = 0;
379 + register_led_drv( MAX_LED_ID + 1 , &temp[2]);
380 +
381 + /* Register led 8 RED DSL GPIO 10 */
382 + temp[3].param = 10;
383 + temp[3].init = gpio_led_init;
384 + temp[3].onfunc = gpio_led_on;
385 + temp[3].offfunc = gpio_led_off;
386 + register_led_drv( 8 , &temp[3]);
387 +
388 + /* Register led 9 RED PPPoE down GPIO 9 */
389 + temp[4].param = 9;
390 + temp[4].init = gpio_led_init;
391 + temp[4].onfunc = gpio_led_on;
392 + temp[4].offfunc = gpio_led_off;
393 + register_led_drv( 9 , &temp[4]);
394 +
395 + /* Register led 10 DSL down GPIO 8 */
396 + temp[5].param = 8;
397 + temp[5].init = gpio_led_init;
398 + temp[5].onfunc = gpio_led_on;
399 + temp[5].offfunc = gpio_led_off;
400 + register_led_drv( 10 , &temp[5]);
401 +
402 + /* Register led 11 Power GPIO 7 */
403 + temp[6].param = 7;
404 + temp[6].init = gpio_led_init;
405 + temp[6].onfunc = gpio_led_on;
406 + temp[6].offfunc = gpio_led_off;
407 + register_led_drv( 11 , &temp[6]);
408 +
409 + /* Register led 12 WiFi 6 */
410 + temp[7].param = 6;
411 + temp[7].init = gpio_led_init;
412 + temp[7].onfunc = gpio_led_on;
413 + temp[7].offfunc = gpio_led_off;
414 + register_led_drv( 12 , &temp[7]);
415 +
416 + /* Register led 13 ELINK(AA1313) GPIO 15 */
417 + temp[8].param = 15;
418 + temp[8].init = gpio_led_init;
419 + temp[8].onfunc = gpio_led_on;
420 + temp[8].offfunc = gpio_led_off;
421 + register_led_drv( 13 , &temp[8]);
422 +
423 + /* Register led 14 EACT(Y13) GPIO 16 */
424 + temp[9].param = 16;
425 + temp[9].init = gpio_led_init;
426 + temp[9].onfunc = gpio_led_on;
427 + temp[9].offfunc = gpio_led_off;
428 + register_led_drv( 14 , &temp[9]);
429 +
430 +#endif
431 +/**************wwzh**************/
432 +#endif
433 +/**************end **************/
434 + return;
435 +}
436 +
437 +
438 +
439 +
440 +
441 +
442 +
443 +
444 diff -urN linux.dev/drivers/char/avalanche_led/ledmod.c linux.dev2/drivers/char/avalanche_led/ledmod.c
445 --- linux.dev/drivers/char/avalanche_led/ledmod.c 1970-01-01 01:00:00.000000000 +0100
446 +++ linux.dev2/drivers/char/avalanche_led/ledmod.c 2005-10-21 18:03:44.513777000 +0200
447 @@ -0,0 +1,1116 @@
448 +#include <linux/config.h>
449 +#include <linux/init.h>
450 +#include <linux/kernel.h>
451 +#include <linux/proc_fs.h>
452 +#include <asm/uaccess.h>
453 +#include <linux/fs.h>
454 +#include <linux/timer.h>
455 +#include <linux/delay.h>
456 +#include <linux/spinlock.h>
457 +#include <asm/ar7/avalanche_regs.h>
458 +#include <asm/ar7/ledapp.h>
459 +#include <linux/module.h>
460 +
461 +#define LED_ON 1
462 +#define LED_OFF 2
463 +#define LED_BLINK 3
464 +#define LED_FLASH 4
465 +
466 +#define LED_BLINK_UP 5
467 +#define LED_BLINK_DOWN 6
468 +
469 +extern void avalanche_leds_init(void);
470 +
471 +/***********wwzh**************/
472 +unsigned int sys_mod_state;
473 +unsigned int wan_mod_state;
474 +unsigned int wlan_mod_state;
475 +
476 +struct timer_list *pWanTimer = NULL;
477 +struct timer_list *pWlanTimer = NULL;
478 +/***********end **************/
479 +
480 +typedef struct state_entry{
481 + unsigned char mode;
482 + unsigned char led;
483 + void (*handler)(struct state_entry *pState);
484 + unsigned long param;
485 +}state_entry_t;
486 +
487 +typedef struct mod_entry{
488 + state_entry_t *states[MAX_STATE_ID];
489 +}mod_entry_t;
490 +
491 +static mod_entry_t *modArr[MAX_MOD_ID];
492 +static struct proc_dir_entry *led_proc_dir,*led_file;
493 +
494 +/* index of the array is the led number HARDWARE SPECIFIC*/
495 +typedef struct led_data{
496 + led_reg_t *led;
497 + int state;
498 + struct timer_list *pTimer;
499 + unsigned char timer_running;
500 + unsigned long param;
501 +}led_data_t;
502 +
503 +led_data_t led_arr[MAX_LED_ID + 1];
504 +/*!!! The last device is actually being used for ar7 reset to factory default */
505 +
506 +
507 +static spinlock_t config_lock;
508 +
509 +static void board_led_link_up( state_entry_t *pState );
510 +static void board_led_link_down( state_entry_t *pState );
511 +static void board_led_activity_on( state_entry_t *pState );
512 +static void board_led_activity_off( state_entry_t *pState );
513 +static void led_timer_func(unsigned long data);
514 +
515 +extern void board_gpio_init(void);
516 +extern void uart_led_init(void);
517 +
518 +static ssize_t proc_read_led_fops(struct file *filp,
519 + char *buf,size_t count , loff_t *offp);
520 +static ssize_t proc_write_led_fops(struct file *filp,const char *buffer,
521 + size_t count , loff_t *offp);
522 +static int config_led( unsigned long y);
523 +
524 +struct file_operations led_fops = {
525 + read: proc_read_led_fops,
526 + write: proc_write_led_fops,
527 + };
528 +
529 +static int led_atoi( char *name)
530 +{
531 + int val = 0;
532 + for(;;name++)
533 + {
534 + switch(*name)
535 + {
536 + case '0'...'9':
537 + val = val*10+(*name - '0');
538 + break;
539 + default:
540 + return val;
541 + }
542 + }
543 +}
544 +
545 +static int free_memory(void)
546 +{
547 + int i, j;
548 +
549 + for( i = 0; i < MAX_MOD_ID ; i++)
550 + {
551 + if( modArr[i] != NULL )
552 + {
553 + for( j = 0; j < MAX_STATE_ID ; j++ )
554 + {
555 + if( modArr[i]->states[j] != NULL )
556 + kfree( modArr[i]->states[j]);
557 + }
558 + kfree(modArr[i]);
559 + modArr[i] = NULL;
560 + }
561 + }
562 + return 0;
563 +}
564 +
565 +static int led_on( state_entry_t *pState )
566 +{
567 + if( led_arr[pState->led].led == NULL)
568 + return -1;
569 + led_arr[pState->led].led->onfunc( led_arr[pState->led].led->param);
570 + return 0;
571 +}
572 +
573 +static int led_off( state_entry_t *pState )
574 +{
575 + if( led_arr[pState->led].led == NULL)
576 + return -1;
577 + led_arr[pState->led].led->offfunc( led_arr[pState->led].led->param);
578 + return 0;
579 +}
580 +
581 +static void board_led_link_up( state_entry_t *pState )
582 +{
583 + led_arr[pState->led].state = LED_ON;
584 + if( led_arr[pState->led].timer_running == 0 )
585 + led_on(pState);
586 + return;
587 +}
588 +
589 +static void board_led_link_down( state_entry_t *pState )
590 +{
591 + led_arr[pState->led].state = LED_OFF;
592 + if( led_arr[pState->led].timer_running == 0 )
593 + led_off(pState);
594 + return;
595 +}
596 +
597 +static void add_led_timer(state_entry_t *pState)
598 +{
599 + led_arr[pState->led].pTimer->expires = jiffies + HZ*(pState->param)/1000;
600 + led_arr[pState->led].param = pState->param;
601 + led_arr[pState->led].pTimer->data = pState;
602 + add_timer (led_arr[pState->led].pTimer);
603 +}
604 +
605 +static void board_led_activity_on(state_entry_t *pState)
606 +{
607 + if(led_arr[pState->led].timer_running == 0)
608 + {
609 + led_on(pState);
610 + add_led_timer(pState);
611 + led_arr[pState->led].timer_running = 1;
612 + led_arr[pState->led].state = LED_BLINK_UP;
613 + }
614 + else if( led_arr[pState->led].timer_running > 0xF0)
615 + {
616 + led_arr[pState->led].state = LED_BLINK_UP;
617 + led_arr[pState->led].pTimer->expires = jiffies + HZ*(pState->param)/1000;
618 + led_arr[pState->led].param = pState->param;
619 + led_arr[pState->led].pTimer->data = pState;
620 + }
621 + return;
622 +}
623 +
624 +static void board_led_activity_off(state_entry_t *pState)
625 +{
626 + if(led_arr[pState->led].timer_running == 0)
627 + {
628 + led_off(pState);
629 + add_led_timer(pState);
630 + led_arr[pState->led].timer_running = 1;
631 + led_arr[pState->led].state = LED_BLINK_UP;
632 + }
633 + else if( led_arr[pState->led].timer_running > 0xF0)
634 + {
635 + led_arr[pState->led].state = LED_BLINK_UP;
636 + led_arr[pState->led].pTimer->expires = jiffies + HZ*(pState->param)/1000;
637 + led_arr[pState->led].param = pState->param;
638 + led_arr[pState->led].pTimer->data = pState;
639 + }
640 + return;
641 +}
642 +
643 +static void board_led_link_flash(state_entry_t *pState)
644 +{
645 + if(led_on(pState))
646 + return;
647 + if(led_arr[pState->led].timer_running == 0)
648 + add_led_timer(pState);
649 + else
650 + led_arr[pState->led].param = pState->param;
651 + led_arr[pState->led].timer_running = 0xFF;
652 + led_arr[pState->led].state = LED_FLASH;
653 + return;
654 +}
655 +
656 +static void led_timer_func(unsigned long data)
657 +{
658 + state_entry_t *pState = NULL;
659 + mod_entry_t *pMod = NULL;
660 + unsigned int flags;
661 +
662 + spin_lock_irqsave(&config_lock, flags);
663 +
664 + pState = (state_entry_t *)data;
665 +
666 + if( led_arr[pState->led].state == LED_BLINK_DOWN )
667 + {
668 + led_arr[pState->led].timer_running = 0;
669 + if( pState->mode == 2 )
670 + led_arr[pState->led].state = LED_OFF;
671 + else
672 + led_arr[pState->led].state = LED_ON;
673 + }
674 + else if( led_arr[pState->led].state == LED_BLINK_UP )
675 + {
676 + led_arr[pState->led].pTimer->expires = jiffies + HZ*(led_arr[pState->led].param)/1000;
677 + led_arr[pState->led].pTimer->data = pState;
678 + add_timer (led_arr[pState->led].pTimer);
679 + if( pState->mode == 2 )
680 + {
681 + led_off(pState);
682 + led_arr[pState->led].state = LED_BLINK_DOWN;
683 + }
684 + else
685 + {
686 + led_on(pState);
687 + led_arr[pState->led].state = LED_BLINK_DOWN;
688 + }
689 + led_arr[pState->led].timer_running = 1;
690 + }
691 + else if( led_arr[pState->led].state == LED_FLASH )
692 + {
693 + led_arr[pState->led].pTimer->expires = jiffies + HZ*(led_arr[pState->led].param)/1000;
694 + led_arr[pState->led].pTimer->data = pState;
695 + add_timer (led_arr[pState->led].pTimer);
696 +
697 + if( led_arr[pState->led].timer_running == 0xFF )
698 + {
699 + led_off(pState);
700 + led_arr[pState->led].timer_running--;
701 + }
702 + else
703 + {
704 + led_on(pState);
705 + led_arr[pState->led].timer_running++;
706 + }
707 + spin_unlock_irqrestore(&config_lock, flags);
708 + return;
709 + }
710 + else if(led_arr[pState->led].state == LED_OFF)
711 + {
712 + led_off(pState);
713 + led_arr[pState->led].timer_running = 0;
714 + }
715 + else if( led_arr[pState->led].state == LED_ON )
716 + {
717 + led_on(pState);
718 + led_arr[pState->led].timer_running = 0;
719 + }
720 + spin_unlock_irqrestore(&config_lock, flags);
721 + return;
722 +}
723 +/************wwzh*****************/
724 +#if 0
725 +/************end *****************/
726 +static ssize_t proc_read_led_fops(struct file *filp,
727 + char *buf,size_t count , loff_t *offp)
728 +{
729 + char * pdata = NULL;
730 + int i = 0, j = 0, len = 0, totallen = 0;
731 + char line[255];
732 +
733 + if( *offp != 0 )
734 + return 0;
735 +
736 + pdata = buf;
737 + len += sprintf(line,"LEDS Registered for use are:");
738 + for( i = 0; i< MAX_LED_ID; i++)
739 + if( led_arr[i].led != NULL )
740 + len += sprintf(&line[len]," %d ", i );
741 + line[len++] = '\n';
742 +
743 + copy_to_user(pdata, line,len );
744 + pdata += len;
745 + totallen += len;
746 + len = 0;
747 + len = sprintf(line,"USER MODULE INFORMATION:\n");
748 + copy_to_user(pdata, line,len );
749 + pdata += len;
750 + totallen += len;
751 + len = 0;
752 + for( i = 0; i< MAX_MOD_ID; i++)
753 + {
754 + if( modArr[i] != NULL )
755 + {
756 + len = sprintf(line," Module ID = %d \n" , i);
757 + copy_to_user(pdata, line,len );
758 + pdata += len;
759 + totallen += len;
760 + len = 0;
761 + for( j = 0; j < MAX_STATE_ID; j++)
762 + {
763 + if( modArr[i]->states[j] != NULL)
764 + {
765 + len = sprintf(line ,
766 + " State = %d , Led = %d," , j , modArr[i]->states[j]->led);
767 + copy_to_user(pdata, line,len );
768 + pdata += len;
769 + totallen += len;
770 +
771 + len = 0;
772 + switch( modArr[i]->states[j]->mode )
773 + {
774 + case 1:
775 + len = sprintf(line ," Mode = OFF\n");
776 + break;
777 + case 2:
778 + len = sprintf(line ," Mode = BLINK_ON , On Time(ms) = %d\n" ,
779 + (unsigned int)modArr[i]->states[j]->param);
780 + break;
781 + case 3:
782 + len = sprintf(line ," Mode = BLINK_OFF , Off Time(ms) = %d\n" ,
783 + (unsigned int)modArr[i]->states[j]->param);
784 + break;
785 + case 4:
786 + len = sprintf(line ," Mode = ON \n");
787 + break;
788 + case 5:
789 + len = sprintf(line ," Mode = FLASH , Time Period(ms) = %d\n" ,
790 + (unsigned int)modArr[i]->states[j]->param);
791 + break;
792 + default:
793 + break;
794 +
795 + }
796 + copy_to_user(pdata, line,len );
797 + pdata += len;
798 + totallen += len;
799 +
800 + len = 0;
801 + }
802 + }
803 + }
804 + }
805 + /* Return with configuration information for LEDs */
806 + *offp = totallen;
807 + return totallen;
808 +}
809 +static ssize_t proc_write_led_fops(struct file *filp,const char *buffer,
810 + size_t count , loff_t *offp)
811 +{
812 + char *pdata = NULL, *ptemp = NULL;
813 + char line[10],temp[10];
814 + int i = 0;
815 + int mod = 0xFFFF , state = 0xFFFF;
816 + int flag = 0;
817 +
818 + /* Check if this write is for configuring stuff */
819 + if( *(int *)(buffer) == 0xFFEEDDCC )
820 + {
821 + printk("<1>proc write:Calling Configuration\n");
822 + config_led((unsigned long)(buffer + sizeof(int)) );
823 + return count;
824 + }
825 +
826 + if( count >= 10)
827 + {
828 + printk("<1>proc write:Input too long,max length = %d\n",10);
829 + return count;
830 + }
831 + memset( temp, 0x00 , 10);
832 + memset( line, 0x00 , 10);
833 + copy_from_user(line,buffer,count);
834 + line[count] = 0x00;
835 + pdata = line;
836 + ptemp = temp;
837 + while( flag == 0)
838 + {
839 + if( i > 10 )
840 + break;
841 + if( ((*pdata) >= '0' ) && ((*pdata) <= '9') )
842 + {
843 + *ptemp = *pdata ;
844 + ptemp++;
845 + }
846 + else if( (*pdata) == ',' )
847 + {
848 + *ptemp = 0x00;
849 + flag = 1;
850 + }
851 + pdata++;
852 + i++;
853 + };
854 + if( flag == 1)
855 + mod = led_atoi( temp);
856 + else
857 + return count;
858 +
859 + ptemp = temp;
860 + *ptemp = 0x00;
861 + flag = 0;
862 + while( flag == 0)
863 + {
864 + if( i > 10 )
865 + break;
866 + if( ((*pdata) >= '0' ) && ((*pdata) <= '9') )
867 + {
868 + *ptemp = *pdata ;
869 + ptemp++;
870 + }
871 + else if( (*pdata) == 0x00 )
872 + {
873 + *ptemp = 0x00;
874 + flag = 1;
875 + }
876 + pdata++;
877 + i++;
878 + };
879 + if( flag == 1)
880 + state = led_atoi( temp);
881 + else
882 + return count;
883 + if( (mod == 0xFFFF) || (state == 0xFFFF))
884 + return count;
885 + else
886 + led_operation( mod , state );
887 + return count;
888 +}
889 +
890 +/************wwzh*******************/
891 +#else
892 +
893 +#define TRUE 1
894 +#define FALSE 0
895 +#define FLICK_TIME (HZ*100/1000)
896 +static unsigned int wan_txrx_state = 0;
897 +static unsigned int wlan_txrx_state = 0;
898 +
899 +void led_operation( int mod , int state)
900 +{
901 +
902 + unsigned int flags;
903 +
904 + spin_lock_irqsave(&config_lock, flags);
905 +
906 + if( (mod >= MAX_MOD_ID) || ( state >= MAX_STATE_ID) )
907 + {
908 + spin_unlock_irqrestore(&config_lock, flags);
909 + return;
910 + }
911 + if ( modArr[mod] == NULL )
912 + {
913 + spin_unlock_irqrestore(&config_lock, flags);
914 + return;
915 + }
916 + if( modArr[mod]->states[state] == NULL )
917 + {
918 + spin_unlock_irqrestore(&config_lock, flags);
919 + return;
920 + }
921 + /* Call the function handler */
922 + modArr[mod]->states[state]->handler(modArr[mod]->states[state]);
923 +
924 + spin_unlock_irqrestore(&config_lock, flags);
925 +}
926 +
927 +static void wan_led_func(unsigned long data)
928 +{
929 + if (wan_txrx_state == 0)
930 + {
931 + tnetd73xx_gpio_out(2, TRUE);
932 + tnetd73xx_gpio_out(3, FALSE);
933 + wan_txrx_state = 1;
934 + }
935 + else
936 + {
937 + tnetd73xx_gpio_out(2, FALSE);
938 + tnetd73xx_gpio_out(3, FALSE);
939 + wan_txrx_state = 0;
940 + }
941 + pWanTimer->expires = jiffies + FLICK_TIME;
942 + add_timer(pWanTimer);
943 +}
944 +//wwzh for wireless
945 +#if 0
946 +static void wlan_led_func(unsigned long data)
947 +{
948 + if (wlan_txrx_state == 0)
949 + {
950 + tnetd73xx_gpio_out(12, TRUE);
951 + tnetd73xx_gpio_out(13, FALSE);
952 + wlan_txrx_state = 1;
953 + }
954 + else
955 + {
956 + tnetd73xx_gpio_out(12, FALSE);
957 + tnetd73xx_gpio_out(13, FALSE);
958 + wlan_txrx_state = 0;
959 +
960 + }
961 + pWlanTimer->expires = jiffies + FLICK_TIME;
962 + add_timer(pWlanTimer);
963 +}
964 +#endif
965 +
966 +void led_active(int mod, int state)
967 +{
968 + unsigned int flags = 0;
969 +
970 +//printk("mod = %d state = %d\n", mod, state);
971 + spin_lock_irqsave(&config_lock, flags);
972 + if ((mod >= 5) || (state >= 5))
973 + {
974 + spin_unlock_irqrestore(&config_lock, flags);
975 + return;
976 + }
977 +
978 + switch (mod)
979 + {
980 + case 2: /*system led */
981 + sys_mod_state = state;
982 + switch (state)
983 + {
984 + case 1:
985 + break;
986 + case 2: /*sys led flashing green */
987 + tnetd73xx_gpio_out(4, FALSE);
988 + tnetd73xx_gpio_out(5, TRUE);
989 + tnetd73xx_gpio_out(8, TRUE);
990 + break;
991 + case 3: /*sys led solid green */
992 + tnetd73xx_gpio_out(4, TRUE);
993 + tnetd73xx_gpio_out(5, TRUE);
994 + tnetd73xx_gpio_out(8, TRUE);
995 +
996 + break;
997 + case 4: /*sys fail red */
998 + tnetd73xx_gpio_out(4, TRUE);
999 + tnetd73xx_gpio_out(5, FALSE);
1000 + tnetd73xx_gpio_out(8, FALSE);
1001 + break;
1002 + default:
1003 + break;
1004 + }
1005 + break;
1006 + case 3: /*wan led */
1007 + wan_mod_state = state;
1008 + switch (state)
1009 + {
1010 + case 1: /*no wan interface*/
1011 + if (pWanTimer)
1012 + {
1013 + del_timer(pWanTimer);
1014 + kfree(pWanTimer);
1015 + pWanTimer = NULL;
1016 + }
1017 + tnetd73xx_gpio_out(2, FALSE);
1018 + tnetd73xx_gpio_out(3, FALSE);
1019 + break;
1020 + case 2: /*wan connected */
1021 + if (pWanTimer)
1022 + {
1023 + del_timer(pWanTimer);
1024 + kfree(pWanTimer);
1025 + pWanTimer = NULL;
1026 + }
1027 + tnetd73xx_gpio_out(2, TRUE);
1028 + tnetd73xx_gpio_out(3, FALSE);
1029 + break;
1030 + case 3: /*rx/tx activity */
1031 + if (pWanTimer != NULL)
1032 + break;
1033 +
1034 + pWanTimer = kmalloc(sizeof(struct timer_list), GFP_KERNEL);
1035 + init_timer(pWanTimer);
1036 +
1037 + pWanTimer->function = wan_led_func;
1038 + pWanTimer->data = 0;
1039 + pWanTimer->expires = jiffies + FLICK_TIME;
1040 + tnetd73xx_gpio_out(2, FALSE);
1041 + tnetd73xx_gpio_out(3, FALSE);
1042 + wan_txrx_state = 0;
1043 + add_timer(pWanTimer);
1044 +
1045 + break;
1046 + case 4: /*no ipaddress */
1047 + if (pWanTimer)
1048 + {
1049 + del_timer(pWanTimer);
1050 + kfree(pWanTimer);
1051 + pWanTimer = NULL;
1052 + }
1053 + tnetd73xx_gpio_out(2, FALSE);
1054 + tnetd73xx_gpio_out(3, TRUE);
1055 + break;
1056 + default:
1057 + if (pWanTimer)
1058 + {
1059 + del_timer(pWanTimer);
1060 + kfree(pWanTimer);
1061 + pWanTimer = NULL;
1062 + }
1063 + break;
1064 + }
1065 + break;
1066 + //wwzh for wireless
1067 + #if 0
1068 + case 4: /*wlan led */
1069 + wlan_mod_state = state;
1070 + switch (state)
1071 + {
1072 + case 1: /* wlan off */
1073 + if (pWlanTimer)
1074 + {
1075 + del_timer(pWlanTimer);
1076 + kfree(pWlanTimer);
1077 + pWlanTimer = NULL;
1078 + }
1079 + tnetd73xx_gpio_out(12, FALSE);
1080 + tnetd73xx_gpio_out(13, FALSE);
1081 + break;
1082 + case 2: /* wlan ready */
1083 + if (pWlanTimer)
1084 + {
1085 + del_timer(pWlanTimer);
1086 + kfree(pWlanTimer);
1087 + pWlanTimer = NULL;
1088 + }
1089 + tnetd73xx_gpio_out(12, TRUE);
1090 + tnetd73xx_gpio_out(13, FALSE);
1091 + break;
1092 + case 3: /* wlan rx/tx activity */
1093 + if (pWlanTimer != NULL)
1094 + break;
1095 +
1096 + pWlanTimer = kmalloc(sizeof(struct timer_list), GFP_KERNEL);
1097 + init_timer(pWlanTimer);
1098 +
1099 + pWlanTimer->function = wlan_led_func;
1100 + pWlanTimer->data = 0;
1101 + pWlanTimer->expires = jiffies + FLICK_TIME;
1102 + tnetd73xx_gpio_out(12, FALSE);
1103 + tnetd73xx_gpio_out(13, FALSE);
1104 + wlan_txrx_state = 0;
1105 + add_timer(pWlanTimer);
1106 +
1107 + break;
1108 + default:
1109 + if (pWlanTimer)
1110 + {
1111 + del_timer(pWlanTimer);
1112 + kfree(pWlanTimer);
1113 + pWlanTimer = NULL;
1114 + }
1115 +
1116 + break;
1117 + }
1118 + break;
1119 + #endif //for wireless
1120 + default:
1121 + break;
1122 + }
1123 + spin_unlock_irqrestore(&config_lock, flags);
1124 +}
1125 +static ssize_t proc_read_led_fops(struct file *filp,
1126 + char *buf,size_t count , loff_t *offp)
1127 +{
1128 + char *pdata = NULL;
1129 + int i = 0, j = 0, len = 0, totallen = 0;
1130 + char line[255];
1131 +
1132 + if (*offp != 0)
1133 + return 0;
1134 + pdata = buf;
1135 + len = sprintf(line, "USER MODULE INFORMATION:\n");
1136 + copy_to_user(pdata, line, len);
1137 + pdata += len;
1138 + totallen += len;
1139 + len = 0;
1140 +
1141 + //*******add Module 1 , this Module is ADSL ********/
1142 + for (i = 0; i < MAX_MOD_ID; i++)
1143 + {
1144 + if (modArr[i] != NULL)
1145 + {
1146 + len = sprintf(line, " Module ID = %d\n", i);
1147 + copy_to_user(pdata, line, len);
1148 + pdata += len;
1149 + totallen += len;
1150 + len = 0;
1151 + for(j = 0; j < MAX_STATE_ID; j++)
1152 + {
1153 + if (modArr[i]->states[j] != NULL)
1154 + {
1155 + len = sprintf(line, "State =%d, Led = %d,", j, modArr[i]->states[j]->led);
1156 + copy_to_user(pdata, line, len);
1157 + pdata += len;
1158 + totallen += len;
1159 + len = 0;
1160 + switch(modArr[i]->states[j]->mode)
1161 + {
1162 + case 1:
1163 + len = sprintf(line, "Mode = OFF\n");
1164 + break;
1165 + case 2:
1166 + len = sprintf(line, "Mode = BLINK_ON, On Time(ms) = %d\n", (unsigned int)modArr[i]->states[j]->param);
1167 + break;
1168 + case 3:
1169 + len = sprintf(line, "Mode = BLINK_OFF, Off Time(ms) = %d\n", (unsigned int)modArr[i]->states[j]->param);
1170 + break;
1171 + case 4:
1172 + len = sprintf(line, "Mode = On\n");
1173 + break;
1174 + case 5:
1175 + len = sprintf(line, "Mode = FLASH, Time Period(ms) = %d\n", (unsigned int)modArr[i]->states[j]->param);
1176 + break;
1177 + default:
1178 + break;
1179 + }
1180 + copy_to_user(pdata, line, len);
1181 + pdata += len;
1182 + totallen += len;
1183 + len = 0;
1184 + }
1185 + }
1186 + }
1187 +
1188 + }
1189 +
1190 + len = sprintf(line, "Module ID = 2(system led)\n");
1191 + copy_to_user(pdata, line, len);
1192 + pdata += len;
1193 + totallen += len;
1194 + len = 0;
1195 + switch(sys_mod_state)
1196 + {
1197 + case 1:
1198 + len = sprintf(line, "State = OFF\n");
1199 + break;
1200 + case 2:
1201 + len = sprintf(line, "State = Booting\n");
1202 + break;
1203 + case 3:
1204 + len = sprintf(line, "State = System Ready\n");
1205 + break;
1206 + case 4:
1207 + len = sprintf(line, "State = System Failure\n");
1208 + break;
1209 + default:
1210 + break;
1211 + }
1212 + copy_to_user(pdata, line, len);
1213 + pdata += len;
1214 + totallen += len;
1215 + len = 0;
1216 +
1217 + len = sprintf(line, "Module ID = 3(WAN led)\n");
1218 + copy_to_user(pdata, line, len);
1219 + pdata += len;
1220 + totallen += len;
1221 + len = 0;
1222 + switch(wan_mod_state)
1223 + {
1224 + case 1:
1225 + len = sprintf(line, "State = OFF\n");
1226 + break;
1227 + case 2:
1228 + len = sprintf(line, "State = Wan Connected\n");
1229 + break;
1230 + case 3:
1231 + len = sprintf(line, "State = Wan Tx/Rx Activity\n");
1232 + break;
1233 + case 4:
1234 + len = sprintf(line, "State = Wan Connect Failure\n");
1235 + break;
1236 + default:
1237 + break;
1238 + }
1239 + copy_to_user(pdata, line, len);
1240 + pdata += len;
1241 + totallen += len;
1242 + len = 0;
1243 +
1244 +//wwzh for wireless
1245 +#if 0
1246 + len = sprintf(line, "Module ID = 4(WLAN led)\n");
1247 + copy_to_user(pdata, line, len);
1248 + pdata += len;
1249 + totallen += len;
1250 + len = 0;
1251 + switch(wlan_mod_state)
1252 + {
1253 + case 1:
1254 + len = sprintf(line, "State = OFF\n");
1255 + break;
1256 + case 2:
1257 + len = sprintf(line, "State = wlan Ready\n");
1258 + break;
1259 + case 3:
1260 + len = sprintf(line, "State = wlan rx/tx activity\n");
1261 + break;
1262 + default:
1263 + break;
1264 + }
1265 + copy_to_user(pdata, line, len);
1266 + pdata += len;
1267 + totallen += len;
1268 + len = 0;
1269 +#endif //for wireless
1270 +
1271 + *offp = totallen;
1272 + return totallen;
1273 +}
1274 +static ssize_t proc_write_led_fops(struct file *filp,const char *buffer,
1275 + size_t count , loff_t *offp)
1276 +{
1277 + char *pdata = NULL, *ptemp = NULL;
1278 + char line[10], temp[10];
1279 + int i = 0;
1280 + int mod = 0xffff, state = 0xffff;
1281 + int flag = 0;
1282 +
1283 + /* Check if this write is for configuring ADSL */
1284 + if( *(int *)(buffer) == 0xFFEEDDCC )
1285 + {
1286 + printk("<1>proc write:Calling Configuration\n");
1287 + config_led((unsigned long)(buffer + sizeof(int)) );
1288 + return count;
1289 + }
1290 +
1291 + if (count > 10)
1292 + {
1293 + printk("<1> proc write: Input too long, max length = 10\n");
1294 + return count;
1295 + }
1296 + memset(temp, 0x00, 10);
1297 + memset(line, 0x00, 10);
1298 + copy_from_user(line, buffer, count);
1299 + line[count] = 0x00;
1300 + pdata = line;
1301 + ptemp = temp;
1302 +
1303 + while (flag == 0)
1304 + {
1305 + if (i > 10)
1306 + break;
1307 + if (((*pdata) >= '0') && ((*pdata) <= '9'))
1308 + {
1309 + *ptemp = *pdata;
1310 + ptemp++;
1311 + }
1312 + else if ((*pdata) == ',')
1313 + {
1314 + *ptemp = 0x00;
1315 + flag = 1;
1316 + }
1317 + pdata++;
1318 + i++;
1319 + }
1320 + if (flag == 1)
1321 + mod = led_atoi(temp);
1322 + else
1323 + return count;
1324 +
1325 + ptemp = temp;
1326 + *ptemp = 0x00;
1327 + flag = 0;
1328 +
1329 + while(flag == 0)
1330 + {
1331 + if (i > 10)
1332 + break;
1333 + if (((*pdata) >= '0') && ((*pdata) <= '9'))
1334 + {
1335 + *ptemp = *pdata;
1336 + ptemp++;
1337 + }
1338 + else if ((*pdata) == 0x00)
1339 + {
1340 + *ptemp = 0x00;
1341 + flag = 1;
1342 + }
1343 + pdata++;
1344 + i++;
1345 + }
1346 + if (flag == 1)
1347 + state = led_atoi(temp);
1348 + else
1349 + return count;
1350 + if ((mod == 0xFFFF) || (state == 0xFFFF))
1351 + return count;
1352 + else
1353 + {
1354 + if (mod != 4)
1355 + led_active(mod, state);
1356 + else
1357 + led_operation(mod, state);
1358 + }
1359 + return 1;
1360 +}
1361 +#endif
1362 +/************end *******************/
1363 +static int config_led(unsigned long y)
1364 +{
1365 + config_elem_t *pcfg = NULL;
1366 + char *pdata = NULL;
1367 + int i;
1368 + int length = 0 , number = 0;
1369 + unsigned int flags;
1370 +
1371 + spin_lock_irqsave(&config_lock, flags);
1372 +
1373 + /* ioctl to configure */
1374 + length = *((int*)y);
1375 + pdata = (char *)y + sizeof(int);
1376 + number = (length - sizeof(int))/sizeof(config_elem_t);
1377 + pcfg = (config_elem_t *)(pdata);
1378 +
1379 + /* Check if an earlier configuration exists IF yes free it up */
1380 + free_memory();
1381 +
1382 + for ( i = 0 ; i < number ; i++ )
1383 + {
1384 + /* If no structure has been allocated for the module do so */
1385 + if ( modArr[pcfg->name] == NULL )
1386 + {
1387 + printk("<1>module = %d\n",pcfg->name);
1388 + if( pcfg->name >= MAX_MOD_ID)
1389 + {
1390 + printk("<1>Exiting Configuration: Module ID too large %d\n",pcfg->name);
1391 + free_memory();
1392 + spin_unlock_irqrestore(&config_lock, flags);
1393 + return -1;
1394 + }
1395 + modArr[pcfg->name] = kmalloc(sizeof(mod_entry_t),GFP_KERNEL);
1396 + if(modArr[pcfg->name] == NULL)
1397 + {
1398 + printk("<1>Exiting Configuration: Error in allocating memory\n");
1399 + free_memory();
1400 + spin_unlock_irqrestore(&config_lock, flags);
1401 + return -1;
1402 + }
1403 + memset( modArr[pcfg->name], 0x00, sizeof(mod_entry_t));
1404 + }
1405 +
1406 + /* if no structure is allocated previously for this state
1407 + allocate a structure, if it's already there fill it up */
1408 + if( modArr[pcfg->name]->states[pcfg->state] == NULL)
1409 + {
1410 + printk("<1>STATE = %d\n",pcfg->state);
1411 + if( pcfg->state >= MAX_STATE_ID)
1412 + {
1413 + printk("<1>Exiting Configuration: State ID too large\n");
1414 + free_memory();
1415 + spin_unlock_irqrestore(&config_lock, flags);
1416 + return -1;
1417 + }
1418 + modArr[pcfg->name]->states[pcfg->state] =
1419 + kmalloc(sizeof(state_entry_t),GFP_KERNEL);
1420 + if( modArr[pcfg->name]->states[pcfg->state] == NULL)
1421 + {
1422 + free_memory();
1423 + spin_unlock_irqrestore(&config_lock, flags);
1424 + return -1;
1425 + }
1426 + memset( modArr[pcfg->name]->states[pcfg->state], 0x00, sizeof(state_entry_t));
1427 + }
1428 + /* Fill up the fields of the state */
1429 + if( pcfg->led >= MAX_LED_ID)
1430 + {
1431 + printk("<1>led = %d\n",pcfg->led);
1432 + free_memory();
1433 + spin_unlock_irqrestore(&config_lock, flags);
1434 + return -1;
1435 + }
1436 + modArr[pcfg->name]->states[pcfg->state]->led = pcfg->led;
1437 + modArr[pcfg->name]->states[pcfg->state]->mode = pcfg->mode;
1438 + modArr[pcfg->name]->states[pcfg->state]->param = pcfg->param;
1439 + switch(pcfg->mode)
1440 + {
1441 + case 1:
1442 + modArr[pcfg->name]->states[pcfg->state]->handler = board_led_link_down;
1443 + break;
1444 + case 2:
1445 + case 3:
1446 + case 5:
1447 + if( pcfg->mode == 2 )
1448 + modArr[pcfg->name]->states[pcfg->state]->handler = board_led_activity_on;
1449 + else if( pcfg->mode == 3)
1450 + modArr[pcfg->name]->states[pcfg->state]->handler = board_led_activity_off;
1451 + else
1452 + modArr[pcfg->name]->states[pcfg->state]->handler = board_led_link_flash;
1453 + break;
1454 + case 4:
1455 + modArr[pcfg->name]->states[pcfg->state]->handler = board_led_link_up;
1456 + break;
1457 + default:
1458 + printk("<1>Exiting Configuration: Unknown LED Mode\n");
1459 + free_memory();
1460 + spin_unlock_irqrestore(&config_lock, flags);
1461 + return -1;
1462 + }
1463 + pcfg++;
1464 + }
1465 + spin_unlock_irqrestore(&config_lock, flags);
1466 + return 0;
1467 +}
1468 +
1469 +
1470 +int __init led_init(void)
1471 +{
1472 +
1473 + /* Clear our memory */
1474 + memset(modArr,0x00,sizeof(mod_entry_t *)*MAX_MOD_ID);
1475 + memset(led_arr,0x00,sizeof(led_data_t *)*MAX_LED_ID);
1476 +
1477 + /* Create spin lock for config data structure */
1478 + config_lock=SPIN_LOCK_UNLOCKED;
1479 +
1480 + /* Create directory */
1481 + led_proc_dir = proc_mkdir("led", NULL);
1482 + if( led_proc_dir == NULL )
1483 + goto out;
1484 +
1485 + /* Create adsl file */
1486 + led_file = create_proc_entry("led", 0777, led_proc_dir);
1487 + if( led_file == NULL)
1488 + goto led_file;
1489 + led_file->owner = THIS_MODULE;
1490 + led_file->proc_fops = &led_fops;
1491 +
1492 + memset( modArr , 0x00 , sizeof(mod_entry_t *) * MAX_MOD_ID);
1493 + /* Reset the GPIO pins */
1494 + board_gpio_init();
1495 +
1496 + /* Register the UART controlled LEDS */
1497 + uart_led_init();
1498 + /* Create the usb proc file */
1499 + avalanche_leds_init();
1500 + return 0;
1501 +
1502 + led_file:
1503 + remove_proc_entry("led",led_proc_dir);
1504 + out:
1505 + return 0;
1506 +
1507 +}
1508 +
1509 +void led_exit()
1510 +{
1511 + remove_proc_entry("led", led_proc_dir);
1512 +}
1513 +
1514 +module_init(led_init);
1515 +module_exit(led_exit);
1516 +
1517 +void register_led_drv( int device , led_reg_t *pInfo)
1518 +{
1519 + unsigned int flags;
1520 + struct timer_list *pTimer = NULL;
1521 +
1522 + spin_lock_irqsave(&config_lock, flags);
1523 +
1524 + led_arr[device].led = pInfo;
1525 + if( led_arr[device].led->init != 0x00)
1526 + led_arr[device].led->init(led_arr[device].led->param);
1527 + if( led_arr[device].led->offfunc != 0x00)
1528 + led_arr[device].led->offfunc(led_arr[device].led->param);
1529 +
1530 + /* Create a timer for blinking */
1531 + pTimer = kmalloc(sizeof(struct timer_list),GFP_KERNEL);
1532 + init_timer( pTimer );
1533 + pTimer->function = led_timer_func;
1534 + pTimer->data = 0;
1535 + led_arr[device].pTimer = pTimer;
1536 + led_arr[device].timer_running = 0;
1537 +
1538 + spin_unlock_irqrestore(&config_lock, flags);
1539 +
1540 + return;
1541 +}
1542 +
1543 +void deregister_led_drv( int device)
1544 +{
1545 + unsigned int flags;
1546 +
1547 + spin_lock_irqsave(&config_lock, flags);
1548 + led_arr[device].led = NULL;
1549 +
1550 + if( led_arr[device].pTimer != NULL)
1551 + {
1552 + del_timer(led_arr[device].pTimer);
1553 + kfree(led_arr[device].pTimer);
1554 + }
1555 + spin_unlock_irqrestore(&config_lock, flags);
1556 +
1557 + return;
1558 +}
1559 +
1560 +EXPORT_SYMBOL_NOVERS(led_operation);
1561 +EXPORT_SYMBOL_NOVERS(register_led_drv);
1562 +EXPORT_SYMBOL_NOVERS(deregister_led_drv);
1563 +
1564 diff -urN linux.dev/drivers/char/avalanche_led/leds.c linux.dev2/drivers/char/avalanche_led/leds.c
1565 --- linux.dev/drivers/char/avalanche_led/leds.c 1970-01-01 01:00:00.000000000 +0100
1566 +++ linux.dev2/drivers/char/avalanche_led/leds.c 2005-10-21 18:03:44.513777000 +0200
1567 @@ -0,0 +1,133 @@
1568 +#include <linux/config.h>
1569 +#include <linux/init.h>
1570 +#include <linux/delay.h>
1571 +#include <asm/ar7/avalanche_regs.h>
1572 +#include <linux/spinlock.h>
1573 +#include <linux/timer.h>
1574 +#include <linux/sched.h>
1575 +#include <linux/module.h>
1576 +#include <linux/proc_fs.h>
1577 +#include <asm/uaccess.h>
1578 +#include <linux/fs.h>
1579 +
1580 +#include <asm/ar7/ledapp.h>
1581 +
1582 +#if defined(CONFIG_AR5D01) || defined(CONFIG_AR5W01) || defined(CONFIG_AR7)
1583 +
1584 +#define ETH_MASK 0x01
1585 +#define USB_MASK 0x02
1586 +
1587 +static struct proc_dir_entry *usb_file;
1588 +static ssize_t proc_read_usb_fops(struct file *filp,
1589 + char *buf,size_t count , loff_t *offp);
1590 +struct file_operations usb_fops = {read: proc_read_usb_fops};
1591 +
1592 +typedef struct mod_states{
1593 + int module;
1594 + int activity;
1595 + int linkup;
1596 + int idle;
1597 +}mod_states_t;
1598 +
1599 +mod_states_t state_arr[] = {
1600 + { MOD_ETH,DEF_ETH_ACTIVITY,DEF_ETH_LINK_UP,DEF_ETH_IDLE },
1601 + { MOD_USB,DEF_USB_ACTIVITY,DEF_USB_LINK_UP,DEF_USB_IDLE },
1602 + { MOD_LAN,DEF_LAN_ACTIVITY,DEF_LAN_LINK_UP,DEF_LAN_IDLE }
1603 + };
1604 +
1605 +unsigned char device_links = 0; /* Bitmask with the devices that are up */
1606 +
1607 +
1608 +void avalanche_led_activity_pulse(unsigned long device)
1609 +{
1610 + /* If device link is not up return */
1611 + if( !(device_links & (unsigned char)(1 << device)))
1612 + return;
1613 +#ifdef MULTIPLEX_LED
1614 + led_operation( state_arr[2].module, state_arr[2].activity);
1615 +#else
1616 + led_operation( state_arr[device].module, state_arr[device].activity);
1617 +#endif
1618 +}
1619 +
1620 +void avalanche_led_link_up( unsigned long device )
1621 +{
1622 +
1623 + /* If already UP ignore */
1624 + if( device_links & (unsigned char)(1 << device))
1625 + return;
1626 + /* Turn on the bit for the device */
1627 + device_links |= (unsigned char)(1 << device);
1628 +#ifdef MULTIPLEX_LED
1629 + led_operation( state_arr[2].module, state_arr[2].linkup);
1630 +#else
1631 + led_operation( state_arr[device].module, state_arr[device].linkup);
1632 +#endif
1633 +}
1634 +
1635 +void avalanche_led_link_down ( unsigned long device )
1636 +{
1637 +
1638 + /* If already DOWN ignore */
1639 + if( !(device_links & (unsigned char)(1 << device)))
1640 + return;
1641 +
1642 + /* Turn off the bit for the device */
1643 + device_links &= ~(unsigned char)(1 << device);
1644 +#ifdef MULTIPLEX_LED
1645 + /* If no links, then shut the LED off */
1646 + if(!device_links)
1647 + led_operation( state_arr[2].module, state_arr[2].idle);
1648 +#else
1649 + led_operation( state_arr[device].module, state_arr[device].idle);
1650 +#endif
1651 +}
1652 +
1653 +static ssize_t proc_read_usb_fops(struct file *filp,
1654 + char *buf,size_t count , loff_t *offp)
1655 +{
1656 + char * pdata = NULL;
1657 + char line[3];
1658 + if( *offp != 0 )
1659 + return 0;
1660 + pdata = buf;
1661 + if( device_links & USB_MASK)
1662 + sprintf(line,"%s\n","1");
1663 + else
1664 + sprintf(line,"%s\n","0");
1665 + copy_to_user(pdata,line,2);
1666 + *offp = 2;
1667 + return 2;
1668 +}
1669 +
1670 +
1671 +void avalanche_leds_init(void)
1672 +{
1673 + /* Create usb link proc file */
1674 + usb_file = create_proc_entry("avalanche/usb_link", 0444, NULL);
1675 + if( usb_file == NULL)
1676 + return;
1677 + usb_file->owner = THIS_MODULE;
1678 + usb_file->proc_fops = &usb_fops;
1679 + return;
1680 +}
1681 +
1682 +EXPORT_SYMBOL(avalanche_led_activity_pulse);
1683 +EXPORT_SYMBOL(avalanche_led_link_up);
1684 +EXPORT_SYMBOL(avalanche_led_link_down);
1685 +
1686 +#else
1687 +/* We make a dummy init routine for the platforms that do not support this led
1688 + API
1689 +*/
1690 +
1691 +void avalanche_leds_init(void)
1692 +{
1693 +}
1694 +
1695 +#endif
1696 +
1697 +
1698 +
1699 +
1700 +
1701 diff -urN linux.dev/drivers/char/avalanche_led/uartled.c linux.dev2/drivers/char/avalanche_led/uartled.c
1702 --- linux.dev/drivers/char/avalanche_led/uartled.c 1970-01-01 01:00:00.000000000 +0100
1703 +++ linux.dev2/drivers/char/avalanche_led/uartled.c 2005-10-21 18:03:44.529778000 +0200
1704 @@ -0,0 +1,55 @@
1705 +#include <linux/kernel.h>
1706 +#include <asm/uaccess.h>
1707 +#include <linux/spinlock.h>
1708 +#include <asm/ar7/avalanche_regs.h>
1709 +#include <asm/ar7/ledapp.h>
1710 +
1711 +#define UART_LED_REG (*(volatile unsigned int *)(UARTA_BASE + 0x10))
1712 +
1713 +static spinlock_t device_lock;
1714 +led_reg_t temp1[2];
1715 +
1716 +static void uart_led_on(unsigned long param)
1717 +{
1718 + unsigned long flags;
1719 +
1720 + spin_lock_irqsave(&device_lock,flags);
1721 + UART_LED_REG &= 0xFFFD;
1722 + spin_unlock_irqrestore(&device_lock, flags);
1723 +}
1724 +
1725 +static void uart_led_off ( unsigned long param )
1726 +{
1727 + unsigned int flags = 0x00;
1728 + spin_lock_irqsave(&device_lock, flags);
1729 + UART_LED_REG |= 0x02;
1730 + spin_unlock_irqrestore(&device_lock, flags);
1731 +}
1732 +
1733 +void uart_led_init(void)
1734 +{
1735 +
1736 +#if defined(CONFIG_AR5D01)
1737 + /* Register led 6 UART Pin 1 */
1738 + temp1[0].param = 0;
1739 + temp1[0].init = NULL;
1740 + temp1[0].onfunc = uart_led_on;
1741 + temp1[0].offfunc = uart_led_off;
1742 + register_led_drv( 6 , &temp1[0]);
1743 +#endif
1744 +
1745 +#if defined(CONFIG_AR5W01)
1746 + /* Register led 8 UART Pin 1 */
1747 + temp1[0].param = 0;
1748 + temp1[0].init = NULL;
1749 + temp1[0].onfunc = uart_led_on;
1750 + temp1[0].offfunc = uart_led_off;
1751 + register_led_drv( 8 , &temp1[0]);
1752 +#endif
1753 +
1754 + /* Initialize the link mask */
1755 + device_lock = SPIN_LOCK_UNLOCKED;
1756 +
1757 + return;
1758 +}
1759 +
1760 diff -urN linux.dev/include/asm-mips/ar7/led_config.h linux.dev2/include/asm-mips/ar7/led_config.h
1761 --- linux.dev/include/asm-mips/ar7/led_config.h 1970-01-01 01:00:00.000000000 +0100
1762 +++ linux.dev2/include/asm-mips/ar7/led_config.h 2005-10-21 17:02:25.568327000 +0200
1763 @@ -0,0 +1,55 @@
1764 +/******************************************************************************
1765 + * FILE PURPOSE: - LED config Header
1766 + ******************************************************************************
1767 + * FILE NAME: led_config.h
1768 + *
1769 + * DESCRIPTION: Header file for LED configuration parameters
1770 + * and data structures
1771 + *
1772 + * REVISION HISTORY:
1773 + * 11 Oct 03 - PSP TII
1774 + *
1775 + * (C) Copyright 2002, Texas Instruments, Inc
1776 + *******************************************************************************/
1777 +
1778 +
1779 +#ifndef __LED_CONFIG__
1780 +#define __LED_CONFIG__
1781 +
1782 +/* LED config parameters */
1783 +#define MAX_GPIO_PIN_NUM 64
1784 +#define MAX_GPIOS_PER_STATE 5
1785 +#define MAX_MODULE_ENTRIES 25
1786 +#define MAX_MODULE_INSTANCES 4
1787 +#define MAX_STATE_ENTRIES 25
1788 +#define MAX_LED_ENTRIES 25
1789 +
1790 +
1791 +/* LED modes */
1792 +#define LED_OFF 0
1793 +#define LED_ON 1
1794 +#define LED_ONESHOT_OFF 2
1795 +#define LED_ONESHOT_ON 3
1796 +#define LED_FLASH 4
1797 +#define LED_BLINK_CODE0 5 /*--- param1: on time, param2: blink nr , (param2 > 100 blink off) ---*/
1798 +#define LED_BLINK_CODE1 6
1799 +#define LED_BLINK_CODE2 7
1800 +
1801 +#define NUM_LED_MODES 8
1802 +
1803 +
1804 +
1805 +/* Data structure for LED configuration */
1806 +typedef struct led_config{
1807 + unsigned char name[80];
1808 + unsigned int instance;
1809 + unsigned int state;
1810 + unsigned int gpio[MAX_GPIOS_PER_STATE];
1811 + unsigned int mode[MAX_GPIOS_PER_STATE];
1812 + unsigned int gpio_num;
1813 + unsigned int param1;
1814 + unsigned int param2;
1815 +}LED_CONFIG_T;
1816 +
1817 +
1818 +#endif /* __LED_CONFIG__ */
1819 diff -urN linux.dev/include/asm-mips/ar7/led_hal.h linux.dev2/include/asm-mips/ar7/led_hal.h
1820 --- linux.dev/include/asm-mips/ar7/led_hal.h 1970-01-01 01:00:00.000000000 +0100
1821 +++ linux.dev2/include/asm-mips/ar7/led_hal.h 2005-10-21 17:02:25.568327000 +0200
1822 @@ -0,0 +1,30 @@
1823 +/******************************************************************************
1824 + * FILE PURPOSE: - LED HAL module Header
1825 + ******************************************************************************
1826 + * FILE NAME: led_hal.h
1827 + *
1828 + * DESCRIPTION: LED HAL API's.
1829 + *
1830 + * REVISION HISTORY:
1831 + * 11 Oct 03 - PSP TII
1832 + *
1833 + * (C) Copyright 2002, Texas Instruments, Inc
1834 + *******************************************************************************/
1835 +
1836 +#ifndef __LED_HAL__
1837 +#define __LED_HAL__
1838 +
1839 +/* Interface prototypes */
1840 +#include "led_config.h"
1841 +
1842 +int avalanche_led_hal_init (int *gpio_off_value, int num_gpio_pins);
1843 +int avalanche_led_config_set (LED_CONFIG_T * led_cfg);
1844 +int avalanche_led_config_get (LED_CONFIG_T *led_cfg,int module_id,int instance, int state);
1845 +void *avalanche_led_register (const char *module_name, int instance_num);
1846 +void avalanche_led_action (void *handle, int state_id);
1847 +void avalanche_led_late_actions(void);
1848 +int avalanche_led_unregister (void *handle);
1849 +void avalanche_led_free_all(void);
1850 +void avalanche_led_hal_exit (void);
1851 +
1852 +#endif /*__LED_HAL__ */
1853 diff -urN linux.dev/include/asm-mips/ar7/ledapp.h linux.dev2/include/asm-mips/ar7/ledapp.h
1854 --- linux.dev/include/asm-mips/ar7/ledapp.h 1970-01-01 01:00:00.000000000 +0100
1855 +++ linux.dev2/include/asm-mips/ar7/ledapp.h 2005-10-21 18:03:44.573780750 +0200
1856 @@ -0,0 +1,59 @@
1857 +#ifndef __LED_APP__
1858 +#define __LED_APP__
1859 +
1860 +#define CONF_FILE "/etc/led.conf"
1861 +#define LED_PROC_FILE "/proc/led_mod/led"
1862 +
1863 +#define CONFIG_LED_MODULE
1864 +
1865 +#define MAX_MOD_ID 25
1866 +#define MAX_STATE_ID 25
1867 +#define MAX_LED_ID 25
1868 +
1869 +#define MOD_ADSL 1
1870 +#define DEF_ADSL_IDLE 1
1871 +#define DEF_ADSL_TRAINING 2
1872 +#define DEF_ADSL_SYNC 3
1873 +#define DEF_ADSL_ACTIVITY 4
1874 +
1875 +#define MOD_WAN 2
1876 +#define DEF_WAN_IDLE 1
1877 +#define DEF_WAN_NEGOTIATE 2
1878 +#define DEF_WAN_SESSION 3
1879 +
1880 +#define MOD_LAN 3
1881 +#define DEF_LAN_IDLE 1
1882 +#define DEF_LAN_LINK_UP 2
1883 +#define DEF_LAN_ACTIVITY 3
1884 +
1885 +#define MOD_WLAN 4
1886 +#define DEF_WLAN_IDLE 1
1887 +#define DEF_WLAN_LINK_UP 2
1888 +#define DEF_WLAN_ACTIVITY 3
1889 +
1890 +#define MOD_USB 5
1891 +#define DEF_USB_IDLE 1
1892 +#define DEF_USB_LINK_UP 2
1893 +#define DEF_USB_ACTIVITY 3
1894 +
1895 +#define MOD_ETH 6
1896 +#define DEF_ETH_IDLE 1
1897 +#define DEF_ETH_LINK_UP 2
1898 +#define DEF_ETH_ACTIVITY 3
1899 +
1900 +typedef struct config_elem{
1901 + unsigned char name;
1902 + unsigned char state;
1903 + unsigned char mode;
1904 + unsigned char led;
1905 + int param;
1906 +}config_elem_t;
1907 +
1908 +typedef struct led_reg{
1909 + unsigned int param;
1910 + void (*init)(unsigned long param);
1911 + void (*onfunc)(unsigned long param);
1912 + void (*offfunc)(unsigned long param);
1913 +}led_reg_t;
1914 +
1915 +#endif
This page took 0.126258 seconds and 5 git commands to generate.