ahb.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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_softc *sc = (struct ath_softc *)common->priv;
  30. iounmap(sc->mem);
  31. }
  32. static bool ath_ahb_eeprom_read(struct ath_common *common, u32 off, u16 *data)
  33. {
  34. struct ath_softc *sc = (struct ath_softc *)common->priv;
  35. struct platform_device *pdev = to_platform_device(sc->dev);
  36. struct ath9k_platform_data *pdata;
  37. pdata = (struct ath9k_platform_data *) pdev->dev.platform_data;
  38. if (off >= (ARRAY_SIZE(pdata->eeprom_data))) {
  39. ath_print(common, ATH_DBG_FATAL,
  40. "%s: flash read failed, offset %08x "
  41. "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_wiphy *aphy;
  57. struct ath_softc *sc;
  58. struct ieee80211_hw *hw;
  59. struct resource *res;
  60. int irq;
  61. int ret = 0;
  62. struct ath_hw *ah;
  63. char hw_name[64];
  64. if (!pdev->dev.platform_data) {
  65. dev_err(&pdev->dev, "no platform data specified\n");
  66. ret = -EINVAL;
  67. goto err_out;
  68. }
  69. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  70. if (res == NULL) {
  71. dev_err(&pdev->dev, "no memory resource found\n");
  72. ret = -ENXIO;
  73. goto err_out;
  74. }
  75. mem = ioremap_nocache(res->start, res->end - res->start + 1);
  76. if (mem == NULL) {
  77. dev_err(&pdev->dev, "ioremap failed\n");
  78. ret = -ENOMEM;
  79. goto err_out;
  80. }
  81. res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  82. if (res == NULL) {
  83. dev_err(&pdev->dev, "no IRQ resource found\n");
  84. ret = -ENXIO;
  85. goto err_iounmap;
  86. }
  87. irq = res->start;
  88. hw = ieee80211_alloc_hw(sizeof(struct ath_wiphy) +
  89. sizeof(struct ath_softc), &ath9k_ops);
  90. if (hw == NULL) {
  91. dev_err(&pdev->dev, "no memory for ieee80211_hw\n");
  92. ret = -ENOMEM;
  93. goto err_iounmap;
  94. }
  95. SET_IEEE80211_DEV(hw, &pdev->dev);
  96. platform_set_drvdata(pdev, hw);
  97. aphy = hw->priv;
  98. sc = (struct ath_softc *) (aphy + 1);
  99. aphy->sc = sc;
  100. aphy->hw = hw;
  101. sc->pri_wiphy = aphy;
  102. sc->hw = hw;
  103. sc->dev = &pdev->dev;
  104. sc->mem = mem;
  105. sc->irq = irq;
  106. ret = ath_init_device(AR5416_AR9100_DEVID, sc, 0x0, &ath_ahb_bus_ops);
  107. if (ret) {
  108. dev_err(&pdev->dev, "failed to initialize device\n");
  109. goto err_free_hw;
  110. }
  111. ret = request_irq(irq, ath_isr, IRQF_SHARED, "ath9k", sc);
  112. if (ret) {
  113. dev_err(&pdev->dev, "request_irq failed\n");
  114. goto err_detach;
  115. }
  116. ah = sc->sc_ah;
  117. ath9k_hw_name(ah, hw_name, sizeof(hw_name));
  118. printk(KERN_INFO
  119. "%s: %s mem=0x%lx, irq=%d\n",
  120. wiphy_name(hw->wiphy),
  121. hw_name,
  122. (unsigned long)mem, irq);
  123. return 0;
  124. err_detach:
  125. ath_detach(sc);
  126. err_free_hw:
  127. ieee80211_free_hw(hw);
  128. platform_set_drvdata(pdev, NULL);
  129. err_iounmap:
  130. iounmap(mem);
  131. err_out:
  132. return ret;
  133. }
  134. static int ath_ahb_remove(struct platform_device *pdev)
  135. {
  136. struct ieee80211_hw *hw = platform_get_drvdata(pdev);
  137. if (hw) {
  138. struct ath_wiphy *aphy = hw->priv;
  139. struct ath_softc *sc = aphy->sc;
  140. ath_cleanup(sc);
  141. platform_set_drvdata(pdev, NULL);
  142. }
  143. return 0;
  144. }
  145. static struct platform_driver ath_ahb_driver = {
  146. .probe = ath_ahb_probe,
  147. .remove = ath_ahb_remove,
  148. .driver = {
  149. .name = "ath9k",
  150. .owner = THIS_MODULE,
  151. },
  152. };
  153. int ath_ahb_init(void)
  154. {
  155. return platform_driver_register(&ath_ahb_driver);
  156. }
  157. void ath_ahb_exit(void)
  158. {
  159. platform_driver_unregister(&ath_ahb_driver);
  160. }