Merge branch develop-3.10-next
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rockchip_wlan / rkwifi / bcmdhd / dhd_custom_gpio.c
1 /*
2 * Customer code to add GPIO control during WLAN start/stop
3 * $Copyright Open Broadcom Corporation$
4 *
5 * $Id: dhd_custom_gpio.c 493822 2014-07-29 13:20:26Z $
6 */
7
8 #include <typedefs.h>
9 #include <linuxver.h>
10 #include <osl.h>
11 #include <bcmutils.h>
12 #include <dngl_stats.h>
13 #include <dhd.h>
14 #include <dhd_linux.h>
15
16 #include <wlioctl.h>
17 #include <wl_iw.h>
18
19 #define WL_ERROR(x) printf x
20 #define WL_TRACE(x)
21
22 #if defined(CUSTOMER_HW2)
23
24 #if defined(PLATFORM_MPS)
25 int __attribute__ ((weak)) wifi_get_fw_nv_path(char *fw, char *nv) { return 0;};
26 #endif
27
28 #endif 
29
30 #if defined(OOB_INTR_ONLY)
31
32 #if defined(BCMLXSDMMC)
33 extern int sdioh_mmc_irq(int irq);
34 #endif /* (BCMLXSDMMC)  */
35
36 #if defined(CUSTOMER_HW3) || defined(PLATFORM_MPS)
37 #include <mach/gpio.h>
38 #endif
39
40 /* Customer specific Host GPIO defintion  */
41 static int dhd_oob_gpio_num = -1;
42
43 module_param(dhd_oob_gpio_num, int, 0644);
44 MODULE_PARM_DESC(dhd_oob_gpio_num, "DHD oob gpio number");
45
46 /* This function will return:
47  *  1) return :  Host gpio interrupt number per customer platform
48  *  2) irq_flags_ptr : Type of Host interrupt as Level or Edge
49  *
50  *  NOTE :
51  *  Customer should check his platform definitions
52  *  and his Host Interrupt spec
53  *  to figure out the proper setting for his platform.
54  *  Broadcom provides just reference settings as example.
55  *
56  */
57 int dhd_customer_oob_irq_map(void *adapter, unsigned long *irq_flags_ptr)
58 {
59         int  host_oob_irq = 0;
60
61 #if defined(CUSTOMER_HW2) && !defined(PLATFORM_MPS)
62         host_oob_irq = wifi_platform_get_irq_number(adapter, irq_flags_ptr);
63
64 #else
65 #if defined(CUSTOM_OOB_GPIO_NUM)
66         if (dhd_oob_gpio_num < 0) {
67                 dhd_oob_gpio_num = CUSTOM_OOB_GPIO_NUM;
68         }
69 #endif /* CUSTOMER_OOB_GPIO_NUM */
70
71         if (dhd_oob_gpio_num < 0) {
72                 WL_ERROR(("%s: ERROR customer specific Host GPIO is NOT defined \n",
73                 __FUNCTION__));
74                 return (dhd_oob_gpio_num);
75         }
76
77         WL_ERROR(("%s: customer specific Host GPIO number is (%d)\n",
78                  __FUNCTION__, dhd_oob_gpio_num));
79
80 #if defined CUSTOMER_HW3 || defined(PLATFORM_MPS)
81         gpio_request(dhd_oob_gpio_num, "oob irq");
82         host_oob_irq = gpio_to_irq(dhd_oob_gpio_num);
83         gpio_direction_input(dhd_oob_gpio_num);
84 #endif /* defined CUSTOMER_HW3 || defined(PLATFORM_MPS) */
85 #endif 
86
87         return (host_oob_irq);
88 }
89 #endif 
90
91 /* Customer function to control hw specific wlan gpios */
92 int
93 dhd_customer_gpio_wlan_ctrl(void *adapter, int onoff)
94 {
95         int err = 0;
96
97         return err;
98 }
99
100 #ifdef GET_CUSTOM_MAC_ENABLE
101 /* Function to get custom MAC address */
102 int
103 dhd_custom_get_mac_address(void *adapter, unsigned char *buf)
104 {
105         int ret = 0;
106
107         WL_TRACE(("%s Enter\n", __FUNCTION__));
108         if (!buf)
109                 return -EINVAL;
110
111         /* Customer access to MAC address stored outside of DHD driver */
112 #if (defined(CUSTOMER_HW2) || defined(CUSTOMER_HW10)) && (LINUX_VERSION_CODE >= \
113         KERNEL_VERSION(2, 6, 35))
114         ret = wifi_platform_get_mac_addr(adapter, buf);
115 #endif
116
117 #ifdef EXAMPLE_GET_MAC
118         /* EXAMPLE code */
119         {
120                 struct ether_addr ea_example = {{0x00, 0x11, 0x22, 0x33, 0x44, 0xFF}};
121                 bcopy((char *)&ea_example, buf, sizeof(struct ether_addr));
122         }
123 #endif /* EXAMPLE_GET_MAC */
124
125         return ret;
126 }
127 #endif /* GET_CUSTOM_MAC_ENABLE */
128
129 /* Customized Locale table : OPTIONAL feature */
130 const struct cntry_locales_custom translate_custom_table[] = {
131 /* Table should be filled out based on custom platform regulatory requirement */
132 #ifdef EXAMPLE_TABLE
133         {"",   "XY", 4},  /* Universal if Country code is unknown or empty */
134         {"US", "US", 69}, /* input ISO "US" to : US regrev 69 */
135         {"CA", "US", 69}, /* input ISO "CA" to : US regrev 69 */
136         {"EU", "EU", 5},  /* European union countries to : EU regrev 05 */
137         {"AT", "EU", 5},
138         {"BE", "EU", 5},
139         {"BG", "EU", 5},
140         {"CY", "EU", 5},
141         {"CZ", "EU", 5},
142         {"DK", "EU", 5},
143         {"EE", "EU", 5},
144         {"FI", "EU", 5},
145         {"FR", "EU", 5},
146         {"DE", "EU", 5},
147         {"GR", "EU", 5},
148         {"HU", "EU", 5},
149         {"IE", "EU", 5},
150         {"IT", "EU", 5},
151         {"LV", "EU", 5},
152         {"LI", "EU", 5},
153         {"LT", "EU", 5},
154         {"LU", "EU", 5},
155         {"MT", "EU", 5},
156         {"NL", "EU", 5},
157         {"PL", "EU", 5},
158         {"PT", "EU", 5},
159         {"RO", "EU", 5},
160         {"SK", "EU", 5},
161         {"SI", "EU", 5},
162         {"ES", "EU", 5},
163         {"SE", "EU", 5},
164         {"GB", "EU", 5},
165         {"KR", "XY", 3},
166         {"AU", "XY", 3},
167         {"CN", "XY", 3}, /* input ISO "CN" to : XY regrev 03 */
168         {"TW", "XY", 3},
169         {"AR", "XY", 3},
170         {"MX", "XY", 3},
171         {"IL", "IL", 0},
172         {"CH", "CH", 0},
173         {"TR", "TR", 0},
174         {"NO", "NO", 0},
175 #endif /* EXMAPLE_TABLE */
176 #if defined(CUSTOMER_HW2) && !defined(CUSTOMER_HW5)
177 #if defined(BCM4335_CHIP)
178         {"",   "XZ", 11},  /* Universal if Country code is unknown or empty */
179 #endif
180         {"AE", "AE", 1},
181         {"AR", "AR", 1},
182         {"AT", "AT", 1},
183         {"AU", "AU", 2},
184         {"BE", "BE", 1},
185         {"BG", "BG", 1},
186         {"BN", "BN", 1},
187         {"CA", "CA", 2},
188         {"CH", "CH", 1},
189         {"CY", "CY", 1},
190         {"CZ", "CZ", 1},
191         {"DE", "DE", 3},
192         {"DK", "DK", 1},
193         {"EE", "EE", 1},
194         {"ES", "ES", 1},
195         {"FI", "FI", 1},
196         {"FR", "FR", 1},
197         {"GB", "GB", 1},
198         {"GR", "GR", 1},
199         {"HR", "HR", 1},
200         {"HU", "HU", 1},
201         {"IE", "IE", 1},
202         {"IS", "IS", 1},
203         {"IT", "IT", 1},
204         {"ID", "ID", 1},
205         {"JP", "JP", 8},
206         {"KR", "KR", 24},
207         {"KW", "KW", 1},
208         {"LI", "LI", 1},
209         {"LT", "LT", 1},
210         {"LU", "LU", 1},
211         {"LV", "LV", 1},
212         {"MA", "MA", 1},
213         {"MT", "MT", 1},
214         {"MX", "MX", 1},
215         {"NL", "NL", 1},
216         {"NO", "NO", 1},
217         {"PL", "PL", 1},
218         {"PT", "PT", 1},
219         {"PY", "PY", 1},
220         {"RO", "RO", 1},
221         {"SE", "SE", 1},
222         {"SI", "SI", 1},
223         {"SK", "SK", 1},
224         {"TR", "TR", 7},
225         {"TW", "TW", 1},
226         {"IR", "XZ", 11},       /* Universal if Country code is IRAN, (ISLAMIC REPUBLIC OF) */
227         {"SD", "XZ", 11},       /* Universal if Country code is SUDAN */
228         {"SY", "XZ", 11},       /* Universal if Country code is SYRIAN ARAB REPUBLIC */
229         {"GL", "XZ", 11},       /* Universal if Country code is GREENLAND */
230         {"PS", "XZ", 11},       /* Universal if Country code is PALESTINIAN TERRITORY, OCCUPIED */
231         {"TL", "XZ", 11},       /* Universal if Country code is TIMOR-LESTE (EAST TIMOR) */
232         {"MH", "XZ", 11},       /* Universal if Country code is MARSHALL ISLANDS */
233 #ifdef BCM4330_CHIP
234         {"RU", "RU", 1},
235         {"US", "US", 5}
236 #endif
237
238 #elif defined(CUSTOMER_HW5)
239         {"",   "XZ", 11},
240         {"AE", "AE", 212},
241         {"AG", "AG", 2},
242         {"AI", "AI", 2},
243         {"AL", "AL", 2},
244         {"AN", "AN", 3},
245         {"AR", "AR", 212},
246         {"AS", "AS", 15},
247         {"AT", "AT", 4},
248         {"AU", "AU", 212},
249         {"AW", "AW", 2},
250         {"AZ", "AZ", 2},
251         {"BA", "BA", 2},
252         {"BD", "BD", 2},
253         {"BE", "BE", 4},
254         {"BG", "BG", 4},
255         {"BH", "BH", 4},
256         {"BM", "BM", 15},
257         {"BN", "BN", 4},
258         {"BR", "BR", 212},
259         {"BS", "BS", 2},
260         {"BY", "BY", 3},
261         {"BW", "BW", 1},
262         {"CA", "CA", 212},
263         {"CH", "CH", 212},
264         {"CL", "CL", 212},
265         {"CN", "CN", 212},
266         {"CO", "CO", 212},
267         {"CR", "CR", 21},
268         {"CY", "CY", 212},
269         {"CZ", "CZ", 212},
270         {"DE", "DE", 212},
271         {"DK", "DK", 4},
272         {"DZ", "DZ", 1},
273         {"EC", "EC", 23},
274         {"EE", "EE", 4},
275         {"EG", "EG", 212},
276         {"ES", "ES", 212},
277         {"ET", "ET", 2},
278         {"FI", "FI", 4},
279         {"FR", "FR", 212},
280         {"GB", "GB", 212},
281         {"GD", "GD", 2},
282         {"GF", "GF", 2},
283         {"GP", "GP", 2},
284         {"GR", "GR", 212},
285         {"GT", "GT", 0},
286         {"GU", "GU", 17},
287         {"HK", "HK", 212},
288         {"HR", "HR", 4},
289         {"HU", "HU", 4},
290         {"IN", "IN", 212},
291         {"ID", "ID", 212},
292         {"IE", "IE", 5},
293         {"IL", "IL", 7},
294         {"IN", "IN", 212},
295         {"IS", "IS", 4},
296         {"IT", "IT", 212},
297         {"JO", "JO", 3},
298         {"JP", "JP", 212},
299         {"KH", "KH", 4},
300         {"KI", "KI", 1},
301         {"KR", "KR", 212},
302         {"KW", "KW", 5},
303         {"KY", "KY", 4},
304         {"KZ", "KZ", 212},
305         {"LA", "LA", 4},
306         {"LB", "LB", 6},
307         {"LI", "LI", 4},
308         {"LK", "LK", 3},
309         {"LS", "LS", 2},
310         {"LT", "LT", 4},
311         {"LR", "LR", 2},
312         {"LU", "LU", 3},
313         {"LV", "LV", 4},
314         {"MA", "MA", 2},
315         {"MC", "MC", 1},
316         {"MD", "MD", 2},
317         {"ME", "ME", 2},
318         {"MK", "MK", 2},
319         {"MN", "MN", 0},
320         {"MO", "MO", 2},
321         {"MR", "MR", 2},
322         {"MT", "MT", 4},
323         {"MQ", "MQ", 2},
324         {"MU", "MU", 2},
325         {"MV", "MV", 3},
326         {"MX", "MX", 212},
327         {"MY", "MY", 212},
328         {"NI", "NI", 0},
329         {"NL", "NL", 212},
330         {"NO", "NO", 4},
331         {"NP", "NP", 3},
332         {"NZ", "NZ", 9},
333         {"OM", "OM", 4},
334         {"PA", "PA", 17},
335         {"PE", "PE", 212},
336         {"PG", "PG", 2},
337         {"PH", "PH", 212},
338         {"PL", "PL", 212},
339         {"PR", "PR", 25},
340         {"PT", "PT", 212},
341         {"PY", "PY", 4},
342         {"RE", "RE", 2},
343         {"RO", "RO", 212},
344         {"RS", "RS", 2},
345         {"RU", "RU", 212},
346         {"SA", "SA", 212},
347         {"SE", "SE", 212},
348         {"SG", "SG", 212},
349         {"SI", "SI", 4},
350         {"SK", "SK", 212},
351         {"SN", "SN", 2},
352         {"SV", "SV", 25},
353         {"TH", "TH", 212},
354         {"TR", "TR", 212},
355         {"TT", "TT", 5},
356         {"TW", "TW", 212},
357         {"UA", "UA", 212},
358         {"UG", "UG", 2},
359         {"US", "US", 212},
360         {"UY", "UY", 5},
361         {"VA", "VA", 2},
362         {"VE", "VE", 3},
363         {"VG", "VG", 2},
364         {"VI", "VI", 18},
365         {"VN", "VN", 4},
366         {"YT", "YT", 2},
367         {"ZA", "ZA", 212},
368         {"ZM", "ZM", 2},
369         {"XT", "XT", 212},
370         {"XZ", "XZ", 11},
371         {"XV", "XV", 17},
372         {"Q1", "Q1", 77},
373 #endif /* CUSTOMER_HW2 and  CUSTOMER_HW5 */
374 };
375
376
377 /* Customized Locale convertor
378 *  input : ISO 3166-1 country abbreviation
379 *  output: customized cspec
380 */
381 void get_customized_country_code(void *adapter, char *country_iso_code, wl_country_t *cspec)
382 {
383 #if defined(CUSTOMER_HW2) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 39))
384
385         struct cntry_locales_custom *cloc_ptr;
386
387         if (!cspec)
388                 return;
389
390         cloc_ptr = wifi_platform_get_country_code(adapter, country_iso_code);
391         if (cloc_ptr) {
392                 strlcpy(cspec->ccode, cloc_ptr->custom_locale, WLC_CNTRY_BUF_SZ);
393                 cspec->rev = cloc_ptr->custom_locale_rev;
394         }
395         return;
396 #else
397         int size, i;
398
399         size = ARRAYSIZE(translate_custom_table);
400
401         if (cspec == 0)
402                  return;
403
404         if (size == 0)
405                  return;
406
407         for (i = 0; i < size; i++) {
408                 if (strcmp(country_iso_code, translate_custom_table[i].iso_abbrev) == 0) {
409                         memcpy(cspec->ccode,
410                                 translate_custom_table[i].custom_locale, WLC_CNTRY_BUF_SZ);
411                         cspec->rev = translate_custom_table[i].custom_locale_rev;
412                         return;
413                 }
414         }
415 #ifdef EXAMPLE_TABLE
416         /* if no country code matched return first universal code from translate_custom_table */
417         memcpy(cspec->ccode, translate_custom_table[0].custom_locale, WLC_CNTRY_BUF_SZ);
418         cspec->rev = translate_custom_table[0].custom_locale_rev;
419 #endif /* EXMAPLE_TABLE */
420         return;
421 #endif /* defined(CUSTOMER_HW2) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 36)) */
422 }