aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/wl12xx
diff options
context:
space:
mode:
authorBob Copeland <me@bobcopeland.com>2009-08-07 06:33:26 -0400
committerJohn W. Linville <linville@tuxdriver.com>2009-08-14 09:13:37 -0400
commit8e639c0673a9b676bb7c6bd4e50f9003bdda423e (patch)
treefb4e87e44347baa1e0b46c9b84c219501a14b11c /drivers/net/wireless/wl12xx
parent0d77e141331b25adf190ce30d69fe5744a69c5bd (diff)
wl1251: move module probe methods into spi.c
This change moves all of the spi specific code from main.c into spi.c. The module initialization code also moves, but common code for initializing mac80211 etc. stays in main.c, as this will eventually form a common library module also used by wl1251_sdio. Signed-off-by: Bob Copeland <me@bobcopeland.com> Signed-off-by: Kalle Valo <kalle.valo@nokia.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'drivers/net/wireless/wl12xx')
-rw-r--r--drivers/net/wireless/wl12xx/wl1251.h7
-rw-r--r--drivers/net/wireless/wl12xx/wl1251_acx.c1
-rw-r--r--drivers/net/wireless/wl12xx/wl1251_cmd.c1
-rw-r--r--drivers/net/wireless/wl12xx/wl1251_main.c148
-rw-r--r--drivers/net/wireless/wl12xx/wl1251_spi.c125
-rw-r--r--drivers/net/wireless/wl12xx/wl1251_tx.c1
6 files changed, 151 insertions, 132 deletions
diff --git a/drivers/net/wireless/wl12xx/wl1251.h b/drivers/net/wireless/wl12xx/wl1251.h
index 284bb508c87b..df4c06d41678 100644
--- a/drivers/net/wireless/wl12xx/wl1251.h
+++ b/drivers/net/wireless/wl12xx/wl1251.h
@@ -292,7 +292,7 @@ struct wl1251 {
292 bool mac80211_registered; 292 bool mac80211_registered;
293 293
294 struct spi_device *spi; 294 struct spi_device *spi;
295 struct wl1251_if_operations *if_ops; 295 const struct wl1251_if_operations *if_ops;
296 296
297 void (*set_power)(bool enable); 297 void (*set_power)(bool enable);
298 int irq; 298 int irq;
@@ -404,6 +404,11 @@ struct wl1251 {
404int wl1251_plt_start(struct wl1251 *wl); 404int wl1251_plt_start(struct wl1251 *wl);
405int wl1251_plt_stop(struct wl1251 *wl); 405int wl1251_plt_stop(struct wl1251 *wl);
406 406
407irqreturn_t wl1251_irq(int irq, void *cookie);
408struct ieee80211_hw *wl1251_alloc_hw(void);
409int wl1251_free_hw(struct wl1251 *wl);
410int wl1251_init_ieee80211(struct wl1251 *wl);
411
407#define DEFAULT_HW_GEN_MODULATION_TYPE CCK_LONG /* Long Preamble */ 412#define DEFAULT_HW_GEN_MODULATION_TYPE CCK_LONG /* Long Preamble */
408#define DEFAULT_HW_GEN_TX_RATE RATE_2MBPS 413#define DEFAULT_HW_GEN_TX_RATE RATE_2MBPS
409#define JOIN_TIMEOUT 5000 /* 5000 milliseconds to join */ 414#define JOIN_TIMEOUT 5000 /* 5000 milliseconds to join */
diff --git a/drivers/net/wireless/wl12xx/wl1251_acx.c b/drivers/net/wireless/wl12xx/wl1251_acx.c
index 2e3171a61b77..91fe16c8d5b7 100644
--- a/drivers/net/wireless/wl12xx/wl1251_acx.c
+++ b/drivers/net/wireless/wl12xx/wl1251_acx.c
@@ -2,7 +2,6 @@
2 2
3#include <linux/module.h> 3#include <linux/module.h>
4#include <linux/crc7.h> 4#include <linux/crc7.h>
5#include <linux/spi/spi.h>
6 5
7#include "wl1251.h" 6#include "wl1251.h"
8#include "reg.h" 7#include "reg.h"
diff --git a/drivers/net/wireless/wl12xx/wl1251_cmd.c b/drivers/net/wireless/wl12xx/wl1251_cmd.c
index 2c30c705908e..dfbf6811976d 100644
--- a/drivers/net/wireless/wl12xx/wl1251_cmd.c
+++ b/drivers/net/wireless/wl12xx/wl1251_cmd.c
@@ -2,7 +2,6 @@
2 2
3#include <linux/module.h> 3#include <linux/module.h>
4#include <linux/crc7.h> 4#include <linux/crc7.h>
5#include <linux/spi/spi.h>
6 5
7#include "wl1251.h" 6#include "wl1251.h"
8#include "reg.h" 7#include "reg.h"
diff --git a/drivers/net/wireless/wl12xx/wl1251_main.c b/drivers/net/wireless/wl12xx/wl1251_main.c
index 0f30d0a62aa9..74544e11f692 100644
--- a/drivers/net/wireless/wl12xx/wl1251_main.c
+++ b/drivers/net/wireless/wl12xx/wl1251_main.c
@@ -26,17 +26,15 @@
26#include <linux/firmware.h> 26#include <linux/firmware.h>
27#include <linux/delay.h> 27#include <linux/delay.h>
28#include <linux/irq.h> 28#include <linux/irq.h>
29#include <linux/spi/spi.h>
30#include <linux/crc32.h> 29#include <linux/crc32.h>
31#include <linux/etherdevice.h> 30#include <linux/etherdevice.h>
32#include <linux/spi/wl12xx.h>
33 31
34#include "wl1251.h" 32#include "wl1251.h"
35#include "wl12xx_80211.h" 33#include "wl12xx_80211.h"
36#include "reg.h" 34#include "reg.h"
37#include "wl1251_ops.h" 35#include "wl1251_ops.h"
38#include "wl1251_io.h" 36#include "wl1251_io.h"
39#include "wl1251_spi.h" 37#include "wl1251_cmd.h"
40#include "wl1251_event.h" 38#include "wl1251_event.h"
41#include "wl1251_tx.h" 39#include "wl1251_tx.h"
42#include "wl1251_rx.h" 40#include "wl1251_rx.h"
@@ -59,7 +57,7 @@ static void wl1251_power_on(struct wl1251 *wl)
59 wl->set_power(true); 57 wl->set_power(true);
60} 58}
61 59
62static irqreturn_t wl1251_irq(int irq, void *cookie) 60irqreturn_t wl1251_irq(int irq, void *cookie)
63{ 61{
64 struct wl1251 *wl; 62 struct wl1251 *wl;
65 63
@@ -1169,8 +1167,10 @@ static int wl1251_register_hw(struct wl1251 *wl)
1169 return 0; 1167 return 0;
1170} 1168}
1171 1169
1172static int wl1251_init_ieee80211(struct wl1251 *wl) 1170int wl1251_init_ieee80211(struct wl1251 *wl)
1173{ 1171{
1172 int ret;
1173
1174 /* The tx descriptor buffer and the TKIP space */ 1174 /* The tx descriptor buffer and the TKIP space */
1175 wl->hw->extra_tx_headroom = sizeof(struct tx_double_buffer_desc) 1175 wl->hw->extra_tx_headroom = sizeof(struct tx_double_buffer_desc)
1176 + WL1251_TKIP_IV_SPACE; 1176 + WL1251_TKIP_IV_SPACE;
@@ -1186,41 +1186,37 @@ static int wl1251_init_ieee80211(struct wl1251 *wl)
1186 wl->hw->wiphy->max_scan_ssids = 1; 1186 wl->hw->wiphy->max_scan_ssids = 1;
1187 wl->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &wl1251_band_2ghz; 1187 wl->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &wl1251_band_2ghz;
1188 1188
1189 SET_IEEE80211_DEV(wl->hw, &wl->spi->dev); 1189 ret = wl1251_register_hw(wl);
1190 if (ret)
1191 goto out;
1190 1192
1191 return 0; 1193 wl1251_debugfs_init(wl);
1192} 1194 wl1251_notice("initialized");
1193 1195
1194extern struct wl1251_if_operations wl1251_spi_ops; 1196 ret = 0;
1197
1198out:
1199 return ret;
1200}
1195 1201
1196#define WL1251_DEFAULT_CHANNEL 1 1202#define WL1251_DEFAULT_CHANNEL 1
1197static int __devinit wl1251_probe(struct spi_device *spi) 1203struct ieee80211_hw *wl1251_alloc_hw(void)
1198{ 1204{
1199 struct wl12xx_platform_data *pdata;
1200 struct ieee80211_hw *hw; 1205 struct ieee80211_hw *hw;
1201 struct wl1251 *wl; 1206 struct wl1251 *wl;
1202 int ret, i; 1207 int i;
1203 static const u8 nokia_oui[3] = {0x00, 0x1f, 0xdf}; 1208 static const u8 nokia_oui[3] = {0x00, 0x1f, 0xdf};
1204 1209
1205 pdata = spi->dev.platform_data;
1206 if (!pdata) {
1207 wl1251_error("no platform data");
1208 return -ENODEV;
1209 }
1210
1211 hw = ieee80211_alloc_hw(sizeof(*wl), &wl1251_ops); 1210 hw = ieee80211_alloc_hw(sizeof(*wl), &wl1251_ops);
1212 if (!hw) { 1211 if (!hw) {
1213 wl1251_error("could not alloc ieee80211_hw"); 1212 wl1251_error("could not alloc ieee80211_hw");
1214 return -ENOMEM; 1213 return ERR_PTR(-ENOMEM);
1215 } 1214 }
1216 1215
1217 wl = hw->priv; 1216 wl = hw->priv;
1218 memset(wl, 0, sizeof(*wl)); 1217 memset(wl, 0, sizeof(*wl));
1219 1218
1220 wl->hw = hw; 1219 wl->hw = hw;
1221 dev_set_drvdata(&spi->dev, wl);
1222 wl->spi = spi;
1223 wl->if_ops = &wl1251_spi_ops;
1224 1220
1225 wl->data_in_count = 0; 1221 wl->data_in_count = 0;
1226 1222
@@ -1268,74 +1264,15 @@ static int __devinit wl1251_probe(struct spi_device *spi)
1268 wl->rx_descriptor = kmalloc(sizeof(*wl->rx_descriptor), GFP_KERNEL); 1264 wl->rx_descriptor = kmalloc(sizeof(*wl->rx_descriptor), GFP_KERNEL);
1269 if (!wl->rx_descriptor) { 1265 if (!wl->rx_descriptor) {
1270 wl1251_error("could not allocate memory for rx descriptor"); 1266 wl1251_error("could not allocate memory for rx descriptor");
1271 ret = -ENOMEM; 1267 ieee80211_free_hw(hw);
1272 goto out_free; 1268 return ERR_PTR(-ENOMEM);
1273 } 1269 }
1274 1270
1275 /* This is the only SPI value that we need to set here, the rest 1271 return hw;
1276 * comes from the board-peripherals file */
1277 spi->bits_per_word = 32;
1278
1279 ret = spi_setup(spi);
1280 if (ret < 0) {
1281 wl1251_error("spi_setup failed");
1282 goto out_free;
1283 }
1284
1285 wl->set_power = pdata->set_power;
1286 if (!wl->set_power) {
1287 wl1251_error("set power function missing in platform data");
1288 ret = -ENODEV;
1289 goto out_free;
1290 }
1291
1292 wl->irq = spi->irq;
1293 if (wl->irq < 0) {
1294 wl1251_error("irq missing in platform data");
1295 ret = -ENODEV;
1296 goto out_free;
1297 }
1298
1299 ret = request_irq(wl->irq, wl1251_irq, 0, DRIVER_NAME, wl);
1300 if (ret < 0) {
1301 wl1251_error("request_irq() failed: %d", ret);
1302 goto out_free;
1303 }
1304
1305 set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
1306
1307 disable_irq(wl->irq);
1308
1309 ret = wl1251_init_ieee80211(wl);
1310 if (ret)
1311 goto out_irq;
1312
1313 ret = wl1251_register_hw(wl);
1314 if (ret)
1315 goto out_irq;
1316
1317 wl1251_debugfs_init(wl);
1318
1319 wl1251_notice("initialized");
1320
1321 return 0;
1322
1323 out_irq:
1324 free_irq(wl->irq, wl);
1325
1326 out_free:
1327 kfree(wl->rx_descriptor);
1328 wl->rx_descriptor = NULL;
1329
1330 ieee80211_free_hw(hw);
1331
1332 return ret;
1333} 1272}
1334 1273
1335static int __devexit wl1251_remove(struct spi_device *spi) 1274int wl1251_free_hw(struct wl1251 *wl)
1336{ 1275{
1337 struct wl1251 *wl = dev_get_drvdata(&spi->dev);
1338
1339 ieee80211_unregister_hw(wl->hw); 1276 ieee80211_unregister_hw(wl->hw);
1340 1277
1341 wl1251_debugfs_exit(wl); 1278 wl1251_debugfs_exit(wl);
@@ -1355,44 +1292,3 @@ static int __devexit wl1251_remove(struct spi_device *spi)
1355 1292
1356 return 0; 1293 return 0;
1357} 1294}
1358
1359
1360static struct spi_driver wl1251_spi_driver = {
1361 .driver = {
1362 /* FIXME: use wl12xx name to not break the user space */
1363 .name = "wl12xx",
1364 .bus = &spi_bus_type,
1365 .owner = THIS_MODULE,
1366 },
1367
1368 .probe = wl1251_probe,
1369 .remove = __devexit_p(wl1251_remove),
1370};
1371
1372static int __init wl1251_init(void)
1373{
1374 int ret;
1375
1376 ret = spi_register_driver(&wl1251_spi_driver);
1377 if (ret < 0) {
1378 wl1251_error("failed to register spi driver: %d", ret);
1379 goto out;
1380 }
1381
1382out:
1383 return ret;
1384}
1385
1386static void __exit wl1251_exit(void)
1387{
1388 spi_unregister_driver(&wl1251_spi_driver);
1389
1390 wl1251_notice("unloaded");
1391}
1392
1393module_init(wl1251_init);
1394module_exit(wl1251_exit);
1395
1396MODULE_LICENSE("GPL");
1397MODULE_AUTHOR("Kalle Valo <Kalle.Valo@nokia.com>, "
1398 "Luciano Coelho <luciano.coelho@nokia.com>");
diff --git a/drivers/net/wireless/wl12xx/wl1251_spi.c b/drivers/net/wireless/wl12xx/wl1251_spi.c
index ceb237b4e579..13e7a726dea2 100644
--- a/drivers/net/wireless/wl12xx/wl1251_spi.c
+++ b/drivers/net/wireless/wl12xx/wl1251_spi.c
@@ -21,9 +21,11 @@
21 * 21 *
22 */ 22 */
23 23
24#include <linux/irq.h>
24#include <linux/module.h> 25#include <linux/module.h>
25#include <linux/crc7.h> 26#include <linux/crc7.h>
26#include <linux/spi/spi.h> 27#include <linux/spi/spi.h>
28#include <linux/spi/wl12xx.h>
27 29
28#include "wl1251.h" 30#include "wl1251.h"
29#include "reg.h" 31#include "reg.h"
@@ -55,7 +57,7 @@ static void wl1251_spi_reset(struct wl1251 *wl)
55 wl1251_dump(DEBUG_SPI, "spi reset -> ", cmd, WSPI_INIT_CMD_LEN); 57 wl1251_dump(DEBUG_SPI, "spi reset -> ", cmd, WSPI_INIT_CMD_LEN);
56} 58}
57 59
58static void wl1251_spi_init(struct wl1251 *wl) 60static void wl1251_spi_wake(struct wl1251 *wl)
59{ 61{
60 u8 crc[WSPI_INIT_CMD_CRC_LEN], *cmd; 62 u8 crc[WSPI_INIT_CMD_CRC_LEN], *cmd;
61 struct spi_transfer t; 63 struct spi_transfer t;
@@ -112,7 +114,7 @@ static void wl1251_spi_init(struct wl1251 *wl)
112static void wl1251_spi_reset_wake(struct wl1251 *wl) 114static void wl1251_spi_reset_wake(struct wl1251 *wl)
113{ 115{
114 wl1251_spi_reset(wl); 116 wl1251_spi_reset(wl);
115 wl1251_spi_init(wl); 117 wl1251_spi_wake(wl);
116} 118}
117 119
118static void wl1251_spi_read(struct wl1251 *wl, int addr, void *buf, 120static void wl1251_spi_read(struct wl1251 *wl, int addr, void *buf,
@@ -191,3 +193,122 @@ const struct wl1251_if_operations wl1251_spi_ops = {
191 .write = wl1251_spi_write, 193 .write = wl1251_spi_write,
192 .reset = wl1251_spi_reset_wake, 194 .reset = wl1251_spi_reset_wake,
193}; 195};
196
197static int __devinit wl1251_spi_probe(struct spi_device *spi)
198{
199 struct wl12xx_platform_data *pdata;
200 struct ieee80211_hw *hw;
201 struct wl1251 *wl;
202 int ret;
203
204 pdata = spi->dev.platform_data;
205 if (!pdata) {
206 wl1251_error("no platform data");
207 return -ENODEV;
208 }
209
210 hw = wl1251_alloc_hw();
211 if (IS_ERR(hw))
212 return PTR_ERR(hw);
213
214 wl = hw->priv;
215
216 SET_IEEE80211_DEV(hw, &spi->dev);
217 dev_set_drvdata(&spi->dev, wl);
218 wl->spi = spi;
219 wl->if_ops = &wl1251_spi_ops;
220
221 /* This is the only SPI value that we need to set here, the rest
222 * comes from the board-peripherals file */
223 spi->bits_per_word = 32;
224
225 ret = spi_setup(spi);
226 if (ret < 0) {
227 wl1251_error("spi_setup failed");
228 goto out_free;
229 }
230
231 wl->set_power = pdata->set_power;
232 if (!wl->set_power) {
233 wl1251_error("set power function missing in platform data");
234 return -ENODEV;
235 }
236
237 wl->irq = spi->irq;
238 if (wl->irq < 0) {
239 wl1251_error("irq missing in platform data");
240 return -ENODEV;
241 }
242
243 ret = request_irq(wl->irq, wl1251_irq, 0, DRIVER_NAME, wl);
244 if (ret < 0) {
245 wl1251_error("request_irq() failed: %d", ret);
246 goto out_free;
247 }
248
249 set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
250
251 disable_irq(wl->irq);
252
253 ret = wl1251_init_ieee80211(wl);
254 if (ret)
255 goto out_irq;
256
257 return 0;
258
259 out_irq:
260 free_irq(wl->irq, wl);
261
262 out_free:
263 ieee80211_free_hw(hw);
264
265 return ret;
266}
267
268static int __devexit wl1251_spi_remove(struct spi_device *spi)
269{
270 struct wl1251 *wl = dev_get_drvdata(&spi->dev);
271
272 wl1251_free_hw(wl);
273
274 return 0;
275}
276
277static struct spi_driver wl1251_spi_driver = {
278 .driver = {
279 .name = "wl12xx",
280 .bus = &spi_bus_type,
281 .owner = THIS_MODULE,
282 },
283
284 .probe = wl1251_spi_probe,
285 .remove = __devexit_p(wl1251_spi_remove),
286};
287
288static int __init wl1251_spi_init(void)
289{
290 int ret;
291
292 ret = spi_register_driver(&wl1251_spi_driver);
293 if (ret < 0) {
294 wl1251_error("failed to register spi driver: %d", ret);
295 goto out;
296 }
297
298out:
299 return ret;
300}
301
302static void __exit wl1251_spi_exit(void)
303{
304 spi_unregister_driver(&wl1251_spi_driver);
305
306 wl1251_notice("unloaded");
307}
308
309module_init(wl1251_spi_init);
310module_exit(wl1251_spi_exit);
311
312MODULE_LICENSE("GPL");
313MODULE_AUTHOR("Kalle Valo <Kalle.Valo@nokia.com>");
314MODULE_AUTHOR("Luciano Coelho <luciano.coelho@nokia.com>");
diff --git a/drivers/net/wireless/wl12xx/wl1251_tx.c b/drivers/net/wireless/wl12xx/wl1251_tx.c
index 7ddc9a346304..f20bab61fd63 100644
--- a/drivers/net/wireless/wl12xx/wl1251_tx.c
+++ b/drivers/net/wireless/wl12xx/wl1251_tx.c
@@ -27,7 +27,6 @@
27 27
28#include "wl1251.h" 28#include "wl1251.h"
29#include "reg.h" 29#include "reg.h"
30#include "wl1251_spi.h"
31#include "wl1251_tx.h" 30#include "wl1251_tx.h"
32#include "wl1251_ps.h" 31#include "wl1251_ps.h"
33#include "wl1251_io.h" 32#include "wl1251_io.h"