Update to compat-wireless-2009-03-31
[openwrt/staging/florian.git] / package / mac80211 / patches / 305-rt2x00-Add-rt2x00soc-bus-module.patch
1 From 18b2be31a35dc8bd216e60e3c9d8d8e7b2179aed Mon Sep 17 00:00:00 2001
2 From: Ivo van Doorn <IvDoorn@gmail.com>
3 Date: Sat, 28 Mar 2009 20:38:40 +0100
4 Subject: [PATCH 6/9] rt2x00: Add rt2x00soc bus module
5
6 Add new library module for SoC drivers.
7 This is needed to fully support the platform
8 driver part of rt2800pci.
9
10 Signed-off-by: Felix Fietkau <nbd@openwrt.org>
11 Signed-off-by: Ivo van Doorn <IvDoorn@gmail.com>
12 ---
13 drivers/net/wireless/rt2x00/Kconfig | 4 +
14 drivers/net/wireless/rt2x00/Makefile | 1 +
15 drivers/net/wireless/rt2x00/rt2x00soc.c | 159 +++++++++++++++++++++++++++++++
16 drivers/net/wireless/rt2x00/rt2x00soc.h | 52 ++++++++++
17 4 files changed, 216 insertions(+), 0 deletions(-)
18 create mode 100644 drivers/net/wireless/rt2x00/rt2x00soc.c
19 create mode 100644 drivers/net/wireless/rt2x00/rt2x00soc.h
20
21 --- a/drivers/net/wireless/rt2x00/Makefile
22 +++ b/drivers/net/wireless/rt2x00/Makefile
23 @@ -12,6 +12,7 @@ rt2x00lib-$(CONFIG_RT2X00_LIB_HT) += rt2
24
25 obj-$(CONFIG_RT2X00_LIB) += rt2x00lib.o
26 obj-$(CONFIG_RT2X00_LIB_PCI) += rt2x00pci.o
27 +obj-$(CONFIG_RT2X00_LIB_SOC) += rt2x00soc.o
28 obj-$(CONFIG_RT2X00_LIB_USB) += rt2x00usb.o
29 obj-$(CONFIG_RT2400PCI) += rt2400pci.o
30 obj-$(CONFIG_RT2500PCI) += rt2500pci.o
31 --- /dev/null
32 +++ b/drivers/net/wireless/rt2x00/rt2x00soc.c
33 @@ -0,0 +1,159 @@
34 +/*
35 + Copyright (C) 2004 - 2009 rt2x00 SourceForge Project
36 + <http://rt2x00.serialmonkey.com>
37 +
38 + This program is free software; you can redistribute it and/or modify
39 + it under the terms of the GNU General Public License as published by
40 + the Free Software Foundation; either version 2 of the License, or
41 + (at your option) any later version.
42 +
43 + This program is distributed in the hope that it will be useful,
44 + but WITHOUT ANY WARRANTY; without even the implied warranty of
45 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
46 + GNU General Public License for more details.
47 +
48 + You should have received a copy of the GNU General Public License
49 + along with this program; if not, write to the
50 + Free Software Foundation, Inc.,
51 + 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
52 + */
53 +
54 +/*
55 + Module: rt2x00soc
56 + Abstract: rt2x00 generic soc device routines.
57 + */
58 +
59 +#include <linux/bug.h>
60 +#include <linux/kernel.h>
61 +#include <linux/module.h>
62 +#include <linux/platform_device.h>
63 +
64 +#include "rt2x00.h"
65 +#include "rt2x00soc.h"
66 +
67 +static void rt2x00soc_free_reg(struct rt2x00_dev *rt2x00dev)
68 +{
69 + kfree(rt2x00dev->rf);
70 + rt2x00dev->rf = NULL;
71 +
72 + kfree(rt2x00dev->eeprom);
73 + rt2x00dev->eeprom = NULL;
74 +}
75 +
76 +static int rt2x00soc_alloc_reg(struct rt2x00_dev *rt2x00dev)
77 +{
78 + struct platform_device *pdev = to_platform_device(rt2x00dev->dev);
79 + struct resource *res;
80 +
81 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
82 + if (!res)
83 + return -ENODEV;
84 +
85 + rt2x00dev->csr.base = (void __iomem *)KSEG1ADDR(res->start);
86 + if (!rt2x00dev->csr.base)
87 + goto exit;
88 +
89 + rt2x00dev->eeprom = kzalloc(rt2x00dev->ops->eeprom_size, GFP_KERNEL);
90 + if (!rt2x00dev->eeprom)
91 + goto exit;
92 +
93 + rt2x00dev->rf = kzalloc(rt2x00dev->ops->rf_size, GFP_KERNEL);
94 + if (!rt2x00dev->rf)
95 + goto exit;
96 +
97 + return 0;
98 +
99 +exit:
100 + ERROR_PROBE("Failed to allocate registers.\n");
101 + rt2x00soc_free_reg(rt2x00dev);
102 +
103 + return -ENOMEM;
104 +}
105 +
106 +int rt2x00soc_probe(struct platform_device *pdev,
107 + const unsigned short chipset,
108 + const struct rt2x00_ops *ops)
109 +{
110 + struct ieee80211_hw *hw;
111 + struct rt2x00_dev *rt2x00dev;
112 + int retval;
113 +
114 + hw = ieee80211_alloc_hw(sizeof(struct rt2x00_dev), ops->hw);
115 + if (!hw) {
116 + ERROR_PROBE("Failed to allocate hardware.\n");
117 + return -ENOMEM;
118 + }
119 +
120 + platform_set_drvdata(pdev, hw);
121 +
122 + rt2x00dev = hw->priv;
123 + rt2x00dev->dev = &pdev->dev;
124 + rt2x00dev->ops = ops;
125 + rt2x00dev->hw = hw;
126 + rt2x00dev->irq = platform_get_irq(pdev, 0);
127 + rt2x00dev->name = pdev->dev.driver->name;
128 +
129 + rt2x00_set_chip_rt(rt2x00dev, chipset);
130 +
131 + retval = rt2x00soc_alloc_reg(rt2x00dev);
132 + if (retval)
133 + goto exit_free_device;
134 +
135 + retval = rt2x00lib_probe_dev(rt2x00dev);
136 + if (retval)
137 + goto exit_free_reg;
138 +
139 + return 0;
140 +
141 +exit_free_reg:
142 + rt2x00soc_free_reg(rt2x00dev);
143 +
144 +exit_free_device:
145 + ieee80211_free_hw(hw);
146 +
147 + return retval;
148 +}
149 +
150 +int rt2x00soc_remove(struct platform_device *pdev)
151 +{
152 + struct ieee80211_hw *hw = platform_get_drvdata(pdev);
153 + struct rt2x00_dev *rt2x00dev = hw->priv;
154 +
155 + /*
156 + * Free all allocated data.
157 + */
158 + rt2x00lib_remove_dev(rt2x00dev);
159 + rt2x00soc_free_reg(rt2x00dev);
160 + ieee80211_free_hw(hw);
161 +
162 + return 0;
163 +}
164 +EXPORT_SYMBOL_GPL(rt2x00soc_remove);
165 +
166 +#ifdef CONFIG_PM
167 +int rt2x00soc_suspend(struct platform_device *pdev, pm_message_t state)
168 +{
169 + struct ieee80211_hw *hw = platform_get_drvdata(pdev);
170 + struct rt2x00_dev *rt2x00dev = hw->priv;
171 +
172 + return rt2x00lib_suspend(rt2x00dev, state);
173 +}
174 +EXPORT_SYMBOL_GPL(rt2x00soc_suspend);
175 +
176 +int rt2x00soc_resume(struct platform_device *pdev)
177 +{
178 + struct ieee80211_hw *hw = platform_get_drvdata(pdev);
179 + struct rt2x00_dev *rt2x00dev = hw->priv;
180 +
181 + return rt2x00lib_resume(rt2x00dev);
182 +}
183 +EXPORT_SYMBOL_GPL(rt2x00soc_resume);
184 +#endif /* CONFIG_PM */
185 +
186 +/*
187 + * rt2x00soc module information.
188 + */
189 +MODULE_AUTHOR(DRV_PROJECT);
190 +MODULE_VERSION(DRV_VERSION);
191 +MODULE_DESCRIPTION("rt2x00 soc library");
192 +MODULE_LICENSE("GPL");
193 --- /dev/null
194 +++ b/drivers/net/wireless/rt2x00/rt2x00soc.h
195 @@ -0,0 +1,52 @@
196 +/*
197 + Copyright (C) 2004 - 2009 rt2x00 SourceForge Project
198 + <http://rt2x00.serialmonkey.com>
199 +
200 + This program is free software; you can redistribute it and/or modify
201 + it under the terms of the GNU General Public License as published by
202 + the Free Software Foundation; either version 2 of the License, or
203 + (at your option) any later version.
204 +
205 + This program is distributed in the hope that it will be useful,
206 + but WITHOUT ANY WARRANTY; without even the implied warranty of
207 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
208 + GNU General Public License for more details.
209 +
210 + You should have received a copy of the GNU General Public License
211 + along with this program; if not, write to the
212 + Free Software Foundation, Inc.,
213 + 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
214 + */
215 +
216 +/*
217 + Module: rt2x00soc
218 + Abstract: Data structures for the rt2x00soc module.
219 + */
220 +
221 +#ifndef RT2X00SOC_H
222 +#define RT2X00SOC_H
223 +
224 +#define KSEG1ADDR(__ptr) __ptr
225 +
226 +#define __rt2x00soc_probe(__chipset, __ops) \
227 +static int __rt2x00soc_probe(struct platform_device *pdev) \
228 +{ \
229 + return rt2x00soc_probe(pdev, (__chipset), (__ops)); \
230 +}
231 +
232 +/*
233 + * SoC driver handlers.
234 + */
235 +int rt2x00soc_probe(struct platform_device *pdev,
236 + const unsigned short chipset,
237 + const struct rt2x00_ops *ops);
238 +int rt2x00soc_remove(struct platform_device *pdev);
239 +#ifdef CONFIG_PM
240 +int rt2x00soc_suspend(struct platform_device *pdev, pm_message_t state);
241 +int rt2x00soc_resume(struct platform_device *pdev);
242 +#else
243 +#define rt2x00soc_suspend NULL
244 +#define rt2x00soc_resume NULL
245 +#endif /* CONFIG_PM */
246 +
247 +#endif /* RT2X00SOC_H */