All of lore.kernel.org
 help / color / mirror / Atom feed
From: Matthias Fuchs <matthias.fuchs@esd.eu>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH V3 4/6] sf command: allow default chip select through CONFIG_SPI_FLASH_CS
Date: Wed, 25 Jan 2012 16:10:18 +0100	[thread overview]
Message-ID: <4F201B5A.4010500@esd.eu> (raw)
In-Reply-To: <1327421904-21487-5-git-send-email-eric.nelson@boundarydevices.com>

Hi Eric,

please see my comments below.

On 24.01.2012 17:18, Eric Nelson wrote:
> This patch allows a board configuration file to provide a default 
> chip-select for serial 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>
> Acked-by: Dirk Behme <dirk.behme@de.bosch.com> 
> Acked-by: Stefano Babic <sbabic@denx.de>
> ---
>  common/cmd_sf.c |   34 +++++++++++++++++++++++-----------
>  1 files changed, 23 insertions(+), 11 deletions(-)
> 
> diff --git a/common/cmd_sf.c b/common/cmd_sf.c
> index 7225656..4b32171 100644
> --- a/common/cmd_sf.c
> +++ b/common/cmd_sf.c
> @@ -70,20 +70,28 @@ static int do_spi_flash_probe(int argc, char * const argv[])
>  	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 != ':'))
> +#ifndef CONFIG_SPI_FLASH_CS
> +	if (argc < 2) {
> +		printf("%s: missing arguments\n", __func__);
I think this format for the error message is a little bit untypical for
u-boot. We do not show up the internal C function name. Better would be
to show the command usage, right?

>  		return -1;
> -	if (*endp == ':') {
> -		if (endp[1] == 0)
> -			return -1;
> +	}
> +#else
> +	cs = CONFIG_SPI_FLASH_CS ;
Other options for the spi flash subsystem are called
CONFIG_SF_DEFAULT_MODE|SPEED. It think it make sense to call
this CONFIG_SF_DEFAULT_CS and CONFIG_SF_DEFAULT_BUS (see below).

> +#endif
>  
> -		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 +307,11 @@ usage:
>  U_BOOT_CMD(
>  	sf,	5,	1,	do_spi_flash,
>  	"SPI flash sub-system",
> +#ifndef CONFIG_SPI_FLASH_CS
>  	"probe [bus:]cs [hz] [mode]	- init flash device on given SPI bus\n"
> +#else
> +	"probe [[bus:]cs] [hz] [mode]	- init flash device on given SPI bus\n"
> +#endif
>  	"				  and chip select\n"
>  	"sf read addr offset len 	- read `len' bytes starting at\n"
>  	"				  `offset' to memory at `addr'\n"
Can you also add a config option for the SPI bus number? I think these
two need to handled in the same patch.

So you could add this stuff:

diff --git a/common/cmd_sf.c b/common/cmd_sf.c
index 9e97c8e..fa4312a 100644
--- a/common/cmd_sf.c
+++ b/common/cmd_sf.c
@@ -63,7 +63,11 @@ static int sf_parse_len_arg(char *arg, ulong *len)

 static int do_spi_flash_probe(int argc, char * const argv[])
 {
+#ifdef CONFIG_SF_DEFAULT_BUS
+       unsigned int bus = CONFIG_SF_DEFAULT_BUS;
+#else
        unsigned int bus = 0;
+#endif
        unsigned int cs;
        unsigned int speed = CONFIG_SF_DEFAULT_SPEED;
        unsigned int mode = CONFIG_SF_DEFAULT_MODE;

Matthias

  parent reply	other threads:[~2012-01-25 15:10 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-24 16:18 [U-Boot] [PATCH V3 0/6] mxc_spi refactoring (for mx6q and mx6qsabrelite) Eric Nelson
2012-01-24 16:18 ` [U-Boot] [PATCH V3 1/6] mxc_spi: move machine specifics into CPU headers Eric Nelson
2012-01-24 16:18 ` [U-Boot] [PATCH V3 2/6] mx6q: Add support for ECSPI through mxc_spi driver Eric Nelson
2012-01-24 16:18 ` [U-Boot] [PATCH V3 3/6] mx6q: mx6qsabrelite: Add ECSPI support to the Sabrelite platform Eric Nelson
2012-01-24 16:18 ` [U-Boot] [PATCH V3 4/6] sf command: allow default chip select through CONFIG_SPI_FLASH_CS Eric Nelson
2012-01-24 16:27   ` Fabio Estevam
2012-01-24 18:08   ` Mike Frysinger
2012-01-27  1:22     ` Eric Nelson
2012-01-27  2:50       ` Mike Frysinger
2012-01-27 13:39         ` Eric Nelson
2012-01-25 15:10   ` Matthias Fuchs [this message]
2012-01-25 19:10     ` Mike Frysinger
2012-01-27  1:36     ` Eric Nelson
2012-01-27  2:52       ` Mike Frysinger
2012-01-24 16:18 ` [U-Boot] [PATCH V3 5/6] mx6q: mx6qsabrelite: Provide default chip-select for serial flash Eric Nelson
2012-01-24 16:18 ` [U-Boot] [PATCH V3 6/6] mx6q: mx6qsabrelite: Conditionally define macros for environment in " Eric Nelson

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=4F201B5A.4010500@esd.eu \
    --to=matthias.fuchs@esd.eu \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.