Skip to contentSkip to conversation

cfi flash: add status polling method for amd flash

PATCH New Thomas Chou 4 participants 13 messages Mar 23, 2010 – Mar 26, 2010 Memory technology devices (MTD)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cfi flash: add status polling method for amd flash

This patch adds status polling method to offer an alternative to data toggle method for amd flash chips.

This patch is needed for nios2 cfi flash interface, where the bus controller performs 4 bytes read cycles for a single byte read instruction. The data toggle method can not detect chip busy status correctly. So we have to poll DQ7, which will be inverted when the chip is busy.

This feature is enabled with the config def,
CONFIG_SYS_CFI_FLASH_STATUS_POLL

Include patch, "drivers/mtd/cfi_flash: precision and underflow problem in tout calculation", submitted by
Alessandro Rubini <[email protected]>
Renato Andreola <[email protected]>

---
 drivers/mtd/cfi_flash.c |   78 ++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 77 insertions(+), 1 deletions(-)
drivers/mtd/cfi_flash.c +77 -1
index fdba297..db22255 100644
@@ -537,7 +537,10 @@ static int flash_status_check (flash_info_t * info, flash_sect_t sector,
 	ulong start;
 
 #if CONFIG_SYS_HZ != 1000
-	tout *= CONFIG_SYS_HZ/1000;
+	if ((ulong)CONFIG_SYS_HZ > 100000)
+		tout *= (ulong)CONFIG_SYS_HZ / 1000;  /* for a big HZ, avoid overflow */
+	else
+		tout = DIV_ROUND_UP (tout * (ulong)CONFIG_SYS_HZ, 1000);
 #endif
 
 	/* Wait for command completion */
@@ -555,6 +558,53 @@ static int flash_status_check (flash_info_t * info, flash_sect_t sector,
 	return ERR_OK;
 }
 
+#ifdef CONFIG_SYS_CFI_FLASH_STATUS_POLL
+static int flash_status_poll (flash_info_t *info, void *src, void *dst,
+			     ulong tout, char *prompt)
+{
+	ulong start;
+	int ready;
+
+#if CONFIG_SYS_HZ != 1000
+	if ((ulong)CONFIG_SYS_HZ > 100000)
+		tout *= (ulong)CONFIG_SYS_HZ / 1000;  /* for a big HZ, avoid overflow */
+	else
+		tout = DIV_ROUND_UP (tout * (ulong)CONFIG_SYS_HZ, 1000);
+#endif
+
+	/* Wait for command completion */
+	start = get_timer (0);
+	while (1) {
+		switch (info->portwidth) {
+		case FLASH_CFI_8BIT:
+			ready = flash_read8(dst) == flash_read8(src);
+			break;
+		case FLASH_CFI_16BIT:
+			ready = flash_read16(dst) == flash_read16(src);
+			break;
+		case FLASH_CFI_32BIT:
+			ready = flash_read32(dst) == flash_read32(src);
+			break;
+		case FLASH_CFI_64BIT:
+			ready = flash_read64(dst) == flash_read64(src);
+			break;
+		default:
+			ready = 0;
+			break;
+		}
+		if (ready)
+			break;
+		if (get_timer (start) > tout) {
+			printf ("Flash %s timeout at address %lx data %lx\n",
+			       prompt, (ulong)dst, (ulong)flash_read8(dst));
+			return ERR_TIMOUT;
+		}
+		udelay (1);		/* also triggers watchdog */
+	}
+	return ERR_OK;
+}
+#endif
+
 /*-----------------------------------------------------------------------
  * Wait for XSR.7 to be set, if it times out print an error, otherwise
  * do a full status check.
@@ -749,6 +799,13 @@ static int flash_write_cfiword (flash_info_t * info, ulong dest,
 	if (!sect_found)
 		sect = find_sector (info, dest);
 
+#ifdef CONFIG_SYS_CFI_FLASH_STATUS_POLL
+	if (info->vendor == CFI_CMDSET_AMD_EXTENDED ||
+	    info->vendor == CFI_CMDSET_AMD_STANDARD)
+		return flash_status_poll (info, &cword, dstaddr,
+					 info->write_tout, "write");
+	else
+#endif
 	return flash_full_status_check (info, sect, info->write_tout, "write");
 }
 
@@ -911,9 +968,14 @@ static int flash_write_cfibuffer (flash_info_t * info, ulong dest, uchar * cp,
 		}
 
 		flash_write_cmd (info, sector, 0, AMD_CMD_WRITE_BUFFER_CONFIRM);
+#ifdef CONFIG_SYS_CFI_FLASH_STATUS_POLL
+		retcode = flash_status_poll (info, src - (1 << shift),
+			dst - (1 << shift), info->buffer_write_tout, "buffer write");
+#else
 		retcode = flash_full_status_check (info, sector,
 						   info->buffer_write_tout,
 						   "buffer write");
+#endif
 		break;
 
 	default:
@@ -935,6 +997,10 @@ int flash_erase (flash_info_t * info, int s_first, int s_last)
 	int rcode = 0;
 	int prot;
 	flash_sect_t sect;
+#ifdef CONFIG_SYS_CFI_FLASH_STATUS_POLL
+	cfiword_t cword = (cfiword_t)0xffffffffffffffffULL;
+	void *dest;
+#endif
 
 	if (info->flash_id != FLASH_MAN_CFI) {
 		puts ("Can't erase unknown flash type - aborted\n");
@@ -998,6 +1064,16 @@ int flash_erase (flash_info_t * info, int s_first, int s_last)
 				break;
 			}
 
+#ifdef CONFIG_SYS_CFI_FLASH_STATUS_POLL
+			dest = flash_map (info, sect, 0);
+			flash_unmap (info, sect, 0, dest);
+			if ((info->vendor == CFI_CMDSET_AMD_EXTENDED ||
+			     info->vendor == CFI_CMDSET_AMD_STANDARD) &&
+			    flash_status_poll (info, &cword, dest,
+					      info->erase_blk_tout, "erase"))
+				rcode = 1;
+			else
+#endif
 			if (flash_full_status_check
 			    (info, sect, info->erase_blk_tout, "erase")) {
 				rcode = 1;
Signature · 1 line
1.6.6.1
#1 lore raw

PATCH 1/1 cfi flash: add status polling method for amd flash

Hi Thomas,

Quoted 9 lines · On Tuesday 23 March 2010 04:24:08 Thomas Chou wrote:

This patch adds status polling method to offer an alternative to data toggle method for amd flash chips.

This patch is needed for nios2 cfi flash interface, where the bus controller performs 4 bytes read cycles for a single byte read instruction. The data toggle method can not detect chip busy status correctly. So we have to poll DQ7, which will be inverted when the chip is busy.

Quoted 7 lines

This feature is enabled with the config def,
CONFIG_SYS_CFI_FLASH_STATUS_POLL

Include patch, "drivers/mtd/cfi_flash: precision and underflow problem in tout calculation", submitted by
Alessandro Rubini <[email protected]>
Renato Andreola <[email protected]>

Thanks for taking care of this. But we shouldn't really integrate this patch into your flash_status_poll() patch. Please re-send this part as a separate patch (some subject as original patch with S-o-b line of original author please). Thanks again for this.

Please find still more enhancement suggestions below.

Quoted 11 lines
---
 drivers/mtd/cfi_flash.c |   78

++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 77 insertions(+), 1 deletions(-)

drivers/mtd/cfi_flash.c +0 -0
index fdba297..db22255 100644

drivers/mtd/cfi_flash.c static int flash_status_check (flash_info_t * info, · line 541

Quoted 6 lines
drivers/mtd/cfi_flash.c +2 -1
@@ -537,7 +537,10 @@ static int flash_status_check (flash_info_t * info,
 flash_sect_t sector, ulong start;
 
 #if CONFIG_SYS_HZ != 1000
-	tout *= CONFIG_SYS_HZ/1000;
+	if ((ulong)CONFIG_SYS_HZ > 100000)
+		tout *= (ulong)CONFIG_SYS_HZ / 1000;  /* for a big HZ, avoid 

overflow */

Quoted 9 lines
drivers/mtd/cfi_flash.c +2 -0
+	else
+		tout = DIV_ROUND_UP (tout * (ulong)CONFIG_SYS_HZ, 1000);
 #endif
 
 	/* Wait for command completion */
@@ -555,6 +558,53 @@ static int flash_status_check (flash_info_t * info,
 flash_sect_t sector, return ERR_OK;
 }
 

drivers/mtd/cfi_flash.c static int flash_status_check (flash_info_t * info, · line 570

Quoted 10 lines
drivers/mtd/cfi_flash.c +10 -0
+#ifdef CONFIG_SYS_CFI_FLASH_STATUS_POLL
+static int flash_status_poll (flash_info_t *info, void *src, void *dst,
+			     ulong tout, char *prompt)
+{
+	ulong start;
+	int ready;
+
+#if CONFIG_SYS_HZ != 1000
+	if ((ulong)CONFIG_SYS_HZ > 100000)
+		tout *= (ulong)CONFIG_SYS_HZ / 1000;  /* for a big HZ, avoid 

overflow */

Quoted 42 lines
drivers/mtd/cfi_flash.c +37 -0
+	else
+		tout = DIV_ROUND_UP (tout * (ulong)CONFIG_SYS_HZ, 1000);
+#endif
+
+	/* Wait for command completion */
+	start = get_timer (0);
+	while (1) {
+		switch (info->portwidth) {
+		case FLASH_CFI_8BIT:
+			ready = flash_read8(dst) == flash_read8(src);
+			break;
+		case FLASH_CFI_16BIT:
+			ready = flash_read16(dst) == flash_read16(src);
+			break;
+		case FLASH_CFI_32BIT:
+			ready = flash_read32(dst) == flash_read32(src);
+			break;
+		case FLASH_CFI_64BIT:
+			ready = flash_read64(dst) == flash_read64(src);
+			break;
+		default:
+			ready = 0;
+			break;
+		}
+		if (ready)
+			break;
+		if (get_timer (start) > tout) {
+			printf ("Flash %s timeout at address %lx data %lx\n",
+			       prompt, (ulong)dst, (ulong)flash_read8(dst));
+			return ERR_TIMOUT;
+		}
+		udelay (1);		/* also triggers watchdog */
+	}
+	return ERR_OK;
+}
+#endif
+
 /*-----------------------------------------------------------------------
  * Wait for XSR.7 to be set, if it times out print an error, otherwise
  * do a full status check.
@@ -749,6 +799,13 @@ static int flash_write_cfiword (flash_info_t * info,
 ulong dest, if (!sect_found)

drivers/mtd/cfi_flash.c static int flash_write_cfiword (flash_info_t * info, · line 809

Quoted 10 lines
drivers/mtd/cfi_flash.c +7 -0
 		sect = find_sector (info, dest);
 
+#ifdef CONFIG_SYS_CFI_FLASH_STATUS_POLL
+	if (info->vendor == CFI_CMDSET_AMD_EXTENDED ||
+	    info->vendor == CFI_CMDSET_AMD_STANDARD)
+		return flash_status_poll (info, &cword, dstaddr,
+					 info->write_tout, "write");
+	else
+#endif
 	return flash_full_status_check (info, sect, info->write_tout, 

"write");

I don't like this ugly "incorrect" indentation of the line below the "#endif" above. Perhaps you could implement this in another way. By moving the #ifdef and the vendor == amd check into a separate function:

static int use_flash_status_poll(flash_info_t *info) {

#ifdef CONFIG_SYS_CFI_FLASH_STATUS_POLL
	if (info->vendor == CFI_CMDSET_AMD_EXTENDED ||
	    info->vendor == CFI_CMDSET_AMD_STANDARD)
		return 1;
#endif
	return 0;
}

And then use this code in flash_write_cfiword():

	if (use_flash_status_poll(info)) {
		return flash_status_poll(info, &cword, dstaddr,
					 info->write_tout, "write");
	} else {
		return flash_full_status_check(info, sect,
					       info->write_tout, "write");
	}

What do you think? Looks nicer to me. And we only need to implement this vendor == AMD check once (see below).

drivers/mtd/cfi_flash.c static int flash_write_cfibuffer (flash_info_t * info, · line 970

Quoted 6 lines
drivers/mtd/cfi_flash.c +0 -0
 }
 
@@ -911,9 +968,14 @@ static int flash_write_cfibuffer (flash_info_t * info,
 ulong dest, uchar * cp, }
 
 		flash_write_cmd (info, sector, 0, 

AMD_CMD_WRITE_BUFFER_CONFIRM);

drivers/mtd/cfi_flash.c static int flash_write_cfibuffer (flash_info_t * info, ulong dest, uchar * cp,

Quoted 3 lines
drivers/mtd/cfi_flash.c +3 -0
+#ifdef CONFIG_SYS_CFI_FLASH_STATUS_POLL
+		retcode = flash_status_poll (info, src - (1 << shift),
+			dst - (1 << shift), info->buffer_write_tout, "buffer 

write");

Quoted 23 lines
drivers/mtd/cfi_flash.c +6 -0
+#else
 		retcode = flash_full_status_check (info, sector,
 						   info->buffer_write_tout,
 						   "buffer write");
+#endif
 		break;
 
 	default:
@@ -935,6 +997,10 @@ int flash_erase (flash_info_t * info, int s_first, int
 s_last) int rcode = 0;
 	int prot;
 	flash_sect_t sect;
+#ifdef CONFIG_SYS_CFI_FLASH_STATUS_POLL
+	cfiword_t cword = (cfiword_t)0xffffffffffffffffULL;
+	void *dest;
+#endif
 
 	if (info->flash_id != FLASH_MAN_CFI) {
 		puts ("Can't erase unknown flash type - aborted\n");
@@ -998,6 +1064,16 @@ int flash_erase (flash_info_t * info, int s_first,
 int s_last) break;
 			}
 

drivers/mtd/cfi_flash.c int flash_erase (flash_info_t * info, int s_first, · line 1076

Quoted 10 lines
drivers/mtd/cfi_flash.c +10 -0
+#ifdef CONFIG_SYS_CFI_FLASH_STATUS_POLL
+			dest = flash_map (info, sect, 0);
+			flash_unmap (info, sect, 0, dest);
+			if ((info->vendor == CFI_CMDSET_AMD_EXTENDED ||
+			     info->vendor == CFI_CMDSET_AMD_STANDARD) &&
+			    flash_status_poll (info, &cword, dest,
+					      info->erase_blk_tout, "erase"))
+				rcode = 1;
+			else
+#endif

Again, you could use the newly created function here.

Please give it a try and let me know if this works.

Thanks.

Cheers,
Stefan

--
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-0 Fax: (+49)-8142-66989-80 Email: office at denx.de

#2 lore raw

PATCH 1/1 cfi flash: add status polling method for amd flash

Quoted 21 lines · Stefan Roese

Hi Thomas,

Quoted 9 lines · On Tuesday 23 March 2010 04:24:08 Thomas Chou wrote:

This patch adds status polling method to offer an alternative to data toggle method for amd flash chips.

This patch is needed for nios2 cfi flash interface, where the bus controller performs 4 bytes read cycles for a single byte read instruction. The data toggle method can not detect chip busy status correctly. So we have to poll DQ7, which will be inverted when the chip is busy.

Quoted 8 lines

This feature is enabled with the config def,
CONFIG_SYS_CFI_FLASH_STATUS_POLL

Include patch, "drivers/mtd/cfi_flash: precision and underflow problem in tout calculation", submitted by
Alessandro Rubini<[email protected]>
Renato Andreola<[email protected]>

Quoted 7 lines

Thanks for taking care of this. But we shouldn't really integrate this patch into your flash_status_poll() patch. Please re-send this part as a separate patch (some subject as original patch with S-o-b line of original author please). Thanks again for this.

Please find still more enhancement suggestions below.

Hi Stefen,

I resent the tout patch from Renato. I have updated and tested the status poll patch as you suggested. Any suggestion and improvement is always welcome.

Cheers,
Thomas

#3 lore raw

PATCH 1/1 cfi flash: add status polling method for amd flash

In reply to Thomas Chou
Quoted 1 line
Quoted 1 line

With 16 bit flash configurations I suppose the Avalon bus will do four Word reads instead of a single one

Supposedly it will do two Word reads, of course, still resulting in the same problem.

-Michael

#4 lore raw

PATCH 1/1 cfi flash: add status polling method for amd flash

Quoted 4 lines · Michael Schnell
Quoted 2 lines
Quoted 2 lines

With 16 bit flash configurations I suppose the Avalon bus will do four Word reads instead of a single one

Supposedly it will do two Word reads, of course, still resulting in the same problem.

Hi Michael,

The write cycle of the avalon bus controller is correct. Just the read cycle (8 bits or 16 bits) caused problem with toggle status checking.

There is no problem with Intel flash, because the busy checking is different.

In u-boot, there are nios2 specific flash drivers (board/altera/common/flash.c and AMDLV065D.c) to handle status polling for amd flash. But they didn't use the cfi info to detect flash parameters. You have to define them for each board.

I have tested 8 bits/16 bits amd flash and 16 bits intel flash on four altera dev boards without problem.

- Thomas

#5 lore raw

PATCH v4 1/1 cfi flash: add status polling method for amd flash

In reply to Thomas Chou

This patch adds status polling method to offer an alternative to data toggle method for amd flash chips.

This patch is needed for nios2 cfi flash interface, where the bus controller performs 4 bytes read cycles for a single byte read instruction. The data toggle method can not detect chip busy status correctly. So we have to poll DQ7, which will be inverted when the chip is busy.

This feature is enabled with the config def,
CONFIG_SYS_CFI_FLASH_STATUS_POLL

In flash_erase, the verbose printing of '.' is changed that it will go with each sector whether successed or failed.

---
 drivers/mtd/cfi_flash.c |   95 +++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 87 insertions(+), 8 deletions(-)
drivers/mtd/cfi_flash.c +87 -8
index cd1a86e..aae93bd 100644
@@ -605,6 +605,63 @@ static int flash_full_status_check (flash_info_t * info, flash_sect_t sector,
 	return retcode;
 }
 
+static int use_flash_status_poll(flash_info_t *info)
+{
+#ifdef CONFIG_SYS_CFI_FLASH_STATUS_POLL
+	if (info->vendor == CFI_CMDSET_AMD_EXTENDED ||
+	    info->vendor == CFI_CMDSET_AMD_STANDARD)
+		return 1;
+#endif
+	return 0;
+}
+
+static int flash_status_poll(flash_info_t *info, void *src, void *dst,
+			     ulong tout, char *prompt)
+{
+#ifdef CONFIG_SYS_CFI_FLASH_STATUS_POLL
+	ulong start;
+	int ready;
+
+#if CONFIG_SYS_HZ != 1000
+	if ((ulong)CONFIG_SYS_HZ > 100000)
+		tout *= (ulong)CONFIG_SYS_HZ / 1000;  /* for a big HZ, avoid overflow */
+	else
+		tout = DIV_ROUND_UP(tout * (ulong)CONFIG_SYS_HZ, 1000);
+#endif
+
+	/* Wait for command completion */
+	start = get_timer(0);
+	while (1) {
+		switch (info->portwidth) {
+		case FLASH_CFI_8BIT:
+			ready = flash_read8(dst) == flash_read8(src);
+			break;
+		case FLASH_CFI_16BIT:
+			ready = flash_read16(dst) == flash_read16(src);
+			break;
+		case FLASH_CFI_32BIT:
+			ready = flash_read32(dst) == flash_read32(src);
+			break;
+		case FLASH_CFI_64BIT:
+			ready = flash_read64(dst) == flash_read64(src);
+			break;
+		default:
+			ready = 0;
+			break;
+		}
+		if (ready)
+			break;
+		if (get_timer(start) > tout) {
+			printf("Flash %s timeout at address %lx data %lx\n",
+			       prompt, (ulong)dst, (ulong)flash_read8(dst));
+			return ERR_TIMOUT;
+		}
+		udelay(1);		/* also triggers watchdog */
+	}
+#endif /* CONFIG_SYS_CFI_FLASH_STATUS_POLL */
+	return ERR_OK;
+}
+
 /*-----------------------------------------------------------------------
  */
 static void flash_add_byte (flash_info_t * info, cfiword_t * cword, uchar c)
@@ -752,7 +809,12 @@ static int flash_write_cfiword (flash_info_t * info, ulong dest,
 	if (!sect_found)
 		sect = find_sector (info, dest);
 
-	return flash_full_status_check (info, sect, info->write_tout, "write");
+	if (use_flash_status_poll(info))
+		return flash_status_poll(info, &cword, dstaddr,
+					 info->write_tout, "write");
+	else
+		return flash_full_status_check(info, sect,
+					       info->write_tout, "write");
 }
 
 #ifdef CONFIG_SYS_FLASH_USE_BUFFER_WRITE
@@ -914,9 +976,15 @@ static int flash_write_cfibuffer (flash_info_t * info, ulong dest, uchar * cp,
 		}
 
 		flash_write_cmd (info, sector, 0, AMD_CMD_WRITE_BUFFER_CONFIRM);
-		retcode = flash_full_status_check (info, sector,
-						   info->buffer_write_tout,
-						   "buffer write");
+		if (use_flash_status_poll(info))
+			retcode = flash_status_poll(info, src - (1 << shift),
+						    dst - (1 << shift),
+						    info->buffer_write_tout,
+						    "buffer write");
+		else
+			retcode = flash_full_status_check(info, sector,
+							  info->buffer_write_tout,
+							  "buffer write");
 		break;
 
 	default:
@@ -1001,10 +1069,21 @@ int flash_erase (flash_info_t * info, int s_first, int s_last)
 				break;
 			}
 
