wl1271_sdio.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. /*
  2. * This file is part of wl1271
  3. *
  4. * Copyright (C) 2009-2010 Nokia Corporation
  5. *
  6. * Contact: Luciano Coelho <luciano.coelho@nokia.com>
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * version 2 as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA
  21. *
  22. */
  23. #include <linux/irq.h>
  24. #include <linux/module.h>
  25. #include <linux/crc7.h>
  26. #include <linux/vmalloc.h>
  27. #include <linux/mmc/sdio_func.h>
  28. #include <linux/mmc/sdio_ids.h>
  29. #include <linux/mmc/card.h>
  30. #include <plat/gpio.h>
  31. #include "wl1271.h"
  32. #include "wl12xx_80211.h"
  33. #include "wl1271_io.h"
  34. #define RX71_WL1271_IRQ_GPIO 42
  35. #ifndef SDIO_VENDOR_ID_TI
  36. #define SDIO_VENDOR_ID_TI 0x0097
  37. #endif
  38. #ifndef SDIO_DEVICE_ID_TI_WL1271
  39. #define SDIO_DEVICE_ID_TI_WL1271 0x4076
  40. #endif
  41. static const struct sdio_device_id wl1271_devices[] = {
  42. { SDIO_DEVICE(SDIO_VENDOR_ID_TI, SDIO_DEVICE_ID_TI_WL1271) },
  43. {}
  44. };
  45. MODULE_DEVICE_TABLE(sdio, wl1271_devices);
  46. static inline struct sdio_func *wl_to_func(struct wl1271 *wl)
  47. {
  48. return wl->if_priv;
  49. }
  50. static struct device *wl1271_sdio_wl_to_dev(struct wl1271 *wl)
  51. {
  52. return &(wl_to_func(wl)->dev);
  53. }
  54. static irqreturn_t wl1271_irq(int irq, void *cookie)
  55. {
  56. struct wl1271 *wl = cookie;
  57. unsigned long flags;
  58. wl1271_debug(DEBUG_IRQ, "IRQ");
  59. /* complete the ELP completion */
  60. spin_lock_irqsave(&wl->wl_lock, flags);
  61. if (wl->elp_compl) {
  62. complete(wl->elp_compl);
  63. wl->elp_compl = NULL;
  64. }
  65. if (!test_and_set_bit(WL1271_FLAG_IRQ_RUNNING, &wl->flags))
  66. ieee80211_queue_work(wl->hw, &wl->irq_work);
  67. set_bit(WL1271_FLAG_IRQ_PENDING, &wl->flags);
  68. spin_unlock_irqrestore(&wl->wl_lock, flags);
  69. return IRQ_HANDLED;
  70. }
  71. static void wl1271_sdio_disable_interrupts(struct wl1271 *wl)
  72. {
  73. disable_irq(wl->irq);
  74. }
  75. static void wl1271_sdio_enable_interrupts(struct wl1271 *wl)
  76. {
  77. enable_irq(wl->irq);
  78. }
  79. static void wl1271_sdio_reset(struct wl1271 *wl)
  80. {
  81. }
  82. static void wl1271_sdio_init(struct wl1271 *wl)
  83. {
  84. }
  85. static void wl1271_sdio_raw_read(struct wl1271 *wl, int addr, void *buf,
  86. size_t len, bool fixed)
  87. {
  88. int ret;
  89. struct sdio_func *func = wl_to_func(wl);
  90. sdio_claim_host(func);
  91. if (unlikely(addr == HW_ACCESS_ELP_CTRL_REG_ADDR)) {
  92. ((u8 *)buf)[0] = sdio_f0_readb(func, addr, &ret);
  93. wl1271_debug(DEBUG_SPI, "sdio read 52 addr 0x%x, byte 0x%02x",
  94. addr, ((u8 *)buf)[0]);
  95. } else {
  96. if (fixed)
  97. ret = sdio_readsb(func, buf, addr, len);
  98. else
  99. ret = sdio_memcpy_fromio(func, buf, addr, len);
  100. wl1271_debug(DEBUG_SPI, "sdio read 53 addr 0x%x, %d bytes",
  101. addr, len);
  102. wl1271_dump_ascii(DEBUG_SPI, "data: ", buf, len);
  103. }
  104. if (ret)
  105. wl1271_error("sdio read failed (%d)", ret);
  106. sdio_release_host(func);
  107. }
  108. static void wl1271_sdio_raw_write(struct wl1271 *wl, int addr, void *buf,
  109. size_t len, bool fixed)
  110. {
  111. int ret;
  112. struct sdio_func *func = wl_to_func(wl);
  113. sdio_claim_host(func);
  114. if (unlikely(addr == HW_ACCESS_ELP_CTRL_REG_ADDR)) {
  115. sdio_f0_writeb(func, ((u8 *)buf)[0], addr, &ret);
  116. wl1271_debug(DEBUG_SPI, "sdio write 52 addr 0x%x, byte 0x%02x",
  117. addr, ((u8 *)buf)[0]);
  118. } else {
  119. wl1271_debug(DEBUG_SPI, "sdio write 53 addr 0x%x, %d bytes",
  120. addr, len);
  121. wl1271_dump_ascii(DEBUG_SPI, "data: ", buf, len);
  122. if (fixed)
  123. ret = sdio_writesb(func, addr, buf, len);
  124. else
  125. ret = sdio_memcpy_toio(func, addr, buf, len);
  126. }
  127. if (ret)
  128. wl1271_error("sdio write failed (%d)", ret);
  129. sdio_release_host(func);
  130. }
  131. static struct wl1271_if_operations sdio_ops = {
  132. .read = wl1271_sdio_raw_read,
  133. .write = wl1271_sdio_raw_write,
  134. .reset = wl1271_sdio_reset,
  135. .init = wl1271_sdio_init,
  136. .dev = wl1271_sdio_wl_to_dev,
  137. .enable_irq = wl1271_sdio_enable_interrupts,
  138. .disable_irq = wl1271_sdio_disable_interrupts
  139. };
  140. static void wl1271_sdio_set_power(bool enable)
  141. {
  142. }
  143. static int __devinit wl1271_probe(struct sdio_func *func,
  144. const struct sdio_device_id *id)
  145. {
  146. struct ieee80211_hw *hw;
  147. struct wl1271 *wl;
  148. int ret;
  149. /* We are only able to handle the wlan function */
  150. if (func->num != 0x02)
  151. return -ENODEV;
  152. hw = wl1271_alloc_hw();
  153. if (IS_ERR(hw))
  154. return PTR_ERR(hw);
  155. wl = hw->priv;
  156. wl->if_priv = func;
  157. wl->if_ops = &sdio_ops;
  158. wl->set_power = wl1271_sdio_set_power;
  159. /* Grab access to FN0 for ELP reg. */
  160. func->card->quirks |= MMC_QUIRK_LENIENT_FN0;
  161. wl->irq = gpio_to_irq(RX71_WL1271_IRQ_GPIO);
  162. if (wl->irq < 0) {
  163. ret = wl->irq;
  164. wl1271_error("could not get irq!");
  165. goto out_free;
  166. }
  167. ret = request_irq(wl->irq, wl1271_irq, 0, DRIVER_NAME, wl);
  168. if (ret < 0) {
  169. wl1271_error("request_irq() failed: %d", ret);
  170. goto out_free;
  171. }
  172. set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
  173. disable_irq(wl->irq);
  174. ret = wl1271_init_ieee80211(wl);
  175. if (ret)
  176. goto out_irq;
  177. ret = wl1271_register_hw(wl);
  178. if (ret)
  179. goto out_irq;
  180. sdio_claim_host(func);
  181. sdio_set_drvdata(func, wl);
  182. ret = sdio_enable_func(func);
  183. if (ret)
  184. goto out_release;
  185. sdio_release_host(func);
  186. wl1271_notice("initialized");
  187. return 0;
  188. out_release:
  189. sdio_release_host(func);
  190. out_irq:
  191. free_irq(wl->irq, wl);
  192. out_free:
  193. ieee80211_free_hw(hw);
  194. return ret;
  195. }
  196. static void __devexit wl1271_remove(struct sdio_func *func)
  197. {
  198. struct wl1271 *wl = sdio_get_drvdata(func);
  199. ieee80211_unregister_hw(wl->hw);
  200. sdio_claim_host(func);
  201. sdio_disable_func(func);
  202. sdio_release_host(func);
  203. free_irq(wl->irq, wl);
  204. kfree(wl->target_mem_map);
  205. vfree(wl->fw);
  206. wl->fw = NULL;
  207. kfree(wl->nvs);
  208. wl->nvs = NULL;
  209. kfree(wl->fw_status);
  210. kfree(wl->tx_res_if);
  211. ieee80211_free_hw(wl->hw);
  212. }
  213. static struct sdio_driver wl1271_sdio_driver = {
  214. .name = "wl1271",
  215. .id_table = wl1271_devices,
  216. .probe = wl1271_probe,
  217. .remove = __devexit_p(wl1271_remove),
  218. };
  219. static int __init wl1271_init(void)
  220. {
  221. int ret;
  222. ret = sdio_register_driver(&wl1271_sdio_driver);
  223. if (ret < 0) {
  224. wl1271_error("failed to register sdio driver: %d", ret);
  225. goto out;
  226. }
  227. out:
  228. return ret;
  229. }
  230. static void __exit wl1271_exit(void)
  231. {
  232. sdio_unregister_driver(&wl1271_sdio_driver);
  233. wl1271_notice("unloaded");
  234. }
  235. module_init(wl1271_init);
  236. module_exit(wl1271_exit);
  237. MODULE_LICENSE("GPL");
  238. MODULE_AUTHOR("Luciano Coelho <luciano.coelho@nokia.com>");
  239. MODULE_AUTHOR("Juuso Oikarinen <juuso.oikarinen@nokia.com>");
  240. MODULE_FIRMWARE(WL1271_FW_NAME);