diff options
author | Geert Uytterhoeven <geert+renesas@glider.be> | 2014-06-20 06:16:17 -0400 |
---|---|---|
committer | Mark Brown <broonie@linaro.org> | 2014-06-21 06:17:35 -0400 |
commit | 76c02e71612533206cb062b875c9609bce83d23a (patch) | |
tree | 33380eaf267c50a33dd6f11c640c2680df934596 /drivers/spi/spi-sh-msiof.c | |
parent | 2e2b36872d7b45b1f88a590283b14c67931b777f (diff) |
spi: sh-msiof: Extract sh_msiof_spi_{start,stop}() helpers
Based on an old patch by Guennadi Liakhovetski <g.liakhovetski@gmx.de>
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Signed-off-by: Mark Brown <broonie@linaro.org>
Diffstat (limited to 'drivers/spi/spi-sh-msiof.c')
-rw-r--r-- | drivers/spi/spi-sh-msiof.c | 51 |
1 files changed, 37 insertions, 14 deletions
diff --git a/drivers/spi/spi-sh-msiof.c b/drivers/spi/spi-sh-msiof.c index 38824a994131..2cd5fcb86f71 100644 --- a/drivers/spi/spi-sh-msiof.c +++ b/drivers/spi/spi-sh-msiof.c | |||
@@ -509,6 +509,40 @@ static int sh_msiof_prepare_message(struct spi_master *master, | |||
509 | return 0; | 509 | return 0; |
510 | } | 510 | } |
511 | 511 | ||
512 | static int sh_msiof_spi_start(struct sh_msiof_spi_priv *p, void *rx_buf) | ||
513 | { | ||
514 | int ret; | ||
515 | |||
516 | /* setup clock and rx/tx signals */ | ||
517 | ret = sh_msiof_modify_ctr_wait(p, 0, CTR_TSCKE); | ||
518 | if (rx_buf && !ret) | ||
519 | ret = sh_msiof_modify_ctr_wait(p, 0, CTR_RXE); | ||
520 | if (!ret) | ||
521 | ret = sh_msiof_modify_ctr_wait(p, 0, CTR_TXE); | ||
522 | |||
523 | /* start by setting frame bit */ | ||
524 | if (!ret) | ||
525 | ret = sh_msiof_modify_ctr_wait(p, 0, CTR_TFSE); | ||
526 | |||
527 | return ret; | ||
528 | } | ||
529 | |||
530 | static int sh_msiof_spi_stop(struct sh_msiof_spi_priv *p, void *rx_buf) | ||
531 | { | ||
532 | int ret; | ||
533 | |||
534 | /* shut down frame, rx/tx and clock signals */ | ||
535 | ret = sh_msiof_modify_ctr_wait(p, CTR_TFSE, 0); | ||
536 | if (!ret) | ||
537 | ret = sh_msiof_modify_ctr_wait(p, CTR_TXE, 0); | ||
538 | if (rx_buf && !ret) | ||
539 | ret = sh_msiof_modify_ctr_wait(p, CTR_RXE, 0); | ||
540 | if (!ret) | ||
541 | ret = sh_msiof_modify_ctr_wait(p, CTR_TSCKE, 0); | ||
542 | |||
543 | return ret; | ||
544 | } | ||
545 | |||
512 | static int sh_msiof_spi_txrx_once(struct sh_msiof_spi_priv *p, | 546 | static int sh_msiof_spi_txrx_once(struct sh_msiof_spi_priv *p, |
513 | void (*tx_fifo)(struct sh_msiof_spi_priv *, | 547 | void (*tx_fifo)(struct sh_msiof_spi_priv *, |
514 | const void *, int, int), | 548 | const void *, int, int), |
@@ -536,15 +570,9 @@ static int sh_msiof_spi_txrx_once(struct sh_msiof_spi_priv *p, | |||
536 | if (tx_buf) | 570 | if (tx_buf) |
537 | tx_fifo(p, tx_buf, words, fifo_shift); | 571 | tx_fifo(p, tx_buf, words, fifo_shift); |
538 | 572 | ||
539 | /* setup clock and rx/tx signals */ | ||
540 | ret = sh_msiof_modify_ctr_wait(p, 0, CTR_TSCKE); | ||
541 | if (rx_buf) | ||
542 | ret = ret ? ret : sh_msiof_modify_ctr_wait(p, 0, CTR_RXE); | ||
543 | ret = ret ? ret : sh_msiof_modify_ctr_wait(p, 0, CTR_TXE); | ||
544 | |||
545 | /* start by setting frame bit */ | ||
546 | reinit_completion(&p->done); | 573 | reinit_completion(&p->done); |
547 | ret = ret ? ret : sh_msiof_modify_ctr_wait(p, 0, CTR_TFSE); | 574 | |
575 | ret = sh_msiof_spi_start(p, rx_buf); | ||
548 | if (ret) { | 576 | if (ret) { |
549 | dev_err(&p->pdev->dev, "failed to start hardware\n"); | 577 | dev_err(&p->pdev->dev, "failed to start hardware\n"); |
550 | goto err; | 578 | goto err; |
@@ -560,12 +588,7 @@ static int sh_msiof_spi_txrx_once(struct sh_msiof_spi_priv *p, | |||
560 | /* clear status bits */ | 588 | /* clear status bits */ |
561 | sh_msiof_reset_str(p); | 589 | sh_msiof_reset_str(p); |
562 | 590 | ||
563 | /* shut down frame, rx/tx and clock signals */ | 591 | ret = sh_msiof_spi_stop(p, rx_buf); |
564 | ret = sh_msiof_modify_ctr_wait(p, CTR_TFSE, 0); | ||
565 | ret = ret ? ret : sh_msiof_modify_ctr_wait(p, CTR_TXE, 0); | ||
566 | if (rx_buf) | ||
567 | ret = ret ? ret : sh_msiof_modify_ctr_wait(p, CTR_RXE, 0); | ||
568 | ret = ret ? ret : sh_msiof_modify_ctr_wait(p, CTR_TSCKE, 0); | ||
569 | if (ret) { | 592 | if (ret) { |
570 | dev_err(&p->pdev->dev, "failed to shut down hardware\n"); | 593 | dev_err(&p->pdev->dev, "failed to shut down hardware\n"); |
571 | goto err; | 594 | goto err; |