ahb.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /*
  2. * Copyright (c) 2008 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 "core.h"
  22. #include "reg.h"
  23. #include "hw.h"
  24. /* return bus cachesize in 4B word units */
  25. static void ath_ahb_read_cachesize(struct ath_softc *sc, int *csz)
  26. {
  27. *csz = L1_CACHE_BYTES >> 2;
  28. }
  29. static void ath_ahb_cleanup(struct ath_softc *sc)
  30. {
  31. iounmap(sc->mem);
  32. }
  33. static bool ath_ahb_eeprom_read(struct ath_hal *ah, u32 off, u16 *data)
  34. {
  35. struct ath_softc *sc = ah->ah_sc;
  36. struct platform_device *pdev = to_platform_device(sc->dev);
  37. struct ath9k_platform_data *pdata;
  38. pdata = (struct ath9k_platform_data *) pdev->dev.platform_data;
  39. if (off >= (ARRAY_SIZE(pdata->eeprom_data))) {
  40. DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
  41. "%s: flash read failed, offset %08x is out of range\n",
  42. __func__, off);
  43. return false;
  44. }
  45. *data = pdata->eeprom_data[off];
  46. return true;
  47. }
  48. static struct ath_bus_ops ath_ahb_bus_ops = {
  49. .read_cachesize = ath_ahb_read_cachesize,
  50. .cleanup = ath_ahb_cleanup,
  51. .eeprom_read = ath_ahb_eeprom_read,
  52. };
  53. static int ath_ahb_probe(struct platform_device *pdev)
  54. {
  55. void __iomem *mem;
  56. struct ath_softc *sc;
  57. struct ieee80211_hw *hw;
  58. struct resource *res;
  59. int irq;
  60. int ret = 0;
  61. struct ath_hal *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_softc), &ath9k_ops);
  87. if (hw == NULL) {
  88. dev_err(&pdev->dev, "no memory for ieee80211_hw\n");
  89. ret = -ENOMEM;
  90. goto err_iounmap;
  91. }
  92. SET_IEEE80211_DEV(hw, &pdev->dev);
  93. platform_set_drvdata(pdev, hw);
  94. sc = hw->priv;
  95. sc->hw = hw;
  96. sc->dev = &pdev->dev;
  97. sc->mem = mem;
  98. sc->bus_ops = &ath_ahb_bus_ops;
  99. sc->irq = irq;
  100. ret = ath_attach(AR5416_AR9100_DEVID, sc);
  101. if (ret != 0) {
  102. dev_err(&pdev->dev, "failed to attach device, err=%d\n", ret);
  103. ret = -ENODEV;
  104. goto err_free_hw;
  105. }
  106. ret = request_irq(irq, ath_isr, IRQF_SHARED, "ath9k", sc);
  107. if (ret) {
  108. dev_err(&pdev->dev, "request_irq failed, err=%d\n", ret);
  109. ret = -EIO;
  110. goto err_detach;
  111. }
  112. ah = sc->sc_ah;
  113. printk(KERN_INFO
  114. "%s: Atheros AR%s MAC/BB Rev:%x, "
  115. "AR%s RF Rev:%x, mem=0x%lx, irq=%d\n",
  116. wiphy_name(hw->wiphy),
  117. ath_mac_bb_name(ah->ah_macVersion),
  118. ah->ah_macRev,
  119. ath_rf_name((ah->ah_analog5GhzRev & AR_RADIO_SREV_MAJOR)),
  120. ah->ah_phyRev,
  121. (unsigned long)mem, irq);
  122. return 0;
  123. err_detach:
  124. ath_detach(sc);
  125. err_free_hw:
  126. ieee80211_free_hw(hw);
  127. platform_set_drvdata(pdev, NULL);
  128. err_iounmap:
  129. iounmap(mem);
  130. err_out:
  131. return ret;
  132. }
  133. static int ath_ahb_remove(struct platform_device *pdev)
  134. {
  135. struct ieee80211_hw *hw = platform_get_drvdata(pdev);
  136. if (hw) {
  137. struct ath_softc *sc = hw->priv;
  138. ath_cleanup(sc);
  139. platform_set_drvdata(pdev, NULL);
  140. }
  141. return 0;
  142. }
  143. static struct platform_driver ath_ahb_driver = {
  144. .probe = ath_ahb_probe,
  145. .remove = ath_ahb_remove,
  146. .driver = {
  147. .name = "ath9k",
  148. .owner = THIS_MODULE,
  149. },
  150. };
  151. int ath_ahb_init(void)
  152. {
  153. return platform_driver_register(&ath_ahb_driver);
  154. }
  155. void ath_ahb_exit(void)
  156. {
  157. platform_driver_unregister(&ath_ahb_driver);
  158. }