kfifo: move struct kfifo in place
[safe/jmp/linux-2.6] / drivers / net / wireless / rt2x00 / rt2x00soc.c
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
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>
31
32 #include "rt2x00.h"
33 #include "rt2x00soc.h"
34
35 static void rt2x00soc_free_reg(struct rt2x00_dev *rt2x00dev)
36 {
37         kfree(rt2x00dev->rf);
38         rt2x00dev->rf = NULL;
39
40         kfree(rt2x00dev->eeprom);
41         rt2x00dev->eeprom = NULL;
42 }
43
44 static int rt2x00soc_alloc_reg(struct rt2x00_dev *rt2x00dev)
45 {
46         struct platform_device *pdev = to_platform_device(rt2x00dev->dev);
47         struct resource *res;
48
49         res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
50         if (!res)
51                 return -ENODEV;
52
53         rt2x00dev->csr.base = (void __iomem *)KSEG1ADDR(res->start);
54         if (!rt2x00dev->csr.base)
55                 goto exit;
56
57         rt2x00dev->eeprom = kzalloc(rt2x00dev->ops->eeprom_size, GFP_KERNEL);
58         if (!rt2x00dev->eeprom)
59                 goto exit;
60
61         rt2x00dev->rf = kzalloc(rt2x00dev->ops->rf_size, GFP_KERNEL);
62         if (!rt2x00dev->rf)
63                 goto exit;
64
65         return 0;
66
67 exit:
68         ERROR_PROBE("Failed to allocate registers.\n");
69         rt2x00soc_free_reg(rt2x00dev);
70
71         return -ENOMEM;
72 }
73
74 int rt2x00soc_probe(struct platform_device *pdev,
75                     const unsigned short chipset,
76                     const struct rt2x00_ops *ops)
77 {
78         struct ieee80211_hw *hw;
79         struct rt2x00_dev *rt2x00dev;
80         int retval;
81
82         hw = ieee80211_alloc_hw(sizeof(struct rt2x00_dev), ops->hw);
83         if (!hw) {
84                 ERROR_PROBE("Failed to allocate hardware.\n");
85                 return -ENOMEM;
86         }
87
88         platform_set_drvdata(pdev, hw);
89
90         rt2x00dev = hw->priv;
91         rt2x00dev->dev = &pdev->dev;
92         rt2x00dev->ops = ops;
93         rt2x00dev->hw = hw;
94         rt2x00dev->irq = platform_get_irq(pdev, 0);
95         rt2x00dev->name = pdev->dev.driver->name;
96
97         /*
98          * SoC devices mimic PCI behavior.
99          */
100         rt2x00_set_chip_intf(rt2x00dev, RT2X00_CHIP_INTF_PCI);
101
102         rt2x00_set_chip_rt(rt2x00dev, chipset);
103
104         retval = rt2x00soc_alloc_reg(rt2x00dev);
105         if (retval)
106                 goto exit_free_device;
107
108         retval = rt2x00lib_probe_dev(rt2x00dev);
109         if (retval)
110                 goto exit_free_reg;
111
112         return 0;
113
114 exit_free_reg:
115         rt2x00soc_free_reg(rt2x00dev);
116
117 exit_free_device:
118         ieee80211_free_hw(hw);
119
120         return retval;
121 }
122
123 int rt2x00soc_remove(struct platform_device *pdev)
124 {
125         struct ieee80211_hw *hw = platform_get_drvdata(pdev);
126         struct rt2x00_dev *rt2x00dev = hw->priv;
127
128         /*
129          * Free all allocated data.
130          */
131         rt2x00lib_remove_dev(rt2x00dev);
132         rt2x00soc_free_reg(rt2x00dev);
133         ieee80211_free_hw(hw);
134
135         return 0;
136 }
137 EXPORT_SYMBOL_GPL(rt2x00soc_remove);
138
139 #ifdef CONFIG_PM
140 int rt2x00soc_suspend(struct platform_device *pdev, pm_message_t state)
141 {
142         struct ieee80211_hw *hw = platform_get_drvdata(pdev);
143         struct rt2x00_dev *rt2x00dev = hw->priv;
144
145         return rt2x00lib_suspend(rt2x00dev, state);
146 }
147 EXPORT_SYMBOL_GPL(rt2x00soc_suspend);
148
149 int rt2x00soc_resume(struct platform_device *pdev)
150 {
151         struct ieee80211_hw *hw = platform_get_drvdata(pdev);
152         struct rt2x00_dev *rt2x00dev = hw->priv;
153
154         return rt2x00lib_resume(rt2x00dev);
155 }
156 EXPORT_SYMBOL_GPL(rt2x00soc_resume);
157 #endif /* CONFIG_PM */
158
159 /*
160  * rt2x00soc module information.
161  */
162 MODULE_AUTHOR(DRV_PROJECT);
163 MODULE_VERSION(DRV_VERSION);
164 MODULE_DESCRIPTION("rt2x00 soc library");
165 MODULE_LICENSE("GPL");