rt2x00soc.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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, see <http://www.gnu.org/licenses/>.
  15. */
  16. /*
  17. Module: rt2x00soc
  18. Abstract: rt2x00 generic soc device routines.
  19. */
  20. #include <linux/bug.h>
  21. #include <linux/kernel.h>
  22. #include <linux/module.h>
  23. #include <linux/platform_device.h>
  24. #include <linux/slab.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. iounmap(rt2x00dev->csr.base);
  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 = ioremap(res->start, resource_size(res));
  43. if (!rt2x00dev->csr.base)
  44. return -ENOMEM;
  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. rt2x00_probe_err("Failed to allocate registers\n");
  54. rt2x00soc_free_reg(rt2x00dev);
  55. return -ENOMEM;
  56. }
  57. int rt2x00soc_probe(struct platform_device *pdev, const struct rt2x00_ops *ops)
  58. {
  59. struct ieee80211_hw *hw;
  60. struct rt2x00_dev *rt2x00dev;
  61. int retval;
  62. hw = ieee80211_alloc_hw(sizeof(struct rt2x00_dev), ops->hw);
  63. if (!hw) {
  64. rt2x00_probe_err("Failed to allocate hardware\n");
  65. return -ENOMEM;
  66. }
  67. platform_set_drvdata(pdev, hw);
  68. rt2x00dev = hw->priv;
  69. rt2x00dev->dev = &pdev->dev;
  70. rt2x00dev->ops = ops;
  71. rt2x00dev->hw = hw;
  72. rt2x00dev->irq = platform_get_irq(pdev, 0);
  73. rt2x00dev->name = pdev->dev.driver->name;
  74. rt2x00_set_chip_intf(rt2x00dev, RT2X00_CHIP_INTF_SOC);
  75. retval = rt2x00soc_alloc_reg(rt2x00dev);
  76. if (retval)
  77. goto exit_free_device;
  78. retval = rt2x00lib_probe_dev(rt2x00dev);
  79. if (retval)
  80. goto exit_free_reg;
  81. return 0;
  82. exit_free_reg:
  83. rt2x00soc_free_reg(rt2x00dev);
  84. exit_free_device:
  85. ieee80211_free_hw(hw);
  86. return retval;
  87. }
  88. EXPORT_SYMBOL_GPL(rt2x00soc_probe);
  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");