From patchwork Mon Oct 12 15:01:01 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagan Teki X-Patchwork-Id: 529146 X-Patchwork-Delegate: jagannadh.teki@gmail.com 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 A33281402B2 for ; Tue, 13 Oct 2015 02:03:24 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 6FA614B8FF; Mon, 12 Oct 2015 17:02:44 +0200 (CEST) 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 GCC-dxzVqJjc; Mon, 12 Oct 2015 17:02:44 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 3BC6D4B88B; Mon, 12 Oct 2015 17:02:41 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 1A9D24B8A5 for ; Mon, 12 Oct 2015 17:02:38 +0200 (CEST) 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 XOeWKp7Ey2BP for ; Mon, 12 Oct 2015 17:02:38 +0200 (CEST) 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-pa0-f67.google.com (mail-pa0-f67.google.com [209.85.220.67]) by theia.denx.de (Postfix) with ESMTPS id 645964B8F3 for ; Mon, 12 Oct 2015 17:02:29 +0200 (CEST) Received: by palb17 with SMTP id b17so19238293pal.2 for ; Mon, 12 Oct 2015 08:02:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=2vWjuz+LFfWeWqUeV7z06x/FFEXY6X2RCt/pyRPcmx8=; b=U+pTLbLH9mNTpbo/Nkqcj7QquGEJGaqFUIHwZtKpObhaEC1EBPQZ2Zfu3dY4VZcIAp xiYne313SiGw+p9iucZvv9C2fuSAP/rIoAvsvAJQhlcWs/DHrtGg7kakaE3YOyhMJG0g 1OnZVDTvRcxDMD0QENKnCYCBU8favMyvu62KktwmZkZu3wCKYfWjWZUyIPT/i6z63R3J JNm0VjsCxmcVGHLpP7Z2r3E+o+S3RrDUvIQaMVtJ3cqbh3/m3EyI0UlcrJM8kb0H4bCF fgU2jJfED7dLv0fZ1YEUOmag4hXjj1oYH/CMb8j2+uZFl1QXKvsVPfPYmZs3zjkf8XcZ 8ofg== X-Received: by 10.68.104.66 with SMTP id gc2mr34379703pbb.21.1444662147845; Mon, 12 Oct 2015 08:02:27 -0700 (PDT) Received: from Jubuntu.amcc.com ([182.73.239.130]) by smtp.gmail.com with ESMTPSA id qy5sm18924909pbb.16.2015.10.12.08.02.22 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 12 Oct 2015 08:02:26 -0700 (PDT) From: Jagan Teki To: u-boot@lists.denx.de Date: Mon, 12 Oct 2015 20:31:01 +0530 Message-Id: <1444662074-2424-9-git-send-email-jteki@openedev.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1444662074-2424-1-git-send-email-jteki@openedev.com> References: <1444662074-2424-1-git-send-email-jteki@openedev.com> Cc: fabio.estevam@freescale.com, Marek Vasut , qiwang@micron.com, Tom Rini , Michal Simek , Siva Durga Prasad Paladugu , frankliu@micron.com, Jagan Teki Subject: [U-Boot] [PATCH v4 08/21] sf: spi_flash_validate_params => spi_flash_scan X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Rename spi_flash_validate_params to spi_flash_scan as this code not only deals with params setup but also configure all spi_flash attributes. And also moved all flash related code into spi_flash_scan for future functionality addition. Signed-off-by: Jagan Teki --- Changes for v4, v3, v2: - none drivers/mtd/spi/sf_probe.c | 145 +++++++++++++++++++++++---------------------- 1 file changed, 75 insertions(+), 70 deletions(-) diff --git a/drivers/mtd/spi/sf_probe.c b/drivers/mtd/spi/sf_probe.c index f591ab1..a150263 100644 --- a/drivers/mtd/spi/sf_probe.c +++ b/drivers/mtd/spi/sf_probe.c @@ -130,13 +130,42 @@ bank_end: } #endif -static int spi_flash_validate_params(struct spi_slave *spi, u8 *idcode, +#if CONFIG_IS_ENABLED(OF_CONTROL) +int spi_flash_decode_fdt(const void *blob, struct spi_flash *flash) +{ + fdt_addr_t addr; + fdt_size_t size; + int node; + + /* If there is no node, do nothing */ + node = fdtdec_next_compatible(blob, 0, COMPAT_GENERIC_SPI_FLASH); + if (node < 0) + return 0; + + addr = fdtdec_get_addr_size(blob, node, "memory-map", &size); + if (addr == FDT_ADDR_T_NONE) { + debug("%s: Cannot decode address\n", __func__); + return 0; + } + + if (flash->size != size) { + debug("%s: Memory map must cover entire device\n", __func__); + return -1; + } + flash->memory_map = map_sysmem(addr, size); + + return 0; +} +#endif /* CONFIG_IS_ENABLED(OF_CONTROL) */ + +static int spi_flash_scan(struct spi_slave *spi, u8 *idcode, struct spi_flash *flash) { const struct spi_flash_params *params; u8 cmd; u16 jedec = idcode[1] << 8 | idcode[2]; u16 ext_jedec = idcode[3] << 8 | idcode[4]; + int ret; /* Validate params from spi_flash_params table */ params = spi_flash_params_table; @@ -158,6 +187,13 @@ static int spi_flash_validate_params(struct spi_slave *spi, u8 *idcode, return -EPROTONOSUPPORT; } + /* Flash powers up read-only, so clear BP# bits */ +#if defined(CONFIG_SPI_FLASH_ATMEL) || \ + defined(CONFIG_SPI_FLASH_MACRONIX) || \ + defined(CONFIG_SPI_FLASH_SST) + spi_flash_cmd_write_status(flash, 0); +#endif + /* Assign spi data */ flash->spi = spi; flash->name = params->name; @@ -238,6 +274,17 @@ static int spi_flash_validate_params(struct spi_slave *spi, u8 *idcode, /* Go for default supported write cmd */ flash->write_cmd = CMD_PAGE_PROGRAM; + /* Set the quad enable bit - only for quad commands */ + if ((flash->read_cmd == CMD_READ_QUAD_OUTPUT_FAST) || + (flash->read_cmd == CMD_READ_QUAD_IO_FAST) || + (flash->write_cmd == CMD_QUAD_PAGE_PROGRAM)) { + ret = spi_flash_set_qeb(flash, idcode[0]); + if (ret) { + debug("SF: Fail to set QEB for %02x\n", idcode[0]); + return -EINVAL; + } + } + /* Read dummy_byte: dummy byte is determined based on the * dummy cycles of a particular command. * Fast commands - dummy_byte = dummy_cycles/8 @@ -264,48 +311,41 @@ static int spi_flash_validate_params(struct spi_slave *spi, u8 *idcode, /* Configure the BAR - discover bank cmds and read current bank */ #ifdef CONFIG_SPI_FLASH_BAR - int ret = spi_flash_read_bank(flash, idcode[0]); + ret = spi_flash_read_bank(flash, idcode[0]); if (ret < 0) return ret; #endif - /* Flash powers up read-only, so clear BP# bits */ -#if defined(CONFIG_SPI_FLASH_ATMEL) || \ - defined(CONFIG_SPI_FLASH_MACRONIX) || \ - defined(CONFIG_SPI_FLASH_SST) - spi_flash_cmd_write_status(flash, 0); -#endif - - return 0; -} - #if CONFIG_IS_ENABLED(OF_CONTROL) -int spi_flash_decode_fdt(const void *blob, struct spi_flash *flash) -{ - fdt_addr_t addr; - fdt_size_t size; - int node; - - /* If there is no node, do nothing */ - node = fdtdec_next_compatible(blob, 0, COMPAT_GENERIC_SPI_FLASH); - if (node < 0) - return 0; - - addr = fdtdec_get_addr_size(blob, node, "memory-map", &size); - if (addr == FDT_ADDR_T_NONE) { - debug("%s: Cannot decode address\n", __func__); - return 0; + ret = spi_flash_decode_fdt(gd->fdt_blob, flash); + if (ret) { + debug("SF: FDT decode error\n"); + return -EINVAL; } +#endif - if (flash->size != size) { - debug("%s: Memory map must cover entire device\n", __func__); - return -1; +#ifndef CONFIG_SPL_BUILD + printf("SF: Detected %s with page size ", flash->name); + print_size(flash->page_size, ", erase size "); + print_size(flash->erase_size, ", total "); + print_size(flash->size, ""); + if (flash->memory_map) + printf(", mapped at %p", flash->memory_map); + puts("\n"); +#endif + +#ifndef CONFIG_SPI_FLASH_BAR + if (((flash->dual_flash == SF_SINGLE_FLASH) && + (flash->size > SPI_FLASH_16MB_BOUN)) || + ((flash->dual_flash > SF_SINGLE_FLASH) && + (flash->size > SPI_FLASH_16MB_BOUN << 1))) { + puts("SF: Warning - Only lower 16MiB accessible,"); + puts(" Full access #define CONFIG_SPI_FLASH_BAR\n"); } - flash->memory_map = map_sysmem(addr, size); +#endif - return 0; + return ret; } -#endif /* CONFIG_IS_ENABLED(OF_CONTROL) */ /** * spi_flash_probe_slave() - Probe for a SPI flash device on a bus @@ -344,47 +384,12 @@ int spi_flash_probe_slave(struct spi_slave *spi, struct spi_flash *flash) print_buffer(0, idcode, 1, sizeof(idcode), 0); #endif - if (spi_flash_validate_params(spi, idcode, flash)) { + ret = spi_flash_scan(spi, idcode, flash); + if (ret) { ret = -EINVAL; goto err_read_id; } - /* Set the quad enable bit - only for quad commands */ - if ((flash->read_cmd == CMD_READ_QUAD_OUTPUT_FAST) || - (flash->read_cmd == CMD_READ_QUAD_IO_FAST) || - (flash->write_cmd == CMD_QUAD_PAGE_PROGRAM)) { - if (spi_flash_set_qeb(flash, idcode[0])) { - debug("SF: Fail to set QEB for %02x\n", idcode[0]); - ret = -EINVAL; - goto err_read_id; - } - } - -#if CONFIG_IS_ENABLED(OF_CONTROL) - if (spi_flash_decode_fdt(gd->fdt_blob, flash)) { - debug("SF: FDT decode error\n"); - ret = -EINVAL; - goto err_read_id; - } -#endif -#ifndef CONFIG_SPL_BUILD - printf("SF: Detected %s with page size ", flash->name); - print_size(flash->page_size, ", erase size "); - print_size(flash->erase_size, ", total "); - print_size(flash->size, ""); - if (flash->memory_map) - printf(", mapped at %p", flash->memory_map); - puts("\n"); -#endif -#ifndef CONFIG_SPI_FLASH_BAR - if (((flash->dual_flash == SF_SINGLE_FLASH) && - (flash->size > SPI_FLASH_16MB_BOUN)) || - ((flash->dual_flash > SF_SINGLE_FLASH) && - (flash->size > SPI_FLASH_16MB_BOUN << 1))) { - puts("SF: Warning - Only lower 16MiB accessible,"); - puts(" Full access #define CONFIG_SPI_FLASH_BAR\n"); - } -#endif #ifdef CONFIG_SPI_FLASH_MTD ret = spi_flash_mtd_register(flash); #endif