Initial commit
[kernel/linux-3.0.git] / drivers / net / wireless / bcmdhd / src / dhd / sys / dhd_custom_gpio.c
1 /*
2 * Customer code to add GPIO control during WLAN start/stop
3 * Copyright (C) 1999-2012, 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 291086 2011-10-21 01:17:24Z $
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(CUSTOMER_HW2) || defined(CUSTOMER_HW_SAMSUNG)
45 #ifdef CONFIG_WIFI_CONTROL_FUNC
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 void *wifi_get_country_code(char *ccode);
50 #else
51 int wifi_set_power(int on, unsigned long msec) { return -1; }
52 int wifi_get_irq_number(unsigned long *irq_flags_ptr) { return -1; }
53 int wifi_get_mac_addr(unsigned char *buf) { return -1; }
54 void *wifi_get_country_code(char *ccode) { return NULL; }
55 #endif /* CONFIG_WIFI_CONTROL_FUNC */
56 #endif /* CUSTOMER_HW2 || CUSTOMER_HW_SAMSUNG */
57
58 #if defined(OOB_INTR_ONLY)
59
60 #if defined(BCMLXSDMMC)
61 extern int sdioh_mmc_irq(int irq);
62 #endif /* (BCMLXSDMMC)  */
63
64 #ifdef CUSTOMER_HW3
65 #include <mach/gpio.h>
66 #endif
67
68 /* Customer specific Host GPIO defintion  */
69 static int dhd_oob_gpio_num = -1;
70
71 module_param(dhd_oob_gpio_num, int, 0644);
72 MODULE_PARM_DESC(dhd_oob_gpio_num, "DHD oob gpio number");
73
74 /* This function will return:
75  *  1) return :  Host gpio interrupt number per customer platform
76  *  2) irq_flags_ptr : Type of Host interrupt as Level or Edge
77  *
78  *  NOTE :
79  *  Customer should check his platform definitions
80  *  and his Host Interrupt spec
81  *  to figure out the proper setting for his platform.
82  *  Broadcom provides just reference settings as example.
83  *
84  */
85 int dhd_customer_oob_irq_map(unsigned long *irq_flags_ptr)
86 {
87         int  host_oob_irq = 0;
88
89 #if defined(CUSTOMER_HW2) || defined(CUSTOMER_HW_SAMSUNG)
90         host_oob_irq = wifi_get_irq_number(irq_flags_ptr);
91
92 #else
93 #if defined(CUSTOM_OOB_GPIO_NUM)
94         if (dhd_oob_gpio_num < 0) {
95                 dhd_oob_gpio_num = CUSTOM_OOB_GPIO_NUM;
96         }
97 #endif /* CUSTOMER_OOB_GPIO_NUM */
98
99         if (dhd_oob_gpio_num < 0) {
100                 WL_ERROR(("%s: ERROR customer specific Host GPIO is NOT defined \n",
101                         __FUNCTION__));
102                 return (dhd_oob_gpio_num);
103         }
104
105         WL_ERROR(("%s: customer specific Host GPIO number is (%d)\n",
106                  __FUNCTION__, dhd_oob_gpio_num));
107
108 #if defined CUSTOMER_HW
109         host_oob_irq = MSM_GPIO_TO_INT(dhd_oob_gpio_num);
110 #elif defined CUSTOMER_HW3
111         gpio_request(dhd_oob_gpio_num, "oob irq");
112         host_oob_irq = gpio_to_irq(dhd_oob_gpio_num);
113         gpio_direction_input(dhd_oob_gpio_num);
114 #endif /* CUSTOMER_HW */
115 #endif /* CUSTOMER_HW2 || CUSTOMER_HW_SAMSUNG */
116
117         return (host_oob_irq);
118 }
119 #endif /* defined(OOB_INTR_ONLY) */
120
121 /* Customer function to control hw specific wlan gpios */
122 void
123 dhd_customer_gpio_wlan_ctrl(int onoff)
124 {
125         switch (onoff) {
126                 case WLAN_RESET_OFF:
127                         WL_TRACE(("%s: call customer specific GPIO to insert WLAN RESET\n",
128                                 __FUNCTION__));
129 #ifdef CUSTOMER_HW
130                         bcm_wlan_power_off(2);
131 #endif /* CUSTOMER_HW */
132 #if defined(CUSTOMER_HW2) || defined(CUSTOMER_HW_SAMSUNG)
133                         wifi_set_power(0, 0);
134 #endif
135                         WL_ERROR(("=========== WLAN placed in RESET ========\n"));
136                 break;
137
138                 case WLAN_RESET_ON:
139                         WL_TRACE(("%s: callc customer specific GPIO to remove WLAN RESET\n",
140                                 __FUNCTION__));
141 #ifdef CUSTOMER_HW
142                         bcm_wlan_power_on(2);
143 #endif /* CUSTOMER_HW */
144 #if defined(CUSTOMER_HW2) || defined(CUSTOMER_HW_SAMSUNG)
145                         wifi_set_power(1, 0);
146 #endif
147                         WL_ERROR(("=========== WLAN going back to live  ========\n"));
148                 break;
149
150                 case WLAN_POWER_OFF:
151                         WL_TRACE(("%s: call customer specific GPIO to turn off WL_REG_ON\n",
152                                 __FUNCTION__));
153 #ifdef CUSTOMER_HW
154                         bcm_wlan_power_off(1);
155 #endif /* CUSTOMER_HW */
156                 break;
157
158                 case WLAN_POWER_ON:
159                         WL_TRACE(("%s: call customer specific GPIO to turn on WL_REG_ON\n",
160                                 __FUNCTION__));
161 #ifdef CUSTOMER_HW
162                         bcm_wlan_power_on(1);
163                         /* Lets customer power to get stable */
164                         OSL_DELAY(200);
165 #endif /* CUSTOMER_HW */
166                 break;
167         }
168 }
169
170 #ifdef GET_CUSTOM_MAC_ENABLE
171 /* Function to get custom MAC address */
172 int
173 dhd_custom_get_mac_address(unsigned char *buf)
174 {
175         int ret = 0;
176
177         WL_TRACE(("%s Enter\n", __FUNCTION__));
178         if (!buf)
179                 return -EINVAL;
180
181         /* Customer access to MAC address stored outside of DHD driver */
182 #if defined(CUSTOMER_HW2) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35))
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 */
197
198 /* Customized Locale table : OPTIONAL feature */
199 const struct cntry_locales_custom translate_custom_table[] = {
200 /* Table should be filled out based on custom platform regulatory requirement */
201 #ifdef BCM4334_CHIP
202         {"",   "XZ", 11},  /* Universal if Country code is unknown or empty */
203 #endif
204         {"AE", "AE", 1},
205         {"AR", "AR", 1},
206         {"AT", "AT", 1},
207         {"AU", "AU", 2},
208         {"BE", "BE", 1},
209         {"BG", "BG", 1},
210         {"BN", "BN", 1},
211         {"CA", "CA", 2},
212         {"CH", "CH", 1},
213         {"CN", "CN", 0},
214         {"CY", "CY", 1},
215         {"CZ", "CZ", 1},
216         {"DE", "DE", 3},
217         {"DK", "DK", 1},
218         {"EE", "EE", 1},
219         {"ES", "ES", 1},
220         {"FI", "FI", 1},
221         {"FR", "FR", 1},
222         {"GB", "GB", 1},
223         {"GR", "GR", 1},
224         {"HR", "HR", 1},
225         {"HU", "HU", 1},
226         {"IE", "IE", 1},
227         {"IS", "IS", 1},
228         {"IT", "IT", 1},
229         {"JP", "JP", 5},
230         {"KR", "KR", 24},
231         {"KW", "KW", 1},
232         {"LI", "LI", 1},
233         {"LT", "LT", 1},
234         {"LU", "LU", 1},
235         {"LV", "LV", 1},
236         {"MA", "MA", 1},
237         {"MT", "MT", 1},
238         {"MX", "MX", 1},
239         {"NL", "NL", 1},
240         {"NO", "NO", 1},
241         {"PL", "PL", 1},
242         {"PT", "PT", 1},
243         {"PY", "PY", 1},
244         {"RO", "RO", 1},
245         {"SE", "SE", 1},
246         {"SI", "SI", 1},
247         {"SK", "SK", 1},
248         {"TR", "TR", 7},
249         {"TW", "TW", 2},
250 #ifdef CUSTOMER_HW_SAMSUNG
251         {"IR", "XZ", 11},        /* Universal if Country code is IRAN, (ISLAMIC REPUBLIC OF) */
252         {"SD", "XZ", 11},        /* Universal if Country code is SUDAN */
253         {"SY", "XZ", 11},        /* Universal if Country code is SYRIAN ARAB REPUBLIC */
254         {"GL", "XZ", 11},        /* Universal if Country code is GREENLAND */
255         {"PS", "XZ", 11},        /* Universal if Country code is PALESTINIAN TERRITORY, OCCUPIED */
256         {"TL", "XZ", 11},        /* Universal if Country code is TIMOR-LESTE (EAST TIMOR) */
257         {"MH", "XZ", 11},        /* Universal if Country code is MARSHALL ISLANDS */
258         {"PK", "XZ", 11},        /* Universal if Country code is PAKISTAN*/
259 #endif
260 #ifdef BCM4334_CHIP
261         {"RU", "RU", 5},
262         {"SG", "SG", 4},
263         {"US", "US", 46},
264         {"UA", "UA", 2}
265 #endif
266 #ifdef BCM4330_CHIP
267         {"RU", "RU", 1},
268         {"US", "US", 5}
269 #endif
270 };
271
272
273 /* Customized Locale convertor
274 *  input : ISO 3166-1 country abbreviation
275 *  output: customized cspec
276 */
277 void get_customized_country_code(char *country_iso_code, wl_country_t *cspec)
278 {
279 #ifndef CUSTOMER_HW_SAMSUNG
280         struct cntry_locales_custom *cloc_ptr;
281
282         if (!cspec)
283                 return;
284
285         cloc_ptr = wifi_get_country_code(country_iso_code);
286         if (cloc_ptr) {
287                 strlcpy(cspec->ccode, cloc_ptr->custom_locale, WLC_CNTRY_BUF_SZ);
288                 cspec->rev = cloc_ptr->custom_locale_rev;
289         }
290         return;
291 #else
292         int size, i;
293
294         size = ARRAYSIZE(translate_custom_table);
295
296         if (cspec == 0)
297                  return;
298
299         if (size == 0)
300                  return;
301
302         for (i = 0; i < size; i++) {
303                 if (strcmp(country_iso_code, translate_custom_table[i].iso_abbrev) == 0) {
304                         memcpy(cspec->ccode,
305                                 translate_custom_table[i].custom_locale, WLC_CNTRY_BUF_SZ);
306                         cspec->rev = translate_custom_table[i].custom_locale_rev;
307                         return;
308                 }
309         }
310 #ifdef EXAMPLE_TABLE
311         /* if no country code matched return first universal code from translate_custom_table */
312         memcpy(cspec->ccode, translate_custom_table[0].custom_locale, WLC_CNTRY_BUF_SZ);
313         cspec->rev = translate_custom_table[0].custom_locale_rev;
314 #endif /* EXMAPLE_TABLE */
315         return;
316 #endif /* CUSTOMER_HW_SAMSUNG) */
317 }