public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] command "sspi": add write-only flag '.w' (discard read data)
@ 2011-07-16 17:32 Andreas Pretzsch
  2011-07-18 17:49 ` Mike Frysinger
  0 siblings, 1 reply; 7+ messages in thread
From: Andreas Pretzsch @ 2011-07-16 17:32 UTC (permalink / raw)
  To: u-boot

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@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

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2011-07-22 19:07 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-07-16 17:32 [U-Boot] [PATCH] command "sspi": add write-only flag '.w' (discard read data) Andreas Pretzsch
2011-07-18 17:49 ` Mike Frysinger
2011-07-20 17:04   ` Andreas Pretzsch
2011-07-21  1:27     ` Mike Frysinger
2011-07-21  9:01       ` Detlev Zundel
2011-07-22 18:02         ` Andreas Pretzsch
2011-07-22 19:07           ` Mike Frysinger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox