From patchwork Tue Jan 31 17:52:07 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Nelson X-Patchwork-Id: 138823 X-Patchwork-Delegate: vapier@gentoo.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 024E11007D1 for ; Wed, 1 Feb 2012 04:52:54 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id A6205280D8; Tue, 31 Jan 2012 18:52:48 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id X5BQJW62GwZv; Tue, 31 Jan 2012 18:52:48 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id EF231280E1; Tue, 31 Jan 2012 18:52:35 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 18FCB280D2 for ; Tue, 31 Jan 2012 18:52:28 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Z43PZgIGWZKL for ; Tue, 31 Jan 2012 18:52:27 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail.integraonline.com (relay1.integra.net [204.130.255.180]) by theia.denx.de (Postfix) with SMTP id 6EBC7280CA for ; Tue, 31 Jan 2012 18:52:26 +0100 (CET) Received: (qmail 15453 invoked from network); 31 Jan 2012 17:52:24 -0000 Received: from unknown (HELO ericsony.example.org) (70.96.116.236) by relay1.integra.net with SMTP; 31 Jan 2012 17:52:24 -0000 From: Eric Nelson To: u-boot@lists.denx.de Date: Tue, 31 Jan 2012 10:52:07 -0700 Message-Id: <1328032330-20883-7-git-send-email-eric.nelson@boundarydevices.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1328032330-20883-1-git-send-email-eric.nelson@boundarydevices.com> References: <1328032330-20883-1-git-send-email-eric.nelson@boundarydevices.com> Cc: fabio.estevam@freescale.com, dirk.behme@de.bosch.com, matthias.fuchs@esd.eu, jason.hui@linaro.org Subject: [U-Boot] [PATCH V6 - Part 3 - 1/2] sf command: allow default bus and chip selects X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de 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 Acked-by: Jason Liu Tested-by: Jason Liu --- 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"