-			if (flash_full_status_check
-			    (info, sect, info->erase_blk_tout, "erase")) {
-				rcode = 1;
-			} else if (flash_verbose)
+			if (use_flash_status_poll(info)) {
+				cfiword_t cword = (cfiword_t)0xffffffffffffffffULL;
+				void *dest;
+				dest = flash_map(info, sect, 0);
+				if (flash_status_poll(info, &cword, dest,
+						      info->erase_blk_tout, "erase"))
+					rcode = 1;
+				flash_unmap(info, sect, 0, dest);
+			} else {
+				if (flash_full_status_check(info, sect,
+							    info->erase_blk_tout,
+							    "erase"))
+					rcode = 1;
+			}
+			if (flash_verbose)
 				putc ('.');
 		}
 	}
Signature · 1 line
1.6.6.1
#6 lore raw

PATCH v4 1/1 cfi flash: add status polling method for amd flash

Quoted 9 lines · On Wednesday 24 March 2010 03:29:21 Thomas Chou wrote:

This patch adds status polling method to offer an alternative to data toggle method for amd flash chips.

This patch is needed for nios2 cfi flash interface, where the bus controller performs 4 bytes read cycles for a single byte read instruction. The data toggle method can not detect chip busy status correctly. So we have to poll DQ7, which will be inverted when the chip is busy.

