From patchwork Fri Nov 2 17:39:35 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vipin Kumar X-Patchwork-Id: 196699 X-Patchwork-Delegate: albert.aribaud@free.fr 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 5F78F2C00C1 for ; Sat, 3 Nov 2012 05:04:49 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 41CE34A1A0; Fri, 2 Nov 2012 19:03:08 +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 1ZrNeMyD+QJN; Fri, 2 Nov 2012 19:03:08 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 6E2294AAE8; Fri, 2 Nov 2012 19:01:08 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 8A84B4A8CA for ; Fri, 2 Nov 2012 19:00:56 +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 1cpDa9d4eQIT for ; Fri, 2 Nov 2012 19:00:55 +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 eu1sys200aog104.obsmtp.com (eu1sys200aog104.obsmtp.com [207.126.144.117]) by theia.denx.de (Postfix) with ESMTPS id 84B344A8EF for ; Fri, 2 Nov 2012 19:00:13 +0100 (CET) Received: from beta.dmz-ap.st.com ([138.198.100.35]) (using TLSv1) by eu1sys200aob104.postini.com ([207.126.147.11]) with SMTP ID DSNKUJQKLeYQdg6nPBCZxfrldRudTfCjq+P4@postini.com; Fri, 02 Nov 2012 18:00:15 UTC Received: from zeta.dmz-ap.st.com (ns6.st.com [138.198.234.13]) by beta.dmz-ap.st.com (STMicroelectronics) with ESMTP id C41DE167; Fri, 2 Nov 2012 17:34:36 +0000 (GMT) Received: from Webmail-ap.st.com (eapex1hubcas2.st.com [10.80.176.10]) by zeta.dmz-ap.st.com (STMicroelectronics) with ESMTP id F3E08107D; Fri, 2 Nov 2012 17:42:49 +0000 (GMT) Received: from localhost (10.251.136.62) by Webmail-ap.st.com (10.80.176.7) with Microsoft SMTP Server (TLS) id 8.3.245.1; Sat, 3 Nov 2012 01:42:49 +0800 From: Vipin Kumar To: Date: Fri, 2 Nov 2012 23:09:35 +0530 Message-ID: <5c48a677aef2bc911860a36feffc7fc39b19b44e.1351877124.git.vipin.kumar@st.com> X-Mailer: git-send-email 1.7.10.rc2.10.gb47606 In-Reply-To: <1c8cd3ce05a1064788a96bb4b49f9b82d9caf736.1351877124.git.vipin.kumar@st.com> References: <1c8cd3ce05a1064788a96bb4b49f9b82d9caf736.1351877124.git.vipin.kumar@st.com> MIME-Version: 1.0 Cc: sr@denx.de, spear-devel@list.st.com Subject: [U-Boot] [Drivers PATCH 05/19] mtd/st_smi: Use page sizes respective to flash 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 The page size is a flash dependent property and the driver was using a macro in place of page size. This patch uses the proper page size wrt the flash device connected on board Signed-off-by: Vipin Kumar --- drivers/mtd/st_smi.c | 41 +++++++++++++++++++++++++++++++++-------- include/linux/mtd/st_smi.h | 1 - 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/drivers/mtd/st_smi.c b/drivers/mtd/st_smi.c index 5298723..ac10a3d 100644 --- a/drivers/mtd/st_smi.c +++ b/drivers/mtd/st_smi.c @@ -96,6 +96,25 @@ static struct flash_device flash_devices[] = { }; /* + * get_flash_device - Return flash_device pointer for a particular device id + * @id: Device id + * + * Return flash_device pointer for a particular device id + */ +static struct flash_device *get_flash_device(u32 id) +{ + struct flash_device *flash_dev_p = &flash_devices[0]; + int i; + + for (i = 0; i < ARRAY_SIZE(flash_devices); i++, flash_dev_p++) { + if (flash_dev_p->device_id == id) + return flash_dev_p; + } + + return NULL; +} + +/* * smi_wait_xfer_finish - Wait until TFF is set in status register * @timeout: timeout in milliseconds * @@ -361,20 +380,27 @@ static int smi_sector_erase(flash_info_t *info, unsigned int sector) /* * smi_write - Write to SMI flash + * @info: flash info structure * @src_addr: source buffer * @dst_addr: destination buffer * @length: length to write in bytes - * @bank: bank base address * * Write to SMI flash */ -static int smi_write(unsigned char *src_addr, unsigned char *dst_addr, - unsigned int length, ulong bank_addr) +static int smi_write(flash_info_t *info, unsigned char *src_addr, + unsigned char *dst_addr, unsigned int length) { + struct flash_device *flash_device_p = get_flash_device(info->flash_id); + u32 page_size; int banknum; int issue_we; - switch (bank_addr) { + if (!flash_device_p) + return -EIO; + + page_size = flash_device_p->pagesize; + + switch (info->start[0]) { case SMIBANK0_BASE: banknum = BANK0; break; @@ -400,9 +426,9 @@ static int smi_write(unsigned char *src_addr, unsigned char *dst_addr, /* Perform the write command */ while (length) { int k; - unsigned int wlen = min(SFLASH_PAGE_SIZE, length); + unsigned int wlen = min(page_size, length); - if (issue_we || (((ulong)(dst_addr) % SFLASH_PAGE_SIZE) == 0)) { + if (issue_we || (((ulong)(dst_addr) % page_size) == 0)) { issue_we = 0; if (smi_wait_till_ready(banknum, @@ -444,8 +470,7 @@ static int smi_write(unsigned char *src_addr, unsigned char *dst_addr, */ int write_buff(flash_info_t *info, uchar *src, ulong dest_addr, ulong length) { - return smi_write(src, (unsigned char *)dest_addr, length, - info->start[0]); + return smi_write(info, src, (unsigned char *)dest_addr, length); } /* diff --git a/include/linux/mtd/st_smi.h b/include/linux/mtd/st_smi.h index 04f81ea..5837493 100644 --- a/include/linux/mtd/st_smi.h +++ b/include/linux/mtd/st_smi.h @@ -108,7 +108,6 @@ struct flash_dev { ushort sector_count; }; -#define SFLASH_PAGE_SIZE 0x100 /* flash page size */ #define XFER_FINISH_TOUT 15 /* xfer finish timeout(in ms) */ #define WMODE_TOUT 15 /* write enable timeout(in ms) */