ahb.c 4.6 KB

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