Quoted 5 lines

This feature is enabled with the config def,
CONFIG_SYS_CFI_FLASH_STATUS_POLL

In flash_erase, the verbose printing of '.' is changed that it will go with each sector whether successed or failed.

Applied to u-boot-cfi-flash/next. Thanks.

Cheers,
Stefan

--
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-0 Fax: (+49)-8142-66989-80 Email: office at denx.de

#7 lore raw

PATCH v4 1/1 cfi flash: add status polling method for amd flash

Dear Stefan Roese,

Quoted 10 lines · In message <[email protected]> you wrote:
Quoted 9 lines · On Wednesday 24 March 2010 03:29:21 Thomas Chou wrote:

This patch adds status polling method to offer an alternative to data toggle method for amd flash chips.

This patch is needed for nios2 cfi flash interface, where the bus controller performs 4 bytes read cycles for a single byte read instruction. The data toggle method can not detect chip busy status correctly. So we have to poll DQ7, which will be inverted when the chip is busy.

Quoted 7 lines
Quoted 5 lines

This feature is enabled with the config def,
CONFIG_SYS_CFI_FLASH_STATUS_POLL

In flash_erase, the verbose printing of '.' is changed that it will go with each sector whether successed or failed.

Applied to u-boot-cfi-flash/next. Thanks.

