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 63 extern void sdioh_sdmmc_devintr_off(sdioh_info_t *sd); 64 extern void sdioh_sdmmc_devintr_on(sdioh_info_t *sd); 65 66 int sdio_function_init(void); 67 void sdio_function_cleanup(void); 68 69 #define DESCRIPTION "bcmsdh_sdmmc Driver" 70 #define AUTHOR "Broadcom Corporation" 71 72 /* module param defaults */ 73 static int clockoverride = 0; 74 75 module_param(clockoverride, int, 0644); 76 MODULE_PARM_DESC(clockoverride, "SDIO card clock override"); 77 78 PBCMSDH_SDMMC_INSTANCE gInstance; 79 80 /* Maximum number of bcmsdh_sdmmc devices supported by driver */ 81 #define BCMSDH_SDMMC_MAX_DEVICES 1 82 83 extern int bcmsdh_probe(struct device *dev); 84 extern int bcmsdh_remove(struct device *dev); 85 struct device sdmmc_dev; 86 87 static int bcmsdh_sdmmc_probe(struct sdio_func *func, 88 const struct sdio_device_id *id) 89 { 90 int ret = 0; 91 static struct sdio_func sdio_func_0; 92 sd_trace(("bcmsdh_sdmmc: %s Enter\n", __FUNCTION__)); 93 sd_trace(("sdio_bcmsdh: func->class=%x\n", func->class)); 94 sd_trace(("sdio_vendor: 0x%04x\n", func->vendor)); 95 sd_trace(("sdio_device: 0x%04x\n", func->device)); 96 sd_trace(("Function#: 0x%04x\n", func->num)); 97 98 if (func->num == 1) { 99 sdio_func_0.num = 0; 100 sdio_func_0.card = func->card; 101 gInstance->func[0] = &sdio_func_0; 102 if(func->device == 0x4) { /* 4318 */ 103 gInstance->func[2] = NULL; 104 sd_trace(("NIC found, calling bcmsdh_probe...\n")); 105 ret = bcmsdh_probe(&sdmmc_dev); 106 } 107 } 108 109 gInstance->func[func->num] = func; 110 111 if (func->num == 2) { 112 sd_trace(("F2 found, calling bcmsdh_probe...\n")); 113 ret = bcmsdh_probe(&sdmmc_dev); 114 } 115 116 return ret; 117 } 118 119 static void bcmsdh_sdmmc_remove(struct sdio_func *func) 120 { 121 sd_trace(("bcmsdh_sdmmc: %s Enter\n", __FUNCTION__)); 122 sd_info(("sdio_bcmsdh: func->class=%x\n", func->class)); 123 sd_info(("sdio_vendor: 0x%04x\n", func->vendor)); 124 sd_info(("sdio_device: 0x%04x\n", func->device)); 125 sd_info(("Function#: 0x%04x\n", func->num)); 126 127 if (func->num == 2) { 128 sd_trace(("F2 found, calling bcmsdh_remove...\n")); 129 bcmsdh_remove(&sdmmc_dev); 130 } 131 } 132 133 /* devices we support, null terminated */ 134 static const struct sdio_device_id bcmsdh_sdmmc_ids[] = { 135 { SDIO_DEVICE(SDIO_VENDOR_ID_BROADCOM, SDIO_DEVICE_ID_BROADCOM_DEFAULT) }, 136 { SDIO_DEVICE(SDIO_VENDOR_ID_BROADCOM, SDIO_DEVICE_ID_BROADCOM_4325_SDGWB) }, 137 { SDIO_DEVICE(SDIO_VENDOR_ID_BROADCOM, SDIO_DEVICE_ID_BROADCOM_4325) }, 138 { SDIO_DEVICE(SDIO_VENDOR_ID_BROADCOM, SDIO_DEVICE_ID_BROADCOM_4329) }, 139 { SDIO_DEVICE(SDIO_VENDOR_ID_BROADCOM, SDIO_DEVICE_ID_BROADCOM_4319) }, 140 { /* end: all zeroes */ }, 141 }; 142 143 MODULE_DEVICE_TABLE(sdio, bcmsdh_sdmmc_ids); 144 145 static struct sdio_driver bcmsdh_sdmmc_driver = { 146 .probe = bcmsdh_sdmmc_probe, 147 .remove = bcmsdh_sdmmc_remove, 148 .name = "bcmsdh_sdmmc", 149 .id_table = bcmsdh_sdmmc_ids, 150 }; 151 152 struct sdos_info { 153 sdioh_info_t *sd; 154 spinlock_t lock; 155 }; 156 157 158 int 159 sdioh_sdmmc_osinit(sdioh_info_t *sd) 160 { 161 struct sdos_info *sdos; 162 163 sdos = (struct sdos_info*)MALLOC(sd->osh, sizeof(struct sdos_info)); 164 sd->sdos_info = (void*)sdos; 165 if (sdos == NULL) 166 return BCME_NOMEM; 167 168 sdos->sd = sd; 169 spin_lock_init(&sdos->lock); 170 return BCME_OK; 171 } 172 173 void 174 sdioh_sdmmc_osfree(sdioh_info_t *sd) 175 { 176 struct sdos_info *sdos; 177 ASSERT(sd && sd->sdos_info); 178 179 sdos = (struct sdos_info *)sd->sdos_info; 180 MFREE(sd->osh, sdos, sizeof(struct sdos_info)); 181 } 182 183 /* Interrupt enable/disable */ 184 SDIOH_API_RC 185 sdioh_interrupt_set(sdioh_info_t *sd, bool enable) 186 { 187 ulong flags; 188 struct sdos_info *sdos; 189 190 sd_trace(("%s: %s\n", __FUNCTION__, enable ? "Enabling" : "Disabling")); 191 192 sdos = (struct sdos_info *)sd->sdos_info; 193 ASSERT(sdos); 194 195 #if !defined(OOB_INTR_ONLY) 196 if (enable && !(sd->intr_handler && sd->intr_handler_arg)) { 197 sd_err(("%s: no handler registered, will not enable\n", __FUNCTION__)); 198 return SDIOH_API_RC_FAIL; 199 } 200 #endif /* !defined(OOB_INTR_ONLY) */ 201 202 /* Ensure atomicity for enable/disable calls */ 203 spin_lock_irqsave(&sdos->lock, flags); 204 205 sd->client_intr_enabled = enable; 206 if (enable) { 207 sdioh_sdmmc_devintr_on(sd); 208 } else { 209 sdioh_sdmmc_devintr_off(sd); 210 } 211 212 spin_unlock_irqrestore(&sdos->lock, flags); 213 214 return SDIOH_API_RC_SUCCESS; 215 } 216 217 218 #ifdef BCMSDH_MODULE 219 static int __init 220 bcmsdh_module_init(void) 221 { 222 int error = 0; 223 sdio_function_init(); 224 return error; 225 } 226 227 static void __exit 228 bcmsdh_module_cleanup(void) 229 { 230 sdio_function_cleanup(); 231 } 232 233 module_init(bcmsdh_module_init); 234 module_exit(bcmsdh_module_cleanup); 235 236 MODULE_LICENSE("GPL v2"); 237 MODULE_DESCRIPTION(DESCRIPTION); 238 MODULE_AUTHOR(AUTHOR); 239 240 #endif /* BCMSDH_MODULE */ 241 /* 242 * module init 243 */ 244 int sdio_function_init(void) 245 { 246 int error = 0; 247 sd_trace(("bcmsdh_sdmmc: %s Enter\n", __FUNCTION__)); 248 249 gInstance = kzalloc(sizeof(BCMSDH_SDMMC_INSTANCE), GFP_KERNEL); 250 if (!gInstance) 251 return -ENOMEM; 252 253 bzero(&sdmmc_dev, sizeof(sdmmc_dev)); 254 error = sdio_register_driver(&bcmsdh_sdmmc_driver); 255 256 257 return error; 258 } 259 260 /* 261 * module cleanup 262 */ 263 extern int bcmsdh_remove(struct device *dev); 264 void sdio_function_cleanup(void) 265 { 266 sd_trace(("%s Enter\n", __FUNCTION__)); 267 268 269 sdio_unregister_driver(&bcmsdh_sdmmc_driver); 270 271 if (gInstance) 272 kfree(gInstance); 273 } 274