wl1251_sdio.c 7.0 KB

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