I object against pulling in a global change to the user interface just like that, without any discussion.

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
No journaling file system can recover your data if the disk dies.
                                 - Steve Rago in <[email protected]>
#8 lore raw

PATCH v4 1/1 cfi flash: add status polling method for amd flash

Hi Wolfgang,

Quoted 7 lines · On Thursday 25 March 2010 12:49:54 Wolfgang Denk wrote:
Quoted 4 lines
Quoted 2 lines

In flash_erase, the verbose printing of '.' is changed that it will go with each sector whether successed or failed.

Applied to u-boot-cfi-flash/next. Thanks.

I object against pulling in a global change to the user interface just like that, without any discussion.

OK, I'll remove this patch and push the new version soon.

Cheers,
Stefan

--
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-0 Fax: (+49)-8142-66989-80 Email: office at denx.de

#9 lore raw

PATCH v4 1/1 cfi flash: add status polling method for amd flash

In reply to Thomas Chou

Dear Thomas Chou,

Quoted 9 lines · In message <[email protected]> you wrote:

This patch adds status polling method to offer an alternative to data toggle method for amd flash chips.

This patch is needed for nios2 cfi flash interface, where the bus controller performs 4 bytes read cycles for a single byte read instruction. The data toggle method can not detect chip busy status correctly. So we have to poll DQ7, which will be inverted when the chip is busy.

