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