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