ahb.c 5.6 KB

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