wl1251_sdio.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /*
  2. * wl12xx SDIO routines
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. * General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program; if not, write to the Free Software
  15. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  16. * 02110-1301 USA
  17. *
  18. * Copyright (C) 2005 Texas Instruments Incorporated
  19. * Copyright (C) 2008 Google Inc
  20. * Copyright (C) 2009 Bob Copeland (me@bobcopeland.com)
  21. */
  22. #include <linux/module.h>
  23. #include <linux/crc7.h>
  24. #include <linux/mod_devicetable.h>
  25. #include <linux/irq.h>
  26. #include <linux/mmc/sdio_func.h>
  27. #include <linux/mmc/sdio_ids.h>
  28. #include <linux/platform_device.h>
  29. #include "wl1251.h"
  30. #include "wl12xx_80211.h"
  31. #include "wl1251_reg.h"
  32. #include "wl1251_ps.h"
  33. #include "wl1251_io.h"
  34. #include "wl1251_tx.h"
  35. #include "wl1251_debugfs.h"
  36. #ifndef SDIO_VENDOR_ID_TI
  37. #define SDIO_VENDOR_ID_TI 0x104c
  38. #endif
  39. #ifndef SDIO_DEVICE_ID_TI_WL1251
  40. #define SDIO_DEVICE_ID_TI_WL1251 0x9066
  41. #endif
  42. static struct sdio_func *wl_to_func(struct wl1251 *wl)
  43. {
  44. return wl->if_priv;
  45. }
  46. static void wl1251_sdio_interrupt(struct sdio_func *func)
  47. {
  48. struct wl1251 *wl = sdio_get_drvdata(func);
  49. wl1251_debug(DEBUG_IRQ, "IRQ");
  50. /* FIXME should be synchronous for sdio */
  51. ieee80211_queue_work(wl->hw, &wl->irq_work);
  52. }
  53. static const struct sdio_device_id wl1251_devices[] = {
  54. { SDIO_DEVICE(SDIO_VENDOR_ID_TI, SDIO_DEVICE_ID_TI_WL1251) },
  55. {}
  56. };
  57. MODULE_DEVICE_TABLE(sdio, wl1251_devices);
  58. void wl1251_sdio_read(struct wl1251 *wl, int addr, void *buf, size_t len)
  59. {
  60. int ret;
  61. struct sdio_func *func = wl_to_func(wl);
  62. sdio_claim_host(func);
  63. ret = sdio_memcpy_fromio(func, buf, addr, len);
  64. if (ret)
  65. wl1251_error("sdio read failed (%d)", ret);
  66. sdio_release_host(func);
  67. }
  68. void wl1251_sdio_write(struct wl1251 *wl, int addr, void *buf, size_t len)
  69. {
  70. int ret;
  71. struct sdio_func *func = wl_to_func(wl);
  72. sdio_claim_host(func);
  73. ret = sdio_memcpy_toio(func, addr, buf, len);
  74. if (ret)
  75. wl1251_error("sdio write failed (%d)", ret);
  76. sdio_release_host(func);
  77. }
  78. void wl1251_sdio_reset(struct wl1251 *wl)
  79. {
  80. }
  81. static void wl1251_sdio_enable_irq(struct wl1251 *wl)
  82. {
  83. struct sdio_func *func = wl_to_func(wl);
  84. sdio_claim_host(func);
  85. sdio_claim_irq(func, wl1251_sdio_interrupt);
  86. sdio_release_host(func);
  87. }
  88. static void wl1251_sdio_disable_irq(struct wl1251 *wl)
  89. {
  90. struct sdio_func *func = wl_to_func(wl);
  91. sdio_claim_host(func);
  92. sdio_release_irq(func);
  93. sdio_release_host(func);
  94. }
  95. void wl1251_sdio_set_power(bool enable)
  96. {
  97. }
  98. struct wl1251_if_operations wl1251_sdio_ops = {
  99. .read = wl1251_sdio_read,
  100. .write = wl1251_sdio_write,
  101. .reset = wl1251_sdio_reset,
  102. .enable_irq = wl1251_sdio_enable_irq,
  103. .disable_irq = wl1251_sdio_disable_irq,
  104. };
  105. int wl1251_sdio_probe(struct sdio_func *func, const struct sdio_device_id *id)
  106. {
  107. int ret;
  108. struct wl1251 *wl;
  109. struct ieee80211_hw *hw;
  110. hw = wl1251_alloc_hw();
  111. if (IS_ERR(hw))
  112. return PTR_ERR(hw);
  113. wl = hw->priv;
  114. sdio_claim_host(func);
  115. ret = sdio_enable_func(func);
  116. if (ret)
  117. goto release;
  118. sdio_set_block_size(func, 512);
  119. SET_IEEE80211_DEV(hw, &func->dev);
  120. wl->if_priv = func;
  121. wl->if_ops = &wl1251_sdio_ops;
  122. wl->set_power = wl1251_sdio_set_power;
  123. sdio_release_host(func);
  124. ret = wl1251_init_ieee80211(wl);
  125. if (ret)
  126. goto disable;
  127. sdio_set_drvdata(func, wl);
  128. return ret;
  129. disable:
  130. sdio_claim_host(func);
  131. sdio_disable_func(func);
  132. release:
  133. sdio_release_host(func);
  134. return ret;
  135. }
  136. static void __devexit wl1251_sdio_remove(struct sdio_func *func)
  137. {
  138. struct wl1251 *wl = sdio_get_drvdata(func);
  139. wl1251_free_hw(wl);
  140. sdio_claim_host(func);
  141. sdio_release_irq(func);
  142. sdio_disable_func(func);
  143. sdio_release_host(func);
  144. }
  145. static struct sdio_driver wl1251_sdio_driver = {
  146. .name = "wl1251_sdio",
  147. .id_table = wl1251_devices,
  148. .probe = wl1251_sdio_probe,
  149. .remove = __devexit_p(wl1251_sdio_remove),
  150. };
  151. static int __init wl1251_sdio_init(void)
  152. {
  153. int err;
  154. err = sdio_register_driver(&wl1251_sdio_driver);
  155. if (err)
  156. wl1251_error("failed to register sdio driver: %d", err);
  157. return err;
  158. }
  159. static void __exit wl1251_sdio_exit(void)
  160. {
  161. sdio_unregister_driver(&wl1251_sdio_driver);
  162. wl1251_notice("unloaded");
  163. }
  164. module_init(wl1251_sdio_init);
  165. module_exit(wl1251_sdio_exit);
  166. MODULE_LICENSE("GPL");
  167. MODULE_AUTHOR("Kalle Valo <kalle.valo@nokia.com>");