aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/spi/spi-sh-msiof.c
diff options
context:
space:
mode:
authorGeert Uytterhoeven <geert+renesas@glider.be>2014-06-20 06:16:19 -0400
committerMark Brown <broonie@linaro.org>2014-06-21 06:17:36 -0400
commit0312d59130693adad85c2acfbc0b92a669930a41 (patch)
treead8fb52e592797d21f69fd44f773a22d9370ab5c /drivers/spi/spi-sh-msiof.c
parent75b82e23a4ea20a9e1a48695ff5e01761889dbb3 (diff)
spi: sh-msiof: Refactor sh_msiof_transfer_one()
- Move buffer pointer and length setup to the top, - Make unsigned values unsigned, - Loop over words and increment pointers instead of recalculating them, which allows to kill bytes_done. 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.c43
1 files changed, 21 insertions, 22 deletions
diff --git a/drivers/spi/spi-sh-msiof.c b/drivers/spi/spi-sh-msiof.c
index e5894a65c797..824f44e6bd88 100644
--- a/drivers/spi/spi-sh-msiof.c
+++ b/drivers/spi/spi-sh-msiof.c
@@ -616,16 +616,17 @@ static int sh_msiof_transfer_one(struct spi_master *master,
616 struct sh_msiof_spi_priv *p = spi_master_get_devdata(master); 616 struct sh_msiof_spi_priv *p = spi_master_get_devdata(master);
617 void (*tx_fifo)(struct sh_msiof_spi_priv *, const void *, int, int); 617 void (*tx_fifo)(struct sh_msiof_spi_priv *, const void *, int, int);
618 void (*rx_fifo)(struct sh_msiof_spi_priv *, void *, int, int); 618 void (*rx_fifo)(struct sh_msiof_spi_priv *, void *, int, int);
619 int bits; 619 const void *tx_buf = t->tx_buf;
620 int bytes_per_word; 620 void *rx_buf = t->rx_buf;
621 int bytes_done; 621 unsigned int len = t->len;
622 int words; 622 unsigned int bits = t->bits_per_word;
623 unsigned int bytes_per_word;
624 unsigned int words;
623 int n; 625 int n;
624 bool swab; 626 bool swab;
625 627
626 bits = t->bits_per_word;
627 628
628 if (bits <= 8 && t->len > 15 && !(t->len & 3)) { 629 if (bits <= 8 && len > 15 && !(len & 3)) {
629 bits = 32; 630 bits = 32;
630 swab = true; 631 swab = true;
631 } else { 632 } else {
@@ -639,34 +640,34 @@ static int sh_msiof_transfer_one(struct spi_master *master,
639 rx_fifo = sh_msiof_spi_read_fifo_8; 640 rx_fifo = sh_msiof_spi_read_fifo_8;
640 } else if (bits <= 16) { 641 } else if (bits <= 16) {
641 bytes_per_word = 2; 642 bytes_per_word = 2;
642 if ((unsigned long)t->tx_buf & 0x01) 643 if ((unsigned long)tx_buf & 0x01)
643 tx_fifo = sh_msiof_spi_write_fifo_16u; 644 tx_fifo = sh_msiof_spi_write_fifo_16u;
644 else 645 else
645 tx_fifo = sh_msiof_spi_write_fifo_16; 646 tx_fifo = sh_msiof_spi_write_fifo_16;
646 647
647 if ((unsigned long)t->rx_buf & 0x01) 648 if ((unsigned long)rx_buf & 0x01)
648 rx_fifo = sh_msiof_spi_read_fifo_16u; 649 rx_fifo = sh_msiof_spi_read_fifo_16u;
649 else 650 else
650 rx_fifo = sh_msiof_spi_read_fifo_16; 651 rx_fifo = sh_msiof_spi_read_fifo_16;
651 } else if (swab) { 652 } else if (swab) {
652 bytes_per_word = 4; 653 bytes_per_word = 4;
653 if ((unsigned long)t->tx_buf & 0x03) 654 if ((unsigned long)tx_buf & 0x03)
654 tx_fifo = sh_msiof_spi_write_fifo_s32u; 655 tx_fifo = sh_msiof_spi_write_fifo_s32u;
655 else 656 else
656 tx_fifo = sh_msiof_spi_write_fifo_s32; 657 tx_fifo = sh_msiof_spi_write_fifo_s32;
657 658
658 if ((unsigned long)t->rx_buf & 0x03) 659 if ((unsigned long)rx_buf & 0x03)
659 rx_fifo = sh_msiof_spi_read_fifo_s32u; 660 rx_fifo = sh_msiof_spi_read_fifo_s32u;
660 else 661 else
661 rx_fifo = sh_msiof_spi_read_fifo_s32; 662 rx_fifo = sh_msiof_spi_read_fifo_s32;
662 } else { 663 } else {
663 bytes_per_word = 4; 664 bytes_per_word = 4;
664 if ((unsigned long)t->tx_buf & 0x03) 665 if ((unsigned long)tx_buf & 0x03)
665 tx_fifo = sh_msiof_spi_write_fifo_32u; 666 tx_fifo = sh_msiof_spi_write_fifo_32u;
666 else 667 else
667 tx_fifo = sh_msiof_spi_write_fifo_32; 668 tx_fifo = sh_msiof_spi_write_fifo_32;
668 669
669 if ((unsigned long)t->rx_buf & 0x03) 670 if ((unsigned long)rx_buf & 0x03)
670 rx_fifo = sh_msiof_spi_read_fifo_32u; 671 rx_fifo = sh_msiof_spi_read_fifo_32u;
671 else 672 else
672 rx_fifo = sh_msiof_spi_read_fifo_32; 673 rx_fifo = sh_msiof_spi_read_fifo_32;
@@ -676,20 +677,18 @@ static int sh_msiof_transfer_one(struct spi_master *master,
676 sh_msiof_spi_set_clk_regs(p, clk_get_rate(p->clk), t->speed_hz); 677 sh_msiof_spi_set_clk_regs(p, clk_get_rate(p->clk), t->speed_hz);
677 678
678 /* transfer in fifo sized chunks */ 679 /* transfer in fifo sized chunks */
679 words = t->len / bytes_per_word; 680 words = len / bytes_per_word;
680 bytes_done = 0; 681
681 682 while (words > 0) {
682 while (bytes_done < t->len) { 683 n = sh_msiof_spi_txrx_once(p, tx_fifo, rx_fifo, tx_buf, rx_buf,
683 void *rx_buf = t->rx_buf ? t->rx_buf + bytes_done : NULL;
684 const void *tx_buf = t->tx_buf ? t->tx_buf + bytes_done : NULL;
685 n = sh_msiof_spi_txrx_once(p, tx_fifo, rx_fifo,
686 tx_buf,
687 rx_buf,
688 words, bits); 684 words, bits);
689 if (n < 0) 685 if (n < 0)
690 return n; 686 return n;
691 687
692 bytes_done += n * bytes_per_word; 688 if (tx_buf)
689 tx_buf += n * bytes_per_word;
690 if (rx_buf)
691 rx_buf += n * bytes_per_word;
693 words -= n; 692 words -= n;
694 } 693 }
695 694