upload tizen1.0 source
[kernel/linux-2.6.36.git] / drivers / net / wireless / bcm4330 / src / dhd / sys / dhd_custom_gpio.c
1 /*
2 * Customer code to add GPIO control during WLAN start/stop
3 * Copyright (C) 1999-2011, Broadcom Corporation
4
5 *         Unless you and Broadcom execute a separate written software license
6 * agreement governing use of this software, this software is licensed to you
7 * under the terms of the GNU General Public License version 2 (the "GPL"),
8 * available at http://www.broadcom.com/licenses/GPLv2.php, with the
9 * following added to such license:
10
11 *      As a special exception, the copyright holders of this software give you
12 * permission to link this software with independent modules, and to copy and
13 * distribute the resulting executable under terms of your choice, provided that
14 * you also meet, for each linked independent module, the terms and conditions of
15 * the license of that module.  An independent module is a module which is not
16 * derived from this software.  The special exception does not apply to any
17 * modifications of the software.
18
19 *      Notwithstanding the above, under no circumstances may you combine this
20 * software in any way with any other Broadcom software provided under a license
21 * other than the GPL, without Broadcom's express prior written consent.
22 *
23 * $Id: dhd_custom_gpio.c,v 1.2.42.1 2010-10-19 00:41:09 $
24 */
25
26 #include <typedefs.h>
27 #include <linuxver.h>
28 #include <osl.h>
29 #include <bcmutils.h>
30
31 #include <dngl_stats.h>
32 #include <dhd.h>
33
34 #include <wlioctl.h>
35 #include <wl_iw.h>
36
37 #define WL_ERROR(x) printf x
38 #define WL_TRACE(x)
39
40 #ifdef CUSTOMER_HW
41 extern  void bcm_wlan_power_off(int);
42 extern  void bcm_wlan_power_on(int);
43 #endif /* CUSTOMER_HW */
44 #if  defined(CONFIG_MACH_MAHIMAHI)
45 int wifi_set_carddetect(int on);
46 int wifi_set_power(int on, unsigned long msec);
47 int wifi_get_irq_number(unsigned long *irq_flags_ptr);
48 int wifi_get_mac_addr(unsigned char *buf);
49 #endif
50
51 #if defined(OOB_INTR_ONLY)
52
53 #if defined(BCMLXSDMMC)
54 extern int sdioh_mmc_irq(int irq);
55 #endif /* (BCMLXSDMMC)  */
56
57 #if defined(CUSTOMER_HW3) || defined(CUSTOMER_HW_SAMSUNG_SLP)
58 #include <mach/gpio.h>
59 #endif
60
61 /* Customer specific Host GPIO defintion  */
62 #ifdef CUSTOMER_HW_SAMSUNG_SLP
63 static int dhd_oob_gpio_num = IRQ_EINT(21);
64 #else
65 static int dhd_oob_gpio_num = -1; /* GG 19 */
66 #endif
67
68 module_param(dhd_oob_gpio_num, int, 0644);
69 MODULE_PARM_DESC(dhd_oob_gpio_num, "DHD oob gpio number");
70
71 /* that function will returns :
72     1) return :  Host gpio interrupt number per customer platform
73     2) irq_flags_ptr : Type of Host interrupt as Level or Edge
74
75     NOTE :
76     Customer should check his platform definitions
77     and hist Host Interrupt  spec
78     to figure out the proper setting for his platform.
79     BRCM provides just reference settings as example.
80
81 */
82 int dhd_customer_oob_irq_map(unsigned long *irq_flags_ptr)
83 {
84         int  host_oob_irq = 0;
85
86 #ifdef CONFIG_MACH_MAHIMAHI
87         host_oob_irq = wifi_get_irq_number(irq_flags_ptr);
88
89 #else /* for NOT  CONFIG_MACH_MAHIMAHI */
90 #if defined(CUSTOM_OOB_GPIO_NUM)
91         if (dhd_oob_gpio_num < 0) {
92                 dhd_oob_gpio_num = CUSTOM_OOB_GPIO_NUM;
93         }
94 #endif
95
96         if (dhd_oob_gpio_num < 0) {
97                 WL_ERROR(("%s: ERROR customer specific Host GPIO is NOT defined \n",
98                         __FUNCTION__));
99                 return (dhd_oob_gpio_num);
100         }
101
102         WL_ERROR(("%s: customer specific Host GPIO number is (%d)\n",
103                  __FUNCTION__, dhd_oob_gpio_num));
104
105 #if defined CUSTOMER_HW
106         host_oob_irq = MSM_GPIO_TO_INT(dhd_oob_gpio_num);
107 #elif defined CUSTOMER_HW3
108         gpio_request(dhd_oob_gpio_num, "oob irq");
109         host_oob_irq = gpio_to_irq(dhd_oob_gpio_num);
110         gpio_direction_input(dhd_oob_gpio_num);
111 #elif defined CUSTOMER_HW_SAMSUNG_SLP
112         host_oob_irq = dhd_oob_gpio_num;        
113 #endif /* CUSTOMER_HW */
114 #endif /* CONFIG_MACH_MAHIMAHI */
115
116         return (host_oob_irq);
117 }
118 #endif /* defined(OOB_INTR_ONLY) */
119
120 /* Customer function to control hw specific wlan gpios */
121 void
122 dhd_customer_gpio_wlan_ctrl(int onoff)
123 {
124         switch (onoff) {
125                 case WLAN_RESET_OFF:
126                         WL_TRACE(("%s: call customer specific GPIO to insert WLAN RESET\n",
127                                 __FUNCTION__));
128 #ifdef CUSTOMER_HW
129                         bcm_wlan_power_off(2);
130 #endif /* CUSTOMER_HW */
131 #ifdef CONFIG_MACH_MAHIMAHI
132                         wifi_set_power(0, 0);
133 #endif
134                         WL_ERROR(("=========== WLAN placed in RESET ========\n"));
135                 break;
136
137                 case WLAN_RESET_ON:
138                         WL_TRACE(("%s: callc customer specific GPIO to remove WLAN RESET\n",
139                                 __FUNCTION__));
140 #ifdef CUSTOMER_HW
141                         bcm_wlan_power_on(2);
142 #endif /* CUSTOMER_HW */
143 #ifdef CONFIG_MACH_MAHIMAHI
144                         wifi_set_power(1, 0);
145 #endif
146                         WL_ERROR(("=========== WLAN going back to live  ========\n"));
147                 break;
148
149                 case WLAN_POWER_OFF:
150                         WL_TRACE(("%s: call customer specific GPIO to turn off WL_REG_ON\n",
151                                 __FUNCTION__));
152 #ifdef CUSTOMER_HW
153                         bcm_wlan_power_off(1);
154 #endif /* CUSTOMER_HW */
155                 break;
156
157                 case WLAN_POWER_ON:
158                         WL_TRACE(("%s: call customer specific GPIO to turn on WL_REG_ON\n",
159                                 __FUNCTION__));
160 #ifdef CUSTOMER_HW
161                         bcm_wlan_power_on(1);
162 #endif /* CUSTOMER_HW */
163                         /* Lets customer power to get stable */
164                         OSL_DELAY(200);
165                 break;
166         }
167 }
168
169 #ifdef GET_CUSTOM_MAC_ENABLE
170 /* Function to get custom MAC address */
171 int
172 dhd_custom_get_mac_address(unsigned char *buf)
173 {
174         int ret = 0;
175
176         WL_TRACE(("%s Enter\n", __FUNCTION__));
177         if (!buf)
178                 return -EINVAL;
179
180         /* Customer access to MAC address stored outside of DHD driver */
181 #if defined(CONFIG_MACH_MAHIMAHI) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35))
182         /* Lin - this will call wifi_control_data->get_mac_addr (dhd_linux.c) */
183         ret = wifi_get_mac_addr(buf);
184 #endif
185
186 #ifdef EXAMPLE_GET_MAC
187         /* EXAMPLE code */
188         {
189                 struct ether_addr ea_example = {{0x00, 0x11, 0x22, 0x33, 0x44, 0xFF}};
190                 bcopy((char *)&ea_example, buf, sizeof(struct ether_addr));
191         }
192 #endif /* EXAMPLE_GET_MAC */
193
194         return ret;
195 }
196 #endif /* GET_CUSTOM_MAC_ENABLE */