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>
This commit is contained in:
committed by
Linus Torvalds
parent
62f9e8f15a
commit
f9b90e39cb
@@ -660,7 +660,7 @@ int spi_write_then_read(struct spi_device *spi,
|
|||||||
|
|
||||||
int status;
|
int status;
|
||||||
struct spi_message message;
|
struct spi_message message;
|
||||||
struct spi_transfer x[2];
|
struct spi_transfer x;
|
||||||
u8 *local_buf;
|
u8 *local_buf;
|
||||||
|
|
||||||
/* Use preallocated DMA-safe buffer. We can't avoid copying here,
|
/* Use preallocated DMA-safe buffer. We can't avoid copying here,
|
||||||
@@ -671,15 +671,9 @@ int spi_write_then_read(struct spi_device *spi,
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
spi_message_init(&message);
|
spi_message_init(&message);
|
||||||
memset(x, 0, sizeof x);
|
memset(&x, 0, sizeof x);
|
||||||
if (n_tx) {
|
x.len = n_tx + n_rx;
|
||||||
x[0].len = n_tx;
|
spi_message_add_tail(&x, &message);
|
||||||
spi_message_add_tail(&x[0], &message);
|
|
||||||
}
|
|
||||||
if (n_rx) {
|
|
||||||
x[1].len = n_rx;
|
|
||||||
spi_message_add_tail(&x[1], &message);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ... unless someone else is using the pre-allocated buffer */
|
/* ... unless someone else is using the pre-allocated buffer */
|
||||||
if (!mutex_trylock(&lock)) {
|
if (!mutex_trylock(&lock)) {
|
||||||
@@ -690,15 +684,15 @@ int spi_write_then_read(struct spi_device *spi,
|
|||||||
local_buf = buf;
|
local_buf = buf;
|
||||||
|
|
||||||
memcpy(local_buf, txbuf, n_tx);
|
memcpy(local_buf, txbuf, n_tx);
|
||||||
x[0].tx_buf = local_buf;
|
x.tx_buf = local_buf;
|
||||||
x[1].rx_buf = local_buf + n_tx;
|
x.rx_buf = local_buf;
|
||||||
|
|
||||||
/* do the i/o */
|
/* do the i/o */
|
||||||
status = spi_sync(spi, &message);
|
status = spi_sync(spi, &message);
|
||||||
if (status == 0)
|
if (status == 0)
|
||||||
memcpy(rxbuf, x[1].rx_buf, n_rx);
|
memcpy(rxbuf, x.rx_buf + n_tx, n_rx);
|
||||||
|
|
||||||
if (x[0].tx_buf == buf)
|
if (x.tx_buf == buf)
|
||||||
mutex_unlock(&lock);
|
mutex_unlock(&lock);
|
||||||
else
|
else
|
||||||
kfree(local_buf);
|
kfree(local_buf);
|
||||||
|
Reference in New Issue
Block a user