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