Quoted 5 lines

This feature is enabled with the config def,
CONFIG_SYS_CFI_FLASH_STATUS_POLL

In flash_erase, the verbose printing of '.' is changed that it will go with each sector whether successed or failed.

Please split this part off into a separate patch. This is a global change to the user interface and must be discussed separately.

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
The easiest way to figure the cost of living is to take  your  income
and add ten percent.
#10 lore raw

PATCH v4 1/1 cfi flash: add status polling method for amd flash

Quoted 19 lines · Wolfgang Denk

Dear Thomas Chou,

Quoted 9 lines · In message<[email protected]> you wrote:

This patch adds status polling method to offer an alternative to data toggle method for amd flash chips.

This patch is needed for nios2 cfi flash interface, where the bus controller performs 4 bytes read cycles for a single byte read instruction. The data toggle method can not detect chip busy status correctly. So we have to poll DQ7, which will be inverted when the chip is busy.

Quoted 6 lines

This feature is enabled with the config def,
CONFIG_SYS_CFI_FLASH_STATUS_POLL

In flash_erase, the verbose printing of '.' is changed that it will go with each sector whether successed or failed.

Quoted 8 lines

Please split this part off into a separate patch. This is a global change to the user interface and must be discussed separately.

Best regards,

Wolfgang Denk

