Merge branch 'x86-platform-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[pandora-kernel.git] / drivers / staging / brcm80211 / brcmfmac / dhd_custom_gpio.c
1 /*
2  * Copyright (c) 2010 Broadcom Corporation
3  *
4  * Permission to use, copy, modify, and/or distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11  * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16
17 #include <linuxver.h>
18 #include <osl.h>
19 #include <bcmutils.h>
20
21 #include <dngl_stats.h>
22 #include <dhd.h>
23
24 #include <wlioctl.h>
25 #include <wl_iw.h>
26
27 #define WL_ERROR(x) printf x
28 #define WL_TRACE(x)
29
30 #ifdef CUSTOMER_HW
31 extern void bcm_wlan_power_off(int);
32 extern void bcm_wlan_power_on(int);
33 #endif                          /* CUSTOMER_HW */
34 #ifdef CUSTOMER_HW2
35 int wifi_set_carddetect(int on);
36 int wifi_set_power(int on, unsigned long msec);
37 int wifi_get_irq_number(unsigned long *irq_flags_ptr);
38 #endif
39
40 #if defined(OOB_INTR_ONLY)
41
42 #if defined(BCMLXSDMMC)
43 extern int sdioh_mmc_irq(int irq);
44 #endif                          /* (BCMLXSDMMC)  */
45
46 #ifdef CUSTOMER_HW3
47 #include <mach/gpio.h>
48 #endif
49
50 /* Customer specific Host GPIO defintion  */
51 static int dhd_oob_gpio_num = -1;       /* GG 19 */
52
53 module_param(dhd_oob_gpio_num, int, 0644);
54 MODULE_PARM_DESC(dhd_oob_gpio_num, "DHD oob gpio number");
55
56 int dhd_customer_oob_irq_map(unsigned long *irq_flags_ptr)
57 {
58         int host_oob_irq = 0;
59
60 #ifdef CUSTOMER_HW2
61         host_oob_irq = wifi_get_irq_number(irq_flags_ptr);
62
63 #else                           /* for NOT  CUSTOMER_HW2 */
64 #if defined(CUSTOM_OOB_GPIO_NUM)
65         if (dhd_oob_gpio_num < 0)
66                 dhd_oob_gpio_num = CUSTOM_OOB_GPIO_NUM;
67 #endif
68
69         if (dhd_oob_gpio_num < 0) {
70                 WL_ERROR(("%s: ERROR customer specific Host GPIO is NOT defined\n",
71                         __func__));
72                 return dhd_oob_gpio_num;
73         }
74
75         WL_ERROR(("%s: customer specific Host GPIO number is (%d)\n",
76                   __func__, dhd_oob_gpio_num));
77
78 #if defined CUSTOMER_HW
79         host_oob_irq = MSM_GPIO_TO_INT(dhd_oob_gpio_num);
80 #elif defined CUSTOMER_HW3
81         gpio_request(dhd_oob_gpio_num, "oob irq");
82         host_oob_irq = gpio_to_irq(dhd_oob_gpio_num);
83         gpio_direction_input(dhd_oob_gpio_num);
84 #endif                          /* CUSTOMER_HW */
85 #endif                          /* CUSTOMER_HW2 */
86
87         return host_oob_irq;
88 }
89 #endif                          /* defined(OOB_INTR_ONLY) */
90
91 /* Customer function to control hw specific wlan gpios */
92 void dhd_customer_gpio_wlan_ctrl(int onoff)
93 {
94         switch (onoff) {
95         case WLAN_RESET_OFF:
96                 WL_TRACE(("%s: call customer specific GPIO to insert WLAN RESET\n",
97                         __func__));
98 #ifdef CUSTOMER_HW
99                 bcm_wlan_power_off(2);
100 #endif                          /* CUSTOMER_HW */
101 #ifdef CUSTOMER_HW2
102                 wifi_set_power(0, 0);
103 #endif
104                 WL_ERROR(("=========== WLAN placed in RESET ========\n"));
105                 break;
106
107         case WLAN_RESET_ON:
108                 WL_TRACE(("%s: callc customer specific GPIO to remove WLAN RESET\n",
109                         __func__));
110 #ifdef CUSTOMER_HW
111                 bcm_wlan_power_on(2);
112 #endif                          /* CUSTOMER_HW */
113 #ifdef CUSTOMER_HW2
114                 wifi_set_power(1, 0);
115 #endif
116                 WL_ERROR(("=========== WLAN going back to live  ========\n"));
117                 break;
118
119         case WLAN_POWER_OFF:
120                 WL_TRACE(("%s: call customer specific GPIO to turn off WL_REG_ON\n",
121                         __func__));
122 #ifdef CUSTOMER_HW
123                 bcm_wlan_power_off(1);
124 #endif                          /* CUSTOMER_HW */
125                 break;
126
127         case WLAN_POWER_ON:
128                 WL_TRACE(("%s: call customer specific GPIO to turn on WL_REG_ON\n",
129                         __func__));
130 #ifdef CUSTOMER_HW
131                 bcm_wlan_power_on(1);
132 #endif                          /* CUSTOMER_HW */
133                 /* Lets customer power to get stable */
134                 udelay(200);
135                 break;
136         }
137 }
138
139 #ifdef GET_CUSTOM_MAC_ENABLE
140 /* Function to get custom MAC address */
141 int dhd_custom_get_mac_address(unsigned char *buf)
142 {
143         WL_TRACE(("%s Enter\n", __func__));
144         if (!buf)
145                 return -EINVAL;
146
147         /* Customer access to MAC address stored outside of DHD driver */
148
149 #ifdef EXAMPLE_GET_MAC
150         /* EXAMPLE code */
151         {
152                 struct ether_addr ea_example = {
153                         {0x00, 0x11, 0x22, 0x33, 0x44, 0xFF} };
154                 bcopy((char *)&ea_example, buf, sizeof(struct ether_addr));
155         }
156 #endif                          /* EXAMPLE_GET_MAC */
157
158         return 0;
159 }
160 #endif                          /* GET_CUSTOM_MAC_ENABLE */