wl1251_sdio.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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/mod_devicetable.h>
  24. #include <linux/mmc/sdio_func.h>
  25. #include <linux/mmc/sdio_ids.h>
  26. #include <linux/platform_device.h>
  27. #include <linux/spi/wl12xx.h>
  28. #include "wl1251.h"
  29. #ifndef SDIO_VENDOR_ID_TI
  30. #define SDIO_VENDOR_ID_TI 0x104c
  31. #endif
  32. #ifndef SDIO_DEVICE_ID_TI_WL1251
  33. #define SDIO_DEVICE_ID_TI_WL1251 0x9066
  34. #endif
  35. static struct wl12xx_platform_data *wl12xx_board_data;
  36. static struct sdio_func *wl_to_func(struct wl1251 *wl)
  37. {
  38. return wl->if_priv;
  39. }
  40. static void wl1251_sdio_interrupt(struct sdio_func *func)
  41. {
  42. struct wl1251 *wl = sdio_get_drvdata(func);
  43. wl1251_debug(DEBUG_IRQ, "IRQ");
  44. /* FIXME should be synchronous for sdio */
  45. ieee80211_queue_work(wl->hw, &wl->irq_work);
  46. }
  47. static const struct sdio_device_id wl1251_devices[] = {
  48. { SDIO_DEVICE(SDIO_VENDOR_ID_TI, SDIO_DEVICE_ID_TI_WL1251) },
  49. {}
  50. };
  51. MODULE_DEVICE_TABLE(sdio, wl1251_devices);
  52. static void wl1251_sdio_read(struct wl1251 *wl, int addr,
  53. void *buf, size_t len)
  54. {
  55. int ret;
  56. struct sdio_func *func = wl_to_func(wl);
  57. sdio_claim_host(func);
  58. ret = sdio_memcpy_fromio(func, buf, addr, len);
  59. if (ret)
  60. wl1251_error("sdio read failed (%d)", ret);
  61. sdio_release_host(func);
  62. }
  63. static void wl1251_sdio_write(struct wl1251 *wl, int addr,
  64. void *buf, size_t len)
  65. {
  66. int ret;
  67. struct sdio_func *func = wl_to_func(wl);
  68. sdio_claim_host(func);
  69. ret = sdio_memcpy_toio(func, addr, buf, len);
  70. if (ret)
  71. wl1251_error("sdio write failed (%d)", ret);
  72. sdio_release_host(func);
  73. }
  74. static void wl1251_sdio_read_elp(struct wl1251 *wl, int addr, u32 *val)
  75. {
  76. int ret = 0;
  77. struct sdio_func *func = wl_to_func(wl);
  78. sdio_claim_host(func);
  79. *val = sdio_readb(func, addr, &ret);
  80. sdio_release_host(func);
  81. if (ret)
  82. wl1251_error("sdio_readb failed (%d)", ret);
  83. }
  84. static void wl1251_sdio_write_elp(struct wl1251 *wl, int addr, u32 val)
  85. {
  86. int ret = 0;
  87. struct sdio_func *func = wl_to_func(wl);
  88. sdio_claim_host(func);
  89. sdio_writeb(func, val, addr, &ret);
  90. sdio_release_host(func);
  91. if (ret)
  92. wl1251_error("sdio_writeb failed (%d)", ret);
  93. }
  94. static void wl1251_sdio_reset(struct wl1251 *wl)
  95. {
  96. }
  97. static void wl1251_sdio_enable_irq(struct wl1251 *wl)
  98. {
  99. struct sdio_func *func = wl_to_func(wl);
  100. sdio_claim_host(func);
  101. sdio_claim_irq(func, wl1251_sdio_interrupt);
  102. sdio_release_host(func);
  103. }
  104. static void wl1251_sdio_disable_irq(struct wl1251 *wl)
  105. {
  106. struct sdio_func *func = wl_to_func(wl);
  107. sdio_claim_host(func);
  108. sdio_release_irq(func);
  109. sdio_release_host(func);
  110. }
  111. static void wl1251_sdio_set_power(bool enable)
  112. {
  113. }
  114. static const struct wl1251_if_operations wl1251_sdio_ops = {
  115. .read = wl1251_sdio_read,
  116. .write = wl1251_sdio_write,
  117. .write_elp = wl1251_sdio_write_elp,
  118. .read_elp = wl1251_sdio_read_elp,
  119. .reset = wl1251_sdio_reset,
  120. .enable_irq = wl1251_sdio_enable_irq,
  121. .disable_irq = wl1251_sdio_disable_irq,
  122. };
  123. static int wl1251_platform_probe(struct platform_device *pdev)
  124. {
  125. if (pdev->id != -1) {
  126. wl1251_error("can only handle single device");
  127. return -ENODEV;
  128. }
  129. wl12xx_board_data = pdev->dev.platform_data;
  130. return 0;
  131. }
  132. /*
  133. * Dummy platform_driver for passing platform_data to this driver,
  134. * until we have a way to pass this through SDIO subsystem or
  135. * some other way.
  136. */
  137. static struct platform_driver wl1251_platform_driver = {
  138. .driver = {
  139. .name = "wl1251_data",
  140. .owner = THIS_MODULE,
  141. },
  142. .probe = wl1251_platform_probe,
  143. };
  144. static int wl1251_sdio_probe(struct sdio_func *func,
  145. const struct sdio_device_id *id)
  146. {
  147. int ret;
  148. struct wl1251 *wl;
  149. struct ieee80211_hw *hw;
  150. hw = wl1251_alloc_hw();
  151. if (IS_ERR(hw))
  152. return PTR_ERR(hw);
  153. wl = hw->priv;
  154. sdio_claim_host(func);
  155. ret = sdio_enable_func(func);
  156. if (ret)
  157. goto release;
  158. sdio_set_block_size(func, 512);
  159. SET_IEEE80211_DEV(hw, &func->dev);
  160. wl->if_priv = func;
  161. wl->if_ops = &wl1251_sdio_ops;
  162. wl->set_power = wl1251_sdio_set_power;
  163. if (wl12xx_board_data != NULL) {
  164. wl->set_power = wl12xx_board_data->set_power;
  165. wl->use_eeprom = wl12xx_board_data->use_eeprom;
  166. }
  167. sdio_release_host(func);
  168. ret = wl1251_init_ieee80211(wl);
  169. if (ret)
  170. goto disable;
  171. sdio_set_drvdata(func, wl);
  172. return ret;
  173. disable:
  174. sdio_claim_host(func);
  175. sdio_disable_func(func);
  176. release:
  177. sdio_release_host(func);
  178. return ret;
  179. }
  180. static void __devexit wl1251_sdio_remove(struct sdio_func *func)
  181. {
  182. struct wl1251 *wl = sdio_get_drvdata(func);
  183. wl1251_free_hw(wl);
  184. sdio_claim_host(func);
  185. sdio_release_irq(func);
  186. sdio_disable_func(func);
  187. sdio_release_host(func);
  188. }
  189. static struct sdio_driver wl1251_sdio_driver = {
  190. .name = "wl1251_sdio",
  191. .id_table = wl1251_devices,
  192. .probe = wl1251_sdio_probe,
  193. .remove = __devexit_p(wl1251_sdio_remove),
  194. };
  195. static int __init wl1251_sdio_init(void)
  196. {
  197. int err;
  198. err = platform_driver_register(&wl1251_platform_driver);
  199. if (err) {
  200. wl1251_error("failed to register platform driver: %d", err);
  201. return err;
  202. }
  203. err = sdio_register_driver(&wl1251_sdio_driver);
  204. if (err)
  205. wl1251_error("failed to register sdio driver: %d", err);
  206. return err;
  207. }
  208. static void __exit wl1251_sdio_exit(void)
  209. {
  210. sdio_unregister_driver(&wl1251_sdio_driver);
  211. platform_driver_unregister(&wl1251_platform_driver);
  212. wl1251_notice("unloaded");
  213. }
  214. module_init(wl1251_sdio_init);
  215. module_exit(wl1251_sdio_exit);
  216. MODULE_LICENSE("GPL");
  217. MODULE_AUTHOR("Kalle Valo <kalle.valo@nokia.com>");