rt2x00soc.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /*
  2. Copyright (C) 2004 - 2009 Ivo van Doorn <IvDoorn@gmail.com>
  3. Copyright (C) 2004 - 2009 Felix Fietkau <nbd@openwrt.org>
  4. <http://rt2x00.serialmonkey.com>
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the
  15. Free Software Foundation, Inc.,
  16. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17. */
  18. /*
  19. Module: rt2x00soc
  20. Abstract: rt2x00 generic soc device routines.
  21. */
  22. #include <linux/bug.h>
  23. #include <linux/kernel.h>
  24. #include <linux/module.h>
  25. #include <linux/platform_device.h>
  26. #include "rt2x00.h"
  27. #include "rt2x00soc.h"
  28. static void rt2x00soc_free_reg(struct rt2x00_dev *rt2x00dev)
  29. {
  30. kfree(rt2x00dev->rf);
  31. rt2x00dev->rf = NULL;
  32. kfree(rt2x00dev->eeprom);
  33. rt2x00dev->eeprom = NULL;
  34. }
  35. static int rt2x00soc_alloc_reg(struct rt2x00_dev *rt2x00dev)
  36. {
  37. struct platform_device *pdev = to_platform_device(rt2x00dev->dev);
  38. struct resource *res;
  39. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  40. if (!res)
  41. return -ENODEV;
  42. rt2x00dev->csr.base = (void __iomem *)KSEG1ADDR(res->start);
  43. if (!rt2x00dev->csr.base)
  44. goto exit;
  45. rt2x00dev->eeprom = kzalloc(rt2x00dev->ops->eeprom_size, GFP_KERNEL);
  46. if (!rt2x00dev->eeprom)
  47. goto exit;
  48. rt2x00dev->rf = kzalloc(rt2x00dev->ops->rf_size, GFP_KERNEL);
  49. if (!rt2x00dev->rf)
  50. goto exit;
  51. return 0;
  52. exit:
  53. ERROR_PROBE("Failed to allocate registers.\n");
  54. rt2x00soc_free_reg(rt2x00dev);
  55. return -ENOMEM;
  56. }
  57. int rt2x00soc_probe(struct platform_device *pdev,
  58. const unsigned short chipset,
  59. const struct rt2x00_ops *ops)
  60. {
  61. struct ieee80211_hw *hw;
  62. struct rt2x00_dev *rt2x00dev;
  63. int retval;
  64. hw = ieee80211_alloc_hw(sizeof(struct rt2x00_dev), ops->hw);
  65. if (!hw) {
  66. ERROR_PROBE("Failed to allocate hardware.\n");
  67. return -ENOMEM;
  68. }
  69. platform_set_drvdata(pdev, hw);
  70. rt2x00dev = hw->priv;
  71. rt2x00dev->dev = &pdev->dev;
  72. rt2x00dev->ops = ops;
  73. rt2x00dev->hw = hw;
  74. rt2x00dev->irq = platform_get_irq(pdev, 0);
  75. rt2x00dev->name = pdev->dev.driver->name;
  76. /*
  77. * SoC devices mimic PCI behavior.
  78. */
  79. rt2x00_set_chip_intf(rt2x00dev, RT2X00_CHIP_INTF_PCI);
  80. rt2x00_set_chip_rt(rt2x00dev, chipset);
  81. retval = rt2x00soc_alloc_reg(rt2x00dev);
  82. if (retval)
  83. goto exit_free_device;
  84. retval = rt2x00lib_probe_dev(rt2x00dev);
  85. if (retval)
  86. goto exit_free_reg;
  87. return 0;
  88. exit_free_reg:
  89. rt2x00soc_free_reg(rt2x00dev);
  90. exit_free_device:
  91. ieee80211_free_hw(hw);
  92. return retval;
  93. }
  94. int rt2x00soc_remove(struct platform_device *pdev)
  95. {
  96. struct ieee80211_hw *hw = platform_get_drvdata(pdev);
  97. struct rt2x00_dev *rt2x00dev = hw->priv;
  98. /*
  99. * Free all allocated data.
  100. */
  101. rt2x00lib_remove_dev(rt2x00dev);
  102. rt2x00soc_free_reg(rt2x00dev);
  103. ieee80211_free_hw(hw);
  104. return 0;
  105. }
  106. EXPORT_SYMBOL_GPL(rt2x00soc_remove);
  107. #ifdef CONFIG_PM
  108. int rt2x00soc_suspend(struct platform_device *pdev, pm_message_t state)
  109. {
  110. struct ieee80211_hw *hw = platform_get_drvdata(pdev);
  111. struct rt2x00_dev *rt2x00dev = hw->priv;
  112. return rt2x00lib_suspend(rt2x00dev, state);
  113. }
  114. EXPORT_SYMBOL_GPL(rt2x00soc_suspend);
  115. int rt2x00soc_resume(struct platform_device *pdev)
  116. {
  117. struct ieee80211_hw *hw = platform_get_drvdata(pdev);
  118. struct rt2x00_dev *rt2x00dev = hw->priv;
  119. return rt2x00lib_resume(rt2x00dev);
  120. }
  121. EXPORT_SYMBOL_GPL(rt2x00soc_resume);
  122. #endif /* CONFIG_PM */
  123. /*
  124. * rt2x00soc module information.
  125. */
  126. MODULE_AUTHOR(DRV_PROJECT);
  127. MODULE_VERSION(DRV_VERSION);
  128. MODULE_DESCRIPTION("rt2x00 soc library");
  129. MODULE_LICENSE("GPL");