ahb.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. /*
  2. * Copyright (c) 2008-2009 Atheros Communications Inc.
  3. * Copyright (c) 2009 Gabor Juhos <juhosg@openwrt.org>
  4. * Copyright (c) 2009 Imre Kaloz <kaloz@openwrt.org>
  5. *
  6. * Permission to use, copy, modify, and/or distribute this software for any
  7. * purpose with or without fee is hereby granted, provided that the above
  8. * copyright notice and this permission notice appear in all copies.
  9. *
  10. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  11. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  12. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  13. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  14. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  15. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  16. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  17. */
  18. #include <linux/nl80211.h>
  19. #include <linux/platform_device.h>
  20. #include <linux/etherdevice.h>
  21. #include <linux/export.h>
  22. #include <ar231x_platform.h>
  23. #include "ath5k.h"
  24. #include "debug.h"
  25. #include "base.h"
  26. #include "reg.h"
  27. /* return bus cachesize in 4B word units */
  28. static void ath5k_ahb_read_cachesize(struct ath_common *common, int *csz)
  29. {
  30. *csz = L1_CACHE_BYTES >> 2;
  31. }
  32. static bool
  33. ath5k_ahb_eeprom_read(struct ath_common *common, u32 off, u16 *data)
  34. {
  35. struct ath5k_hw *ah = common->priv;
  36. struct platform_device *pdev = to_platform_device(ah->dev);
  37. struct ar231x_board_config *bcfg = pdev->dev.platform_data;
  38. u16 *eeprom, *eeprom_end;
  39. bcfg = pdev->dev.platform_data;
  40. eeprom = (u16 *) bcfg->radio;
  41. eeprom_end = ((void *) bcfg->config) + BOARD_CONFIG_BUFSZ;
  42. eeprom += off;
  43. if (eeprom > eeprom_end)
  44. return false;
  45. *data = *eeprom;
  46. return true;
  47. }
  48. int ath5k_hw_read_srev(struct ath5k_hw *ah)
  49. {
  50. struct platform_device *pdev = to_platform_device(ah->dev);
  51. struct ar231x_board_config *bcfg = pdev->dev.platform_data;
  52. ah->ah_mac_srev = bcfg->devid;
  53. return 0;
  54. }
  55. static int ath5k_ahb_eeprom_read_mac(struct ath5k_hw *ah, u8 *mac)
  56. {
  57. struct platform_device *pdev = to_platform_device(ah->dev);
  58. struct ar231x_board_config *bcfg = pdev->dev.platform_data;
  59. u8 *cfg_mac;
  60. if (to_platform_device(ah->dev)->id == 0)
  61. cfg_mac = bcfg->config->wlan0_mac;
  62. else
  63. cfg_mac = bcfg->config->wlan1_mac;
  64. memcpy(mac, cfg_mac, ETH_ALEN);
  65. return 0;
  66. }
  67. static const struct ath_bus_ops ath_ahb_bus_ops = {
  68. .ath_bus_type = ATH_AHB,
  69. .read_cachesize = ath5k_ahb_read_cachesize,
  70. .eeprom_read = ath5k_ahb_eeprom_read,
  71. .eeprom_read_mac = ath5k_ahb_eeprom_read_mac,
  72. };
  73. /*Initialization*/
  74. static int ath_ahb_probe(struct platform_device *pdev)
  75. {
  76. struct ar231x_board_config *bcfg = pdev->dev.platform_data;
  77. struct ath5k_hw *ah;
  78. struct ieee80211_hw *hw;
  79. struct resource *res;
  80. void __iomem *mem;
  81. int irq;
  82. int ret = 0;
  83. u32 reg;
  84. if (!pdev->dev.platform_data) {
  85. dev_err(&pdev->dev, "no platform data specified\n");
  86. ret = -EINVAL;
  87. goto err_out;
  88. }
  89. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  90. if (res == NULL) {
  91. dev_err(&pdev->dev, "no memory resource found\n");
  92. ret = -ENXIO;
  93. goto err_out;
  94. }
  95. mem = ioremap_nocache(res->start, resource_size(res));
  96. if (mem == NULL) {
  97. dev_err(&pdev->dev, "ioremap failed\n");
  98. ret = -ENOMEM;
  99. goto err_out;
  100. }
  101. res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  102. if (res == NULL) {
  103. dev_err(&pdev->dev, "no IRQ resource found\n");
  104. ret = -ENXIO;
  105. goto err_iounmap;
  106. }
  107. irq = res->start;
  108. hw = ieee80211_alloc_hw(sizeof(struct ath5k_hw), &ath5k_hw_ops);
  109. if (hw == NULL) {
  110. dev_err(&pdev->dev, "no memory for ieee80211_hw\n");
  111. ret = -ENOMEM;
  112. goto err_iounmap;
  113. }
  114. ah = hw->priv;
  115. ah->hw = hw;
  116. ah->dev = &pdev->dev;
  117. ah->iobase = mem;
  118. ah->irq = irq;
  119. ah->devid = bcfg->devid;
  120. if (bcfg->devid >= AR5K_SREV_AR2315_R6) {
  121. /* Enable WMAC AHB arbitration */
  122. reg = ioread32((void __iomem *) AR5K_AR2315_AHB_ARB_CTL);
  123. reg |= AR5K_AR2315_AHB_ARB_CTL_WLAN;
  124. iowrite32(reg, (void __iomem *) AR5K_AR2315_AHB_ARB_CTL);
  125. /* Enable global WMAC swapping */
  126. reg = ioread32((void __iomem *) AR5K_AR2315_BYTESWAP);
  127. reg |= AR5K_AR2315_BYTESWAP_WMAC;
  128. iowrite32(reg, (void __iomem *) AR5K_AR2315_BYTESWAP);
  129. } else {
  130. /* Enable WMAC DMA access (assuming 5312 or 231x*/
  131. /* TODO: check other platforms */
  132. reg = ioread32((void __iomem *) AR5K_AR5312_ENABLE);
  133. if (to_platform_device(ah->dev)->id == 0)
  134. reg |= AR5K_AR5312_ENABLE_WLAN0;
  135. else
  136. reg |= AR5K_AR5312_ENABLE_WLAN1;
  137. iowrite32(reg, (void __iomem *) AR5K_AR5312_ENABLE);
  138. /*
  139. * On a dual-band AR5312, the multiband radio is only
  140. * used as pass-through. Disable 2 GHz support in the
  141. * driver for it
  142. */
  143. if (to_platform_device(ah->dev)->id == 0 &&
  144. (bcfg->config->flags & (BD_WLAN0 | BD_WLAN1)) ==
  145. (BD_WLAN1 | BD_WLAN0))
  146. ah->ah_capabilities.cap_needs_2GHz_ovr = true;
  147. else
  148. ah->ah_capabilities.cap_needs_2GHz_ovr = false;
  149. }
  150. ret = ath5k_init_ah(ah, &ath_ahb_bus_ops);
  151. if (ret != 0) {
  152. dev_err(&pdev->dev, "failed to attach device, err=%d\n", ret);
  153. ret = -ENODEV;
  154. goto err_free_hw;
  155. }
  156. platform_set_drvdata(pdev, hw);
  157. return 0;
  158. err_free_hw:
  159. ieee80211_free_hw(hw);
  160. platform_set_drvdata(pdev, NULL);
  161. err_iounmap:
  162. iounmap(mem);
  163. err_out:
  164. return ret;
  165. }
  166. static int ath_ahb_remove(struct platform_device *pdev)
  167. {
  168. struct ar231x_board_config *bcfg = pdev->dev.platform_data;
  169. struct ieee80211_hw *hw = platform_get_drvdata(pdev);
  170. struct ath5k_hw *ah;
  171. u32 reg;
  172. if (!hw)
  173. return 0;
  174. ah = hw->priv;
  175. if (bcfg->devid >= AR5K_SREV_AR2315_R6) {
  176. /* Disable WMAC AHB arbitration */
  177. reg = ioread32((void __iomem *) AR5K_AR2315_AHB_ARB_CTL);
  178. reg &= ~AR5K_AR2315_AHB_ARB_CTL_WLAN;
  179. iowrite32(reg, (void __iomem *) AR5K_AR2315_AHB_ARB_CTL);
  180. } else {
  181. /*Stop DMA access */
  182. reg = ioread32((void __iomem *) AR5K_AR5312_ENABLE);
  183. if (to_platform_device(ah->dev)->id == 0)
  184. reg &= ~AR5K_AR5312_ENABLE_WLAN0;
  185. else
  186. reg &= ~AR5K_AR5312_ENABLE_WLAN1;
  187. iowrite32(reg, (void __iomem *) AR5K_AR5312_ENABLE);
  188. }
  189. ath5k_deinit_ah(ah);
  190. iounmap(ah->iobase);
  191. platform_set_drvdata(pdev, NULL);
  192. ieee80211_free_hw(hw);
  193. return 0;
  194. }
  195. static struct platform_driver ath_ahb_driver = {
  196. .probe = ath_ahb_probe,
  197. .remove = ath_ahb_remove,
  198. .driver = {
  199. .name = "ar231x-wmac",
  200. .owner = THIS_MODULE,
  201. },
  202. };
  203. static int __init
  204. ath5k_ahb_init(void)
  205. {
  206. return platform_driver_register(&ath_ahb_driver);
  207. }
  208. static void __exit
  209. ath5k_ahb_exit(void)
  210. {
  211. platform_driver_unregister(&ath_ahb_driver);
  212. }
  213. module_init(ath5k_ahb_init);
  214. module_exit(ath5k_ahb_exit);