Hi Wolfgang and Stefan,

I will restore the original printing so that the user interface won't change.

Best regards,
Thomas

#11 lore raw

PATCH v5 1/1 cfi flash: add status polling method for amd flash

In reply to Thomas Chou

This patch adds status polling method to offer an alternative to data toggle method for amd flash chips.

This patch is needed for nios2 cfi flash interface, where the bus controller performs 4 bytes read cycles for a single byte read instruction. The data toggle method can not detect chip busy status correctly. So we have to poll DQ7, which will be inverted when the chip is busy.

This feature is enabled with the config def,
CONFIG_SYS_CFI_FLASH_STATUS_POLL

---
 drivers/mtd/cfi_flash.c |   99 ++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 90 insertions(+), 9 deletions(-)
drivers/mtd/cfi_flash.c +90 -9
index cd1a86e..8d2c623 100644
@@ -605,6 +605,63 @@ static int flash_full_status_check (flash_info_t * info, flash_sect_t sector,
 	return retcode;
 }
 
+static int use_flash_status_poll(flash_info_t *info)
+{
+#ifdef CONFIG_SYS_CFI_FLASH_STATUS_POLL
+	if (info->vendor == CFI_CMDSET_AMD_EXTENDED ||
+	    info->vendor == CFI_CMDSET_AMD_STANDARD)
+		return 1;
+#endif
+	return 0;
+}
+
+static int flash_status_poll(flash_info_t *info, void *src, void *dst,
+			     ulong tout, char *prompt)
+{
+#ifdef CONFIG_SYS_CFI_FLASH_STATUS_POLL
+	ulong start;
+	int ready;
+
+#if CONFIG_SYS_HZ != 1000
+	if ((ulong)CONFIG_SYS_HZ > 100000)
+		tout *= (ulong)CONFIG_SYS_HZ / 1000;  /* for a big HZ, avoid overflow */
+	else
+		tout = DIV_ROUND_UP(tout * (ulong)CONFIG_SYS_HZ, 1000);
+#endif
+
+	/* Wait for command completion */
+	start = get_timer(0);
+	while (1) {
+		switch (info->portwidth) {
+		case FLASH_CFI_8BIT:
+			ready = flash_read8(dst) == flash_read8(src);
+			break;
+		case FLASH_CFI_16BIT:
+			ready = flash_read16(dst) == flash_read16(src);
+			break;
+		case FLASH_CFI_32BIT:
+			ready = flash_read32(dst) == flash_read32(src);
+			break;
+		case FLASH_CFI_64BIT:
+			ready = flash_read64(dst) == flash_read64(src);
+			break;
+		default:
+			ready = 0;
+			break;
+		}
+		if (ready)
+			break;
+		if (get_timer(start) > tout) {
+			printf("Flash %s timeout at address %lx data %lx\n",
+			       prompt, (ulong)dst, (ulong)flash_read8(dst));
+			return ERR_TIMOUT;
+		}
+		udelay(1);		/* also triggers watchdog */
+	}
+#endif /* CONFIG_SYS_CFI_FLASH_STATUS_POLL */
+	return ERR_OK;
+}
+
 /*-----------------------------------------------------------------------
  */
 static void flash_add_byte (flash_info_t * info, cfiword_t * cword, uchar c)
