aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/bcm4329/bcmsdh_sdmmc_linux.c
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.c316
1 files changed, 316 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..b1fc35b7783
--- /dev/null
+++ b/drivers/net/wireless/bcm4329/bcmsdh_sdmmc_linux.c
@@ -0,0 +1,316 @@
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
144#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 39)) && defined(CONFIG_PM)
145static int bcmsdh_sdmmc_suspend(struct device *pdev)
146{
147 struct sdio_func *func = dev_to_sdio_func(pdev);
148 mmc_pm_flag_t sdio_flags;
149 int ret = 0;
150
151 if (func->num != 2)
152 return 0;
153
154 sdio_flags = sdio_get_host_pm_caps(func);
155
156 if (!(sdio_flags & MMC_PM_KEEP_POWER)) {
157 sd_err(("can't keep power while host "
158 "is suspended\n", __FUNCTION__));
159 ret = -EINVAL;
160 goto out;
161 }
162
163 /* keep power while host suspended */
164 ret = sdio_set_host_pm_flags(func, MMC_PM_KEEP_POWER);
165 if (ret) {
166 sd_err(("error while trying to keep power\n", __FUNCTION__));
167 goto out;
168 }
169
170out:
171 return ret;
172}
173
174static int bcmsdh_sdmmc_resume(struct device *pdev)
175{
176 /* nothing to do since MMC_PM_KEEP_POWER is cleared by MMC stack */
177 return 0;
178}
179
180static const struct dev_pm_ops bcmsdh_sdmmc_pm_ops = {
181 .suspend = bcmsdh_sdmmc_suspend,
182 .resume = bcmsdh_sdmmc_resume,
183};
184#endif
185
186static struct sdio_driver bcmsdh_sdmmc_driver = {
187 .probe = bcmsdh_sdmmc_probe,
188 .remove = bcmsdh_sdmmc_remove,
189 .name = "bcmsdh_sdmmc",
190 .id_table = bcmsdh_sdmmc_ids,
191#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 39)) && defined(CONFIG_PM)
192 .drv = {
193 .pm = &bcmsdh_sdmmc_pm_ops,
194 },
195#endif
196 };
197
198struct sdos_info {
199 sdioh_info_t *sd;
200 spinlock_t lock;
201};
202
203
204int
205sdioh_sdmmc_osinit(sdioh_info_t *sd)
206{
207 struct sdos_info *sdos;
208
209 sdos = (struct sdos_info*)MALLOC(sd->osh, sizeof(struct sdos_info));
210 sd->sdos_info = (void*)sdos;
211 if (sdos == NULL)
212 return BCME_NOMEM;
213
214 sdos->sd = sd;
215 spin_lock_init(&sdos->lock);
216 return BCME_OK;
217}
218
219void
220sdioh_sdmmc_osfree(sdioh_info_t *sd)
221{
222 struct sdos_info *sdos;
223 ASSERT(sd && sd->sdos_info);
224
225 sdos = (struct sdos_info *)sd->sdos_info;
226 MFREE(sd->osh, sdos, sizeof(struct sdos_info));
227}
228
229/* Interrupt enable/disable */
230SDIOH_API_RC
231sdioh_interrupt_set(sdioh_info_t *sd, bool enable)
232{
233 ulong flags;
234 struct sdos_info *sdos;
235
236 sd_trace(("%s: %s\n", __FUNCTION__, enable ? "Enabling" : "Disabling"));
237
238 sdos = (struct sdos_info *)sd->sdos_info;
239 ASSERT(sdos);
240
241#if !defined(OOB_INTR_ONLY)
242 if (enable && !(sd->intr_handler && sd->intr_handler_arg)) {
243 sd_err(("%s: no handler registered, will not enable\n", __FUNCTION__));
244 return SDIOH_API_RC_FAIL;
245 }
246#endif /* !defined(OOB_INTR_ONLY) */
247
248 /* Ensure atomicity for enable/disable calls */
249 spin_lock_irqsave(&sdos->lock, flags);
250
251 sd->client_intr_enabled = enable;
252 if (enable) {
253 sdioh_sdmmc_devintr_on(sd);
254 } else {
255 sdioh_sdmmc_devintr_off(sd);
256 }
257
258 spin_unlock_irqrestore(&sdos->lock, flags);
259
260 return SDIOH_API_RC_SUCCESS;
261}
262
263
264#ifdef BCMSDH_MODULE
265static int __init
266bcmsdh_module_init(void)
267{
268 int error = 0;
269 sdio_function_init();
270 return error;
271}
272
273static void __exit
274bcmsdh_module_cleanup(void)
275{
276 sdio_function_cleanup();
277}
278
279module_init(bcmsdh_module_init);
280module_exit(bcmsdh_module_cleanup);
281
282MODULE_LICENSE("GPL v2");
283MODULE_DESCRIPTION(DESCRIPTION);
284MODULE_AUTHOR(AUTHOR);
285
286#endif /* BCMSDH_MODULE */
287/*
288 * module init
289*/
290int sdio_function_init(void)
291{
292 int error = 0;
293 sd_trace(("bcmsdh_sdmmc: %s Enter\n", __FUNCTION__));
294
295 gInstance = kzalloc(sizeof(BCMSDH_SDMMC_INSTANCE), GFP_KERNEL);
296 if (!gInstance)
297 return -ENOMEM;
298
299 error = sdio_register_driver(&bcmsdh_sdmmc_driver);
300
301 return error;
302}
303
304/*
305 * module cleanup
306*/
307extern int bcmsdh_remove(struct device *dev);
308void sdio_function_cleanup(void)
309{
310 sd_trace(("%s Enter\n", __FUNCTION__));
311
312 sdio_unregister_driver(&bcmsdh_sdmmc_driver);
313
314 if (gInstance)
315 kfree(gInstance);
316}