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