rt2x00soc.c 3.7 KB

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