public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Eric Nelson <eric.nelson@boundarydevices.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH V6 - Part 3 - 1/2] sf command: allow default bus and chip selects
Date: Tue, 31 Jan 2012 10:52:07 -0700	[thread overview]
Message-ID: <1328032330-20883-7-git-send-email-eric.nelson@boundarydevices.com> (raw)
In-Reply-To: <1328032330-20883-1-git-send-email-eric.nelson@boundarydevices.com>

This patch allows a board configuration file to provide default bus
and chip-selects for SPI flash so that first argument to the 'sf' command
is optional.

On boards that use the mxc_spi driver and a GPIO for chip select, this allows
a much simpler command line:
	U-Boot> sf probe
instead of
	U-Boot> sf probe 0x5300
Signed-off-by: Eric Nelson <eric.nelson@boundarydevices.com>
---
 common/cmd_sf.c |   37 +++++++++++++++++++++----------------
 1 files changed, 21 insertions(+), 16 deletions(-)

diff --git a/common/cmd_sf.c b/common/cmd_sf.c
index 612fd18..98e4162 100644
--- a/common/cmd_sf.c
+++ b/common/cmd_sf.c
@@ -17,6 +17,12 @@
 #ifndef CONFIG_SF_DEFAULT_MODE
 # define CONFIG_SF_DEFAULT_MODE		SPI_MODE_3
 #endif
+#ifndef CONFIG_SF_DEFAULT_CS
+# define CONFIG_SF_DEFAULT_CS		0
+#endif
+#ifndef CONFIG_SF_DEFAULT_BUS
+# define CONFIG_SF_DEFAULT_BUS		0
+#endif
 
 static struct spi_flash *flash;
 
@@ -63,27 +69,26 @@ static int sf_parse_len_arg(char *arg, ulong *len)
 
 static int do_spi_flash_probe(int argc, char * const argv[])
 {
-	unsigned int bus = 0;
-	unsigned int cs;
+	unsigned int bus = CONFIG_SF_DEFAULT_BUS;
+	unsigned int cs = CONFIG_SF_DEFAULT_CS;
 	unsigned int speed = CONFIG_SF_DEFAULT_SPEED;
 	unsigned int mode = CONFIG_SF_DEFAULT_MODE;
 	char *endp;
 	struct spi_flash *new;
 
-	if (argc < 2)
-		return -1;
-
-	cs = simple_strtoul(argv[1], &endp, 0);
-	if (*argv[1] == 0 || (*endp != 0 && *endp != ':'))
-		return -1;
-	if (*endp == ':') {
-		if (endp[1] == 0)
-			return -1;
-
-		bus = cs;
-		cs = simple_strtoul(endp + 1, &endp, 0);
-		if (*endp != 0)
+	if (argc >= 2) {
+		cs = simple_strtoul(argv[1], &endp, 0);
+		if (*argv[1] == 0 || (*endp != 0 && *endp != ':'))
 			return -1;
+		if (*endp == ':') {
+			if (endp[1] == 0)
+				return -1;
+
+			bus = cs;
+			cs = simple_strtoul(endp + 1, &endp, 0);
+			if (*endp != 0)
+				return -1;
+		}
 	}
 
 	if (argc >= 3) {
@@ -299,7 +304,7 @@ usage:
 U_BOOT_CMD(
 	sf,	5,	1,	do_spi_flash,
 	"SPI flash sub-system",
-	"probe [bus:]cs [hz] [mode]	- init flash device on given SPI bus\n"
+	"probe [[bus:]cs] [hz] [mode]	- init flash device on given SPI bus\n"
 	"				  and chip select\n"
 	"sf read addr offset len 	- read `len' bytes starting at\n"
 	"				  `offset' to memory at `addr'\n"
-- 
1.7.1

  parent reply	other threads:[~2012-01-31 17:52 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-31 17:52 [U-Boot] [PATCH V6 - Part 1 - 1/1] mx6q: define GPIO macros for translating between ordinals and port:index Eric Nelson
2012-01-31 17:52 ` [U-Boot] [PATCH V6 - Part 2 - 0/3] mxc_spi refactoring (for mx6q and mx6qsabrelite) Eric Nelson
2012-01-31 17:52 ` [U-Boot] [PATCH V6 - Part 2 - 1/3] mxc_spi: move machine specifics into CPU headers Eric Nelson
2012-02-01 11:23   ` Jason Hui
2012-02-08 11:23   ` Stefano Babic
2012-01-31 17:52 ` [U-Boot] [PATCH V6 - Part 2 - 2/3] mx6q: Add support for ECSPI through mxc_spi driver Eric Nelson
2012-02-01 11:24   ` Jason Hui
2012-02-08 11:23   ` Stefano Babic
2012-01-31 17:52 ` [U-Boot] [PATCH V6 - Part 2 - 3/3] mx6q: mx6qsabrelite: Add ECSPI support to the Sabrelite platform Eric Nelson
2012-02-01 11:25   ` Jason Hui
2012-02-08 11:23   ` Stefano Babic
2012-01-31 17:52 ` [U-Boot] [PATCH V6 - Part 3 - 0/2] SPI flash enhancements: allow default bus and chip-selects Eric Nelson
2012-01-31 18:11   ` Mike Frysinger
2012-01-31 19:14     ` Eric Nelson
2012-02-01 11:30       ` Stefano Babic
2012-02-01 11:35         ` Dirk Behme
2012-02-01 17:00         ` Mike Frysinger
2012-02-01 19:31           ` Eric Nelson
2012-02-01 21:04             ` Mike Frysinger
2012-02-02  9:18             ` Stefano Babic
2012-02-02 14:56               ` Eric Nelson
2012-02-02 16:32               ` Mike Frysinger
2012-02-03  9:27                 ` Stefano Babic
2012-02-09  6:40     ` Dirk Behme
2012-01-31 17:52 ` Eric Nelson [this message]
2012-02-01 11:26   ` [U-Boot] [PATCH V6 - Part 3 - 1/2] sf command: allow default bus and chip selects Jason Hui
2012-01-31 17:52 ` [U-Boot] [PATCH V6 - Part 2 - 2/2] README: Add description of SPI Flash (SF) command configuration Eric Nelson
2012-02-01 11:27   ` Jason Hui
2012-01-31 17:52 ` [U-Boot] [PATCH V6 - Part 4 - 1/1] mx6q: mx6qsabrelite: Provide default serial flash bus and chip-select Eric Nelson
2012-02-01 11:28   ` Jason Hui
2012-02-08 11:23   ` Stefano Babic
2012-01-31 17:52 ` [U-Boot] [PATCH V6 - Part 5 - 1/1] mx6q: mx6qsabrelite: Conditionally define macros for environment in serial flash Eric Nelson
2012-02-01 11:29   ` Jason Hui
2012-02-08 11:23   ` Stefano Babic
2012-02-08 11:23 ` [U-Boot] [PATCH V6 - Part 1 - 1/1] mx6q: define GPIO macros for translating between ordinals and port:index Stefano Babic

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1328032330-20883-7-git-send-email-eric.nelson@boundarydevices.com \
    --to=eric.nelson@boundarydevices.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox