2 * BCMSDH Function Driver for the native SDIO/MMC driver in the Linux Kernel
4 * Copyright (C) 1999-2013, Broadcom Corporation
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:
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.
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.
24 * $Id: bcmsdh_sdmmc_linux.c 404103 2013-05-23 20:07:27Z $
29 #include <sdio.h> /* SDIO Device and Protocol Specs */
30 #include <bcmsdbus.h> /* bcmsdh to/from specific controller APIs */
31 #include <sdiovar.h> /* to get msglevel bit values */
33 #include <linux/sched.h> /* request_irq() */
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 #include <dhd_config.h>
41 #if !defined(SDIO_VENDOR_ID_BROADCOM)
42 #define SDIO_VENDOR_ID_BROADCOM 0x02d0
43 #endif /* !defined(SDIO_VENDOR_ID_BROADCOM) */
45 #define SDIO_DEVICE_ID_BROADCOM_DEFAULT 0x0000
47 #if !defined(SDIO_DEVICE_ID_BROADCOM_4325_SDGWB)
48 #define SDIO_DEVICE_ID_BROADCOM_4325_SDGWB 0x0492 /* BCM94325SDGWB */
49 #endif /* !defined(SDIO_DEVICE_ID_BROADCOM_4325_SDGWB) */
50 #if !defined(SDIO_DEVICE_ID_BROADCOM_4325)
51 #define SDIO_DEVICE_ID_BROADCOM_4325 0x0493
52 #endif /* !defined(SDIO_DEVICE_ID_BROADCOM_4325) */
53 #if !defined(SDIO_DEVICE_ID_BROADCOM_4329)
54 #define SDIO_DEVICE_ID_BROADCOM_4329 0x4329
55 #endif /* !defined(SDIO_DEVICE_ID_BROADCOM_4329) */
56 #if !defined(SDIO_DEVICE_ID_BROADCOM_4319)
57 #define SDIO_DEVICE_ID_BROADCOM_4319 0x4319
58 #endif /* !defined(SDIO_DEVICE_ID_BROADCOM_4319) */
59 #if !defined(SDIO_DEVICE_ID_BROADCOM_4330)
60 #define SDIO_DEVICE_ID_BROADCOM_4330 0x4330
61 #endif /* !defined(SDIO_DEVICE_ID_BROADCOM_4330) */
62 #if !defined(SDIO_DEVICE_ID_BROADCOM_4334)
63 #define SDIO_DEVICE_ID_BROADCOM_4334 0x4334
64 #endif /* !defined(SDIO_DEVICE_ID_BROADCOM_4334) */
65 #if !defined(SDIO_DEVICE_ID_BROADCOM_4324)
66 #define SDIO_DEVICE_ID_BROADCOM_4324 0x4324
67 #endif /* !defined(SDIO_DEVICE_ID_BROADCOM_4324) */
68 #if !defined(SDIO_DEVICE_ID_BROADCOM_43239)
69 #define SDIO_DEVICE_ID_BROADCOM_43239 43239
70 #endif /* !defined(SDIO_DEVICE_ID_BROADCOM_43239) */
73 #include <bcmsdh_sdmmc.h>
78 extern void wl_cfg80211_set_parent_dev(void *dev);
81 extern void sdioh_sdmmc_devintr_off(sdioh_info_t *sd);
82 extern void sdioh_sdmmc_devintr_on(sdioh_info_t *sd);
83 extern int dhd_os_check_wakelock(void *dhdp);
84 extern int dhd_os_check_if_up(void *dhdp);
85 extern void *bcmsdh_get_drvdata(void);
87 int sdio_function_init(void);
88 void sdio_function_cleanup(void);
90 #define DESCRIPTION "bcmsdh_sdmmc Driver"
91 #define AUTHOR "Broadcom Corporation"
93 /* module param defaults */
94 static int clockoverride = 0;
96 module_param(clockoverride, int, 0644);
97 MODULE_PARM_DESC(clockoverride, "SDIO card clock override");
99 PBCMSDH_SDMMC_INSTANCE gInstance;
101 /* Maximum number of bcmsdh_sdmmc devices supported by driver */
102 #define BCMSDH_SDMMC_MAX_DEVICES 1
104 extern int bcmsdh_probe(struct device *dev);
105 extern int bcmsdh_remove(struct device *dev);
106 extern volatile bool dhd_mmc_suspend;
108 static int bcmsdh_sdmmc_probe(struct sdio_func *func,
109 const struct sdio_device_id *id)
112 static struct sdio_func sdio_func_0;
118 sd_trace(("bcmsdh_sdmmc: %s Enter\n", __FUNCTION__));
119 sd_trace(("sdio_bcmsdh: func->class=%x\n", func->class));
120 sd_trace(("sdio_vendor: 0x%04x\n", func->vendor));
121 sd_trace(("sdio_device: 0x%04x\n", func->device));
122 sd_trace(("Function#: 0x%04x\n", func->num));
124 if (func->num == 1) {
126 sdio_func_0.card = func->card;
127 gInstance->func[0] = &sdio_func_0;
128 if(func->device == 0x4) { /* 4318 */
129 gInstance->func[2] = NULL;
130 sd_trace(("NIC found, calling bcmsdh_probe...\n"));
131 ret = bcmsdh_probe(&func->dev);
135 gInstance->func[func->num] = func;
137 if (func->num == 2) {
139 wl_cfg80211_set_parent_dev(&func->dev);
141 sd_trace(("F2 found, calling bcmsdh_probe...\n"));
142 ret = bcmsdh_probe(&func->dev);
144 gInstance->func[2] = NULL;
149 #ifdef POWER_OFF_IN_SUSPEND
150 dhd_conf_register_wifi_suspend(func);
156 static void bcmsdh_sdmmc_remove(struct sdio_func *func)
159 sd_trace(("bcmsdh_sdmmc: %s Enter\n", __FUNCTION__));
160 sd_info(("sdio_bcmsdh: func->class=%x\n", func->class));
161 sd_info(("sdio_vendor: 0x%04x\n", func->vendor));
162 sd_info(("sdio_device: 0x%04x\n", func->device));
163 sd_info(("Function#: 0x%04x\n", func->num));
165 #ifdef POWER_OFF_IN_SUSPEND
166 dhd_conf_unregister_wifi_suspend(func);
168 if (gInstance->func[2]) {
169 sd_trace(("F2 found, calling bcmsdh_remove...\n"));
170 bcmsdh_remove(&func->dev);
171 gInstance->func[2] = NULL;
173 if (func->num == 1) {
174 sdio_claim_host(func);
175 sdio_disable_func(func);
176 sdio_release_host(func);
177 gInstance->func[1] = NULL;
182 /* devices we support, null terminated */
183 static const struct sdio_device_id bcmsdh_sdmmc_ids[] = {
184 { SDIO_DEVICE(SDIO_VENDOR_ID_BROADCOM, SDIO_DEVICE_ID_BROADCOM_DEFAULT) },
185 { SDIO_DEVICE(SDIO_VENDOR_ID_BROADCOM, SDIO_DEVICE_ID_BROADCOM_4325_SDGWB) },
186 { SDIO_DEVICE(SDIO_VENDOR_ID_BROADCOM, SDIO_DEVICE_ID_BROADCOM_4325) },
187 { SDIO_DEVICE(SDIO_VENDOR_ID_BROADCOM, SDIO_DEVICE_ID_BROADCOM_4329) },
188 { SDIO_DEVICE(SDIO_VENDOR_ID_BROADCOM, SDIO_DEVICE_ID_BROADCOM_4319) },
189 { SDIO_DEVICE(SDIO_VENDOR_ID_BROADCOM, SDIO_DEVICE_ID_BROADCOM_4330) },
190 { SDIO_DEVICE(SDIO_VENDOR_ID_BROADCOM, SDIO_DEVICE_ID_BROADCOM_4334) },
191 { SDIO_DEVICE(SDIO_VENDOR_ID_BROADCOM, SDIO_DEVICE_ID_BROADCOM_4324) },
192 { SDIO_DEVICE(SDIO_VENDOR_ID_BROADCOM, SDIO_DEVICE_ID_BROADCOM_43239) },
193 { SDIO_DEVICE_CLASS(SDIO_CLASS_NONE) },
194 { /* end: all zeroes */ },
197 MODULE_DEVICE_TABLE(sdio, bcmsdh_sdmmc_ids);
199 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 39)) && defined(CONFIG_PM)
200 static int bcmsdh_sdmmc_suspend(struct device *pdev)
202 struct sdio_func *func = dev_to_sdio_func(pdev);
203 #ifndef POWER_OFF_IN_SUSPEND
204 mmc_pm_flag_t sdio_flags;
211 sd_trace(("%s Enter\n", __FUNCTION__));
212 if (dhd_os_check_wakelock(bcmsdh_get_drvdata()))
215 #ifdef POWER_OFF_IN_SUSPEND
216 dhd_conf_wifi_suspend(func);
218 sdio_flags = sdio_get_host_pm_caps(func);
220 if (!(sdio_flags & MMC_PM_KEEP_POWER)) {
221 sd_err(("%s: can't keep power while host is suspended\n", __FUNCTION__));
225 /* keep power while host suspended */
226 ret = sdio_set_host_pm_flags(func, MMC_PM_KEEP_POWER);
228 sd_err(("%s: error while trying to keep power\n", __FUNCTION__));
231 #if defined(OOB_INTR_ONLY)
232 bcmsdh_oob_intr_set(0);
235 dhd_mmc_suspend = TRUE;
241 static int bcmsdh_sdmmc_resume(struct device *pdev)
243 #if defined(OOB_INTR_ONLY) || defined(POWER_OFF_IN_SUSPEND)
244 struct sdio_func *func = dev_to_sdio_func(pdev);
246 sd_trace(("%s Enter\n", __FUNCTION__));
247 dhd_mmc_suspend = FALSE;
249 #ifdef POWER_OFF_IN_SUSPEND
250 gInstance->func[func->num] = func;
252 #if defined(OOB_INTR_ONLY)
253 if ((func->num == 2) && dhd_os_check_if_up(bcmsdh_get_drvdata()))
254 bcmsdh_oob_intr_set(1);
261 static const struct dev_pm_ops bcmsdh_sdmmc_pm_ops = {
262 .suspend = bcmsdh_sdmmc_suspend,
263 .resume = bcmsdh_sdmmc_resume,
265 #endif /* (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 39)) && defined(CONFIG_PM) */
267 #if defined(BCMLXSDMMC)
268 static struct semaphore *notify_semaphore = NULL;
270 static int dummy_probe(struct sdio_func *func,
271 const struct sdio_device_id *id)
273 if (notify_semaphore)
274 up(notify_semaphore);
278 static void dummy_remove(struct sdio_func *func)
282 static struct sdio_driver dummy_sdmmc_driver = {
283 .probe = dummy_probe,
284 .remove = dummy_remove,
285 .name = "dummy_sdmmc",
286 .id_table = bcmsdh_sdmmc_ids,
289 int sdio_func_reg_notify(void* semaphore)
291 notify_semaphore = semaphore;
292 if (notify_semaphore)
293 up(notify_semaphore);
295 //return sdio_register_driver(&dummy_sdmmc_driver);
298 void sdio_func_unreg_notify(void)
300 //sdio_unregister_driver(&dummy_sdmmc_driver);
303 #endif /* defined(BCMLXSDMMC) */
305 static struct sdio_driver bcmsdh_sdmmc_driver = {
306 .probe = bcmsdh_sdmmc_probe,
307 .remove = bcmsdh_sdmmc_remove,
308 .name = "bcmsdh_sdmmc",
309 .id_table = bcmsdh_sdmmc_ids,
310 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 39)) && defined(CONFIG_PM)
312 .pm = &bcmsdh_sdmmc_pm_ops,
314 #endif /* (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 39)) && defined(CONFIG_PM) */
324 sdioh_sdmmc_osinit(sdioh_info_t *sd)
326 struct sdos_info *sdos;
331 sdos = (struct sdos_info*)MALLOC(sd->osh, sizeof(struct sdos_info));
332 sd->sdos_info = (void*)sdos;
337 spin_lock_init(&sdos->lock);
342 sdioh_sdmmc_osfree(sdioh_info_t *sd)
344 struct sdos_info *sdos;
345 ASSERT(sd && sd->sdos_info);
347 sdos = (struct sdos_info *)sd->sdos_info;
348 MFREE(sd->osh, sdos, sizeof(struct sdos_info));
351 /* Interrupt enable/disable */
353 sdioh_interrupt_set(sdioh_info_t *sd, bool enable)
356 struct sdos_info *sdos;
361 sd_trace(("%s: %s\n", __FUNCTION__, enable ? "Enabling" : "Disabling"));
363 sdos = (struct sdos_info *)sd->sdos_info;
366 #if !defined(OOB_INTR_ONLY)
367 if (enable && !(sd->intr_handler && sd->intr_handler_arg)) {
368 sd_err(("%s: no handler registered, will not enable\n", __FUNCTION__));
369 return SDIOH_API_RC_FAIL;
371 #endif /* !defined(OOB_INTR_ONLY) */
373 /* Ensure atomicity for enable/disable calls */
374 spin_lock_irqsave(&sdos->lock, flags);
376 sd->client_intr_enabled = enable;
378 sdioh_sdmmc_devintr_on(sd);
380 sdioh_sdmmc_devintr_off(sd);
383 spin_unlock_irqrestore(&sdos->lock, flags);
385 return SDIOH_API_RC_SUCCESS;
391 bcmsdh_module_init(void)
394 error = sdio_function_init();
399 bcmsdh_module_cleanup(void)
401 sdio_function_cleanup();
404 module_init(bcmsdh_module_init);
405 module_exit(bcmsdh_module_cleanup);
407 MODULE_LICENSE("GPL v2");
408 MODULE_DESCRIPTION(DESCRIPTION);
409 MODULE_AUTHOR(AUTHOR);
411 #endif /* BCMSDH_MODULE */
415 int sdio_function_init(void)
418 sd_trace(("bcmsdh_sdmmc: %s Enter\n", __FUNCTION__));
420 gInstance = kzalloc(sizeof(BCMSDH_SDMMC_INSTANCE), GFP_KERNEL);
424 error = sdio_register_driver(&bcmsdh_sdmmc_driver);
436 extern int bcmsdh_remove(struct device *dev);
437 void sdio_function_cleanup(void)
439 sd_trace(("%s Enter\n", __FUNCTION__));
442 sdio_unregister_driver(&bcmsdh_sdmmc_driver);