@@ -752,7 +809,12 @@ static int flash_write_cfiword (flash_info_t * info, ulong dest,
 	if (!sect_found)
 		sect = find_sector (info, dest);
 
-	return flash_full_status_check (info, sect, info->write_tout, "write");
+	if (use_flash_status_poll(info))
+		return flash_status_poll(info, &cword, dstaddr,
+					 info->write_tout, "write");
+	else
+		return flash_full_status_check(info, sect,
+					       info->write_tout, "write");
 }
 
 #ifdef CONFIG_SYS_FLASH_USE_BUFFER_WRITE
@@ -914,9 +976,15 @@ static int flash_write_cfibuffer (flash_info_t * info, ulong dest, uchar * cp,
 		}
 
 		flash_write_cmd (info, sector, 0, AMD_CMD_WRITE_BUFFER_CONFIRM);
-		retcode = flash_full_status_check (info, sector,
-						   info->buffer_write_tout,
-						   "buffer write");
+		if (use_flash_status_poll(info))
+			retcode = flash_status_poll(info, src - (1 << shift),
+						    dst - (1 << shift),
+						    info->buffer_write_tout,
+						    "buffer write");
+		else
+			retcode = flash_full_status_check(info, sector,
+							  info->buffer_write_tout,
+							  "buffer write");
 		break;
 
 	default:
@@ -1001,11 +1069,24 @@ int flash_erase (flash_info_t * info, int s_first, int s_last)
 				break;
 			}
 
-			if (flash_full_status_check
-			    (info, sect, info->erase_blk_tout, "erase")) {
-				rcode = 1;
-			} else if (flash_verbose)
-				putc ('.');
+			if (use_flash_status_poll(info)) {
+				cfiword_t cword = (cfiword_t)0xffffffffffffffffULL;
+				void *dest;
+				dest = flash_map(info, sect, 0);
+				if (flash_status_poll(info, &cword, dest,
+						      info->erase_blk_tout, "erase"))
+					rcode = 1;
+				else if (flash_verbose)
+					putc('.');
+				flash_unmap(info, sect, 0, dest);
+			} else {
+				if (flash_full_status_check(info, sect,
+							    info->erase_blk_tout,
+							    "erase"))
+					rcode = 1;
+				else if (flash_verbose)
+					putc('.');
+			}
 		}
 	}
 
Signature · 1 line
1.6.6.1
#12 lore raw

PATCH v6 1/1 cfi flash: add status polling method for amd flash

In reply to Thomas Chou

This patch adds status polling method to offer an alternative to data toggle method for amd flash chips.

This patch is needed for nios2 cfi flash interface, where the bus controller performs 4 bytes read cycles for a single byte read instruction. The data toggle method can not detect chip busy status correctly. So we have to poll DQ7, which will be inverted when the chip is busy.

This feature is enabled with the config def,
CONFIG_SYS_CFI_FLASH_STATUS_POLL

---
 drivers/mtd/cfi_flash.c |   93 +++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 86 insertions(+), 7 deletions(-)
drivers/mtd/cfi_flash.c +86 -7
index cd1a86e..d0240f5 100644
@@ -605,6 +605,63 @@ static int flash_full_status_check (flash_info_t * info, flash_sect_t sector,
 	return retcode;
 }
 
