aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/spi/spi.c
diff options
context:
space:
mode:
authorDavid Brownell <dbrownell@users.sourceforge.net>2009-04-13 17:39:57 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2009-04-13 18:04:30 -0400
commitbdff549ebeff92b1a6952e5501caf16a6f8898c8 (patch)
tree3cebe8c0f7b26433e42832a6feb50fd6e4de75b7 /drivers/spi/spi.c
parent0769c2981495c3d05429840d6fc7a1b5e26accaa (diff)
spi: spi_write_then_read() bugfixes
The "simplify spi_write_then_read()" patch included two regressions from the 2.6.27 behaviors: - The data it wrote out during the (full duplex) read side of the transfer was not zeroed. - It fails completely on half duplex hardware, such as Microwire and most "3-wire" SPI variants. So, revert that patch. A revised version should be submitted at some point, which can get the speedup on standard hardware (full duplex) without breaking on less-capable half-duplex stuff. Signed-off-by: David Brownell <dbrownell@users.sourceforge.net> Cc: <stable@kernel.org> [2.6.28.x, 2.6.29.x] Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/spi/spi.c')
-rw-r--r--drivers/spi/spi.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 643908b74bc0..8eba98c8ed1e 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -658,7 +658,7 @@ int spi_write_then_read(struct spi_device *spi,
658 658
659 int status; 659 int status;
660 struct spi_message message; 660 struct spi_message message;
661 struct spi_transfer x; 661 struct spi_transfer x[2];
662 u8 *local_buf; 662 u8 *local_buf;
663 663
664 /* Use preallocated DMA-safe buffer. We can't avoid copying here, 664 /* Use preallocated DMA-safe buffer. We can't avoid copying here,
@@ -669,9 +669,15 @@ int spi_write_then_read(struct spi_device *spi,
669 return -EINVAL; 669 return -EINVAL;
670 670
671 spi_message_init(&message); 671 spi_message_init(&message);
672 memset(&x, 0, sizeof x); 672 memset(x, 0, sizeof x);
673 x.len = n_tx + n_rx; 673 if (n_tx) {
674 spi_message_add_tail(&x, &message); 674 x[0].len = n_tx;
675 spi_message_add_tail(&x[0], &message);
676 }
677 if (n_rx) {
678 x[1].len = n_rx;
679 spi_message_add_tail(&x[1], &message);
680 }
675 681
676 /* ... unless someone else is using the pre-allocated buffer */ 682 /* ... unless someone else is using the pre-allocated buffer */
677 if (!mutex_trylock(&lock)) { 683 if (!mutex_trylock(&lock)) {
@@ -682,15 +688,15 @@ int spi_write_then_read(struct spi_device *spi,
682 local_buf = buf; 688 local_buf = buf;
683 689
684 memcpy(local_buf, txbuf, n_tx); 690 memcpy(local_buf, txbuf, n_tx);
685 x.tx_buf = local_buf; 691 x[0].tx_buf = local_buf;
686 x.rx_buf = local_buf; 692 x[1].rx_buf = local_buf + n_tx;
687 693
688 /* do the i/o */ 694 /* do the i/o */
689 status = spi_sync(spi, &message); 695 status = spi_sync(spi, &message);
690 if (status == 0) 696 if (status == 0)
691 memcpy(rxbuf, x.rx_buf + n_tx, n_rx); 697 memcpy(rxbuf, x[1].rx_buf, n_rx);
692 698
693 if (x.tx_buf == buf) 699 if (x[0].tx_buf == buf)
694 mutex_unlock(&lock); 700 mutex_unlock(&lock);
695 else 701 else
696 kfree(local_buf); 702 kfree(local_buf);