• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.1 2010/09/02 23:13:16 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
42 extern  void bcm_wlan_power_off(int);
43 extern  void bcm_wlan_power_on(int);
44 #endif /* CUSTOMER_HW */
45 #ifdef CUSTOMER_HW2
46 int wifi_set_carddetect(int on);
47 int wifi_set_power(int on, unsigned long msec);
48 int wifi_get_irq_number(unsigned long *irq_flags_ptr);
49 int wifi_get_mac_addr(unsigned char *buf);
50 #endif
51 
52 #if defined(OOB_INTR_ONLY)
53 
54 #if defined(BCMLXSDMMC)
55 extern int sdioh_mmc_irq(int irq);
56 #endif /* (BCMLXSDMMC)  */
57 
58 #ifdef CUSTOMER_HW3
59 #include <mach/gpio.h>
60 #endif
61 
62 /* Customer specific Host GPIO defintion  */
63 static int dhd_oob_gpio_num = -1; /* GG 19 */
64 
65 module_param(dhd_oob_gpio_num, int, 0644);
66 MODULE_PARM_DESC(dhd_oob_gpio_num, "DHD oob gpio number");
67 
dhd_customer_oob_irq_map(unsigned long * irq_flags_ptr)68 int dhd_customer_oob_irq_map(unsigned long *irq_flags_ptr)
69 {
70 	int  host_oob_irq = 0;
71 
72 #ifdef CUSTOMER_HW2
73 	host_oob_irq = wifi_get_irq_number(irq_flags_ptr);
74 
75 #else /* for NOT  CUSTOMER_HW2 */
76 #if defined(CUSTOM_OOB_GPIO_NUM)
77 	if (dhd_oob_gpio_num < 0) {
78 		dhd_oob_gpio_num = CUSTOM_OOB_GPIO_NUM;
79 	}
80 #endif
81 
82 	if (dhd_oob_gpio_num < 0) {
83 		WL_ERROR(("%s: ERROR customer specific Host GPIO is NOT defined \n",
84 			__FUNCTION__));
85 		return (dhd_oob_gpio_num);
86 	}
87 
88 	WL_ERROR(("%s: customer specific Host GPIO number is (%d)\n",
89 	         __FUNCTION__, dhd_oob_gpio_num));
90 
91 #if defined CUSTOMER_HW
92 	host_oob_irq = MSM_GPIO_TO_INT(dhd_oob_gpio_num);
93 #elif defined CUSTOMER_HW3
94 	gpio_request(dhd_oob_gpio_num, "oob irq");
95 	host_oob_irq = gpio_to_irq(dhd_oob_gpio_num);
96 	gpio_direction_input(dhd_oob_gpio_num);
97 #endif /* CUSTOMER_HW */
98 #endif /* CUSTOMER_HW2 */
99 
100 	return (host_oob_irq);
101 }
102 #endif /* defined(OOB_INTR_ONLY) */
103 
104 /* Customer function to control hw specific wlan gpios */
105 void
dhd_customer_gpio_wlan_ctrl(int onoff)106 dhd_customer_gpio_wlan_ctrl(int onoff)
107 {
108 	switch (onoff) {
109 		case WLAN_RESET_OFF:
110 			WL_TRACE(("%s: call customer specific GPIO to insert WLAN RESET\n",
111 				__FUNCTION__));
112 #ifdef CUSTOMER_HW
113 			bcm_wlan_power_off(2);
114 #endif /* CUSTOMER_HW */
115 #ifdef CUSTOMER_HW2
116 			wifi_set_power(0, 0);
117 #endif
118 			WL_ERROR(("=========== WLAN placed in RESET ========\n"));
119 		break;
120 
121 		case WLAN_RESET_ON:
122 			WL_TRACE(("%s: callc customer specific GPIO to remove WLAN RESET\n",
123 				__FUNCTION__));
124 #ifdef CUSTOMER_HW
125 			bcm_wlan_power_on(2);
126 #endif /* CUSTOMER_HW */
127 #ifdef CUSTOMER_HW2
128 			wifi_set_power(1, 0);
129 #endif
130 			WL_ERROR(("=========== WLAN going back to live  ========\n"));
131 		break;
132 
133 		case WLAN_POWER_OFF:
134 			WL_TRACE(("%s: call customer specific GPIO to turn off WL_REG_ON\n",
135 				__FUNCTION__));
136 #ifdef CUSTOMER_HW
137 			bcm_wlan_power_off(1);
138 #endif /* CUSTOMER_HW */
139 		break;
140 
141 		case WLAN_POWER_ON:
142 			WL_TRACE(("%s: call customer specific GPIO to turn on WL_REG_ON\n",
143 				__FUNCTION__));
144 #ifdef CUSTOMER_HW
145 			bcm_wlan_power_on(1);
146 			/* Lets customer power to get stable */
147 			OSL_DELAY(50);
148 #endif /* CUSTOMER_HW */
149 		break;
150 	}
151 }
152 
153 #ifdef GET_CUSTOM_MAC_ENABLE
154 /* Function to get custom MAC address */
155 int
dhd_custom_get_mac_address(unsigned char * buf)156 dhd_custom_get_mac_address(unsigned char *buf)
157 {
158 	int ret = 0;
159 
160 	WL_TRACE(("%s Enter\n", __FUNCTION__));
161 	if (!buf)
162 		return -EINVAL;
163 
164 	/* Customer access to MAC address stored outside of DHD driver */
165 #ifdef CUSTOMER_HW2
166 	ret = wifi_get_mac_addr(buf);
167 #endif
168 
169 #ifdef EXAMPLE_GET_MAC
170 	/* EXAMPLE code */
171 	{
172 		struct ether_addr ea_example = {{0x00, 0x11, 0x22, 0x33, 0x44, 0xFF}};
173 		bcopy((char *)&ea_example, buf, sizeof(struct ether_addr));
174 	}
175 #endif /* EXAMPLE_GET_MAC */
176 
177 	return ret;
178 }
179 #endif /* GET_CUSTOM_MAC_ENABLE */
180