PageRenderTime 37ms CodeModel.GetById 29ms app.highlight 6ms RepoModel.GetById 0ms app.codeStats 0ms

/drivers/net/wireless/bcm4329/dhd_custom_gpio.c

https://bitbucket.org/cyanogenmod/android_kernel_asus_tf300t
C | 285 lines | 211 code | 36 blank | 38 comment | 13 complexity | 3cfcca556ee71d4e2b7179415f7b9427 MD5 | raw file
Possible License(s): LGPL-2.0, AGPL-1.0, GPL-2.0
  1/*
  2* Customer code to add GPIO control during WLAN start/stop
  3* Copyright (C) 1999-2010, 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,v 1.1.4.8.4.4 2011/01/20 20:23:09 Exp $
 24*/
 25
 26
 27#include <typedefs.h>
 28#include <linuxver.h>
 29#include <osl.h>
 30#include <bcmutils.h>
 31
 32#include <dngl_stats.h>
 33#include <dhd.h>
 34
 35#include <wlioctl.h>
 36#include <wl_iw.h>
 37
 38#define WL_ERROR(x) printf x
 39#define WL_TRACE(x)
 40
 41#ifdef CUSTOMER_HW
 42extern  void bcm_wlan_power_off(int);
 43extern  void bcm_wlan_power_on(int);
 44#endif /* CUSTOMER_HW */
 45#ifdef CUSTOMER_HW2
 46int wifi_set_carddetect(int on);
 47int wifi_set_power(int on, unsigned long msec);
 48int wifi_get_irq_number(unsigned long *irq_flags_ptr);
 49int wifi_get_mac_addr(unsigned char *buf);
 50void *wifi_get_country_code(char *ccode);
 51#endif
 52
 53#if defined(OOB_INTR_ONLY)
 54
 55#if defined(BCMLXSDMMC)
 56extern int sdioh_mmc_irq(int irq);
 57#endif /* (BCMLXSDMMC)  */
 58
 59#ifdef CUSTOMER_HW3
 60#include <mach/gpio.h>
 61#endif
 62
 63/* Customer specific Host GPIO defintion  */
 64static int dhd_oob_gpio_num = -1; /* GG 19 */
 65
 66module_param(dhd_oob_gpio_num, int, 0644);
 67MODULE_PARM_DESC(dhd_oob_gpio_num, "DHD oob gpio number");
 68
 69int dhd_customer_oob_irq_map(unsigned long *irq_flags_ptr)
 70{
 71	int  host_oob_irq = 0;
 72
 73#ifdef CUSTOMER_HW2
 74	host_oob_irq = wifi_get_irq_number(irq_flags_ptr);
 75
 76#else /* for NOT  CUSTOMER_HW2 */
 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
 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#if defined CUSTOMER_HW
 93	host_oob_irq = MSM_GPIO_TO_INT(dhd_oob_gpio_num);
 94#elif defined CUSTOMER_HW3
 95	gpio_request(dhd_oob_gpio_num, "oob irq");
 96	host_oob_irq = gpio_to_irq(dhd_oob_gpio_num);
 97	gpio_direction_input(dhd_oob_gpio_num);
 98#endif /* CUSTOMER_HW */
 99#endif /* CUSTOMER_HW2 */
100
101	return (host_oob_irq);
102}
103#endif /* defined(OOB_INTR_ONLY) */
104
105/* Customer function to control hw specific wlan gpios */
106void
107dhd_customer_gpio_wlan_ctrl(int onoff)
108{
109	switch (onoff) {
110		case WLAN_RESET_OFF:
111			WL_TRACE(("%s: call customer specific GPIO to insert WLAN RESET\n",
112				__FUNCTION__));
113#ifdef CUSTOMER_HW
114			bcm_wlan_power_off(2);
115#endif /* CUSTOMER_HW */
116#ifdef CUSTOMER_HW2
117			wifi_set_power(0, 0);
118#endif
119			WL_ERROR(("=========== WLAN placed in RESET ========\n"));
120		break;
121
122		case WLAN_RESET_ON:
123			WL_TRACE(("%s: callc customer specific GPIO to remove WLAN RESET\n",
124				__FUNCTION__));
125#ifdef CUSTOMER_HW
126			bcm_wlan_power_on(2);
127#endif /* CUSTOMER_HW */
128#ifdef CUSTOMER_HW2
129			wifi_set_power(1, 0);
130#endif
131			WL_ERROR(("=========== WLAN going back to live  ========\n"));
132		break;
133
134		case WLAN_POWER_OFF:
135			WL_TRACE(("%s: call customer specific GPIO to turn off WL_REG_ON\n",
136				__FUNCTION__));
137#ifdef CUSTOMER_HW
138			bcm_wlan_power_off(1);
139#endif /* CUSTOMER_HW */
140		break;
141
142		case WLAN_POWER_ON:
143			WL_TRACE(("%s: call customer specific GPIO to turn on WL_REG_ON\n",
144				__FUNCTION__));
145#ifdef CUSTOMER_HW
146			bcm_wlan_power_on(1);
147			/* Lets customer power to get stable */
148			OSL_DELAY(50);
149#endif /* CUSTOMER_HW */
150		break;
151	}
152}
153
154#ifdef GET_CUSTOM_MAC_ENABLE
155/* Function to get custom MAC address */
156int
157dhd_custom_get_mac_address(unsigned char *buf)
158{
159	int ret = 0;
160
161	WL_TRACE(("%s Enter\n", __FUNCTION__));
162	if (!buf)
163		return -EINVAL;
164
165	/* Customer access to MAC address stored outside of DHD driver */
166#ifdef CUSTOMER_HW2
167	ret = wifi_get_mac_addr(buf);
168#endif
169
170#ifdef EXAMPLE_GET_MAC
171	/* EXAMPLE code */
172	{
173		struct ether_addr ea_example = {{0x00, 0x11, 0x22, 0x33, 0x44, 0xFF}};
174		bcopy((char *)&ea_example, buf, sizeof(struct ether_addr));
175	}
176#endif /* EXAMPLE_GET_MAC */
177
178	return ret;
179}
180#endif /* GET_CUSTOM_MAC_ENABLE */
181
182#define EXAMPLE_TABLE
183/* Customized Locale table : OPTIONAL feature */
184const struct cntry_locales_custom translate_custom_table[] = {
185/* Table should be filled out based on custom platform regulatory requirement */
186#ifdef EXAMPLE_TABLE
187	{"",   "XY", 4},  /* Universal if Country code is unknown or empty */
188	{"EU", "EU", 5},  /* European union countries to : EU regrev 05 */
189	{"AT", "EU", 5},
190	{"BE", "EU", 5},
191	{"BG", "EU", 5},
192	{"CY", "EU", 5},
193	{"CZ", "EU", 5},
194	{"DK", "EU", 5},
195	{"EE", "EU", 5},
196	{"FI", "EU", 5},
197	{"FR", "EU", 5},
198	{"DE", "EU", 5},
199	{"GR", "EU", 5},
200	{"HU", "EU", 5},
201	{"IE", "EU", 5},
202	{"IT", "EU", 5},
203	{"LV", "EU", 5},
204	{"LI", "EU", 5},
205	{"LT", "EU", 5},
206	{"LU", "EU", 5},
207	{"MT", "EU", 5},
208	{"NL", "EU", 5},
209	{"PL", "EU", 5},
210	{"PT", "EU", 5},
211	{"RO", "EU", 5},
212	{"SK", "EU", 5},
213	{"SI", "EU", 5},
214	{"ES", "EU", 5},
215	{"SE", "EU", 5},
216	{"GB", "EU", 5},
217	{"IL", "IL", 0},
218	{"CH", "CH", 0},
219	{"TR", "TR", 0},
220	{"NO", "NO", 0},
221	{"KR", "XY", 3},
222	{"AU", "XY", 3},
223	{"CN", "XY", 3},  /* input ISO "CN" to : XY regrev 03 */
224	{"AR", "XY", 3},
225	{"MX", "XY", 3},
226	{"AS", "US", 69},
227	{"CA", "US", 69}, /* input ISO "CA" to : US regrev 69 */
228	{"KY", "US", 69},
229	{"GU", "US", 69},
230	{"FM", "US", 69},
231	{"MP", "US", 69},
232	{"PR", "US", 69},
233	{"TW", "US", 69},
234	{"VI", "US", 69},
235	{"UM", "US", 69},
236	{"US", "US", 69}  /* input ISO "US" to : US regrev 69 */
237#endif /* EXAMPLE_TABLE */
238};
239
240
241/* Customized Locale convertor
242*  input : ISO 3166-1 country abbreviation
243*  output: customized cspec
244*/
245void get_customized_country_code(char *country_iso_code, wl_country_t *cspec)
246{
247//#ifdef CUSTOMER_HW2
248#if 0  // Use Broadcom country code table
249	struct cntry_locales_custom *cloc_ptr;
250
251	if (!cspec)
252		return;
253
254	cloc_ptr = wifi_get_country_code(country_iso_code);
255	if (cloc_ptr) {
256		strlcpy(cspec->ccode, cloc_ptr->custom_locale, WLC_CNTRY_BUF_SZ);
257		cspec->rev = cloc_ptr->custom_locale_rev;
258	}
259	return;
260#else
261	int size, i;
262
263	size = ARRAYSIZE(translate_custom_table);
264
265	if (cspec == 0)
266		return;
267
268	if (size == 0)
269		return;
270
271	for (i = 0; i < size; i++) {
272		if (strcmp(country_iso_code, translate_custom_table[i].iso_abbrev) == 0) {
273			memcpy(cspec->ccode, translate_custom_table[i].custom_locale, WLC_CNTRY_BUF_SZ);
274			cspec->rev = translate_custom_table[i].custom_locale_rev;
275			return;
276		}
277	}
278#ifdef EXAMPLE_TABLE
279	/* if no country code matched return first universal code from translate_custom_table */
280	memcpy(cspec->ccode, translate_custom_table[0].custom_locale, WLC_CNTRY_BUF_SZ);
281	cspec->rev = translate_custom_table[0].custom_locale_rev;
282#endif /* EXAMPLE_TABLE */
283	return;
284#endif
285}