1/*************************************************************************** 2*** 3*** Copyright 2008 Hon Hai Precision Ind. Co. Ltd. 4*** All Rights Reserved. 5*** No portions of this material shall be reproduced in any form without the 6*** written permission of Hon Hai Precision Ind. Co. Ltd. 7*** 8*** All information contained in this document is Hon Hai Precision Ind. 9*** Co. Ltd. company private, proprietary, and trade secret property and 10*** are protected by international intellectual property laws and treaties. 11*** 12****************************************************************************/ 13 14#include <linux/module.h> 15#include <linux/init.h> 16#include <linux/fs.h> 17#include <linux/miscdevice.h> 18#include <asm/uaccess.h> 19 20#include <typedefs.h> 21#include <bcmutils.h> 22#include <siutils.h> 23#include <bcmdevs.h> 24 25#include "wps_led.h" 26 27/*#define _DEBUG*/ 28 29 30#ifdef CONFIG_DEVFS_FS 31static int wps_led_major; 32devfs_handle_t wps_leddev_handle; 33#endif /* CONFIG_DEVFS_FS */ 34 35extern int wps_led_pattern; 36extern int wps_led_state; 37extern int is_wl_secu_mode; /* foxconn added, zacker, 09/17/2009, @wps_led */ 38 39static int 40wps_led_open(struct inode *inode, struct file * file) 41{ 42 MOD_INC_USE_COUNT; 43 return 0; 44} 45 46static int 47wps_led_release(struct inode *inode, struct file * file) 48{ 49 MOD_DEC_USE_COUNT; 50 return 0; 51} 52 53static int 54wps_led_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) 55{ 56 /* Foxconn added start pling 02/26/2010 */ 57 /* Add USB LED support. 58 * Note: need to add at the beginning the 'arg' check below. 59 * Otherwise, we might change the wireless LED 60 * by accident. 61 */ 62#if (defined INCLUDE_USB_LED) 63 if (cmd == USB_LED_STATE_ON || cmd == USB_LED_STATE_OFF) 64 { 65 /* Foxconn modified start, Wins, 04/11/2011 */ 66#if defined(WNDR4500REV) || defined(R4500) 67 extern int usb1_led_state; 68 69 if (cmd == USB_LED_STATE_ON) 70 usb1_led_state = 1; 71 else 72 usb1_led_state = 0; 73#else /* WNDR4500REV */ 74 extern int usb_led_state; 75 if (cmd == USB_LED_STATE_ON) 76 usb_led_state = 1; 77 else 78 usb_led_state = 0; 79#endif /* WNDR4500REV */ 80 /* Foxconn modified end, Wins, 04/11/2011 */ 81 return 0; 82 } 83 84 /* Foxconn added start, Wins, 04/11/2011 */ 85#if defined(WNDR4500REV) || defined(R4500) 86 if (cmd == USB2_LED_STATE_ON || cmd == USB2_LED_STATE_OFF) 87 { 88 extern int usb2_led_state; 89 90 if (cmd == USB2_LED_STATE_ON) 91 usb2_led_state = 1; 92 else 93 usb2_led_state = 0; 94 return 0; 95 } 96#endif /* WNDR4500REV */ 97 /* Foxconn added end, Wins, 04/11/2011 */ 98#endif 99 /* Foxconn added end pling 02/26/2010 */ 100 101 /* foxconn added start, zacker, 09/17/2009, @wps_led */ 102 if (arg) 103 is_wl_secu_mode = 1; 104 else 105 is_wl_secu_mode = 0; 106 /* foxconn added end, zacker, 09/17/2009, @wps_led */ 107 108 switch (cmd) 109 { 110 case WPS_LED_BLINK_NORMAL: 111 wps_led_state = 1; 112#ifdef _DEBUG 113 printk("%s: blink normal\n", __FUNCTION__); 114#endif 115 break; 116 117 case WPS_LED_BLINK_QUICK: 118 wps_led_state = 2; 119#ifdef _DEBUG 120 printk("%s: blink WPS\n", __FUNCTION__); 121#endif 122 break; 123 124 case WPS_LED_BLINK_OFF: 125 /* foxconn added start, zacker, 09/17/2009, @wps_led */ 126 /* wps_led_state will change to 0 automatically after 127 * blinking a few seconds if it's 2 currently 128 */ 129 if (wps_led_state != 2) 130 /* foxconn added end, zacker, 09/17/2009, @wps_led */ 131 wps_led_state = 0; 132#ifdef _DEBUG 133 printk("%s: blink OFF\n", __FUNCTION__); 134#endif 135 break; 136 137 case WPS_LED_CHANGE_GREEN: 138 break; 139 140 case WPS_LED_CHANGE_AMBER: 141 break; 142 143 case WPS_LED_BLINK_QUICK2: 144 wps_led_state = 3; 145 break; 146 case WPS_LED_BLINK_AP_LOCKDOWN: 147 wps_led_state = 4; 148 break; 149 150 default: 151 break; 152 } 153 154 return 0; 155} 156 157static struct file_operations wps_led_fops = { 158#ifndef CONFIG_DEVFS_FS 159 .owner = THIS_MODULE, 160 .open = wps_led_open, 161 .release = wps_led_release, 162 .ioctl = wps_led_ioctl, 163#else /* CONFIG_DEVFS_FS */ 164 owner: THIS_MODULE, 165 open: wps_led_open, 166 release: wps_led_release, 167 ioctl: wps_led_ioctl, 168#endif /* CONFIG_DEVFS_FS */ 169 }; 170 171static int __init 172wps_led_init(void) 173{ 174#ifndef CONFIG_DEVFS_FS 175 int ret_val; 176 /* 177 * Register the character device (atleast try) 178 */ 179 ret_val = register_chrdev(WPS_LED_MAJOR_NUM, "wps_led", &wps_led_fops); 180 /* 181 * Negative values signify an error 182 */ 183 if (ret_val < 0) 184 { 185 printf("%s failed with %d\n","Sorry, registering the character device wps_led", ret_val); 186 return ret_val; 187 } 188#else /* CONFIG_DEVFS_FS */ 189 if ((wps_led_major = devfs_register_chrdev(WPS_LED_MAJOR_NUM, "wps_led", &wps_led_fops)) < 0) 190 return wps_led_major; 191 192 wps_leddev_handle = devfs_register(NULL, "wps_led", DEVFS_FL_DEFAULT, 193 wps_led_major, 0, S_IFCHR | S_IRUGO | S_IWUGO, 194 &wps_led_fops, NULL); 195#endif /* CONFIG_DEVFS_FS */ 196 return 0; 197} 198 199static void __exit 200wps_led_exit(void) 201{ 202#ifndef CONFIG_DEVFS_FS 203 int ret_val; 204 ret_val = unregister_chrdev(WPS_LED_MAJOR_NUM, "wps_led"); 205#else /* CONFIG_DEVFS_FS */ 206 if (wps_leddev_handle != NULL) 207 devfs_unregister(wps_leddev_handle); 208 wps_leddev_handle = NULL; 209 devfs_unregister_chrdev(wps_led_major, "wps_led"); 210#endif /* CONFIG_DEVFS_FS */ 211} 212 213module_init(wps_led_init); 214module_exit(wps_led_exit); 215