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