aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/wl12xx/spi.c
diff options
context:
space:
mode:
authorFelipe Balbi <balbi@ti.com>2011-10-06 03:07:44 -0400
committerLuciano Coelho <coelho@ti.com>2011-10-11 09:01:09 -0400
commita390e85cfe91c346ff4745bcd45ad0a7e7101aa2 (patch)
tree789c84bbe5228b6c15dda7c1072dd220bd15dba1 /drivers/net/wireless/wl12xx/spi.c
parentce2a217c8268906640ebf7291d7a06210a35dd2f (diff)
wl12xx: move common init code from bus modules to main
Move all common parts from sdio.c and spi.c to main.c, since they now can be handled as part of the platform driver. Signed-off-by: Felipe Balbi <balbi@ti.com> [forward-ported, cleaned-up and rephrased commit message] [added a bunch of fixes and a new pdata element] [moved some new code into main.c as well] Signed-off-by: Luciano Coelho <coelho@ti.com>
Diffstat (limited to 'drivers/net/wireless/wl12xx/spi.c')
-rw-r--r--drivers/net/wireless/wl12xx/spi.c161
1 files changed, 22 insertions, 139 deletions
diff --git a/drivers/net/wireless/wl12xx/spi.c b/drivers/net/wireless/wl12xx/spi.c
index 2dd659886a04..22c1337ba883 100644
--- a/drivers/net/wireless/wl12xx/spi.c
+++ b/drivers/net/wireless/wl12xx/spi.c
@@ -72,33 +72,12 @@
72 72
73struct wl12xx_spi_glue { 73struct wl12xx_spi_glue {
74 struct device *dev; 74 struct device *dev;
75 struct wl1271 *wl;
76 struct platform_device *core; 75 struct platform_device *core;
77}; 76};
78 77
79static inline struct wl12xx_spi_glue *wl_to_glue(struct wl1271 *wl) 78static void wl12xx_spi_reset(struct device *child)
80{ 79{
81 return wl->if_priv; 80 struct wl12xx_spi_glue *glue = dev_get_drvdata(child->parent);
82}
83
84static struct device *wl1271_spi_wl_to_dev(struct wl1271 *wl)
85{
86 return wl_to_glue(wl)->dev;
87}
88
89static void wl1271_spi_disable_interrupts(struct wl1271 *wl)
90{
91 disable_irq(wl->irq);
92}
93
94static void wl1271_spi_enable_interrupts(struct wl1271 *wl)
95{
96 enable_irq(wl->irq);
97}
98
99static void wl1271_spi_reset(struct wl1271 *wl)
100{
101 struct wl12xx_spi_glue *glue = wl_to_glue(wl);
102 u8 *cmd; 81 u8 *cmd;
103 struct spi_transfer t; 82 struct spi_transfer t;
104 struct spi_message m; 83 struct spi_message m;
@@ -124,9 +103,9 @@ static void wl1271_spi_reset(struct wl1271 *wl)
124 kfree(cmd); 103 kfree(cmd);
125} 104}
126 105
127static void wl1271_spi_init(struct wl1271 *wl) 106static void wl12xx_spi_init(struct device *child)
128{ 107{
129 struct wl12xx_spi_glue *glue = wl_to_glue(wl); 108 struct wl12xx_spi_glue *glue = dev_get_drvdata(child->parent);
130 u8 crc[WSPI_INIT_CMD_CRC_LEN], *cmd; 109 u8 crc[WSPI_INIT_CMD_CRC_LEN], *cmd;
131 struct spi_transfer t; 110 struct spi_transfer t;
132 struct spi_message m; 111 struct spi_message m;
@@ -181,9 +160,10 @@ static void wl1271_spi_init(struct wl1271 *wl)
181 160
182#define WL1271_BUSY_WORD_TIMEOUT 1000 161#define WL1271_BUSY_WORD_TIMEOUT 1000
183 162
184static int wl1271_spi_read_busy(struct wl1271 *wl) 163static int wl12xx_spi_read_busy(struct device *child)
185{ 164{
186 struct wl12xx_spi_glue *glue = wl_to_glue(wl); 165 struct wl12xx_spi_glue *glue = dev_get_drvdata(child->parent);
166 struct wl1271 *wl = dev_get_drvdata(child);
187 struct spi_transfer t[1]; 167 struct spi_transfer t[1];
188 struct spi_message m; 168 struct spi_message m;
189 u32 *busy_buf; 169 u32 *busy_buf;
@@ -215,10 +195,11 @@ static int wl1271_spi_read_busy(struct wl1271 *wl)
215 return -ETIMEDOUT; 195 return -ETIMEDOUT;
216} 196}
217 197
218static void wl1271_spi_raw_read(struct wl1271 *wl, int addr, void *buf, 198static void wl12xx_spi_raw_read(struct device *child, int addr, void *buf,
219 size_t len, bool fixed) 199 size_t len, bool fixed)
220{ 200{
221 struct wl12xx_spi_glue *glue = wl_to_glue(wl); 201 struct wl12xx_spi_glue *glue = dev_get_drvdata(child->parent);
202 struct wl1271 *wl = dev_get_drvdata(child);
222 struct spi_transfer t[2]; 203 struct spi_transfer t[2];
223 struct spi_message m; 204 struct spi_message m;
224 u32 *busy_buf; 205 u32 *busy_buf;
@@ -257,7 +238,7 @@ static void wl1271_spi_raw_read(struct wl1271 *wl, int addr, void *buf,
257 spi_sync(to_spi_device(glue->dev), &m); 238 spi_sync(to_spi_device(glue->dev), &m);
258 239
259 if (!(busy_buf[WL1271_BUSY_WORD_CNT - 1] & 0x1) && 240 if (!(busy_buf[WL1271_BUSY_WORD_CNT - 1] & 0x1) &&
260 wl1271_spi_read_busy(wl)) { 241 wl12xx_spi_read_busy(child)) {
261 memset(buf, 0, chunk_len); 242 memset(buf, 0, chunk_len);
262 return; 243 return;
263 } 244 }
@@ -282,10 +263,10 @@ static void wl1271_spi_raw_read(struct wl1271 *wl, int addr, void *buf,
282 } 263 }
283} 264}
284 265
285static void wl1271_spi_raw_write(struct wl1271 *wl, int addr, void *buf, 266static void wl12xx_spi_raw_write(struct device *child, int addr, void *buf,
286 size_t len, bool fixed) 267 size_t len, bool fixed)
287{ 268{
288 struct wl12xx_spi_glue *glue = wl_to_glue(wl); 269 struct wl12xx_spi_glue *glue = dev_get_drvdata(child->parent);
289 struct spi_transfer t[2 * WSPI_MAX_NUM_OF_CHUNKS]; 270 struct spi_transfer t[2 * WSPI_MAX_NUM_OF_CHUNKS];
290 struct spi_message m; 271 struct spi_message m;
291 u32 commands[WSPI_MAX_NUM_OF_CHUNKS]; 272 u32 commands[WSPI_MAX_NUM_OF_CHUNKS];
@@ -333,42 +314,11 @@ static void wl1271_spi_raw_write(struct wl1271 *wl, int addr, void *buf,
333 spi_sync(to_spi_device(glue->dev), &m); 314 spi_sync(to_spi_device(glue->dev), &m);
334} 315}
335 316
336static irqreturn_t wl1271_hardirq(int irq, void *cookie)
337{
338 struct wl1271 *wl = cookie;
339 unsigned long flags;
340
341 wl1271_debug(DEBUG_IRQ, "IRQ");
342
343 /* complete the ELP completion */
344 spin_lock_irqsave(&wl->wl_lock, flags);
345 set_bit(WL1271_FLAG_IRQ_RUNNING, &wl->flags);
346 if (wl->elp_compl) {
347 complete(wl->elp_compl);
348 wl->elp_compl = NULL;
349 }
350 spin_unlock_irqrestore(&wl->wl_lock, flags);
351
352 return IRQ_WAKE_THREAD;
353}
354
355static int wl1271_spi_set_power(struct wl1271 *wl, bool enable)
356{
357 if (wl->set_power)
358 wl->set_power(enable);
359
360 return 0;
361}
362
363static struct wl1271_if_operations spi_ops = { 317static struct wl1271_if_operations spi_ops = {
364 .read = wl1271_spi_raw_read, 318 .read = wl12xx_spi_raw_read,
365 .write = wl1271_spi_raw_write, 319 .write = wl12xx_spi_raw_write,
366 .reset = wl1271_spi_reset, 320 .reset = wl12xx_spi_reset,
367 .init = wl1271_spi_init, 321 .init = wl12xx_spi_init,
368 .power = wl1271_spi_set_power,
369 .dev = wl1271_spi_wl_to_dev,
370 .enable_irq = wl1271_spi_enable_interrupts,
371 .disable_irq = wl1271_spi_disable_interrupts,
372 .set_block_size = NULL, 322 .set_block_size = NULL,
373}; 323};
374 324
@@ -376,10 +326,7 @@ static int __devinit wl1271_probe(struct spi_device *spi)
376{ 326{
377 struct wl12xx_spi_glue *glue; 327 struct wl12xx_spi_glue *glue;
378 struct wl12xx_platform_data *pdata; 328 struct wl12xx_platform_data *pdata;
379 struct ieee80211_hw *hw;
380 struct wl1271 *wl;
381 struct resource res[1]; 329 struct resource res[1];
382 unsigned long irqflags;
383 int ret = -ENOMEM; 330 int ret = -ENOMEM;
384 331
385 pdata = spi->dev.platform_data; 332 pdata = spi->dev.platform_data;
@@ -388,27 +335,17 @@ static int __devinit wl1271_probe(struct spi_device *spi)
388 return -ENODEV; 335 return -ENODEV;
389 } 336 }
390 337
338 pdata->ops = &spi_ops;
339
391 glue = kzalloc(sizeof(*glue), GFP_KERNEL); 340 glue = kzalloc(sizeof(*glue), GFP_KERNEL);
392 if (!glue) { 341 if (!glue) {
393 wl1271_error("can't allocate glue"); 342 wl1271_error("can't allocate glue");
394 goto out; 343 goto out;
395 } 344 }
396 345
397 hw = wl1271_alloc_hw();
398 if (IS_ERR(hw)) {
399 ret = PTR_ERR(hw);
400 goto out_free_glue;
401 }
402
403 wl = hw->priv;
404
405 glue->dev = &spi->dev; 346 glue->dev = &spi->dev;
406 glue->wl = wl;
407 347
408 spi_set_drvdata(spi, glue); 348 spi_set_drvdata(spi, glue);
409 wl->if_priv = glue;
410
411 wl->if_ops = &spi_ops;
412 349
413 /* This is the only SPI value that we need to set here, the rest 350 /* This is the only SPI value that we need to set here, the rest
414 * comes from the board-peripherals file */ 351 * comes from the board-peripherals file */
@@ -417,55 +354,14 @@ static int __devinit wl1271_probe(struct spi_device *spi)
417 ret = spi_setup(spi); 354 ret = spi_setup(spi);
418 if (ret < 0) { 355 if (ret < 0) {
419 wl1271_error("spi_setup failed"); 356 wl1271_error("spi_setup failed");
420 goto out_free_hw; 357 goto out_free_glue;
421 }
422
423 wl->set_power = pdata->set_power;
424 if (!wl->set_power) {
425 wl1271_error("set power function missing in platform data");
426 ret = -ENODEV;
427 goto out_free_hw;
428 }
429
430 wl->ref_clock = pdata->board_ref_clock;
431 wl->tcxo_clock = pdata->board_tcxo_clock;
432 wl->platform_quirks = pdata->platform_quirks;
433
434 if (wl->platform_quirks & WL12XX_PLATFORM_QUIRK_EDGE_IRQ)
435 irqflags = IRQF_TRIGGER_RISING;
436 else
437 irqflags = IRQF_TRIGGER_HIGH | IRQF_ONESHOT;
438
439 wl->irq = spi->irq;
440 if (wl->irq < 0) {
441 wl1271_error("irq missing in platform data");
442 ret = -ENODEV;
443 goto out_free_hw;
444 }
445
446 ret = request_threaded_irq(wl->irq, wl1271_hardirq, wl1271_irq,
447 irqflags,
448 DRIVER_NAME, wl);
449 if (ret < 0) {
450 wl1271_error("request_irq() failed: %d", ret);
451 goto out_free_hw;
452 } 358 }
453 359
454 disable_irq(wl->irq);
455
456 ret = wl1271_init_ieee80211(wl);
457 if (ret)
458 goto out_irq;
459
460 ret = wl1271_register_hw(wl);
461 if (ret)
462 goto out_irq;
463
464 glue->core = platform_device_alloc("wl12xx-spi", -1); 360 glue->core = platform_device_alloc("wl12xx-spi", -1);
465 if (!glue->core) { 361 if (!glue->core) {
466 wl1271_error("can't allocate platform_device"); 362 wl1271_error("can't allocate platform_device");
467 ret = -ENOMEM; 363 ret = -ENOMEM;
468 goto out_unreg_hw; 364 goto out_free_glue;
469 } 365 }
470 366
471 glue->core->dev.parent = &spi->dev; 367 glue->core->dev.parent = &spi->dev;
@@ -499,15 +395,6 @@ static int __devinit wl1271_probe(struct spi_device *spi)
499out_dev_put: 395out_dev_put:
500 platform_device_put(glue->core); 396 platform_device_put(glue->core);
501 397
502out_unreg_hw:
503 wl1271_unregister_hw(wl);
504
505out_irq:
506 free_irq(wl->irq, wl);
507
508out_free_hw:
509 wl1271_free_hw(wl);
510
511out_free_glue: 398out_free_glue:
512 kfree(glue); 399 kfree(glue);
513out: 400out:
@@ -517,11 +404,7 @@ out:
517static int __devexit wl1271_remove(struct spi_device *spi) 404static int __devexit wl1271_remove(struct spi_device *spi)
518{ 405{
519 struct wl12xx_spi_glue *glue = spi_get_drvdata(spi); 406 struct wl12xx_spi_glue *glue = spi_get_drvdata(spi);
520 struct wl1271 *wl = glue->wl;
521 407
522 wl1271_unregister_hw(wl);
523 free_irq(wl->irq, wl);
524 wl1271_free_hw(wl);
525 platform_device_del(glue->core); 408 platform_device_del(glue->core);
526 platform_device_put(glue->core); 409 platform_device_put(glue->core);
527 kfree(glue); 410 kfree(glue);