diff options
author | Sonic Zhang <sonic.zhang@analog.com> | 2007-12-05 02:45:17 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-12-05 12:21:19 -0500 |
commit | cc487e732089360727e60f9fdbe3ff6cc4ca3155 (patch) | |
tree | a4037cc7b238b582c50ff0520c5a47822e0f83fc /drivers | |
parent | 12e17c4267a5b2a5ba77bd53a62388be641534b8 (diff) |
spi: spi_bfin: change handling of communication parameters
Fix SPI driver to work with SPI flash ST M25P16 on bf548
Currently the SPI driver enables the SPI controller and sets the SPI baud
register for each SPI transfer. But they should never be changed within a SPI
message session, in which several SPI transfers are pumped.
This patch moves SPI setting to the begining of a message session, and
never disables SPI controller until an error occurs.
Signed-off-by: Sonic Zhang <sonic.zhang@analog.com>
Signed-off-by: Bryan Wu <bryan.wu@analog.com>
Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/spi/spi_bfin5xx.c | 162 |
1 files changed, 87 insertions, 75 deletions
diff --git a/drivers/spi/spi_bfin5xx.c b/drivers/spi/spi_bfin5xx.c index 4496ed158e6b..c99a2afabf0c 100644 --- a/drivers/spi/spi_bfin5xx.c +++ b/drivers/spi/spi_bfin5xx.c | |||
@@ -222,9 +222,13 @@ static int restore_state(struct driver_data *drv_data) | |||
222 | dev_dbg(&drv_data->pdev->dev, "restoring spi ctl state\n"); | 222 | dev_dbg(&drv_data->pdev->dev, "restoring spi ctl state\n"); |
223 | 223 | ||
224 | /* Load the registers */ | 224 | /* Load the registers */ |
225 | write_CTRL(chip->ctl_reg); | 225 | cs_deactive(chip); |
226 | write_BAUD(chip->baud); | 226 | write_BAUD(chip->baud); |
227 | cs_active(chip); | 227 | chip->ctl_reg &= (~BIT_CTL_TIMOD); |
228 | chip->ctl_reg |= (chip->width << 8); | ||
229 | write_CTRL(chip->ctl_reg); | ||
230 | |||
231 | bfin_spi_enable(drv_data); | ||
228 | 232 | ||
229 | if (ret) | 233 | if (ret) |
230 | dev_dbg(&drv_data->pdev->dev, | 234 | dev_dbg(&drv_data->pdev->dev, |
@@ -271,6 +275,7 @@ static void u8_writer(struct driver_data *drv_data) | |||
271 | { | 275 | { |
272 | dev_dbg(&drv_data->pdev->dev, | 276 | dev_dbg(&drv_data->pdev->dev, |
273 | "cr8-s is 0x%x\n", read_STAT()); | 277 | "cr8-s is 0x%x\n", read_STAT()); |
278 | |||
274 | while (drv_data->tx < drv_data->tx_end) { | 279 | while (drv_data->tx < drv_data->tx_end) { |
275 | write_TDBR(*(u8 *) (drv_data->tx)); | 280 | write_TDBR(*(u8 *) (drv_data->tx)); |
276 | while (read_STAT() & BIT_STAT_TXS) | 281 | while (read_STAT() & BIT_STAT_TXS) |
@@ -293,16 +298,16 @@ static void u8_cs_chg_writer(struct driver_data *drv_data) | |||
293 | write_TDBR(*(u8 *) (drv_data->tx)); | 298 | write_TDBR(*(u8 *) (drv_data->tx)); |
294 | while (read_STAT() & BIT_STAT_TXS) | 299 | while (read_STAT() & BIT_STAT_TXS) |
295 | continue; | 300 | continue; |
296 | while (!(read_STAT() & BIT_STAT_SPIF)) | ||
297 | continue; | ||
298 | cs_deactive(chip); | 301 | cs_deactive(chip); |
299 | 302 | ||
300 | if (chip->cs_chg_udelay) | 303 | if (chip->cs_chg_udelay) |
301 | udelay(chip->cs_chg_udelay); | 304 | udelay(chip->cs_chg_udelay); |
302 | ++drv_data->tx; | 305 | ++drv_data->tx; |
303 | } | 306 | } |
304 | cs_deactive(chip); | ||
305 | 307 | ||
308 | /* poll for SPI completion before returning */ | ||
309 | while (!(read_STAT() & BIT_STAT_SPIF)) | ||
310 | continue; | ||
306 | } | 311 | } |
307 | 312 | ||
308 | static void u8_reader(struct driver_data *drv_data) | 313 | static void u8_reader(struct driver_data *drv_data) |
@@ -314,6 +319,7 @@ static void u8_reader(struct driver_data *drv_data) | |||
314 | write_TDBR(0xFFFF); | 319 | write_TDBR(0xFFFF); |
315 | 320 | ||
316 | dummy_read(); | 321 | dummy_read(); |
322 | |||
317 | while (drv_data->rx < drv_data->rx_end - 1) { | 323 | while (drv_data->rx < drv_data->rx_end - 1) { |
318 | while (!(read_STAT() & BIT_STAT_RXS)) | 324 | while (!(read_STAT() & BIT_STAT_RXS)) |
319 | continue; | 325 | continue; |
@@ -331,23 +337,30 @@ static void u8_cs_chg_reader(struct driver_data *drv_data) | |||
331 | { | 337 | { |
332 | struct chip_data *chip = drv_data->cur_chip; | 338 | struct chip_data *chip = drv_data->cur_chip; |
333 | 339 | ||
334 | while (drv_data->rx < drv_data->rx_end) { | 340 | /* clear TDBR buffer before read(else it will be shifted out) */ |
335 | cs_active(chip); | 341 | write_TDBR(0xFFFF); |
336 | 342 | ||
337 | read_RDBR(); /* kick off */ | 343 | cs_active(chip); |
338 | while (!(read_STAT() & BIT_STAT_RXS)) | 344 | dummy_read(); |
339 | continue; | 345 | |
340 | while (!(read_STAT() & BIT_STAT_SPIF)) | 346 | while (drv_data->rx < drv_data->rx_end - 1) { |
341 | continue; | ||
342 | *(u8 *) (drv_data->rx) = read_SHAW(); | ||
343 | cs_deactive(chip); | 347 | cs_deactive(chip); |
344 | 348 | ||
345 | if (chip->cs_chg_udelay) | 349 | if (chip->cs_chg_udelay) |
346 | udelay(chip->cs_chg_udelay); | 350 | udelay(chip->cs_chg_udelay); |
351 | |||
352 | while (!(read_STAT() & BIT_STAT_RXS)) | ||
353 | continue; | ||
354 | cs_active(chip); | ||
355 | *(u8 *) (drv_data->rx) = read_RDBR(); | ||
347 | ++drv_data->rx; | 356 | ++drv_data->rx; |
348 | } | 357 | } |
349 | cs_deactive(chip); | 358 | cs_deactive(chip); |
350 | 359 | ||
360 | while (!(read_STAT() & BIT_STAT_RXS)) | ||
361 | continue; | ||
362 | *(u8 *) (drv_data->rx) = read_SHAW(); | ||
363 | ++drv_data->rx; | ||
351 | } | 364 | } |
352 | 365 | ||
353 | static void u8_duplex(struct driver_data *drv_data) | 366 | static void u8_duplex(struct driver_data *drv_data) |
@@ -355,7 +368,7 @@ static void u8_duplex(struct driver_data *drv_data) | |||
355 | /* in duplex mode, clk is triggered by writing of TDBR */ | 368 | /* in duplex mode, clk is triggered by writing of TDBR */ |
356 | while (drv_data->rx < drv_data->rx_end) { | 369 | while (drv_data->rx < drv_data->rx_end) { |
357 | write_TDBR(*(u8 *) (drv_data->tx)); | 370 | write_TDBR(*(u8 *) (drv_data->tx)); |
358 | while (!(read_STAT() & BIT_STAT_SPIF)) | 371 | while (read_STAT() & BIT_STAT_TXS) |
359 | continue; | 372 | continue; |
360 | while (!(read_STAT() & BIT_STAT_RXS)) | 373 | while (!(read_STAT() & BIT_STAT_RXS)) |
361 | continue; | 374 | continue; |
@@ -363,6 +376,10 @@ static void u8_duplex(struct driver_data *drv_data) | |||
363 | ++drv_data->rx; | 376 | ++drv_data->rx; |
364 | ++drv_data->tx; | 377 | ++drv_data->tx; |
365 | } | 378 | } |
379 | |||
380 | /* poll for SPI completion before returning */ | ||
381 | while (!(read_STAT() & BIT_STAT_SPIF)) | ||
382 | continue; | ||
366 | } | 383 | } |
367 | 384 | ||
368 | static void u8_cs_chg_duplex(struct driver_data *drv_data) | 385 | static void u8_cs_chg_duplex(struct driver_data *drv_data) |
@@ -372,9 +389,8 @@ static void u8_cs_chg_duplex(struct driver_data *drv_data) | |||
372 | while (drv_data->rx < drv_data->rx_end) { | 389 | while (drv_data->rx < drv_data->rx_end) { |
373 | cs_active(chip); | 390 | cs_active(chip); |
374 | 391 | ||
375 | |||
376 | write_TDBR(*(u8 *) (drv_data->tx)); | 392 | write_TDBR(*(u8 *) (drv_data->tx)); |
377 | while (!(read_STAT() & BIT_STAT_SPIF)) | 393 | while (read_STAT() & BIT_STAT_TXS) |
378 | continue; | 394 | continue; |
379 | while (!(read_STAT() & BIT_STAT_RXS)) | 395 | while (!(read_STAT() & BIT_STAT_RXS)) |
380 | continue; | 396 | continue; |
@@ -386,7 +402,10 @@ static void u8_cs_chg_duplex(struct driver_data *drv_data) | |||
386 | ++drv_data->rx; | 402 | ++drv_data->rx; |
387 | ++drv_data->tx; | 403 | ++drv_data->tx; |
388 | } | 404 | } |
389 | cs_deactive(chip); | 405 | |
406 | /* poll for SPI completion before returning */ | ||
407 | while (!(read_STAT() & BIT_STAT_SPIF)) | ||
408 | continue; | ||
390 | } | 409 | } |
391 | 410 | ||
392 | static void u16_writer(struct driver_data *drv_data) | 411 | static void u16_writer(struct driver_data *drv_data) |
@@ -416,21 +435,26 @@ static void u16_cs_chg_writer(struct driver_data *drv_data) | |||
416 | write_TDBR(*(u16 *) (drv_data->tx)); | 435 | write_TDBR(*(u16 *) (drv_data->tx)); |
417 | while ((read_STAT() & BIT_STAT_TXS)) | 436 | while ((read_STAT() & BIT_STAT_TXS)) |
418 | continue; | 437 | continue; |
419 | while (!(read_STAT() & BIT_STAT_SPIF)) | ||
420 | continue; | ||
421 | cs_deactive(chip); | 438 | cs_deactive(chip); |
422 | 439 | ||
423 | if (chip->cs_chg_udelay) | 440 | if (chip->cs_chg_udelay) |
424 | udelay(chip->cs_chg_udelay); | 441 | udelay(chip->cs_chg_udelay); |
425 | drv_data->tx += 2; | 442 | drv_data->tx += 2; |
426 | } | 443 | } |
427 | cs_deactive(chip); | 444 | |
445 | /* poll for SPI completion before returning */ | ||
446 | while (!(read_STAT() & BIT_STAT_SPIF)) | ||
447 | continue; | ||
428 | } | 448 | } |
429 | 449 | ||
430 | static void u16_reader(struct driver_data *drv_data) | 450 | static void u16_reader(struct driver_data *drv_data) |
431 | { | 451 | { |
432 | dev_dbg(&drv_data->pdev->dev, | 452 | dev_dbg(&drv_data->pdev->dev, |
433 | "cr-16 is 0x%x\n", read_STAT()); | 453 | "cr-16 is 0x%x\n", read_STAT()); |
454 | |||
455 | /* clear TDBR buffer before read(else it will be shifted out) */ | ||
456 | write_TDBR(0xFFFF); | ||
457 | |||
434 | dummy_read(); | 458 | dummy_read(); |
435 | 459 | ||
436 | while (drv_data->rx < (drv_data->rx_end - 2)) { | 460 | while (drv_data->rx < (drv_data->rx_end - 2)) { |
@@ -450,22 +474,30 @@ static void u16_cs_chg_reader(struct driver_data *drv_data) | |||
450 | { | 474 | { |
451 | struct chip_data *chip = drv_data->cur_chip; | 475 | struct chip_data *chip = drv_data->cur_chip; |
452 | 476 | ||
453 | while (drv_data->rx < drv_data->rx_end) { | 477 | /* clear TDBR buffer before read(else it will be shifted out) */ |
454 | cs_active(chip); | 478 | write_TDBR(0xFFFF); |
455 | 479 | ||
456 | read_RDBR(); /* kick off */ | 480 | cs_active(chip); |
457 | while (!(read_STAT() & BIT_STAT_RXS)) | 481 | dummy_read(); |
458 | continue; | 482 | |
459 | while (!(read_STAT() & BIT_STAT_SPIF)) | 483 | while (drv_data->rx < drv_data->rx_end) { |
460 | continue; | ||
461 | *(u16 *) (drv_data->rx) = read_SHAW(); | ||
462 | cs_deactive(chip); | 484 | cs_deactive(chip); |
463 | 485 | ||
464 | if (chip->cs_chg_udelay) | 486 | if (chip->cs_chg_udelay) |
465 | udelay(chip->cs_chg_udelay); | 487 | udelay(chip->cs_chg_udelay); |
488 | |||
489 | while (!(read_STAT() & BIT_STAT_RXS)) | ||
490 | continue; | ||
491 | cs_active(chip); | ||
492 | *(u16 *) (drv_data->rx) = read_RDBR(); | ||
466 | drv_data->rx += 2; | 493 | drv_data->rx += 2; |
467 | } | 494 | } |
468 | cs_deactive(chip); | 495 | cs_deactive(chip); |
496 | |||
497 | while (!(read_STAT() & BIT_STAT_RXS)) | ||
498 | continue; | ||
499 | *(u16 *) (drv_data->rx) = read_SHAW(); | ||
500 | drv_data->rx += 2; | ||
469 | } | 501 | } |
470 | 502 | ||
471 | static void u16_duplex(struct driver_data *drv_data) | 503 | static void u16_duplex(struct driver_data *drv_data) |
@@ -473,7 +505,7 @@ static void u16_duplex(struct driver_data *drv_data) | |||
473 | /* in duplex mode, clk is triggered by writing of TDBR */ | 505 | /* in duplex mode, clk is triggered by writing of TDBR */ |
474 | while (drv_data->tx < drv_data->tx_end) { | 506 | while (drv_data->tx < drv_data->tx_end) { |
475 | write_TDBR(*(u16 *) (drv_data->tx)); | 507 | write_TDBR(*(u16 *) (drv_data->tx)); |
476 | while (!(read_STAT() & BIT_STAT_SPIF)) | 508 | while (read_STAT() & BIT_STAT_TXS) |
477 | continue; | 509 | continue; |
478 | while (!(read_STAT() & BIT_STAT_RXS)) | 510 | while (!(read_STAT() & BIT_STAT_RXS)) |
479 | continue; | 511 | continue; |
@@ -481,6 +513,10 @@ static void u16_duplex(struct driver_data *drv_data) | |||
481 | drv_data->rx += 2; | 513 | drv_data->rx += 2; |
482 | drv_data->tx += 2; | 514 | drv_data->tx += 2; |
483 | } | 515 | } |
516 | |||
517 | /* poll for SPI completion before returning */ | ||
518 | while (!(read_STAT() & BIT_STAT_SPIF)) | ||
519 | continue; | ||
484 | } | 520 | } |
485 | 521 | ||
486 | static void u16_cs_chg_duplex(struct driver_data *drv_data) | 522 | static void u16_cs_chg_duplex(struct driver_data *drv_data) |
@@ -491,7 +527,7 @@ static void u16_cs_chg_duplex(struct driver_data *drv_data) | |||
491 | cs_active(chip); | 527 | cs_active(chip); |
492 | 528 | ||
493 | write_TDBR(*(u16 *) (drv_data->tx)); | 529 | write_TDBR(*(u16 *) (drv_data->tx)); |
494 | while (!(read_STAT() & BIT_STAT_SPIF)) | 530 | while (read_STAT() & BIT_STAT_TXS) |
495 | continue; | 531 | continue; |
496 | while (!(read_STAT() & BIT_STAT_RXS)) | 532 | while (!(read_STAT() & BIT_STAT_RXS)) |
497 | continue; | 533 | continue; |
@@ -503,7 +539,10 @@ static void u16_cs_chg_duplex(struct driver_data *drv_data) | |||
503 | drv_data->rx += 2; | 539 | drv_data->rx += 2; |
504 | drv_data->tx += 2; | 540 | drv_data->tx += 2; |
505 | } | 541 | } |
506 | cs_deactive(chip); | 542 | |
543 | /* poll for SPI completion before returning */ | ||
544 | while (!(read_STAT() & BIT_STAT_SPIF)) | ||
545 | continue; | ||
507 | } | 546 | } |
508 | 547 | ||
509 | /* test if ther is more transfer to be done */ | 548 | /* test if ther is more transfer to be done */ |
@@ -587,8 +626,6 @@ static irqreturn_t dma_irq_handler(int irq, void *dev_id) | |||
587 | while (!(read_STAT() & SPIF)) | 626 | while (!(read_STAT() & SPIF)) |
588 | continue; | 627 | continue; |
589 | 628 | ||
590 | bfin_spi_disable(drv_data); | ||
591 | |||
592 | msg->actual_length += drv_data->len_in_bytes; | 629 | msg->actual_length += drv_data->len_in_bytes; |
593 | 630 | ||
594 | if (drv_data->cs_change) | 631 | if (drv_data->cs_change) |
@@ -698,12 +735,8 @@ static void pump_transfers(unsigned long data) | |||
698 | message->state = RUNNING_STATE; | 735 | message->state = RUNNING_STATE; |
699 | dma_config = 0; | 736 | dma_config = 0; |
700 | 737 | ||
701 | /* restore spi status for each spi transfer */ | 738 | write_STAT(BIT_STAT_CLR); |
702 | if (transfer->speed_hz) { | 739 | cr = (read_CTRL() & (~BIT_CTL_TIMOD)); |
703 | write_BAUD(hz_to_spi_baud(transfer->speed_hz)); | ||
704 | } else { | ||
705 | write_BAUD(chip->baud); | ||
706 | } | ||
707 | cs_active(chip); | 740 | cs_active(chip); |
708 | 741 | ||
709 | dev_dbg(&drv_data->pdev->dev, | 742 | dev_dbg(&drv_data->pdev->dev, |
@@ -717,10 +750,8 @@ static void pump_transfers(unsigned long data) | |||
717 | */ | 750 | */ |
718 | if (drv_data->cur_chip->enable_dma && drv_data->len > 6) { | 751 | if (drv_data->cur_chip->enable_dma && drv_data->len > 6) { |
719 | 752 | ||
720 | write_STAT(BIT_STAT_CLR); | ||
721 | disable_dma(spi_dma_ch); | 753 | disable_dma(spi_dma_ch); |
722 | clear_dma_irqstat(spi_dma_ch); | 754 | clear_dma_irqstat(spi_dma_ch); |
723 | bfin_spi_disable(drv_data); | ||
724 | 755 | ||
725 | /* config dma channel */ | 756 | /* config dma channel */ |
726 | dev_dbg(&drv_data->pdev->dev, "doing dma transfer\n"); | 757 | dev_dbg(&drv_data->pdev->dev, "doing dma transfer\n"); |
@@ -734,14 +765,14 @@ static void pump_transfers(unsigned long data) | |||
734 | dma_width = WDSIZE_8; | 765 | dma_width = WDSIZE_8; |
735 | } | 766 | } |
736 | 767 | ||
737 | /* set transfer width,direction. And enable spi */ | ||
738 | cr = (read_CTRL() & (~BIT_CTL_TIMOD)); | ||
739 | |||
740 | /* dirty hack for autobuffer DMA mode */ | 768 | /* dirty hack for autobuffer DMA mode */ |
741 | if (drv_data->tx_dma == 0xFFFF) { | 769 | if (drv_data->tx_dma == 0xFFFF) { |
742 | dev_dbg(&drv_data->pdev->dev, | 770 | dev_dbg(&drv_data->pdev->dev, |
743 | "doing autobuffer DMA out.\n"); | 771 | "doing autobuffer DMA out.\n"); |
744 | 772 | ||
773 | /* set SPI transfer mode */ | ||
774 | write_CTRL(cr | CFG_SPI_DMAWRITE); | ||
775 | |||
745 | /* no irq in autobuffer mode */ | 776 | /* no irq in autobuffer mode */ |
746 | dma_config = | 777 | dma_config = |
747 | (DMAFLOW_AUTO | RESTART | dma_width | DI_EN); | 778 | (DMAFLOW_AUTO | RESTART | dma_width | DI_EN); |
@@ -749,8 +780,6 @@ static void pump_transfers(unsigned long data) | |||
749 | set_dma_start_addr(spi_dma_ch, | 780 | set_dma_start_addr(spi_dma_ch, |
750 | (unsigned long)drv_data->tx); | 781 | (unsigned long)drv_data->tx); |
751 | enable_dma(spi_dma_ch); | 782 | enable_dma(spi_dma_ch); |
752 | write_CTRL(cr | CFG_SPI_DMAWRITE | (width << 8) | | ||
753 | (CFG_SPI_ENABLE << 14)); | ||
754 | 783 | ||
755 | /* just return here, there can only be one transfer in this mode */ | 784 | /* just return here, there can only be one transfer in this mode */ |
756 | message->status = 0; | 785 | message->status = 0; |
@@ -763,11 +792,11 @@ static void pump_transfers(unsigned long data) | |||
763 | /* set transfer mode, and enable SPI */ | 792 | /* set transfer mode, and enable SPI */ |
764 | dev_dbg(&drv_data->pdev->dev, "doing DMA in.\n"); | 793 | dev_dbg(&drv_data->pdev->dev, "doing DMA in.\n"); |
765 | 794 | ||
766 | /* disable SPI before write to TDBR */ | 795 | /* set SPI transfer mode */ |
767 | write_CTRL(cr & ~BIT_CTL_ENABLE); | 796 | write_CTRL(cr | CFG_SPI_DMAREAD); |
768 | 797 | ||
769 | /* clear tx reg soformer data is not shifted out */ | 798 | /* clear tx reg soformer data is not shifted out */ |
770 | write_TDBR(0xFF); | 799 | write_TDBR(0xFFFF); |
771 | 800 | ||
772 | set_dma_x_count(spi_dma_ch, drv_data->len); | 801 | set_dma_x_count(spi_dma_ch, drv_data->len); |
773 | 802 | ||
@@ -779,14 +808,12 @@ static void pump_transfers(unsigned long data) | |||
779 | (unsigned long)drv_data->rx); | 808 | (unsigned long)drv_data->rx); |
780 | enable_dma(spi_dma_ch); | 809 | enable_dma(spi_dma_ch); |
781 | 810 | ||
782 | cr |= | ||
783 | CFG_SPI_DMAREAD | (width << 8) | (CFG_SPI_ENABLE << | ||
784 | 14); | ||
785 | /* set transfer mode, and enable SPI */ | ||
786 | write_CTRL(cr); | ||
787 | } else if (drv_data->tx != NULL) { | 811 | } else if (drv_data->tx != NULL) { |
788 | dev_dbg(&drv_data->pdev->dev, "doing DMA out.\n"); | 812 | dev_dbg(&drv_data->pdev->dev, "doing DMA out.\n"); |
789 | 813 | ||
814 | /* set SPI transfer mode */ | ||
815 | write_CTRL(cr | CFG_SPI_DMAWRITE); | ||
816 | |||
790 | /* start dma */ | 817 | /* start dma */ |
791 | dma_enable_irq(spi_dma_ch); | 818 | dma_enable_irq(spi_dma_ch); |
792 | dma_config = (RESTART | dma_width | DI_EN); | 819 | dma_config = (RESTART | dma_width | DI_EN); |
@@ -794,28 +821,20 @@ static void pump_transfers(unsigned long data) | |||
794 | set_dma_start_addr(spi_dma_ch, | 821 | set_dma_start_addr(spi_dma_ch, |
795 | (unsigned long)drv_data->tx); | 822 | (unsigned long)drv_data->tx); |
796 | enable_dma(spi_dma_ch); | 823 | enable_dma(spi_dma_ch); |
797 | |||
798 | write_CTRL(cr | CFG_SPI_DMAWRITE | (width << 8) | | ||
799 | (CFG_SPI_ENABLE << 14)); | ||
800 | |||
801 | } | 824 | } |
802 | } else { | 825 | } else { |
803 | /* IO mode write then read */ | 826 | /* IO mode write then read */ |
804 | dev_dbg(&drv_data->pdev->dev, "doing IO transfer\n"); | 827 | dev_dbg(&drv_data->pdev->dev, "doing IO transfer\n"); |
805 | 828 | ||
806 | write_STAT(BIT_STAT_CLR); | ||
807 | |||
808 | if (drv_data->tx != NULL && drv_data->rx != NULL) { | 829 | if (drv_data->tx != NULL && drv_data->rx != NULL) { |
809 | /* full duplex mode */ | 830 | /* full duplex mode */ |
810 | BUG_ON((drv_data->tx_end - drv_data->tx) != | 831 | BUG_ON((drv_data->tx_end - drv_data->tx) != |
811 | (drv_data->rx_end - drv_data->rx)); | 832 | (drv_data->rx_end - drv_data->rx)); |
812 | cr = (read_CTRL() & (~BIT_CTL_TIMOD)); | ||
813 | cr |= CFG_SPI_WRITE | (width << 8) | | ||
814 | (CFG_SPI_ENABLE << 14); | ||
815 | dev_dbg(&drv_data->pdev->dev, | 833 | dev_dbg(&drv_data->pdev->dev, |
816 | "IO duplex: cr is 0x%x\n", cr); | 834 | "IO duplex: cr is 0x%x\n", cr); |
817 | 835 | ||
818 | write_CTRL(cr); | 836 | /* set SPI transfer mode */ |
837 | write_CTRL(cr | CFG_SPI_WRITE); | ||
819 | 838 | ||
820 | drv_data->duplex(drv_data); | 839 | drv_data->duplex(drv_data); |
821 | 840 | ||
@@ -823,13 +842,11 @@ static void pump_transfers(unsigned long data) | |||
823 | tranf_success = 0; | 842 | tranf_success = 0; |
824 | } else if (drv_data->tx != NULL) { | 843 | } else if (drv_data->tx != NULL) { |
825 | /* write only half duplex */ | 844 | /* write only half duplex */ |
826 | cr = (read_CTRL() & (~BIT_CTL_TIMOD)); | ||
827 | cr |= CFG_SPI_WRITE | (width << 8) | | ||
828 | (CFG_SPI_ENABLE << 14); | ||
829 | dev_dbg(&drv_data->pdev->dev, | 845 | dev_dbg(&drv_data->pdev->dev, |
830 | "IO write: cr is 0x%x\n", cr); | 846 | "IO write: cr is 0x%x\n", cr); |
831 | 847 | ||
832 | write_CTRL(cr); | 848 | /* set SPI transfer mode */ |
849 | write_CTRL(cr | CFG_SPI_WRITE); | ||
833 | 850 | ||
834 | drv_data->write(drv_data); | 851 | drv_data->write(drv_data); |
835 | 852 | ||
@@ -837,13 +854,11 @@ static void pump_transfers(unsigned long data) | |||
837 | tranf_success = 0; | 854 | tranf_success = 0; |
838 | } else if (drv_data->rx != NULL) { | 855 | } else if (drv_data->rx != NULL) { |
839 | /* read only half duplex */ | 856 | /* read only half duplex */ |
840 | cr = (read_CTRL() & (~BIT_CTL_TIMOD)); | ||
841 | cr |= CFG_SPI_READ | (width << 8) | | ||
842 | (CFG_SPI_ENABLE << 14); | ||
843 | dev_dbg(&drv_data->pdev->dev, | 857 | dev_dbg(&drv_data->pdev->dev, |
844 | "IO read: cr is 0x%x\n", cr); | 858 | "IO read: cr is 0x%x\n", cr); |
845 | 859 | ||
846 | write_CTRL(cr); | 860 | /* set SPI transfer mode */ |
861 | write_CTRL(cr | CFG_SPI_READ); | ||
847 | 862 | ||
848 | drv_data->read(drv_data); | 863 | drv_data->read(drv_data); |
849 | if (drv_data->rx != drv_data->rx_end) | 864 | if (drv_data->rx != drv_data->rx_end) |
@@ -858,9 +873,6 @@ static void pump_transfers(unsigned long data) | |||
858 | /* Update total byte transfered */ | 873 | /* Update total byte transfered */ |
859 | message->actual_length += drv_data->len; | 874 | message->actual_length += drv_data->len; |
860 | 875 | ||
861 | if (drv_data->cs_change) | ||
862 | cs_deactive(chip); | ||
863 | |||
864 | /* Move to next transfer of this msg */ | 876 | /* Move to next transfer of this msg */ |
865 | message->state = next_transfer(drv_data); | 877 | message->state = next_transfer(drv_data); |
866 | } | 878 | } |