2 * BCMSDH Function Driver for the native SDIO/MMC driver in the Linux Kernel
4 * Copyright (C) 1999-2014, 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 434777 2013-11-07 09:30: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/host.h>
38 #include <linux/mmc/sdio_func.h>
39 #include <linux/mmc/sdio_ids.h>
40 #include <dhd_linux.h>
41 #include <bcmsdh_sdmmc.h>
44 #if !defined(SDIO_VENDOR_ID_BROADCOM)
45 #define SDIO_VENDOR_ID_BROADCOM 0x02d0
46 #endif /* !defined(SDIO_VENDOR_ID_BROADCOM) */
48 #define SDIO_DEVICE_ID_BROADCOM_DEFAULT 0x0000
50 #if !defined(SDIO_DEVICE_ID_BROADCOM_4325_SDGWB)
51 #define SDIO_DEVICE_ID_BROADCOM_4325_SDGWB 0x0492 /* BCM94325SDGWB */
52 #endif /* !defined(SDIO_DEVICE_ID_BROADCOM_4325_SDGWB) */
53 #if !defined(SDIO_DEVICE_ID_BROADCOM_4325)
54 #define SDIO_DEVICE_ID_BROADCOM_4325 0x0493
55 #endif /* !defined(SDIO_DEVICE_ID_BROADCOM_4325) */
56 #if !defined(SDIO_DEVICE_ID_BROADCOM_4329)
57 #define SDIO_DEVICE_ID_BROADCOM_4329 0x4329
58 #endif /* !defined(SDIO_DEVICE_ID_BROADCOM_4329) */
59 #if !defined(SDIO_DEVICE_ID_BROADCOM_4319)
60 #define SDIO_DEVICE_ID_BROADCOM_4319 0x4319
61 #endif /* !defined(SDIO_DEVICE_ID_BROADCOM_4319) */
62 #if !defined(SDIO_DEVICE_ID_BROADCOM_4330)
63 #define SDIO_DEVICE_ID_BROADCOM_4330 0x4330
64 #endif /* !defined(SDIO_DEVICE_ID_BROADCOM_4330) */
65 #if !defined(SDIO_DEVICE_ID_BROADCOM_4334)
66 #define SDIO_DEVICE_ID_BROADCOM_4334 0x4334
67 #endif /* !defined(SDIO_DEVICE_ID_BROADCOM_4334) */
68 #if !defined(SDIO_DEVICE_ID_BROADCOM_4324)
69 #define SDIO_DEVICE_ID_BROADCOM_4324 0x4324
70 #endif /* !defined(SDIO_DEVICE_ID_BROADCOM_4324) */
71 #if !defined(SDIO_DEVICE_ID_BROADCOM_43239)
72 #define SDIO_DEVICE_ID_BROADCOM_43239 43239
73 #endif /* !defined(SDIO_DEVICE_ID_BROADCOM_43239) */
75 extern void wl_cfg80211_set_parent_dev(void *dev);
76 extern void sdioh_sdmmc_devintr_off(sdioh_info_t *sd);
77 extern void sdioh_sdmmc_devintr_on(sdioh_info_t *sd);
78 extern void* bcmsdh_probe(osl_t *osh, void *dev, void *sdioh, void *adapter_info, uint bus_type,
79 uint bus_num, uint slot_num);
80 extern int bcmsdh_remove(bcmsdh_info_t *bcmsdh);
82 int sdio_function_init(void);
83 void sdio_function_cleanup(void);
85 #define DESCRIPTION "bcmsdh_sdmmc Driver"
86 #define AUTHOR "Broadcom Corporation"
88 /* module param defaults */
89 static int clockoverride = 0;
91 module_param(clockoverride, int, 0644);
92 MODULE_PARM_DESC(clockoverride, "SDIO card clock override");
94 #ifdef GLOBAL_SDMMC_INSTANCE
95 PBCMSDH_SDMMC_INSTANCE gInstance;
98 /* Maximum number of bcmsdh_sdmmc devices supported by driver */
99 #define BCMSDH_SDMMC_MAX_DEVICES 1
101 extern volatile bool dhd_mmc_suspend;
103 static int sdioh_probe(struct sdio_func *func)
105 int host_idx = func->card->host->index;
106 uint32 rca = func->card->rca;
107 wifi_adapter_info_t *adapter;
109 sdioh_info_t *sdioh = NULL;
111 sd_err(("bus num (host idx)=%d, slot num (rca)=%d\n", host_idx, rca));
112 adapter = dhd_wifi_platform_get_adapter(SDIO_BUS, host_idx, rca);
114 sd_err(("found adapter info '%s'\n", adapter->name));
116 sd_err(("can't find adapter info for this chip\n"));
119 wl_cfg80211_set_parent_dev(&func->dev);
122 /* allocate SDIO Host Controller state info */
123 osh = osl_attach(&func->dev, SDIO_BUS, TRUE);
125 sd_err(("%s: osl_attach failed\n", __FUNCTION__));
128 osl_static_mem_init(osh, adapter);
129 sdioh = sdioh_attach(osh, func);
131 sd_err(("%s: sdioh_attach failed\n", __FUNCTION__));
134 sdioh->bcmsdh = bcmsdh_probe(osh, &func->dev, sdioh, adapter, SDIO_BUS, host_idx, rca);
135 if (sdioh->bcmsdh == NULL) {
136 sd_err(("%s: bcmsdh_probe failed\n", __FUNCTION__));
140 sdio_set_drvdata(func, sdioh);
145 sdioh_detach(osh, sdioh);
151 static void sdioh_remove(struct sdio_func *func)
156 sdioh = sdio_get_drvdata(func);
158 sd_err(("%s: error, no sdioh handler found\n", __FUNCTION__));
161 sd_err(("%s: Enter\n", __FUNCTION__));
164 bcmsdh_remove(sdioh->bcmsdh);
165 sdioh_detach(osh, sdioh);
169 static int bcmsdh_sdmmc_probe(struct sdio_func *func,
170 const struct sdio_device_id *id)
177 sd_err(("bcmsdh_sdmmc: %s Enter\n", __FUNCTION__));
178 sd_info(("sdio_bcmsdh: func->class=%x\n", func->class));
179 sd_info(("sdio_vendor: 0x%04x\n", func->vendor));
180 sd_info(("sdio_device: 0x%04x\n", func->device));
181 sd_info(("Function#: 0x%04x\n", func->num));
183 #ifdef GLOBAL_SDMMC_INSTANCE
184 gInstance->func[func->num] = func;
187 /* 4318 doesn't have function 2 */
188 if ((func->num == 2) || (func->num == 1 && func->device == 0x4))
189 ret = sdioh_probe(func);
194 static void bcmsdh_sdmmc_remove(struct sdio_func *func)
197 sd_err(("%s is called with NULL SDIO function pointer\n", __FUNCTION__));
201 sd_trace(("bcmsdh_sdmmc: %s Enter\n", __FUNCTION__));
202 sd_info(("sdio_bcmsdh: func->class=%x\n", func->class));
203 sd_info(("sdio_vendor: 0x%04x\n", func->vendor));
204 sd_info(("sdio_device: 0x%04x\n", func->device));
205 sd_info(("Function#: 0x%04x\n", func->num));
207 if ((func->num == 2) || (func->num == 1 && func->device == 0x4))
211 /* devices we support, null terminated */
212 static const struct sdio_device_id bcmsdh_sdmmc_ids[] = {
213 { SDIO_DEVICE(SDIO_VENDOR_ID_BROADCOM, SDIO_DEVICE_ID_BROADCOM_DEFAULT) },
214 { SDIO_DEVICE(SDIO_VENDOR_ID_BROADCOM, SDIO_DEVICE_ID_BROADCOM_4325_SDGWB) },
215 { SDIO_DEVICE(SDIO_VENDOR_ID_BROADCOM, SDIO_DEVICE_ID_BROADCOM_4325) },
216 { SDIO_DEVICE(SDIO_VENDOR_ID_BROADCOM, SDIO_DEVICE_ID_BROADCOM_4329) },
217 { SDIO_DEVICE(SDIO_VENDOR_ID_BROADCOM, SDIO_DEVICE_ID_BROADCOM_4319) },
218 { SDIO_DEVICE(SDIO_VENDOR_ID_BROADCOM, SDIO_DEVICE_ID_BROADCOM_4330) },
219 { SDIO_DEVICE(SDIO_VENDOR_ID_BROADCOM, SDIO_DEVICE_ID_BROADCOM_4334) },
220 { SDIO_DEVICE(SDIO_VENDOR_ID_BROADCOM, SDIO_DEVICE_ID_BROADCOM_4324) },
221 { SDIO_DEVICE(SDIO_VENDOR_ID_BROADCOM, SDIO_DEVICE_ID_BROADCOM_43239) },
222 { SDIO_DEVICE_CLASS(SDIO_CLASS_NONE) },
223 { /* end: all zeroes */ },
226 MODULE_DEVICE_TABLE(sdio, bcmsdh_sdmmc_ids);
228 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 39)) && defined(CONFIG_PM)
229 static int bcmsdh_sdmmc_suspend(struct device *pdev)
233 struct sdio_func *func = dev_to_sdio_func(pdev);
234 mmc_pm_flag_t sdio_flags;
236 printf("%s Enter func->num=%d\n", __FUNCTION__, func->num);
240 sdioh = sdio_get_drvdata(func);
241 err = bcmsdh_suspend(sdioh->bcmsdh);
243 printf("%s bcmsdh_suspend err=%d\n", __FUNCTION__, err);
247 sdio_flags = sdio_get_host_pm_caps(func);
248 if (!(sdio_flags & MMC_PM_KEEP_POWER)) {
249 sd_err(("%s: can't keep power while host is suspended\n", __FUNCTION__));
253 /* keep power while host suspended */
254 err = sdio_set_host_pm_flags(func, MMC_PM_KEEP_POWER);
256 sd_err(("%s: error while trying to keep power\n", __FUNCTION__));
259 #if defined(OOB_INTR_ONLY)
260 bcmsdh_oob_intr_set(sdioh->bcmsdh, FALSE);
262 dhd_mmc_suspend = TRUE;
265 printf("%s Exit\n", __FUNCTION__);
269 static int bcmsdh_sdmmc_resume(struct device *pdev)
271 #if defined(OOB_INTR_ONLY)
274 struct sdio_func *func = dev_to_sdio_func(pdev);
276 printf("%s Enter func->num=%d\n", __FUNCTION__, func->num);
280 dhd_mmc_suspend = FALSE;
281 #if defined(OOB_INTR_ONLY)
282 sdioh = sdio_get_drvdata(func);
283 bcmsdh_resume(sdioh->bcmsdh);
287 printf("%s Exit\n", __FUNCTION__);
291 static const struct dev_pm_ops bcmsdh_sdmmc_pm_ops = {
292 .suspend = bcmsdh_sdmmc_suspend,
293 .resume = bcmsdh_sdmmc_resume,
295 #endif /* (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 39)) && defined(CONFIG_PM) */
297 #if defined(BCMLXSDMMC)
298 static struct semaphore *notify_semaphore = NULL;
300 static int dummy_probe(struct sdio_func *func,
301 const struct sdio_device_id *id)
303 if (func && (func->num != 2)) {
307 if (notify_semaphore)
308 up(notify_semaphore);
312 static void dummy_remove(struct sdio_func *func)
316 static struct sdio_driver dummy_sdmmc_driver = {
317 .probe = dummy_probe,
318 .remove = dummy_remove,
319 .name = "dummy_sdmmc",
320 .id_table = bcmsdh_sdmmc_ids,
323 int sdio_func_reg_notify(void* semaphore)
325 notify_semaphore = semaphore;
326 return sdio_register_driver(&dummy_sdmmc_driver);
329 void sdio_func_unreg_notify(void)
332 sdio_unregister_driver(&dummy_sdmmc_driver);
335 #endif /* defined(BCMLXSDMMC) */
337 static struct sdio_driver bcmsdh_sdmmc_driver = {
338 .probe = bcmsdh_sdmmc_probe,
339 .remove = bcmsdh_sdmmc_remove,
340 .name = "bcmsdh_sdmmc",
341 .id_table = bcmsdh_sdmmc_ids,
342 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 39)) && defined(CONFIG_PM)
344 .pm = &bcmsdh_sdmmc_pm_ops,
346 #endif /* (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 39)) && defined(CONFIG_PM) */
354 /* Interrupt enable/disable */
356 sdioh_interrupt_set(sdioh_info_t *sd, bool enable)
361 sd_trace(("%s: %s\n", __FUNCTION__, enable ? "Enabling" : "Disabling"));
362 return SDIOH_API_RC_SUCCESS;
367 bcmsdh_module_init(void)
370 error = sdio_function_init();
375 bcmsdh_module_cleanup(void)
377 sdio_function_cleanup();
380 module_init(bcmsdh_module_init);
381 module_exit(bcmsdh_module_cleanup);
383 MODULE_LICENSE("GPL v2");
384 MODULE_DESCRIPTION(DESCRIPTION);
385 MODULE_AUTHOR(AUTHOR);
387 #endif /* BCMSDH_MODULE */
391 int bcmsdh_register_client_driver(void)
393 #ifdef GLOBAL_SDMMC_INSTANCE
394 gInstance = kzalloc(sizeof(BCMSDH_SDMMC_INSTANCE), GFP_KERNEL);
399 return sdio_register_driver(&bcmsdh_sdmmc_driver);
405 void bcmsdh_unregister_client_driver(void)
407 sdio_unregister_driver(&bcmsdh_sdmmc_driver);
408 #ifdef GLOBAL_SDMMC_INSTANCE