ahb.c 5.6 KB

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