From patchwork Wed Oct 19 08:36:05 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Packham X-Patchwork-Id: 684006 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 3szQNH24bGz9sxS for ; Wed, 19 Oct 2016 19:39:27 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=NR8RRYri; dkim-atps=neutral Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 4057BA7544; Wed, 19 Oct 2016 10:39:25 +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 XVevoX-muIn5; Wed, 19 Oct 2016 10:39:25 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 1E0B6A7548; Wed, 19 Oct 2016 10:39:23 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id D82D2A7558 for ; Wed, 19 Oct 2016 10:37:59 +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 qhNuicGDmMh1 for ; Wed, 19 Oct 2016 10:37:56 +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-pf0-f193.google.com (mail-pf0-f193.google.com [209.85.192.193]) by theia.denx.de (Postfix) with ESMTPS id 4C766A7560 for ; Wed, 19 Oct 2016 10:36:18 +0200 (CEST) Received: by mail-pf0-f193.google.com with SMTP id r16so1847975pfg.3 for ; Wed, 19 Oct 2016 01:36:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=QfNMXoVwrrj499P3eEBuzy6YVJtbM+dtOWV7JDZ1C2E=; b=NR8RRYri6mGO+nTpX1fKEPYJqlzlObtPdFjubCAapjtgiYkcogpWNmix6zvbTIVAtX +2pNq5hOn298lmuF+yclXKgnUsk3OivBpWbhnH0aeFJrQlzgTr1GPyi3x5ncyKL/jzEr iRsdcLIsp7nFtoqeisR/9p3AVlSycmdxmqjloLwV5MqNkwvCU6yK/uxkJf4VEok2HrLG 4x/ytSll4iAC/BrZb6ZMnSaCmD9Rrhue7Se3cYkRuEgGPPQeSNkKWIjrDQZxYqjG2ftW MJYYai8mpWYJxkLhEkzEAFaI51TtDR+FSViuTLH49jJpDCW811X+f8LWMjFJmD9/ySRu avnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=QfNMXoVwrrj499P3eEBuzy6YVJtbM+dtOWV7JDZ1C2E=; b=Cf0H92DGopG0lQlQvMhMDO0qiy5mGz2bLWaro8rakMnuNjU/tOy5zjapOka0nyH8+B Fs19fSry1NKkOT10OLEL5z/RmExgqtsYu4FK4fUS/oN75ZD9N6h27kFlIKq0O/Y4JQte NSZpUCrnJFWA9SJ6Bkb01FDFeUsUHSzNSoicEZ0hSi2LkrQLS5fJMsF9ClvEGFverPOW K8TCVA7u/YF6hp60R4wBkii1jn8Jqz/qyd7ShdPEsM5uo27IsoHzQ32pAUd2LZEn6+3B nKANp8otOaseX0aLE8xBnS5gInvqMLG643GxvHNSpf/JwPDlrHWdF/ST/7tr8BkHT7YJ ayvA== X-Gm-Message-State: AA6/9Rk1fA9TtTTN2L68FWuAG+bSm8ZxRrKtXuy2vmZ11QmBSeng8hTER70rG43hOQck8A== X-Received: by 10.98.192.24 with SMTP id x24mr8981459pff.118.1476866174941; Wed, 19 Oct 2016 01:36:14 -0700 (PDT) Received: from chrisp-dl.ws.atlnz.lc (2-163-36-202-static.alliedtelesis.co.nz. [202.36.163.2]) by smtp.gmail.com with ESMTPSA id yk6sm61746799pab.43.2016.10.19.01.36.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 19 Oct 2016 01:36:14 -0700 (PDT) From: Chris Packham To: u-boot@lists.denx.de Date: Wed, 19 Oct 2016 21:36:05 +1300 Message-Id: <20161019083605.17612-1-judge.packham@gmail.com> X-Mailer: git-send-email 2.10.0.479.g7c56b16 In-Reply-To: <20161017005145.21956-2-judge.packham@gmail.com> References: <20161017005145.21956-2-judge.packham@gmail.com> Cc: Jagan Teki , Chris Packham Subject: [U-Boot] [RFC PATCH v2] sf: support chips using 4-byte addressing 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" SPI chips with >16MB capacity use 4-byte addressing to allow accessing beyond 16MB. When the size of the SPI flash exceeds 16MB switch to using 4 byte addressing. Signed-off-by: Chris Packham --- Changes in v2: - automatically detect when 4 byte addressing is needed. This is similar to how the linux kernel does the same detection drivers/mtd/spi/sf_internal.h | 4 ++-- drivers/mtd/spi/spi_flash.c | 32 ++++++++++++++++++++++---------- include/spi_flash.h | 2 ++ 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/drivers/mtd/spi/sf_internal.h b/drivers/mtd/spi/sf_internal.h index cde4cfbf2e32..db4532849145 100644 --- a/drivers/mtd/spi/sf_internal.h +++ b/drivers/mtd/spi/sf_internal.h @@ -25,8 +25,8 @@ enum spi_nor_option_flags { SNOR_F_USE_FSR = BIT(1), }; -#define SPI_FLASH_3B_ADDR_LEN 3 -#define SPI_FLASH_CMD_LEN (1 + SPI_FLASH_3B_ADDR_LEN) +#define SPI_FLASE_MAX_ADDR_WIDTH 4 +#define SPI_FLASH_CMD_LEN (1 + SPI_FLASE_MAX_ADDR_WIDTH) #define SPI_FLASH_16MB_BOUN 0x1000000 /* CFI Manufacture ID's */ diff --git a/drivers/mtd/spi/spi_flash.c b/drivers/mtd/spi/spi_flash.c index 7f6e9ae23ea8..a3efaa129231 100644 --- a/drivers/mtd/spi/spi_flash.c +++ b/drivers/mtd/spi/spi_flash.c @@ -22,12 +22,19 @@ DECLARE_GLOBAL_DATA_PTR; -static void spi_flash_addr(u32 addr, u8 *cmd) +static void spi_flash_addr(u32 addr, u8 *cmd, u8 addr_width) { /* cmd[0] is actual command */ - cmd[1] = addr >> 16; - cmd[2] = addr >> 8; - cmd[3] = addr >> 0; + if (addr_width == 4) { + cmd[1] = addr >> 24; + cmd[2] = addr >> 16; + cmd[3] = addr >> 8; + cmd[4] = addr; + } else { + cmd[1] = addr >> 16; + cmd[2] = addr >> 8; + cmd[3] = addr >> 0; + } } static int read_sr(struct spi_flash *flash, u8 *rs) @@ -357,12 +364,13 @@ int spi_flash_cmd_erase_ops(struct spi_flash *flash, u32 offset, size_t len) if (ret < 0) return ret; #endif - spi_flash_addr(erase_addr, cmd); + spi_flash_addr(erase_addr, cmd, flash->addr_width); debug("SF: erase %2x %2x %2x %2x (%x)\n", cmd[0], cmd[1], cmd[2], cmd[3], erase_addr); - ret = spi_flash_write_common(flash, cmd, sizeof(cmd), NULL, 0); + ret = spi_flash_write_common(flash, cmd, flash->addr_width + 1, + NULL, 0); if (ret < 0) { debug("SF: erase failed\n"); break; @@ -415,12 +423,12 @@ int spi_flash_cmd_write_ops(struct spi_flash *flash, u32 offset, chunk_len = min(chunk_len, (size_t)spi->max_write_size); - spi_flash_addr(write_addr, cmd); + spi_flash_addr(write_addr, cmd, flash->addr_width); debug("SF: 0x%p => cmd = { 0x%02x 0x%02x%02x%02x } chunk_len = %zu\n", buf + actual, cmd[0], cmd[1], cmd[2], cmd[3], chunk_len); - ret = spi_flash_write_common(flash, cmd, sizeof(cmd), + ret = spi_flash_write_common(flash, cmd, flash->addr_width + 1, buf + actual, chunk_len); if (ret < 0) { debug("SF: write failed\n"); @@ -492,7 +500,7 @@ int spi_flash_cmd_read_ops(struct spi_flash *flash, u32 offset, return 0; } - cmdsz = SPI_FLASH_CMD_LEN + flash->dummy_byte; + cmdsz = flash->addr_width + 1 + flash->dummy_byte; cmd = calloc(1, cmdsz); if (!cmd) { debug("SF: Failed to allocate cmd\n"); @@ -520,7 +528,7 @@ int spi_flash_cmd_read_ops(struct spi_flash *flash, u32 offset, else read_len = remain_len; - spi_flash_addr(read_addr, cmd); + spi_flash_addr(read_addr, cmd, flash->addr_width); ret = spi_flash_read_common(flash, cmd, cmdsz, data, read_len); if (ret < 0) { @@ -1154,6 +1162,10 @@ int spi_flash_scan(struct spi_flash *flash) if (flash->dual_flash & SF_DUAL_STACKED_FLASH) flash->size <<= 1; #endif + if (flash->size > SPI_FLASH_16MB_BOUN) + flash->addr_width = 4; + else + flash->addr_width = 3; #ifdef CONFIG_SPI_FLASH_USE_4K_SECTORS /* Compute erase sector and command */ diff --git a/include/spi_flash.h b/include/spi_flash.h index be2fe3f84cb9..c65bf22aee8b 100644 --- a/include/spi_flash.h +++ b/include/spi_flash.h @@ -39,6 +39,7 @@ struct spi_slave; * @flags: Indication of spi flash flags * @size: Total flash size * @page_size: Write (page) size + * @addr_width: number of address bytes * @sector_size: Sector size * @erase_size: Erase size * @bank_read_cmd: Bank read cmd @@ -72,6 +73,7 @@ struct spi_flash { u32 size; u32 page_size; + u8 addr_width; u32 sector_size; u32 erase_size; #ifdef CONFIG_SPI_FLASH_BAR