diff options
author | Andrew Ruder <andrew.ruder@elecsyscorp.com> | 2014-04-24 13:39:32 -0500 |
---|---|---|
committer | Jagannadha Sutradharudu Teki <jaganna@xilinx.com> | 2014-06-08 23:12:27 +0530 |
commit | c1c0dd2644d6bdd64f5d36528d801d14832f6394 (patch) | |
tree | e00eeb8db9318ad294b18f9349a5fe60539d0975 /drivers/spi/soft_spi.c | |
parent | 04728086088e2dcc37ae0512a521246b21389838 (diff) | |
download | u-boot-imx-c1c0dd2644d6bdd64f5d36528d801d14832f6394.zip u-boot-imx-c1c0dd2644d6bdd64f5d36528d801d14832f6394.tar.gz u-boot-imx-c1c0dd2644d6bdd64f5d36528d801d14832f6394.tar.bz2 |
spi: soft_spi: Support NULL din/dout buffers
This mirrors the conventions used in other SPI drivers (kirkwood,
davinci, atmel, et al) where the din/dout buffer can be NULL when the
received/transmitted data isn't important. This reduces the need for
allocating additional buffers when write-only/read-only functionality is
needed.
In the din == NULL case, the received data is simply not stored. In the
dout == NULL case, zeroes are transmitted.
Signed-off-by: Andrew Ruder <andrew.ruder@elecsyscorp.com>
Cc: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Reviewed-by: Jagannadha Sutradharudu Teki <jaganna@xilinx.com>
Diffstat (limited to 'drivers/spi/soft_spi.c')
-rw-r--r-- | drivers/spi/soft_spi.c | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/drivers/spi/soft_spi.c b/drivers/spi/soft_spi.c index 5d22351..c969be3 100644 --- a/drivers/spi/soft_spi.c +++ b/drivers/spi/soft_spi.c @@ -136,10 +136,14 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen, /* * Check if it is time to work on a new byte. */ - if((j % 8) == 0) { - tmpdout = *txd++; + if ((j % 8) == 0) { + if (txd) + tmpdout = *txd++; + else + tmpdout = 0; if(j != 0) { - *rxd++ = tmpdin; + if (rxd) + *rxd++ = tmpdin; } tmpdin = 0; } @@ -164,9 +168,11 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen, * bits over to left-justify them. Then store the last byte * read in. */ - if((bitlen % 8) != 0) - tmpdin <<= 8 - (bitlen % 8); - *rxd++ = tmpdin; + if (rxd) { + if ((bitlen % 8) != 0) + tmpdin <<= 8 - (bitlen % 8); + *rxd++ = tmpdin; + } if (flags & SPI_XFER_END) spi_cs_deactivate(slave); |