Patchwork [U-Boot,03/13] spl mxc nand: Merge duplicated code

login
register
mail settings
Submitter Benoît Thébaudeau
Date Aug. 13, 2012, 8:48 p.m.
Message ID <1413177045.2374986.1344890936074.JavaMail.root@advansee.com>
Download mbox | patch
Permalink /patch/177087/
State Accepted
Commit 5d818a2821c3c7cf350ee4a2c67a11f8e1039af0
Delegated to: Scott Wood
Headers show

Comments

Benoît Thébaudeau - Aug. 13, 2012, 8:48 p.m.
Merge duplicated code into functions, which is better for SPL size too.

Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
Cc: Scott Wood <scottwood@freescale.com>
Cc: Stefano Babic <sbabic@denx.de>
---
 .../nand_spl/nand_boot_fsl_nfc.c                   |   50 +++++++++-----------
 1 file changed, 23 insertions(+), 27 deletions(-)
Stefano Babic - Aug. 14, 2012, 9:25 a.m.
On 13/08/2012 22:48, Benoît Thébaudeau wrote:
> Merge duplicated code into functions, which is better for SPL size too.
> 
> Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
> Cc: Scott Wood <scottwood@freescale.com>
> Cc: Stefano Babic <sbabic@denx.de>
> ---

Hi Benoît,

>  .../nand_spl/nand_boot_fsl_nfc.c                   |   50 +++++++++-----------
>  1 file changed, 23 insertions(+), 27 deletions(-)
> 
> diff --git u-boot-4d3c95f.orig/nand_spl/nand_boot_fsl_nfc.c u-boot-4d3c95f/nand_spl/nand_boot_fsl_nfc.c
> index b90f93e..b98fe41 100644
> --- u-boot-4d3c95f.orig/nand_spl/nand_boot_fsl_nfc.c
> +++ u-boot-4d3c95f/nand_spl/nand_boot_fsl_nfc.c
> @@ -83,37 +83,35 @@ static void nfc_nand_command(unsigned short command)
>  	nfc_wait_ready();
>  }

Surely a good issue to fix if we go on using nand_spl - however, as I
said in my previous e-mail, nand_spl is obsolete and we move to the SPL
framework.

Best regards,
Stefano Babic

Patch

diff --git u-boot-4d3c95f.orig/nand_spl/nand_boot_fsl_nfc.c u-boot-4d3c95f/nand_spl/nand_boot_fsl_nfc.c
index b90f93e..b98fe41 100644
--- u-boot-4d3c95f.orig/nand_spl/nand_boot_fsl_nfc.c
+++ u-boot-4d3c95f/nand_spl/nand_boot_fsl_nfc.c
@@ -83,37 +83,35 @@  static void nfc_nand_command(unsigned short command)
 	nfc_wait_ready();
 }
 
+static void nfc_nand_address(unsigned short address)
+{
+	writew(address, &nfc->flash_addr);
+	writew(NFC_ADDR, &nfc->config2);
+	nfc_wait_ready();
+}
+
 static void nfc_nand_page_address(unsigned int page_address)
 {
 	unsigned int page_count;
 
-	writew(0x00, &nfc->flash_addr);
-	writew(NFC_ADDR, &nfc->config2);
-	nfc_wait_ready();
+	nfc_nand_address(0x00);
 
 	/* code only for large page flash */
-	if (CONFIG_SYS_NAND_PAGE_SIZE > 512) {
-		writew(0x00, &nfc->flash_addr);
-		writew(NFC_ADDR, &nfc->config2);
-		nfc_wait_ready();
-	}
+	if (CONFIG_SYS_NAND_PAGE_SIZE > 512)
+		nfc_nand_address(0x00);
 
 	page_count = CONFIG_SYS_NAND_SIZE / CONFIG_SYS_NAND_PAGE_SIZE;
 
 	if (page_address <= page_count) {
 		page_count--; /* transform 0x01000000 to 0x00ffffff */
 		do {
-			writew(page_address & 0xff, &nfc->flash_addr);
-			writew(NFC_ADDR, &nfc->config2);
-			nfc_wait_ready();
+			nfc_nand_address(page_address & 0xff);
 			page_address = page_address >> 8;
 			page_count = page_count >> 8;
 		} while (page_count);
 	}
 
-	writew(0x00, &nfc->flash_addr);
-	writew(NFC_ADDR, &nfc->config2);
-	nfc_wait_ready();
+	nfc_nand_address(0x00);
 }
 
 static void nfc_nand_data_output(void)
@@ -149,12 +147,8 @@  static int nfc_nand_check_ecc(void)
 	return readw(&nfc->ecc_status_result);
 }
 
-static int nfc_read_page(unsigned int page_address, unsigned char *buf)
+static void nfc_nand_read_page(unsigned int page_address)
 {
-	int i;
-	u32 *src;
-	u32 *dst;
-
 	writew(0, &nfc->buf_addr); /* read in first 0 buffer */
 	nfc_nand_command(NAND_CMD_READ0);
 	nfc_nand_page_address(page_address);
@@ -163,6 +157,15 @@  static int nfc_read_page(unsigned int page_address, unsigned char *buf)
 		nfc_nand_command(NAND_CMD_READSTART);
 
 	nfc_nand_data_output(); /* fill the main buffer 0 */
+}
+
+static int nfc_read_page(unsigned int page_address, unsigned char *buf)
+{
+	int i;
+	u32 *src;
+	u32 *dst;
+
+	nfc_nand_read_page(page_address);
 
 	if (nfc_nand_check_ecc())
 		return -1;
@@ -188,14 +191,7 @@  static int is_badblock(int pagenumber)
 
 	/* Check the first two pages for bad block markers */
 	for (page = pagenumber; page < pagenumber + 2; page++) {
-		writew(0, &nfc->buf_addr); /* read in first 0 buffer */
-		nfc_nand_command(NAND_CMD_READ0);
-		nfc_nand_page_address(page);
-
-		if (CONFIG_SYS_NAND_PAGE_SIZE > 512)
-			nfc_nand_command(NAND_CMD_READSTART);
-
-		nfc_nand_data_output(); /* fill the main buffer 0 */
+		nfc_nand_read_page(page);
 
 		src = (u32 *)&nfc->spare_area[0][0];