aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/wireless/bcm4329/bcmsdh_sdmmc_linux.c')
-rw-r--r--drivers/net/wireless/bcm4329/bcmsdh_sdmmc_linux.c269
1 files changed, 269 insertions, 0 deletions
diff --git a/drivers/net/wireless/bcm4329/bcmsdh_sdmmc_linux.c b/drivers/net/wireless/bcm4329/bcmsdh_sdmmc_linux.c
new file mode 100644
index 00000000000..5a1a46c9357
--- /dev/null
+++ b/drivers/net/wireless/bcm4329/bcmsdh_sdmmc_linux.c
@@ -0,0 +1,269 @@
1/*
2 * BCMSDH Function Driver for the native SDIO/MMC driver in the Linux Kernel
3 *
4 * Copyright (C) 1999-2010, 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 * $Id: bcmsdh_sdmmc_linux.c,v 1.1.2.5.6.17 2010/08/13 00:36:19 Exp $
25 */
26
27#include <typedefs.h>
28#include <bcmutils.h>
29#include <sdio.h> /* SDIO Specs */
30#include <bcmsdbus.h> /* bcmsdh to/from specific controller APIs */
31#include <sdiovar.h> /* to get msglevel bit values */
32
33#include <linux/sched.h> /* request_irq() */
34
35#include <linux/mmc/core.h>
36#include <linux/mmc/card.h>
37#include <linux/mmc/sdio_func.h>
38#include <linux/mmc/sdio_ids.h>
39
40#if !defined(SDIO_VENDOR_ID_BROADCOM)
41#define SDIO_VENDOR_ID_BROADCOM 0x02d0
42#endif /* !defined(SDIO_VENDOR_ID_BROADCOM) */
43
44#define SDIO_DEVICE_ID_BROADCOM_DEFAULT 0x0000
45
46#if !defined(SDIO_DEVICE_ID_BROADCOM_4325_SDGWB)
47#define SDIO_DEVICE_ID_BROADCOM_4325_SDGWB 0x0492 /* BCM94325SDGWB */
48#endif /* !defined(SDIO_DEVICE_ID_BROADCOM_4325_SDGWB) */
49#if !defined(SDIO_DEVICE_ID_BROADCOM_4325)
50#define SDIO_DEVICE_ID_BROADCOM_4325 0x0493
51#endif /* !defined(SDIO_DEVICE_ID_BROADCOM_4325) */
52#if !defined(SDIO_DEVICE_ID_BROADCOM_4329)
53#define SDIO_DEVICE_ID_BROADCOM_4329 0x4329
54#endif /* !defined(SDIO_DEVICE_ID_BROADCOM_4329) */
55#if !defined(SDIO_DEVICE_ID_BROADCOM_4319)
56#define SDIO_DEVICE_ID_BROADCOM_4319 0x4319
57#endif /* !defined(SDIO_DEVICE_ID_BROADCOM_4329) */
58
59#include <bcmsdh_sdmmc.h>
60
61#include <dhd_dbg.h>
62
63extern void sdioh_sdmmc_devintr_off(sdioh_info_t *sd);
64extern void sdioh_sdmmc_devintr_on(sdioh_info_t *sd);
65
66int sdio_function_init(void);
67void sdio_function_cleanup(void);
68
69#define DESCRIPTION "bcmsdh_sdmmc Driver"
70#define AUTHOR "Broadcom Corporation"
71
72/* module param defaults */
73static int clockoverride = 0;
74
75module_param(clockoverride, int, 0644);
76MODULE_PARM_DESC(clockoverride, "SDIO card clock override");
77
78PBCMSDH_SDMMC_INSTANCE gInstance;
79
80/* Maximum number of bcmsdh_sdmmc devices supported by driver */
81#define BCMSDH_SDMMC_MAX_DEVICES 1
82
83extern int bcmsdh_probe(struct device *dev);
84extern int bcmsdh_remove(struct device *dev);
85
86static int bcmsdh_sdmmc_probe(struct sdio_func *func,
87 const struct sdio_device_id *id)
88{
89 int ret = 0;
90 static struct sdio_func sdio_func_0;
91 sd_trace(("bcmsdh_sdmmc: %s Enter\n", __FUNCTION__));
92 sd_trace(("sdio_bcmsdh: func->class=%x\n", func->class));
93 sd_trace(("sdio_vendor: 0x%04x\n", func->vendor));
94 sd_trace(("sdio_device: 0x%04x\n", func->device));
95 sd_trace(("Function#: 0x%04x\n", func->num));
96
97 if (func->num == 1) {
98 sdio_func_0.num = 0;
99 sdio_func_0.card = func->card;
100 gInstance->func[0] = &sdio_func_0;
101 if(func->device == 0x4) { /* 4318 */
102 gInstance->func[2] = NULL;
103 sd_trace(("NIC found, calling bcmsdh_probe...\n"));
104 ret = bcmsdh_probe(&func->dev);
105 }
106 }
107
108 gInstance->func[func->num] = func;
109
110 if (func->num == 2) {
111 sd_trace(("F2 found, calling bcmsdh_probe...\n"));
112 ret = bcmsdh_probe(&func->dev);
113 }
114
115 return ret;
116}
117
118static void bcmsdh_sdmmc_remove(struct sdio_func *func)
119{
120 sd_trace(("bcmsdh_sdmmc: %s Enter\n", __FUNCTION__));
121 sd_info(("sdio_bcmsdh: func->class=%x\n", func->class));
122 sd_info(("sdio_vendor: 0x%04x\n", func->vendor));
123 sd_info(("sdio_device: 0x%04x\n", func->device));
124 sd_info(("Function#: 0x%04x\n", func->num));
125
126 if (func->num == 2) {
127 sd_trace(("F2 found, calling bcmsdh_remove...\n"));
128 bcmsdh_remove(&func->dev);
129 }
130}
131
132/* devices we support, null terminated */
133static const struct sdio_device_id bcmsdh_sdmmc_ids[] = {
134 { SDIO_DEVICE(SDIO_VENDOR_ID_BROADCOM, SDIO_DEVICE_ID_BROADCOM_DEFAULT) },
135 { SDIO_DEVICE(SDIO_VENDOR_ID_BROADCOM, SDIO_DEVICE_ID_BROADCOM_4325_SDGWB) },
136 { SDIO_DEVICE(SDIO_VENDOR_ID_BROADCOM, SDIO_DEVICE_ID_BROADCOM_4325) },
137 { SDIO_DEVICE(SDIO_VENDOR_ID_BROADCOM, SDIO_DEVICE_ID_BROADCOM_4329) },
138 { SDIO_DEVICE(SDIO_VENDOR_ID_BROADCOM, SDIO_DEVICE_ID_BROADCOM_4319) },
139 { /* end: all zeroes */ },
140};
141
142MODULE_DEVICE_TABLE(sdio, bcmsdh_sdmmc_ids);
143
144static struct sdio_driver bcmsdh_sdmmc_driver = {
145 .probe = bcmsdh_sdmmc_probe,
146 .remove = bcmsdh_sdmmc_remove,
147 .name = "bcmsdh_sdmmc",
148 .id_table = bcmsdh_sdmmc_ids,
149 };
150
151struct sdos_info {
152 sdioh_info_t *sd;
153 spinlock_t lock;
154};
155
156
157int
158sdioh_sdmmc_osinit(sdioh_info_t *sd)
159{
160 struct sdos_info *sdos;
161
162 sdos = (struct sdos_info*)MALLOC(sd->osh, sizeof(struct sdos_info));
163 sd->sdos_info = (void*)sdos;
164 if (sdos == NULL)
165 return BCME_NOMEM;
166
167 sdos->sd = sd;
168 spin_lock_init(&sdos->lock);
169 return BCME_OK;
170}
171
172void
173sdioh_sdmmc_osfree(sdioh_info_t *sd)
174{
175 struct sdos_info *sdos;
176 ASSERT(sd && sd->sdos_info);
177
178 sdos = (struct sdos_info *)sd->sdos_info;
179 MFREE(sd->osh, sdos, sizeof(struct sdos_info));
180}
181
182/* Interrupt enable/disable */
183SDIOH_API_RC
184sdioh_interrupt_set(sdioh_info_t *sd, bool enable)
185{
186 ulong flags;
187 struct sdos_info *sdos;
188
189 sd_trace(("%s: %s\n", __FUNCTION__, enable ? "Enabling" : "Disabling"));
190
191 sdos = (struct sdos_info *)sd->sdos_info;
192 ASSERT(sdos);
193
194#if !defined(OOB_INTR_ONLY)
195 if (enable && !(sd->intr_handler && sd->intr_handler_arg)) {
196 sd_err(("%s: no handler registered, will not enable\n", __FUNCTION__));
197 return SDIOH_API_RC_FAIL;
198 }
199#endif /* !defined(OOB_INTR_ONLY) */
200
201 /* Ensure atomicity for enable/disable calls */
202 spin_lock_irqsave(&sdos->lock, flags);
203
204 sd->client_intr_enabled = enable;
205 if (enable) {
206 sdioh_sdmmc_devintr_on(sd);
207 } else {
208 sdioh_sdmmc_devintr_off(sd);
209 }
210
211 spin_unlock_irqrestore(&sdos->lock, flags);
212
213 return SDIOH_API_RC_SUCCESS;
214}
215
216
217#ifdef BCMSDH_MODULE
218static int __init
219bcmsdh_module_init(void)
220{
221 int error = 0;
222 sdio_function_init();
223 return error;
224}
225
226static void __exit
227bcmsdh_module_cleanup(void)
228{
229 sdio_function_cleanup();
230}
231
232module_init(bcmsdh_module_init);
233module_exit(bcmsdh_module_cleanup);
234
235MODULE_LICENSE("GPL v2");
236MODULE_DESCRIPTION(DESCRIPTION);
237MODULE_AUTHOR(AUTHOR);
238
239#endif /* BCMSDH_MODULE */
240/*
241 * module init
242*/
243int sdio_function_init(void)
244{
245 int error = 0;
246 sd_trace(("bcmsdh_sdmmc: %s Enter\n", __FUNCTION__));
247
248 gInstance = kzalloc(sizeof(BCMSDH_SDMMC_INSTANCE), GFP_KERNEL);
249 if (!gInstance)
250 return -ENOMEM;
251
252 error = sdio_register_driver(&bcmsdh_sdmmc_driver);
253
254 return error;
255}
256
257/*
258 * module cleanup
259*/
260extern int bcmsdh_remove(struct device *dev);
261void sdio_function_cleanup(void)
262{
263 sd_trace(("%s Enter\n", __FUNCTION__));
264
265 sdio_unregister_driver(&bcmsdh_sdmmc_driver);
266
267 if (gInstance)
268 kfree(gInstance);
269}