1 /*
2 * Customer code to add GPIO control during WLAN start/stop
3 *
4 * Portions of this code are copyright (c) 2021 Cypress Semiconductor Corporation
5 *
6 * Copyright (C) 1999-2017, Broadcom Corporation
7 *
8 * Unless you and Broadcom execute a separate written software license
9 * agreement governing use of this software, this software is licensed to you
10 * under the terms of the GNU General Public License version 2 (the "GPL"),
11 * available at http://www.broadcom.com/licenses/GPLv2.php, with the
12 * following added to such license:
13 *
14 * As a special exception, the copyright holders of this software give you
15 * permission to link this software with independent modules, and to copy and
16 * distribute the resulting executable under terms of your choice, provided that
17 * you also meet, for each linked independent module, the terms and conditions of
18 * the license of that module. An independent module is a module which is not
19 * derived from this software. The special exception does not apply to any
20 * modifications of the software.
21 *
22 * Notwithstanding the above, under no circumstances may you combine this
23 * software in any way with any other Broadcom software provided under a license
24 * other than the GPL, without Broadcom's express prior written consent.
25 *
26 *
27 * <<Broadcom-WL-IPTag/Open:>>
28 *
29 * $Id: dhd_custom_gpio.c 691191 2017-03-21 07:09:04Z $
30 */
31
32 #include <typedefs.h>
33 #include <linuxver.h>
34 #include <osl.h>
35 #include <bcmutils.h>
36 #include <dngl_stats.h>
37 #include <dhd.h>
38 #include <dhd_linux.h>
39
40 #include <wlioctl.h>
41 #if defined(WL_WIRELESS_EXT)
42 #include <wl_iw.h>
43 #endif // endif
44
45 #define WL_ERROR(x) printf x
46 #define WL_TRACE(x)
47
48 #if defined(OOB_INTR_ONLY) || defined(BCMSPI_ANDROID)
49
50 #if defined(BCMLXSDMMC)
51 extern int sdioh_mmc_irq(int irq);
52 #endif /* (BCMLXSDMMC) */
53
54 /* Customer specific Host GPIO defintion */
55 static int dhd_oob_gpio_num = -1;
56
57 module_param(dhd_oob_gpio_num, int, 0644);
58 MODULE_PARM_DESC(dhd_oob_gpio_num, "DHD oob gpio number");
59
60 /* This function will return:
61 * 1) return : Host gpio interrupt number per customer platform
62 * 2) irq_flags_ptr : Type of Host interrupt as Level or Edge
63 *
64 * NOTE :
65 * Customer should check his platform definitions
66 * and his Host Interrupt spec
67 * to figure out the proper setting for his platform.
68 * Broadcom provides just reference settings as example.
69 *
70 */
dhd_customer_oob_irq_map(void * adapter,unsigned long * irq_flags_ptr)71 int dhd_customer_oob_irq_map(void *adapter, unsigned long *irq_flags_ptr)
72 {
73 int host_oob_irq = 0;
74
75 #if defined(CUSTOMER_HW2) || defined(BOARD_HIKEY)
76 host_oob_irq = wifi_platform_get_irq_number(adapter, irq_flags_ptr);
77
78 #else
79 #if defined(CUSTOM_OOB_GPIO_NUM)
80 if (dhd_oob_gpio_num < 0) {
81 dhd_oob_gpio_num = CUSTOM_OOB_GPIO_NUM;
82 }
83 #endif /* CUSTOMER_OOB_GPIO_NUM */
84
85 if (dhd_oob_gpio_num < 0) {
86 WL_ERROR(("%s: ERROR customer specific Host GPIO is NOT defined \n",
87 __FUNCTION__));
88 return (dhd_oob_gpio_num);
89 }
90
91 WL_ERROR(("%s: customer specific Host GPIO number is (%d)\n",
92 __FUNCTION__, dhd_oob_gpio_num));
93
94 #endif // endif
95
96 return (host_oob_irq);
97 }
98 #endif /* defined(OOB_INTR_ONLY) || defined(BCMSPI_ANDROID) */
99
100 /* Customer function to control hw specific wlan gpios */
101 int
dhd_customer_gpio_wlan_ctrl(void * adapter,int onoff)102 dhd_customer_gpio_wlan_ctrl(void *adapter, int onoff)
103 {
104 int err = 0;
105
106 return err;
107 }
108
109 #ifdef GET_CUSTOM_MAC_ENABLE
110 /* Function to get custom MAC address */
111 int
dhd_custom_get_mac_address(void * adapter,unsigned char * buf)112 dhd_custom_get_mac_address(void *adapter, unsigned char *buf)
113 {
114 int ret = 0;
115
116 WL_TRACE(("%s Enter\n", __FUNCTION__));
117 if (!buf)
118 return -EINVAL;
119
120 /* Customer access to MAC address stored outside of DHD driver */
121 #if (defined(CUSTOMER_HW2) || defined(BOARD_HIKEY)) && (LINUX_VERSION_CODE >= \
122 KERNEL_VERSION(2, 6, 35))
123 ret = wifi_platform_get_mac_addr(adapter, buf);
124 #endif // endif
125
126 #ifdef EXAMPLE_GET_MAC
127 /* EXAMPLE code */
128 {
129 struct ether_addr ea_example = {{0x00, 0x11, 0x22, 0x33, 0x44, 0xFF}};
130 bcopy((char *)&ea_example, buf, sizeof(struct ether_addr));
131 }
132 #endif /* EXAMPLE_GET_MAC */
133
134 return ret;
135 }
136 #endif /* GET_CUSTOM_MAC_ENABLE */
137
138 /* Customized Locale table : OPTIONAL feature */
139 const struct cntry_locales_custom translate_custom_table[] = {
140 /* Table should be filled out based on custom platform regulatory requirement */
141 #ifdef EXAMPLE_TABLE
142 {"", "XY", 4}, /* Universal if Country code is unknown or empty */
143 {"US", "US", 69}, /* input ISO "US" to : US regrev 69 */
144 {"CA", "US", 69}, /* input ISO "CA" to : US regrev 69 */
145 {"EU", "EU", 5}, /* European union countries to : EU regrev 05 */
146 {"AT", "EU", 5},
147 {"BE", "EU", 5},
148 {"BG", "EU", 5},
149 {"CY", "EU", 5},
150 {"CZ", "EU", 5},
151 {"DK", "EU", 5},
152 {"EE", "EU", 5},
153 {"FI", "EU", 5},
154 {"FR", "EU", 5},
155 {"DE", "EU", 5},
156 {"GR", "EU", 5},
157 {"HU", "EU", 5},
158 {"IE", "EU", 5},
159 {"IT", "EU", 5},
160 {"LV", "EU", 5},
161 {"LI", "EU", 5},
162 {"LT", "EU", 5},
163 {"LU", "EU", 5},
164 {"MT", "EU", 5},
165 {"NL", "EU", 5},
166 {"PL", "EU", 5},
167 {"PT", "EU", 5},
168 {"RO", "EU", 5},
169 {"SK", "EU", 5},
170 {"SI", "EU", 5},
171 {"ES", "EU", 5},
172 {"SE", "EU", 5},
173 {"GB", "EU", 5},
174 {"KR", "XY", 3},
175 {"AU", "XY", 3},
176 {"CN", "XY", 3}, /* input ISO "CN" to : XY regrev 03 */
177 {"TW", "XY", 3},
178 {"AR", "XY", 3},
179 {"MX", "XY", 3},
180 {"IL", "IL", 0},
181 {"CH", "CH", 0},
182 {"TR", "TR", 0},
183 {"NO", "NO", 0},
184 #endif /* EXMAPLE_TABLE */
185 #if (defined(CUSTOMER_HW2) || defined(BOARD_HIKEY))
186 #if defined(BCM4335_CHIP)
187 {"", "XZ", 11}, /* Universal if Country code is unknown or empty */
188 #endif // endif
189 {"AE", "AE", 1},
190 {"AR", "AR", 1},
191 {"AT", "AT", 1},
192 {"AU", "AU", 2},
193 {"BE", "BE", 1},
194 {"BG", "BG", 1},
195 {"BN", "BN", 1},
196 {"CA", "CA", 2},
197 {"CH", "CH", 1},
198 {"CY", "CY", 1},
199 {"CZ", "CZ", 1},
200 {"DE", "DE", 3},
201 {"DK", "DK", 1},
202 {"EE", "EE", 1},
203 {"ES", "ES", 1},
204 {"FI", "FI", 1},
205 {"FR", "FR", 1},
206 {"GB", "GB", 1},
207 {"GR", "GR", 1},
208 {"HR", "HR", 1},
209 {"HU", "HU", 1},
210 {"IE", "IE", 1},
211 {"IS", "IS", 1},
212 {"IT", "IT", 1},
213 {"ID", "ID", 1},
214 {"JP", "JP", 8},
215 {"KR", "KR", 24},
216 {"KW", "KW", 1},
217 {"LI", "LI", 1},
218 {"LT", "LT", 1},
219 {"LU", "LU", 1},
220 {"LV", "LV", 1},
221 {"MA", "MA", 1},
222 {"MT", "MT", 1},
223 {"MX", "MX", 1},
224 {"NL", "NL", 1},
225 {"NO", "NO", 1},
226 {"PL", "PL", 1},
227 {"PT", "PT", 1},
228 {"PY", "PY", 1},
229 {"RO", "RO", 1},
230 {"SE", "SE", 1},
231 {"SI", "SI", 1},
232 {"SK", "SK", 1},
233 {"TR", "TR", 7},
234 {"TW", "TW", 1},
235 {"IR", "XZ", 11}, /* Universal if Country code is IRAN, (ISLAMIC REPUBLIC OF) */
236 {"SD", "XZ", 11}, /* Universal if Country code is SUDAN */
237 {"SY", "XZ", 11}, /* Universal if Country code is SYRIAN ARAB REPUBLIC */
238 {"GL", "XZ", 11}, /* Universal if Country code is GREENLAND */
239 {"PS", "XZ", 11}, /* Universal if Country code is PALESTINIAN TERRITORY, OCCUPIED */
240 {"TL", "XZ", 11}, /* Universal if Country code is TIMOR-LESTE (EAST TIMOR) */
241 {"MH", "XZ", 11}, /* Universal if Country code is MARSHALL ISLANDS */
242 #endif // endif
243 };
244
245 /* Customized Locale convertor
246 * input : ISO 3166-1 country abbreviation
247 * output: customized cspec
248 */
249 #ifdef CUSTOM_COUNTRY_CODE
get_customized_country_code(void * adapter,char * country_iso_code,wl_country_t * cspec,u32 flags)250 void get_customized_country_code(void *adapter, char *country_iso_code,
251 wl_country_t *cspec, u32 flags)
252 #else
253 void get_customized_country_code(void *adapter, char *country_iso_code, wl_country_t *cspec)
254 #endif /* CUSTOM_COUNTRY_CODE */
255 {
256 #if defined(OEM_ANDROID)
257 #if (defined(CUSTOMER_HW2) || defined(BOARD_HIKEY)) && (LINUX_VERSION_CODE >= \
258 KERNEL_VERSION(2, 6, 39))
259
260 struct cntry_locales_custom *cloc_ptr;
261
262 if (!cspec)
263 return;
264 #ifdef CUSTOM_COUNTRY_CODE
265 cloc_ptr = wifi_platform_get_country_code(adapter, country_iso_code, flags);
266 #else
267 cloc_ptr = wifi_platform_get_country_code(adapter, country_iso_code);
268 #endif /* CUSTOM_COUNTRY_CODE */
269
270 if (cloc_ptr) {
271 strlcpy(cspec->ccode, cloc_ptr->custom_locale, WLC_CNTRY_BUF_SZ);
272 cspec->rev = cloc_ptr->custom_locale_rev;
273 }
274 return;
275 #else
276 int size, i;
277
278 size = ARRAYSIZE(translate_custom_table);
279
280 if (cspec == 0)
281 return;
282
283 if (size == 0)
284 return;
285
286 for (i = 0; i < size; i++) {
287 if (strcmp(country_iso_code, translate_custom_table[i].iso_abbrev) == 0) {
288 memcpy(cspec->ccode,
289 translate_custom_table[i].custom_locale, WLC_CNTRY_BUF_SZ);
290 cspec->rev = translate_custom_table[i].custom_locale_rev;
291 return;
292 }
293 }
294 #ifdef EXAMPLE_TABLE
295 /* if no country code matched return first universal code from translate_custom_table */
296 memcpy(cspec->ccode, translate_custom_table[0].custom_locale, WLC_CNTRY_BUF_SZ);
297 cspec->rev = translate_custom_table[0].custom_locale_rev;
298 #endif /* EXMAPLE_TABLE */
299 return;
300 #endif /* (defined(CUSTOMER_HW2) || defined(BOARD_HIKEY)) &&
301 * (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 36))
302 */
303 #endif /* OEM_ANDROID */
304 }
305