aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorVernon Sauder <vernoninhand@gmail.com>2008-10-16 01:02:40 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2008-10-16 14:21:38 -0400
commitf9b90e39cbc5c4d6ef60022fd1f25d541df0aad1 (patch)
treeaf043fc4e24a12447c7312ef9b246f24d619f6f7 /drivers
parent62f9e8f15a95822e0a793090ff69b277690c6aa6 (diff)
spi: simplify spi_write_then_read()
Modify spi_write_then_read() to use one transfer. This speeds up all callers, and is a minor code shrink. Signed-off-by: Vernon Sauder <Vernon.Sauder@gmail.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.c22
1 files changed, 8 insertions, 14 deletions
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 75e86865234c..2de6b0e72f3f 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -660,7 +660,7 @@ int spi_write_then_read(struct spi_device *spi,
660 660
661 int status; 661 int status;
662 struct spi_message message; 662 struct spi_message message;
663 struct spi_transfer x[2]; 663 struct spi_transfer x;
664 u8 *local_buf; 664 u8 *local_buf;
665 665
666 /* Use preallocated DMA-safe buffer. We can't avoid copying here, 666 /* Use preallocated DMA-safe buffer. We can't avoid copying here,
@@ -671,15 +671,9 @@ int spi_write_then_read(struct spi_device *spi,
671 return -EINVAL; 671 return -EINVAL;
672 672
673 spi_message_init(&message); 673 spi_message_init(&message);
674 memset(x, 0, sizeof x); 674 memset(&x, 0, sizeof x);
675 if (n_tx) { 675 x.len = n_tx + n_rx;
676 x[0].len = n_tx; 676 spi_message_add_tail(&x, &message);
677 spi_message_add_tail(&x[0], &message);
678 }
679 if (n_rx) {
680 x[1].len = n_rx;
681 spi_message_add_tail(&x[1], &message);
682 }
683 677
684 /* ... unless someone else is using the pre-allocated buffer */ 678 /* ... unless someone else is using the pre-allocated buffer */
685 if (!mutex_trylock(&lock)) { 679 if (!mutex_trylock(&lock)) {
@@ -690,15 +684,15 @@ int spi_write_then_read(struct spi_device *spi,
690 local_buf = buf; 684 local_buf = buf;
691 685
692 memcpy(local_buf, txbuf, n_tx); 686 memcpy(local_buf, txbuf, n_tx);
693 x[0].tx_buf = local_buf; 687 x.tx_buf = local_buf;
694 x[1].rx_buf = local_buf + n_tx; 688 x.rx_buf = local_buf;
695 689
696 /* do the i/o */ 690 /* do the i/o */
697 status = spi_sync(spi, &message); 691 status = spi_sync(spi, &message);
698 if (status == 0) 692 if (status == 0)
699 memcpy(rxbuf, x[1].rx_buf, n_rx); 693 memcpy(rxbuf, x.rx_buf + n_tx, n_rx);
700 694
701 if (x[0].tx_buf == buf) 695 if (x.tx_buf == buf)
702 mutex_unlock(&lock); 696 mutex_unlock(&lock);
703 else 697 else
704 kfree(local_buf); 698 kfree(local_buf);