Skip to contentSkip to conversation

sf: Add bank address register writing support

PATCH Superseded Jagannadha Sutradharudu Teki 3 participants 19 messages Jun 13, 2013 – Jun 19, 2013 1 message not in the archive

Subsystems (2)

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH v4 1/14 sf: Add bank address register writing support

This patch provides support to program a flash bank address register.

extended/bank address register contains an information to access the 4th byte addressing in 3-byte address mode.

reff' the spec for more details about bank addr register in Page-63, Table 8.16
http://www.spansion.com/Support/Datasheets/S25FL128S_256S_00.pdf

---
Changes for v4:
- remove bank cmds
Changes for v3:
- none
Changes for v2:
- none

 drivers/mtd/spi/spi_flash.c          | 26 ++++++++++++++++++++++++++
 drivers/mtd/spi/spi_flash_internal.h |  3 +++
 2 files changed, 29 insertions(+)
drivers/mtd/spi/spi_flash.c +26 -0
index 0e38f59..9ddd070 100644
@@ -278,6 +278,32 @@ int spi_flash_cmd_write_status(struct spi_flash *flash, u8 sr)
 	return 0;
 }
 
+int spi_flash_cmd_bankaddr_write(struct spi_flash *flash, u8 bank_sel)
+{
+	u8 cmd;
+	int ret;
+
+	ret = spi_flash_cmd_write_enable(flash);
+	if (ret < 0) {
+		debug("SF: enabling write failed\n");
+		return ret;
+	}
+
+	ret = spi_flash_cmd_write(flash->spi, &cmd, 1, &bank_sel, 1);
+	if (ret) {
+		debug("SF: fail to write bank addr register\n");
+		return ret;
+	}
+
+	ret = spi_flash_cmd_wait_ready(flash, SPI_FLASH_PROG_TIMEOUT);
+	if (ret < 0) {
+		debug("SF: write bank addr register timed out\n");
+		return ret;
+	}
+
+	return 0;
+}
+
 #ifdef CONFIG_OF_CONTROL
 int spi_flash_decode_fdt(const void *blob, struct spi_flash *flash)
 {
drivers/mtd/spi/spi_flash_internal.h +3 -0
index 141cfa8..772fef6 100644
@@ -77,6 +77,9 @@ static inline int spi_flash_cmd_write_disable(struct spi_flash *flash)
 /* Program the status register. */
 int spi_flash_cmd_write_status(struct spi_flash *flash, u8 sr);
 
+/* Program the bank address register */
+int spi_flash_cmd_bankaddr_write(struct spi_flash *flash, u8 bank_sel);
+
 /*
  * Same as spi_flash_cmd_read() except it also claims/releases the SPI
  * bus. Used as common part of the ->read() operation.
Signature · 1 line
1.8.3
#2 lore raw

PATCH v4 2/14 sf: Discover the bank addr commands

In reply to a message not in the archive

Bank/Extended addr commands are specific to particular flash vendor so discover them based on the idocode0.

Assign the discovered bank commands to spi_flash members so-that the bank read/write will use their specific operations.

---
Changes for v4:
- none
Changes for v3:
- none
Changes for v2:
- none

 drivers/mtd/spi/spi_flash.c          | 21 +++++++++++++++++++++
 drivers/mtd/spi/spi_flash_internal.h | 14 ++++++++++++++
 include/spi_flash.h                  |  2 ++
 3 files changed, 37 insertions(+)
drivers/mtd/spi/spi_flash.c +21 -0
index 9ddd070..9c90f00 100644
@@ -304,6 +304,27 @@ int spi_flash_cmd_bankaddr_write(struct spi_flash *flash, u8 bank_sel)
 	return 0;
 }
 
+int spi_flash_bank_config(struct spi_flash *flash, u8 idcode0)
+{
+	/* discover bank cmds */
+	switch (idcode0) {
+	case SPI_FLASH_SPANSION_IDCODE0:
+		flash->bank_cmd[0] = CMD_BANKADDR_BRRD;
+		flash->bank_cmd[1] = CMD_BANKADDR_BRWR;
+		break;
+	case SPI_FLASH_STMICRO_IDCODE0:
+	case SPI_FLASH_WINBOND_IDCODE0:
+		flash->bank_cmd[0] = CMD_EXTNADDR_RDEAR;
+		flash->bank_cmd[1] = CMD_EXTNADDR_WREAR;
+		break;
+	default:
+		printf("SF: Unsupported bank commands %02x\n", idcode0);
+		return -1;
+	}
+
+	return 0;
+}
+
 #ifdef CONFIG_OF_CONTROL
 int spi_flash_decode_fdt(const void *blob, struct spi_flash *flash)
 {
drivers/mtd/spi/spi_flash_internal.h +14 -0
index 772fef6..db6c444 100644
@@ -28,6 +28,17 @@
 #define CMD_ERASE_64K			0xd8
 #define CMD_ERASE_CHIP			0xc7
 
+/* Manufacture ID's */
+#define SPI_FLASH_SPANSION_IDCODE0	0x01
+#define SPI_FLASH_STMICRO_IDCODE0	0x20
+#define SPI_FLASH_WINBOND_IDCODE0	0xef
+
+/* Bank addr access commands */
+#define CMD_BANKADDR_BRWR		0x17
+#define CMD_BANKADDR_BRRD		0x16
+#define CMD_EXTNADDR_WREAR		0xC5
+#define CMD_EXTNADDR_RDEAR		0xC8
+
 /* Common status */
 #define STATUS_WIP			0x01
 
@@ -80,6 +91,9 @@ int spi_flash_cmd_write_status(struct spi_flash *flash, u8 sr);
 /* Program the bank address register */
 int spi_flash_cmd_bankaddr_write(struct spi_flash *flash, u8 bank_sel);
 
+/* Configure the BAR - discover the bank cmds */
+int spi_flash_bank_config(struct spi_flash *flash, u8 idcode0);
+
 /*
  * Same as spi_flash_cmd_read() except it also claims/releases the SPI
  * bus. Used as common part of the ->read() operation.
include/spi_flash.h +2 -0
index 3b6a44e..50a03bf 100644
@@ -38,6 +38,8 @@ struct spi_flash {
 	u32		page_size;
 	/* Erase (sector) size */
 	u32		sector_size;
+	/* Bank cmds - cmd[0] - read, cmd[1] - write */
+	u8		bank_cmd[2];
 
 	void *memory_map;	/* Address of read-only SPI flash access */
 	int		(*read)(struct spi_flash *flash, u32 offset,
Signature · 1 line
1.8.3
#3 lore raw

PATCH v4 2/14 sf: Discover the bank addr commands

Hi Jagan,

Quoted 27 lines · Jagannadha Sutradharudu Teki

Bank/Extended addr commands are specific to particular flash vendor so discover them based on the idocode0.

Assign the discovered bank commands to spi_flash members so-that the bank read/write will use their specific operations.

---
Changes for v4:
- none
Changes for v3:
- none
Changes for v2:
- none

 drivers/mtd/spi/spi_flash.c          | 21 +++++++++++++++++++++
 drivers/mtd/spi/spi_flash_internal.h | 14 ++++++++++++++
 include/spi_flash.h                  |  2 ++
 3 files changed, 37 insertions(+)
drivers/mtd/spi/spi_flash.c +0 -0
index 9ddd070..9c90f00 100644
@@ -304,6 +304,27 @@ int spi_flash_cmd_bankaddr_write(struct spi_flash
 *flash, u8 bank_sel)
        return 0;

drivers/mtd/spi/spi_flash.c int spi_flash_cmd_bankaddr_write(struct spi_flash · line 315

Quoted 10 lines
drivers/mtd/spi/spi_flash.c +7 -0
 }
 
+int spi_flash_bank_config(struct spi_flash *flash, u8 idcode0)
+{
+       /* discover bank cmds */
+       switch (idcode0) {
+       case SPI_FLASH_SPANSION_IDCODE0:
+               flash->bank_cmd[0] = CMD_BANKADDR_BRRD;
+               flash->bank_cmd[1] = CMD_BANKADDR_BRWR;
 

I suggest bank_read_cmd, bank_write_cmd

Quoted 65 lines
drivers/mtd/spi/spi_flash.c +14 -0
+               break;
+       case SPI_FLASH_STMICRO_IDCODE0:
+       case SPI_FLASH_WINBOND_IDCODE0:
+               flash->bank_cmd[0] = CMD_EXTNADDR_RDEAR;
+               flash->bank_cmd[1] = CMD_EXTNADDR_WREAR;
+               break;
+       default:
+               printf("SF: Unsupported bank commands %02x\n", idcode0);
+               return -1;
+       }
+
+       return 0;
+}
+
 #ifdef CONFIG_OF_CONTROL

int spi_flash_decode_fdt(const void *blob, struct spi_flash *flash) {

drivers/mtd/spi/spi_flash_internal.h +14 -0
index 772fef6..db6c444 100644
@@ -28,6 +28,17 @@
 #define CMD_ERASE_64K                  0xd8
 #define CMD_ERASE_CHIP                 0xc7
 
+/* Manufacture ID's */
+#define SPI_FLASH_SPANSION_IDCODE0     0x01
+#define SPI_FLASH_STMICRO_IDCODE0      0x20
+#define SPI_FLASH_WINBOND_IDCODE0      0xef
+
+/* Bank addr access commands */
+#define CMD_BANKADDR_BRWR              0x17
+#define CMD_BANKADDR_BRRD              0x16
+#define CMD_EXTNADDR_WREAR             0xC5
+#define CMD_EXTNADDR_RDEAR             0xC8
+
 /* Common status */
 #define STATUS_WIP                     0x01
 
@@ -80,6 +91,9 @@ int spi_flash_cmd_write_status(struct spi_flash *flash,
 u8 sr);
 /* Program the bank address register */
 int spi_flash_cmd_bankaddr_write(struct spi_flash *flash, u8 bank_sel);
 
+/* Configure the BAR - discover the bank cmds */
+int spi_flash_bank_config(struct spi_flash *flash, u8 idcode0);
+
 /*
  * Same as spi_flash_cmd_read() except it also claims/releases the SPI

* bus. Used as common part of the ->read() operation.

include/spi_flash.h +2 -1
index 3b6a44e..50a03bf 100644
@@ -38,6 +38,8 @@ struct spi_flash {
        u32             page_size;
        /* Erase (sector) size */
        u32             sector_size;
+       /* Bank cmds - cmd[0] - read, cmd[1] - write */
+       u8              bank_cmd[2];
 
        void *memory_map;       /* Address of read-only SPI flash access */
        int             (*read)(struct spi_flash *flash, u32 offset,
--
Quoted 4 lines

1.8.3

Regards,
Simon

#4 lore raw

PATCH v4 2/14 sf: Discover the bank addr commands

Quoted 34 lines · Simon Glass

Hi Jagan,

Quoted 29 lines · Jagannadha Sutradharudu Teki

Bank/Extended addr commands are specific to particular flash vendor so discover them based on the idocode0.

Assign the discovered bank commands to spi_flash members so-that the bank read/write will use their specific operations.

---
Changes for v4:
- none
Changes for v3:
- none
Changes for v2:
- none

 drivers/mtd/spi/spi_flash.c          | 21 +++++++++++++++++++++
 drivers/mtd/spi/spi_flash_internal.h | 14 ++++++++++++++
 include/spi_flash.h                  |  2 ++
 3 files changed, 37 insertions(+)
drivers/mtd/spi/spi_flash.c +0 -0
index 9ddd070..9c90f00 100644
@@ -304,6 +304,27 @@ int spi_flash_cmd_bankaddr_write(struct spi_flash
 *flash, u8 bank_sel)
        return 0;
 }
 
Quoted 10 lines

drivers/mtd/spi/spi_flash.c int spi_flash_cmd_bankaddr_write(struct spi_flash *flash, u8 bank_sel)

Quoted 8 lines
drivers/mtd/spi/spi_flash.c +7 -0
+int spi_flash_bank_config(struct spi_flash *flash, u8 idcode0)
+{
+       /* discover bank cmds */
+       switch (idcode0) {
+       case SPI_FLASH_SPANSION_IDCODE0:
+               flash->bank_cmd[0] = CMD_BANKADDR_BRRD;
+               flash->bank_cmd[1] = CMD_BANKADDR_BRWR;
 

I suggest bank_read_cmd, bank_write_cmd

Thought of same, later tried with array.
OK will make this change.

--
Thanks,
Jagan.

Quoted 79 lines
Quoted 67 lines
drivers/mtd/spi/spi_flash.c +14 -0
+               break;
+       case SPI_FLASH_STMICRO_IDCODE0:
+       case SPI_FLASH_WINBOND_IDCODE0:
+               flash->bank_cmd[0] = CMD_EXTNADDR_RDEAR;
+               flash->bank_cmd[1] = CMD_EXTNADDR_WREAR;
+               break;
+       default:
+               printf("SF: Unsupported bank commands %02x\n", idcode0);
+               return -1;
+       }
+
+       return 0;
+}
+
 #ifdef CONFIG_OF_CONTROL

int spi_flash_decode_fdt(const void *blob, struct spi_flash *flash) {

drivers/mtd/spi/spi_flash_internal.h +14 -0
index 772fef6..db6c444 100644
@@ -28,6 +28,17 @@
 #define CMD_ERASE_64K                  0xd8
 #define CMD_ERASE_CHIP                 0xc7
 
+/* Manufacture ID's */
+#define SPI_FLASH_SPANSION_IDCODE0     0x01
+#define SPI_FLASH_STMICRO_IDCODE0      0x20
+#define SPI_FLASH_WINBOND_IDCODE0      0xef
+
+/* Bank addr access commands */
+#define CMD_BANKADDR_BRWR              0x17
+#define CMD_BANKADDR_BRRD              0x16
+#define CMD_EXTNADDR_WREAR             0xC5
+#define CMD_EXTNADDR_RDEAR             0xC8
+
 /* Common status */
 #define STATUS_WIP                     0x01
 
@@ -80,6 +91,9 @@ int spi_flash_cmd_write_status(struct spi_flash *flash,
 u8 sr);
 /* Program the bank address register */
 int spi_flash_cmd_bankaddr_write(struct spi_flash *flash, u8 bank_sel);
 
+/* Configure the BAR - discover the bank cmds */
+int spi_flash_bank_config(struct spi_flash *flash, u8 idcode0);
+
 /*
  * Same as spi_flash_cmd_read() except it also claims/releases the SPI

* bus. Used as common part of the ->read() operation.

include/spi_flash.h +2 -1
index 3b6a44e..50a03bf 100644
@@ -38,6 +38,8 @@ struct spi_flash {
        u32             page_size;
        /* Erase (sector) size */
        u32             sector_size;
+       /* Bank cmds - cmd[0] - read, cmd[1] - write */
+       u8              bank_cmd[2];
 
        void *memory_map;       /* Address of read-only SPI flash access */
        int             (*read)(struct spi_flash *flash, u32 offset,
--
Quoted 4 lines

1.8.3

Regards,
Simon

_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

#5 lore raw

PATCH v4 3/14 sf: Read flash bank addr register at probe time

In reply to a message not in the archive

Read the flash bank addr register to get the state of bank in a perticular flash. and also bank write happens only when there is a change in bank selection from user.

bank read only valid for flashes which has > 16Mbytes those are opearted in 3-byte addr mode, each bank occupies 16Mytes.

Suppose if the flash has 64Mbytes size consists of 4 banks like bank0, bank1, bank2 and bank3.

---
Changes for v4:
- Added spi_flash_bank_config
Changes for v3:
- none
Changes for v2:
- none

 drivers/mtd/spi/spi_flash.c          | 27 +++++++++++++++++++++++++++
 drivers/mtd/spi/spi_flash_internal.h |  2 ++
 include/spi_flash.h                  |  2 ++
 3 files changed, 31 insertions(+)
drivers/mtd/spi/spi_flash.c +27 -0
index 9c90f00..cdd9546 100644
@@ -283,6 +283,12 @@ int spi_flash_cmd_bankaddr_write(struct spi_flash *flash, u8 bank_sel)
 	u8 cmd;
 	int ret;
 
+	if (flash->bank_curr == bank_sel) {
+		debug("SF: not require to enable bank%d\n", bank_sel);
+		return 0;
+	}
+
+	cmd = flash->bank_cmd[1];
 	ret = spi_flash_cmd_write_enable(flash);
 	if (ret < 0) {
 		debug("SF: enabling write failed\n");
@@ -294,6 +300,7 @@ int spi_flash_cmd_bankaddr_write(struct spi_flash *flash, u8 bank_sel)
 		debug("SF: fail to write bank addr register\n");
 		return ret;
 	}
+	flash->bank_curr = bank_sel;
 
 	ret = spi_flash_cmd_wait_ready(flash, SPI_FLASH_PROG_TIMEOUT);
 	if (ret < 0) {
@@ -306,6 +313,9 @@ int spi_flash_cmd_bankaddr_write(struct spi_flash *flash, u8 bank_sel)
 
 int spi_flash_bank_config(struct spi_flash *flash, u8 idcode0)
 {
+	u8 cmd;
+	u8 curr_bank = 0;
+
 	/* discover bank cmds */
 	switch (idcode0) {
 	case SPI_FLASH_SPANSION_IDCODE0:
@@ -322,6 +332,18 @@ int spi_flash_bank_config(struct spi_flash *flash, u8 idcode0)
 		return -1;
 	}
 
+	/* read the bank reg - on which bank the flash is in currently */
+	cmd = flash->bank_cmd[0];
+	if (flash->size > SPI_FLASH_16MB_BOUN) {
+		if (spi_flash_read_common(flash, &cmd, 1, &curr_bank, 1)) {
+			debug("SF: fail to read bank addr register\n");
+			return -1;
+		}
+		flash->bank_curr = curr_bank;
+	} else {
+		flash->bank_curr = curr_bank;
+	}
+
 	return 0;
 }
 
@@ -469,6 +491,11 @@ struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs,
 		goto err_manufacturer_probe;
 	}
 
+	/* Configure the BAR - disover bank cmds and read current bank  */
+	ret = spi_flash_bank_config(flash, *idp);
+	if (ret < 0)
+		goto err_manufacturer_probe;
+
 #ifdef CONFIG_OF_CONTROL
 	if (spi_flash_decode_fdt(gd->fdt_blob, flash)) {
 		debug("SF: FDT decode error\n");
drivers/mtd/spi/spi_flash_internal.h +2 -0
index db6c444..00ed1ee 100644
@@ -28,6 +28,8 @@
 #define CMD_ERASE_64K			0xd8
 #define CMD_ERASE_CHIP			0xc7
 
+#define SPI_FLASH_16MB_BOUN		0x1000000
+
 /* Manufacture ID's */
 #define SPI_FLASH_SPANSION_IDCODE0	0x01
 #define SPI_FLASH_STMICRO_IDCODE0	0x20
include/spi_flash.h +2 -0
index 50a03bf..1f9ec69 100644
@@ -40,6 +40,8 @@ struct spi_flash {
 	u32		sector_size;
 	/* Bank cmds - cmd[0] - read, cmd[1] - write */
 	u8		bank_cmd[2];
+	/* Current flash bank */
+	u8		bank_curr;
 
 	void *memory_map;	/* Address of read-only SPI flash access */
 	int		(*read)(struct spi_flash *flash, u32 offset,
Signature · 1 line
1.8.3
#6 lore raw

PATCH v4 4/14 sf: Update sf to support all sizes of flashes

In reply to a message not in the archive

Updated the spi_flash framework to handle all sizes of flashes using bank/extd addr reg facility

The current implementation in spi_flash supports 3-byte address mode due to this up to 16Mbytes amount of flash is able to access for those flashes which has an actual size of > 16MB.

As most of the flashes introduces a bank/extd address registers for accessing the flashes in 16Mbytes of banks if the flash size is > 16Mbytes, this new scheme will add the bank selection feature for performing write/erase operations on all flashes.

---
Changes for v4:
- none
Changes for v3:
- none
Changes for v2:
- none

 drivers/mtd/spi/spi_flash.c | 39 ++++++++++++++++++++++++++-------------
 1 file changed, 26 insertions(+), 13 deletions(-)
drivers/mtd/spi/spi_flash.c +26 -13
index cdd9546..a6c5d83 100644
@@ -74,11 +74,9 @@ int spi_flash_cmd_write_multi(struct spi_flash *flash, u32 offset,
 	unsigned long page_addr, byte_addr, page_size;
 	size_t chunk_len, actual;
 	int ret;
-	u8 cmd[4];
+	u8 cmd[4], bank_sel;
 
 	page_size = flash->page_size;
-	page_addr = offset / page_size;
-	byte_addr = offset % page_size;
 
 	ret = spi_claim_bus(flash->spi);
 	if (ret) {
@@ -88,6 +86,16 @@ int spi_flash_cmd_write_multi(struct spi_flash *flash, u32 offset,
 
 	cmd[0] = CMD_PAGE_PROGRAM;
 	for (actual = 0; actual < len; actual += chunk_len) {
+		bank_sel = offset / SPI_FLASH_16MB_BOUN;
+
+		ret = spi_flash_cmd_bankaddr_write(flash, bank_sel);
+		if (ret) {
+			debug("SF: fail to set bank%d\n", bank_sel);
+			return ret;
+		}
+
+		page_addr = offset / page_size;
+		byte_addr = offset % page_size;
 		chunk_len = min(len - actual, page_size - byte_addr);
 
 		if (flash->spi->max_write_size)
@@ -117,11 +125,7 @@ int spi_flash_cmd_write_multi(struct spi_flash *flash, u32 offset,
 		if (ret)
 			break;
 
-		byte_addr += chunk_len;
-		if (byte_addr == page_size) {
-			page_addr++;
-			byte_addr = 0;
-		}
+		offset += chunk_len;
 	}
 
 	spi_release_bus(flash->spi);
@@ -204,9 +208,9 @@ int spi_flash_cmd_wait_ready(struct spi_flash *flash, unsigned long timeout)
 
 int spi_flash_cmd_erase(struct spi_flash *flash, u32 offset, size_t len)
 {
-	u32 end, erase_size;
+	u32 erase_size;
 	int ret;
-	u8 cmd[4];
+	u8 cmd[4], bank_sel;
 
 	erase_size = flash->sector_size;
 	if (offset % erase_size || len % erase_size) {
@@ -224,11 +228,17 @@ int spi_flash_cmd_erase(struct spi_flash *flash, u32 offset, size_t len)
 		cmd[0] = CMD_ERASE_4K;
 	else
 		cmd[0] = CMD_ERASE_64K;
-	end = offset + len;
 
-	while (offset < end) {
+	while (len) {
+		bank_sel = offset / SPI_FLASH_16MB_BOUN;
+
+		ret = spi_flash_cmd_bankaddr_write(flash, bank_sel);
+		if (ret) {
+			debug("SF: fail to set bank%d\n", bank_sel);
+			return ret;
+		}
+
 		spi_flash_addr(offset, cmd);
-		offset += erase_size;
 
 		debug("SF: erase %2x %2x %2x %2x (%x)\n", cmd[0], cmd[1],
 		      cmd[2], cmd[3], offset);
@@ -244,6 +254,9 @@ int spi_flash_cmd_erase(struct spi_flash *flash, u32 offset, size_t len)
 		ret = spi_flash_cmd_wait_ready(flash, SPI_FLASH_PAGE_ERASE_TIMEOUT);
 		if (ret)
 			goto out;
+
+		offset += erase_size;
+		len -= erase_size;
 	}
 
  out:
Signature · 1 line
1.8.3
#7 lore raw

PATCH v4 5/14 sf: Update sf read to support all sizes of flashes

In reply to a message not in the archive

This patch updated the spi_flash read func to support all sizes of flashes using bank reg addr facility.

The same support has been added in below patch for erase/write spi_flash functions:
"sf: Support all sizes of flashes using bank addr reg facility" (sha1: c956f600cbb0943d0afe1004cdb503f4fcd8f415)

With these new updates on sf framework, the flashes which has < 16MB are not effected as per as performance is concern and but the u-boot.bin size incrased ~460 bytes.

sf update(for first 16MBytes), Changes before:
U-Boot> sf update 0x1000000 0x0 0x1000000
- N25Q256
16777216 bytes written, 0 bytes skipped in 199.72s, speed 86480 B/s
- W25Q128BV
16777216 bytes written, 0 bytes skipped in 351.739s, speed 48913 B/s
- S25FL256S_64K
16777216 bytes written, 0 bytes skipped in 65.659s, speed 262144 B/s

sf update(for first 16MBytes), Changes before:
U-Boot> sf update 0x1000000 0x0 0x1000000
- N25Q256
16777216 bytes written, 0 bytes skipped in 198.953s, speed 86480 B/s
- W25Q128BV
16777216 bytes written, 0 bytes skipped in 350.90s, speed 49200 B/s
- S25FL256S_64K
16777216 bytes written, 0 bytes skipped in 66.521s, speed 262144 B/s

---
Changes for v4:
- none
Changes for v3:
- none
Changes for v2:
- none

 drivers/mtd/spi/spi_flash.c | 36 +++++++++++++++++++++++++++++++++---
 1 file changed, 33 insertions(+), 3 deletions(-)
drivers/mtd/spi/spi_flash.c +33 -3
index a6c5d83..7e987a0 100644
@@ -148,7 +148,9 @@ int spi_flash_read_common(struct spi_flash *flash, const u8 *cmd,
 int spi_flash_cmd_read_fast(struct spi_flash *flash, u32 offset,
 		size_t len, void *data)
 {
-	u8 cmd[5];
+	u8 cmd[5], bank_sel;
+	u32 remain_len, read_len;
+	int ret = -1;
 
 	/* Handle memory-mapped SPI */
 	if (flash->memory_map) {
@@ -157,10 +159,38 @@ int spi_flash_cmd_read_fast(struct spi_flash *flash, u32 offset,
 	}
 
 	cmd[0] = CMD_READ_ARRAY_FAST;
-	spi_flash_addr(offset, cmd);
 	cmd[4] = 0x00;
 
-	return spi_flash_read_common(flash, cmd, sizeof(cmd), data, len);
+	while (len) {
+		bank_sel = offset / SPI_FLASH_16MB_BOUN;
+
+		ret = spi_flash_cmd_bankaddr_write(flash, bank_sel);
+		if (ret) {
+			debug("SF: fail to set bank%d\n", bank_sel);
+			return ret;
+		}
+
+		remain_len = (SPI_FLASH_16MB_BOUN * (bank_sel + 1) - offset);
+		if (len < remain_len)
+			read_len = len;
+		else
+			read_len = remain_len;
+
+		spi_flash_addr(offset, cmd);
+
+		ret = spi_flash_read_common(flash, cmd, sizeof(cmd),
+							data, read_len);
+		if (ret < 0) {
+			debug("SF: read failed\n");
+			break;
+		}
+
+		offset += read_len;
+		len -= read_len;
+		data += read_len;
+	}
+
+	return ret;
 }
 
 int spi_flash_cmd_poll_bit(struct spi_flash *flash, unsigned long timeout,
Signature · 1 line
1.8.3
#8 lore raw

PATCH v4 5/14 sf: Update sf read to support all sizes of flashes

Hi Jagan,

Quoted 21 lines · Jagannadha Sutradharudu Teki

This patch updated the spi_flash read func to support all sizes of flashes using bank reg addr facility.

The same support has been added in below patch for erase/write spi_flash functions:
"sf: Support all sizes of flashes using bank addr reg facility" (sha1: c956f600cbb0943d0afe1004cdb503f4fcd8f415)

With these new updates on sf framework, the flashes which has < 16MB are not effected as per as performance is concern and but the u-boot.bin size incrased ~460 bytes.

sf update(for first 16MBytes), Changes before:
U-Boot> sf update 0x1000000 0x0 0x1000000
- N25Q256
16777216 bytes written, 0 bytes skipped in 199.72s, speed 86480 B/s
- W25Q128BV
16777216 bytes written, 0 bytes skipped in 351.739s, speed 48913 B/s
- S25FL256S_64K
16777216 bytes written, 0 bytes skipped in 65.659s, speed 262144 B/s

Quoted 9 lines

sf update(for first 16MBytes), Changes before:
U-Boot> sf update 0x1000000 0x0 0x1000000
- N25Q256
16777216 bytes written, 0 bytes skipped in 198.953s, speed 86480 B/s
- W25Q128BV
16777216 bytes written, 0 bytes skipped in 350.90s, speed 49200 B/s
- S25FL256S_64K
16777216 bytes written, 0 bytes skipped in 66.521s, speed 262144 B/s

FYI you can also use 'sf test' to get performance numbers.

Regards,
Simon

#9 lore raw

PATCH v4 6/14 sf: Add bank addr code in CONFIG_SPI_FLASH_BAR

In reply to a message not in the archive

Defined bank addr code on CONFIG_SPI_FLASH_BAR macro, to reduce the size for existing boards which has < 16Mbytes SPI flashes.

It's upto user which has provision to use the bank addr code for flashes which has > 16Mbytes.

---
Changes for v4:
- rebase of 02/14
Changes for v3:
- none
Changes for v2:
- none

 README                               |  5 +++++
 drivers/mtd/spi/spi_flash.c          | 23 +++++++++++++++++------
 drivers/mtd/spi/spi_flash_internal.h | 12 ++++++++----
 include/spi_flash.h                  |  3 ++-
 4 files changed, 32 insertions(+), 11 deletions(-)
README +5 -0
index 3d81092..a2b956e 100644
@@ -2489,6 +2489,11 @@ CBFS (Coreboot Filesystem) support
 		Define this option to include a destructive SPI flash
 		test ('sf test').
 
+		CONFIG_SPI_FLASH_BAR		Ban/Extended Addr Reg
+
+		Define this option to use the Bank addr/Extended addr
+		support on SPI flashes which has size > 16Mbytes.
+
 - SystemACE Support:
 		CONFIG_SYSTEMACE
 
drivers/mtd/spi/spi_flash.c +17 -6
index 7e987a0..c9ef61f 100644
@@ -74,7 +74,7 @@ int spi_flash_cmd_write_multi(struct spi_flash *flash, u32 offset,
 	unsigned long page_addr, byte_addr, page_size;
 	size_t chunk_len, actual;
 	int ret;
-	u8 cmd[4], bank_sel;
+	u8 cmd[4];
 
 	page_size = flash->page_size;
 
@@ -86,6 +86,9 @@ int spi_flash_cmd_write_multi(struct spi_flash *flash, u32 offset,
 
 	cmd[0] = CMD_PAGE_PROGRAM;
 	for (actual = 0; actual < len; actual += chunk_len) {
+#ifdef CONFIG_SPI_FLASH_BAR
+		u8 bank_sel;
+
 		bank_sel = offset / SPI_FLASH_16MB_BOUN;
 
 		ret = spi_flash_cmd_bankaddr_write(flash, bank_sel);
@@ -93,7 +96,7 @@ int spi_flash_cmd_write_multi(struct spi_flash *flash, u32 offset,
 			debug("SF: fail to set bank%d\n", bank_sel);
 			return ret;
 		}
-
+#endif
 		page_addr = offset / page_size;
 		byte_addr = offset % page_size;
 		chunk_len = min(len - actual, page_size - byte_addr);
@@ -148,7 +151,7 @@ int spi_flash_read_common(struct spi_flash *flash, const u8 *cmd,
 int spi_flash_cmd_read_fast(struct spi_flash *flash, u32 offset,
 		size_t len, void *data)
 {
-	u8 cmd[5], bank_sel;
+	u8 cmd[5], bank_sel = 0;
 	u32 remain_len, read_len;
 	int ret = -1;
 
@@ -162,6 +165,7 @@ int spi_flash_cmd_read_fast(struct spi_flash *flash, u32 offset,
 	cmd[4] = 0x00;
 
 	while (len) {
+#ifdef CONFIG_SPI_FLASH_BAR
 		bank_sel = offset / SPI_FLASH_16MB_BOUN;
 
 		ret = spi_flash_cmd_bankaddr_write(flash, bank_sel);
@@ -169,7 +173,7 @@ int spi_flash_cmd_read_fast(struct spi_flash *flash, u32 offset,
 			debug("SF: fail to set bank%d\n", bank_sel);
 			return ret;
 		}
-
+#endif
 		remain_len = (SPI_FLASH_16MB_BOUN * (bank_sel + 1) - offset);
 		if (len < remain_len)
 			read_len = len;
@@ -240,7 +244,7 @@ int spi_flash_cmd_erase(struct spi_flash *flash, u32 offset, size_t len)
 {
 	u32 erase_size;
 	int ret;
-	u8 cmd[4], bank_sel;
+	u8 cmd[4];
 
 	erase_size = flash->sector_size;
 	if (offset % erase_size || len % erase_size) {
@@ -260,6 +264,9 @@ int spi_flash_cmd_erase(struct spi_flash *flash, u32 offset, size_t len)
 		cmd[0] = CMD_ERASE_64K;
 
 	while (len) {
+#ifdef CONFIG_SPI_FLASH_BAR
+		u8 bank_sel;
+
 		bank_sel = offset / SPI_FLASH_16MB_BOUN;
 
 		ret = spi_flash_cmd_bankaddr_write(flash, bank_sel);
@@ -267,7 +274,7 @@ int spi_flash_cmd_erase(struct spi_flash *flash, u32 offset, size_t len)
 			debug("SF: fail to set bank%d\n", bank_sel);
 			return ret;
 		}
-
+#endif
 		spi_flash_addr(offset, cmd);
 
 		debug("SF: erase %2x %2x %2x %2x (%x)\n", cmd[0], cmd[1],
@@ -321,6 +328,7 @@ int spi_flash_cmd_write_status(struct spi_flash *flash, u8 sr)
 	return 0;
 }
 
+#ifdef CONFIG_SPI_FLASH_BAR
 int spi_flash_cmd_bankaddr_write(struct spi_flash *flash, u8 bank_sel)
 {
 	u8 cmd;
@@ -389,6 +397,7 @@ int spi_flash_bank_config(struct spi_flash *flash, u8 idcode0)
 
 	return 0;
 }
+#endif
 
 #ifdef CONFIG_OF_CONTROL
 int spi_flash_decode_fdt(const void *blob, struct spi_flash *flash)
@@ -534,10 +543,12 @@ struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs,
 		goto err_manufacturer_probe;
 	}
 
+#ifdef CONFIG_SPI_FLASH_BAR
 	/* Configure the BAR - disover bank cmds and read current bank  */
 	ret = spi_flash_bank_config(flash, *idp);
 	if (ret < 0)
 		goto err_manufacturer_probe;
+#endif
 
 #ifdef CONFIG_OF_CONTROL
 	if (spi_flash_decode_fdt(gd->fdt_blob, flash)) {
drivers/mtd/spi/spi_flash_internal.h +8 -4
index 00ed1ee..e613ef3 100644
@@ -35,11 +35,13 @@
 #define SPI_FLASH_STMICRO_IDCODE0	0x20
 #define SPI_FLASH_WINBOND_IDCODE0	0xef
 
+#ifdef CONFIG_SPI_FLASH_BAR
 /* Bank addr access commands */
-#define CMD_BANKADDR_BRWR		0x17
-#define CMD_BANKADDR_BRRD		0x16
-#define CMD_EXTNADDR_WREAR		0xC5
-#define CMD_EXTNADDR_RDEAR		0xC8
+# define CMD_BANKADDR_BRWR		0x17
+# define CMD_BANKADDR_BRRD		0x16
+# define CMD_EXTNADDR_WREAR		0xC5
+# define CMD_EXTNADDR_RDEAR		0xC8
+#endif
 
 /* Common status */
 #define STATUS_WIP			0x01
@@ -90,11 +92,13 @@ static inline int spi_flash_cmd_write_disable(struct spi_flash *flash)
 /* Program the status register. */
 int spi_flash_cmd_write_status(struct spi_flash *flash, u8 sr);
 
+#ifdef CONFIG_SPI_FLASH_BAR
 /* Program the bank address register */
 int spi_flash_cmd_bankaddr_write(struct spi_flash *flash, u8 bank_sel);
 
 /* Configure the BAR - discover the bank cmds */
 int spi_flash_bank_config(struct spi_flash *flash, u8 idcode0);
+#endif
 
 /*
  * Same as spi_flash_cmd_read() except it also claims/releases the SPI
include/spi_flash.h +2 -1
index 1f9ec69..1de193a 100644
@@ -38,11 +38,12 @@ struct spi_flash {
 	u32		page_size;
 	/* Erase (sector) size */
 	u32		sector_size;
+#ifdef CONFIG_SPI_FLASH_BAR
 	/* Bank cmds - cmd[0] - read, cmd[1] - write */
 	u8		bank_cmd[2];
 	/* Current flash bank */
 	u8		bank_curr;
-
+#endif
 	void *memory_map;	/* Address of read-only SPI flash access */
 	int		(*read)(struct spi_flash *flash, u32 offset,
 				size_t len, void *buf);
Signature · 1 line
1.8.3
#10 lore raw

PATCH v4 7/14 sf: Use spi_flash_addr() in write call

In reply to a message not in the archive

Use the existing spi_flash_addr() for 3-byte addressing cmd filling in write call.

---
Changes for v4:
- none
Changes for v3:
- none
Changes for v2:
- none

 drivers/mtd/spi/spi_flash.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/mtd/spi/spi_flash.c +2 -5
index c9ef61f..88efa92 100644
@@ -71,7 +71,7 @@ int spi_flash_cmd_write(struct spi_slave *spi, const u8 *cmd, size_t cmd_len,
 int spi_flash_cmd_write_multi(struct spi_flash *flash, u32 offset,
 		size_t len, const void *buf)
 {
-	unsigned long page_addr, byte_addr, page_size;
+	unsigned long byte_addr, page_size;
 	size_t chunk_len, actual;
 	int ret;
 	u8 cmd[4];
@@ -97,16 +97,13 @@ int spi_flash_cmd_write_multi(struct spi_flash *flash, u32 offset,
 			return ret;
 		}
 #endif
-		page_addr = offset / page_size;
 		byte_addr = offset % page_size;
 		chunk_len = min(len - actual, page_size - byte_addr);
 
 		if (flash->spi->max_write_size)
 			chunk_len = min(chunk_len, flash->spi->max_write_size);
 
-		cmd[1] = page_addr >> 8;
-		cmd[2] = page_addr;
-		cmd[3] = byte_addr;
+		spi_flash_addr(offset, cmd);
 
 		debug("PP: 0x%p => cmd = { 0x%02x 0x%02x%02x%02x } chunk_len = %zu\n",
 		      buf + actual, cmd[0], cmd[1], cmd[2], cmd[3], chunk_len);
Signature · 1 line
1.8.3
#11 lore raw

PATCH v4 8/14 sf: stmicro: Add support for N25Q512

In reply to a message not in the archive

Add support for Numonyx N25Q512 SPI flash.

---
Changes for v4:
- none
Changes for v3:
- none
Changes for v2:
- none

 drivers/mtd/spi/stmicro.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/mtd/spi/stmicro.c +6 -0
index 2a9972b..e9adfa5 100644
@@ -140,6 +140,12 @@ static const struct stmicro_spi_flash_params stmicro_spi_flash_table[] = {
 		.nr_sectors = 512,
 		.name = "N25Q256A",
 	},
+	{
+		.id = 0xba20,
+		.pages_per_sector = 256,
+		.nr_sectors = 1024,
+		.name = "N25Q512",
+	},
 };
 
 struct spi_flash *spi_flash_probe_stmicro(struct spi_slave *spi, u8 * idcode)
Signature · 1 line
1.8.3
#12 lore raw

PATCH v4 9/14 sf: stmicro: Add support for N25Q512A

In reply to a message not in the archive

Add support for Numonyx N25Q512A SPI flash.

---
Changes for v4:
- none
Changes for v3:
- none
Changes for v2:
- none

 drivers/mtd/spi/stmicro.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/mtd/spi/stmicro.c +6 -0
index e9adfa5..bf61a37 100644
@@ -146,6 +146,12 @@ static const struct stmicro_spi_flash_params stmicro_spi_flash_table[] = {
 		.nr_sectors = 1024,
 		.name = "N25Q512",
 	},
+	{
+		.id = 0xbb20,
+		.pages_per_sector = 256,
+		.nr_sectors = 1024,
+		.name = "N25Q512A",
+	},
 };
 
 struct spi_flash *spi_flash_probe_stmicro(struct spi_slave *spi, u8 * idcode)
Signature · 1 line
1.8.3
#13 lore raw

PATCH v4 10/14 sf: stmicro: Add support for N25Q1024

In reply to a message not in the archive

Add support for Numonyx N25Q1024 SPI flash.

---
Changes for v4:
- none
Changes for v3:
- none
Changes for v2:
- none

 drivers/mtd/spi/stmicro.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/mtd/spi/stmicro.c +6 -0
index bf61a37..cac1013 100644
@@ -152,6 +152,12 @@ static const struct stmicro_spi_flash_params stmicro_spi_flash_table[] = {
 		.nr_sectors = 1024,
 		.name = "N25Q512A",
 	},
+	{
+		.id = 0xba21,
+		.pages_per_sector = 256,
+		.nr_sectors = 2048,
+		.name = "N25Q1024",
+	},
 };
 
 struct spi_flash *spi_flash_probe_stmicro(struct spi_slave *spi, u8 * idcode)
Signature · 1 line
1.8.3
#14 lore raw

PATCH v4 11/14 sf: stmicro: Add support for N25Q1024A

In reply to a message not in the archive

Add support for Numonyx N25Q1024A SPI flash.

---
Changes for v4:
- none
Changes for v3:
- none
Changes for v2:
- none

 drivers/mtd/spi/stmicro.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/mtd/spi/stmicro.c +6 -0
index cac1013..ef4b911 100644
@@ -158,6 +158,12 @@ static const struct stmicro_spi_flash_params stmicro_spi_flash_table[] = {
 		.nr_sectors = 2048,
 		.name = "N25Q1024",
 	},
+	{
+		.id = 0xbb21,
+		.pages_per_sector = 256,
+		.nr_sectors = 2048,
+		.name = "N25Q1024A",
+	},
 };
 
 struct spi_flash *spi_flash_probe_stmicro(struct spi_slave *spi, u8 * idcode)
Signature · 1 line
1.8.3
#15 lore raw

PATCH v4 12/14 sf: spansion: Add support for S25FL512S_64K

In reply to a message not in the archive

Add support for Spansion S25FL512S_64K SPI flash.

---
Changes for v4:
- none
Changes for v3:
- none
Changes for v2:
- none

 drivers/mtd/spi/spansion.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/mtd/spi/spansion.c +7 -0
index 2218e2f..b4ee442 100644
@@ -110,6 +110,13 @@ static const struct spansion_spi_flash_params spansion_spi_flash_table[] = {
 		.nr_sectors = 512,
 		.name = "S25FL256S_64K",
 	},
+	{
+		.idcode1 = 0x0220,
+		.idcode2 = 0x4d01,
+		.pages_per_sector = 256,
+		.nr_sectors = 1024,
+		.name = "S25FL512S_64K",
+	},
 };
 
 struct spi_flash *spi_flash_probe_spansion(struct spi_slave *spi, u8 *idcode)
Signature · 1 line
1.8.3
#16 lore raw

PATCH v4 13/14 sf: Remove spi_flash_cmd_poll_bit()

In reply to a message not in the archive

There is no other call other than spi_flash_cmd_wait_ready(), hence removed spi_flash_cmd_poll_bit and use the poll status code spi_flash_cmd_wait_ready() itself.

---
Changes for v4:
- none
Changes for v3:
- none
Changes for v2:
- none

 drivers/mtd/spi/spi_flash.c          | 11 +++--------
 drivers/mtd/spi/spi_flash_internal.h |  4 ----
 2 files changed, 3 insertions(+), 12 deletions(-)
drivers/mtd/spi/spi_flash.c +3 -8
index 88efa92..e5b401f 100644
@@ -194,13 +194,14 @@ int spi_flash_cmd_read_fast(struct spi_flash *flash, u32 offset,
 	return ret;
 }
 
-int spi_flash_cmd_poll_bit(struct spi_flash *flash, unsigned long timeout,
-			   u8 cmd, u8 poll_bit)
+int spi_flash_cmd_wait_ready(struct spi_flash *flash, unsigned long timeout)
 {
 	struct spi_slave *spi = flash->spi;
 	unsigned long timebase;
 	int ret;
 	u8 status;
+	u8 poll_bit = STATUS_WIP;
+	u8 cmd = CMD_READ_STATUS;
 
 	ret = spi_xfer(spi, 8, &cmd, NULL, SPI_XFER_BEGIN);
 	if (ret) {
@@ -231,12 +232,6 @@ int spi_flash_cmd_poll_bit(struct spi_flash *flash, unsigned long timeout,
 	return -1;
 }
 
-int spi_flash_cmd_wait_ready(struct spi_flash *flash, unsigned long timeout)
-{
-	return spi_flash_cmd_poll_bit(flash, timeout,
-		CMD_READ_STATUS, STATUS_WIP);
-}
-
 int spi_flash_cmd_erase(struct spi_flash *flash, u32 offset, size_t len)
 {
 	u32 erase_size;
drivers/mtd/spi/spi_flash_internal.h +0 -4
index e613ef3..e9b85bf 100644
@@ -107,10 +107,6 @@ int spi_flash_bank_config(struct spi_flash *flash, u8 idcode0);
 int spi_flash_read_common(struct spi_flash *flash, const u8 *cmd,
 		size_t cmd_len, void *data, size_t data_len);
 
-/* Send a command to the device and wait for some bit to clear itself. */
-int spi_flash_cmd_poll_bit(struct spi_flash *flash, unsigned long timeout,
-			   u8 cmd, u8 poll_bit);
-
 /*
  * Send the read status command to the device and wait for the wip
  * (write-in-progress) bit to clear itself.
Signature · 1 line
1.8.3
#17 lore raw

PATCH v4 14/14 sf: Add Flag status register polling support

In reply to a message not in the archive

Flag status register polling is required for micron 512Mb flash devices onwards, for performing erase/program operations.

Like polling for WIP(Write-In-Progress) bit in read status register, spi_flash_cmd_wait_ready will poll for PEC(Program-Erase-Control) bit in flag status register.

---
Changes for v4:
- Remove STMICRO config, discover poll_cmd at probe
Changes for v3:
- none
Changes for v2:
- none

 drivers/mtd/spi/spi_flash.c          | 21 +++++++++++++++++----
 drivers/mtd/spi/spi_flash_internal.h |  2 ++
 include/spi_flash.h                  |  3 +++
 3 files changed, 22 insertions(+), 4 deletions(-)
drivers/mtd/spi/spi_flash.c +17 -4
index e5b401f..c439601 100644
@@ -200,12 +200,19 @@ int spi_flash_cmd_wait_ready(struct spi_flash *flash, unsigned long timeout)
 	unsigned long timebase;
 	int ret;
 	u8 status;
+	u8 check_status = 0x0;
 	u8 poll_bit = STATUS_WIP;
-	u8 cmd = CMD_READ_STATUS;
+	u8 cmd = flash->poll_cmd;
+
+	if (cmd == CMD_FLAG_STATUS) {
+		poll_bit = STATUS_PEC;
+		check_status = poll_bit;
+	}
 
 	ret = spi_xfer(spi, 8, &cmd, NULL, SPI_XFER_BEGIN);
 	if (ret) {
-		debug("SF: Failed to send command %02x: %d\n", cmd, ret);
+		debug("SF: fail to read %s status register\n",
+			cmd == CMD_READ_STATUS ? "read" : "flag");
 		return ret;
 	}
 
@@ -217,14 +224,14 @@ int spi_flash_cmd_wait_ready(struct spi_flash *flash, unsigned long timeout)
 		if (ret)
 			return -1;
 
-		if ((status & poll_bit) == 0)
+		if ((status & poll_bit) == check_status)
 			break;
 
 	} while (get_timer(timebase) < timeout);
 
 	spi_xfer(spi, 0, NULL, NULL, SPI_XFER_END);
 
-	if ((status & poll_bit) == 0)
+	if ((status & poll_bit) == check_status)
 		return 0;
 
 	/* Timed out */
@@ -542,6 +549,12 @@ struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs,
 		goto err_manufacturer_probe;
 #endif
 
+	/* Discover the poll_cmd, as STMICRO is something different */
+	flash->poll_cmd = CMD_READ_STATUS;
+	if ((*idp == SPI_FLASH_STMICRO_IDCODE0) &&
+			(flash->size >= 0x4000000))
+		flash->poll_cmd = CMD_FLAG_STATUS;
+
 #ifdef CONFIG_OF_CONTROL
 	if (spi_flash_decode_fdt(gd->fdt_blob, flash)) {
 		debug("SF: FDT decode error\n");
drivers/mtd/spi/spi_flash_internal.h +2 -0
index e9b85bf..8147f27 100644
@@ -22,6 +22,7 @@
 #define CMD_PAGE_PROGRAM		0x02
 #define CMD_WRITE_DISABLE		0x04
 #define CMD_READ_STATUS			0x05
+#define CMD_FLAG_STATUS			0x70
 #define CMD_WRITE_ENABLE		0x06
 #define CMD_ERASE_4K			0x20
 #define CMD_ERASE_32K			0x52
@@ -45,6 +46,7 @@
 
 /* Common status */
 #define STATUS_WIP			0x01
+#define STATUS_PEC			0x80
 
 /* Send a single-byte command to the device and read the response */
 int spi_flash_cmd(struct spi_slave *spi, u8 cmd, void *response, size_t len);
include/spi_flash.h +3 -0
index 1de193a..e94e59c 100644
@@ -44,6 +44,9 @@ struct spi_flash {
 	/* Current flash bank */
 	u8		bank_curr;
 #endif
+	/* Poll cmd - for flash erase/program */
+	u8		poll_cmd;
+
 	void *memory_map;	/* Address of read-only SPI flash access */
 	int		(*read)(struct spi_flash *flash, u32 offset,
 				size_t len, void *buf);
Signature · 1 line
1.8.3
#18 lore raw

PATCH v4 14/14 sf: Add Flag status register polling support

Hi Jagan,

Quoted 68 lines · Jagannadha Sutradharudu Teki

Flag status register polling is required for micron 512Mb flash devices onwards, for performing erase/program operations.

Like polling for WIP(Write-In-Progress) bit in read status register, spi_flash_cmd_wait_ready will poll for PEC(Program-Erase-Control) bit in flag status register.

---
Changes for v4:
- Remove STMICRO config, discover poll_cmd at probe
Changes for v3:
- none
Changes for v2:
- none

 drivers/mtd/spi/spi_flash.c          | 21 +++++++++++++++++----
 drivers/mtd/spi/spi_flash_internal.h |  2 ++
 include/spi_flash.h                  |  3 +++
 3 files changed, 22 insertions(+), 4 deletions(-)
drivers/mtd/spi/spi_flash.c +11 -4
index e5b401f..c439601 100644
@@ -200,12 +200,19 @@ int spi_flash_cmd_wait_ready(struct spi_flash
 *flash, unsigned long timeout)
        unsigned long timebase;
        int ret;
        u8 status;
+       u8 check_status = 0x0;
        u8 poll_bit = STATUS_WIP;
-       u8 cmd = CMD_READ_STATUS;
+       u8 cmd = flash->poll_cmd;
+
+       if (cmd == CMD_FLAG_STATUS) {
+               poll_bit = STATUS_PEC;
+               check_status = poll_bit;
+       }
 
        ret = spi_xfer(spi, 8, &cmd, NULL, SPI_XFER_BEGIN);
        if (ret) {
-               debug("SF: Failed to send command %02x: %d\n", cmd, ret);
+               debug("SF: fail to read %s status register\n",
+                       cmd == CMD_READ_STATUS ? "read" : "flag");
                return ret;
        }
@@ -217,14 +224,14 @@ int spi_flash_cmd_wait_ready(struct spi_flash
 *flash, unsigned long timeout)
                if (ret)
                        return -1;
 
-               if ((status & poll_bit) == 0)
+               if ((status & poll_bit) == check_status)
                        break;
 
        } while (get_timer(timebase) < timeout);
 
        spi_xfer(spi, 0, NULL, NULL, SPI_XFER_END);
 
-       if ((status & poll_bit) == 0)
+       if ((status & poll_bit) == check_status)
                return 0;
 
        /* Timed out */

drivers/mtd/spi/spi_flash.c struct spi_flash *spi_flash_probe(unsigned int bus, · line 555

Quoted 7 lines
drivers/mtd/spi/spi_flash.c +2 -0
@@ -542,6 +549,12 @@ struct spi_flash *spi_flash_probe(unsigned int bus,
 unsigned int cs,
                goto err_manufacturer_probe;
 #endif
 
+       /* Discover the poll_cmd, as STMICRO is something different */
+       flash->poll_cmd = CMD_READ_STATUS;
 

Move this line into spi_flash_do_alloc()

+ if ((*idp == SPI_FLASH_STMICRO_IDCODE0) &&

drivers/mtd/spi/spi_flash.c struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs,

Quoted 3 lines
drivers/mtd/spi/spi_flash.c +2 -0
+                       (flash->size >= 0x4000000))
+               flash->poll_cmd = CMD_FLAG_STATUS;
 

...and the above into the stmicro.c's probe handler

Quoted 44 lines
drivers/mtd/spi/spi_flash.c +1 -0
+
 #ifdef CONFIG_OF_CONTROL
        if (spi_flash_decode_fdt(gd->fdt_blob, flash)) {
                debug("SF: FDT decode error\n");
drivers/mtd/spi/spi_flash_internal.h +2 -0
index e9b85bf..8147f27 100644
@@ -22,6 +22,7 @@
 #define CMD_PAGE_PROGRAM               0x02
 #define CMD_WRITE_DISABLE              0x04
 #define CMD_READ_STATUS                        0x05
+#define CMD_FLAG_STATUS                        0x70
 #define CMD_WRITE_ENABLE               0x06
 #define CMD_ERASE_4K                   0x20
 #define CMD_ERASE_32K                  0x52
@@ -45,6 +46,7 @@
 
 /* Common status */
 #define STATUS_WIP                     0x01
+#define STATUS_PEC                     0x80
 
 /* Send a single-byte command to the device and read the response */
 int spi_flash_cmd(struct spi_slave *spi, u8 cmd, void *response, size_t

len);

include/spi_flash.h +3 -1
index 1de193a..e94e59c 100644
@@ -44,6 +44,9 @@ struct spi_flash {
        /* Current flash bank */
        u8              bank_curr;
 #endif
+       /* Poll cmd - for flash erase/program */
+       u8              poll_cmd;
+
        void *memory_map;       /* Address of read-only SPI flash access */
        int             (*read)(struct spi_flash *flash, u32 offset,
                                size_t len, void *buf);
--

1.8.3

Quoted 1 line

Regards,

Simon

#19 lore raw

PATCH v4 14/14 sf: Add Flag status register polling support

Quoted 83 lines · Simon Glass

Hi Jagan,

Quoted 68 lines · Jagannadha Sutradharudu Teki

Flag status register polling is required for micron 512Mb flash devices onwards, for performing erase/program operations.

Like polling for WIP(Write-In-Progress) bit in read status register, spi_flash_cmd_wait_ready will poll for PEC(Program-Erase-Control) bit in flag status register.

---
Changes for v4:
- Remove STMICRO config, discover poll_cmd at probe
Changes for v3:
- none
Changes for v2:
- none

 drivers/mtd/spi/spi_flash.c          | 21 +++++++++++++++++----
 drivers/mtd/spi/spi_flash_internal.h |  2 ++
 include/spi_flash.h                  |  3 +++
 3 files changed, 22 insertions(+), 4 deletions(-)
drivers/mtd/spi/spi_flash.c +11 -4
index e5b401f..c439601 100644
@@ -200,12 +200,19 @@ int spi_flash_cmd_wait_ready(struct spi_flash
 *flash, unsigned long timeout)
        unsigned long timebase;
        int ret;
        u8 status;
+       u8 check_status = 0x0;
        u8 poll_bit = STATUS_WIP;
-       u8 cmd = CMD_READ_STATUS;
+       u8 cmd = flash->poll_cmd;
+
+       if (cmd == CMD_FLAG_STATUS) {
+               poll_bit = STATUS_PEC;
+               check_status = poll_bit;
+       }
 
        ret = spi_xfer(spi, 8, &cmd, NULL, SPI_XFER_BEGIN);
        if (ret) {
-               debug("SF: Failed to send command %02x: %d\n", cmd, ret);
+               debug("SF: fail to read %s status register\n",
+                       cmd == CMD_READ_STATUS ? "read" : "flag");
                return ret;
        }
@@ -217,14 +224,14 @@ int spi_flash_cmd_wait_ready(struct spi_flash
 *flash, unsigned long timeout)
                if (ret)
                        return -1;
 
-               if ((status & poll_bit) == 0)
+               if ((status & poll_bit) == check_status)
                        break;
 
        } while (get_timer(timebase) < timeout);
 
        spi_xfer(spi, 0, NULL, NULL, SPI_XFER_END);
 
-       if ((status & poll_bit) == 0)
+       if ((status & poll_bit) == check_status)
                return 0;
 
        /* Timed out */

drivers/mtd/spi/spi_flash.c struct spi_flash *spi_flash_probe(unsigned int bus, · line 555

Quoted 7 lines
drivers/mtd/spi/spi_flash.c +2 -0
@@ -542,6 +549,12 @@ struct spi_flash *spi_flash_probe(unsigned int bus,
 unsigned int cs,
                goto err_manufacturer_probe;
 #endif
 
+       /* Discover the poll_cmd, as STMICRO is something different */
+       flash->poll_cmd = CMD_READ_STATUS;
 

Move this line into spi_flash_do_alloc()

Quoted 6 lines

+ if ((*idp == SPI_FLASH_STMICRO_IDCODE0) &&

drivers/mtd/spi/spi_flash.c struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs,

Quoted 3 lines
drivers/mtd/spi/spi_flash.c +2 -0
+                       (flash->size >= 0x4000000))
+               flash->poll_cmd = CMD_FLAG_STATUS;
 

...and the above into the stmicro.c's probe handler

Sound reasonable-
Will do it.

--
Thanks,
Jagan.

Quoted 54 lines
Quoted 46 lines
drivers/mtd/spi/spi_flash.c +1 -0
+
 #ifdef CONFIG_OF_CONTROL
        if (spi_flash_decode_fdt(gd->fdt_blob, flash)) {
                debug("SF: FDT decode error\n");
drivers/mtd/spi/spi_flash_internal.h +2 -0
index e9b85bf..8147f27 100644
@@ -22,6 +22,7 @@
 #define CMD_PAGE_PROGRAM               0x02
 #define CMD_WRITE_DISABLE              0x04
 #define CMD_READ_STATUS                        0x05
+#define CMD_FLAG_STATUS                        0x70
 #define CMD_WRITE_ENABLE               0x06
 #define CMD_ERASE_4K                   0x20
 #define CMD_ERASE_32K                  0x52
@@ -45,6 +46,7 @@
 
 /* Common status */
 #define STATUS_WIP                     0x01
+#define STATUS_PEC                     0x80
 
 /* Send a single-byte command to the device and read the response */
 int spi_flash_cmd(struct spi_slave *spi, u8 cmd, void *response, size_t

len);

include/spi_flash.h +3 -1
index 1de193a..e94e59c 100644
@@ -44,6 +44,9 @@ struct spi_flash {
        /* Current flash bank */
        u8              bank_curr;
 #endif
+       /* Poll cmd - for flash erase/program */
+       u8              poll_cmd;
+
        void *memory_map;       /* Address of read-only SPI flash access */
        int             (*read)(struct spi_flash *flash, u32 offset,
                                size_t len, void *buf);
--

1.8.3

Quoted 1 line

Regards,

Simon

_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot