* [U-Boot] [PATCH] spi: soft_spi: Support NULL din/dout buffers
@ 2013-10-23 0:11 Andrew Ruder
2014-01-08 12:41 ` Jagan Teki
0 siblings, 1 reply; 2+ messages in thread
From: Andrew Ruder @ 2013-10-23 0:11 UTC (permalink / raw)
To: u-boot
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>
---
drivers/spi/soft_spi.c | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
diff --git a/drivers/spi/soft_spi.c b/drivers/spi/soft_spi.c
index 5d22351..5fdd091 100644
--- a/drivers/spi/soft_spi.c
+++ b/drivers/spi/soft_spi.c
@@ -137,9 +137,15 @@ 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 (txd) {
+ tmpdout = *txd++;
+ } else {
+ tmpdout = 0;
+ }
if(j != 0) {
- *rxd++ = tmpdin;
+ if (rxd) {
+ *rxd++ = tmpdin;
+ }
}
tmpdin = 0;
}
@@ -164,9 +170,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);
--
1.8.4.rc3
^ permalink raw reply related [flat|nested] 2+ messages in thread* [U-Boot] [PATCH] spi: soft_spi: Support NULL din/dout buffers
2013-10-23 0:11 [U-Boot] [PATCH] spi: soft_spi: Support NULL din/dout buffers Andrew Ruder
@ 2014-01-08 12:41 ` Jagan Teki
0 siblings, 0 replies; 2+ messages in thread
From: Jagan Teki @ 2014-01-08 12:41 UTC (permalink / raw)
To: u-boot
Hi Andrew Ruder,
On Wed, Oct 23, 2013 at 5:41 AM, Andrew Ruder
<andrew.ruder@elecsyscorp.com> wrote:
> 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>
> ---
> drivers/spi/soft_spi.c | 18 +++++++++++++-----
> 1 file changed, 13 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/spi/soft_spi.c b/drivers/spi/soft_spi.c
> index 5d22351..5fdd091 100644
> --- a/drivers/spi/soft_spi.c
> +++ b/drivers/spi/soft_spi.c
> @@ -137,9 +137,15 @@ 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 (txd) {
> + tmpdout = *txd++;
> + } else {
> + tmpdout = 0;
> + }
> if(j != 0) {
> - *rxd++ = tmpdin;
> + if (rxd) {
> + *rxd++ = tmpdin;
> + }
> }
> tmpdin = 0;
> }
> @@ -164,9 +170,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);
> --
I'm not sure does this NULL buf config stuff will works all boards as
you listed.
I guess ie the reason the earlier code doesn't have this.
Does this tested on your board? any possibility to test others too.
Jean-Christophe, any comments here!
--
Thanks,
Jagan.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-01-08 12:41 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-10-23 0:11 [U-Boot] [PATCH] spi: soft_spi: Support NULL din/dout buffers Andrew Ruder
2014-01-08 12:41 ` Jagan Teki
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox