public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Jagan Teki <jteki@openedev.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v5 04/14] sf: probe: Code cleanup
Date: Wed, 28 Oct 2015 00:07:46 +0530	[thread overview]
Message-ID: <1445971076-17270-4-git-send-email-jteki@openedev.com> (raw)
In-Reply-To: <1445971076-17270-1-git-send-email-jteki@openedev.com>

- Move bar read code below the bar write hance both
  at once place, hence it easy for #ifdef macro only
  once and readable.
- Move read_cmd_array at top

Signed-off-by: Jagan Teki <jteki@openedev.com>
---
 drivers/mtd/spi/sf_ops.c | 81 +++++++++++++++++++++++-------------------------
 1 file changed, 39 insertions(+), 42 deletions(-)

diff --git a/drivers/mtd/spi/sf_ops.c b/drivers/mtd/spi/sf_ops.c
index 016a5df..e20a3d6 100644
--- a/drivers/mtd/spi/sf_ops.c
+++ b/drivers/mtd/spi/sf_ops.c
@@ -29,6 +29,16 @@ static void spi_flash_addr(u32 addr, u8 *cmd)
 	cmd[3] = addr >> 0;
 }
 
+/* Read commands array */
+static u8 spi_read_cmds_array[] = {
+	CMD_READ_ARRAY_SLOW,
+	CMD_READ_ARRAY_FAST,
+	CMD_READ_DUAL_OUTPUT_FAST,
+	CMD_READ_DUAL_IO_FAST,
+	CMD_READ_QUAD_OUTPUT_FAST,
+	CMD_READ_QUAD_IO_FAST,
+};
+
 int spi_flash_cmd_read_status(struct spi_flash *flash, u8 *rs)
 {
 	int ret;
@@ -132,6 +142,35 @@ bar_end:
 	flash->bank_curr = bank_sel;
 	return flash->bank_curr;
 }
+
+static int spi_flash_read_bank(struct spi_flash *flash, u8 idcode0)
+{
+	u8 curr_bank = 0;
+	int ret;
+
+	if (flash->size <= SPI_FLASH_16MB_BOUN)
+		goto bank_end;
+
+	switch (idcode0) {
+	case SPI_FLASH_CFI_MFR_SPANSION:
+		flash->bank_read_cmd = CMD_BANKADDR_BRRD;
+		flash->bank_write_cmd = CMD_BANKADDR_BRWR;
+	default:
+		flash->bank_read_cmd = CMD_EXTNADDR_RDEAR;
+		flash->bank_write_cmd = CMD_EXTNADDR_WREAR;
+	}
+
+	ret = spi_flash_read_common(flash, &flash->bank_read_cmd, 1,
+				    &curr_bank, 1);
+	if (ret) {
+		debug("SF: fail to read bank addr register\n");
+		return ret;
+	}
+
+bank_end:
+	flash->bank_curr = curr_bank;
+	return 0;
+}
 #endif
 
 #ifdef CONFIG_SF_DUAL_FLASH
@@ -569,17 +608,6 @@ int sst_write_bp(struct spi_flash *flash, u32 offset, size_t len,
 }
 #endif
 
-
-/* Read commands array */
-static u8 spi_read_cmds_array[] = {
-	CMD_READ_ARRAY_SLOW,
-	CMD_READ_ARRAY_FAST,
-	CMD_READ_DUAL_OUTPUT_FAST,
-	CMD_READ_DUAL_IO_FAST,
-	CMD_READ_QUAD_OUTPUT_FAST,
-	CMD_READ_QUAD_IO_FAST,
-};
-
 #ifdef CONFIG_SPI_FLASH_MACRONIX
 static int spi_flash_set_qeb_mxic(struct spi_flash *flash)
 {
@@ -647,37 +675,6 @@ static int spi_flash_set_qeb(struct spi_flash *flash, u8 idcode0)
 	}
 }
 
-#ifdef CONFIG_SPI_FLASH_BAR
-static int spi_flash_read_bank(struct spi_flash *flash, u8 idcode0)
-{
-	u8 curr_bank = 0;
-	int ret;
-
-	if (flash->size <= SPI_FLASH_16MB_BOUN)
-		goto bank_end;
-
-	switch (idcode0) {
-	case SPI_FLASH_CFI_MFR_SPANSION:
-		flash->bank_read_cmd = CMD_BANKADDR_BRRD;
-		flash->bank_write_cmd = CMD_BANKADDR_BRWR;
-	default:
-		flash->bank_read_cmd = CMD_EXTNADDR_RDEAR;
-		flash->bank_write_cmd = CMD_EXTNADDR_WREAR;
-	}
-
-	ret = spi_flash_read_common(flash, &flash->bank_read_cmd, 1,
-				    &curr_bank, 1);
-	if (ret) {
-		debug("SF: fail to read bank addr register\n");
-		return ret;
-	}
-
-bank_end:
-	flash->bank_curr = curr_bank;
-	return 0;
-}
-#endif
-
 #if CONFIG_IS_ENABLED(OF_CONTROL)
 int spi_flash_decode_fdt(const void *blob, struct spi_flash *flash)
 {
-- 
1.9.1

  parent reply	other threads:[~2015-10-27 18:37 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-27 18:37 [U-Boot] [PATCH v5 01/14] sf: spi_flash_validate_params => spi_flash_scan Jagan Teki
2015-10-27 18:37 ` [U-Boot] [PATCH v5 02/14] sf: Move spi_flash_scan code to sf_ops Jagan Teki
2015-10-27 18:37 ` [U-Boot] [PATCH v5 03/14] sf: Move read_id " Jagan Teki
2015-10-27 18:37 ` Jagan Teki [this message]
2015-10-27 18:37 ` [U-Boot] [PATCH v5 05/14] sf: Use static for file-scope functions Jagan Teki
2015-10-27 18:37 ` [U-Boot] [PATCH v5 06/14] sf: Fix Makefile Jagan Teki
2015-10-27 18:37 ` [U-Boot] [PATCH v5 07/14] sf: Use simple name for register access functions Jagan Teki
2015-10-27 18:37 ` [U-Boot] [PATCH v5 08/14] sf: Use flash function pointers in dm_spi_flash_ops Jagan Teki
2015-10-27 18:37 ` [U-Boot] [PATCH v5 09/14] sf: Flash power up read-only based on idcode0 Jagan Teki
2015-10-27 18:37 ` [U-Boot] [PATCH v5 10/14] sf: Use static for file-scope functions Jagan Teki
2015-10-27 18:37 ` [U-Boot] [PATCH v5 11/14] sf: Remove unneeded header includes Jagan Teki
2015-10-27 18:37 ` [U-Boot] [PATCH v5 12/14] sf: probe: Use spi_flash_scan in dm-spi-flash Jagan Teki
2015-10-27 18:37 ` [U-Boot] [PATCH v5 13/14] sf: Re-factorize spi_flash_probe_tail code Jagan Teki
2015-10-27 18:37 ` [U-Boot] [PATCH v5 14/14] dm-sf: Re-factorize spi_flash_std_probe code Jagan Teki
2015-10-27 19:20   ` Troy Kisky
2015-10-28  5:18     ` Jagan Teki
2015-10-28  5:31       ` Bin Meng
2015-10-28  6:37         ` Jagan Teki

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1445971076-17270-4-git-send-email-jteki@openedev.com \
    --to=jteki@openedev.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox