ahb.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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 <ar231x_platform.h>
  22. #include "ath5k.h"
  23. #include "debug.h"
  24. #include "base.h"
  25. #include "reg.h"
  26. /* return bus cachesize in 4B word units */
  27. static void ath5k_ahb_read_cachesize(struct ath_common *common, int *csz)
  28. {
  29. *csz = L1_CACHE_BYTES >> 2;
  30. }
  31. static bool
  32. ath5k_ahb_eeprom_read(struct ath_common *common, u32 off, u16 *data)
  33. {
  34. struct ath5k_hw *ah = common->priv;
  35. struct platform_device *pdev = to_platform_device(ah->dev);
  36. struct ar231x_board_config *bcfg = pdev->dev.platform_data;
  37. u16 *eeprom, *eeprom_end;
  38. bcfg = pdev->dev.platform_data;
  39. eeprom = (u16 *) bcfg->radio;
  40. eeprom_end = ((void *) bcfg->config) + BOARD_CONFIG_BUFSZ;
  41. eeprom += off;
  42. if (eeprom > eeprom_end)
  43. return false;
  44. *data = *eeprom;
  45. return true;
  46. }
  47. int ath5k_hw_read_srev(struct ath5k_hw *ah)
  48. {
  49. struct platform_device *pdev = to_platform_device(ah->dev);
  50. struct ar231x_board_config *bcfg = pdev->dev.platform_data;
  51. ah->ah_mac_srev = bcfg->devid;
  52. return 0;
  53. }
  54. static int ath5k_ahb_eeprom_read_mac(struct ath5k_hw *ah, u8 *mac)
  55. {
  56. struct platform_device *pdev = to_platform_device(ah->dev);
  57. struct ar231x_board_config *bcfg = pdev->dev.platform_data;
  58. u8 *cfg_mac;
  59. if (to_platform_device(ah->dev)->id == 0)
  60. cfg_mac = bcfg->config->wlan0_mac;
  61. else
  62. cfg_mac = bcfg->config->wlan1_mac;
  63. memcpy(mac, cfg_mac, ETH_ALEN);
  64. return 0;
  65. }
  66. static const struct ath_bus_ops ath_ahb_bus_ops = {
  67. .ath_bus_type = ATH_AHB,
  68. .read_cachesize = ath5k_ahb_read_cachesize,
  69. .eeprom_read = ath5k_ahb_eeprom_read,
  70. .eeprom_read_mac = ath5k_ahb_eeprom_read_mac,
  71. };
  72. /*Initialization*/
  73. static int ath_ahb_probe(struct platform_device *pdev)
  74. {
  75. struct ar231x_board_config *bcfg = pdev->dev.platform_data;
  76. struct ath5k_hw *ah;
  77. struct ieee80211_hw *hw;
  78. struct resource *res;
  79. void __iomem *mem;
  80. int irq;
  81. int ret = 0;
  82. u32 reg;
  83. if (!pdev->dev.platform_data) {
  84. dev_err(&pdev->dev, "no platform data specified\n");
  85. ret = -EINVAL;
  86. goto err_out;
  87. }
  88. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  89. if (res == NULL) {
  90. dev_err(&pdev->dev, "no memory resource found\n");
  91. ret = -ENXIO;
  92. goto err_out;
  93. }
  94. mem = ioremap_nocache(res->start, resource_size(res));
  95. if (mem == NULL) {
  96. dev_err(&pdev->dev, "ioremap failed\n");
  97. ret = -ENOMEM;
  98. goto err_out;
  99. }
  100. res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  101. if (res == NULL) {
  102. dev_err(&pdev->dev, "no IRQ resource found\n");
  103. ret = -ENXIO;
  104. goto err_out;
  105. }
  106. irq = res->start;
  107. hw = ieee80211_alloc_hw(sizeof(struct ath5k_hw), &ath5k_hw_ops);
  108. if (hw == NULL) {
  109. dev_err(&pdev->dev, "no memory for ieee80211_hw\n");
  110. ret = -ENOMEM;
  111. goto err_out;
  112. }
  113. ah = hw->priv;
  114. ah->hw = hw;
  115. ah->dev = &pdev->dev;
  116. ah->iobase = mem;
  117. ah->irq = irq;
  118. ah->devid = bcfg->devid;
  119. if (bcfg->devid >= AR5K_SREV_AR2315_R6) {
  120. /* Enable WMAC AHB arbitration */
  121. reg = __raw_readl((void __iomem *) AR5K_AR2315_AHB_ARB_CTL);
  122. reg |= AR5K_AR2315_AHB_ARB_CTL_WLAN;
  123. __raw_writel(reg, (void __iomem *) AR5K_AR2315_AHB_ARB_CTL);
  124. /* Enable global WMAC swapping */
  125. reg = __raw_readl((void __iomem *) AR5K_AR2315_BYTESWAP);
  126. reg |= AR5K_AR2315_BYTESWAP_WMAC;
  127. __raw_writel(reg, (void __iomem *) AR5K_AR2315_BYTESWAP);
  128. } else {
  129. /* Enable WMAC DMA access (assuming 5312 or 231x*/
  130. /* TODO: check other platforms */
  131. reg = __raw_readl((void __iomem *) AR5K_AR5312_ENABLE);
  132. if (to_platform_device(ah->dev)->id == 0)
  133. reg |= AR5K_AR5312_ENABLE_WLAN0;
  134. else
  135. reg |= AR5K_AR5312_ENABLE_WLAN1;
  136. __raw_writel(reg, (void __iomem *) AR5K_AR5312_ENABLE);
  137. /*
  138. * On a dual-band AR5312, the multiband radio is only
  139. * used as pass-through. Disable 2 GHz support in the
  140. * driver for it
  141. */
  142. if (to_platform_device(ah->dev)->id == 0 &&
  143. (bcfg->config->flags & (BD_WLAN0 | BD_WLAN1)) ==
  144. (BD_WLAN1 | BD_WLAN0))
  145. __set_bit(ATH_STAT_2G_DISABLED, ah->status);
  146. }
  147. ret = ath5k_init_softc(ah, &ath_ahb_bus_ops);
  148. if (ret != 0) {
  149. dev_err(&pdev->dev, "failed to attach device, err=%d\n", ret);
  150. ret = -ENODEV;
  151. goto err_free_hw;
  152. }
  153. platform_set_drvdata(pdev, hw);
  154. return 0;
  155. err_free_hw:
  156. ieee80211_free_hw(hw);
  157. platform_set_drvdata(pdev, NULL);
  158. err_out:
  159. return ret;
  160. }
  161. static int ath_ahb_remove(struct platform_device *pdev)
  162. {
  163. struct ar231x_board_config *bcfg = pdev->dev.platform_data;
  164. struct ieee80211_hw *hw = platform_get_drvdata(pdev);
  165. struct ath5k_hw *ah;
  166. u32 reg;
  167. if (!hw)
  168. return 0;
  169. ah = hw->priv;
  170. if (bcfg->devid >= AR5K_SREV_AR2315_R6) {
  171. /* Disable WMAC AHB arbitration */
  172. reg = __raw_readl((void __iomem *) AR5K_AR2315_AHB_ARB_CTL);
  173. reg &= ~AR5K_AR2315_AHB_ARB_CTL_WLAN;
  174. __raw_writel(reg, (void __iomem *) AR5K_AR2315_AHB_ARB_CTL);
  175. } else {
  176. /*Stop DMA access */
  177. reg = __raw_readl((void __iomem *) AR5K_AR5312_ENABLE);
  178. if (to_platform_device(ah->dev)->id == 0)
  179. reg &= ~AR5K_AR5312_ENABLE_WLAN0;
  180. else
  181. reg &= ~AR5K_AR5312_ENABLE_WLAN1;
  182. __raw_writel(reg, (void __iomem *) AR5K_AR5312_ENABLE);
  183. }
  184. ath5k_deinit_softc(ah);
  185. platform_set_drvdata(pdev, NULL);
  186. ieee80211_free_hw(hw);
  187. return 0;
  188. }
  189. static struct platform_driver ath_ahb_driver = {
  190. .probe = ath_ahb_probe,
  191. .remove = ath_ahb_remove,
  192. .driver = {
  193. .name = "ar231x-wmac",
  194. .owner = THIS_MODULE,
  195. },
  196. };
  197. static int __init
  198. ath5k_ahb_init(void)
  199. {
  200. return platform_driver_register(&ath_ahb_driver);
  201. }
  202. static void __exit
  203. ath5k_ahb_exit(void)
  204. {
  205. platform_driver_unregister(&ath_ahb_driver);
  206. }
  207. module_init(ath5k_ahb_init);
  208. module_exit(ath5k_ahb_exit);