-diff -urN kernel-old/drivers/char/avalanche_led/led_drv.c kernel-current/drivers/char/avalanche_led/led_drv.c
---- kernel-old/drivers/char/avalanche_led/led_drv.c 1970-01-01 01:00:00.000000000 +0100
-+++ kernel-current/drivers/char/avalanche_led/led_drv.c 2005-07-10 18:40:23.008730752 +0200
-@@ -0,0 +1,375 @@
-+/******************************************************************************
-+ * FILE PURPOSE: - LED driver module Source
-+ ******************************************************************************
-+ * FILE NAME: led_drv.c
-+ *
-+ * DESCRIPTION: Linux LED character driver implementation
-+ *
-+ * REVISION HISTORY:
-+ * 27 Aug 2003 Initial Creation Sharath Kumar<krs@ti.com>
-+ *
-+ * 16 Dec 2003 Updates for 5.7 Sharath Kumar<krs@ti.com>
-+ *
-+ * 07 Jan 2004 Wrapper for DSL Sharath Kumar<krs@ti.com>
-+ *
-+ * (C) Copyright 2002, Texas Instruments, Inc
-+ *******************************************************************************/
-+
-+#include <linux/config.h>
-+#include <linux/module.h>
-+#include <linux/init.h>
-+#include <linux/types.h>
-+#include <linux/errno.h>
-+#include <linux/slab.h>
-+#include <linux/ioport.h>
-+#include <linux/fcntl.h>
-+#include <linux/interrupt.h>
-+#include <linux/sched.h>
-+#include <linux/mm.h>
-+#include <asm/io.h>
+diff -urN linux.old/drivers/char/avalanche_led/gpio.c linux.dev/drivers/char/avalanche_led/gpio.c
+--- linux.old/drivers/char/avalanche_led/gpio.c 1970-01-01 01:00:00.000000000 +0100
++++ linux.dev/drivers/char/avalanche_led/gpio.c 2005-07-22 06:52:42.973338640 +0200
+@@ -0,0 +1,382 @@
++#include <linux/kernel.h>
+#include <asm/uaccess.h>
-+#include <asm/system.h>
-+#include <linux/delay.h>
-+#include <linux/devfs_fs_kernel.h>
-+#include <linux/wait.h>
++#include <linux/spinlock.h>
+#include <linux/proc_fs.h>
++#include <linux/fs.h>
+#include <linux/timer.h>
-+#include <asm/ar7/sangam.h>
-+#include <asm/ar7/avalanche_misc.h>
-+
-+#include "led_config.h"
-+#include "led_hal.h"
-+#include "led_ioctl.h"
-+#include "led_platform.h"
-+
-+//#define tnetd73xx_gpio_ctrl(gpio_pin, pin_mode, pin_direction) avalanche_gpio_ctrl(gpio_pin, pin_mode, pin_direction)
-+#define tnetd73xx_gpio_out(gpio_pin, value) avalanche_gpio_out_bit(gpio_pin, value)
-+//#define avalanche_gpio_in_bit(gpio_pin) tnetd73xx_gpio_in(gpio_pin)
-+
-+#define TI_LED_VERSION "0.1"
-+#define GPIO_MAP_LEN ((MAX_GPIO_PIN_NUM/32) + 1)
++#include <linux/module.h>
+
-+static int gpio_off_state[GPIO_MAP_LEN] = AVALANCHE_GPIO_OFF_MAP;
++#include <asm/ar7/tnetd73xx_err.h>
++#include <asm/ar7/tnetd73xx_misc.h>
++#include <asm/ar7/ledapp.h>
+
+#define TRUE 1
+#define FALSE 0
-+#define FLICK_TIME (HZ*100/1000)
-+static unsigned int wan_txrx_state = 0;
-+static unsigned int wlan_txrx_state = 0;
-+struct timer_list *pWanTimer = NULL;
+
-+static void wan_led_func(unsigned long data)
-+{
-+ avalanche_gpio_ctrl(2, GPIO_PIN, GPIO_OUTPUT_PIN);
-+ avalanche_gpio_ctrl(3, GPIO_PIN, GPIO_OUTPUT_PIN);
-+
-+ if (wan_txrx_state == 0)
-+ {
-+ tnetd73xx_gpio_out(2, TRUE);
-+ tnetd73xx_gpio_out(3, FALSE);
-+ wan_txrx_state = 1;
-+ }
-+ else
-+ {
-+ tnetd73xx_gpio_out(2, FALSE);
-+ tnetd73xx_gpio_out(3, FALSE);
-+ wan_txrx_state = 0;
-+ }
-+ pWanTimer->expires = jiffies + FLICK_TIME;
-+ add_timer(pWanTimer);
++#if defined CONFIG_AR7WRD || defined CONFIG_AR7RD
++
++#define AR7_RESET_FILE "led_mod/ar7reset"
++#define AR7_VERSION_FILE "led_mod/hardware_version"
++#define AR7_RESET_GPIO 11
++#define RESET_POLL_TIME 1
++#define RESET_HOLD_TIME 4
++#define NO_OF_LEDS
++
++static struct proc_dir_entry *reset_file;
++static int res_state = 0;
++static int count;
++static struct timer_list *pTimer = NULL;
++static ssize_t proc_read_reset_fops(struct file *filp,
++ char *buf,size_t count , loff_t *offp);
++
++static ssize_t proc_read_hwversion_fops(struct file *filp,
++ char *buf,size_t count , loff_t *offp);
++
++struct file_operations reset_fops = {
++ read: proc_read_reset_fops
++ };
++struct file_operations hardware_version_fops = {
++ read: proc_read_hwversion_fops
++ };
++#endif
+
-+}
++static spinlock_t device_lock;
++led_reg_t temp[15];
+
-+static int led_ioctl( struct inode * inode, struct file * file,
-+ unsigned int cmd, unsigned long arg )
++static void gpio_led_on( unsigned long param )
+{
++ unsigned int flags;
+
-+ int ret = 0;
-+// char name[80];
++ spin_lock_irqsave(&device_lock, flags);
+
-+ switch ( cmd )
-+ {
-+ case LED_CONFIG:
-+ {
-+ LED_CONFIG_T led_cfg;
-+ if (copy_from_user((char *)&led_cfg, (char *)arg, sizeof(led_cfg)))
-+ {
-+ printk("in led config error\n");
-+ ret = -EFAULT;
-+ break;
-+ }
-+ printk("in led config\n");
-+ ret = avalanche_led_config_set(&led_cfg);
-+ }
-+ break;
-+
-+ case LED_GET_HANDLE:
-+ {
-+ LED_MODULE_T led_mod;
-+ int handle;
-+
-+ if (copy_from_user((char *)&led_mod, (char *)arg, sizeof(led_mod)))
-+ {
-+ ret = -EFAULT;
-+ break;
-+ }
-+
-+ handle = (int)avalanche_led_register(led_mod.name,led_mod.instance);
-+
-+ if (copy_to_user((char *)(&(((LED_MODULE_T *)arg)->handle)), (char *)(&handle), sizeof(int)))
-+ {
-+ ret = -EFAULT;
-+ break;
-+ }
-+
-+ if(handle)
-+ ret = 0;
-+ else
-+ ret = -1;
-+ }
-+ break;
-+
-+ case LED_ACTION:
-+ {
-+ LED_STATE_T led_state;
-+ if (copy_from_user((char *)&led_state, (char *)arg, sizeof(led_state)))
-+ {
-+ ret = -EFAULT;
-+ break;
-+ }
-+ else {
-+ printk("led action : handle = %d, id = %d\n", led_state.handle, led_state.state_id);
-+ //add by leijun
-+ if (led_state.handle == 2) //system led
-+ {
-+ switch (led_state.state_id)
-+ {
-+ case 1:
-+ break;
-+ case 2: /*sys led flashing green */
-+ tnetd73xx_gpio_out(4, FALSE);
-+ tnetd73xx_gpio_out(5, TRUE);
-+ tnetd73xx_gpio_out(8, TRUE);
-+ break;
-+ case 3: /*sys led solid green */
-+ tnetd73xx_gpio_out(4, TRUE);
-+ tnetd73xx_gpio_out(5, TRUE);
-+ tnetd73xx_gpio_out(8, TRUE);
-+
-+ break;
-+ case 4: /*sys fail red */
-+ tnetd73xx_gpio_out(4, TRUE);
-+ tnetd73xx_gpio_out(5, FALSE);
-+ tnetd73xx_gpio_out(8, FALSE);
-+ break;
-+ default:
-+ break;
++ tnetd73xx_gpio_out(param,FALSE);
++ spin_unlock_irqrestore(&device_lock, flags);
++}
+
-+ }
-+ }else if (led_state.handle == 3)
-+ {
-+ printk("led action : handle = %d, id = %d\n", led_state.handle, led_state.state_id);
-+ avalanche_gpio_ctrl(2, GPIO_PIN, GPIO_OUTPUT_PIN);
-+ avalanche_gpio_ctrl(3, GPIO_PIN, GPIO_OUTPUT_PIN);
++static void gpio_led_off ( unsigned long param )
++{
++ unsigned int flags = 0x00;
+
-+ switch (led_state.state_id)
-+ {
-+ case 1: /*no wan interface*/
-+ if (pWanTimer)
-+ {
-+ del_timer(pWanTimer);
-+ kfree(pWanTimer);
-+ pWanTimer = NULL;
-+ }
-+ tnetd73xx_gpio_out(2, FALSE);
-+ tnetd73xx_gpio_out(3, FALSE);
-+ break;
-+ case 2: /*wan connected */
-+ if (pWanTimer)
-+ {
-+ del_timer(pWanTimer);
-+ kfree(pWanTimer);
-+ pWanTimer = NULL;
-+ }
-+ tnetd73xx_gpio_out(2, TRUE);
-+ tnetd73xx_gpio_out(3, FALSE);
-+ break;
-+ case 3: /*rx/tx activity */
-+ if (pWanTimer != NULL)
-+ break;
-+
-+ pWanTimer = kmalloc(sizeof(struct timer_list), GFP_KERNEL);
-+ init_timer(pWanTimer);
-+
-+ pWanTimer->function = wan_led_func;
-+ pWanTimer->data = 0;
-+ pWanTimer->expires = jiffies + FLICK_TIME;
-+ tnetd73xx_gpio_out(2, FALSE);
-+ tnetd73xx_gpio_out(3, FALSE);
-+ wan_txrx_state = 0;
-+ add_timer(pWanTimer);
-+
-+ break;
-+ case 4: /*no ipaddress */
-+ if (pWanTimer)
-+ {
-+ del_timer(pWanTimer);
-+ kfree(pWanTimer);
-+ pWanTimer = NULL;
-+ }
-+ tnetd73xx_gpio_out(2, FALSE);
-+ tnetd73xx_gpio_out(3, TRUE);
-+ break;
-+ default:
-+ if (pWanTimer)
-+ {
-+ del_timer(pWanTimer);
-+ kfree(pWanTimer);
-+ pWanTimer = NULL;
-+ }
-+ break;
-+ }
-+ }else if (led_state.handle == 4) //test
-+ {
-+ int high, low;
-+ high = (led_state.state_id & 0xf0) >> 4;
-+ low = (led_state.state_id & 0x0f);
-+ tnetd73xx_gpio_out(high, (low > 0)?1:0);
-+ }else avalanche_led_action((void *)led_state.handle,led_state.state_id);
-+ }
-+
-+ }
-+ break;
-+
-+ case LED_RELEASE_HANDLE:
-+ ret = avalanche_led_unregister((void *)arg);
-+ break;
-+
-+ default:
-+ ret = -EINVAL;
-+ }
-+ return ret;
++ spin_lock_irqsave(&device_lock, flags);
+
++ tnetd73xx_gpio_out(param,TRUE);
++ spin_unlock_irqrestore(&device_lock, flags);
+}
+
-+static int led_open( struct inode * inode, struct file * file )
++static void gpio_led_init( unsigned long param)
+{
-+ return 0;
++ tnetd73xx_gpio_ctrl(param,GPIO_PIN,GPIO_OUTPUT_PIN);
+}
+
-+static int led_close( struct inode * inode, struct file * file )
++static void board_gpio_reset(void)
+{
-+ return 0;
++ /* Initialize the link mask */
++ device_lock = SPIN_LOCK_UNLOCKED;
++ return;
+}
+
-+struct file_operations led_fops = {
-+ ioctl: led_ioctl,
-+ open: led_open,
-+ release: led_close
-+};
-+
-+
-+/* Proc function to display driver version */
-+static int
-+led_ver_info(char *buf, char **start, off_t offset, int count, int *eof, void *data)
-+{
-+// int instance;
-+ int len=0;
-+
-+ len += sprintf(buf +len,"\nTI Linux LED Driver Version %s\n",TI_LED_VERSION);
-+ return len;
-+}
-+
-+
-+/* proc interface /proc/avalanche/led */
-+int led_cfg_info(char* buf, char **start, off_t offset, int count,
-+ int *eof, void *data)
-+{
-+ int mod_count = 0;
-+ int len=0;
-+ int limit = count - 80;
-+ char *msg[5]={"LED OFF", "LED_ON", "LED_ONESHOT_OFF", "LED_ONESHOT_ON","LED_FLASH"};
++#if defined CONFIG_AR7WRD || defined CONFIG_AR7RD
+
-+ for(mod_count = 0;mod_count<MAX_MODULE_ENTRIES;mod_count++)
-+ {
-+ int instance;
-+
-+ for(instance = 0; instance < MAX_MODULE_INSTANCES; instance++)
-+ {
-+ int state_id;
-+ int flag = 0;
-+
-+ for(state_id =0 ;state_id < MAX_STATE_ENTRIES; state_id++)
-+ {
-+ LED_CONFIG_T led_cfg;
-+ if(avalanche_led_config_get(&led_cfg,mod_count,instance,state_id) == 0)
-+ {
-+ if(flag == 0)
-+ {
-+ flag = 1;
-+ if(len <= limit)
-+ len+= sprintf(buf+len, "\nModule:%s\n",led_cfg.name);
-+
-+ if(len <= limit)
-+ len+= sprintf(buf+len, "\n Instance:%d\n",instance);
-+
-+ }
-+
-+ if(len <= limit)
-+ len+= sprintf(buf+len, "\n State: %d\n",state_id);
-+
-+ if(len <= limit)
-+ len+= sprintf(buf+len, "\n mode: %s\n",msg[led_cfg.mode[0]% 5 ]);
-+
-+ if(len <= limit)
-+ len+= sprintf(buf+len, "\n gpio: %d\n",led_cfg.gpio[0]);
-+
-+ if(len <= limit)
-+ len+= sprintf(buf+len, "\n param1: %d\n",led_cfg.param1);
-+
-+ if(len <= limit)
-+ len+= sprintf(buf+len, "\n param2: %d\n",led_cfg.param2);
-+ }
-+ }
-+ }
-+ }
-+
-+
-+
-+ return len;
-+}
-+
-+
-+
-+int __init led_init(void)
++static ssize_t proc_read_hwversion_fops(struct file *filp, char *buf,
++ size_t count, loff_t *offp)
+{
-+
-+ /* register LED device */
-+ devfs_register(NULL, "led", DEVFS_FL_AUTO_DEVNUM, 0, 0,
-+ S_IFCHR | S_IRUGO | S_IWUGO, &led_fops,NULL);
-+
-+
-+ avalanche_led_hal_init(gpio_off_state,AVALANCHE_GPIO_PIN_COUNT);
-+
-+ /* create proc entry */
-+ create_proc_read_entry("avalanche/led_cfg", 0, NULL, led_cfg_info, NULL);
-+ create_proc_read_entry("avalanche/led_ver", 0, NULL, led_ver_info, NULL);
-+
-+ return 0;
-+}
-+
-+void led_exit(void)
++ char line[8];
++ int len = 0;
++ if( *offp != 0 )
++ return 0;
++
++ len = sprintf(line, "%d%d.%d%d%d%d\n", tnetd73xx_gpio_in(20),
++ tnetd73xx_gpio_in(21), tnetd73xx_gpio_in(22),
++ tnetd73xx_gpio_in(23), tnetd73xx_gpio_in(24),
++ tnetd73xx_gpio_in(25));
++
++ copy_to_user(buf, line, len);
++ *offp = len;
++ return len;
++}
++
++static ssize_t proc_read_reset_fops(struct file *filp,
++ char *buf,size_t count , loff_t *offp)
+{
-+ avalanche_led_hal_exit();
-+ return;
++ char * pdata = NULL;
++ char line[3];
++ int len = 0;
++ if( *offp != 0 )
++ return 0;
++
++ pdata = buf;
++ len = sprintf(line,"%d\n", res_state );
++//wwzh
++// res_state = 0;
++ copy_to_user(buf,line,len );
++ *offp = len;
++ return len;
+}
+
-+module_init(led_init);
-+module_exit(led_exit);
-+
-+
-+EXPORT_SYMBOL_NOVERS(avalanche_led_register);
-+EXPORT_SYMBOL_NOVERS(avalanche_led_action);
-+EXPORT_SYMBOL_NOVERS(avalanche_led_unregister);
-+EXPORT_SYMBOL_NOVERS(avalanche_led_config_set);
-+EXPORT_SYMBOL_NOVERS(avalanche_led_config_get);
-diff -urN kernel-old/drivers/char/avalanche_led/led_hal.c kernel-current/drivers/char/avalanche_led/led_hal.c
---- kernel-old/drivers/char/avalanche_led/led_hal.c 1970-01-01 01:00:00.000000000 +0100
-+++ kernel-current/drivers/char/avalanche_led/led_hal.c 2005-07-10 18:24:22.242038232 +0200
-@@ -0,0 +1,821 @@
-+/******************************************************************************
-+ * FILE PURPOSE: - LED HAL module source
-+ ******************************************************************************
-+ * FILE NAME: led_hal.c
-+ *
-+ * DESCRIPTION: LED HAL API's source.
-+ *
-+ * REVISION HISTORY:
-+ * 27 Aug 2003 Initial Creation Sharath Kumar<krs@ti.com>
-+ *
-+ * 16 Dec 2003 Updates for 5.7 Sharath Kumar<krs@ti.com>
-+ *
-+ * 07 Jan 2004 Wrapper for DSL Sharath Kumar<krs@ti.com>
-+ *
-+ * (C) Copyright 2002, Texas Instruments, Inc
-+ *******************************************************************************/
-+
-+#include "led_platform.h"
-+#include "led_config.h"
-+#include "led_hal.h"
-+
-+/* include for gpio APIs */
-+#include <asm/ar7/avalanche_misc.h>
-+
-+
-+#define REQUIRES_TIMER(x) ( (x == LED_ONESHOT_ON) || (x == LED_ONESHOT_OFF) || (x == LED_FLASH) )
-+
-+/*******************TYPEDEFs**************************************************/
-+typedef struct
++static void reset_timer_func(unsigned long data)
+{
-+ unsigned int state;
-+ unsigned int module_map;
-+ unsigned int pos_map[2];
++//wwzh
++#if 0
++ count = (tnetd73xx_gpio_in(AR7_RESET_GPIO) == 0) ? count + 1: 0;
++ if( count >= RESET_HOLD_TIME/RESET_POLL_TIME )
++#endif
++ if (tnetd73xx_gpio_in(AR7_RESET_GPIO) == 0)
++ res_state = 1;
++ else
++ res_state = 0;
++ pTimer->expires = jiffies + HZ*RESET_POLL_TIME;
++ add_timer (pTimer);
++ return;
+}
-+LED_OBJ_T;
+
-+typedef struct state_entry STATE_ENTRY_T;
-+
-+struct state_entry
-+{
-+ void (*handler) (STATE_ENTRY_T * state);
-+ unsigned int timer_running;
-+ LED_OBJ_T *led;
-+ unsigned int map1[2];
-+ unsigned int map2[2];
-+ void *os_timer;
-+ unsigned int param1;
-+ unsigned int param2;
-+ unsigned int module_id;
-+ unsigned int mode;
-+};
-+
-+typedef struct module_instance
++static void hardware_version_init(void)
+{
-+ int module_id;
-+ int instance;
-+ STATE_ENTRY_T *states[MAX_STATE_ENTRIES];
++ static struct proc_dir_entry *hardware_version_file;
++ hardware_version_file = create_proc_entry(AR7_VERSION_FILE, 0777, NULL);
++ if(hardware_version_file == NULL)
++ return;
++
++ hardware_version_file->owner = THIS_MODULE;
++ hardware_version_file->proc_fops = &hardware_version_fops;
++
++ tnetd73xx_gpio_ctrl(20,GPIO_PIN,GPIO_INPUT_PIN);
++ tnetd73xx_gpio_ctrl(21,GPIO_PIN,GPIO_INPUT_PIN);
++ tnetd73xx_gpio_ctrl(22,GPIO_PIN,GPIO_INPUT_PIN);
++ tnetd73xx_gpio_ctrl(23,GPIO_PIN,GPIO_INPUT_PIN);
++ tnetd73xx_gpio_ctrl(24,GPIO_PIN,GPIO_INPUT_PIN);
++ tnetd73xx_gpio_ctrl(25,GPIO_PIN,GPIO_INPUT_PIN);
++
++ return;
+}
-+MODULE_INSTANCE_T;
+
-+typedef struct module_entry
++static void reset_init(void)
+{
-+ unsigned char *name;
-+ MODULE_INSTANCE_T *module_instance[MAX_MODULE_INSTANCES];
++ /* Create board reset proc file */
++ reset_file = create_proc_entry( AR7_RESET_FILE, 0777, NULL);
++ if( reset_file == NULL)
++ goto reset_file;
++ reset_file->owner = THIS_MODULE;
++ reset_file->proc_fops = &reset_fops;
++
++ /* Initialise GPIO 11 for input */
++ tnetd73xx_gpio_ctrl(AR7_RESET_GPIO,GPIO_PIN,GPIO_INPUT_PIN);
++
++ /* Create a timer which fires every seconds */
++ pTimer = kmalloc(sizeof(struct timer_list),GFP_KERNEL);
++ init_timer( pTimer );
++ pTimer->function = reset_timer_func;
++ pTimer->data = 0;
++ /* Start the timer */
++ reset_timer_func(0);
++ return ;
++
++ reset_file:
++ remove_proc_entry("AR7_RESET_FILE",NULL);
++ return;
+}
-+MODULE_ENTRY_T;
-+
-+
-+
-+/******************variable defn/declns***************************************/
-+
-+static LED_OBJ_T *leds[MAX_LED_ENTRIES];
-+static MODULE_ENTRY_T *modules[MAX_MODULE_ENTRIES];
-+
-+/* Declare Mutex lock */
-+MUTEX_DECLARE (led_lock);
-+
-+/* GPIO OFF STATE */
-+static unsigned int gpio_offstate_map[2];
-+
-+/* Number of GPIO pins in the system */
-+static unsigned int num_gpios;
-+
-+/* LED handlers */
-+static void (*led_mode_handler[NUM_LED_MODES]) (STATE_ENTRY_T * state);
-+
-+
-+
-+/******************static functions*****************************************/
-+
-+static void *led_malloc (int n)
++#endif
++/*************wwzh****************/
++#if 1
++extern unsigned int sys_mod_state;
++extern unsigned int wan_mod_state;
++extern unsigned int wlan_mod_state;
++void sys_led_init(void)
+{
-+ void *p;
-+ p = os_malloc (n);
++ tnetd73xx_gpio_ctrl(4, GPIO_PIN, GPIO_OUTPUT_PIN);
++ tnetd73xx_gpio_ctrl(5, GPIO_PIN, GPIO_OUTPUT_PIN);
++ tnetd73xx_gpio_ctrl(8, GPIO_PIN, GPIO_OUTPUT_PIN);
+
-+ if (p)
-+ os_memset (p, 0, n);
++ tnetd73xx_gpio_out(4, FALSE);
++ tnetd73xx_gpio_out(5, TRUE);
++ tnetd73xx_gpio_out(8, TRUE);
++
+
-+ return p;
-+}
++ sys_mod_state = 2;
+
-+static void avalanche_gpio_set(int * set_map,int *pos_map)
++}
++void wan_led_init(void)
+{
-+ int i;
-+
-+ for(i = 0;i <num_gpios ;i+=32)
-+ {
-+ int index = i/32;
-+ avalanche_gpio_out_value(set_map[index],pos_map[index],index);
-+
-+ }
-+
++
++ tnetd73xx_gpio_ctrl(2, GPIO_PIN, GPIO_OUTPUT_PIN);
++ tnetd73xx_gpio_ctrl(3, GPIO_PIN, GPIO_OUTPUT_PIN);
++
++ tnetd73xx_gpio_out(2, FALSE);
++ tnetd73xx_gpio_out(3, FALSE);
++
++ wan_mod_state = 1;
+}
-+
-+
-+static MODULE_INSTANCE_T *get_module (char *name, int instance)
++//wwzh wireless
++#if 0
++void wlan_led_init(void)
+{
-+ int module_id;
-+ MODULE_INSTANCE_T *mod_inst;
-+
-+
-+ if (instance >= MAX_MODULE_INSTANCES)
-+ return NULL;
-+
-+ for (module_id = 0; module_id < MAX_MODULE_ENTRIES; module_id++)
-+ {
-+ if (modules[module_id]
-+ && !os_strcmp (name, modules[module_id]->name))
-+ break;
-+ }
-+
-+ if (module_id == MAX_MODULE_ENTRIES)
-+ {
-+ for (module_id = 0;
-+ (module_id < MAX_MODULE_ENTRIES) && modules[module_id];
-+ module_id++);
-+
-+ if (module_id < MAX_MODULE_ENTRIES)
-+ {
-+ modules[module_id] = led_malloc (sizeof (MODULE_ENTRY_T));
-+
-+ if (!modules[module_id])
-+ return NULL;
-+
-+ modules[module_id]->name = led_malloc (os_strlen (name) + 1);
-+
-+ if (!modules[module_id]->name)
-+ return NULL;
-+
-+ os_strcpy (modules[module_id]->name, name);
-+ }
-+ else
-+ {
-+ log_msg ("ERROR:Module Count exceeded\n");
-+ return NULL;
-+ }
-+ }
-+
-+ if (!modules[module_id]->module_instance[instance])
-+ modules[module_id]->module_instance[instance] =
-+ led_malloc (sizeof (MODULE_INSTANCE_T));
-+
-+ if (!modules[module_id]->module_instance[instance])
-+ return NULL;
-+
-+ mod_inst = modules[module_id]->module_instance[instance];
-+ mod_inst->module_id = module_id;
-+ mod_inst->instance = instance;
-+
-+ return mod_inst;
++ //unsigned long i = 0;
++ tnetd73xx_gpio_ctrl(12, GPIO_PIN, GPIO_OUTPUT_PIN);
++ tnetd73xx_gpio_ctrl(13, GPIO_PIN, GPIO_OUTPUT_PIN);
++
++ tnetd73xx_gpio_out(12, FALSE);
++ tnetd73xx_gpio_out(13, TRUE);
++ //for (i = 0; i < 0x20000000; i++);
++ wlan_mod_state = 1;
+}
++#endif
+
++#endif
++/*************end ****************/
+
-+static void assign_map(int *to, int *from)
++void board_gpio_init(void)
+{
-+ int i;
-+
-+ for(i = 0;i <num_gpios ;i+=32)
-+ {
-+ int index = i/32;
-+ to[index] = from[index];
-+ }
-+}
+
++ board_gpio_reset();
++/**************wwzh*************/
++ sys_led_init();
++ wan_led_init();
++
++ //junzhao 2004.3.15
++ hardware_version_init();
++
++ //wlan_led_init();
++
++ /* Register Device MAX_LED_ID + 1 for reset to factory default */
++ temp[0].param = 0;
++ temp[0].init = reset_init;
++ temp[0].onfunc = 0;
++ temp[0].offfunc = 0;
++ register_led_drv( MAX_LED_ID + 1 , &temp[0]);
++//wwzh for wireless led
++#if 1
++ /* Register led 12 WiFi 6 */
++ temp[1].param = 6;
++ temp[1].init = gpio_led_init;
++ temp[1].onfunc = gpio_led_on;
++ temp[1].offfunc = gpio_led_off;
++ register_led_drv( 12 , &temp[1]);
+
++#endif
+
++#if 0
++/**************end ************/
++#if defined(CONFIG_AR5D01)
++ /* Register led 1 GPIO0 */
++ temp[0].param = GPIO_0;
++ temp[0].init = gpio_led_init;
++ temp[0].onfunc = gpio_led_on;
++ temp[0].offfunc = gpio_led_off;
++ register_led_drv( 1 , &temp[0]);
++
++ /* Register led 2 EINT1 */
++ temp[1].param = EINT_1;
++ temp[1].init = gpio_led_init;
++ temp[1].onfunc = gpio_led_on;
++ temp[1].offfunc = gpio_led_off;
++ register_led_drv( 2 , &temp[1]);
++
++ /* Register led 5 EINT1 */
++ temp[2].param = GPIO_1;
++ temp[2].init = gpio_led_init;
++ temp[2].onfunc = gpio_led_on;
++ temp[2].offfunc = gpio_led_off;
++ register_led_drv( 5 , &temp[2]);
++#endif
+
-+static LED_OBJ_T *get_led (int * pos_map)
-+{
-+ int led_id;
-+
-+ for (led_id = 0; led_id < MAX_LED_ENTRIES; led_id++)
-+ {
-+ if (leds[led_id])
-+ {
-+ int i;
-+ int flag=0;
-+
-+ for(i = 0;i <num_gpios ;i+=32)
-+ {
-+ int index = i/32;
-+ if(leds[led_id]->pos_map[index] != pos_map[index])
-+ flag =1;
-+ }
-+ if(flag == 0)
-+ break;
-+ }
-+ }
-+
-+ if (led_id == MAX_LED_ENTRIES)
-+ {
-+ for (led_id = 0; (led_id < MAX_LED_ENTRIES) && leds[led_id];
-+ led_id++);
-+
-+ if (led_id < MAX_LED_ENTRIES)
-+ {
-+ leds[led_id] = led_malloc (sizeof (LED_OBJ_T));
-+
-+ if (!leds[led_id])
-+ return NULL;
-+
-+ assign_map(leds[led_id]->pos_map,pos_map);
-+ }
-+ else
-+ {
-+ log_msg ("ERROR:Module Count exceeded\n");
-+ return NULL;
-+ }
-+ }
-+
-+ return leds[led_id];
-+}
++#if defined(CONFIG_AR5W01)
++ /* Register led 5 GPIO_1 */
++ temp[0].param = GPIO_1;
++ temp[0].init = gpio_led_init;
++ temp[0].onfunc = gpio_led_on;
++ temp[0].offfunc = gpio_led_off;
++ register_led_drv( 5 , &temp[0]);
++
++ /* Register led 7 GPIO_0 */
++ temp[1].param = GPIO_0;
++ temp[1].init = gpio_led_init;
++ temp[1].onfunc = gpio_led_on;
++ temp[1].offfunc = gpio_led_off;
++ register_led_drv( 7 , &temp[1]);
++#endif
+
-+static void led_oneshot_on_timer_func (int arg)
-+{
-+ STATE_ENTRY_T *state = (STATE_ENTRY_T *) arg;
-+ LED_OBJ_T *led = state->led;
-+
-+ state->timer_running = 0;
-+ MUTEX_GET (led_lock);
-+ if (led->state == LED_ONESHOT_ON)
-+ {
-+ led->state = LED_OFF;
-+ avalanche_gpio_set (state->map2,led->pos_map);
-+ }
-+ MUTEX_RELEASE (led_lock);
++//wwzh #if defined(CONFIG_AR7RD)
++#if defined CONFIG_AR7WRD || defined CONFIG_AR7RD
++ /* Register led 5 Green PPPOE GPIO 13 */
++ temp[0].param = 13;
++ temp[0].init = gpio_led_init;
++ temp[0].onfunc = gpio_led_on;
++ temp[0].offfunc = gpio_led_off;
++ register_led_drv( 5 , &temp[0]);
++
++ /* Register led 7 Green USB GPIO 12 */
++ temp[1].param = 12;
++ temp[1].init = gpio_led_init;
++ temp[1].onfunc = gpio_led_on;
++ temp[1].offfunc = gpio_led_off;
++ register_led_drv( 7 , &temp[1]);
++
++ /* Register Device MAX_LED_ID + 1 for reset to factory default */
++ temp[2].param = 0;
++ temp[2].init = reset_init;
++ temp[2].onfunc = 0;
++ temp[2].offfunc = 0;
++ register_led_drv( MAX_LED_ID + 1 , &temp[2]);
++
++ /* Register led 8 RED DSL GPIO 10 */
++ temp[3].param = 10;
++ temp[3].init = gpio_led_init;
++ temp[3].onfunc = gpio_led_on;
++ temp[3].offfunc = gpio_led_off;
++ register_led_drv( 8 , &temp[3]);
++
++ /* Register led 9 RED PPPoE down GPIO 9 */
++ temp[4].param = 9;
++ temp[4].init = gpio_led_init;
++ temp[4].onfunc = gpio_led_on;
++ temp[4].offfunc = gpio_led_off;
++ register_led_drv( 9 , &temp[4]);
++
++ /* Register led 10 DSL down GPIO 8 */
++ temp[5].param = 8;
++ temp[5].init = gpio_led_init;
++ temp[5].onfunc = gpio_led_on;
++ temp[5].offfunc = gpio_led_off;
++ register_led_drv( 10 , &temp[5]);
++
++ /* Register led 11 Power GPIO 7 */
++ temp[6].param = 7;
++ temp[6].init = gpio_led_init;
++ temp[6].onfunc = gpio_led_on;
++ temp[6].offfunc = gpio_led_off;
++ register_led_drv( 11 , &temp[6]);
++
++ /* Register led 12 WiFi 6 */
++ temp[7].param = 6;
++ temp[7].init = gpio_led_init;
++ temp[7].onfunc = gpio_led_on;
++ temp[7].offfunc = gpio_led_off;
++ register_led_drv( 12 , &temp[7]);
++
++ /* Register led 13 ELINK(AA1313) GPIO 15 */
++ temp[8].param = 15;
++ temp[8].init = gpio_led_init;
++ temp[8].onfunc = gpio_led_on;
++ temp[8].offfunc = gpio_led_off;
++ register_led_drv( 13 , &temp[8]);
++
++ /* Register led 14 EACT(Y13) GPIO 16 */
++ temp[9].param = 16;
++ temp[9].init = gpio_led_init;
++ temp[9].onfunc = gpio_led_on;
++ temp[9].offfunc = gpio_led_off;
++ register_led_drv( 14 , &temp[9]);
+
++#endif
++/**************wwzh**************/
++#endif
++/**************end **************/
++ return;
+}
+
-+static void led_oneshot_off_timer_func (int arg)
-+{
-+ STATE_ENTRY_T *state = (STATE_ENTRY_T *) arg;
-+ LED_OBJ_T *led = state->led;
+
-+ state->timer_running = 0;
+
-+ MUTEX_GET (led_lock);
-+ if (led->state == LED_ONESHOT_OFF)
-+ {
-+ led->state = LED_ON;
-+ avalanche_gpio_set(state->map2,led->pos_map);
-+ }
-+ MUTEX_RELEASE (led_lock);
+
-+}
+
-+static void led_flash_timer_func (int arg)
-+{
-+ STATE_ENTRY_T *state = (STATE_ENTRY_T *) arg;
-+ LED_OBJ_T *led = state->led;
-+
-+
-+ if (led->state != LED_FLASH)
-+ return;
-+
-+ MUTEX_GET (led_lock);
-+
-+ if (state->timer_running == 1)
-+ {
-+ state->timer_running = 2;
-+ avalanche_gpio_set(state->map2,led->pos_map);
-+ os_timer_add (state->os_timer, state->param2, (int)state);
-+ }
-+ else
-+ {
-+ state->timer_running = 1;
-+ avalanche_gpio_set(state->map1,led->pos_map);
-+ os_timer_add (state->os_timer, state->param1, (int)state);
-+ }
-+
-+ MUTEX_RELEASE (led_lock);
-+}
+
-+static void led_on(STATE_ENTRY_T * state)
-+{
-+ LED_OBJ_T *led = state->led;
+
-+ led->state = LED_ON;
-+ avalanche_gpio_set(state->map1,led->pos_map);
-+ led->module_map |= (1 << (state->module_id));
+
-+}
+diff -urN linux.old/drivers/char/avalanche_led/ledmod.c linux.dev/drivers/char/avalanche_led/ledmod.c
+--- linux.old/drivers/char/avalanche_led/ledmod.c 1970-01-01 01:00:00.000000000 +0100
++++ linux.dev/drivers/char/avalanche_led/ledmod.c 2005-07-22 06:52:42.975338336 +0200
+@@ -0,0 +1,1116 @@
++#include <linux/config.h>
++#include <linux/init.h>
++#include <linux/kernel.h>
++#include <linux/proc_fs.h>
++#include <asm/uaccess.h>
++#include <linux/fs.h>
++#include <linux/timer.h>
++#include <linux/delay.h>
++#include <linux/spinlock.h>
++#include <asm/ar7/avalanche_regs.h>
++#include <asm/ar7/ledapp.h>
++#include <linux/module.h>
+
-+static void led_off (STATE_ENTRY_T * state)
-+{
-+ LED_OBJ_T *led = state->led;
++#define LED_ON 1
++#define LED_OFF 2
++#define LED_BLINK 3
++#define LED_FLASH 4
+
-+ led->module_map &= ~(1 << (state->module_id));
-+ if (!led->module_map)
-+ {
-+ led->state = LED_OFF;
-+ avalanche_gpio_set(state->map1,led->pos_map);
-+ }
++#define LED_BLINK_UP 5
++#define LED_BLINK_DOWN 6
+
-+}
++extern void avalanche_leds_init(void);
+
-+static void led_oneshot_on (STATE_ENTRY_T * state)
-+{
-+ LED_OBJ_T *led = state->led;
++/***********wwzh**************/
++unsigned int sys_mod_state;
++unsigned int wan_mod_state;
++unsigned int wlan_mod_state;
+
-+ if (state->timer_running)
-+ return;
++struct timer_list *pWanTimer = NULL;
++struct timer_list *pWlanTimer = NULL;
++/***********end **************/
+
-+ state->timer_running = 1;
-+ led->state = LED_ONESHOT_ON;
-+ avalanche_gpio_set(state->map1,led->pos_map);
-+ os_timer_add (state->os_timer, state->param1,(int) state);
-+}
++typedef struct state_entry{
++ unsigned char mode;
++ unsigned char led;
++ void (*handler)(struct state_entry *pState);
++ unsigned long param;
++}state_entry_t;
+
-+static void led_oneshot_off (STATE_ENTRY_T * state)
-+{
++typedef struct mod_entry{
++ state_entry_t *states[MAX_STATE_ID];
++}mod_entry_t;
+
-+ LED_OBJ_T *led = state->led;
++static mod_entry_t *modArr[MAX_MOD_ID];
++static struct proc_dir_entry *led_proc_dir,*led_file;
+
-+ if (state->timer_running)
-+ return;
++/* index of the array is the led number HARDWARE SPECIFIC*/
++typedef struct led_data{
++ led_reg_t *led;
++ int state;
++ struct timer_list *pTimer;
++ unsigned char timer_running;
++ unsigned long param;
++}led_data_t;
+
-+ state->timer_running = 1;
-+ led->state = LED_ONESHOT_OFF;
-+ avalanche_gpio_set(state->map1,led->pos_map);
-+ os_timer_add (state->os_timer, state->param1,(int) state);
-+}
++led_data_t led_arr[MAX_LED_ID + 1];
++/*!!! The last device is actually being used for ar7 reset to factory default */
+
-+static void led_flash (STATE_ENTRY_T * state)
-+{
-+ LED_OBJ_T *led = state->led;
+
-+ if (state->timer_running)
-+ return;
++static spinlock_t config_lock;
+
-+ state->timer_running = 1;
-+ led->state = LED_FLASH;
-+ avalanche_gpio_set(state->map1,led->pos_map);
-+ os_timer_add (state->os_timer, state->param1,(int) state);
-+}
++static void board_led_link_up( state_entry_t *pState );
++static void board_led_link_down( state_entry_t *pState );
++static void board_led_activity_on( state_entry_t *pState );
++static void board_led_activity_off( state_entry_t *pState );
++static void led_timer_func(unsigned long data);
+
++extern void board_gpio_init(void);
++extern void uart_led_init(void);
+
++static ssize_t proc_read_led_fops(struct file *filp,
++ char *buf,size_t count , loff_t *offp);
++static ssize_t proc_write_led_fops(struct file *filp,const char *buffer,
++ size_t count , loff_t *offp);
++static int config_led( unsigned long y);
+
-+static int led_get_mode(LED_CONFIG_T *led_cfg)
-+{
-+ int num_gpio = led_cfg->gpio_num;
-+ int i;
-+ int *led_mode = led_cfg->mode;
-+ int max = -1;
++struct file_operations led_fops = {
++ read: proc_read_led_fops,
++ write: proc_write_led_fops,
++ };
+
-+ /* Return Max of available modes */
-+ for(i = 0; i<num_gpio; i++)
-+ {
-+ max = (max > led_mode[i]) ? max : led_mode[i];
-+ }
-+
-+ return max;
++static int led_atoi( char *name)
++{
++ int val = 0;
++ for(;;name++)
++ {
++ switch(*name)
++ {
++ case '0'...'9':
++ val = val*10+(*name - '0');
++ break;
++ default:
++ return val;
++ }
++ }
+}
+
-+static void led_assign_timer(STATE_ENTRY_T *state_entry)
++static int free_memory(void)
+{
++ int i, j;
+
-+ if (state_entry->os_timer)
-+ {
-+ os_timer_delete(state_entry->os_timer);
-+ }
-+
-+ switch(state_entry->mode)
-+ {
-+ case LED_ONESHOT_ON:
-+ state_entry->os_timer = os_timer_init(led_oneshot_on_timer_func);
-+ break;
-+
-+ case LED_ONESHOT_OFF:
-+ state_entry->os_timer = os_timer_init(led_oneshot_off_timer_func);
-+ break;
-+
-+ case LED_FLASH:
-+ state_entry->os_timer = os_timer_init(led_flash_timer_func);
-+ break;
-+
-+ default:
-+ log_msg("invalid mode in function led_assign timer\n");
-+ }
-+
++ for( i = 0; i < MAX_MOD_ID ; i++)
++ {
++ if( modArr[i] != NULL )
++ {
++ for( j = 0; j < MAX_STATE_ID ; j++ )
++ {
++ if( modArr[i]->states[j] != NULL )
++ kfree( modArr[i]->states[j]);
++ }
++ kfree(modArr[i]);
++ modArr[i] = NULL;
++ }
++ }
++ return 0;
+}
+
-+static int led_get_map(LED_CONFIG_T *led_cfg,int *p_pos_map,int *p_map1,int *p_map2)
++static int led_on( state_entry_t *pState )
+{
-+ int i;
-+ int map1[2] = {0,0};
-+ int pos_map[2] = {0,0};
-+ int map2[2] = {0,0};
-+ int requires_timer = REQUIRES_TIMER(led_get_mode(led_cfg));
-+
-+ for (i = 0; i < led_cfg->gpio_num; i++)
-+ {
-+ int gpio_map;
-+ int index = led_cfg->gpio[i]/32;
-+ int pos = led_cfg->gpio[i] % 32;
-+
-+ if (led_cfg->gpio[i] >= num_gpios)
-+ {
-+ log_msg ("Error: gpio number out of range\n");
-+ return -1;
-+ }
-+
-+ gpio_map = 1 << pos;
-+
-+ pos_map[index] |= gpio_map;
-+
-+
-+ switch (led_cfg->mode[i])
-+ {
-+ case LED_OFF:
-+ if(gpio_offstate_map[index] & gpio_map)
-+ map1[index] |= gpio_map;
-+
-+ if (requires_timer && (gpio_offstate_map[index] & gpio_map))
-+ map2[index] |= gpio_map;
-+ break;
-+
-+ case LED_ON:
-+
-+ if(!(gpio_offstate_map[index] & gpio_map))
-+ map1[index] |= gpio_map;
-+
-+ if (requires_timer && !(gpio_offstate_map[index] & gpio_map))
-+ map2[index] |= gpio_map;
-+ break;
-+
-+ case LED_ONESHOT_OFF:
-+
-+ if ((gpio_offstate_map[index] & gpio_map))
-+ map1[index] |= gpio_map;
-+ else
-+ map2[index] |= gpio_map;
-+ break;
-+
-+ case LED_ONESHOT_ON:
-+ case LED_FLASH:
-+
-+ if (!(gpio_offstate_map[index] & gpio_map))
-+ map1[index] |= gpio_map;
-+ else
-+ map2[index] |= gpio_map;
-+ break;
-+
-+ default:
-+ log_msg ("Error: Invalid mode\n");
-+ return -1;
-+ }
-+ }
-+
-+ assign_map(p_pos_map,pos_map);
-+ assign_map(p_map1,map1);
-+ assign_map(p_map2,map2);
-+
-+ return 0;
++ if( led_arr[pState->led].led == NULL)
++ return -1;
++ led_arr[pState->led].led->onfunc( led_arr[pState->led].led->param);
++ return 0;
+}
+
-+
-+
-+
-+static int configure_state(STATE_ENTRY_T *state_entry,LED_CONFIG_T *led_cfg)
++static int led_off( state_entry_t *pState )
+{
-+// int state = led_cfg->state;
-+ int i;
-+ int map1[2] ;
-+ int pos_map[2];
-+ int map2[2];
-+
-+ if((state_entry->mode = led_get_mode(led_cfg)) >= NUM_LED_MODES)
-+ {
-+ log_msg ("Error: Invalid mode in func configure_state\n");
-+ return -1;
-+ }
-+
-+ state_entry->handler = led_mode_handler[state_entry->mode];
-+
-+
-+ if(led_get_map(led_cfg,pos_map,map1,map2))
-+ {
-+ log_msg ("Error: gpio number out of range\n");
-+ return -1;
-+ }
-+
-+ assign_map(state_entry->map1,map1);
-+ assign_map(state_entry->map2,map2);
-+ state_entry->led = get_led(pos_map);
-+
-+ /* Check if the state requires timer */
-+ if(REQUIRES_TIMER(state_entry->mode))
-+ {
-+ state_entry->timer_running = 0;
-+ state_entry->param1 = led_cfg->param1;
-+ state_entry->param2 = led_cfg->param2;
-+ led_assign_timer(state_entry);
-+ }
-+
-+ /* enable gpio pins */
-+ for(i = 0;i<led_cfg->gpio_num;i++)
-+ {
-+ int value;
-+ int index;
-+ int pos;
-+ avalanche_gpio_ctrl (led_cfg->gpio[i],GPIO_PIN,GPIO_OUTPUT_PIN);
-+
-+ /* Turn off the led */
-+ index = led_cfg->gpio[i]/32;
-+ pos = led_cfg->gpio[i] % 32;
-+ value = (gpio_offstate_map[index] & (1 << pos))?1:0;
-+ avalanche_gpio_out_bit(led_cfg->gpio[i],value);
-+ }
-+
-+ return 0;
++ if( led_arr[pState->led].led == NULL)
++ return -1;
++ led_arr[pState->led].led->offfunc( led_arr[pState->led].led->param);
++ return 0;
+}
+
-+
-+static void free_all_states(void)
++static void board_led_link_up( state_entry_t *pState )
+{
-+ int module_id;
-+
-+ for(module_id = 0; module_id < MAX_MODULE_ENTRIES; module_id++)
-+ {
-+ if(modules[module_id])
-+ {
-+ int i;
-+ for(i = 0; i< MAX_MODULE_INSTANCES; i++)
-+ {
-+ MODULE_INSTANCE_T *module_instance = modules[module_id]->module_instance[i];
-+
-+ if(module_instance)
-+ {
-+ int state_id;
-+
-+ for(state_id =0; state_id < MAX_STATE_ENTRIES; state_id++)
-+ {
-+ STATE_ENTRY_T *state= module_instance->states[state_id];
-+
-+ if(state)
-+ {
-+ if(state->os_timer)
-+ os_timer_delete(state->os_timer);
-+
-+ os_free(state);
-+ module_instance->states[state_id] = NULL;
-+ }
-+
-+ }
-+ }
-+
-+ }
-+ os_free(modules[module_id]->name);
-+ os_free(modules[module_id]);
-+ modules[module_id] = NULL;
-+ }
-+ }
++ led_arr[pState->led].state = LED_ON;
++ if( led_arr[pState->led].timer_running == 0 )
++ led_on(pState);
++ return;
+}
+
-+/***********************************HAL APIS************************************/
-+
-+/**************************************************************************
-+ * FUNCTION NAME : avalanche_led_hal_init
-+ **************************************************************************
-+ * DESCRIPTION :
-+ * The function initializes led hal module
-+ *
-+ * RETURNS :
-+ * 0 on Success
-+ * Negative value on Error
-+ ***************************************************************************/
-+
-+
-+int avalanche_led_hal_init (int *gpio_off_value, int num_gpio_pins)
++static void board_led_link_down( state_entry_t *pState )
+{
-+ //int i;
-+
-+ num_gpios = num_gpio_pins + 4;
-+ assign_map(gpio_offstate_map, gpio_off_value);
-+
-+ MUTEX_INIT (led_lock);
-+
-+ /* initialize led state function handlers */
-+ led_mode_handler[LED_ON] = led_on;
-+ led_mode_handler[LED_OFF] = led_off;
-+ led_mode_handler[LED_ONESHOT_ON] = led_oneshot_on;
-+ led_mode_handler[LED_ONESHOT_OFF] = led_oneshot_off;
-+ led_mode_handler[LED_FLASH] = led_flash;
-+
-+ return 0;
++ led_arr[pState->led].state = LED_OFF;
++ if( led_arr[pState->led].timer_running == 0 )
++ led_off(pState);
++ return;
+}
+
-+
-+/**************************************************************************
-+ * FUNCTION NAME : avalanche_led_config_set
-+ **************************************************************************
-+ * DESCRIPTION :
-+ * The function configures LED state object
-+ *
-+ * RETURNS :
-+ * 0 on Success
-+ * Negative value on Error
-+ ***************************************************************************/
-+
-+int avalanche_led_config_set(LED_CONFIG_T * led_cfg)
++static void add_led_timer(state_entry_t *pState)
+{
-+ MODULE_INSTANCE_T *module;
-+ MUTEX_GET (led_lock);
-+ module = get_module (led_cfg->name, led_cfg->instance);
-+
-+ if (!module)
-+ goto config_failed;
-+
-+ if (led_cfg->state < MAX_STATE_ENTRIES)
-+ {
-+ int state = led_cfg->state;
-+
-+ if (!(module->states[state]))
-+ {
-+ module->states[state] = led_malloc (sizeof (STATE_ENTRY_T));
-+ }
-+
-+ if (!(module->states[state]))
-+ goto config_failed;
-+
-+ module->states[state]->module_id = module->module_id;
-+
-+ if(configure_state(module->states[state],led_cfg))
-+ {
-+ os_free(module->states[state]);
-+ module->states[state] = NULL;
-+ goto config_failed;
-+ }
-+
-+ }
-+ else
-+ {
-+ log_msg ("ERROR:State Count exceeded\n");
-+ goto config_failed;
-+ }
-+
-+ MUTEX_RELEASE (led_lock);
-+ return 0;
-+
-+ config_failed:
-+
-+ MUTEX_RELEASE (led_lock);
-+ return -1;
-+
++ led_arr[pState->led].pTimer->expires = jiffies + HZ*(pState->param)/1000;
++ led_arr[pState->led].param = pState->param;
++ led_arr[pState->led].pTimer->data = pState;
++ add_timer (led_arr[pState->led].pTimer);
+}
+
-+/**************************************************************************
-+ * FUNCTION NAME : avalanche_led_register
-+ **************************************************************************
-+ * DESCRIPTION :
-+ * The function creates handle to the given module and returns it.
-+ *
-+ * RETURNS :
-+ * Handle to the module instance on success.
-+ * NULL on failure.
-+ ***************************************************************************/
-+
-+void *avalanche_led_register (const char *mod_name, int instance)
++static void board_led_activity_on(state_entry_t *pState)
+{
-+ void *p;
-+ MUTEX_GET (led_lock);
-+ p = (void *)get_module ((char *)mod_name, instance);
-+ MUTEX_RELEASE (led_lock);
-+ return p;
++ if(led_arr[pState->led].timer_running == 0)
++ {
++ led_on(pState);
++ add_led_timer(pState);
++ led_arr[pState->led].timer_running = 1;
++ led_arr[pState->led].state = LED_BLINK_UP;
++ }
++ else if( led_arr[pState->led].timer_running > 0xF0)
++ {
++ led_arr[pState->led].state = LED_BLINK_UP;
++ led_arr[pState->led].pTimer->expires = jiffies + HZ*(pState->param)/1000;
++ led_arr[pState->led].param = pState->param;
++ led_arr[pState->led].pTimer->data = pState;
++ }
++ return;
+}
+
-+
-+/**************************************************************************
-+ * FUNCTION NAME : avalanche_led_action
-+ **************************************************************************
-+ * DESCRIPTION :
-+ * The function triggers action on LED
-+ *
-+ ***************************************************************************/
-+
-+void avalanche_led_action (void *module, int state_id)
++static void board_led_activity_off(state_entry_t *pState)
+{
-+
-+ MUTEX_GET (led_lock);
-+ if (module && (state_id < MAX_STATE_ENTRIES))
-+ {
-+
-+ STATE_ENTRY_T *state =
-+ ((MODULE_INSTANCE_T *) (module))->states[state_id];
-+ if (state)
-+ {
-+ state->handler (state);
-+ }
-+ }
-+ MUTEX_RELEASE (led_lock);
-+ return;
++ if(led_arr[pState->led].timer_running == 0)
++ {
++ led_off(pState);
++ add_led_timer(pState);
++ led_arr[pState->led].timer_running = 1;
++ led_arr[pState->led].state = LED_BLINK_UP;
++ }
++ else if( led_arr[pState->led].timer_running > 0xF0)
++ {
++ led_arr[pState->led].state = LED_BLINK_UP;
++ led_arr[pState->led].pTimer->expires = jiffies + HZ*(pState->param)/1000;
++ led_arr[pState->led].param = pState->param;
++ led_arr[pState->led].pTimer->data = pState;
++ }
++ return;
+}
+
-+
-+/**************************************************************************
-+ * FUNCTION NAME : avalanche_led_unregister
-+ **************************************************************************
-+ * DESCRIPTION :
-+ * The function unregisters the module
-+ *
-+ * RETURNS :
-+ * 0 on Success
-+ * Negative value on Error
-+ ***************************************************************************/
-+
-+int avalanche_led_unregister (void *mod_inst)
++static void board_led_link_flash(state_entry_t *pState)
+{
-+
-+ return 0;
++ if(led_on(pState))
++ return;
++ if(led_arr[pState->led].timer_running == 0)
++ add_led_timer(pState);
++ else
++ led_arr[pState->led].param = pState->param;
++ led_arr[pState->led].timer_running = 0xFF;
++ led_arr[pState->led].state = LED_FLASH;
++ return;
+}
+
-+
-+/**************************************************************************
-+ * FUNCTION NAME : led_free_all
-+ **************************************************************************
-+ * DESCRIPTION :
-+ * The function frees the memory allocated for holding state
-+ * configuration data
-+ *
-+ ***************************************************************************/
-+
-+void avalanche_led_free_all()
++static void led_timer_func(unsigned long data)
+{
-+ free_all_states();
++ state_entry_t *pState = NULL;
++ mod_entry_t *pMod = NULL;
++ unsigned int flags;
++
++ spin_lock_irqsave(&config_lock, flags);
++
++ pState = (state_entry_t *)data;
++
++ if( led_arr[pState->led].state == LED_BLINK_DOWN )
++ {
++ led_arr[pState->led].timer_running = 0;
++ if( pState->mode == 2 )
++ led_arr[pState->led].state = LED_OFF;
++ else
++ led_arr[pState->led].state = LED_ON;
++ }
++ else if( led_arr[pState->led].state == LED_BLINK_UP )
++ {
++ led_arr[pState->led].pTimer->expires = jiffies + HZ*(led_arr[pState->led].param)/1000;
++ led_arr[pState->led].pTimer->data = pState;
++ add_timer (led_arr[pState->led].pTimer);
++ if( pState->mode == 2 )
++ {
++ led_off(pState);
++ led_arr[pState->led].state = LED_BLINK_DOWN;
++ }
++ else
++ {
++ led_on(pState);
++ led_arr[pState->led].state = LED_BLINK_DOWN;
++ }
++ led_arr[pState->led].timer_running = 1;
++ }
++ else if( led_arr[pState->led].state == LED_FLASH )
++ {
++ led_arr[pState->led].pTimer->expires = jiffies + HZ*(led_arr[pState->led].param)/1000;
++ led_arr[pState->led].pTimer->data = pState;
++ add_timer (led_arr[pState->led].pTimer);
++
++ if( led_arr[pState->led].timer_running == 0xFF )
++ {
++ led_off(pState);
++ led_arr[pState->led].timer_running--;
++ }
++ else
++ {
++ led_on(pState);
++ led_arr[pState->led].timer_running++;
++ }
++ spin_unlock_irqrestore(&config_lock, flags);
++ return;
++ }
++ else if(led_arr[pState->led].state == LED_OFF)
++ {
++ led_off(pState);
++ led_arr[pState->led].timer_running = 0;
++ }
++ else if( led_arr[pState->led].state == LED_ON )
++ {
++ led_on(pState);
++ led_arr[pState->led].timer_running = 0;
++ }
++ spin_unlock_irqrestore(&config_lock, flags);
++ return;
+}
-+
-+/**************************************************************************
-+ * FUNCTION NAME : avalanche_led_hal_exit
-+ **************************************************************************
-+ * DESCRIPTION :
-+ * The function releases all the allocated memory
-+ *
-+ ***************************************************************************/
-+
-+void avalanche_led_hal_exit ()
++/************wwzh*****************/
++#if 0
++/************end *****************/
++static ssize_t proc_read_led_fops(struct file *filp,
++ char *buf,size_t count , loff_t *offp)
+{
-+ free_all_states();
++ char * pdata = NULL;
++ int i = 0, j = 0, len = 0, totallen = 0;
++ char line[255];
++
++ if( *offp != 0 )
++ return 0;
++
++ pdata = buf;
++ len += sprintf(line,"LEDS Registered for use are:");
++ for( i = 0; i< MAX_LED_ID; i++)
++ if( led_arr[i].led != NULL )
++ len += sprintf(&line[len]," %d ", i );
++ line[len++] = '\n';
++
++ copy_to_user(pdata, line,len );
++ pdata += len;
++ totallen += len;
++ len = 0;
++ len = sprintf(line,"USER MODULE INFORMATION:\n");
++ copy_to_user(pdata, line,len );
++ pdata += len;
++ totallen += len;
++ len = 0;
++ for( i = 0; i< MAX_MOD_ID; i++)
++ {
++ if( modArr[i] != NULL )
++ {
++ len = sprintf(line," Module ID = %d \n" , i);
++ copy_to_user(pdata, line,len );
++ pdata += len;
++ totallen += len;
++ len = 0;
++ for( j = 0; j < MAX_STATE_ID; j++)
++ {
++ if( modArr[i]->states[j] != NULL)
++ {
++ len = sprintf(line ,
++ " State = %d , Led = %d," , j , modArr[i]->states[j]->led);
++ copy_to_user(pdata, line,len );
++ pdata += len;
++ totallen += len;
++
++ len = 0;
++ switch( modArr[i]->states[j]->mode )
++ {
++ case 1:
++ len = sprintf(line ," Mode = OFF\n");
++ break;
++ case 2:
++ len = sprintf(line ," Mode = BLINK_ON , On Time(ms) = %d\n" ,
++ (unsigned int)modArr[i]->states[j]->param);
++ break;
++ case 3:
++ len = sprintf(line ," Mode = BLINK_OFF , Off Time(ms) = %d\n" ,
++ (unsigned int)modArr[i]->states[j]->param);
++ break;
++ case 4:
++ len = sprintf(line ," Mode = ON \n");
++ break;
++ case 5:
++ len = sprintf(line ," Mode = FLASH , Time Period(ms) = %d\n" ,
++ (unsigned int)modArr[i]->states[j]->param);
++ break;
++ default:
++ break;
++
++ }
++ copy_to_user(pdata, line,len );
++ pdata += len;
++ totallen += len;
++
++ len = 0;
++ }
++ }
++ }
++ }
++ /* Return with configuration information for LEDs */
++ *offp = totallen;
++ return totallen;
+}
-+
-+/*****************************************************************************
-+ * FUNCTION NAME : avalanche_led_config_get
-+ *****************************************************************************
-+ * DESCRIPTION :
-+ * The function returns configuration information corresponding to module
-+ * state.
-+ *
-+ * RETURNS :
-+ * 0 on Success
-+ * Negative value on Error
-+ ***************************************************************************/
-+int avalanche_led_config_get(LED_CONFIG_T *led_cfg,int module_id,int instance, int state_id)
++static ssize_t proc_write_led_fops(struct file *filp,const char *buffer,
++ size_t count , loff_t *offp)
+{
-+ if(module_id == -1)
-+ {
-+ /* The module info is passed through field of led_cfg */
-+ MODULE_INSTANCE_T *mod = get_module (led_cfg->name, instance);
-+ if(mod)
-+ module_id = mod->module_id;
-+
-+ }
-+ if(module_id >= MAX_MODULE_ENTRIES || module_id < 0)
-+ return -1;
-+
-+ if(state_id >= MAX_STATE_ENTRIES || module_id < 0)
-+ return -1;
-+
-+ if(instance >= MAX_MODULE_INSTANCES || module_id < 0)
-+ return -1;
-+
-+ if(modules[module_id])
-+ {
-+ MODULE_INSTANCE_T *module = modules[module_id]->module_instance[instance];
-+ if(module)
-+ {
-+ STATE_ENTRY_T *state = module->states[state_id];
-+ if(state)
-+ {
-+ int i;
-+ LED_OBJ_T *led;
-+ strcpy(led_cfg->name, modules[module_id]->name);
-+ led_cfg->state = state_id;
-+ led_cfg->instance = instance;
-+ led_cfg->param1 = state->param1;
-+ led_cfg->param2 = state->param2;
-+ led_cfg->mode[0] = state->mode;
-+ led = state->led;
-+
-+ /* needs to be modified for multi-pin leds */
-+ for(i = 0;i < num_gpios && !(led->pos_map[i/32] & (1 << i)); i++);
-+
-+ led_cfg->gpio[0] = i;
-+ led_cfg->gpio_num = 1;
-+
-+ return 0;
-+ }
-+ }
-+ }
-+
-+ return -1;
++ char *pdata = NULL, *ptemp = NULL;
++ char line[10],temp[10];
++ int i = 0;
++ int mod = 0xFFFF , state = 0xFFFF;
++ int flag = 0;
++
++ /* Check if this write is for configuring stuff */
++ if( *(int *)(buffer) == 0xFFEEDDCC )
++ {
++ printk("<1>proc write:Calling Configuration\n");
++ config_led((unsigned long)(buffer + sizeof(int)) );
++ return count;
++ }
++
++ if( count >= 10)
++ {
++ printk("<1>proc write:Input too long,max length = %d\n",10);
++ return count;
++ }
++ memset( temp, 0x00 , 10);
++ memset( line, 0x00 , 10);
++ copy_from_user(line,buffer,count);
++ line[count] = 0x00;
++ pdata = line;
++ ptemp = temp;
++ while( flag == 0)
++ {
++ if( i > 10 )
++ break;
++ if( ((*pdata) >= '0' ) && ((*pdata) <= '9') )
++ {
++ *ptemp = *pdata ;
++ ptemp++;
++ }
++ else if( (*pdata) == ',' )
++ {
++ *ptemp = 0x00;
++ flag = 1;
++ }
++ pdata++;
++ i++;
++ };
++ if( flag == 1)
++ mod = led_atoi( temp);
++ else
++ return count;
++
++ ptemp = temp;
++ *ptemp = 0x00;
++ flag = 0;
++ while( flag == 0)
++ {
++ if( i > 10 )
++ break;
++ if( ((*pdata) >= '0' ) && ((*pdata) <= '9') )
++ {
++ *ptemp = *pdata ;
++ ptemp++;
++ }
++ else if( (*pdata) == 0x00 )
++ {
++ *ptemp = 0x00;
++ flag = 1;
++ }
++ pdata++;
++ i++;
++ };
++ if( flag == 1)
++ state = led_atoi( temp);
++ else
++ return count;
++ if( (mod == 0xFFFF) || (state == 0xFFFF))
++ return count;
++ else
++ led_operation( mod , state );
++ return count;
+}
-diff -urN kernel-old/drivers/char/avalanche_led/led_hal.h kernel-current/drivers/char/avalanche_led/led_hal.h
---- kernel-old/drivers/char/avalanche_led/led_hal.h 1970-01-01 01:00:00.000000000 +0100
-+++ kernel-current/drivers/char/avalanche_led/led_hal.h 2005-07-10 18:03:46.120957200 +0200
-@@ -0,0 +1,28 @@
-+/******************************************************************************
-+ * FILE PURPOSE: - LED HAL module Header
-+ ******************************************************************************
-+ * FILE NAME: led_hal.h
-+ *
-+ * DESCRIPTION: LED HAL API's.
-+ *
-+ * REVISION HISTORY:
-+ * 11 Oct 03 - PSP TII
-+ *
-+ * (C) Copyright 2002, Texas Instruments, Inc
-+ *******************************************************************************/
-+
-+#ifndef __LED_HAL__
-+#define __LED_HAL__
-+
-+/* Interface prototypes */
-+
-+int avalanche_led_hal_init (int *gpio_off_value, int num_gpio_pins);
-+int avalanche_led_config_set (LED_CONFIG_T * led_cfg);
-+int avalanche_led_config_get (LED_CONFIG_T *led_cfg,int module_id,int instance, int state);
-+void *avalanche_led_register (const char *module_name, int instance_num);
-+void avalanche_led_action (void *handle, int state_id);
-+int avalanche_led_unregister (void *handle);
-+void avalanche_led_free_all(void);
-+void avalanche_led_hal_exit (void);
-+
-+#endif /*__LED_HAL__ */
-diff -urN kernel-old/drivers/char/avalanche_led/led_platform.h kernel-current/drivers/char/avalanche_led/led_platform.h
---- kernel-old/drivers/char/avalanche_led/led_platform.h 1970-01-01 01:00:00.000000000 +0100
-+++ kernel-current/drivers/char/avalanche_led/led_platform.h 2005-07-10 18:03:46.120957200 +0200
-@@ -0,0 +1,117 @@
-+/******************************************************************************
-+ * FILE PURPOSE: - LED Platform specific Header file
-+ ******************************************************************************
-+ * FILE NAME: led_platform.h
-+ *
-+ * DESCRIPTION: Linux specific implementation for OS abstracted function calls
-+ * made by LED HAL module. This file has functions defined for
-+ * Memory allocation calls, Mutex calls, String and Timer
-+ * operations.
-+ *
-+ * REVISION HISTORY:
-+ * 11 Oct 03 - PSP TII
-+ *
-+ * (C) Copyright 2002, Texas Instruments, Inc
-+ *******************************************************************************/
-+
-+#ifndef __LED_PLATFORM__
-+#define __LED_PLATFORM__
-+
-+#include <linux/mm.h>
-+#include <linux/slab.h>
-+#include <asm/string.h>
-+#include <linux/param.h>
-+#include <linux/sched.h>
-+#include <linux/timer.h>
-+#include <linux/spinlock.h>
-+
+
-+#define os_malloc(x) kmalloc(x,GFP_KERNEL)
-+#define os_memset memset
-+#define os_free(x) kfree(x)
-+#define os_strcmp os_strcasecmp
-+#define os_strcpy strcpy
-+
-+#if defined(DEBUG)
-+#define log_msg printk
++/************wwzh*******************/
+#else
-+#define log_msg(x)
-+#endif
-+
-+/* defines for Mutex */
-+typedef struct {
-+ spinlock_t lock;
-+ int flags;
-+}OS_SPINLOCK_T;
-+
-+#define MUTEX_DECLARE(x) static OS_SPINLOCK_T x
-+#define MUTEX_INIT(x) x.lock = SPIN_LOCK_UNLOCKED
-+#define MUTEX_GET(x) spin_lock_irqsave(&x.lock, x.flags)
-+#define MUTEX_RELEASE(x) spin_unlock_irqrestore(&x.lock, x.flags)
-+
+
++#define TRUE 1
++#define FALSE 0
++#define FLICK_TIME (HZ*100/1000)
++static unsigned int wan_txrx_state = 0;
++static unsigned int wlan_txrx_state = 0;
+
-+/* String handling functions not defined in asm/string.h */
-+static __inline__ int os_strlen(char *str)
++void led_operation( int mod , int state)
+{
-+ int i;
-+ for(i=0;str[i];i++);
-+ return i;
-+}
-+
+
-+#define LOWER(x) ((x < 'a') ? (x - 'A' + 'a'):(x))
-+#define ISALPHA(x) ((( x >= 'a') && (x <= 'z')) || (( x >= 'A') && (x <= 'Z')))
-+#define COMP(x,y) ((x == y) || ((ISALPHA(x) && ISALPHA(y)) && (LOWER(x) == LOWER(y))))
-+
-+
-+static __inline__ int os_strcasecmp(char *str1, char *str2)
-+{
-+ int i;
-+
-+ for(i=0;str1[i] && str2[i];i++)
-+ {
-+ char x,y;
-+
-+ x = str1[i];
-+ y = str2[i];
-+
-+ if(!COMP(x,y))
-+ break;
-+ }
-+
-+ return(str1[i] || str2[i]);
-+}
-+
-+
-+
-+/* Functions for timer related operations */
-+static __inline__ void * os_timer_init(void (*func)(int))
-+{
-+ struct timer_list *ptimer;
-+ ptimer = (struct timer_list *) kmalloc(sizeof(struct timer_list),GFP_KERNEL);
-+ init_timer( ptimer );
-+ (void *)ptimer->function = (void *)func;
-+ return (void *)ptimer;
++ unsigned int flags;
++
++ spin_lock_irqsave(&config_lock, flags);
++
++ if( (mod >= MAX_MOD_ID) || ( state >= MAX_STATE_ID) )
++ {
++ spin_unlock_irqrestore(&config_lock, flags);
++ return;
++ }
++ if ( modArr[mod] == NULL )
++ {
++ spin_unlock_irqrestore(&config_lock, flags);
++ return;
++ }
++ if( modArr[mod]->states[state] == NULL )
++ {
++ spin_unlock_irqrestore(&config_lock, flags);
++ return;
++ }
++ /* Call the function handler */
++ modArr[mod]->states[state]->handler(modArr[mod]->states[state]);
++
++ spin_unlock_irqrestore(&config_lock, flags);
+}
+
-+static __inline__ int os_timer_add(void *timer_handle,int milisec,int arg)
++static void wan_led_func(unsigned long data)
+{
-+ struct timer_list *ptimer=timer_handle;
-+ ptimer->expires = ((HZ * milisec)/1000) + jiffies;
-+ ptimer->data = arg;
-+ add_timer(ptimer);
-+ return 0;
-+
++ if (wan_txrx_state == 0)
++ {
++ tnetd73xx_gpio_out(2, TRUE);
++ tnetd73xx_gpio_out(3, FALSE);
++ wan_txrx_state = 1;
++ }
++ else
++ {
++ tnetd73xx_gpio_out(2, FALSE);
++ tnetd73xx_gpio_out(3, FALSE);
++ wan_txrx_state = 0;
++ }
++ pWanTimer->expires = jiffies + FLICK_TIME;
++ add_timer(pWanTimer);
+}
-+
-+static __inline__ int os_timer_delete(void *timer_handle)
++//wwzh for wireless
++#if 0
++static void wlan_led_func(unsigned long data)
+{
-+ struct timer_list *ptimer=timer_handle;
-+ del_timer(ptimer);
-+ kfree(ptimer);
-+ return 0;
++ if (wlan_txrx_state == 0)
++ {
++ tnetd73xx_gpio_out(12, TRUE);
++ tnetd73xx_gpio_out(13, FALSE);
++ wlan_txrx_state = 1;
++ }
++ else
++ {
++ tnetd73xx_gpio_out(12, FALSE);
++ tnetd73xx_gpio_out(13, FALSE);
++ wlan_txrx_state = 0;
++
++ }
++ pWlanTimer->expires = jiffies + FLICK_TIME;
++ add_timer(pWlanTimer);
+}
++#endif
+
-+
-+#endif /* __LED_PLATFORM__ */
-diff -urN kernel-old/drivers/char/avalanche_led/led_wrapper.c kernel-current/drivers/char/avalanche_led/led_wrapper.c
---- kernel-old/drivers/char/avalanche_led/led_wrapper.c 1970-01-01 01:00:00.000000000 +0100
-+++ kernel-current/drivers/char/avalanche_led/led_wrapper.c 2005-07-10 18:25:14.657069936 +0200
-@@ -0,0 +1,561 @@
-+/******************************************************************************
-+ * FILE PURPOSE: - LED Wrapper file for DSL module support
-+ ******************************************************************************
-+ * FILE NAME: led_wrapper.c
-+ *
-+ * DESCRIPTION: LED Wrapper file for DSL module support
-+ * This is to provide backward compatibility to the ADSL module
-+ * using OLD LED driver. The numbers mapped for DSL LEDs in the
-+ * previous implementation is 3,4,5,6. Since these numbers overlap
-+ * with the existing numbering scheme, the following numbers need to
-+ * be used in the led configuration file - 32,33,34,35.
-+ *
-+ * (C) Copyright 2002, Texas Instruments, Inc
-+ *******************************************************************************/
-+#include <linux/config.h>
-+#include <linux/init.h>
-+#include <linux/module.h>
-+#include <asm/ar7/sangam.h>
-+#include "led_platform.h"
-+#include "led_config.h"
-+
-+#define BITS_PER_INT (8 * sizeof(int))
-+#define GPIOS_PER_INT BITS_PER_INT
-+#define GPIO_MAP_LEN ((MAX_GPIO_PIN_NUM + GPIOS_PER_INT -1)/GPIOS_PER_INT)
-+#define MODULE_MAP_LEN ((MAX_MODULE_ENTRIES + BITS_PER_INT -1)/BITS_PER_INT)
-+
-+
-+#define REQUIRES_TIMER(x) (x > 1)
-+
-+#define gpio_on(gpio) do \
-+ { \
-+ if(gpio >= 32 && adsl_led_objs[gpio - 32].onfunc) \
-+ adsl_led_objs[gpio - 32].onfunc(adsl_led_objs[gpio - 32].param);\
-+ } while(0)
-+
-+
-+
-+#define gpio_off(gpio) \
-+ do \
-+ { \
-+ if(gpio >= 32 && adsl_led_objs[gpio - 32].offfunc) \
-+ adsl_led_objs[gpio - 32].offfunc(adsl_led_objs[gpio - 32].param);\
-+ } while(0)
-+
-+
-+
-+
-+
-+
-+/********************TYPEDEFS***********************************************/
-+
-+typedef struct gpio_module
-+{
-+ volatile unsigned int *gpio_write_reg;
-+ volatile unsigned int *gpio_dir_reg;
-+ volatile unsigned int *gpio_mode_reg;
-+}GPIO_REGS_T;
-+
-+typedef struct {
-+ unsigned int gpio_id;
-+ unsigned int gpio_state;
-+ int module_map[MODULE_MAP_LEN];
-+}GPIO_OBJ_T;
-+
-+
-+typedef struct state_entry STATE_ENTRY_T;
-+
-+struct state_entry{
-+ unsigned int timer_running;
-+ STATE_ENTRY_T *next;
-+ void (*handler)(STATE_ENTRY_T *state);
-+ GPIO_OBJ_T *gpio;
-+ void *os_timer;
-+ unsigned int param;
-+ unsigned int module_id;
-+ unsigned int mode;
-+};
-+
-+
-+typedef struct module_instance{
-+ int module_id;
-+ int instance;
-+ STATE_ENTRY_T *states[MAX_STATE_ENTRIES];
-+}MODULE_INSTANCE_T;
-+
-+typedef struct module_entry{
-+ unsigned char *name;
-+ MODULE_INSTANCE_T *module_instance[MAX_MODULE_INSTANCES];
-+}MODULE_ENTRY_T;
-+
-+
-+
-+typedef struct led_reg{
-+ unsigned int param;
-+ void (*init)(unsigned long param);
-+ void (*onfunc)(unsigned long param);
-+ void (*offfunc)(unsigned long param);
-+}led_reg_t;
-+
-+
-+
-+/* Interface prototypes */
-+static int led_hal_init(GPIO_REGS_T gpio_mod, unsigned int *gpio_off_value,int num_gpio_pins);
-+static int avalanche_led_set_config(LED_CONFIG_T *led_cfg);
-+static void *avalanche_led_register(const char *module_name, int instance_num);
-+static int avalanche_led_action(void *handle,int state_id);
-+int avalanche_led_config_get (LED_CONFIG_T *led_cfg,int module_id,int instance, int state);
-+
-+led_reg_t adsl_led_objs[4];
-+MODULE_INSTANCE_T *dsl_mod = NULL;
-+static int gpio_off_state[GPIO_MAP_LEN] = AVALANCHE_GPIO_OFF_MAP;
-+
-+
-+
-+static unsigned int num_gpios;
-+static GPIO_OBJ_T *gpio_arr;
-+GPIO_REGS_T gpio_regs;
-+
-+/* GPIO OFF STATE */
-+static unsigned int gpio_off_val[GPIO_MAP_LEN];
-+
-+
-+MODULE_ENTRY_T *modules[MAX_MODULE_ENTRIES];
-+
-+/* LED handlers */
-+void (*led_mode_handler[NUM_LED_MODES])(STATE_ENTRY_T *state);
-+
-+
-+/******************static functions*****************************************/
-+static void *led_malloc(int n)
++void led_active(int mod, int state)
+{
-+ void *p;
-+ p=kmalloc(n,GFP_ATOMIC);
-+
-+ if(p)
-+ os_memset(p,0,n);
-+ return p;
++ unsigned int flags = 0;
++
++//printk("mod = %d state = %d\n", mod, state);
++ spin_lock_irqsave(&config_lock, flags);
++ if ((mod >= 5) || (state >= 5))
++ {
++ spin_unlock_irqrestore(&config_lock, flags);
++ return;
++ }
++
++ switch (mod)
++ {
++ case 2: /*system led */
++ sys_mod_state = state;
++ switch (state)
++ {
++ case 1:
++ break;
++ case 2: /*sys led flashing green */
++ tnetd73xx_gpio_out(4, FALSE);
++ tnetd73xx_gpio_out(5, TRUE);
++ tnetd73xx_gpio_out(8, TRUE);
++ break;
++ case 3: /*sys led solid green */
++ tnetd73xx_gpio_out(4, TRUE);
++ tnetd73xx_gpio_out(5, TRUE);
++ tnetd73xx_gpio_out(8, TRUE);
++
++ break;
++ case 4: /*sys fail red */
++ tnetd73xx_gpio_out(4, TRUE);
++ tnetd73xx_gpio_out(5, FALSE);
++ tnetd73xx_gpio_out(8, FALSE);
++ break;
++ default:
++ break;
++ }
++ break;
++ case 3: /*wan led */
++ wan_mod_state = state;
++ switch (state)
++ {
++ case 1: /*no wan interface*/
++ if (pWanTimer)
++ {
++ del_timer(pWanTimer);
++ kfree(pWanTimer);
++ pWanTimer = NULL;
++ }
++ tnetd73xx_gpio_out(2, FALSE);
++ tnetd73xx_gpio_out(3, FALSE);
++ break;
++ case 2: /*wan connected */
++ if (pWanTimer)
++ {
++ del_timer(pWanTimer);
++ kfree(pWanTimer);
++ pWanTimer = NULL;
++ }
++ tnetd73xx_gpio_out(2, TRUE);
++ tnetd73xx_gpio_out(3, FALSE);
++ break;
++ case 3: /*rx/tx activity */
++ if (pWanTimer != NULL)
++ break;
++
++ pWanTimer = kmalloc(sizeof(struct timer_list), GFP_KERNEL);
++ init_timer(pWanTimer);
++
++ pWanTimer->function = wan_led_func;
++ pWanTimer->data = 0;
++ pWanTimer->expires = jiffies + FLICK_TIME;
++ tnetd73xx_gpio_out(2, FALSE);
++ tnetd73xx_gpio_out(3, FALSE);
++ wan_txrx_state = 0;
++ add_timer(pWanTimer);
++
++ break;
++ case 4: /*no ipaddress */
++ if (pWanTimer)
++ {
++ del_timer(pWanTimer);
++ kfree(pWanTimer);
++ pWanTimer = NULL;
++ }
++ tnetd73xx_gpio_out(2, FALSE);
++ tnetd73xx_gpio_out(3, TRUE);
++ break;
++ default:
++ if (pWanTimer)
++ {
++ del_timer(pWanTimer);
++ kfree(pWanTimer);
++ pWanTimer = NULL;
++ }
++ break;
++ }
++ break;
++ //wwzh for wireless
++ #if 0
++ case 4: /*wlan led */
++ wlan_mod_state = state;
++ switch (state)
++ {
++ case 1: /* wlan off */
++ if (pWlanTimer)
++ {
++ del_timer(pWlanTimer);
++ kfree(pWlanTimer);
++ pWlanTimer = NULL;
++ }
++ tnetd73xx_gpio_out(12, FALSE);
++ tnetd73xx_gpio_out(13, FALSE);
++ break;
++ case 2: /* wlan ready */
++ if (pWlanTimer)
++ {
++ del_timer(pWlanTimer);
++ kfree(pWlanTimer);
++ pWlanTimer = NULL;
++ }
++ tnetd73xx_gpio_out(12, TRUE);
++ tnetd73xx_gpio_out(13, FALSE);
++ break;
++ case 3: /* wlan rx/tx activity */
++ if (pWlanTimer != NULL)
++ break;
++
++ pWlanTimer = kmalloc(sizeof(struct timer_list), GFP_KERNEL);
++ init_timer(pWlanTimer);
++
++ pWlanTimer->function = wlan_led_func;
++ pWlanTimer->data = 0;
++ pWlanTimer->expires = jiffies + FLICK_TIME;
++ tnetd73xx_gpio_out(12, FALSE);
++ tnetd73xx_gpio_out(13, FALSE);
++ wlan_txrx_state = 0;
++ add_timer(pWlanTimer);
++
++ break;
++ default:
++ if (pWlanTimer)
++ {
++ del_timer(pWlanTimer);
++ kfree(pWlanTimer);
++ pWlanTimer = NULL;
++ }
++
++ break;
++ }
++ break;
++ #endif //for wireless
++ default:
++ break;
++ }
++ spin_unlock_irqrestore(&config_lock, flags);
+}
-+
-+static void free_state(STATE_ENTRY_T *state)
++static ssize_t proc_read_led_fops(struct file *filp,
++ char *buf,size_t count , loff_t *offp)
+{
-+
-+ STATE_ENTRY_T *prev = NULL;
-+ STATE_ENTRY_T *curr = NULL ;
-+ while(curr != state)
-+ {
-+ curr = state;
-+ prev = NULL;
-+
-+ while(curr->next != NULL)
-+ {
-+ prev = curr;
-+ curr = curr->next;
-+ }
-+
-+ os_free(curr);
-+ if(prev)
-+ {
-+ prev->next = NULL;
-+ }
-+
-+ }
-+
++ char *pdata = NULL;
++ int i = 0, j = 0, len = 0, totallen = 0;
++ char line[255];
++
++ if (*offp != 0)
++ return 0;
++ pdata = buf;
++ len = sprintf(line, "USER MODULE INFORMATION:\n");
++ copy_to_user(pdata, line, len);
++ pdata += len;
++ totallen += len;
++ len = 0;
++
++ //*******add Module 1 , this Module is ADSL ********/
++ for (i = 0; i < MAX_MOD_ID; i++)
++ {
++ if (modArr[i] != NULL)
++ {
++ len = sprintf(line, " Module ID = %d\n", i);
++ copy_to_user(pdata, line, len);
++ pdata += len;
++ totallen += len;
++ len = 0;
++ for(j = 0; j < MAX_STATE_ID; j++)
++ {
++ if (modArr[i]->states[j] != NULL)
++ {
++ len = sprintf(line, "State =%d, Led = %d,", j, modArr[i]->states[j]->led);
++ copy_to_user(pdata, line, len);
++ pdata += len;
++ totallen += len;
++ len = 0;
++ switch(modArr[i]->states[j]->mode)
++ {
++ case 1:
++ len = sprintf(line, "Mode = OFF\n");
++ break;
++ case 2:
++ len = sprintf(line, "Mode = BLINK_ON, On Time(ms) = %d\n", (unsigned int)modArr[i]->states[j]->param);
++ break;
++ case 3:
++ len = sprintf(line, "Mode = BLINK_OFF, Off Time(ms) = %d\n", (unsigned int)modArr[i]->states[j]->param);
++ break;
++ case 4:
++ len = sprintf(line, "Mode = On\n");
++ break;
++ case 5:
++ len = sprintf(line, "Mode = FLASH, Time Period(ms) = %d\n", (unsigned int)modArr[i]->states[j]->param);
++ break;
++ default:
++ break;
++ }
++ copy_to_user(pdata, line, len);
++ pdata += len;
++ totallen += len;
++ len = 0;
++ }
++ }
++ }
++
++ }
++
++ len = sprintf(line, "Module ID = 2(system led)\n");
++ copy_to_user(pdata, line, len);
++ pdata += len;
++ totallen += len;
++ len = 0;
++ switch(sys_mod_state)
++ {
++ case 1:
++ len = sprintf(line, "State = OFF\n");
++ break;
++ case 2:
++ len = sprintf(line, "State = Booting\n");
++ break;
++ case 3:
++ len = sprintf(line, "State = System Ready\n");
++ break;
++ case 4:
++ len = sprintf(line, "State = System Failure\n");
++ break;
++ default:
++ break;
++ }
++ copy_to_user(pdata, line, len);
++ pdata += len;
++ totallen += len;
++ len = 0;
++
++ len = sprintf(line, "Module ID = 3(WAN led)\n");
++ copy_to_user(pdata, line, len);
++ pdata += len;
++ totallen += len;
++ len = 0;
++ switch(wan_mod_state)
++ {
++ case 1:
++ len = sprintf(line, "State = OFF\n");
++ break;
++ case 2:
++ len = sprintf(line, "State = Wan Connected\n");
++ break;
++ case 3:
++ len = sprintf(line, "State = Wan Tx/Rx Activity\n");
++ break;
++ case 4:
++ len = sprintf(line, "State = Wan Connect Failure\n");
++ break;
++ default:
++ break;
++ }
++ copy_to_user(pdata, line, len);
++ pdata += len;
++ totallen += len;
++ len = 0;
++
++//wwzh for wireless
++#if 0
++ len = sprintf(line, "Module ID = 4(WLAN led)\n");
++ copy_to_user(pdata, line, len);
++ pdata += len;
++ totallen += len;
++ len = 0;
++ switch(wlan_mod_state)
++ {
++ case 1:
++ len = sprintf(line, "State = OFF\n");
++ break;
++ case 2:
++ len = sprintf(line, "State = wlan Ready\n");
++ break;
++ case 3:
++ len = sprintf(line, "State = wlan rx/tx activity\n");
++ break;
++ default:
++ break;
++ }
++ copy_to_user(pdata, line, len);
++ pdata += len;
++ totallen += len;
++ len = 0;
++#endif //for wireless
++
++ *offp = totallen;
++ return totallen;
+}
-+
-+static MODULE_INSTANCE_T* get_module(char * name,int instance)
++static ssize_t proc_write_led_fops(struct file *filp,const char *buffer,
++ size_t count , loff_t *offp)
+{
-+ int module_id;
-+ MODULE_INSTANCE_T *mod_inst;
-+
-+ if(instance >= MAX_MODULE_INSTANCES)
-+ return NULL;
-+
-+ for(module_id=0;module_id <MAX_MODULE_ENTRIES;module_id++)
-+ {
-+ if(modules[module_id] && !os_strcmp(name,modules[module_id]->name))
-+ break;
-+ }
-+
-+ if(module_id == MAX_MODULE_ENTRIES)
-+ {
-+ for(module_id = 0; (module_id < MAX_MODULE_ENTRIES) && modules[module_id] ; module_id++);
-+
-+ if(module_id < MAX_MODULE_ENTRIES)
-+ {
-+ modules[module_id]=led_malloc(sizeof(MODULE_ENTRY_T));
-+ modules[module_id]->name = led_malloc(os_strlen(name));
-+ os_strcpy(modules[module_id]->name,name);
-+ }
-+ else
-+ {
-+ log_msg("ERROR:Module Count exceeded\n");
-+ return NULL;
-+ }
-+ }
-+
-+ if(!modules[module_id]->module_instance[instance])
-+ modules[module_id]->module_instance[instance] = led_malloc(sizeof(MODULE_INSTANCE_T));
-+
-+ mod_inst = modules[module_id]->module_instance[instance];
-+ mod_inst->module_id = module_id;
-+ mod_inst->instance = instance;
-+
-+ return mod_inst;
++ char *pdata = NULL, *ptemp = NULL;
++ char line[10], temp[10];
++ int i = 0;
++ int mod = 0xffff, state = 0xffff;
++ int flag = 0;
++
++ /* Check if this write is for configuring ADSL */
++ if( *(int *)(buffer) == 0xFFEEDDCC )
++ {
++ printk("<1>proc write:Calling Configuration\n");
++ config_led((unsigned long)(buffer + sizeof(int)) );
++ return count;
++ }
++
++ if (count > 10)
++ {
++ printk("<1> proc write: Input too long, max length = 10\n");
++ return count;
++ }
++ memset(temp, 0x00, 10);
++ memset(line, 0x00, 10);
++ copy_from_user(line, buffer, count);
++ line[count] = 0x00;
++ pdata = line;
++ ptemp = temp;
++
++ while (flag == 0)
++ {
++ if (i > 10)
++ break;
++ if (((*pdata) >= '0') && ((*pdata) <= '9'))
++ {
++ *ptemp = *pdata;
++ ptemp++;
++ }
++ else if ((*pdata) == ',')
++ {
++ *ptemp = 0x00;
++ flag = 1;
++ }
++ pdata++;
++ i++;
++ }
++ if (flag == 1)
++ mod = led_atoi(temp);
++ else
++ return count;
++
++ ptemp = temp;
++ *ptemp = 0x00;
++ flag = 0;
++
++ while(flag == 0)
++ {
++ if (i > 10)
++ break;
++ if (((*pdata) >= '0') && ((*pdata) <= '9'))
++ {
++ *ptemp = *pdata;
++ ptemp++;
++ }
++ else if ((*pdata) == 0x00)
++ {
++ *ptemp = 0x00;
++ flag = 1;
++ }
++ pdata++;
++ i++;
++ }
++ if (flag == 1)
++ state = led_atoi(temp);
++ else
++ return count;
++ if ((mod == 0xFFFF) || (state == 0xFFFF))
++ return count;
++ else
++ {
++ if (mod != 4)
++ led_active(mod, state);
++ else
++ led_operation(mod, state);
++ }
++ return 1;
+}
-+
-+
-+static void led_timer_func(int arg)
++#endif
++/************end *******************/
++static int config_led(unsigned long y)
+{
-+ STATE_ENTRY_T *state = (STATE_ENTRY_T *) arg;
-+ GPIO_OBJ_T *gpio;
++ config_elem_t *pcfg = NULL;
++ char *pdata = NULL;
++ int i;
++ int length = 0 , number = 0;
++ unsigned int flags;
++
++ spin_lock_irqsave(&config_lock, flags);
+
++ /* ioctl to configure */
++ length = *((int*)y);
++ pdata = (char *)y + sizeof(int);
++ number = (length - sizeof(int))/sizeof(config_elem_t);
++ pcfg = (config_elem_t *)(pdata);
+
-+ gpio = state->gpio;
++ /* Check if an earlier configuration exists IF yes free it up */
++ free_memory();
+
-+ switch(gpio->gpio_state)
++ for ( i = 0 ; i < number ; i++ )
+ {
-+ case LED_ONESHOT_ON:
-+ gpio->gpio_state = LED_OFF;
-+ gpio_off(gpio->gpio_id);
-+ break;
-+
-+ case LED_ONESHOT_OFF:
-+ gpio->gpio_state = LED_ON;
-+ gpio_on(gpio->gpio_id);
-+ break;
-+
-+ case LED_FLASH:
-+ {
-+
-+ if(state->timer_running == 1)
-+ {
-+ state->timer_running = 2;
-+ gpio_off(gpio->gpio_id);
-+ os_timer_add(state->os_timer,(state->param >> 16),(int)state);
-+ }
-+ else
-+ {
-+ state->timer_running = 1;
-+ gpio_on(gpio->gpio_id);
-+ os_timer_add(state->os_timer, (state->param & 0xffff),(int)state);
-+ }
-+ return;
-+ }
-+ default:
-+ break;
++ /* If no structure has been allocated for the module do so */
++ if ( modArr[pcfg->name] == NULL )
++ {
++ printk("<1>module = %d\n",pcfg->name);
++ if( pcfg->name >= MAX_MOD_ID)
++ {
++ printk("<1>Exiting Configuration: Module ID too large %d\n",pcfg->name);
++ free_memory();
++ spin_unlock_irqrestore(&config_lock, flags);
++ return -1;
++ }
++ modArr[pcfg->name] = kmalloc(sizeof(mod_entry_t),GFP_KERNEL);
++ if(modArr[pcfg->name] == NULL)
++ {
++ printk("<1>Exiting Configuration: Error in allocating memory\n");
++ free_memory();
++ spin_unlock_irqrestore(&config_lock, flags);
++ return -1;
++ }
++ memset( modArr[pcfg->name], 0x00, sizeof(mod_entry_t));
++ }
+
++ /* if no structure is allocated previously for this state
++ allocate a structure, if it's already there fill it up */
++ if( modArr[pcfg->name]->states[pcfg->state] == NULL)
++ {
++ printk("<1>STATE = %d\n",pcfg->state);
++ if( pcfg->state >= MAX_STATE_ID)
++ {
++ printk("<1>Exiting Configuration: State ID too large\n");
++ free_memory();
++ spin_unlock_irqrestore(&config_lock, flags);
++ return -1;
++ }
++ modArr[pcfg->name]->states[pcfg->state] =
++ kmalloc(sizeof(state_entry_t),GFP_KERNEL);
++ if( modArr[pcfg->name]->states[pcfg->state] == NULL)
++ {
++ free_memory();
++ spin_unlock_irqrestore(&config_lock, flags);
++ return -1;
++ }
++ memset( modArr[pcfg->name]->states[pcfg->state], 0x00, sizeof(state_entry_t));
++ }
++ /* Fill up the fields of the state */
++ if( pcfg->led >= MAX_LED_ID)
++ {
++ printk("<1>led = %d\n",pcfg->led);
++ free_memory();
++ spin_unlock_irqrestore(&config_lock, flags);
++ return -1;
++ }
++ modArr[pcfg->name]->states[pcfg->state]->led = pcfg->led;
++ modArr[pcfg->name]->states[pcfg->state]->mode = pcfg->mode;
++ modArr[pcfg->name]->states[pcfg->state]->param = pcfg->param;
++ switch(pcfg->mode)
++ {
++ case 1:
++ modArr[pcfg->name]->states[pcfg->state]->handler = board_led_link_down;
++ break;
++ case 2:
++ case 3:
++ case 5:
++ if( pcfg->mode == 2 )
++ modArr[pcfg->name]->states[pcfg->state]->handler = board_led_activity_on;
++ else if( pcfg->mode == 3)
++ modArr[pcfg->name]->states[pcfg->state]->handler = board_led_activity_off;
++ else
++ modArr[pcfg->name]->states[pcfg->state]->handler = board_led_link_flash;
++ break;
++ case 4:
++ modArr[pcfg->name]->states[pcfg->state]->handler = board_led_link_up;
++ break;
++ default:
++ printk("<1>Exiting Configuration: Unknown LED Mode\n");
++ free_memory();
++ spin_unlock_irqrestore(&config_lock, flags);
++ return -1;
++ }
++ pcfg++;
+ }
-+
-+ state->timer_running = 0;
-+
-+
++ spin_unlock_irqrestore(&config_lock, flags);
++ return 0;
+}
+
+
-+static void led_on(STATE_ENTRY_T *state)
++int __init led_init(void)
+{
-+ int mod_index = state->module_id >> 5;
-+ GPIO_OBJ_T *gpio = state->gpio;
+
-+ gpio->gpio_state = LED_ON;
-+ gpio_on(gpio->gpio_id);
-+ gpio->module_map[mod_index] |= (1 << (state->module_id % BITS_PER_INT));
++ /* Clear our memory */
++ memset(modArr,0x00,sizeof(mod_entry_t *)*MAX_MOD_ID);
++ memset(led_arr,0x00,sizeof(led_data_t *)*MAX_LED_ID);
++
++ /* Create spin lock for config data structure */
++ config_lock=SPIN_LOCK_UNLOCKED;
++
++ /* Create directory */
++ led_proc_dir = proc_mkdir("led", NULL);
++ if( led_proc_dir == NULL )
++ goto out;
++
++ /* Create adsl file */
++ led_file = create_proc_entry("led", 0777, led_proc_dir);
++ if( led_file == NULL)
++ goto led_file;
++ led_file->owner = THIS_MODULE;
++ led_file->proc_fops = &led_fops;
++
++ memset( modArr , 0x00 , sizeof(mod_entry_t *) * MAX_MOD_ID);
++ /* Reset the GPIO pins */
++ board_gpio_init();
++
++ /* Register the UART controlled LEDS */
++ uart_led_init();
++ /* Create the usb proc file */
++ avalanche_leds_init();
++ return 0;
++
++ led_file:
++ remove_proc_entry("led",led_proc_dir);
++ out:
++ return 0;
+
+}
+
-+static void led_off(STATE_ENTRY_T *state)
++void led_exit()
+{
-+
-+ int mod_index = state->module_id >> 5;
-+ GPIO_OBJ_T *gpio = state->gpio;
-+
-+ gpio->module_map[mod_index] &= ~(1 << (state->module_id % BITS_PER_INT) );
-+ if(!gpio->module_map[mod_index])
-+ {
-+ gpio->gpio_state = LED_OFF;
-+ gpio_off(gpio->gpio_id);
-+ }
-+
++ remove_proc_entry("led", led_proc_dir);
+}
+
-+static void led_oneshot_on(STATE_ENTRY_T *state)
-+{
-+ GPIO_OBJ_T *gpio = state->gpio;
-+
-+ state->timer_running = 1;
-+ gpio->gpio_state = LED_ONESHOT_ON;
-+ gpio_on(gpio->gpio_id);
-+ os_timer_add(state->os_timer,state->param,(int)state);
-+}
++module_init(led_init);
++module_exit(led_exit);
+
-+static void led_oneshot_off(STATE_ENTRY_T *state)
++void register_led_drv( int device , led_reg_t *pInfo)
+{
++ unsigned int flags;
++ struct timer_list *pTimer = NULL;
+
-+ GPIO_OBJ_T *gpio = state->gpio;
++ spin_lock_irqsave(&config_lock, flags);
+
-+ state->timer_running = 1;
-+ gpio->gpio_state = LED_ONESHOT_OFF;
-+ gpio_off(gpio->gpio_id);
-+ os_timer_add(state->os_timer,state->param,(int)state);
-+}
-+
-+static void led_flash(STATE_ENTRY_T *state)
-+{
++ led_arr[device].led = pInfo;
++ if( led_arr[device].led->init != 0x00)
++ led_arr[device].led->init(led_arr[device].led->param);
++ if( led_arr[device].led->offfunc != 0x00)
++ led_arr[device].led->offfunc(led_arr[device].led->param);
+
-+ GPIO_OBJ_T *gpio = state->gpio;
-+
-+ state->timer_running = 1;
-+ gpio->gpio_state = LED_FLASH;
-+ gpio_on(gpio->gpio_id);
-+ os_timer_add(state->os_timer,(state->param & 0xffff),(int)state);
-+}
++ /* Create a timer for blinking */
++ pTimer = kmalloc(sizeof(struct timer_list),GFP_KERNEL);
++ init_timer( pTimer );
++ pTimer->function = led_timer_func;
++ pTimer->data = 0;
++ led_arr[device].pTimer = pTimer;
++ led_arr[device].timer_running = 0;
+
++ spin_unlock_irqrestore(&config_lock, flags);
+
-+/****************HAL APIS***********************************************/
-+int led_hal_init(GPIO_REGS_T gpio_reg,unsigned int *gpio_off_value,int num_gpio_pins)
-+{
-+ int i;
-+ unsigned int *p_gpio=gpio_off_val;
-+
-+ gpio_regs = gpio_reg;
-+ num_gpios = num_gpio_pins;
-+
-+ gpio_arr = led_malloc((num_gpio_pins + 4) * sizeof(GPIO_OBJ_T)); /* 4 added for ADSL gpio pins */
-+
-+ /* get gpios off state */
-+ for(i=0; i < num_gpio_pins; i+=GPIOS_PER_INT)
-+ {
-+ *p_gpio = *gpio_off_value;
-+ gpio_off_value++;
-+ p_gpio++;
-+ }
-+
-+ /* initialize gpio objects */
-+ for(i=0; i<num_gpio_pins + 4;i++) /* 4 added for ADSL gpio pins */
-+ {
-+ gpio_arr[i].gpio_id = i;
-+ }
-+
-+
-+
-+ /* initialize led state function handlers */
-+ led_mode_handler[LED_ON] = led_on;
-+ led_mode_handler[LED_OFF] = led_off;
-+ led_mode_handler[LED_ONESHOT_ON] = led_oneshot_on;
-+ led_mode_handler[LED_ONESHOT_OFF] = led_oneshot_off;
-+ led_mode_handler[LED_FLASH] = led_flash;
-+
-+
-+ return 0;
++ return;
+}
+
-+
-+ /*********************************************************/
-+
-+int avalanche_led_set_config(LED_CONFIG_T *led_cfg)
++void deregister_led_drv( int device)
+{
-+ MODULE_INSTANCE_T *module;
-+ module = get_module(led_cfg->name,led_cfg->instance);
-+
-+ if(!module )
-+ goto config_failed;
-+
-+ if(led_cfg->state < MAX_STATE_ENTRIES)
-+ {
-+ STATE_ENTRY_T *state_entry;
-+ int state=led_cfg->state;
-+ int i;
-+
-+ if(!(module->states[state]))
-+ {
-+ module->states[state] = led_malloc(sizeof(STATE_ENTRY_T));
-+ }
-+
-+ state_entry = module->states[state];
-+
-+ for(i=0;i<led_cfg->gpio_num;i++)
-+ {
-+ if(led_cfg->gpio[i] >= (num_gpios + 4) ) /* 4 added for ADSL */
-+ {
-+ log_msg("Error: gpio number out of range\n");
-+ goto config_failed;
-+ }
++ unsigned int flags;
+
-+ state_entry->gpio = &gpio_arr[led_cfg->gpio[i]];
-+ state_entry->mode = led_cfg->mode[i];
-+ state_entry->module_id = module->module_id;
-+ state_entry->handler = led_mode_handler[state_entry->mode];
-+ state_entry->timer_running = 0;
++ spin_lock_irqsave(&config_lock, flags);
++ led_arr[device].led = NULL;
+
-+ if(REQUIRES_TIMER(led_cfg->mode[i])) /* requires timer */
-+ {
-+
-+ state_entry->param = led_cfg->param1;
-+
-+ if(led_cfg->mode[i] == LED_FLASH)
-+ state_entry->param |= (led_cfg->param2 << 16);
-+
-+ if(!(state_entry->os_timer))
-+ state_entry->os_timer = os_timer_init(led_timer_func);
-+ }
-+
-+ if(i == led_cfg->gpio_num - 1)
-+ {
-+ free_state(state_entry->next);
-+ state_entry->next = NULL;
-+ break;
-+ }
-+
-+
-+ /* allocate next node */
-+ else if( !(state_entry->next))
-+ {
-+ state_entry->next = led_malloc(sizeof(STATE_ENTRY_T));
-+ }
-+
-+ state_entry = state_entry->next;
++ if( led_arr[device].pTimer != NULL)
++ {
++ del_timer(led_arr[device].pTimer);
++ kfree(led_arr[device].pTimer);
++ }
++ spin_unlock_irqrestore(&config_lock, flags);
+
++ return;
++}
+
-+ }
++EXPORT_SYMBOL_NOVERS(led_operation);
++EXPORT_SYMBOL_NOVERS(register_led_drv);
++EXPORT_SYMBOL_NOVERS(deregister_led_drv);
+
-+ }
-+ else
-+ {
-+ log_msg("ERROR:State Count exceeded\n");
-+ goto config_failed;
-+ }
+diff -urN linux.old/drivers/char/avalanche_led/leds.c linux.dev/drivers/char/avalanche_led/leds.c
+--- linux.old/drivers/char/avalanche_led/leds.c 1970-01-01 01:00:00.000000000 +0100
++++ linux.dev/drivers/char/avalanche_led/leds.c 2005-07-22 06:52:42.976338184 +0200
+@@ -0,0 +1,133 @@
++#include <linux/config.h>
++#include <linux/init.h>
++#include <linux/delay.h>
++#include <asm/ar7/avalanche_regs.h>
++#include <linux/spinlock.h>
++#include <linux/timer.h>
++#include <linux/sched.h>
++#include <linux/module.h>
++#include <linux/proc_fs.h>
++#include <asm/uaccess.h>
++#include <linux/fs.h>
+
-+ return 0;
++#include <asm/ar7/ledapp.h>
+
-+ config_failed:
-+
-+ return -1;
++#if defined(CONFIG_AR5D01) || defined(CONFIG_AR5W01) || defined(CONFIG_AR7)
+
++#define ETH_MASK 0x01
++#define USB_MASK 0x02
+
++static struct proc_dir_entry *usb_file;
++static ssize_t proc_read_usb_fops(struct file *filp,
++ char *buf,size_t count , loff_t *offp);
++struct file_operations usb_fops = {read: proc_read_usb_fops};
+
-+}
++typedef struct mod_states{
++ int module;
++ int activity;
++ int linkup;
++ int idle;
++}mod_states_t;
+
-+ /*********************************************************/
++mod_states_t state_arr[] = {
++ { MOD_ETH,DEF_ETH_ACTIVITY,DEF_ETH_LINK_UP,DEF_ETH_IDLE },
++ { MOD_USB,DEF_USB_ACTIVITY,DEF_USB_LINK_UP,DEF_USB_IDLE },
++ { MOD_LAN,DEF_LAN_ACTIVITY,DEF_LAN_LINK_UP,DEF_LAN_IDLE }
++ };
+
-+void *avalanche_led_register(const char * mod_name,int instance)
-+{
-+ void *p;
-+ p = get_module((void * )mod_name,instance);
-+ return p;
-+ }
++unsigned char device_links = 0; /* Bitmask with the devices that are up */
+
+
-+int avalanche_led_action(void *module, int state_id)
++void avalanche_led_activity_pulse(unsigned long device)
+{
-+
-+ if(module && state_id < MAX_STATE_ENTRIES)
-+ {
-+
-+ STATE_ENTRY_T *state =((MODULE_INSTANCE_T *)(module))->states[state_id];
-+ while(state)
-+ {
-+ if(state->timer_running == 0)
-+ {
-+ state->handler(state);
-+ }
-+ state = state->next;
-+
-+ }
-+ }
-+ return 0;
++ /* If device link is not up return */
++ if( !(device_links & (unsigned char)(1 << device)))
++ return;
++#ifdef MULTIPLEX_LED
++ led_operation( state_arr[2].module, state_arr[2].activity);
++#else
++ led_operation( state_arr[device].module, state_arr[device].activity);
++#endif
+}
+
-+
-+
-+int led_get_dsl_config(void)
++void avalanche_led_link_up( unsigned long device )
+{
-+
-+ int state_id = 0;
-+ LED_CONFIG_T led_cfg;
-+ int state_count = 0;
-+
-+ os_strcpy(led_cfg.name,"adsl");
-+
-+ for(state_id = 0; state_id < MAX_STATE_ENTRIES;state_id++)
-+ {
-+ if(avalanche_led_config_get(&led_cfg,-1,0,state_id) == 0)
-+ {
-+ /* call configure */
-+ avalanche_led_set_config(&led_cfg);
-+ state_count++;
-+ }
-+
-+ }
-+ return state_count;
-+
-+
++
++ /* If already UP ignore */
++ if( device_links & (unsigned char)(1 << device))
++ return;
++ /* Turn on the bit for the device */
++ device_links |= (unsigned char)(1 << device);
++#ifdef MULTIPLEX_LED
++ led_operation( state_arr[2].module, state_arr[2].linkup);
++#else
++ led_operation( state_arr[device].module, state_arr[device].linkup);
++#endif
+}
+
-+
-+void register_led_drv(int led_num,led_reg_t *led)
++void avalanche_led_link_down ( unsigned long device )
+{
+
-+ /* DSL leds are numbered from 3 to 6 */
-+ int led_index = led_num - 3;
-+
-+ if(led_index >=0 && led_index <= 2)
-+ {
-+ adsl_led_objs[led_index] = *led;
-+
-+ if(adsl_led_objs[led_index].init)
-+ adsl_led_objs[led_index].init(adsl_led_objs[led_index].param);
-+ }
++ /* If already DOWN ignore */
++ if( !(device_links & (unsigned char)(1 << device)))
++ return;
+
++ /* Turn off the bit for the device */
++ device_links &= ~(unsigned char)(1 << device);
++#ifdef MULTIPLEX_LED
++ /* If no links, then shut the LED off */
++ if(!device_links)
++ led_operation( state_arr[2].module, state_arr[2].idle);
++#else
++ led_operation( state_arr[device].module, state_arr[device].idle);
++#endif
+}
+
-+void deregister_led_drv( int led_num)
++static ssize_t proc_read_usb_fops(struct file *filp,
++ char *buf,size_t count , loff_t *offp)
+{
-+ /* DSL leds are numbered from 3 to 6 */
-+ int led_index = led_num - 3;
-+
-+ if(led_index >=0 && led_index <= 2)
-+ {
-+ adsl_led_objs[led_index].onfunc = NULL;
-+ adsl_led_objs[led_index].offfunc = NULL;
-+ }
-+ return;
++ char * pdata = NULL;
++ char line[3];
++ if( *offp != 0 )
++ return 0;
++ pdata = buf;
++ if( device_links & USB_MASK)
++ sprintf(line,"%s\n","1");
++ else
++ sprintf(line,"%s\n","0");
++ copy_to_user(pdata,line,2);
++ *offp = 2;
++ return 2;
+}
+
-+void led_operation(int mod,int state_id)
-+{
-+ static int configured = 0;
-+
-+ if(configured == 0)
-+ {
-+ configured = led_get_dsl_config();
-+ }
-+
-+ avalanche_led_action(dsl_mod,state_id);
-+}
+
-+static int __init led_init(void)
++void avalanche_leds_init(void)
+{
-+ GPIO_REGS_T gpio_regs;
++ /* Create usb link proc file */
++ usb_file = create_proc_entry("avalanche/usb_link", 0444, NULL);
++ if( usb_file == NULL)
++ return;
++ usb_file->owner = THIS_MODULE;
++ usb_file->proc_fops = &usb_fops;
++ return;
++}
+
-+ gpio_regs.gpio_write_reg = NULL;
-+ gpio_regs.gpio_dir_reg = NULL;
-+ gpio_regs.gpio_mode_reg = NULL;
-+
-+ led_hal_init(gpio_regs,gpio_off_state,AVALANCHE_GPIO_PIN_COUNT);
++EXPORT_SYMBOL(avalanche_led_activity_pulse);
++EXPORT_SYMBOL(avalanche_led_link_up);
++EXPORT_SYMBOL(avalanche_led_link_down);
+
-+ /* register instance 0 of adsl module */
-+ dsl_mod = avalanche_led_register("adsl",0);
-+ return 0;
++#else
++/* We make a dummy init routine for the platforms that do not support this led
++ API
++*/
+
++void avalanche_leds_init(void)
++{
+}
+
-+__initcall(led_init);
++#endif
+
+
+
-+EXPORT_SYMBOL_NOVERS(led_init);
-+EXPORT_SYMBOL_NOVERS(led_operation);
-+EXPORT_SYMBOL_NOVERS(register_led_drv);
-+EXPORT_SYMBOL_NOVERS(deregister_led_drv);
+
-diff -urN kernel-old/drivers/char/avalanche_led/Makefile kernel-current/drivers/char/avalanche_led/Makefile
---- kernel-old/drivers/char/avalanche_led/Makefile 1970-01-01 01:00:00.000000000 +0100
-+++ kernel-current/drivers/char/avalanche_led/Makefile 2005-07-10 18:25:32.692328160 +0200
++
+diff -urN linux.old/drivers/char/avalanche_led/Makefile linux.dev/drivers/char/avalanche_led/Makefile
+--- linux.old/drivers/char/avalanche_led/Makefile 1970-01-01 01:00:00.000000000 +0100
++++ linux.dev/drivers/char/avalanche_led/Makefile 2005-07-22 06:52:42.977338032 +0200
@@ -0,0 +1,23 @@
+# File: drivers/char/avalanche_led/Makefile
+#
+
+EXTRA_CFLAGS := -I$(TOPDIR)/include/asm/ar7
+
-+export-objs := led_drv.o led_wrapper.o
++export-objs := ledmod.o leds.o
+
-+avalanche_led-objs := led_hal.o led_drv.o led_wrapper.o
++avalanche_led-objs := ledmod.o gpio.o uartled.o leds.o
+
+include $(TOPDIR)/Rules.make
+
+
+clean:
+ rm -f core *.o *.a *.s
-diff -urN kernel-old/drivers/char/Config.in kernel-current/drivers/char/Config.in
---- kernel-old/drivers/char/Config.in 2005-07-10 02:55:18.318811000 +0200
-+++ kernel-current/drivers/char/Config.in 2005-07-10 18:03:46.121957048 +0200
+diff -urN linux.old/drivers/char/avalanche_led/uartled.c linux.dev/drivers/char/avalanche_led/uartled.c
+--- linux.old/drivers/char/avalanche_led/uartled.c 1970-01-01 01:00:00.000000000 +0100
++++ linux.dev/drivers/char/avalanche_led/uartled.c 2005-07-22 06:52:42.977338032 +0200
+@@ -0,0 +1,55 @@
++#include <linux/kernel.h>
++#include <asm/uaccess.h>
++#include <linux/spinlock.h>
++#include <asm/ar7/avalanche_regs.h>
++#include <asm/ar7/ledapp.h>
++
++#define UART_LED_REG (*(volatile unsigned int *)(UARTA_BASE + 0x10))
++
++static spinlock_t device_lock;
++led_reg_t temp1[2];
++
++static void uart_led_on(unsigned long param)
++{
++ unsigned long flags;
++
++ spin_lock_irqsave(&device_lock,flags);
++ UART_LED_REG &= 0xFFFD;
++ spin_unlock_irqrestore(&device_lock, flags);
++}
++
++static void uart_led_off ( unsigned long param )
++{
++ unsigned int flags = 0x00;
++ spin_lock_irqsave(&device_lock, flags);
++ UART_LED_REG |= 0x02;
++ spin_unlock_irqrestore(&device_lock, flags);
++}
++
++void uart_led_init(void)
++{
++
++#if defined(CONFIG_AR5D01)
++ /* Register led 6 UART Pin 1 */
++ temp1[0].param = 0;
++ temp1[0].init = NULL;
++ temp1[0].onfunc = uart_led_on;
++ temp1[0].offfunc = uart_led_off;
++ register_led_drv( 6 , &temp1[0]);
++#endif
++
++#if defined(CONFIG_AR5W01)
++ /* Register led 8 UART Pin 1 */
++ temp1[0].param = 0;
++ temp1[0].init = NULL;
++ temp1[0].onfunc = uart_led_on;
++ temp1[0].offfunc = uart_led_off;
++ register_led_drv( 8 , &temp1[0]);
++#endif
++
++ /* Initialize the link mask */
++ device_lock = SPIN_LOCK_UNLOCKED;
++
++ return;
++}
++
+diff -urN linux.old/drivers/char/Config.in linux.dev/drivers/char/Config.in
+--- linux.old/drivers/char/Config.in 2005-07-10 20:53:55.650624000 +0200
++++ linux.dev/drivers/char/Config.in 2005-07-22 06:52:58.716945248 +0200
@@ -133,6 +133,10 @@
fi
fi
fi
+if [ "$CONFIG_AR7" = "y" ]; then
-+ bool 'Enable LED support' CONFIG_MIPS_AVALANCHE_LED
++ bool 'Enable LED support' CONFIG_AR7_LED
+fi
+
if [ "$CONFIG_EXPERIMENTAL" = "y" -a "$CONFIG_ZORRO" = "y" ]; then
tristate 'Commodore A2232 serial support (EXPERIMENTAL)' CONFIG_A2232
fi
-diff -urN kernel-old/drivers/char/Makefile kernel-current/drivers/char/Makefile
---- kernel-old/drivers/char/Makefile 2005-07-10 02:55:18.319811000 +0200
-+++ kernel-current/drivers/char/Makefile 2005-07-10 18:03:46.122956896 +0200
-@@ -190,6 +190,19 @@
+diff -urN linux.old/drivers/char/Makefile linux.dev/drivers/char/Makefile
+--- linux.old/drivers/char/Makefile 2005-07-10 20:53:55.651623000 +0200
++++ linux.dev/drivers/char/Makefile 2005-07-22 06:53:35.321380528 +0200
+@@ -190,6 +190,12 @@
obj-$(CONFIG_PCI) += keyboard.o $(KEYMAP)
endif
+#
+# Texas Intruments LED driver
+#
-+ifeq ($(CONFIG_MIPS_AVALANCHE_LED),y)
-+obj-$(CONFIG_MIPS_AVALANCHE_LED) += avalanche_led/avalanche_led.o
-+subdir-$(CONFIG_MIPS_AVALANCHE_LED) += avalanche_led
-+endif
-+
-+ifeq ($(CONFIG_MIPS_AVALANCHE_LED),m)
-+obj-$(CONFIG_MIPS_AVALANCHE_LED) += avalanche_led/avalanche_led.o
-+subdir-$(CONFIG_MIPS_AVALANCHE_LED) += avalanche_led
-+endif
++obj-$(CONFIG_AR7_LED) += avalanche_led/avalanche_led.o
++subdir-$(CONFIG_AR7_LED) += avalanche_led
+
obj-$(CONFIG_HIL) += hp_keyb.o
obj-$(CONFIG_MAGIC_SYSRQ) += sysrq.o
obj-$(CONFIG_ATARI_DSP56K) += dsp56k.o
-diff -urN kernel-old/include/asm-mips/ar7/ledapp.h kernel-current/include/asm-mips/ar7/ledapp.h
---- kernel-old/include/asm-mips/ar7/ledapp.h 1970-01-01 01:00:00.000000000 +0100
-+++ kernel-current/include/asm-mips/ar7/ledapp.h 2005-07-10 18:49:37.556426688 +0200
+diff -urN linux.old/include/asm-mips/ar7/ledapp.h linux.dev/include/asm-mips/ar7/ledapp.h
+--- linux.old/include/asm-mips/ar7/ledapp.h 1970-01-01 01:00:00.000000000 +0100
++++ linux.dev/include/asm-mips/ar7/ledapp.h 2005-07-22 06:52:42.982337272 +0200
@@ -0,0 +1,59 @@
+#ifndef __LED_APP__
+#define __LED_APP__
+}led_reg_t;
+
+#endif
-diff -urN kernel-old/include/asm-mips/ar7/led_config.h kernel-current/include/asm-mips/ar7/led_config.h
---- kernel-old/include/asm-mips/ar7/led_config.h 1970-01-01 01:00:00.000000000 +0100
-+++ kernel-current/include/asm-mips/ar7/led_config.h 2005-07-10 18:03:46.122956896 +0200
-@@ -0,0 +1,51 @@
-+/******************************************************************************
-+ * FILE PURPOSE: - LED config Header
-+ ******************************************************************************
-+ * FILE NAME: led_config.h
-+ *
-+ * DESCRIPTION: Header file for LED configuration parameters
-+ * and data structures
-+ *
-+ * REVISION HISTORY:
-+ * 11 Oct 03 - PSP TII
-+ *
-+ * (C) Copyright 2002, Texas Instruments, Inc
-+ *******************************************************************************/
-+
-+
-+#ifndef __LED_CONFIG__
-+#define __LED_CONFIG__
-+
-+/* LED config parameters */
-+#define MAX_GPIO_PIN_NUM 64
-+#define MAX_GPIOS_PER_STATE 2
-+#define MAX_MODULE_ENTRIES 25
-+#define MAX_MODULE_INSTANCES 2
-+#define MAX_STATE_ENTRIES 25
-+#define NUM_LED_MODES 5
-+#define MAX_LED_ENTRIES 25
-+
-+
-+/* LED modes */
-+#define LED_OFF 0
-+#define LED_ON 1
-+#define LED_ONESHOT_OFF 2
-+#define LED_ONESHOT_ON 3
-+#define LED_FLASH 4
-+
-+
-+
-+/* Data structure for LED configuration */
-+typedef struct led_config{
-+ unsigned char name[80];
-+ unsigned int instance;
-+ unsigned int state;
-+ unsigned int gpio[MAX_GPIOS_PER_STATE];
-+ unsigned int mode[MAX_GPIOS_PER_STATE];
-+ unsigned int gpio_num;
-+ unsigned int param1;
-+ unsigned int param2;
-+}LED_CONFIG_T;
-+
-+
-+#endif /* __LED_CONFIG__ */
-diff -urN kernel-old/include/asm-mips/ar7/led_ioctl.h kernel-current/include/asm-mips/ar7/led_ioctl.h
---- kernel-old/include/asm-mips/ar7/led_ioctl.h 1970-01-01 01:00:00.000000000 +0100
-+++ kernel-current/include/asm-mips/ar7/led_ioctl.h 2005-07-10 18:03:46.122956896 +0200
-@@ -0,0 +1,32 @@
-+/******************************************************************************
-+ * FILE PURPOSE: - LED ioctl Header
-+ ******************************************************************************
-+ * FILE NAME: led_ioctl.h
-+ *
-+ * DESCRIPTION: Header file defining macros for ioctl commands.
-+ *
-+ * REVISION HISTORY:
-+ * 11 Oct 03 - PSP TII
-+ *
-+ * (C) Copyright 2002, Texas Instruments, Inc
-+ *******************************************************************************/
-+#ifndef __LED_IOCTL__
-+#define __LED_IOCTL__
-+
-+typedef struct led_mod{
-+unsigned char *name;
-+unsigned int instance;
-+unsigned int handle;
-+}LED_MODULE_T;
-+
-+typedef struct led_state{
-+unsigned int handle;
-+unsigned int state_id;
-+}LED_STATE_T;
-+
-+#define LED_CONFIG 0
-+#define LED_GET_HANDLE 1
-+#define LED_ACTION 2
-+#define LED_RELEASE_HANDLE 3
-+
-+#endif /* __LED_IOCTL__ */