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