ahb.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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/ath9k_platform.h>
  21. #include "ath9k.h"
  22. /* return bus cachesize in 4B word units */
  23. static void ath_ahb_read_cachesize(struct ath_common *common, int *csz)
  24. {
  25. *csz = L1_CACHE_BYTES >> 2;
  26. }
  27. static void ath_ahb_cleanup(struct ath_common *common)
  28. {
  29. struct ath_hw *ah = (struct ath_hw *) common->ah;
  30. struct ath_softc *sc = ah->ah_sc;
  31. iounmap(sc->mem);
  32. }
  33. static bool ath_ahb_eeprom_read(struct ath_common *common, u32 off, u16 *data)
  34. {
  35. struct ath_hw *ah = (struct ath_hw *) common->ah;
  36. struct ath_softc *sc = ah->ah_sc;
  37. struct platform_device *pdev = to_platform_device(sc->dev);
  38. struct ath9k_platform_data *pdata;
  39. pdata = (struct ath9k_platform_data *) pdev->dev.platform_data;
  40. if (off >= (ARRAY_SIZE(pdata->eeprom_data))) {
  41. ath_print(common, ATH_DBG_FATAL,
  42. "%s: flash read failed, offset %08x "
  43. "is out of range\n",
  44. __func__, off);
  45. return false;
  46. }
  47. *data = pdata->eeprom_data[off];
  48. return true;
  49. }
  50. static struct ath_bus_ops ath_ahb_bus_ops = {
  51. .read_cachesize = ath_ahb_read_cachesize,
  52. .cleanup = ath_ahb_cleanup,
  53. .eeprom_read = ath_ahb_eeprom_read,
  54. };
  55. static int ath_ahb_probe(struct platform_device *pdev)
  56. {
  57. void __iomem *mem;
  58. struct ath_wiphy *aphy;
  59. struct ath_softc *sc;
  60. struct ieee80211_hw *hw;
  61. struct resource *res;
  62. int irq;
  63. int ret = 0;
  64. struct ath_hw *ah;
  65. if (!pdev->dev.platform_data) {
  66. dev_err(&pdev->dev, "no platform data specified\n");
  67. ret = -EINVAL;
  68. goto err_out;
  69. }
  70. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  71. if (res == NULL) {
  72. dev_err(&pdev->dev, "no memory resource found\n");
  73. ret = -ENXIO;
  74. goto err_out;
  75. }
  76. mem = ioremap_nocache(res->start, res->end - res->start + 1);
  77. if (mem == NULL) {
  78. dev_err(&pdev->dev, "ioremap failed\n");
  79. ret = -ENOMEM;
  80. goto err_out;
  81. }
  82. res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  83. if (res == NULL) {
  84. dev_err(&pdev->dev, "no IRQ resource found\n");
  85. ret = -ENXIO;
  86. goto err_iounmap;
  87. }
  88. irq = res->start;
  89. hw = ieee80211_alloc_hw(sizeof(struct ath_wiphy) +
  90. sizeof(struct ath_softc), &ath9k_ops);
  91. if (hw == NULL) {
  92. dev_err(&pdev->dev, "no memory for ieee80211_hw\n");
  93. ret = -ENOMEM;
  94. goto err_iounmap;
  95. }
  96. SET_IEEE80211_DEV(hw, &pdev->dev);
  97. platform_set_drvdata(pdev, hw);
  98. aphy = hw->priv;
  99. sc = (struct ath_softc *) (aphy + 1);
  100. aphy->sc = sc;
  101. aphy->hw = hw;
  102. sc->pri_wiphy = aphy;
  103. sc->hw = hw;
  104. sc->dev = &pdev->dev;
  105. sc->mem = mem;
  106. sc->irq = irq;
  107. ret = ath_init_device(AR5416_AR9100_DEVID, sc, 0x0, &ath_ahb_bus_ops);
  108. if (ret) {
  109. dev_err(&pdev->dev, "failed to initialize device\n");
  110. goto err_free_hw;
  111. }
  112. ret = request_irq(irq, ath_isr, IRQF_SHARED, "ath9k", sc);
  113. if (ret) {
  114. dev_err(&pdev->dev, "request_irq failed\n");
  115. goto err_detach;
  116. }
  117. ah = sc->sc_ah;
  118. printk(KERN_INFO
  119. "%s: Atheros AR%s MAC/BB Rev:%x, "
  120. "AR%s RF Rev:%x, mem=0x%lx, irq=%d\n",
  121. wiphy_name(hw->wiphy),
  122. ath_mac_bb_name(ah->hw_version.macVersion),
  123. ah->hw_version.macRev,
  124. ath_rf_name((ah->hw_version.analog5GhzRev & AR_RADIO_SREV_MAJOR)),
  125. ah->hw_version.phyRev,
  126. (unsigned long)mem, irq);
  127. return 0;
  128. err_detach:
  129. ath_detach(sc);
  130. err_free_hw:
  131. ieee80211_free_hw(hw);
  132. platform_set_drvdata(pdev, NULL);
  133. err_iounmap:
  134. iounmap(mem);
  135. err_out:
  136. return ret;
  137. }
  138. static int ath_ahb_remove(struct platform_device *pdev)
  139. {
  140. struct ieee80211_hw *hw = platform_get_drvdata(pdev);
  141. if (hw) {
  142. struct ath_wiphy *aphy = hw->priv;
  143. struct ath_softc *sc = aphy->sc;
  144. ath_cleanup(sc);
  145. platform_set_drvdata(pdev, NULL);
  146. }
  147. return 0;
  148. }
  149. static struct platform_driver ath_ahb_driver = {
  150. .probe = ath_ahb_probe,
  151. .remove = ath_ahb_remove,
  152. .driver = {
  153. .name = "ath9k",
  154. .owner = THIS_MODULE,
  155. },
  156. };
  157. int ath_ahb_init(void)
  158. {
  159. return platform_driver_register(&ath_ahb_driver);
  160. }
  161. void ath_ahb_exit(void)
  162. {
  163. platform_driver_unregister(&ath_ahb_driver);
  164. }