From patchwork Wed Feb 16 20:27:53 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Retanubun X-Patchwork-Id: 83398 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 0B42CB70FD for ; Thu, 17 Feb 2011 07:28:27 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id B43AA280AD; Wed, 16 Feb 2011 21:28:16 +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 pOAPDrela5Ul; Wed, 16 Feb 2011 21:28:16 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 41696280CB; Wed, 16 Feb 2011 21:28:12 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id C0AC5280A9 for ; Wed, 16 Feb 2011 21:28:06 +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 AiCEhUw1Ww0G for ; Wed, 16 Feb 2011 21:28:05 +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 mail2.ruggedcom.com (mail2.ruggedcom.com [204.50.148.11]) by theia.denx.de (Postfix) with ESMTPS id 6D1C72807B for ; Wed, 16 Feb 2011 21:28:04 +0100 (CET) Received: from rceng01.eng.lan (10.200.2.11) by RCexchangesvr1 (10.200.2.21) with Microsoft SMTP Server id 8.2.176.0; Wed, 16 Feb 2011 15:28:42 -0500 Received: from richardretanubun.eng.lan (unknown [10.200.19.10]) by rceng01.eng.lan (Postfix) with ESMTP id 6965B14E938; Wed, 16 Feb 2011 15:28:03 -0500 (EST) Received: from richardretanubun by richardretanubun.eng.lan with local (Exim 4.72) (envelope-from ) id 1Ppnyl-0002BF-DA; Wed, 16 Feb 2011 15:28:03 -0500 From: Richard Retanubun To: Date: Wed, 16 Feb 2011 15:27:53 -0500 Message-ID: <1297888074-8344-2-git-send-email-RichardRetanubun@RuggedCom.com> X-Mailer: git-send-email 1.7.2.3 In-Reply-To: <201102150434.39422.vapier@gentoo.org> References: <201102150434.39422.vapier@gentoo.org> MIME-Version: 1.0 Cc: mcmullan@netapp.com, Richard Retanubun Subject: [U-Boot] [PATCH 1/2] SPI: Add struct spi_flash.sector_size parameter X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.9 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de This patch adds a new member to struct spi_flash (u16 sector_size) and updates the spi flash drivers to start populating it. This parameter can be used by spi flash commands that need to round up units of operation to the flash's sector_size. --- drivers/mtd/spi/atmel.c | 1 + drivers/mtd/spi/macronix.c | 1 + drivers/mtd/spi/spansion.c | 4 ++-- drivers/mtd/spi/sst.c | 3 ++- drivers/mtd/spi/stmicro.c | 4 ++-- drivers/mtd/spi/winbond.c | 5 +++-- include/spi_flash.h | 2 ++ 7 files changed, 13 insertions(+), 7 deletions(-) diff --git a/drivers/mtd/spi/atmel.c b/drivers/mtd/spi/atmel.c index a9910b1..180a52b 100644 --- a/drivers/mtd/spi/atmel.c +++ b/drivers/mtd/spi/atmel.c @@ -498,6 +498,7 @@ struct spi_flash *spi_flash_probe_atmel(struct spi_slave *spi, u8 *idcode) asf->flash.size = page_size * params->pages_per_block * params->blocks_per_sector * params->nr_sectors; + asf->flash.sector_size = page_size; printf("SF: Detected %s with page size %u, total ", params->name, page_size); diff --git a/drivers/mtd/spi/macronix.c b/drivers/mtd/spi/macronix.c index 4155d4d..4a8e17f 100644 --- a/drivers/mtd/spi/macronix.c +++ b/drivers/mtd/spi/macronix.c @@ -217,6 +217,7 @@ struct spi_flash *spi_flash_probe_macronix(struct spi_slave *spi, u8 *idcode) mcx->flash.read = spi_flash_cmd_read_fast; mcx->flash.size = params->page_size * params->pages_per_sector * params->sectors_per_block * params->nr_blocks; + mcx->flash.sector_size = mcx->flash.size/params->nr_blocks; printf("SF: Detected %s with page size %u, total ", params->name, params->page_size); diff --git a/drivers/mtd/spi/spansion.c b/drivers/mtd/spi/spansion.c index d54a5fa..c88457b 100644 --- a/drivers/mtd/spi/spansion.c +++ b/drivers/mtd/spi/spansion.c @@ -199,8 +199,7 @@ static int spansion_write(struct spi_flash *flash, int spansion_erase(struct spi_flash *flash, u32 offset, size_t len) { struct spansion_spi_flash *spsn = to_spansion_spi_flash(flash); - return spi_flash_cmd_erase(flash, CMD_S25FLXX_SE, - spsn->params->page_size * spsn->params->pages_per_sector, + return spi_flash_cmd_erase(flash, CMD_S25FLXX_SE, flash->sector_size, offset, len); } @@ -242,6 +241,7 @@ struct spi_flash *spi_flash_probe_spansion(struct spi_slave *spi, u8 *idcode) spsn->flash.read = spi_flash_cmd_read_fast; spsn->flash.size = params->page_size * params->pages_per_sector * params->nr_sectors; + spsn->flash.sector_size = spsn->flash.size/params->nr_sectors; printf("SF: Detected %s with page size %u, total ", params->name, params->page_size); diff --git a/drivers/mtd/spi/sst.c b/drivers/mtd/spi/sst.c index 792d04d..15de12b 100644 --- a/drivers/mtd/spi/sst.c +++ b/drivers/mtd/spi/sst.c @@ -201,7 +201,7 @@ sst_write(struct spi_flash *flash, u32 offset, size_t len, const void *buf) int sst_erase(struct spi_flash *flash, u32 offset, size_t len) { - return spi_flash_cmd_erase(flash, CMD_SST_SE, SST_SECTOR_SIZE, + return spi_flash_cmd_erase(flash, CMD_SST_SE, flash->sector_size, offset, len); } @@ -257,6 +257,7 @@ spi_flash_probe_sst(struct spi_slave *spi, u8 *idcode) stm->flash.write = sst_write; stm->flash.erase = sst_erase; stm->flash.size = SST_SECTOR_SIZE * params->nr_sectors; + stm->flash.sector_size = SST_SECTOR_SIZE; printf("SF: Detected %s with page size %u, total ", params->name, SST_SECTOR_SIZE); diff --git a/drivers/mtd/spi/stmicro.c b/drivers/mtd/spi/stmicro.c index 7ef690d..80d838e 100644 --- a/drivers/mtd/spi/stmicro.c +++ b/drivers/mtd/spi/stmicro.c @@ -200,8 +200,7 @@ static int stmicro_write(struct spi_flash *flash, int stmicro_erase(struct spi_flash *flash, u32 offset, size_t len) { struct stmicro_spi_flash *stm = to_stmicro_spi_flash(flash); - return spi_flash_cmd_erase(flash, CMD_M25PXX_SE, - stm->params->page_size * stm->params->pages_per_sector, + return spi_flash_cmd_erase(flash, CMD_M25PXX_SE, flash->sector_size, offset, len); } @@ -251,6 +250,7 @@ struct spi_flash *spi_flash_probe_stmicro(struct spi_slave *spi, u8 * idcode) stm->flash.read = spi_flash_cmd_read_fast; stm->flash.size = params->page_size * params->pages_per_sector * params->nr_sectors; + stm->flash.sector_size = stm->flash.size/params->nr_sectors; printf("SF: Detected %s with page size %u, total ", params->name, params->page_size); diff --git a/drivers/mtd/spi/winbond.c b/drivers/mtd/spi/winbond.c index e88802f..ec6fb79 100644 --- a/drivers/mtd/spi/winbond.c +++ b/drivers/mtd/spi/winbond.c @@ -173,8 +173,7 @@ out: int winbond_erase(struct spi_flash *flash, u32 offset, size_t len) { struct winbond_spi_flash *stm = to_winbond_spi_flash(flash); - return spi_flash_cmd_erase(flash, CMD_W25_SE, - (1 << stm->params->l2_page_size) * stm->params->pages_per_sector, + return spi_flash_cmd_erase(flash, CMD_W25_SE, flash->sector_size, offset, len); } @@ -216,6 +215,8 @@ struct spi_flash *spi_flash_probe_winbond(struct spi_slave *spi, u8 *idcode) stm->flash.size = page_size * params->pages_per_sector * params->sectors_per_block * params->nr_blocks; + stm->flash.sector_size = (1 << stm->params->l2_page_size) * + stm->params->pages_per_sector; printf("SF: Detected %s with page size %u, total ", params->name, page_size); diff --git a/include/spi_flash.h b/include/spi_flash.h index 1f8ba29..039b94e 100644 --- a/include/spi_flash.h +++ b/include/spi_flash.h @@ -38,6 +38,8 @@ struct spi_flash { u32 size; + u16 sector_size; + int (*read)(struct spi_flash *flash, u32 offset, size_t len, void *buf); int (*write)(struct spi_flash *flash, u32 offset,