From patchwork Wed Sep 2 06:09:53 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagan Teki X-Patchwork-Id: 513350 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 20EE2140129 for ; Wed, 2 Sep 2015 18:05:59 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 5DC904B809; Wed, 2 Sep 2015 10:05:20 +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 irl4g1Hk3PCn; Wed, 2 Sep 2015 10:05:20 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 82BA94B803; Wed, 2 Sep 2015 10:04:47 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 7797D4B773 for ; Wed, 2 Sep 2015 08:10:57 +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 1roxZYDTxnmn for ; Wed, 2 Sep 2015 08:10:57 +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-f42.google.com (mail-pa0-f42.google.com [209.85.220.42]) by theia.denx.de (Postfix) with ESMTPS id 096D74B73C for ; Wed, 2 Sep 2015 08:10:53 +0200 (CEST) Received: by pacfv12 with SMTP id fv12so80972pac.2 for ; Tue, 01 Sep 2015 23:10:52 -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=5ntRan8b/5niV7hZ8Aqh50G1WCD+8QPklkZ0TpeN3yI=; b=YsIMX9UuTrIO51uq4nmcy127Qb39kK0ubm3z7x4hlItk9125FZTYrwf41Yz20rL5Xg RMQ3262xohREA6Ur8JF89kwDWXmEHBD4QXN9bAmy6BeliUc9+6V5ccFkLxxvyMSG9k53 t1PvEYbSylBgxR+99i5xUR37Ffh2rkVoj6GRagLGGZam5B4QoT44d1Dl4nHBjDQAccJ4 Z1NURGKe5F2Mt7ZwWZ+pugnipn97wZMT40NWgh11LtQZKU/Qsqj4AA7/Tnn3QTW8u78L h4UG55Rha4Xcr+BY15skeNnMWtu1iOFwPduptc2ram0bZv44f4UIyeJ3iqUPxU3ErZGr 5WuQ== X-Received: by 10.66.147.131 with SMTP id tk3mr53522105pab.104.1441174252208; Tue, 01 Sep 2015 23:10:52 -0700 (PDT) Received: from Jubuntu.amcc.com ([182.73.239.130]) by smtp.gmail.com with ESMTPSA id pi9sm20195859pbb.96.2015.09.01.23.10.49 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 01 Sep 2015 23:10:51 -0700 (PDT) From: Jagan Teki To: u-boot@lists.denx.de Date: Wed, 2 Sep 2015 11:39:53 +0530 Message-Id: <1441174197-5096-10-git-send-email-jteki@openedev.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1441174197-5096-1-git-send-email-jteki@openedev.com> References: <1441174197-5096-1-git-send-email-jteki@openedev.com> X-Mailman-Approved-At: Wed, 02 Sep 2015 10:04:23 +0200 Cc: Jagan Teki Subject: [U-Boot] [PATCH v3 09/13] sf: Use flash_read_reg routine 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" This patch uses flash_read_reg routine for all respective read register calls. Signed-off-by: Jagan Teki --- Changes for v3: - none Changes for v2: - none drivers/mtd/spi/sf_internal.h | 4 +-- drivers/mtd/spi/sf_ops.c | 63 +++++++++++++++++++------------------------ drivers/mtd/spi/sf_probe.c | 21 +++++++-------- 3 files changed, 39 insertions(+), 49 deletions(-) diff --git a/drivers/mtd/spi/sf_internal.h b/drivers/mtd/spi/sf_internal.h index 14b8b55..9341fb3 100644 --- a/drivers/mtd/spi/sf_internal.h +++ b/drivers/mtd/spi/sf_internal.h @@ -171,13 +171,13 @@ int spi_flash_cmd_write(struct spi_slave *spi, const u8 *cmd, size_t cmd_len, int spi_flash_cmd_erase_ops(struct spi_flash *flash, u32 offset, size_t len); /* Read the status register */ -int spi_flash_cmd_read_status(struct spi_flash *flash, u8 *rs); +int spi_flash_cmd_read_status(struct spi_flash *flash); /* Program the status register */ int spi_flash_cmd_write_status(struct spi_flash *flash, u8 ws); /* Read the config register */ -int spi_flash_cmd_read_config(struct spi_flash *flash, u8 *rc); +int spi_flash_cmd_read_config(struct spi_flash *flash); /* Program the config register */ int spi_flash_cmd_write_config(struct spi_flash *flash, u8 wc); diff --git a/drivers/mtd/spi/sf_ops.c b/drivers/mtd/spi/sf_ops.c index 85e15b9..4c807ed 100644 --- a/drivers/mtd/spi/sf_ops.c +++ b/drivers/mtd/spi/sf_ops.c @@ -26,34 +26,32 @@ static void spi_flash_addr(u32 addr, u8 *cmd) cmd[3] = addr >> 0; } -int spi_flash_cmd_read_status(struct spi_flash *flash, u8 *rs) +int spi_flash_cmd_read_status(struct spi_flash *flash) { int ret; - u8 cmd; + u8 rs; - cmd = CMD_READ_STATUS; - ret = spi_flash_read_common(flash, &cmd, 1, rs, 1); + ret = flash_read_reg(flash, CMD_READ_STATUS, &rs, 1); if (ret < 0) { debug("SF: fail to read status register\n"); return ret; } - return 0; + return rs; } -static int read_fsr(struct spi_flash *flash, u8 *fsr) +static int read_fsr(struct spi_flash *flash) { int ret; - u8 cmd; + u8 fsr; - cmd = CMD_FLAG_STATUS; - ret = spi_flash_read_common(flash, &cmd, 1, fsr, 1); + ret = flash_read_reg(flash, CMD_FLAG_STATUS, &fsr, 1); if (ret < 0) { debug("SF: fail to read flag status register\n"); return ret; } - return 0; + return fsr; } int spi_flash_cmd_write_status(struct spi_flash *flash, u8 ws) @@ -72,30 +70,31 @@ int spi_flash_cmd_write_status(struct spi_flash *flash, u8 ws) } #if defined(CONFIG_SPI_FLASH_SPANSION) || defined(CONFIG_SPI_FLASH_WINBOND) -int spi_flash_cmd_read_config(struct spi_flash *flash, u8 *rc) +int spi_flash_cmd_read_config(struct spi_flash *flash) { int ret; - u8 cmd; + u8 rc; - cmd = CMD_READ_CONFIG; - ret = spi_flash_read_common(flash, &cmd, 1, rc, 1); + ret = flash_read_reg(flash, CMD_READ_CONFIG, &rc, 1); if (ret < 0) { debug("SF: fail to read config register\n"); return ret; } - return 0; + return rc; } int spi_flash_cmd_write_config(struct spi_flash *flash, u8 wc) { u8 data[2]; u8 cmd; - int ret; + int ret, val; - ret = spi_flash_cmd_read_status(flash, &data[0]); - if (ret < 0) - return ret; + val = spi_flash_cmd_read_status(flash); + if (val < 0) + return val; + + data[0] = val; cmd = CMD_WRITE_STATUS; data[1] = wc; @@ -156,26 +155,20 @@ static void spi_flash_dual_flash(struct spi_flash *flash, u32 *addr) static inline int spi_flash_sr_ready(struct spi_flash *flash) { - u8 sr; - int ret; - - ret = spi_flash_cmd_read_status(flash, &sr); - if (ret < 0) - return ret; - - return !(sr & STATUS_WIP); + int sr = spi_flash_cmd_read_status(flash); + if (sr < 0) + return sr; + else + return !(sr & STATUS_WIP); } static inline int spi_flash_fsr_ready(struct spi_flash *flash) { - u8 fsr; - int ret; - - ret = read_fsr(flash, &fsr); - if (ret < 0) - return ret; - - return fsr & STATUS_PEC; + int fsr = read_fsr(flash); + if (fsr < 0) + return fsr; + else + return fsr & STATUS_PEC; } static int spi_flash_ready(struct spi_flash *flash) diff --git a/drivers/mtd/spi/sf_probe.c b/drivers/mtd/spi/sf_probe.c index 758347b..262849e 100644 --- a/drivers/mtd/spi/sf_probe.c +++ b/drivers/mtd/spi/sf_probe.c @@ -35,12 +35,11 @@ static u8 spi_read_cmds_array[] = { #ifdef CONFIG_SPI_FLASH_MACRONIX static int spi_flash_set_qeb_mxic(struct spi_flash *flash) { - u8 qeb_status; - int ret; + int qeb_status, ret; - ret = spi_flash_cmd_read_status(flash, &qeb_status); - if (ret < 0) - return ret; + qeb_status = spi_flash_cmd_read_config(flash); + if (qeb_status < 0) + return qeb_status; if (qeb_status & STATUS_QEB_MXIC) { debug("SF: mxic: QEB is already set\n"); @@ -57,12 +56,11 @@ static int spi_flash_set_qeb_mxic(struct spi_flash *flash) #if defined(CONFIG_SPI_FLASH_SPANSION) || defined(CONFIG_SPI_FLASH_WINBOND) static int spi_flash_set_qeb_winspan(struct spi_flash *flash) { - u8 qeb_status; - int ret; + int qeb_status, ret; - ret = spi_flash_cmd_read_config(flash, &qeb_status); - if (ret < 0) - return ret; + qeb_status = spi_flash_cmd_read_config(flash); + if (qeb_status < 0) + return qeb_status; if (qeb_status & STATUS_QEB_WINSPAN) { debug("SF: winspan: QEB is already set\n"); @@ -117,8 +115,7 @@ static int spi_flash_read_bank(struct spi_flash *flash, u8 idcode0) flash->bank_write_cmd = CMD_EXTNADDR_WREAR; } - ret = spi_flash_read_common(flash, &flash->bank_read_cmd, 1, - &curr_bank, 1); + ret = flash_read_reg(flash, flash->bank_read_cmd, &curr_bank, 1); if (ret) { debug("SF: fail to read bank addr register\n"); return ret;