[U-Boot] [PATCH 4/6] spi: Add spi_xfer_single() convenience wrapper
Haavard Skinnemoen
haavard.skinnemoen at atmel.com
Tue Sep 2 11:20:52 CEST 2008
Quite often, you only want to do a single SPI transfer with chip select
toggling before and after. Add a simple convenience wrapper for this
purpose. For more "advanced" usage, the spi_xfer() function is still
available.
Signed-off-by: Haavard Skinnemoen <haavard.skinnemoen at atmel.com>
---
include/spi.h | 15 ++++++++++++++-
1 files changed, 14 insertions(+), 1 deletions(-)
diff --git a/include/spi.h b/include/spi.h
index 320e50e..be87173 100644
--- a/include/spi.h
+++ b/include/spi.h
@@ -176,6 +176,19 @@ void spi_cs_activate(struct spi_slave *slave);
void spi_cs_deactivate(struct spi_slave *slave);
/*-----------------------------------------------------------------------
+ * Single SPI Transfer
+ *
+ * Convenience wrapper for doing a single SPI transfer, i.e. asserting
+ * CS before, and deasserting it after the transfer.
+ */
+static inline int spi_xfer_single(struct spi_slave *slave,
+ unsigned int bitlen, const void *dout, void *din)
+{
+ return spi_xfer(slave, bitlen, dout, din,
+ SPI_XFER_BEGIN | SPI_XFER_END);
+}
+
+/*-----------------------------------------------------------------------
* Write 8 bits, then read 8 bits.
* slave: The SPI slave we're communicating with
* byte: Byte to be written
@@ -193,7 +206,7 @@ static inline int spi_w8r8(struct spi_slave *slave, unsigned char byte)
dout[0] = byte;
dout[1] = 0;
- ret = spi_xfer(slave, 16, dout, din, SPI_XFER_BEGIN | SPI_XFER_END);
+ ret = spi_xfer_single(slave, 16, dout, din);
return ret < 0 ? ret : din[1];
}
--
1.5.6.3
More information about the U-Boot
mailing list