rt2x00soc.c 3.8 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, 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 <linux/slab.h>
  27. #include "rt2x00.h"
  28. #include "rt2x00soc.h"
  29. static void rt2x00soc_free_reg(struct rt2x00_dev *rt2x00dev)
  30. {
  31. kfree(rt2x00dev->rf);
  32. rt2x00dev->rf = NULL;
  33. kfree(rt2x00dev->eeprom);
  34. rt2x00dev->eeprom = NULL;
  35. }
  36. static int rt2x00soc_alloc_reg(struct rt2x00_dev *rt2x00dev)
  37. {
  38. struct platform_device *pdev = to_platform_device(rt2x00dev->dev);
  39. struct resource *res;
  40. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  41. if (!res)
  42. return -ENODEV;
  43. rt2x00dev->csr.base = (void __iomem *)KSEG1ADDR(res->start);
  44. if (!rt2x00dev->csr.base)
  45. goto exit;
  46. rt2x00dev->eeprom = kzalloc(rt2x00dev->ops->eeprom_size, GFP_KERNEL);
  47. if (!rt2x00dev->eeprom)
  48. goto exit;
  49. rt2x00dev->rf = kzalloc(rt2x00dev->ops->rf_size, GFP_KERNEL);
  50. if (!rt2x00dev->rf)
  51. goto exit;
  52. return 0;
  53. exit:
  54. ERROR_PROBE("Failed to allocate registers.\n");
  55. rt2x00soc_free_reg(rt2x00dev);
  56. return -ENOMEM;
  57. }
  58. int rt2x00soc_probe(struct platform_device *pdev, 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_intf(rt2x00dev, RT2X00_CHIP_INTF_SOC);
  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. EXPORT_SYMBOL_GPL(rt2x00soc_probe);
  90. int rt2x00soc_remove(struct platform_device *pdev)
  91. {
  92. struct ieee80211_hw *hw = platform_get_drvdata(pdev);
  93. struct rt2x00_dev *rt2x00dev = hw->priv;
  94. /*
  95. * Free all allocated data.
  96. */
  97. rt2x00lib_remove_dev(rt2x00dev);
  98. rt2x00soc_free_reg(rt2x00dev);
  99. ieee80211_free_hw(hw);
  100. return 0;
  101. }
  102. EXPORT_SYMBOL_GPL(rt2x00soc_remove);
  103. #ifdef CONFIG_PM
  104. int rt2x00soc_suspend(struct platform_device *pdev, pm_message_t state)
  105. {
  106. struct ieee80211_hw *hw = platform_get_drvdata(pdev);
  107. struct rt2x00_dev *rt2x00dev = hw->priv;
  108. return rt2x00lib_suspend(rt2x00dev, state);
  109. }
  110. EXPORT_SYMBOL_GPL(rt2x00soc_suspend);
  111. int rt2x00soc_resume(struct platform_device *pdev)
  112. {
  113. struct ieee80211_hw *hw = platform_get_drvdata(pdev);
  114. struct rt2x00_dev *rt2x00dev = hw->priv;
  115. return rt2x00lib_resume(rt2x00dev);
  116. }
  117. EXPORT_SYMBOL_GPL(rt2x00soc_resume);
  118. #endif /* CONFIG_PM */
  119. /*
  120. * rt2x00soc module information.
  121. */
  122. MODULE_AUTHOR(DRV_PROJECT);
  123. MODULE_VERSION(DRV_VERSION);
  124. MODULE_DESCRIPTION("rt2x00 soc library");
  125. MODULE_LICENSE("GPL");