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