bcmsdh_sdmmc_linux.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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.15 2010/04/14 21:11:46 Exp $
  25. */
  26. #include <typedefs.h>
  27. #include <bcmutils.h>
  28. #include <sdio.h> /* SDIO Specs */
  29. #include <bcmsdbus.h> /* bcmsdh to/from specific controller APIs */
  30. #include <sdiovar.h> /* to get msglevel bit values */
  31. #include <linux/sched.h> /* request_irq() */
  32. #include <linux/mmc/core.h>
  33. #include <linux/mmc/card.h>
  34. #include <linux/mmc/sdio_func.h>
  35. #include <linux/mmc/sdio_ids.h>
  36. #if !defined(SDIO_VENDOR_ID_BROADCOM)
  37. #define SDIO_VENDOR_ID_BROADCOM 0x02d0
  38. #endif /* !defined(SDIO_DEVICE_ID_BROADCOM_4325) */
  39. #if !defined(SDIO_DEVICE_ID_BROADCOM_4325)
  40. #define SDIO_DEVICE_ID_BROADCOM_4325 0x0000
  41. #endif /* !defined(SDIO_DEVICE_ID_BROADCOM_4325) */
  42. #if !defined(SDIO_DEVICE_ID_BROADCOM_4329)
  43. #define SDIO_DEVICE_ID_BROADCOM_4329 0x4329
  44. #endif /* !defined(SDIO_DEVICE_ID_BROADCOM_4329) */
  45. #if !defined(SDIO_DEVICE_ID_BROADCOM_4319)
  46. #define SDIO_DEVICE_ID_BROADCOM_4319 0x4319
  47. #endif /* !defined(SDIO_DEVICE_ID_BROADCOM_4329) */
  48. #include <bcmsdh_sdmmc.h>
  49. #include <dhd_dbg.h>
  50. extern void sdioh_sdmmc_devintr_off(sdioh_info_t *sd);
  51. extern void sdioh_sdmmc_devintr_on(sdioh_info_t *sd);
  52. int sdio_function_init(void);
  53. void sdio_function_cleanup(void);
  54. #define DESCRIPTION "bcmsdh_sdmmc Driver"
  55. #define AUTHOR "Broadcom Corporation"
  56. /* module param defaults */
  57. static int clockoverride = 0;
  58. module_param(clockoverride, int, 0644);
  59. MODULE_PARM_DESC(clockoverride, "SDIO card clock override");
  60. PBCMSDH_SDMMC_INSTANCE gInstance;
  61. /* Maximum number of bcmsdh_sdmmc devices supported by driver */
  62. #define BCMSDH_SDMMC_MAX_DEVICES 1
  63. extern int bcmsdh_probe(struct device *dev);
  64. extern int bcmsdh_remove(struct device *dev);
  65. struct device sdmmc_dev;
  66. static int bcmsdh_sdmmc_probe(struct sdio_func *func,
  67. const struct sdio_device_id *id)
  68. {
  69. int ret = 0;
  70. static struct sdio_func sdio_func_0;
  71. sd_trace(("bcmsdh_sdmmc: %s Enter\n", __FUNCTION__));
  72. sd_trace(("sdio_bcmsdh: func->class=%x\n", func->class));
  73. sd_trace(("sdio_vendor: 0x%04x\n", func->vendor));
  74. sd_trace(("sdio_device: 0x%04x\n", func->device));
  75. sd_trace(("Function#: 0x%04x\n", func->num));
  76. if (func->num == 1) {
  77. sdio_func_0.num = 0;
  78. sdio_func_0.card = func->card;
  79. gInstance->func[0] = &sdio_func_0;
  80. if(func->device == 0x4) { /* 4318 */
  81. gInstance->func[2] = NULL;
  82. sd_trace(("NIC found, calling bcmsdh_probe...\n"));
  83. ret = bcmsdh_probe(&sdmmc_dev);
  84. }
  85. }
  86. gInstance->func[func->num] = func;
  87. if (func->num == 2) {
  88. sd_trace(("F2 found, calling bcmsdh_probe...\n"));
  89. ret = bcmsdh_probe(&sdmmc_dev);
  90. }
  91. return ret;
  92. }
  93. static void bcmsdh_sdmmc_remove(struct sdio_func *func)
  94. {
  95. sd_trace(("bcmsdh_sdmmc: %s Enter\n", __FUNCTION__));
  96. sd_info(("sdio_bcmsdh: func->class=%x\n", func->class));
  97. sd_info(("sdio_vendor: 0x%04x\n", func->vendor));
  98. sd_info(("sdio_device: 0x%04x\n", func->device));
  99. sd_info(("Function#: 0x%04x\n", func->num));
  100. if (func->num == 2) {
  101. sd_trace(("F2 found, calling bcmsdh_remove...\n"));
  102. bcmsdh_remove(&sdmmc_dev);
  103. }
  104. }
  105. /* devices we support, null terminated */
  106. static const struct sdio_device_id bcmsdh_sdmmc_ids[] = {
  107. { SDIO_DEVICE(SDIO_VENDOR_ID_BROADCOM, SDIO_DEVICE_ID_BROADCOM_4325) },
  108. { SDIO_DEVICE(SDIO_VENDOR_ID_BROADCOM, SDIO_DEVICE_ID_BROADCOM_4329) },
  109. { SDIO_DEVICE(SDIO_VENDOR_ID_BROADCOM, SDIO_DEVICE_ID_BROADCOM_4319) },
  110. { /* end: all zeroes */ },
  111. };
  112. MODULE_DEVICE_TABLE(sdio, bcmsdh_sdmmc_ids);
  113. static struct sdio_driver bcmsdh_sdmmc_driver = {
  114. .probe = bcmsdh_sdmmc_probe,
  115. .remove = bcmsdh_sdmmc_remove,
  116. .name = "bcmsdh_sdmmc",
  117. .id_table = bcmsdh_sdmmc_ids,
  118. };
  119. struct sdos_info {
  120. sdioh_info_t *sd;
  121. spinlock_t lock;
  122. };
  123. int
  124. sdioh_sdmmc_osinit(sdioh_info_t *sd)
  125. {
  126. struct sdos_info *sdos;
  127. sdos = (struct sdos_info*)MALLOC(sd->osh, sizeof(struct sdos_info));
  128. sd->sdos_info = (void*)sdos;
  129. if (sdos == NULL)
  130. return BCME_NOMEM;
  131. sdos->sd = sd;
  132. spin_lock_init(&sdos->lock);
  133. return BCME_OK;
  134. }
  135. void
  136. sdioh_sdmmc_osfree(sdioh_info_t *sd)
  137. {
  138. struct sdos_info *sdos;
  139. ASSERT(sd && sd->sdos_info);
  140. sdos = (struct sdos_info *)sd->sdos_info;
  141. MFREE(sd->osh, sdos, sizeof(struct sdos_info));
  142. }
  143. /* Interrupt enable/disable */
  144. SDIOH_API_RC
  145. sdioh_interrupt_set(sdioh_info_t *sd, bool enable)
  146. {
  147. ulong flags;
  148. struct sdos_info *sdos;
  149. sd_trace(("%s: %s\n", __FUNCTION__, enable ? "Enabling" : "Disabling"));
  150. sdos = (struct sdos_info *)sd->sdos_info;
  151. ASSERT(sdos);
  152. #if !defined(OOB_INTR_ONLY)
  153. if (enable && !(sd->intr_handler && sd->intr_handler_arg)) {
  154. sd_err(("%s: no handler registered, will not enable\n", __FUNCTION__));
  155. return SDIOH_API_RC_FAIL;
  156. }
  157. #endif /* !defined(OOB_INTR_ONLY) */
  158. /* Ensure atomicity for enable/disable calls */
  159. spin_lock_irqsave(&sdos->lock, flags);
  160. sd->client_intr_enabled = enable;
  161. if (enable) {
  162. sdioh_sdmmc_devintr_on(sd);
  163. } else {
  164. sdioh_sdmmc_devintr_off(sd);
  165. }
  166. spin_unlock_irqrestore(&sdos->lock, flags);
  167. return SDIOH_API_RC_SUCCESS;
  168. }
  169. #ifdef BCMSDH_MODULE
  170. static int __init
  171. bcmsdh_module_init(void)
  172. {
  173. int error = 0;
  174. sdio_function_init();
  175. return error;
  176. }
  177. static void __exit
  178. bcmsdh_module_cleanup(void)
  179. {
  180. sdio_function_cleanup();
  181. }
  182. module_init(bcmsdh_module_init);
  183. module_exit(bcmsdh_module_cleanup);
  184. MODULE_LICENSE("GPL v2");
  185. MODULE_DESCRIPTION(DESCRIPTION);
  186. MODULE_AUTHOR(AUTHOR);
  187. #endif /* BCMSDH_MODULE */
  188. /*
  189. * module init
  190. */
  191. int sdio_function_init(void)
  192. {
  193. int error = 0;
  194. sd_trace(("bcmsdh_sdmmc: %s Enter\n", __FUNCTION__));
  195. gInstance = kzalloc(sizeof(BCMSDH_SDMMC_INSTANCE), GFP_KERNEL);
  196. if (!gInstance)
  197. return -ENOMEM;
  198. bzero(&sdmmc_dev, sizeof(sdmmc_dev));
  199. error = sdio_register_driver(&bcmsdh_sdmmc_driver);
  200. return error;
  201. }
  202. /*
  203. * module cleanup
  204. */
  205. extern int bcmsdh_remove(struct device *dev);
  206. void sdio_function_cleanup(void)
  207. {
  208. sd_trace(("%s Enter\n", __FUNCTION__));
  209. sdio_unregister_driver(&bcmsdh_sdmmc_driver);
  210. if (gInstance)
  211. kfree(gInstance);
  212. }