ahb.c 4.6 KB

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