+static int use_flash_status_poll(flash_info_t *info)
+{
+#ifdef CONFIG_SYS_CFI_FLASH_STATUS_POLL
+	if (info->vendor == CFI_CMDSET_AMD_EXTENDED ||
+	    info->vendor == CFI_CMDSET_AMD_STANDARD)
+		return 1;
+#endif
+	return 0;
+}
+
+static int flash_status_poll(flash_info_t *info, void *src, void *dst,
+			     ulong tout, char *prompt)
+{
+#ifdef CONFIG_SYS_CFI_FLASH_STATUS_POLL
+	ulong start;
+	int ready;
+
+#if CONFIG_SYS_HZ != 1000
+	if ((ulong)CONFIG_SYS_HZ > 100000)
+		tout *= (ulong)CONFIG_SYS_HZ / 1000;  /* for a big HZ, avoid overflow */
+	else
+		tout = DIV_ROUND_UP(tout * (ulong)CONFIG_SYS_HZ, 1000);
+#endif
+
+	/* Wait for command completion */
+	start = get_timer(0);
+	while (1) {
+		switch (info->portwidth) {
+		case FLASH_CFI_8BIT:
+			ready = flash_read8(dst) == flash_read8(src);
+			break;
+		case FLASH_CFI_16BIT:
+			ready = flash_read16(dst) == flash_read16(src);
+			break;
+		case FLASH_CFI_32BIT:
+			ready = flash_read32(dst) == flash_read32(src);
+			break;
+		case FLASH_CFI_64BIT:
+			ready = flash_read64(dst) == flash_read64(src);
+			break;
+		default:
+			ready = 0;
+			break;
+		}
+		if (ready)
+			break;
+		if (get_timer(start) > tout) {
+			printf("Flash %s timeout at address %lx data %lx\n",
+			       prompt, (ulong)dst, (ulong)flash_read8(dst));
+			return ERR_TIMOUT;
+		}
+		udelay(1);		/* also triggers watchdog */
+	}
+#endif /* CONFIG_SYS_CFI_FLASH_STATUS_POLL */
+	return ERR_OK;
+}
+
 /*-----------------------------------------------------------------------
  */
 static void flash_add_byte (flash_info_t * info, cfiword_t * cword, uchar c)
@@ -752,7 +809,12 @@ static int flash_write_cfiword (flash_info_t * info, ulong dest,
 	if (!sect_found)
 		sect = find_sector (info, dest);
 
-	return flash_full_status_check (info, sect, info->write_tout, "write");
+	if (use_flash_status_poll(info))
+		return flash_status_poll(info, &cword, dstaddr,
+					 info->write_tout, "write");
+	else
+		return flash_full_status_check(info, sect,
+					       info->write_tout, "write");
 }
 
 #ifdef CONFIG_SYS_FLASH_USE_BUFFER_WRITE
@@ -914,9 +976,15 @@ static int flash_write_cfibuffer (flash_info_t * info, ulong dest, uchar * cp,
 		}
 
 		flash_write_cmd (info, sector, 0, AMD_CMD_WRITE_BUFFER_CONFIRM);
-		retcode = flash_full_status_check (info, sector,
-						   info->buffer_write_tout,
-						   "buffer write");
+		if (use_flash_status_poll(info))
+			retcode = flash_status_poll(info, src - (1 << shift),
+						    dst - (1 << shift),
+						    info->buffer_write_tout,
+						    "buffer write");
+		else
+			retcode = flash_full_status_check(info, sector,
+							  info->buffer_write_tout,
+							  "buffer write");
 		break;
 
 	default:
@@ -938,6 +1006,7 @@ int flash_erase (flash_info_t * info, int s_first, int s_last)
 	int rcode = 0;
 	int prot;
 	flash_sect_t sect;
+	int st;
 
 	if (info->flash_id != FLASH_MAN_CFI) {
 		puts ("Can't erase unknown flash type - aborted\n");
@@ -1001,10 +1070,20 @@ int flash_erase (flash_info_t * info, int s_first, int s_last)
 				break;
 			}
 
-			if (flash_full_status_check
-			    (info, sect, info->erase_blk_tout, "erase")) {
+			if (use_flash_status_poll(info)) {
+				cfiword_t cword = (cfiword_t)0xffffffffffffffffULL;
+				void *dest;
+				dest = flash_map(info, sect, 0);
+				st = flash_status_poll(info, &cword, dest,
+						       info->erase_blk_tout, "erase");
+				flash_unmap(info, sect, 0, dest);
+			} else
+				st = flash_full_status_check(info, sect,
+							     info->erase_blk_tout,
+							     "erase");
+			if (st)
 				rcode = 1;
-			} else if (flash_verbose)
+			else if (flash_verbose)
 				putc ('.');
 		}
 	}
Signature · 1 line
1.6.6.1