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 <[EMAIL PROTECTED]>
---
 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

_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

Reply via email to