From patchwork Thu Oct 10 16:46:49 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagannadha Sutradharudu Teki X-Patchwork-Id: 282411 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 B4E202C0335 for ; Fri, 11 Oct 2013 03:47:37 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 778494A0F4; Thu, 10 Oct 2013 18:47:35 +0200 (CEST) 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 BmwiiVJsjcRs; Thu, 10 Oct 2013 18:47:35 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 4A8694A100; Thu, 10 Oct 2013 18:47:30 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id A5CBF4A107 for ; Thu, 10 Oct 2013 18:47:24 +0200 (CEST) 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 PLT4r0KMY9TW for ; Thu, 10 Oct 2013 18:47:19 +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 db8outboundpool.messaging.microsoft.com (mail-db8lp0185.outbound.messaging.microsoft.com [213.199.154.185]) by theia.denx.de (Postfix) with ESMTPS id 2FE534A0FC for ; Thu, 10 Oct 2013 18:47:07 +0200 (CEST) Received: from mail183-db8-R.bigfish.com (10.174.8.254) by DB8EHSOBE022.bigfish.com (10.174.4.85) with Microsoft SMTP Server id 14.1.225.22; Thu, 10 Oct 2013 16:47:06 +0000 Received: from mail183-db8 (localhost [127.0.0.1]) by mail183-db8-R.bigfish.com (Postfix) with ESMTP id 72E6D42009E; Thu, 10 Oct 2013 16:47:06 +0000 (UTC) X-Forefront-Antispam-Report: CIP:149.199.60.83; KIP:(null); UIP:(null); IPV:NLI; H:xsj-gw1; RD:unknown-60-83.xilinx.com; EFVD:NLI X-SpamScore: 1 X-BigFish: VPS1(zzzz1f42h208ch1ee6h1de0h1fdah2073h1202h1e76h1d1ah1d2ah1fc6hzz1de098h1de097h8275bhz2fh95h839hd24hf0ah119dh1288h12a5h12a9h12bdh12e5h137ah139eh13b6h1441h14ddh1504h1537h162dh1631h1758h1898h18e1h1946h19b5h1b0ah1d0ch1d2eh1d3fh1dc1h1dfeh1dffh1e1dh1e23h1fe8h1ff5h906i1155h192ch) Received-SPF: pass (mail183-db8: domain of xilinx.com designates 149.199.60.83 as permitted sender) client-ip=149.199.60.83; envelope-from=jagannadha.sutradharudu-teki@xilinx.com; helo=xsj-gw1 ; helo=xsj-gw1 ; Received: from mail183-db8 (localhost.localdomain [127.0.0.1]) by mail183-db8 (MessageSwitch) id 1381423624244492_9414; Thu, 10 Oct 2013 16:47:04 +0000 (UTC) Received: from DB8EHSMHS027.bigfish.com (unknown [10.174.8.244]) by mail183-db8.bigfish.com (Postfix) with ESMTP id 376AD400046; Thu, 10 Oct 2013 16:47:04 +0000 (UTC) Received: from xsj-gw1 (149.199.60.83) by DB8EHSMHS027.bigfish.com (10.174.4.37) with Microsoft SMTP Server id 14.16.227.3; Thu, 10 Oct 2013 16:47:03 +0000 Received: from unknown-38-66.xilinx.com ([149.199.38.66] helo=xsj-smtp1.xilinx.com) by xsj-gw1 with esmtp (Exim 4.63) (envelope-from ) id 1VUJOB-0003Ph-13; Thu, 10 Oct 2013 09:47:03 -0700 From: Jagannadha Sutradharudu Teki To: Date: Thu, 10 Oct 2013 22:16:49 +0530 X-Mailer: git-send-email 1.8.3 X-RCIS-Action: ALLOW MIME-Version: 1.0 Message-ID: X-OriginatorOrg: xilinx.com X-FOPE-CONNECTOR: Id%0$Dn%*$RO%0$TLS%0$FQDN%$TlsDn% Cc: Tom Rini , Jagannadha@theia.denx.de, Sutradharudu Teki Subject: [U-Boot] [PATCH 1/2] sf_ops: Unify bank_sel calculation code 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: , Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de Unified the bank_sel calculation code for erase and write ops. Signed-off-by: Jagannadha Sutradharudu Teki --- drivers/mtd/spi/sf_ops.c | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/drivers/mtd/spi/sf_ops.c b/drivers/mtd/spi/sf_ops.c index 2396e22..1003038 100644 --- a/drivers/mtd/spi/sf_ops.c +++ b/drivers/mtd/spi/sf_ops.c @@ -59,6 +59,22 @@ static int spi_flash_cmd_bankaddr_write(struct spi_flash *flash, u8 bank_sel) return 0; } + +static int spi_flash_bank(struct spi_flash *flash, u32 offset) +{ + u8 bank_sel; + int ret; + + bank_sel = offset / SPI_FLASH_16MB_BOUN; + + ret = spi_flash_cmd_bankaddr_write(flash, bank_sel); + if (ret) { + debug("SF: fail to set bank%d\n", bank_sel); + return ret; + } + + return 0; +} #endif int spi_flash_cmd_wait_ready(struct spi_flash *flash, unsigned long timeout) @@ -162,15 +178,9 @@ int spi_flash_cmd_erase_ops(struct spi_flash *flash, u32 offset, size_t len) cmd[0] = flash->erase_cmd; while (len) { #ifdef CONFIG_SPI_FLASH_BAR - u8 bank_sel; - - bank_sel = offset / SPI_FLASH_16MB_BOUN; - - ret = spi_flash_cmd_bankaddr_write(flash, bank_sel); - if (ret) { - debug("SF: fail to set bank%d\n", bank_sel); + ret = spi_flash_bank(flash, offset); + if (ret < 0) return ret; - } #endif spi_flash_addr(offset, cmd); @@ -203,15 +213,9 @@ int spi_flash_cmd_write_ops(struct spi_flash *flash, u32 offset, cmd[0] = CMD_PAGE_PROGRAM; for (actual = 0; actual < len; actual += chunk_len) { #ifdef CONFIG_SPI_FLASH_BAR - u8 bank_sel; - - bank_sel = offset / SPI_FLASH_16MB_BOUN; - - ret = spi_flash_cmd_bankaddr_write(flash, bank_sel); - if (ret) { - debug("SF: fail to set bank%d\n", bank_sel); + ret = spi_flash_bank(flash, offset); + if (ret < 0) return ret; - } #endif byte_addr = offset % page_size; chunk_len = min(len - actual, page_size - byte_addr);