[U-Boot] [PATCH] command "sspi": add write-only flag '.w' (discard read data)

Andreas Pretzsch apr at cn-eng.de
Sat Jul 16 19:32:06 CEST 2011


The sspi command writes the given data out on SPI and prints the data it
reads to the console. For write-only slaves (i.e. a SPI-connected latch
used as output expander), this is pointless and clutters the console.
When called as "sspi.w", this output is omitted.

The flag is optional and backwards compatible, previous sspi revisions
would simply ignore the flag (checked back to 2011.03).

Signed-off-by: Andreas Pretzsch <apr at cn-eng.de>
---
Data size (number of bits) are passed as separate parameter to sspi,
hence .w is "free" and not used as data size anyway.
---
 common/cmd_spi.c |   16 ++++++++++++----
 1 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/common/cmd_spi.c b/common/cmd_spi.c
index 8c623c9..c56c191 100644
--- a/common/cmd_spi.c
+++ b/common/cmd_spi.c
@@ -72,12 +72,17 @@ int do_spi (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 	uchar tmp;
 	int   j;
 	int   rcode = 0;
+	int   write_only = 0;
 
 	/*
 	 * We use the last specified parameters, unless new ones are
 	 * entered.
 	 */
 
+	j = strlen(argv[0]);
+	if (j > 2 && argv[0][j-2] == '.' && argv[0][j-1] == 'w')
+		write_only = 1;
+
 	if ((flag & CMD_FLAG_REPEAT) == 0)
 	{
 		if (argc >= 2) {
@@ -131,10 +136,12 @@ int do_spi (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 		printf("Error during SPI transaction\n");
 		rcode = 1;
 	} else {
-		for(j = 0; j < ((bitlen + 7) / 8); j++) {
-			printf("%02X", din[j]);
+		if (!write_only) {
+			/* dump read values to console */
+			for (j = 0; j < ((bitlen + 7) / 8); j++)
+				printf("%02X", din[j]);
+			printf("\n");
 		}
-		printf("\n");
 	}
 	spi_release_bus(slave);
 	spi_free_slave(slave);
@@ -147,7 +154,8 @@ int do_spi (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 U_BOOT_CMD(
 	sspi,	5,	1,	do_spi,
 	"SPI utility command",
-	"[<bus>:]<cs>[.<mode>] <bit_len> <dout> - Send and receive bits\n"
+	"[.w] [<bus>:]<cs>[.<mode>] <bit_len> <dout> - Send and receive bits\n"
+	".w        - write only => don't print read result\n"
 	"<bus>     - Identifies the SPI bus\n"
 	"<cs>      - Identifies the chip select\n"
 	"<mode>    - Identifies the SPI mode to use\n"
-- 
1.7.5.4



More information about the U-Boot mailing list