Skip to contentSkip to conversation

sf: Add bank address register writing support

PATCH Superseded Jagannadha Sutradharudu Teki 4 participants 37 messages May 31, 2013 – Jun 11, 2013 1 message not in the archive

Subsystems (2)

v2 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 v2 1/16 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.

Currently added an bank address register writing support for spansion flashes.

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 v2:
- none

 drivers/mtd/spi/spi_flash.c          | 37 ++++++++++++++++++++++++++++++++++++
 drivers/mtd/spi/spi_flash_internal.h |  6 ++++++
 include/spi_flash.h                  |  2 ++
 3 files changed, 45 insertions(+)
drivers/mtd/spi/spi_flash.c +37 -0
index 0e38f59..7aba520 100644
@@ -278,6 +278,40 @@ 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, idcode0;
+	int ret;
+
+	idcode0 = flash->idcode0;
+	if (idcode0 == 0x01) {
+		cmd = CMD_BANKADDR_BRWR;
+	} else {
+		printf("SF: Unsupported bank addr write %02x\n", idcode0);
+		return -1;
+	}
+
+	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)
 {
@@ -422,6 +456,9 @@ struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs,
 		goto err_manufacturer_probe;
 	}
 
+	/* store the manuf id, for performing specific flash ops */
+	flash->idcode0 = *idp;
+
 #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 +6 -0
index 141cfa8..6e38494 100644
@@ -28,6 +28,9 @@
 #define CMD_ERASE_64K			0xd8
 #define CMD_ERASE_CHIP			0xc7
 
+/* Bank addr acess commands */
+#define CMD_BANKADDR_BRWR		0x17
+
 /* Common status */
 #define STATUS_WIP			0x01
 
@@ -77,6 +80,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.
include/spi_flash.h +2 -0
index 3b6a44e..5ea42e1 100644
@@ -38,6 +38,8 @@ struct spi_flash {
 	u32		page_size;
 	/* Erase (sector) size */
 	u32		sector_size;
+	/* ID code0 */
+	u8              idcode0;
 
 	void *memory_map;	/* Address of read-only SPI flash access */
 	int		(*read)(struct spi_flash *flash, u32 offset,
Signature · 1 line
1.8.3
#2 lore raw

PATCH v2 2/16 sf: Add bank address register reading support

In reply to a message not in the archive

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

reading extended/bank address register will give whether the flash is operated on extended/bank addressing or normal addressing in 3-byte address mode.

Currently added an extended/bank address register reading support for spansion flashes.

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 v2:
- none

 drivers/mtd/spi/spi_flash.c          | 15 +++++++++++++++
 drivers/mtd/spi/spi_flash_internal.h |  4 ++++
 2 files changed, 19 insertions(+)
drivers/mtd/spi/spi_flash.c +15 -0
index 7aba520..193de42 100644
@@ -312,6 +312,21 @@ int spi_flash_cmd_bankaddr_write(struct spi_flash *flash, u8 bank_sel)
 	return 0;
 }
 
+int spi_flash_cmd_bankaddr_read(struct spi_flash *flash, void *data)
+{
+	u8 cmd;
+	u8 idcode0 = flash->idcode0;
+
+	if (idcode0 == 0x01) {
+		cmd = CMD_BANKADDR_BRRD;
+	} else {
+		printf("SF: Unsupported bank addr read %02x\n", idcode0);
+		return -1;
+	}
+
+	return spi_flash_read_common(flash, &cmd, 1, data, 1);
+}
+
 #ifdef CONFIG_OF_CONTROL
 int spi_flash_decode_fdt(const void *blob, struct spi_flash *flash)
 {
drivers/mtd/spi/spi_flash_internal.h +4 -0
index 6e38494..2567bbc 100644
@@ -30,6 +30,7 @@
 
 /* Bank addr acess commands */
 #define CMD_BANKADDR_BRWR		0x17
+#define CMD_BANKADDR_BRRD		0x16
 
 /* Common status */
 #define STATUS_WIP			0x01
@@ -83,6 +84,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);
 
+/* Read the bank address register */
+int spi_flash_cmd_bankaddr_read(struct spi_flash *flash, void *data);
+
 /*
  * 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
#3 lore raw

PATCH v2 3/16 sf: Add extended addr write support for winbond|stmicro

In reply to a message not in the archive

This patch provides support to program a flash extended address register for winbond and stmicro SPI flashes.

---
Changes for v2:
- none

 drivers/mtd/spi/spi_flash.c          | 2 ++
 drivers/mtd/spi/spi_flash_internal.h | 1 +
 2 files changed, 3 insertions(+)
drivers/mtd/spi/spi_flash.c +2 -0
index 193de42..05d1792 100644
@@ -286,6 +286,8 @@ int spi_flash_cmd_bankaddr_write(struct spi_flash *flash, u8 bank_sel)
 	idcode0 = flash->idcode0;
 	if (idcode0 == 0x01) {
 		cmd = CMD_BANKADDR_BRWR;
+	} else if ((idcode0 == 0xef) || (idcode0 == 0x20)) {
+		cmd = CMD_EXTNADDR_WREAR;
 	} else {
 		printf("SF: Unsupported bank addr write %02x\n", idcode0);
 		return -1;
drivers/mtd/spi/spi_flash_internal.h +1 -0
index 2567bbc..de1a0df 100644
@@ -31,6 +31,7 @@
 /* Bank addr acess commands */
 #define CMD_BANKADDR_BRWR		0x17
 #define CMD_BANKADDR_BRRD		0x16
+#define CMD_EXTNADDR_WREAR		0xC5
 
 /* Common status */
 #define STATUS_WIP			0x01
Signature · 1 line
1.8.3
#4 lore raw

PATCH v2 4/16 sf: Add extended addr read support for winbond|stmicro

In reply to a message not in the archive

This patch provides support to read a flash extended address register for winbond and stmicro SPI flashes.

---
Changes for v2:
- none

 drivers/mtd/spi/spi_flash.c          | 2 ++
 drivers/mtd/spi/spi_flash_internal.h | 1 +
 2 files changed, 3 insertions(+)
drivers/mtd/spi/spi_flash.c +2 -0
index 05d1792..66b6b14 100644
@@ -321,6 +321,8 @@ int spi_flash_cmd_bankaddr_read(struct spi_flash *flash, void *data)
 
 	if (idcode0 == 0x01) {
 		cmd = CMD_BANKADDR_BRRD;
+	} else if ((idcode0 == 0xef) || (idcode0 == 0x20)) {
+		cmd = CMD_EXTNADDR_RDEAR;
 	} else {
 		printf("SF: Unsupported bank addr read %02x\n", idcode0);
 		return -1;
drivers/mtd/spi/spi_flash_internal.h +1 -0
index de1a0df..1b29e2d 100644
@@ -32,6 +32,7 @@
 #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
Signature · 1 line
1.8.3
#5 lore raw

PATCH v2 5/16 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 v2:
- none

 drivers/mtd/spi/spi_flash.c          | 17 +++++++++++++++++
 drivers/mtd/spi/spi_flash_internal.h |  2 ++
 include/spi_flash.h                  |  2 ++
 3 files changed, 21 insertions(+)
drivers/mtd/spi/spi_flash.c +17 -0
index 66b6b14..4576a16 100644
@@ -283,6 +283,11 @@ int spi_flash_cmd_bankaddr_write(struct spi_flash *flash, u8 bank_sel)
 	u8 cmd, idcode0;
 	int ret;
 
+	if (flash->bank_curr == bank_sel) {
+		debug("SF: not require to enable bank%d\n", bank_sel);
+		return 0;
+	}
+
 	idcode0 = flash->idcode0;
 	if (idcode0 == 0x01) {
 		cmd = CMD_BANKADDR_BRWR;
@@ -304,6 +309,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) {
@@ -432,6 +438,7 @@ struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs,
 	struct spi_flash *flash = NULL;
 	int ret, i, shift;
 	u8 idcode[IDCODE_LEN], *idp;
+	u8 curr_bank = 0;
 
 	spi = spi_setup_slave(bus, cs, max_hz, spi_mode);
 	if (!spi) {
@@ -491,6 +498,16 @@ struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs,
 		printf(", mapped@%p", flash->memory_map);
 	puts("\n");
 
+	if (flash->size > SPI_FLASH_16MB_BOUN) {
+		if (spi_flash_cmd_bankaddr_read(flash, &curr_bank)) {
+			debug("SF: fail to read bank addr register\n");
+			goto err_manufacturer_probe;
+		}
+		flash->bank_curr = curr_bank;
+	} else {
+		flash->bank_curr = curr_bank;
+	}
+
 	spi_release_bus(spi);
 
 	return flash;
drivers/mtd/spi/spi_flash_internal.h +2 -0
index 1b29e2d..455dc02 100644
@@ -12,6 +12,8 @@
 #define SPI_FLASH_PAGE_ERASE_TIMEOUT	(5 * CONFIG_SYS_HZ)
 #define SPI_FLASH_SECTOR_ERASE_TIMEOUT	(10 * CONFIG_SYS_HZ)
 
+#define SPI_FLASH_16MB_BOUN		0x1000000
+
 /* Common commands */
 #define CMD_READ_ID			0x9f
 
include/spi_flash.h +2 -0
index 5ea42e1..acac17a 100644
@@ -40,6 +40,8 @@ struct spi_flash {
 	u32		sector_size;
 	/* ID code0 */
 	u8              idcode0;
+	/* 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 v2 6/16 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 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 4576a16..5386884 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 v2 6/16 sf: Update sf to support all sizes of flashes

Hi Jagan,

Quoted 7 lines · Jagannadha Sutradharudu Teki

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.

Quoted 7 lines

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.

I have a few comments on this series, but it mostly looks fine. I think the new code is correct.

The patches did not apply cleanly for me. Perhaps I am missing something. My tree looks like this after I did a bit of merging:

5864e87 (HEAD, try-spi) cfi_flash: Fix detection of 8-bit bus flash devices via address shift
f700095 sf: Add Flag status register polling support
42f4b70 sf: Remove spi_flash_cmd_poll_bit()
fc31387 sf: Use spi_flash_read_common() in write status poll 923e40e sf: spansion: Add support for S25FL512S_256K
c72e52a sf: stmicro: Add support for N25Q1024A
4066f71 sf: stmicro: Add support for N25Q1024
0efaf86 sf: stmicro: Add support for N25Q512A
8fd962f sf: stmicro: Add support for N25Q512
f1a2080 sf: Use spi_flash_addr() in write call
31ed498 sf: Update sf read to support all sizes of flashes 0f77642 sf: Update sf to support all sizes of flashes
9e57220 sf: read flash bank addr register at probe time
e99a43d sf: Add extended addr read support for winbond|stmicro 2f06d56 sf: Add extended addr write support for winbond|stmicro f02ecf1 sf: Add bank address register reading support
02ba27c sf: Add bank address register writing support

Also do you think spi_flash_cmd_bankaddr_write() and related stuff should be behind a flag like CONFIG_SPI_BANK_ADDR or similar? How much code space does this add?

In your change to spi_flash_cmd_poll_bit() the effect is not the same I think. It is designed to hold CS active and read the status byte continuously until it changes. But your implementation asserts CS, reads the status byte, de-asserts CS, then repeats. Why do we want to change this?

---

Quoted 27 lines

Changes for v2:
- none

 drivers/mtd/spi/spi_flash.c | 39 ++++++++++++++++++++++++++-------------
 1 file changed, 26 insertions(+), 13 deletions(-)
drivers/mtd/spi/spi_flash.c +1 -3
index 4576a16..5386884 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) {
drivers/mtd/spi/spi_flash.c +0 -0
@@ -88,6 +86,16 @@ int spi_flash_cmd_write_multi(struct spi_flash *flash,
 u32 offset,
 

drivers/mtd/spi/spi_flash.c int spi_flash_cmd_write_multi(struct spi_flash *flash, · line 97

Quoted 10 lines
drivers/mtd/spi/spi_flash.c +7 -0
        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;
+               }
 

So we are now doing this for all chips. But isn't it true that only some chips (>16MB?) have a bank address. If so, then I think we should have a flag somewhere to enable this feature

drivers/mtd/spi/spi_flash.c int spi_flash_cmd_write_multi(struct spi_flash *flash, u32 offset, · line 100

Quoted 4 lines
drivers/mtd/spi/spi_flash.c +3 -0
+
+               page_addr = offset / page_size;
+               byte_addr = offset % page_size;
 

This is OK I think. We really don't care about the slower divide so it is not worth optimising for I think.

Quoted 63 lines
                chunk_len = min(len - actual, page_size - byte_addr);

                if (flash->spi->max_write_size)
drivers/mtd/spi/spi_flash.c +1 -5
@@ -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);
drivers/mtd/spi/spi_flash.c +2 -2
@@ -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) {
drivers/mtd/spi/spi_flash.c +9 -3
@@ -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);
drivers/mtd/spi/spi_flash.c +3 -0
@@ -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;
        }
Quoted 6 lines

out:
--
1.8.3

Regards,
Simon

#8 lore raw

PATCH v2 6/16 sf: Update sf to support all sizes of flashes

Hi Simon,

Quoted 17 lines · Simon Glass

Hi Jagan,

Quoted 13 lines · Jagannadha Sutradharudu Teki

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.

Quoted 8 lines
Quoted 1 line

I have a few comments on this series, but it mostly looks fine. I think the new code is correct.

The patches did not apply cleanly for me. Perhaps I am missing something. My tree looks like this after I did a bit of merging:

Which patches you had an issues while applying,we have few patches on u-boot-spi.git i created these on top of it.

Quoted 20 lines

5864e87 (HEAD, try-spi) cfi_flash: Fix detection of 8-bit bus flash devices via address shift
f700095 sf: Add Flag status register polling support
42f4b70 sf: Remove spi_flash_cmd_poll_bit()
fc31387 sf: Use spi_flash_read_common() in write status poll 923e40e sf: spansion: Add support for S25FL512S_256K
c72e52a sf: stmicro: Add support for N25Q1024A
4066f71 sf: stmicro: Add support for N25Q1024
0efaf86 sf: stmicro: Add support for N25Q512A
8fd962f sf: stmicro: Add support for N25Q512
f1a2080 sf: Use spi_flash_addr() in write call
31ed498 sf: Update sf read to support all sizes of flashes 0f77642 sf: Update sf to support all sizes of flashes
9e57220 sf: read flash bank addr register at probe time
e99a43d sf: Add extended addr read support for winbond|stmicro 2f06d56 sf: Add extended addr write support for winbond|stmicro f02ecf1 sf: Add bank address register reading support
02ba27c sf: Add bank address register writing support

Quoted 3 lines

Also do you think spi_flash_cmd_bankaddr_write() and related stuff should be behind a flag like CONFIG_SPI_BANK_ADDR or similar? How much code space does this add?

Initially i thought of the same, but I just updated sf which is generic to all sizes of flashes.
due to this i haven't included the bank read/write on macros, and the flash ops will call these
bank write call irrespective of flash sizes.

As flashes which has below 16Mbytes will have a bank_curr value 0 so-that even bank write will exit for
bank 0 operations.

+ if (flash->bank_curr == bank_sel) {
+ debug("SF: not require to enable bank%d\n", bank_sel);
+ return 0;
+ }
+

And due to these framework changes bank+flash ops addition, bin size increases appr' ~600bytes
by enabling stmicro, winbond and spansion flash drivers.(please check the size from your end also if required)

Please see the commit body on below thread for more info
http://patchwork.ozlabs.org/patch/247954/

Quoted 5 lines

In your change to spi_flash_cmd_poll_bit() the effect is not the same I think. It is designed to hold CS active and read the status byte continuously until it changes. But your implementation asserts CS, reads the status byte, de-asserts CS, then repeats. Why do we want to change this?

I commented on the actual patch thread, please refer,

Quoted 31 lines
Quoted 31 lines

---
Changes for v2:
- none

 drivers/mtd/spi/spi_flash.c | 39 ++++++++++++++++++++++++++-------------
 1 file changed, 26 insertions(+), 13 deletions(-)
drivers/mtd/spi/spi_flash.c +1 -3
index 4576a16..5386884 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) {
drivers/mtd/spi/spi_flash.c +0 -0
@@ -88,6 +86,16 @@ int spi_flash_cmd_write_multi(struct spi_flash *flash,
 u32 offset,
 
Quoted 14 lines

drivers/mtd/spi/spi_flash.c int spi_flash_cmd_write_multi(struct spi_flash *flash, u32 offset, · line 95

Quoted 9 lines
drivers/mtd/spi/spi_flash.c +7 -0
        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;
+               }

So we are now doing this for all chips. But isn't it true that only some chips (>16MB?) have a bank address. If so, then I think we should have a flag somewhere to enable this feature

APAMK, currently stmicro, winbond, spansion and macronix have a flashes which has > 16Mbytes flashes.

And macronix is also have same bank setup like stmicro, extended addr read(RDEAR - 0xC8) and extended addr write(WREAR - 0xC5) We need to add this in near future.

I have added Prafulla Wadaskar on this thread (initial contributor for macronix.c), may be he will give some more information
for accessing > 16Mbytes flashes in 3-byte addr mode.

I think we can go ahead for now, may be we will tune sf some more in future based on the availability of different flash which crosses 16Mbytes
with different apparoch (other than banking/extended), what do you say?

Quoted 9 lines

drivers/mtd/spi/spi_flash.c int spi_flash_cmd_write_multi(struct spi_flash *flash, u32 offset, · line 98

Quoted 5 lines
drivers/mtd/spi/spi_flash.c +3 -0
+
+               page_addr = offset / page_size;
+               byte_addr = offset % page_size;

This is OK I think. We really don't care about the slower divide so it is not worth optimising for I think.

Yes, I just used the existing spi_flash_addr with offset as an argument, anyway sf write have a logic
to use writing in terms of page sizes and even offset is also varies page sizes or requested sizes.

Thanks,
Jagan.

#9 lore raw

PATCH v2 6/16 sf: Update sf to support all sizes of flashes

Hi,

Quoted 25 lines · Jagan Teki

Hi Simon,

Quoted 17 lines · Simon Glass

Hi Jagan,

Quoted 13 lines · Jagannadha Sutradharudu Teki

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.

Quoted 4 lines
Quoted 1 line

I have a few comments on this series, but it mostly looks fine. I think

the

Quoted 9 lines
Quoted 3 lines

new code is correct.

The patches did not apply cleanly for me. Perhaps I am missing

something. My

Quoted 1 line

tree looks like this after I did a bit of merging:

Which patches you had an issues while applying,we have few patches on u-boot-spi.git i created these on top of it.

I am not sure now - sorry I did not keep a record. But the bundle I used is here, and it doesn't apply cleanly.

http://patchwork.ozlabs.org/bundle/sjg/jagan/

git am ~/Downloads/bundle-4407-jagan.mbox
Applying: sf: Add bank address register writing support
Applying: sf: Add bank address register reading support
Applying: sf: Add extended addr write support for winbond|stmicro
Applying: sf: Add extended addr read support for winbond|stmicro
Applying: sf: read flash bank addr register at probe time
Applying: sf: Update sf to support all sizes of flashes
error: patch failed: drivers/mtd/spi/spi_flash.c:117
error: drivers/mtd/spi/spi_flash.c: patch does not apply Patch failed at 0006 sf: Update sf to support all sizes of flashes The copy of the patch that failed is found in:
/home/sjg/u/.git/rebase-apply/patch
When you have resolved this problem, run "git am --resolved". If you prefer to skip this patch, run "git am --skip" instead. To restore the original branch and stop patching, run "git am --abort"

Quoted 34 lines
Quoted 3 lines

5864e87 (HEAD, try-spi) cfi_flash: Fix detection of 8-bit bus flash

devices

Quoted 18 lines

via address shift
f700095 sf: Add Flag status register polling support 42f4b70 sf: Remove spi_flash_cmd_poll_bit()
fc31387 sf: Use spi_flash_read_common() in write status poll 923e40e sf: spansion: Add support for S25FL512S_256K c72e52a sf: stmicro: Add support for N25Q1024A 4066f71 sf: stmicro: Add support for N25Q1024
0efaf86 sf: stmicro: Add support for N25Q512A
8fd962f sf: stmicro: Add support for N25Q512
f1a2080 sf: Use spi_flash_addr() in write call 31ed498 sf: Update sf read to support all sizes of flashes 0f77642 sf: Update sf to support all sizes of flashes 9e57220 sf: read flash bank addr register at probe time e99a43d sf: Add extended addr read support for winbond|stmicro 2f06d56 sf: Add extended addr write support for winbond|stmicro f02ecf1 sf: Add bank address register reading support 02ba27c sf: Add bank address register writing support

Quoted 1 line

Also do you think spi_flash_cmd_bankaddr_write() and related stuff

should be

Quoted 1 line

behind a flag like CONFIG_SPI_BANK_ADDR or similar? How much code space

does

Quoted 1 line

this add?

Initially i thought of the same, but I just updated sf which is generic to all sizes of flashes.
due to this i haven't included the bank read/write on macros, and the flash ops will call these
bank write call irrespective of flash sizes.

Quoted 4 lines

As flashes which has below 16Mbytes will have a bank_curr value 0 so-that even bank write will exit for
bank 0 operations.

Yes this is fine.

Quoted 7 lines
(quoted diff) +5 -0
+       if (flash->bank_curr == bank_sel) {
+               debug("SF: not require to enable bank%d\n", bank_sel);
+               return 0;
+       }
+
Quoted 5 lines

And due to these framework changes bank+flash ops addition, bin size increases appr' ~600bytes
by enabling stmicro, winbond and spansion flash drivers.(please check the size from your end also if required)

I suggest you make that function a nop (perhaps using an #ifdef CONFIG_SPI_BANK_ADDR
inside it or some other name) so that your patches don't increase U-Boot code size for those boards that don't need support larger devices (which I guess is almost all of them, right now). U-Boot is quite concerned about code size.

Tom may chime in and decide it is fine, though.

Quoted 5 lines

Please see the commit body on below thread for more info
http://patchwork.ozlabs.org/patch/247954/

Quoted 1 line
Quoted 8 lines
Quoted 3 lines

In your change to spi_flash_cmd_poll_bit() the effect is not the same I think. It is designed to hold CS active and read the status byte continuously until it changes. But your implementation asserts CS, reads

the

Quoted 1 line

status byte, de-asserts CS, then repeats. Why do we want to change this?

I commented on the actual patch thread, please refer,

OK I will take a look.

Quoted 57 lines
Quoted 9 lines
Quoted 9 lines

---
Changes for v2:
- none

 drivers/mtd/spi/spi_flash.c | 39

++++++++++++++++++++++++++-------------

Quoted 7 lines

drivers/mtd/spi/spi_flash.c int spi_flash_cmd_write_multi(struct spi_flash

Quoted 7 lines
 1 file changed, 26 insertions(+), 13 deletions(-)
drivers/mtd/spi/spi_flash.c +0 -0
index 4576a16..5386884 100644
@@ -74,11 +74,9 @@ int spi_flash_cmd_write_multi(struct spi_flash

*flash,

Quoted 7 lines
Quoted 7 lines
drivers/mtd/spi/spi_flash.c +1 -1
 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;
 
Quoted 7 lines

drivers/mtd/spi/spi_flash.c int spi_flash_cmd_write_multi(struct spi_flash

Quoted 7 lines
drivers/mtd/spi/spi_flash.c +0 -2
        page_size = flash->page_size;
-       page_addr = offset / page_size;
-       byte_addr = offset % page_size;
 
        ret = spi_claim_bus(flash->spi);
        if (ret) {
drivers/mtd/spi/spi_flash.c +0 -0
@@ -88,6 +86,16 @@ int spi_flash_cmd_write_multi(struct spi_flash

*flash,

Quoted 13 lines

drivers/mtd/spi/spi_flash.c int spi_flash_cmd_write_multi(struct spi_flash *flash, u32 offset, · line 95

Quoted 11 lines
drivers/mtd/spi/spi_flash.c +7 -0
 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;
+               }
Quoted 3 lines

So we are now doing this for all chips. But isn't it true that only some chips (>16MB?) have a bank address. If so, then I think we should have a flag somewhere to enable this feature

APAMK, currently stmicro, winbond, spansion and macronix have a flashes which has > 16Mbytes flashes.

And macronix is also have same bank setup like stmicro, extended addr read(RDEAR - 0xC8) and extended addr write(WREAR - 0xC5) We need to add this in near future.

Quoted 9 lines

I have added Prafulla Wadaskar on this thread (initial contributor for macronix.c), may be he will give some more information
for accessing > 16Mbytes flashes in 3-byte addr mode.

I think we can go ahead for now, may be we will tune sf some more in future based on the availability of different flash which crosses 16Mbytes
with different apparoch (other than banking/extended), what do you say?

OK, well we don't need a flag since you will never issue the bank address command unless the chip is larger than 16MB.,

Quoted 11 lines
Quoted 10 lines

drivers/mtd/spi/spi_flash.c int spi_flash_cmd_write_multi(struct spi_flash *flash, u32 offset, · line 98

Quoted 6 lines
drivers/mtd/spi/spi_flash.c +3 -0
+
+               page_addr = offset / page_size;
+               byte_addr = offset % page_size;

This is OK I think. We really don't care about the slower divide so it is not worth optimising for I think.

Quoted 8 lines

Yes, I just used the existing spi_flash_addr with offset as an argument, anyway sf write have a logic
to use writing in terms of page sizes and even offset is also varies page sizes or requested sizes.

Thanks,
Jagan.

Regards,
Simon

#10 lore raw

PATCH v2 6/16 sf: Update sf to support all sizes of flashes

Hi Simon,

Quoted 116 lines · Simon Glass

Hi,

Quoted 28 lines · Jagan Teki

Hi Simon,

Quoted 24 lines · Simon Glass

Hi Jagan,

Quoted 8 lines · Jagannadha Sutradharudu Teki

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.

Quoted 6 lines

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.

I have a few comments on this series, but it mostly looks fine. I think the
new code is correct.

Quoted 6 lines
Quoted 3 lines

The patches did not apply cleanly for me. Perhaps I am missing something. My
tree looks like this after I did a bit of merging:

Which patches you had an issues while applying,we have few patches on u-boot-spi.git i created these on top of it.

I am not sure now - sorry I did not keep a record. But the bundle I used is here, and it doesn't apply cleanly.

http://patchwork.ozlabs.org/bundle/sjg/jagan/

git am ~/Downloads/bundle-4407-jagan.mbox
Applying: sf: Add bank address register writing support
Applying: sf: Add bank address register reading support
Applying: sf: Add extended addr write support for winbond|stmicro
Applying: sf: Add extended addr read support for winbond|stmicro
Applying: sf: read flash bank addr register at probe time
Applying: sf: Update sf to support all sizes of flashes
error: patch failed: drivers/mtd/spi/spi_flash.c:117
error: drivers/mtd/spi/spi_flash.c: patch does not apply Patch failed at 0006 sf: Update sf to support all sizes of flashes The copy of the patch that failed is found in:
/home/sjg/u/.git/rebase-apply/patch
When you have resolved this problem, run "git am --resolved". If you prefer to skip this patch, run "git am --skip" instead. To restore the original branch and stop patching, run "git am --abort"

Quoted 35 lines
Quoted 23 lines

5864e87 (HEAD, try-spi) cfi_flash: Fix detection of 8-bit bus flash devices
via address shift
f700095 sf: Add Flag status register polling support 42f4b70 sf: Remove spi_flash_cmd_poll_bit()
fc31387 sf: Use spi_flash_read_common() in write status poll 923e40e sf: spansion: Add support for S25FL512S_256K c72e52a sf: stmicro: Add support for N25Q1024A
4066f71 sf: stmicro: Add support for N25Q1024
0efaf86 sf: stmicro: Add support for N25Q512A
8fd962f sf: stmicro: Add support for N25Q512
f1a2080 sf: Use spi_flash_addr() in write call
31ed498 sf: Update sf read to support all sizes of flashes 0f77642 sf: Update sf to support all sizes of flashes 9e57220 sf: read flash bank addr register at probe time e99a43d sf: Add extended addr read support for winbond|stmicro 2f06d56 sf: Add extended addr write support for winbond|stmicro f02ecf1 sf: Add bank address register reading support 02ba27c sf: Add bank address register writing support

Quoted 5 lines

Also do you think spi_flash_cmd_bankaddr_write() and related stuff should be
behind a flag like CONFIG_SPI_BANK_ADDR or similar? How much code space does
this add?

Initially i thought of the same, but I just updated sf which is generic to all sizes of flashes.
due to this i haven't included the bank read/write on macros, and the flash ops will call these
bank write call irrespective of flash sizes.

Quoted 3 lines

As flashes which has below 16Mbytes will have a bank_curr value 0 so-that even bank write will exit for
bank 0 operations.

Yes this is fine.

Quoted 8 lines
(quoted diff) +5 -0
+       if (flash->bank_curr == bank_sel) {
+               debug("SF: not require to enable bank%d\n", bank_sel);
+               return 0;
+       }
+
Quoted 4 lines

And due to these framework changes bank+flash ops addition, bin size increases appr' ~600bytes
by enabling stmicro, winbond and spansion flash drivers.(please check the size from your end also if required)

Quoted 5 lines

I suggest you make that function a nop (perhaps using an #ifdef CONFIG_SPI_BANK_ADDR inside it or some other name) so that your patches don't increase U-Boot code size for those boards that don't need support larger devices (which I guess is almost all of them, right now). U-Boot is quite concerned about code size.

Little concern here, the point here I stated is this new changes is common for all sizes of flashes.(which are less or greater than 16Mbytes).
and yes it increase the code size little bit but i don't think it will require the separate macro.

Thanks,
Jagan.

Quoted 117 lines

Tom may chime in and decide it is fine, though.

Quoted 6 lines

Please see the commit body on below thread for more info
http://patchwork.ozlabs.org/patch/247954/

Quoted 1 line
Quoted 7 lines
Quoted 5 lines

In your change to spi_flash_cmd_poll_bit() the effect is not the same I think. It is designed to hold CS active and read the status byte continuously until it changes. But your implementation asserts CS, reads the
status byte, de-asserts CS, then repeats. Why do we want to change this?

I commented on the actual patch thread, please refer,

OK I will take a look.

Quoted 58 lines
Quoted 36 lines
Quoted 36 lines

---
Changes for v2:
- none

 drivers/mtd/spi/spi_flash.c | 39
++++++++++++++++++++++++++-------------
 1 file changed, 26 insertions(+), 13 deletions(-)
drivers/mtd/spi/spi_flash.c +1 -3
index 4576a16..5386884 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) {
drivers/mtd/spi/spi_flash.c +0 -0
@@ -88,6 +86,16 @@ int spi_flash_cmd_write_multi(struct spi_flash
 *flash,
 u32 offset,
 
Quoted 14 lines

drivers/mtd/spi/spi_flash.c int spi_flash_cmd_write_multi(struct spi_flash *flash, u32 offset, · line 95

Quoted 9 lines
drivers/mtd/spi/spi_flash.c +7 -0
        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;
+               }

So we are now doing this for all chips. But isn't it true that only some chips (>16MB?) have a bank address. If so, then I think we should have a flag somewhere to enable this feature

APAMK, currently stmicro, winbond, spansion and macronix have a flashes which has > 16Mbytes flashes.

And macronix is also have same bank setup like stmicro, extended addr read(RDEAR - 0xC8) and extended addr write(WREAR - 0xC5) We need to add this in near future.

Quoted 8 lines

I have added Prafulla Wadaskar on this thread (initial contributor for macronix.c), may be he will give some more information
for accessing > 16Mbytes flashes in 3-byte addr mode.

I think we can go ahead for now, may be we will tune sf some more in future based on the availability of different flash which crosses 16Mbytes
with different apparoch (other than banking/extended), what do you say?

OK, well we don't need a flag since you will never issue the bank address command unless the chip is larger than 16MB.,

Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
Quoted 8 lines

drivers/mtd/spi/spi_flash.c int spi_flash_cmd_write_multi(struct spi_flash *flash, u32 offset, · line 98

Quoted 3 lines
drivers/mtd/spi/spi_flash.c +3 -0
+
+               page_addr = offset / page_size;
+               byte_addr = offset % page_size;

This is OK I think. We really don't care about the slower divide so it is
not worth optimising for I think.

Quoted 7 lines

Yes, I just used the existing spi_flash_addr with offset as an argument, anyway sf write have a logic
to use writing in terms of page sizes and even offset is also varies page sizes or requested sizes.

Thanks,
Jagan.

Regards,
Simon

#11 lore raw

PATCH v2 6/16 sf: Update sf to support all sizes of flashes

Hi Tom,

Quoted 125 lines · Jagan Teki

Hi Simon,

Quoted 116 lines · Simon Glass

Hi,

Quoted 28 lines · Jagan Teki

Hi Simon,

Quoted 24 lines · Simon Glass

Hi Jagan,

Quoted 8 lines · Jagannadha Sutradharudu Teki

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.

Quoted 6 lines

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.

I have a few comments on this series, but it mostly looks fine. I think the
new code is correct.

Quoted 6 lines
Quoted 3 lines

The patches did not apply cleanly for me. Perhaps I am missing something. My
tree looks like this after I did a bit of merging:

Which patches you had an issues while applying,we have few patches on u-boot-spi.git i created these on top of it.

I am not sure now - sorry I did not keep a record. But the bundle I used is here, and it doesn't apply cleanly.

http://patchwork.ozlabs.org/bundle/sjg/jagan/

git am ~/Downloads/bundle-4407-jagan.mbox
Applying: sf: Add bank address register writing support
Applying: sf: Add bank address register reading support
Applying: sf: Add extended addr write support for winbond|stmicro
Applying: sf: Add extended addr read support for winbond|stmicro
Applying: sf: read flash bank addr register at probe time
Applying: sf: Update sf to support all sizes of flashes
error: patch failed: drivers/mtd/spi/spi_flash.c:117
error: drivers/mtd/spi/spi_flash.c: patch does not apply Patch failed at 0006 sf: Update sf to support all sizes of flashes The copy of the patch that failed is found in:
/home/sjg/u/.git/rebase-apply/patch
When you have resolved this problem, run "git am --resolved". If you prefer to skip this patch, run "git am --skip" instead. To restore the original branch and stop patching, run "git am --abort"

Quoted 35 lines
Quoted 23 lines

5864e87 (HEAD, try-spi) cfi_flash: Fix detection of 8-bit bus flash devices
via address shift
f700095 sf: Add Flag status register polling support 42f4b70 sf: Remove spi_flash_cmd_poll_bit()
fc31387 sf: Use spi_flash_read_common() in write status poll 923e40e sf: spansion: Add support for S25FL512S_256K c72e52a sf: stmicro: Add support for N25Q1024A
4066f71 sf: stmicro: Add support for N25Q1024
0efaf86 sf: stmicro: Add support for N25Q512A
8fd962f sf: stmicro: Add support for N25Q512
f1a2080 sf: Use spi_flash_addr() in write call
31ed498 sf: Update sf read to support all sizes of flashes 0f77642 sf: Update sf to support all sizes of flashes 9e57220 sf: read flash bank addr register at probe time e99a43d sf: Add extended addr read support for winbond|stmicro 2f06d56 sf: Add extended addr write support for winbond|stmicro f02ecf1 sf: Add bank address register reading support 02ba27c sf: Add bank address register writing support

Quoted 5 lines

Also do you think spi_flash_cmd_bankaddr_write() and related stuff should be
behind a flag like CONFIG_SPI_BANK_ADDR or similar? How much code space does
this add?

Initially i thought of the same, but I just updated sf which is generic to all sizes of flashes.
due to this i haven't included the bank read/write on macros, and the flash ops will call these
bank write call irrespective of flash sizes.

Quoted 3 lines

As flashes which has below 16Mbytes will have a bank_curr value 0 so-that even bank write will exit for
bank 0 operations.

Yes this is fine.

Quoted 8 lines
(quoted diff) +5 -0
+       if (flash->bank_curr == bank_sel) {
+               debug("SF: not require to enable bank%d\n", bank_sel);
+               return 0;
+       }
+
Quoted 4 lines

And due to these framework changes bank+flash ops addition, bin size increases appr' ~600bytes
by enabling stmicro, winbond and spansion flash drivers.(please check the size from your end also if required)

Quoted 5 lines

I suggest you make that function a nop (perhaps using an #ifdef CONFIG_SPI_BANK_ADDR inside it or some other name) so that your patches don't increase U-Boot code size for those boards that don't need support larger devices (which I guess is almost all of them, right now). U-Boot is quite concerned about code size.

Quoted 5 lines

Little concern here, the point here I stated that these new changes is common for all sizes of flashes.(which are less or greater than 16Mbytes).
and yes it increase the code size little bit but i don't think it will require the separate macro.

Any comments.

--
Thanks,
Jagan.

Quoted 121 lines

Thanks,
Jagan.

Quoted 117 lines

Tom may chime in and decide it is fine, though.

Quoted 6 lines

Please see the commit body on below thread for more info
http://patchwork.ozlabs.org/patch/247954/

Quoted 1 line
Quoted 7 lines
Quoted 5 lines

In your change to spi_flash_cmd_poll_bit() the effect is not the same I think. It is designed to hold CS active and read the status byte continuously until it changes. But your implementation asserts CS, reads the
status byte, de-asserts CS, then repeats. Why do we want to change this?

I commented on the actual patch thread, please refer,

OK I will take a look.

Quoted 58 lines
Quoted 36 lines
Quoted 36 lines

---
Changes for v2:
- none

 drivers/mtd/spi/spi_flash.c | 39
++++++++++++++++++++++++++-------------
 1 file changed, 26 insertions(+), 13 deletions(-)
drivers/mtd/spi/spi_flash.c +1 -3
index 4576a16..5386884 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) {
drivers/mtd/spi/spi_flash.c +0 -0
@@ -88,6 +86,16 @@ int spi_flash_cmd_write_multi(struct spi_flash
 *flash,
 u32 offset,
 
Quoted 14 lines

drivers/mtd/spi/spi_flash.c int spi_flash_cmd_write_multi(struct spi_flash *flash, u32 offset, · line 95

Quoted 9 lines
drivers/mtd/spi/spi_flash.c +7 -0
        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;
+               }

So we are now doing this for all chips. But isn't it true that only some chips (>16MB?) have a bank address. If so, then I think we should have a flag somewhere to enable this feature

APAMK, currently stmicro, winbond, spansion and macronix have a flashes which has > 16Mbytes flashes.

And macronix is also have same bank setup like stmicro, extended addr read(RDEAR - 0xC8) and extended addr write(WREAR - 0xC5) We need to add this in near future.

Quoted 8 lines

I have added Prafulla Wadaskar on this thread (initial contributor for macronix.c), may be he will give some more information
for accessing > 16Mbytes flashes in 3-byte addr mode.

I think we can go ahead for now, may be we will tune sf some more in future based on the availability of different flash which crosses 16Mbytes
with different apparoch (other than banking/extended), what do you say?

OK, well we don't need a flag since you will never issue the bank address command unless the chip is larger than 16MB.,

Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
Quoted 8 lines

drivers/mtd/spi/spi_flash.c int spi_flash_cmd_write_multi(struct spi_flash *flash, u32 offset, · line 98

Quoted 3 lines
drivers/mtd/spi/spi_flash.c +3 -0
+
+               page_addr = offset / page_size;
+               byte_addr = offset % page_size;

This is OK I think. We really don't care about the slower divide so it is
not worth optimising for I think.

Quoted 7 lines

Yes, I just used the existing spi_flash_addr with offset as an argument, anyway sf write have a logic
to use writing in terms of page sizes and even offset is also varies page sizes or requested sizes.

Thanks,
Jagan.

Regards,
Simon

#12 lore raw

PATCH v2 6/16 sf: Update sf to support all sizes of flashes

Quoted 135 lines · Jagan Teki

Hi Tom,

Quoted 6 lines · Jagan Teki

Hi Simon,

Quoted 3 lines · Simon Glass

Hi,

On Sat, Jun 8, 2013 at 1:22 AM, Jagan Teki <[email protected]>

Quoted 6 lines · wrote:
Quoted 6 lines
Quoted 6 lines

Hi Simon,

Quoted 2 lines · Simon Glass

Hi Jagan,

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines · Jagannadha Sutradharudu Teki

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

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 8 lines

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.

I have a few comments on this series, but it mostly looks fine. I

think

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines

the
new code is correct.

The patches did not apply cleanly for me. Perhaps I am missing something. My
tree looks like this after I did a bit of merging:

Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

Which patches you had an issues while applying,we have few patches on u-boot-spi.git i created these on top of it.

I am not sure now - sorry I did not keep a record. But the bundle I

used is

Quoted 43 lines
Quoted 43 lines

here, and it doesn't apply cleanly.

http://patchwork.ozlabs.org/bundle/sjg/jagan/

git am ~/Downloads/bundle-4407-jagan.mbox
Applying: sf: Add bank address register writing support
Applying: sf: Add bank address register reading support
Applying: sf: Add extended addr write support for winbond|stmicro
Applying: sf: Add extended addr read support for winbond|stmicro
Applying: sf: read flash bank addr register at probe time
Applying: sf: Update sf to support all sizes of flashes
error: patch failed: drivers/mtd/spi/spi_flash.c:117
error: drivers/mtd/spi/spi_flash.c: patch does not apply Patch failed at 0006 sf: Update sf to support all sizes of flashes The copy of the patch that failed is found in:
/home/sjg/u/.git/rebase-apply/patch
When you have resolved this problem, run "git am --resolved". If you prefer to skip this patch, run "git am --skip" instead. To restore the original branch and stop patching, run "git am --abort"

Quoted 23 lines
Quoted 23 lines

5864e87 (HEAD, try-spi) cfi_flash: Fix detection of 8-bit bus flash devices
via address shift
f700095 sf: Add Flag status register polling support 42f4b70 sf: Remove spi_flash_cmd_poll_bit()
fc31387 sf: Use spi_flash_read_common() in write status poll 923e40e sf: spansion: Add support for S25FL512S_256K c72e52a sf: stmicro: Add support for N25Q1024A
4066f71 sf: stmicro: Add support for N25Q1024
0efaf86 sf: stmicro: Add support for N25Q512A
8fd962f sf: stmicro: Add support for N25Q512
f1a2080 sf: Use spi_flash_addr() in write call
31ed498 sf: Update sf read to support all sizes of flashes 0f77642 sf: Update sf to support all sizes of flashes 9e57220 sf: read flash bank addr register at probe time e99a43d sf: Add extended addr read support for winbond|stmicro 2f06d56 sf: Add extended addr write support for winbond|stmicro f02ecf1 sf: Add bank address register reading support 02ba27c sf: Add bank address register writing support

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Also do you think spi_flash_cmd_bankaddr_write() and related stuff should be
behind a flag like CONFIG_SPI_BANK_ADDR or similar? How much code

space

Quoted 30 lines
Quoted 30 lines
Quoted 9 lines
Quoted 2 lines

does
this add?

Initially i thought of the same, but I just updated sf which is generic to all sizes of flashes.
due to this i haven't included the bank read/write on macros, and the flash ops will call these
bank write call irrespective of flash sizes.

Quoted 3 lines

As flashes which has below 16Mbytes will have a bank_curr value 0 so-that even bank write will exit for
bank 0 operations.

Yes this is fine.

Quoted 12 lines
(quoted diff) +5 -0
+       if (flash->bank_curr == bank_sel) {
+               debug("SF: not require to enable bank%d\n", bank_sel);
+               return 0;
+       }
+

And due to these framework changes bank+flash ops addition, bin size increases appr' ~600bytes
by enabling stmicro, winbond and spansion flash drivers.(please check the size from your end also if required)

Quoted 4 lines
Quoted 4 lines

I suggest you make that function a nop (perhaps using an #ifdef CONFIG_SPI_BANK_ADDR inside it or some other name) so that your patches don't increase U-Boot code size for those boards that don't need support larger devices (which I guess is almost all of them, right now). U-Boot

is

Quoted 2 lines
Quoted 1 line

quite concerned about code size.

Quoted 8 lines
Quoted 5 lines

Little concern here, the point here I stated that these new changes is common for all sizes of flashes.(which are less or greater than 16Mbytes).
and yes it increase the code size little bit but i don't think it will require the separate macro.

Any comments.

In U-Boot it is generally not acceptable to increase code size for existing boards when adding a new feature that they don't use. So I suspect in this case you should add a new CONFIG to enable your feature. It seems to increase code by more than 200 bytes for snow, for example.

Tom may have further comments.

Also my buildman run of your commit gave an error on this commit:

07: sf: Update sf to support all sizes of flashes

Regards,
Simon

Quoted 135 lines

--
Thanks,
Jagan.

Quoted 14 lines

Thanks,
Jagan.

Quoted 10 lines

Tom may chime in and decide it is fine, though.

Quoted 7 lines

Please see the commit body on below thread for more info
http://patchwork.ozlabs.org/patch/247954/

Quoted 2 lines

In your change to spi_flash_cmd_poll_bit() the effect is not the

same I

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

think. It is designed to hold CS active and read the status byte continuously until it changes. But your implementation asserts CS,

reads

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

the
status byte, de-asserts CS, then repeats. Why do we want to change

this?

Quoted 15 lines
Quoted 15 lines
Quoted 2 lines

I commented on the actual patch thread, please refer,

OK I will take a look.

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

---
Changes for v2:
- none

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Review

Quoted 5 lines
 drivers/mtd/spi/spi_flash.c | 39
++++++++++++++++++++++++++-------------
 1 file changed, 26 insertions(+), 13 deletions(-)
(quoted diff) +0 -0

b/drivers/mtd/spi/spi_flash.c

Quoted 22 lines
Quoted 22 lines
Quoted 22 lines
Quoted 22 lines
Quoted 22 lines

index 4576a16..5386884 100644

drivers/mtd/spi/spi_flash.c +1 -3
@@ -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) {
drivers/mtd/spi/spi_flash.c +0 -0
@@ -88,6 +86,16 @@ int spi_flash_cmd_write_multi(struct spi_flash
 *flash,
 u32 offset,
 
Quoted 12 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 9 lines
drivers/mtd/spi/spi_flash.c +7 -0
        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;
+               }
Quoted 1 line
Quoted 1 line
Quoted 1 line

So we are now doing this for all chips. But isn't it true that only

some

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

chips (>16MB?) have a bank address. If so, then I think we should

have a

Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 1 line

flag somewhere to enable this feature

APAMK, currently stmicro, winbond, spansion and macronix have a flashes which has > 16Mbytes flashes.

And macronix is also have same bank setup like stmicro, extended addr read(RDEAR - 0xC8) and extended addr write(WREAR - 0xC5) We need to add this in near future.

I have added Prafulla Wadaskar on this thread (initial contributor for macronix.c), may be he will give some more information
for accessing > 16Mbytes flashes in 3-byte addr mode.

Quoted 7 lines
Quoted 7 lines
Quoted 4 lines

I think we can go ahead for now, may be we will tune sf some more in future based on the availability of different flash which crosses 16Mbytes
with different apparoch (other than banking/extended), what do you say?

OK, well we don't need a flag since you will never issue the bank

address

Quoted 6 lines
Quoted 6 lines

command unless the chip is larger than 16MB.,

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

drivers/mtd/spi/spi_flash.c int spi_flash_cmd_write_multi(struct spi_flash *flash, u32 offset, · line 98

Quoted 3 lines
drivers/mtd/spi/spi_flash.c +3 -0
+
+               page_addr = offset / page_size;
+               byte_addr = offset % page_size;

This is OK I think. We really don't care about the slower divide so

it

Quoted 16 lines
Quoted 16 lines
Quoted 10 lines
Quoted 2 lines

is
not worth optimising for I think.

Yes, I just used the existing spi_flash_addr with offset as an argument, anyway sf write have a logic
to use writing in terms of page sizes and even offset is also varies page sizes or requested sizes.

Thanks,
Jagan.

Regards,
Simon

#13 lore raw

PATCH v2 6/16 sf: Update sf to support all sizes of flashes

Hi Simon,

Quoted 146 lines · Simon Glass
Quoted 144 lines · Jagan Teki

Hi Tom,

Quoted 138 lines · Jagan Teki

Hi Simon,

Quoted 122 lines · Simon Glass

Hi,

Quoted 31 lines · Jagan Teki

Hi Simon,

Quoted 27 lines · Simon Glass

Hi Jagan,

Quoted 10 lines · Jagannadha Sutradharudu Teki

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.

Quoted 6 lines

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.

I have a few comments on this series, but it mostly looks fine. I think
the
new code is correct.

Quoted 6 lines
Quoted 3 lines

The patches did not apply cleanly for me. Perhaps I am missing something. My
tree looks like this after I did a bit of merging:

Which patches you had an issues while applying,we have few patches on u-boot-spi.git i created these on top of it.

I am not sure now - sorry I did not keep a record. But the bundle I used is
here, and it doesn't apply cleanly.

http://patchwork.ozlabs.org/bundle/sjg/jagan/

git am ~/Downloads/bundle-4407-jagan.mbox
Applying: sf: Add bank address register writing support
Applying: sf: Add bank address register reading support
Applying: sf: Add extended addr write support for winbond|stmicro
Applying: sf: Add extended addr read support for winbond|stmicro
Applying: sf: read flash bank addr register at probe time
Applying: sf: Update sf to support all sizes of flashes
error: patch failed: drivers/mtd/spi/spi_flash.c:117
error: drivers/mtd/spi/spi_flash.c: patch does not apply Patch failed at 0006 sf: Update sf to support all sizes of flashes The copy of the patch that failed is found in:
/home/sjg/u/.git/rebase-apply/patch
When you have resolved this problem, run "git am --resolved". If you prefer to skip this patch, run "git am --skip" instead. To restore the original branch and stop patching, run "git am --abort"

Quoted 36 lines
Quoted 23 lines

5864e87 (HEAD, try-spi) cfi_flash: Fix detection of 8-bit bus flash devices
via address shift
f700095 sf: Add Flag status register polling support 42f4b70 sf: Remove spi_flash_cmd_poll_bit()
fc31387 sf: Use spi_flash_read_common() in write status poll 923e40e sf: spansion: Add support for S25FL512S_256K c72e52a sf: stmicro: Add support for N25Q1024A
4066f71 sf: stmicro: Add support for N25Q1024
0efaf86 sf: stmicro: Add support for N25Q512A
8fd962f sf: stmicro: Add support for N25Q512
f1a2080 sf: Use spi_flash_addr() in write call
31ed498 sf: Update sf read to support all sizes of flashes 0f77642 sf: Update sf to support all sizes of flashes 9e57220 sf: read flash bank addr register at probe time e99a43d sf: Add extended addr read support for winbond|stmicro 2f06d56 sf: Add extended addr write support for winbond|stmicro f02ecf1 sf: Add bank address register reading support 02ba27c sf: Add bank address register writing support

Quoted 6 lines

Also do you think spi_flash_cmd_bankaddr_write() and related stuff should be
behind a flag like CONFIG_SPI_BANK_ADDR or similar? How much code space
does
this add?

Initially i thought of the same, but I just updated sf which is generic to all sizes of flashes.
due to this i haven't included the bank read/write on macros, and the flash ops will call these
bank write call irrespective of flash sizes.

Quoted 3 lines

As flashes which has below 16Mbytes will have a bank_curr value 0 so-that even bank write will exit for
bank 0 operations.

Yes this is fine.

Quoted 8 lines
(quoted diff) +5 -0
+       if (flash->bank_curr == bank_sel) {
+               debug("SF: not require to enable bank%d\n", bank_sel);
+               return 0;
+       }
+
Quoted 4 lines

And due to these framework changes bank+flash ops addition, bin size increases appr' ~600bytes
by enabling stmicro, winbond and spansion flash drivers.(please check the size from your end also if required)

Quoted 7 lines

I suggest you make that function a nop (perhaps using an #ifdef CONFIG_SPI_BANK_ADDR inside it or some other name) so that your patches don't increase U-Boot code size for those boards that don't need support
larger devices (which I guess is almost all of them, right now). U-Boot is
quite concerned about code size.

Little concern here, the point here I stated that these new changes is common for all sizes of flashes.(which are less or greater than 16Mbytes).
and yes it increase the code size little bit but i don't think it will require the separate macro.

Quoted 7 lines
Quoted 1 line

Any comments.

In U-Boot it is generally not acceptable to increase code size for existing boards when adding a new feature that they don't use. So I suspect in this case you should add a new CONFIG to enable your feature. It seems to increase code by more than 200 bytes for snow, for example.

OK, I did coding on sf to have a common framework for all sizes of flashes in mind.
but as you said it's increasing the size of u-boot.bin > 200 bytes.

Seems like no choice to comprise, I am going to create v3 series for these changes.
Will that be OK?

Quoted 6 lines

Tom may have further comments.

Also my buildman run of your commit gave an error on this commit:

07: sf: Update sf to support all sizes of flashes

I am created these patches on top of u-boot-spi.git, there some patches already available on sf.
may be you used master.

Thanks,
Jagan.

Quoted 145 lines

Regards,
Simon

Quoted 138 lines

--
Thanks,
Jagan.

Quoted 132 lines

Thanks,
Jagan.

Quoted 128 lines

Tom may chime in and decide it is fine, though.

Quoted 15 lines

Please see the commit body on below thread for more info
http://patchwork.ozlabs.org/patch/247954/

Quoted 9 lines

In your change to spi_flash_cmd_poll_bit() the effect is not the same I
think. It is designed to hold CS active and read the status byte continuously until it changes. But your implementation asserts CS, reads
the
status byte, de-asserts CS, then repeats. Why do we want to change this?

Quoted 1 line

I commented on the actual patch thread, please refer,

OK I will take a look.

Quoted 67 lines
Quoted 47 lines
Quoted 47 lines

---
Changes for v2:
- none

 drivers/mtd/spi/spi_flash.c | 39
++++++++++++++++++++++++++-------------
 1 file changed, 26 insertions(+), 13 deletions(-)
drivers/mtd/spi/spi_flash.c +1 -3
index 4576a16..5386884 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) {
drivers/mtd/spi/spi_flash.c +5 -0
@@ -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;

Quoted 8 lines
Quoted 1 line

+ }

So we are now doing this for all chips. But isn't it true that only some
chips (>16MB?) have a bank address. If so, then I think we should have a
flag somewhere to enable this feature

APAMK, currently stmicro, winbond, spansion and macronix have a flashes which has > 16Mbytes flashes.

And macronix is also have same bank setup like stmicro, extended addr read(RDEAR - 0xC8) and extended addr write(WREAR - 0xC5) We need to add this in near future.

I have added Prafulla Wadaskar on this thread (initial contributor for macronix.c), may be he will give some more information
for accessing > 16Mbytes flashes in 3-byte addr mode.

Quoted 5 lines

I think we can go ahead for now, may be we will tune sf some more in future based on the availability of different flash which crosses 16Mbytes
with different apparoch (other than banking/extended), what do you say?

OK, well we don't need a flag since you will never issue the bank address
command unless the chip is larger than 16MB.,

Quoted 14 lines
Quoted 9 lines

drivers/mtd/spi/spi_flash.c

Quoted 7 lines
drivers/mtd/spi/spi_flash.c +3 -0
+
+               page_addr = offset / page_size;
+               byte_addr = offset % page_size;
Quoted 4 lines

This is OK I think. We really don't care about the slower divide so it
is
not worth optimising for I think.

Quoted 7 lines

Yes, I just used the existing spi_flash_addr with offset as an argument, anyway sf write have a logic
to use writing in terms of page sizes and even offset is also varies page sizes or requested sizes.

Thanks,
Jagan.

Regards,
Simon

#14 lore raw

PATCH v2 6/16 sf: Update sf to support all sizes of flashes

Hi Jagan,

Quoted 170 lines · Jagan Teki

Hi Simon,

Quoted 19 lines · Simon Glass
Quoted 17 lines · Jagan Teki

Hi Tom,

Quoted 12 lines · Jagan Teki

Hi Simon,

Quoted 9 lines · Simon Glass

Hi,

On Sat, Jun 8, 2013 at 1:22 AM, Jagan Teki <[email protected]

Quoted 4 lines · wrote:

Hi Simon,

On Sat, Jun 8, 2013 at 4:44 AM, Simon Glass <[email protected]>

Quoted 14 lines · wrote:
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines

Hi Jagan,

Quoted 10 lines · Jagannadha Sutradharudu Teki

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.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

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

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 3 lines

for performing write/erase operations on all flashes.

I have a few comments on this series, but it mostly looks fine. I think
the
new code is correct.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines

The patches did not apply cleanly for me. Perhaps I am missing something. My
tree looks like this after I did a bit of merging:

Which patches you had an issues while applying,we have few patches

on

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 1 line

u-boot-spi.git i created these on top of it.

I am not sure now - sorry I did not keep a record. But the bundle I used is
here, and it doesn't apply cleanly.

http://patchwork.ozlabs.org/bundle/sjg/jagan/

Quoted 15 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

git am ~/Downloads/bundle-4407-jagan.mbox
Applying: sf: Add bank address register writing support
Applying: sf: Add bank address register reading support
Applying: sf: Add extended addr write support for winbond|stmicro
Applying: sf: Add extended addr read support for winbond|stmicro
Applying: sf: read flash bank addr register at probe time
Applying: sf: Update sf to support all sizes of flashes

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

error: patch failed: drivers/mtd/spi/spi_flash.c:117
error: drivers/mtd/spi/spi_flash.c: patch does not apply Patch failed at 0006 sf: Update sf to support all sizes of flashes The copy of the patch that failed is found in:
/home/sjg/u/.git/rebase-apply/patch
When you have resolved this problem, run "git am --resolved". If you prefer to skip this patch, run "git am --skip" instead. To restore the original branch and stop patching, run "git am

--abort"

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

5864e87 (HEAD, try-spi) cfi_flash: Fix detection of 8-bit bus

flash

Quoted 26 lines
Quoted 26 lines
Quoted 26 lines
Quoted 26 lines
Quoted 26 lines
Quoted 25 lines

devices
via address shift
f700095 sf: Add Flag status register polling support 42f4b70 sf: Remove spi_flash_cmd_poll_bit()
fc31387 sf: Use spi_flash_read_common() in write status poll 923e40e sf: spansion: Add support for S25FL512S_256K c72e52a sf: stmicro: Add support for N25Q1024A 4066f71 sf: stmicro: Add support for N25Q1024
0efaf86 sf: stmicro: Add support for N25Q512A
8fd962f sf: stmicro: Add support for N25Q512
f1a2080 sf: Use spi_flash_addr() in write call 31ed498 sf: Update sf read to support all sizes of flashes 0f77642 sf: Update sf to support all sizes of flashes 9e57220 sf: read flash bank addr register at probe time e99a43d sf: Add extended addr read support for winbond|stmicro 2f06d56 sf: Add extended addr write support for winbond|stmicro f02ecf1 sf: Add bank address register reading support 02ba27c sf: Add bank address register writing support

Also do you think spi_flash_cmd_bankaddr_write() and related stuff should be
behind a flag like CONFIG_SPI_BANK_ADDR or similar? How much code space
does
this add?

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Initially i thought of the same, but I just updated sf which is generic to all sizes of flashes.
due to this i haven't included the bank read/write on macros, and

the

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines

flash ops will call these
bank write call irrespective of flash sizes.

As flashes which has below 16Mbytes will have a bank_curr value 0 so-that even bank write will exit for
bank 0 operations.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

Yes this is fine.

Quoted 4 lines
(quoted diff) +2 -0
+       if (flash->bank_curr == bank_sel) {
+               debug("SF: not require to enable bank%d\n",

bank_sel);

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
(quoted diff) +3 -0
+               return 0;
+       }
+

And due to these framework changes bank+flash ops addition, bin size increases appr' ~600bytes
by enabling stmicro, winbond and spansion flash drivers.(please

check

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 1 line

the size from your end also if required)

I suggest you make that function a nop (perhaps using an #ifdef CONFIG_SPI_BANK_ADDR inside it or some other name) so that your

patches

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

don't increase U-Boot code size for those boards that don't need support
larger devices (which I guess is almost all of them, right now).

U-Boot

Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 2 lines

is
quite concerned about code size.

Little concern here, the point here I stated that these new changes is common for all sizes of flashes.(which are less or greater than 16Mbytes).
and yes it increase the code size little bit but i don't think it will require the separate macro.

Quoted 4 lines
Quoted 1 line

Any comments.

In U-Boot it is generally not acceptable to increase code size for

existing

Quoted 1 line

boards when adding a new feature that they don't use. So I suspect in

this

Quoted 2 lines

case you should add a new CONFIG to enable your feature. It seems to increase code by more than 200 bytes for snow, for example.

Quoted 8 lines

OK, I did coding on sf to have a common framework for all sizes of flashes in mind.
but as you said it's increasing the size of u-boot.bin > 200 bytes.

Seems like no choice to comprise, I am going to create v3 series for these changes.
Will that be OK?

What does 'comprise' mean in this context?

Quoted 4 lines
Quoted 4 lines

Tom may have further comments.

Quoted 8 lines
Quoted 3 lines

Also my buildman run of your commit gave an error on this commit:

07: sf: Update sf to support all sizes of flashes

I am created these patches on top of u-boot-spi.git, there some patches already available on sf.
may be you used master.

OK, sorry, I didn't know about that tree...thanks for pointing me to it.

Regards,
Simon

Quoted 154 lines

Thanks,
Jagan.

Quoted 89 lines

Regards,
Simon

Quoted 84 lines

--
Thanks,
Jagan.

Quoted 78 lines

Thanks,
Jagan.

Quoted 74 lines

Tom may chime in and decide it is fine, though.

Quoted 15 lines

Please see the commit body on below thread for more info
http://patchwork.ozlabs.org/patch/247954/

Quoted 9 lines

In your change to spi_flash_cmd_poll_bit() the effect is not the same I
think. It is designed to hold CS active and read the status byte continuously until it changes. But your implementation asserts CS, reads
the
status byte, de-asserts CS, then repeats. Why do we want to change this?

Quoted 1 line

I commented on the actual patch thread, please refer,

OK I will take a look.

Quoted 51 lines
Quoted 51 lines
Quoted 46 lines

---
Changes for v2:
- none

 drivers/mtd/spi/spi_flash.c | 39
++++++++++++++++++++++++++-------------
 1 file changed, 26 insertions(+), 13 deletions(-)
drivers/mtd/spi/spi_flash.c +1 -3
index 4576a16..5386884 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) {
drivers/mtd/spi/spi_flash.c +5 -0
@@ -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);

drivers/mtd/spi/spi_flash.c

Quoted 2 lines
drivers/mtd/spi/spi_flash.c +2 -0
+                       return ret;
+               }

So we are now doing this for all chips. But isn't it true that

only

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 4 lines

some
chips (>16MB?) have a bank address. If so, then I think we should have a
flag somewhere to enable this feature

APAMK, currently stmicro, winbond, spansion and macronix have a flashes which has > 16Mbytes flashes.

And macronix is also have same bank setup like stmicro, extended

addr

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

read(RDEAR - 0xC8) and extended addr write(WREAR - 0xC5) We need to add this in near future.

I have added Prafulla Wadaskar on this thread (initial contributor

for

Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
Quoted 8 lines

macronix.c), may be he will give some more information for accessing > 16Mbytes flashes in 3-byte addr mode.

I think we can go ahead for now, may be we will tune sf some more in future based on the availability of different flash which crosses 16Mbytes
with different apparoch (other than banking/extended), what do you say?

OK, well we don't need a flag since you will never issue the bank address
command unless the chip is larger than 16MB.,

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

drivers/mtd/spi/spi_flash.c

Quoted 3 lines
drivers/mtd/spi/spi_flash.c +3 -0
+
+               page_addr = offset / page_size;
+               byte_addr = offset % page_size;

This is OK I think. We really don't care about the slower divide

so

Quoted 19 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 11 lines
Quoted 3 lines

it
is
not worth optimising for I think.

Yes, I just used the existing spi_flash_addr with offset as an argument, anyway sf write have a logic
to use writing in terms of page sizes and even offset is also varies page sizes or requested sizes.

Thanks,
Jagan.

Regards,
Simon

#15 lore raw

PATCH v2 6/16 sf: Update sf to support all sizes of flashes

Hi Simon,

Quoted 183 lines · Simon Glass

Hi Jagan,

Quoted 179 lines · Jagan Teki

Hi Simon,

Quoted 164 lines · Simon Glass
Quoted 159 lines · Jagan Teki

Hi Tom,

Quoted 146 lines · Jagan Teki

Hi Simon,

Quoted 133 lines · Simon Glass

Hi,

Quoted 33 lines · Jagan Teki

Hi Simon,

Quoted 28 lines · Simon Glass

Hi Jagan,

Quoted 10 lines · Jagannadha Sutradharudu Teki

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.

Quoted 7 lines

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.

I have a few comments on this series, but it mostly looks fine. I think
the
new code is correct.

Quoted 7 lines
Quoted 3 lines

The patches did not apply cleanly for me. Perhaps I am missing something. My
tree looks like this after I did a bit of merging:

Which patches you had an issues while applying,we have few patches on
u-boot-spi.git i created these on top of it.

I am not sure now - sorry I did not keep a record. But the bundle I used is
here, and it doesn't apply cleanly.

http://patchwork.ozlabs.org/bundle/sjg/jagan/

git am ~/Downloads/bundle-4407-jagan.mbox
Applying: sf: Add bank address register writing support
Applying: sf: Add bank address register reading support
Applying: sf: Add extended addr write support for winbond|stmicro
Applying: sf: Add extended addr read support for winbond|stmicro
Applying: sf: read flash bank addr register at probe time
Applying: sf: Update sf to support all sizes of flashes
error: patch failed: drivers/mtd/spi/spi_flash.c:117
error: drivers/mtd/spi/spi_flash.c: patch does not apply Patch failed at 0006 sf: Update sf to support all sizes of flashes The copy of the patch that failed is found in:
/home/sjg/u/.git/rebase-apply/patch
When you have resolved this problem, run "git am --resolved". If you prefer to skip this patch, run "git am --skip" instead. To restore the original branch and stop patching, run "git am --abort"

Quoted 39 lines
Quoted 24 lines

5864e87 (HEAD, try-spi) cfi_flash: Fix detection of 8-bit bus flash
devices
via address shift
f700095 sf: Add Flag status register polling support 42f4b70 sf: Remove spi_flash_cmd_poll_bit()
fc31387 sf: Use spi_flash_read_common() in write status poll 923e40e sf: spansion: Add support for S25FL512S_256K c72e52a sf: stmicro: Add support for N25Q1024A 4066f71 sf: stmicro: Add support for N25Q1024
0efaf86 sf: stmicro: Add support for N25Q512A
8fd962f sf: stmicro: Add support for N25Q512
f1a2080 sf: Use spi_flash_addr() in write call 31ed498 sf: Update sf read to support all sizes of flashes 0f77642 sf: Update sf to support all sizes of flashes 9e57220 sf: read flash bank addr register at probe time e99a43d sf: Add extended addr read support for winbond|stmicro 2f06d56 sf: Add extended addr write support for winbond|stmicro f02ecf1 sf: Add bank address register reading support 02ba27c sf: Add bank address register writing support

Quoted 7 lines

Also do you think spi_flash_cmd_bankaddr_write() and related stuff
should be
behind a flag like CONFIG_SPI_BANK_ADDR or similar? How much code space
does
this add?

Initially i thought of the same, but I just updated sf which is generic to all sizes of flashes.
due to this i haven't included the bank read/write on macros, and the
flash ops will call these
bank write call irrespective of flash sizes.

Quoted 3 lines

As flashes which has below 16Mbytes will have a bank_curr value 0 so-that even bank write will exit for
bank 0 operations.

Yes this is fine.

Quoted 9 lines
(quoted diff) +2 -0
+       if (flash->bank_curr == bank_sel) {
+               debug("SF: not require to enable bank%d\n",

bank_sel);

(quoted diff) +3 -0
+               return 0;
+       }
+
Quoted 6 lines

And due to these framework changes bank+flash ops addition, bin size
increases appr' ~600bytes
by enabling stmicro, winbond and spansion flash drivers.(please check
the size from your end also if required)

Quoted 9 lines

I suggest you make that function a nop (perhaps using an #ifdef CONFIG_SPI_BANK_ADDR inside it or some other name) so that your patches
don't increase U-Boot code size for those boards that don't need support
larger devices (which I guess is almost all of them, right now). U-Boot
is
quite concerned about code size.

Quoted 7 lines

Little concern here, the point here I stated that these new changes is
common for all sizes of flashes.(which are less or greater than 16Mbytes).
and yes it increase the code size little bit but i don't think it will
require the separate macro.

Quoted 1 line

Any comments.

Quoted 6 lines

In U-Boot it is generally not acceptable to increase code size for existing
boards when adding a new feature that they don't use. So I suspect in this
case you should add a new CONFIG to enable your feature. It seems to increase code by more than 200 bytes for snow, for example.

OK, I did coding on sf to have a common framework for all sizes of flashes in mind.
but as you said it's increasing the size of u-boot.bin > 200 bytes.

Quoted 6 lines
Quoted 3 lines

Seems like no choice to comprise, I am going to create v3 series for these changes.
Will that be OK?

What does 'comprise' mean in this context?

I am saying as uboot.bin size increases for these new updates I must compromise use the macros for reducing the sizes.

Am i clear.

Thanks,
Jagan.

Quoted 181 lines
Quoted 6 lines
Quoted 6 lines

Tom may have further comments.

Quoted 7 lines
Quoted 3 lines

Also my buildman run of your commit gave an error on this commit:

07: sf: Update sf to support all sizes of flashes

I am created these patches on top of u-boot-spi.git, there some patches already available on sf.
may be you used master.

OK, sorry, I didn't know about that tree...thanks for pointing me to it.

Regards,
Simon

Quoted 160 lines

Thanks,
Jagan.

Quoted 155 lines

Regards,
Simon

Quoted 148 lines

--
Thanks,
Jagan.

Quoted 142 lines

Thanks,
Jagan.

Quoted 138 lines

Tom may chime in and decide it is fine, though.

Quoted 17 lines

Please see the commit body on below thread for more info
http://patchwork.ozlabs.org/patch/247954/

Quoted 11 lines

In your change to spi_flash_cmd_poll_bit() the effect is not the same I
think. It is designed to hold CS active and read the status byte continuously until it changes. But your implementation asserts CS,
reads
the
status byte, de-asserts CS, then repeats. Why do we want to change
this?

Quoted 1 line

I commented on the actual patch thread, please refer,

OK I will take a look.

Quoted 72 lines
Quoted 52 lines
Quoted 48 lines

---
Changes for v2:
- none

 drivers/mtd/spi/spi_flash.c | 39
++++++++++++++++++++++++++-------------
 1 file changed, 26 insertions(+), 13 deletions(-)
drivers/mtd/spi/spi_flash.c +0 -0
index 4576a16..5386884 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;
drivers/mtd/spi/spi_flash.c +1 -3
-       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) {
drivers/mtd/spi/spi_flash.c +3 -0
+               bank_sel = offset / SPI_FLASH_16MB_BOUN;
+
+               ret = spi_flash_cmd_bankaddr_write(flash,

bank_sel);

drivers/mtd/spi/spi_flash.c +2 -0
+               if (ret) {
+                       debug("SF: fail to set bank%d\n",

bank_sel);

drivers/mtd/spi/spi_flash.c

Quoted 2 lines
drivers/mtd/spi/spi_flash.c +2 -0
+                       return ret;
+               }
Quoted 6 lines

So we are now doing this for all chips. But isn't it true that only
some
chips (>16MB?) have a bank address. If so, then I think we should have a
flag somewhere to enable this feature

APAMK, currently stmicro, winbond, spansion and macronix have a flashes which has > 16Mbytes flashes.

And macronix is also have same bank setup like stmicro, extended addr
read(RDEAR - 0xC8) and extended addr write(WREAR - 0xC5) We need to add this in near future.

I have added Prafulla Wadaskar on this thread (initial contributor for
macronix.c), may be he will give some more information for accessing > 16Mbytes flashes in 3-byte addr mode.

Quoted 6 lines

I think we can go ahead for now, may be we will tune sf some more in
future based on the availability of different flash which crosses 16Mbytes
with different apparoch (other than banking/extended), what do you say?

OK, well we don't need a flag since you will never issue the bank address
command unless the chip is larger than 16MB.,

Quoted 15 lines
Quoted 9 lines

drivers/mtd/spi/spi_flash.c

Quoted 7 lines
drivers/mtd/spi/spi_flash.c +3 -0
+
+               page_addr = offset / page_size;
+               byte_addr = offset % page_size;
Quoted 5 lines

This is OK I think. We really don't care about the slower divide so
it
is
not worth optimising for I think.

Quoted 8 lines

Yes, I just used the existing spi_flash_addr with offset as an argument, anyway sf write have a logic
to use writing in terms of page sizes and even offset is also varies
page sizes or requested sizes.

Thanks,
Jagan.

Regards,
Simon

#16 lore raw

PATCH v2 6/16 sf: Update sf to support all sizes of flashes

Hi,

Quoted 203 lines · Jagan Teki

Hi Simon,

Quoted 20 lines · Simon Glass

Hi Jagan,

Quoted 16 lines · Jagan Teki

Hi Simon,

Quoted 12 lines · Simon Glass

On Mon, Jun 10, 2013 at 9:05 AM, Jagan Teki <[email protected]

Quoted 9 lines · wrote:

Hi Tom,

On Sat, Jun 8, 2013 at 8:24 PM, Jagan Teki <[email protected]

Quoted 3 lines · wrote:

Hi Simon,

On Sat, Jun 8, 2013 at 8:11 PM, Simon Glass <[email protected]>

Quoted 12 lines · wrote:
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines

Hi,

Quoted 7 lines · Jagan Teki

Hi Simon,

Quoted 2 lines · Simon Glass

Hi Jagan,

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines · Jagannadha Sutradharudu Teki

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

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

mode
due to this up to 16Mbytes amount of flash is able to access

for

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

those
flashes which has an actual size of > 16MB.

As most of the flashes introduces a bank/extd address

registers

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

for accessing the flashes in 16Mbytes of banks if the flash

size

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

is > 16Mbytes, this new scheme will add the bank selection feature
for performing write/erase operations on all flashes.

Signed-off-by Jagannadha Sutradharudu Teki <

jaganna at xilinx.com>

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

I have a few comments on this series, but it mostly looks

fine. I

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 7 lines

think
the
new code is correct.

The patches did not apply cleanly for me. Perhaps I am missing something. My
tree looks like this after I did a bit of merging:

Which patches you had an issues while applying,we have few

patches

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

on
u-boot-spi.git i created these on top of it.

I am not sure now - sorry I did not keep a record. But the bundle

I

Quoted 46 lines
Quoted 46 lines
Quoted 46 lines
Quoted 46 lines
Quoted 46 lines
Quoted 46 lines

used is
here, and it doesn't apply cleanly.

http://patchwork.ozlabs.org/bundle/sjg/jagan/

git am ~/Downloads/bundle-4407-jagan.mbox
Applying: sf: Add bank address register writing support
Applying: sf: Add bank address register reading support
Applying: sf: Add extended addr write support for winbond|stmicro
Applying: sf: Add extended addr read support for winbond|stmicro
Applying: sf: read flash bank addr register at probe time
Applying: sf: Update sf to support all sizes of flashes
error: patch failed: drivers/mtd/spi/spi_flash.c:117
error: drivers/mtd/spi/spi_flash.c: patch does not apply Patch failed at 0006 sf: Update sf to support all sizes of flashes The copy of the patch that failed is found in:
/home/sjg/u/.git/rebase-apply/patch
When you have resolved this problem, run "git am --resolved". If you prefer to skip this patch, run "git am --skip" instead. To restore the original branch and stop patching, run "git am --abort"

Quoted 24 lines
Quoted 24 lines

5864e87 (HEAD, try-spi) cfi_flash: Fix detection of 8-bit bus flash
devices
via address shift
f700095 sf: Add Flag status register polling support 42f4b70 sf: Remove spi_flash_cmd_poll_bit()
fc31387 sf: Use spi_flash_read_common() in write status poll 923e40e sf: spansion: Add support for S25FL512S_256K c72e52a sf: stmicro: Add support for N25Q1024A 4066f71 sf: stmicro: Add support for N25Q1024
0efaf86 sf: stmicro: Add support for N25Q512A
8fd962f sf: stmicro: Add support for N25Q512
f1a2080 sf: Use spi_flash_addr() in write call 31ed498 sf: Update sf read to support all sizes of flashes 0f77642 sf: Update sf to support all sizes of flashes 9e57220 sf: read flash bank addr register at probe time e99a43d sf: Add extended addr read support for winbond|stmicro 2f06d56 sf: Add extended addr write support for winbond|stmicro f02ecf1 sf: Add bank address register reading support 02ba27c sf: Add bank address register writing support

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Also do you think spi_flash_cmd_bankaddr_write() and related stuff
should be
behind a flag like CONFIG_SPI_BANK_ADDR or similar? How much

code

Quoted 72 lines
Quoted 70 lines
Quoted 56 lines
Quoted 53 lines
Quoted 45 lines
Quoted 35 lines
Quoted 11 lines
Quoted 3 lines

space
does
this add?

Initially i thought of the same, but I just updated sf which is generic to all sizes of flashes.
due to this i haven't included the bank read/write on macros, and the
flash ops will call these
bank write call irrespective of flash sizes.

Quoted 3 lines

As flashes which has below 16Mbytes will have a bank_curr value 0 so-that even bank write will exit for
bank 0 operations.

Yes this is fine.

Quoted 9 lines
(quoted diff) +2 -0
+       if (flash->bank_curr == bank_sel) {
+               debug("SF: not require to enable bank%d\n",

bank_sel);

(quoted diff) +3 -0
+               return 0;
+       }
+
Quoted 6 lines

And due to these framework changes bank+flash ops addition, bin size
increases appr' ~600bytes
by enabling stmicro, winbond and spansion flash drivers.(please check
the size from your end also if required)

Quoted 9 lines

I suggest you make that function a nop (perhaps using an #ifdef CONFIG_SPI_BANK_ADDR inside it or some other name) so that your patches
don't increase U-Boot code size for those boards that don't need support
larger devices (which I guess is almost all of them, right now). U-Boot
is
quite concerned about code size.

Quoted 7 lines

Little concern here, the point here I stated that these new changes is
common for all sizes of flashes.(which are less or greater than 16Mbytes).
and yes it increase the code size little bit but i don't think it will
require the separate macro.

Quoted 1 line

Any comments.

Quoted 6 lines

In U-Boot it is generally not acceptable to increase code size for existing
boards when adding a new feature that they don't use. So I suspect in this
case you should add a new CONFIG to enable your feature. It seems to increase code by more than 200 bytes for snow, for example.

OK, I did coding on sf to have a common framework for all sizes of flashes in mind.
but as you said it's increasing the size of u-boot.bin > 200 bytes.

Seems like no choice to comprise, I am going to create v3 series for these changes.
Will that be OK?

Quoted 5 lines
Quoted 1 line

What does 'comprise' mean in this context?

I am saying as uboot.bin size increases for these new updates I must compromise use the macros for reducing the sizes.

Yes, I think it is OK to increase size by a few bytes, but if you are adding a new feature that will not be used by existing boards, suggest putting it behind a CONFIG_... flag.

Also see Tom's comment.

Regards,
Simon

Quoted 194 lines

Am i clear.

Thanks,
Jagan.

Quoted 15 lines
Quoted 6 lines
Quoted 6 lines

Tom may have further comments.

Quoted 7 lines
Quoted 3 lines

Also my buildman run of your commit gave an error on this commit:

07: sf: Update sf to support all sizes of flashes

I am created these patches on top of u-boot-spi.git, there some patches already available on sf.
may be you used master.

Quoted 35 lines

OK, sorry, I didn't know about that tree...thanks for pointing me to it.

Regards,
Simon

Quoted 30 lines

Thanks,
Jagan.

Quoted 25 lines

Regards,
Simon

Quoted 20 lines

--
Thanks,
Jagan.

Quoted 14 lines

Thanks,
Jagan.

Quoted 10 lines

Tom may chime in and decide it is fine, though.

Quoted 7 lines

Please see the commit body on below thread for more info
http://patchwork.ozlabs.org/patch/247954/

Quoted 2 lines

In your change to spi_flash_cmd_poll_bit() the effect is not

the

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

same I
think. It is designed to hold CS active and read the status

byte

Quoted 61 lines
Quoted 61 lines
Quoted 61 lines
Quoted 61 lines
Quoted 61 lines
Quoted 61 lines
Quoted 9 lines
Quoted 7 lines

continuously until it changes. But your implementation asserts CS,
reads
the
status byte, de-asserts CS, then repeats. Why do we want to change
this?

I commented on the actual patch thread, please refer,

OK I will take a look.

Quoted 48 lines
Quoted 48 lines
Quoted 48 lines

---
Changes for v2:
- none

 drivers/mtd/spi/spi_flash.c | 39
++++++++++++++++++++++++++-------------
 1 file changed, 26 insertions(+), 13 deletions(-)
drivers/mtd/spi/spi_flash.c +0 -0
index 4576a16..5386884 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;
drivers/mtd/spi/spi_flash.c +1 -3
-       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) {
drivers/mtd/spi/spi_flash.c +3 -0
+               bank_sel = offset / SPI_FLASH_16MB_BOUN;
+
+               ret = spi_flash_cmd_bankaddr_write(flash,

bank_sel);

drivers/mtd/spi/spi_flash.c +2 -0
+               if (ret) {
+                       debug("SF: fail to set bank%d\n",

bank_sel);

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/mtd/spi/spi_flash.c

Quoted 2 lines
drivers/mtd/spi/spi_flash.c +2 -0
+                       return ret;
+               }

So we are now doing this for all chips. But isn't it true that only
some
chips (>16MB?) have a bank address. If so, then I think we

should

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

have a
flag somewhere to enable this feature

APAMK, currently stmicro, winbond, spansion and macronix have a flashes which has > 16Mbytes flashes.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

And macronix is also have same bank setup like stmicro, extended addr
read(RDEAR - 0xC8) and extended addr write(WREAR - 0xC5) We need to add this in near future.

I have added Prafulla Wadaskar on this thread (initial

contributor

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

for
macronix.c), may be he will give some more information for accessing > 16Mbytes flashes in 3-byte addr mode.

I think we can go ahead for now, may be we will tune sf some more in
future based on the availability of different flash which crosses 16Mbytes
with different apparoch (other than banking/extended), what do

you

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 1 line

say?

OK, well we don't need a flag since you will never issue the bank address
command unless the chip is larger than 16MB.,

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

drivers/mtd/spi/spi_flash.c

Quoted 3 lines
drivers/mtd/spi/spi_flash.c +3 -0
+
+               page_addr = offset / page_size;
+               byte_addr = offset % page_size;

This is OK I think. We really don't care about the slower

divide

Quoted 22 lines
Quoted 21 lines
Quoted 21 lines
Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
Quoted 5 lines
Quoted 4 lines

so
it
is
not worth optimising for I think.

Quoted 8 lines

Yes, I just used the existing spi_flash_addr with offset as an argument, anyway sf write have a logic
to use writing in terms of page sizes and even offset is also varies
page sizes or requested sizes.

Thanks,
Jagan.

Regards,
Simon

#17 lore raw

PATCH v2 6/16 sf: Update sf to support all sizes of flashes

In reply to Simon Glass
Quoted 146 lines · Simon Glass
Quoted 135 lines · Jagan Teki

Hi Tom,

Quoted 6 lines · Jagan Teki

Hi Simon,

Quoted 3 lines · Simon Glass

Hi,

On Sat, Jun 8, 2013 at 1:22 AM, Jagan Teki <[email protected]>

Quoted 6 lines · wrote:
Quoted 6 lines
Quoted 6 lines

Hi Simon,

Quoted 2 lines · Simon Glass

Hi Jagan,

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines · Jagannadha Sutradharudu Teki

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

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 8 lines

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.

I have a few comments on this series, but it mostly looks fine. I

think

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines

the
new code is correct.

The patches did not apply cleanly for me. Perhaps I am missing something. My
tree looks like this after I did a bit of merging:

Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

Which patches you had an issues while applying,we have few patches on u-boot-spi.git i created these on top of it.

I am not sure now - sorry I did not keep a record. But the bundle I

used is

Quoted 43 lines
Quoted 43 lines

here, and it doesn't apply cleanly.

http://patchwork.ozlabs.org/bundle/sjg/jagan/

git am ~/Downloads/bundle-4407-jagan.mbox
Applying: sf: Add bank address register writing support
Applying: sf: Add bank address register reading support
Applying: sf: Add extended addr write support for winbond|stmicro
Applying: sf: Add extended addr read support for winbond|stmicro
Applying: sf: read flash bank addr register at probe time
Applying: sf: Update sf to support all sizes of flashes
error: patch failed: drivers/mtd/spi/spi_flash.c:117
error: drivers/mtd/spi/spi_flash.c: patch does not apply Patch failed at 0006 sf: Update sf to support all sizes of flashes The copy of the patch that failed is found in:
/home/sjg/u/.git/rebase-apply/patch
When you have resolved this problem, run "git am --resolved". If you prefer to skip this patch, run "git am --skip" instead. To restore the original branch and stop patching, run "git am --abort"

Quoted 23 lines
Quoted 23 lines

5864e87 (HEAD, try-spi) cfi_flash: Fix detection of 8-bit bus flash devices
via address shift
f700095 sf: Add Flag status register polling support 42f4b70 sf: Remove spi_flash_cmd_poll_bit()
fc31387 sf: Use spi_flash_read_common() in write status poll 923e40e sf: spansion: Add support for S25FL512S_256K c72e52a sf: stmicro: Add support for N25Q1024A
4066f71 sf: stmicro: Add support for N25Q1024
0efaf86 sf: stmicro: Add support for N25Q512A
8fd962f sf: stmicro: Add support for N25Q512
f1a2080 sf: Use spi_flash_addr() in write call
31ed498 sf: Update sf read to support all sizes of flashes 0f77642 sf: Update sf to support all sizes of flashes 9e57220 sf: read flash bank addr register at probe time e99a43d sf: Add extended addr read support for winbond|stmicro 2f06d56 sf: Add extended addr write support for winbond|stmicro f02ecf1 sf: Add bank address register reading support 02ba27c sf: Add bank address register writing support

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Also do you think spi_flash_cmd_bankaddr_write() and related stuff should be
behind a flag like CONFIG_SPI_BANK_ADDR or similar? How much code

space

Quoted 30 lines
Quoted 30 lines
Quoted 9 lines
Quoted 2 lines

does
this add?

Initially i thought of the same, but I just updated sf which is generic to all sizes of flashes.
due to this i haven't included the bank read/write on macros, and the flash ops will call these
bank write call irrespective of flash sizes.

Quoted 3 lines

As flashes which has below 16Mbytes will have a bank_curr value 0 so-that even bank write will exit for
bank 0 operations.

Yes this is fine.

Quoted 12 lines
(quoted diff) +5 -0
+       if (flash->bank_curr == bank_sel) {
+               debug("SF: not require to enable bank%d\n", bank_sel);
+               return 0;
+       }
+

And due to these framework changes bank+flash ops addition, bin size increases appr' ~600bytes
by enabling stmicro, winbond and spansion flash drivers.(please check the size from your end also if required)

Quoted 4 lines
Quoted 4 lines

I suggest you make that function a nop (perhaps using an #ifdef CONFIG_SPI_BANK_ADDR inside it or some other name) so that your patches don't increase U-Boot code size for those boards that don't need support larger devices (which I guess is almost all of them, right now). U-Boot

is

Quoted 2 lines
Quoted 1 line

quite concerned about code size.

Quoted 8 lines
Quoted 5 lines

Little concern here, the point here I stated that these new changes is common for all sizes of flashes.(which are less or greater than 16Mbytes).
and yes it increase the code size little bit but i don't think it will require the separate macro.

Any comments.

Quoted 6 lines

In U-Boot it is generally not acceptable to increase code size for existing boards when adding a new feature that they don't use. So I suspect in this case you should add a new CONFIG to enable your feature. It seems to increase code by more than 200 bytes for snow, for example.

Tom may have further comments.

I think it's important we keep both binary size and code complexity in mind when we say "no binary size increase". It really has to mean "no unreasonable binary size increase, when compared with code complexity changes". The question has to be "can we easily make things opt-in".

Perhaps the answer here is that we need to add CONFIG_SPI_FLASH_STMICRO_STATIC_TABLE and a corresponding set of CONFIG_SPI_FLASH_STMICRO_ID/PPS/NR_SECT/NAME (and Winbond variant) so that boards with size constrains can opt to define the single chip they support, and other boards can just get the full probe table. This will allow boards to get a net size decrease here if desired.

Heck, for ARM we are, or have just, reclaimed a bunch of space at least on SPL using boards in the main binary now that we --gc-sections U-Boot.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20130611/3399dec4/attachment.pgp>
#18 lore raw

PATCH v2 6/16 sf: Update sf to support all sizes of flashes

Hi Tom,

Quoted 152 lines · Tom Rini
Quoted 151 lines · Simon Glass
Quoted 135 lines · Jagan Teki

Hi Tom,

Quoted 6 lines · Jagan Teki

Hi Simon,

Quoted 3 lines · Simon Glass

Hi,

On Sat, Jun 8, 2013 at 1:22 AM, Jagan Teki <[email protected]>

Quoted 6 lines · wrote:
Quoted 6 lines
Quoted 6 lines

Hi Simon,

Quoted 2 lines · Simon Glass

Hi Jagan,

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines · Jagannadha Sutradharudu Teki

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

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 8 lines

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.

I have a few comments on this series, but it mostly looks fine. I

think

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines

the
new code is correct.

The patches did not apply cleanly for me. Perhaps I am missing something. My
tree looks like this after I did a bit of merging:

Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

Which patches you had an issues while applying,we have few patches on u-boot-spi.git i created these on top of it.

I am not sure now - sorry I did not keep a record. But the bundle I

used is

Quoted 43 lines
Quoted 43 lines

here, and it doesn't apply cleanly.

http://patchwork.ozlabs.org/bundle/sjg/jagan/

git am ~/Downloads/bundle-4407-jagan.mbox
Applying: sf: Add bank address register writing support
Applying: sf: Add bank address register reading support
Applying: sf: Add extended addr write support for winbond|stmicro
Applying: sf: Add extended addr read support for winbond|stmicro
Applying: sf: read flash bank addr register at probe time
Applying: sf: Update sf to support all sizes of flashes
error: patch failed: drivers/mtd/spi/spi_flash.c:117
error: drivers/mtd/spi/spi_flash.c: patch does not apply Patch failed at 0006 sf: Update sf to support all sizes of flashes The copy of the patch that failed is found in:
/home/sjg/u/.git/rebase-apply/patch
When you have resolved this problem, run "git am --resolved". If you prefer to skip this patch, run "git am --skip" instead. To restore the original branch and stop patching, run "git am --abort"

Quoted 23 lines
Quoted 23 lines

5864e87 (HEAD, try-spi) cfi_flash: Fix detection of 8-bit bus flash devices
via address shift
f700095 sf: Add Flag status register polling support 42f4b70 sf: Remove spi_flash_cmd_poll_bit()
fc31387 sf: Use spi_flash_read_common() in write status poll 923e40e sf: spansion: Add support for S25FL512S_256K c72e52a sf: stmicro: Add support for N25Q1024A
4066f71 sf: stmicro: Add support for N25Q1024
0efaf86 sf: stmicro: Add support for N25Q512A
8fd962f sf: stmicro: Add support for N25Q512
f1a2080 sf: Use spi_flash_addr() in write call
31ed498 sf: Update sf read to support all sizes of flashes 0f77642 sf: Update sf to support all sizes of flashes 9e57220 sf: read flash bank addr register at probe time e99a43d sf: Add extended addr read support for winbond|stmicro 2f06d56 sf: Add extended addr write support for winbond|stmicro f02ecf1 sf: Add bank address register reading support 02ba27c sf: Add bank address register writing support

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Also do you think spi_flash_cmd_bankaddr_write() and related stuff should be
behind a flag like CONFIG_SPI_BANK_ADDR or similar? How much code

space

Quoted 30 lines
Quoted 30 lines
Quoted 9 lines
Quoted 2 lines

does
this add?

Initially i thought of the same, but I just updated sf which is generic to all sizes of flashes.
due to this i haven't included the bank read/write on macros, and the flash ops will call these
bank write call irrespective of flash sizes.

Quoted 3 lines

As flashes which has below 16Mbytes will have a bank_curr value 0 so-that even bank write will exit for
bank 0 operations.

Yes this is fine.

Quoted 12 lines
(quoted diff) +5 -0
+       if (flash->bank_curr == bank_sel) {
+               debug("SF: not require to enable bank%d\n", bank_sel);
+               return 0;
+       }
+

And due to these framework changes bank+flash ops addition, bin size increases appr' ~600bytes
by enabling stmicro, winbond and spansion flash drivers.(please check the size from your end also if required)

Quoted 4 lines
Quoted 4 lines

I suggest you make that function a nop (perhaps using an #ifdef CONFIG_SPI_BANK_ADDR inside it or some other name) so that your patches don't increase U-Boot code size for those boards that don't need support larger devices (which I guess is almost all of them, right now). U-Boot

is

Quoted 2 lines
Quoted 1 line

quite concerned about code size.

Quoted 8 lines
Quoted 5 lines

Little concern here, the point here I stated that these new changes is common for all sizes of flashes.(which are less or greater than 16Mbytes).
and yes it increase the code size little bit but i don't think it will require the separate macro.

Any comments.

In U-Boot it is generally not acceptable to increase code size for existing boards when adding a new feature that they don't use. So I suspect in this case you should add a new CONFIG to enable your feature. It seems to increase code by more than 200 bytes for snow, for example.

Quoted 6 lines
Quoted 1 line

Tom may have further comments.

I think it's important we keep both binary size and code complexity in mind when we say "no binary size increase". It really has to mean "no unreasonable binary size increase, when compared with code complexity changes". The question has to be "can we easily make things opt-in".

Understood.

Quoted 7 lines

Perhaps the answer here is that we need to add CONFIG_SPI_FLASH_STMICRO_STATIC_TABLE and a corresponding set of CONFIG_SPI_FLASH_STMICRO_ID/PPS/NR_SECT/NAME (and Winbond variant) so that boards with size constrains can opt to define the single chip they support, and other boards can just get the full probe table. This will allow boards to get a net size decrease here if desired.

Yes, we should think about this.

I will come to this again for better more idea, if any.

--
Thanks,
Jagan.

Quoted 6 lines

Heck, for ARM we are, or have just, reclaimed a bunch of space at least on SPL using boards in the main binary now that we --gc-sections U-Boot.

--
Tom

#19 lore raw

PATCH v2 7/16 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 ~600 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 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 5386884..40c0389 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
#20 lore raw

PATCH v2 8/16 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 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 40c0389..821aa2e 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], bank_sel;
@@ -94,16 +94,13 @@ int spi_flash_cmd_write_multi(struct spi_flash *flash, u32 offset,
 			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)
 			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
#21 lore raw

PATCH v2 9/16 sf: stmicro: Add support for N25Q512

In reply to a message not in the archive

Add support for Numonyx N25Q512 SPI flash.

---
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
#22 lore raw

PATCH v2 10/16 sf: stmicro: Add support for N25Q512A

In reply to a message not in the archive

Add support for Numonyx N25Q512A SPI flash.

---
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
#23 lore raw

PATCH v2 11/16 sf: stmicro: Add support for N25Q1024

In reply to a message not in the archive

Add support for Numonyx N25Q1024 SPI flash.

---
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
#24 lore raw

PATCH v2 12/16 sf: stmicro: Add support for N25Q1024A

In reply to a message not in the archive

Add support for Numonyx N25Q1024A SPI flash.

---
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
#25 lore raw

PATCH v2 13/16 sf: spansion: Add support for S25FL512S_256K

In reply to a message not in the archive

Add support for Spansion S25FL512S_256K SPI flash.

---
Changes for v2:
- none

 drivers/mtd/spi/spansion.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/mtd/spi/spansion.c +7 -0
index dad4fbb..1ded39f 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 = 0x4d00,
+		.pages_per_sector = 256,
+		.nr_sectors = 1024,
+		.name = "S25FL512S_256K",
+	},
 };
 
 struct spi_flash *spi_flash_probe_spansion(struct spi_slave *spi, u8 *idcode)
Signature · 1 line
1.8.3
#26 lore raw

PATCH v2 14/16 sf: Use spi_flash_read_common() in write status poll

In reply to a message not in the archive

Instead of using spi_xfer for SPI_XFER_BEGIN and SPI_XFER_END separatley use common read call spi_flash_read_common() which does the same.

---
Changes for v2:
- none

 drivers/mtd/spi/spi_flash.c | 17 +++++------------
 1 file changed, 5 insertions(+), 12 deletions(-)
drivers/mtd/spi/spi_flash.c +5 -12
index 821aa2e..765d4bc 100644
@@ -193,32 +193,25 @@ int spi_flash_cmd_read_fast(struct spi_flash *flash, u32 offset,
 int spi_flash_cmd_poll_bit(struct spi_flash *flash, unsigned long timeout,
 			   u8 cmd, u8 poll_bit)
 {
-	struct spi_slave *spi = flash->spi;
 	unsigned long timebase;
 	int ret;
 	u8 status;
 
-	ret = spi_xfer(spi, 8, &cmd, NULL, SPI_XFER_BEGIN);
-	if (ret) {
-		debug("SF: Failed to send command %02x: %d\n", cmd, ret);
-		return ret;
-	}
-
 	timebase = get_timer(0);
 	do {
 		WATCHDOG_RESET();
 
-		ret = spi_xfer(spi, 8, NULL, &status, 0);
-		if (ret)
-			return -1;
+		ret = spi_flash_read_common(flash, &cmd, 1, &status, 1);
+		if (ret < 0) {
+			debug("SF: fail to read read status register\n");
+			return ret;
+		}
 
 		if ((status & poll_bit) == 0)
 			break;
 
 	} while (get_timer(timebase) < timeout);
 
-	spi_xfer(spi, 0, NULL, NULL, SPI_XFER_END);
-
 	if ((status & poll_bit) == 0)
 		return 0;
 
Signature · 1 line
1.8.3
#27 lore raw

PATCH v2 14/16 sf: Use spi_flash_read_common() in write status poll

Hi Jagan,

Quoted 35 lines · Jagannadha Sutradharudu Teki

Instead of using spi_xfer for SPI_XFER_BEGIN and SPI_XFER_END separatley use common read call spi_flash_read_common() which does the same.

---
Changes for v2:
- none

 drivers/mtd/spi/spi_flash.c | 17 +++++------------
 1 file changed, 5 insertions(+), 12 deletions(-)
drivers/mtd/spi/spi_flash.c +0 -7
index 821aa2e..765d4bc 100644
@@ -193,32 +193,25 @@ int spi_flash_cmd_read_fast(struct spi_flash *flash,
 u32 offset,
 int spi_flash_cmd_poll_bit(struct spi_flash *flash, unsigned long timeout,
                           u8 cmd, u8 poll_bit)
 {
-       struct spi_slave *spi = flash->spi;
        unsigned long timebase;
        int ret;
        u8 status;
 
-       ret = spi_xfer(spi, 8, &cmd, NULL, SPI_XFER_BEGIN);
-       if (ret) {
-               debug("SF: Failed to send command %02x: %d\n", cmd, ret);
-               return ret;
-       }
-
        timebase = get_timer(0);
        do {
                WATCHDOG_RESET();

drivers/mtd/spi/spi_flash.c int spi_flash_cmd_read_fast(struct spi_flash *flash, · line 210

Quoted 10 lines
drivers/mtd/spi/spi_flash.c +5 -3
 
-               ret = spi_xfer(spi, 8, NULL, &status, 0);
-               if (ret)
-                       return -1;
+               ret = spi_flash_read_common(flash, &cmd, 1, &status, 1);
+               if (ret < 0) {
+                       debug("SF: fail to read read status register\n");
+                       return ret;
+               }
 

As mentioned elsewhere, do you need to make this change? Is it not possible to read the status register in the same way as now?

spi_flash_read_common() does a separate SPI transaction for each read.

Quoted 12 lines
drivers/mtd/spi/spi_flash.c +0 -3
                if ((status & poll_bit) == 0)
                        break;
 
        } while (get_timer(timebase) < timeout);
 
-       spi_xfer(spi, 0, NULL, NULL, SPI_XFER_END);
-
        if ((status & poll_bit) == 0)
                return 0;
 
--
Quoted 4 lines

1.8.3

Regards,
Simon

#28 lore raw

PATCH v2 15/16 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 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 765d4bc..527423d 100644
@@ -190,12 +190,13 @@ 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)
 {
 	unsigned long timebase;
 	int ret;
 	u8 status;
+	u8 poll_bit = STATUS_WIP;
+	u8 cmd = CMD_READ_STATUS;
 
 	timebase = get_timer(0);
 	do {
@@ -220,12 +221,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 455dc02..ac4530f 100644
@@ -98,10 +98,6 @@ int spi_flash_cmd_bankaddr_read(struct spi_flash *flash, void *data);
 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
#29 lore raw

PATCH v2 16/16 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 v2:
- none

 drivers/mtd/spi/spi_flash.c          | 15 ++++++++++++---
 drivers/mtd/spi/spi_flash_internal.h |  3 +++
 2 files changed, 15 insertions(+), 3 deletions(-)
drivers/mtd/spi/spi_flash.c +12 -3
index 527423d..8cd2988 100644
@@ -195,25 +195,34 @@ 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;
 
+	if ((flash->idcode0 == 0x20) &&
+			(flash->size >= SPI_FLASH_512MB_STMIC)) {
+		poll_bit = STATUS_PEC;
+		check_status = poll_bit;
+		cmd = CMD_FLAG_STATUS;
+	}
+
 	timebase = get_timer(0);
 	do {
 		WATCHDOG_RESET();
 
 		ret = spi_flash_read_common(flash, &cmd, 1, &status, 1);
 		if (ret < 0) {
-			debug("SF: fail to read read status register\n");
+			debug("SF: fail to read %s status register\n",
+				cmd == CMD_READ_STATUS ? "read" : "flag");
 			return ret;
 		}
 
-		if ((status & poll_bit) == 0)
+		if ((status & poll_bit) == check_status)
 			break;
 
 	} while (get_timer(timebase) < timeout);
 
-	if ((status & poll_bit) == 0)
+	if ((status & poll_bit) == check_status)
 		return 0;
 
 	/* Timed out */
drivers/mtd/spi/spi_flash_internal.h +3 -0
index ac4530f..cb7a505 100644
@@ -13,6 +13,7 @@
 #define SPI_FLASH_SECTOR_ERASE_TIMEOUT	(10 * CONFIG_SYS_HZ)
 
 #define SPI_FLASH_16MB_BOUN		0x1000000
+#define SPI_FLASH_512MB_STMIC		0x4000000
 
 /* Common commands */
 #define CMD_READ_ID			0x9f
@@ -24,6 +25,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
@@ -38,6 +40,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);
Signature · 1 line
1.8.3
#30 lore raw

PATCH v2 16/16 sf: Add Flag status register polling support

Hi Simon,

Please let know your comments.

I have changed the logic, but removed spi_flash_cmd_poll_bit() use poll code on spi_flash_cmd_wait_ready()
as no other call for spi_flash_cmd_poll_bit() this.

And also for read_status the check_status i assigned as 0,earlier it has direct 0 (w/o check_status variable).

To add the support for flag status on the same code, i define this check_status. I don't see any coding functionality change for now, compared to before.

--
Thanks,
Jagan.

Quoted 89 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 v2:
- none

 drivers/mtd/spi/spi_flash.c          | 15 ++++++++++++---
 drivers/mtd/spi/spi_flash_internal.h |  3 +++
 2 files changed, 15 insertions(+), 3 deletions(-)
drivers/mtd/spi/spi_flash.c +12 -3
index 527423d..8cd2988 100644
@@ -195,25 +195,34 @@ 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;
 
+       if ((flash->idcode0 == 0x20) &&
+                       (flash->size >= SPI_FLASH_512MB_STMIC)) {
+               poll_bit = STATUS_PEC;
+               check_status = poll_bit;
+               cmd = CMD_FLAG_STATUS;
+       }
+
        timebase = get_timer(0);
        do {
                WATCHDOG_RESET();
 
                ret = spi_flash_read_common(flash, &cmd, 1, &status, 1);
                if (ret < 0) {
-                       debug("SF: fail to read read status register\n");
+                       debug("SF: fail to read %s status register\n",
+                               cmd == CMD_READ_STATUS ? "read" : "flag");
                        return ret;
                }
 
-               if ((status & poll_bit) == 0)
+               if ((status & poll_bit) == check_status)
                        break;
 
        } while (get_timer(timebase) < timeout);
 
-       if ((status & poll_bit) == 0)
+       if ((status & poll_bit) == check_status)
                return 0;
 
        /* Timed out */
drivers/mtd/spi/spi_flash_internal.h +3 -1
index ac4530f..cb7a505 100644
@@ -13,6 +13,7 @@
 #define SPI_FLASH_SECTOR_ERASE_TIMEOUT (10 * CONFIG_SYS_HZ)
 
 #define SPI_FLASH_16MB_BOUN            0x1000000
+#define SPI_FLASH_512MB_STMIC          0x4000000
 
 /* Common commands */
 #define CMD_READ_ID                    0x9f
@@ -24,6 +25,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
@@ -38,6 +40,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);
--

1.8.3

#31 lore raw

PATCH v2 16/16 sf: Add Flag status register polling support

Hi Jagan,

Quoted 8 lines · Jagan Teki

Hi Simon,

Please let know your comments.

I have changed the logic, but removed spi_flash_cmd_poll_bit() use poll code on spi_flash_cmd_wait_ready()
as no other call for spi_flash_cmd_poll_bit() this.

Quoted 7 lines

And also for read_status the check_status i assigned as 0,earlier it has direct 0 (w/o check_status variable).

To add the support for flag status on the same code, i define this check_status.
I don't see any coding functionality change for now, compared to before.

This is not the right patch, but in one of them you remove spi_flash_cmd_poll_bit(),
so that it no longer works the same way. You will get lots of individual SPI transactions on the bus instead of a single one that reads the status byte continuously.

Do we need to change this?

Regards,
Simon

Quoted 101 lines

--
Thanks,
Jagan.

drivers/mtd/spi/spi_flash.c int spi_flash_cmd_wait_ready(struct spi_flash

Quoted 21 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 v2:
- none

 drivers/mtd/spi/spi_flash.c          | 15 ++++++++++++---
 drivers/mtd/spi/spi_flash_internal.h |  3 +++
 2 files changed, 15 insertions(+), 3 deletions(-)
drivers/mtd/spi/spi_flash.c +0 -0
index 527423d..8cd2988 100644
@@ -195,25 +195,34 @@ int spi_flash_cmd_wait_ready(struct spi_flash

*flash, unsigned long timeout)

Quoted 13 lines
drivers/mtd/spi/spi_flash.c +7 -0
        unsigned long timebase;
        int ret;
        u8 status;
+       u8 check_status = 0x0;
        u8 poll_bit = STATUS_WIP;
        u8 cmd = CMD_READ_STATUS;
 
+       if ((flash->idcode0 == 0x20) &&
+                       (flash->size >= SPI_FLASH_512MB_STMIC)) {
+               poll_bit = STATUS_PEC;
+               check_status = poll_bit;
+               cmd = CMD_FLAG_STATUS;
+       }

drivers/mtd/spi/spi_flash.c int spi_flash_cmd_wait_ready(struct spi_flash *flash, unsigned long timeout)

Quoted 10 lines
drivers/mtd/spi/spi_flash.c +3 -1
+
        timebase = get_timer(0);
        do {
                WATCHDOG_RESET();
 
                ret = spi_flash_read_common(flash, &cmd, 1, &status, 1);
                if (ret < 0) {
-                       debug("SF: fail to read read status register\n");
+                       debug("SF: fail to read %s status register\n",
+                               cmd == CMD_READ_STATUS ? "read" :

"flag");

Review

Quoted 15 lines
drivers/mtd/spi/spi_flash.c +2 -2
                        return ret;
                }
 
-               if ((status & poll_bit) == 0)
+               if ((status & poll_bit) == check_status)
                        break;
 
        } while (get_timer(timebase) < timeout);
 
-       if ((status & poll_bit) == 0)
+       if ((status & poll_bit) == check_status)
                return 0;
 
        /* Timed out */
(quoted diff) +0 -0

b/drivers/mtd/spi/spi_flash_internal.h

Quoted 20 lines

index ac4530f..cb7a505 100644

drivers/mtd/spi/spi_flash_internal.h +2 -0
@@ -13,6 +13,7 @@
 #define SPI_FLASH_SECTOR_ERASE_TIMEOUT (10 * CONFIG_SYS_HZ)
 
 #define SPI_FLASH_16MB_BOUN            0x1000000
+#define SPI_FLASH_512MB_STMIC          0x4000000
 
 /* Common commands */
 #define CMD_READ_ID                    0x9f
@@ -24,6 +25,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

drivers/mtd/spi/spi_flash_internal.h line 46

Quoted 7 lines
drivers/mtd/spi/spi_flash_internal.h +1 -0
@@ -38,6 +40,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);

Quoted 3 lines

--
1.8.3

#32 lore raw

PATCH v2 16/16 sf: Add Flag status register polling support

Hi Simon,

Quoted 20 lines · Simon Glass

Hi Jagan,

Quoted 9 lines · Jagan Teki

Hi Simon,

Please let know your comments.

I have changed the logic, but removed spi_flash_cmd_poll_bit() use poll code on spi_flash_cmd_wait_ready()
as no other call for spi_flash_cmd_poll_bit() this.

Quoted 6 lines

And also for read_status the check_status i assigned as 0,earlier it has direct 0 (w/o check_status variable).

To add the support for flag status on the same code, i define this check_status.
I don't see any coding functionality change for now, compared to before.

Quoted 4 lines

This is not the right patch, but in one of them you remove spi_flash_cmd_poll_bit(), so that it no longer works the same way. You will get lots of individual SPI transactions on the bus instead of a single one that reads the status byte continuously.

I couldn't understand you clearly.

Earlier all erase/write they were calling spi_flash_cmd_wait_ready with flash, timeout values.
spi_flash_cmd_wait_ready() is intern call to spi_flash_cmd_poll_bit() with CMD_READ_STATUS and STATUS_WIP.

In my changes I have removed spi_flash_cmd_poll_bit() as there is no other caller except spi_flash_cmd_wait_ready()
so all polling stuff on spi_flash_cmd_wait_ready() means, still erase/program can call spi_flash_cmd_wait_ready() with flash, timeout and CMD_READ_STATUS and STAUS_WIP were use directly used on spi_flash_cmd_wait_ready() instead
of passing through spi_flash_cmd_poll_bit().

Any wrong here, please comment.

Thanks,
Jagan.

Quoted 106 lines

Do we need to change this?

Quoted 102 lines

--
Thanks,
Jagan.

Quoted 93 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 v2:
- none

 drivers/mtd/spi/spi_flash.c          | 15 ++++++++++++---
 drivers/mtd/spi/spi_flash_internal.h |  3 +++
 2 files changed, 15 insertions(+), 3 deletions(-)
drivers/mtd/spi/spi_flash.c +12 -3
index 527423d..8cd2988 100644
@@ -195,25 +195,34 @@ 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;
 
+       if ((flash->idcode0 == 0x20) &&
+                       (flash->size >= SPI_FLASH_512MB_STMIC)) {
+               poll_bit = STATUS_PEC;
+               check_status = poll_bit;
+               cmd = CMD_FLAG_STATUS;
+       }
+
        timebase = get_timer(0);
        do {
                WATCHDOG_RESET();
 
                ret = spi_flash_read_common(flash, &cmd, 1, &status, 1);
                if (ret < 0) {
-                       debug("SF: fail to read read status
 register\n");
+                       debug("SF: fail to read %s status register\n",
+                               cmd == CMD_READ_STATUS ? "read" :
 "flag");
                        return ret;
                }
 
-               if ((status & poll_bit) == 0)
+               if ((status & poll_bit) == check_status)
                        break;
 
        } while (get_timer(timebase) < timeout);
 
-       if ((status & poll_bit) == 0)
+       if ((status & poll_bit) == check_status)
                return 0;

        /* Timed out */
drivers/mtd/spi/spi_flash_internal.h +3 -0
index ac4530f..cb7a505 100644
@@ -13,6 +13,7 @@
 #define SPI_FLASH_SECTOR_ERASE_TIMEOUT (10 * CONFIG_SYS_HZ)
 
 #define SPI_FLASH_16MB_BOUN            0x1000000
+#define SPI_FLASH_512MB_STMIC          0x4000000
 
 /* Common commands */
 #define CMD_READ_ID                    0x9f
@@ -24,6 +25,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
@@ -38,6 +40,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);
--
1.8.3

#33 lore raw

PATCH v2 16/16 sf: Add Flag status register polling support

Hi Jagan,

Quoted 46 lines · Jagan Teki

Hi Simon,

Quoted 3 lines · Simon Glass

Hi Jagan,

On Sat, Jun 8, 2013 at 1:32 AM, Jagan Teki <[email protected]>

Quoted 12 lines · wrote:
Quoted 12 lines

Hi Simon,

Please let know your comments.

I have changed the logic, but removed spi_flash_cmd_poll_bit() use poll code on spi_flash_cmd_wait_ready()
as no other call for spi_flash_cmd_poll_bit() this.

And also for read_status the check_status i assigned as 0,earlier it has direct 0 (w/o check_status variable).

Quoted 7 lines
Quoted 3 lines

To add the support for flag status on the same code, i define this check_status.
I don't see any coding functionality change for now, compared to before.

This is not the right patch, but in one of them you remove spi_flash_cmd_poll_bit(), so that it no longer works the same way. You

will

Quoted 1 line

get lots of individual SPI transactions on the bus instead of a single

one

Quoted 1 line

that reads the status byte continuously.

I couldn't understand you clearly.

Earlier all erase/write they were calling spi_flash_cmd_wait_ready with flash, timeout values.
spi_flash_cmd_wait_ready() is intern call to spi_flash_cmd_poll_bit() with CMD_READ_STATUS and STATUS_WIP.

In my changes I have removed spi_flash_cmd_poll_bit() as there is no other caller except spi_flash_cmd_wait_ready()
so all polling stuff on spi_flash_cmd_wait_ready() means, still erase/program can call spi_flash_cmd_wait_ready() with flash, timeout and CMD_READ_STATUS and STAUS_WIP were use directly used on spi_flash_cmd_wait_ready() instead
of passing through spi_flash_cmd_poll_bit().

Quoted 2 lines

Any wrong here, please comment.

You have changed the implementation of spi_flash_cmd_wait_ready() so that instead of polling for the bit within a single SPI transaction (CS staying asserted) you are now doing multiple transactions.

The old code for spi_flash_cmd_wait_ready() ended up with an algorithm like this, when you look inside the nested functions:

spi_claim_bus(spi);
ret = spi_xfer(spi, cmd_len * 8, cmd, NULL, SPI_XFER_BEGIN); do {

ret = spi_xfer(spi, 8, NULL, &status, 0);
        ...
}

spi_xfer(spi, 0, NULL, NULL, SPI_XFER_END);
spi_release_bus(spi);

The new code is:

do {

spi_claim_bus(spi);
        ret = spi_xfer(spi, cmd_len * 8, cmd, NULL, SPI_XFER_BEGIN);
        ret = spi_xfer(spi, data_len * 8, data_out, data_in, SPI_XFER_END);
spi_release_bus(spi);
        ...
} while (...)

Can you see the difference? The bus clain and SPI_XFER_BEGIN/END is now inside the loop.

Is there a reason why this change is needed? Does updating the bank address not work with the old code?

It is find to move the spi_flash_cmd_poll_bit() function into spi_flash_cmd_wait_ready() - I am not worried about that. I am only worried about your change of algorithm as above.

Regards,
Simon

Quoted 113 lines

Thanks,
Jagan.

Quoted 52 lines

Do we need to change this?

Quoted 48 lines

--
Thanks,
Jagan.

Quoted 40 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 v2:
- none

 drivers/mtd/spi/spi_flash.c          | 15 ++++++++++++---
 drivers/mtd/spi/spi_flash_internal.h |  3 +++
 2 files changed, 15 insertions(+), 3 deletions(-)
drivers/mtd/spi/spi_flash.c +8 -0
index 527423d..8cd2988 100644
@@ -195,25 +195,34 @@ 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;
 
+       if ((flash->idcode0 == 0x20) &&
+                       (flash->size >= SPI_FLASH_512MB_STMIC)) {
+               poll_bit = STATUS_PEC;
+               check_status = poll_bit;
+               cmd = CMD_FLAG_STATUS;
+       }
+
        timebase = get_timer(0);
        do {
                WATCHDOG_RESET();
 
Quoted 1 line
Quoted 1 line

drivers/mtd/spi/spi_flash.c int spi_flash_cmd_wait_ready(struct spi_flash · line 214

Quoted 1 line
drivers/mtd/spi/spi_flash.c +0 -0
                ret = spi_flash_read_common(flash, &cmd, 1, &status,

1);

Quoted 43 lines
Quoted 43 lines
Quoted 43 lines
drivers/mtd/spi/spi_flash.c +4 -3
                if (ret < 0) {
-                       debug("SF: fail to read read status
 register\n");
+                       debug("SF: fail to read %s status register\n",
+                               cmd == CMD_READ_STATUS ? "read" :
 "flag");
                        return ret;
                }
 
-               if ((status & poll_bit) == 0)
+               if ((status & poll_bit) == check_status)
                        break;
 
        } while (get_timer(timebase) < timeout);
 
-       if ((status & poll_bit) == 0)
+       if ((status & poll_bit) == check_status)
                return 0;

        /* Timed out */
drivers/mtd/spi/spi_flash_internal.h +2 -0
index ac4530f..cb7a505 100644
@@ -13,6 +13,7 @@
 #define SPI_FLASH_SECTOR_ERASE_TIMEOUT (10 * CONFIG_SYS_HZ)
 
 #define SPI_FLASH_16MB_BOUN            0x1000000
+#define SPI_FLASH_512MB_STMIC          0x4000000
 
 /* Common commands */
 #define CMD_READ_ID                    0x9f
@@ -24,6 +25,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
@@ -38,6 +40,7 @@
 
Quoted 6 lines
Quoted 6 lines

drivers/mtd/spi/spi_flash_internal.h

Quoted 6 lines
drivers/mtd/spi/spi_flash_internal.h +1 -0
 /* 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

Quoted 4 lines
Quoted 4 lines
Quoted 3 lines

len);
--
1.8.3

#34 lore raw

PATCH v2 16/16 sf: Add Flag status register polling support

Hi Simon,

Quoted 81 lines · Simon Glass

Hi Jagan,

Quoted 48 lines · Jagan Teki

Hi Simon,

Quoted 22 lines · Simon Glass

Hi Jagan,

Quoted 9 lines · Jagan Teki

Hi Simon,

Please let know your comments.

I have changed the logic, but removed spi_flash_cmd_poll_bit() use poll code on spi_flash_cmd_wait_ready()
as no other call for spi_flash_cmd_poll_bit() this.

Quoted 7 lines

And also for read_status the check_status i assigned as 0,earlier it has direct 0 (w/o check_status variable).

To add the support for flag status on the same code, i define this check_status.
I don't see any coding functionality change for now, compared to before.

Quoted 6 lines

This is not the right patch, but in one of them you remove spi_flash_cmd_poll_bit(), so that it no longer works the same way. You will
get lots of individual SPI transactions on the bus instead of a single one
that reads the status byte continuously.

I couldn't understand you clearly.

Earlier all erase/write they were calling spi_flash_cmd_wait_ready with flash, timeout values.
spi_flash_cmd_wait_ready() is intern call to spi_flash_cmd_poll_bit() with CMD_READ_STATUS and STATUS_WIP.

In my changes I have removed spi_flash_cmd_poll_bit() as there is no other caller except spi_flash_cmd_wait_ready()
so all polling stuff on spi_flash_cmd_wait_ready() means, still erase/program can call spi_flash_cmd_wait_ready() with flash, timeout and CMD_READ_STATUS and STAUS_WIP were use directly used on spi_flash_cmd_wait_ready() instead
of passing through spi_flash_cmd_poll_bit().

Quoted 1 line

Any wrong here, please comment.

You have changed the implementation of spi_flash_cmd_wait_ready() so that instead of polling for the bit within a single SPI transaction (CS staying asserted) you are now doing multiple transactions.

The old code for spi_flash_cmd_wait_ready() ended up with an algorithm like this, when you look inside the nested functions:

spi_claim_bus(spi);
ret = spi_xfer(spi, cmd_len * 8, cmd, NULL, SPI_XFER_BEGIN); do {

ret = spi_xfer(spi, 8, NULL, &status, 0);
        ...
}

spi_xfer(spi, 0, NULL, NULL, SPI_XFER_END);
spi_release_bus(spi);

The new code is:

do {

spi_claim_bus(spi);
        ret = spi_xfer(spi, cmd_len * 8, cmd, NULL, SPI_XFER_BEGIN);
        ret = spi_xfer(spi, data_len * 8, data_out, data_in, SPI_XFER_END);
spi_release_bus(spi);
        ...
} while (...)
Quoted 2 lines

Can you see the difference? The bus clain and SPI_XFER_BEGIN/END is now inside the loop.

Understand, i thought as we do _END transfer in old code as well. It could be fine to go with using common function as it will do _BEGIN and _END.

What could be the problem you see if we do _BEGIN and _END on loop...?

Quoted 3 lines

Is there a reason why this change is needed? Does updating the bank address not work with the old code?

It doesn't effect with banking.

Thanks,
Jagan.

Quoted 124 lines

It is find to move the spi_flash_cmd_poll_bit() function into spi_flash_cmd_wait_ready() - I am not worried about that. I am only worried about your change of algorithm as above.

Regards,
Simon

Quoted 115 lines

Thanks,
Jagan.

Quoted 110 lines

Do we need to change this?

Quoted 106 lines

--
Thanks,
Jagan.

Quoted 97 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 v2:
- none

 drivers/mtd/spi/spi_flash.c          | 15 ++++++++++++---
 drivers/mtd/spi/spi_flash_internal.h |  3 +++
 2 files changed, 15 insertions(+), 3 deletions(-)
drivers/mtd/spi/spi_flash.c +12 -3
index 527423d..8cd2988 100644
@@ -195,25 +195,34 @@ 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;
 
+       if ((flash->idcode0 == 0x20) &&
+                       (flash->size >= SPI_FLASH_512MB_STMIC)) {
+               poll_bit = STATUS_PEC;
+               check_status = poll_bit;
+               cmd = CMD_FLAG_STATUS;
+       }
+
        timebase = get_timer(0);
        do {
                WATCHDOG_RESET();
 
                ret = spi_flash_read_common(flash, &cmd, 1, &status,
 1);
                if (ret < 0) {
-                       debug("SF: fail to read read status
 register\n");
+                       debug("SF: fail to read %s status
 register\n",
+                               cmd == CMD_READ_STATUS ? "read" :
 "flag");
                        return ret;
                }
 
-               if ((status & poll_bit) == 0)
+               if ((status & poll_bit) == check_status)
                        break;
 
        } while (get_timer(timebase) < timeout);
 
-       if ((status & poll_bit) == 0)
+       if ((status & poll_bit) == check_status)
                return 0;
 
        /* Timed out */
drivers/mtd/spi/spi_flash_internal.h +3 -0
index ac4530f..cb7a505 100644
@@ -13,6 +13,7 @@
 #define SPI_FLASH_SECTOR_ERASE_TIMEOUT (10 * CONFIG_SYS_HZ)
 
 #define SPI_FLASH_16MB_BOUN            0x1000000
+#define SPI_FLASH_512MB_STMIC          0x4000000
 
 /* Common commands */
 #define CMD_READ_ID                    0x9f
@@ -24,6 +25,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
@@ -38,6 +40,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);
--
1.8.3

#35 lore raw

PATCH v2 16/16 sf: Add Flag status register polling support

Hi Simon,

Quoted 93 lines · Jagan Teki

Hi Simon,

Quoted 81 lines · Simon Glass

Hi Jagan,

Quoted 48 lines · Jagan Teki

Hi Simon,

Quoted 22 lines · Simon Glass

Hi Jagan,

Quoted 9 lines · Jagan Teki

Hi Simon,

Please let know your comments.

I have changed the logic, but removed spi_flash_cmd_poll_bit() use poll code on spi_flash_cmd_wait_ready()
as no other call for spi_flash_cmd_poll_bit() this.

Quoted 7 lines

And also for read_status the check_status i assigned as 0,earlier it has direct 0 (w/o check_status variable).

To add the support for flag status on the same code, i define this check_status.
I don't see any coding functionality change for now, compared to before.

Quoted 6 lines

This is not the right patch, but in one of them you remove spi_flash_cmd_poll_bit(), so that it no longer works the same way. You will
get lots of individual SPI transactions on the bus instead of a single one
that reads the status byte continuously.

I couldn't understand you clearly.

Earlier all erase/write they were calling spi_flash_cmd_wait_ready with flash, timeout values.
spi_flash_cmd_wait_ready() is intern call to spi_flash_cmd_poll_bit() with CMD_READ_STATUS and STATUS_WIP.

In my changes I have removed spi_flash_cmd_poll_bit() as there is no other caller except spi_flash_cmd_wait_ready()
so all polling stuff on spi_flash_cmd_wait_ready() means, still erase/program can call spi_flash_cmd_wait_ready() with flash, timeout and CMD_READ_STATUS and STAUS_WIP were use directly used on spi_flash_cmd_wait_ready() instead
of passing through spi_flash_cmd_poll_bit().

Quoted 1 line

Any wrong here, please comment.

You have changed the implementation of spi_flash_cmd_wait_ready() so that instead of polling for the bit within a single SPI transaction (CS staying asserted) you are now doing multiple transactions.

The old code for spi_flash_cmd_wait_ready() ended up with an algorithm like this, when you look inside the nested functions:

spi_claim_bus(spi);
ret = spi_xfer(spi, cmd_len * 8, cmd, NULL, SPI_XFER_BEGIN); do {

ret = spi_xfer(spi, 8, NULL, &status, 0);
        ...
}

spi_xfer(spi, 0, NULL, NULL, SPI_XFER_END);
spi_release_bus(spi);

The new code is:

do {

spi_claim_bus(spi);
        ret = spi_xfer(spi, cmd_len * 8, cmd, NULL, SPI_XFER_BEGIN);
        ret = spi_xfer(spi, data_len * 8, data_out, data_in, SPI_XFER_END);
spi_release_bus(spi);
        ...
} while (...)
Quoted 2 lines

Can you see the difference? The bus clain and SPI_XFER_BEGIN/END is now inside the loop.

Understand, i thought as we do _END transfer in old code as well. It could be fine to go with using common function as it will do _BEGIN and _END.

What could be the problem you see if we do _BEGIN and _END on loop...?

Quoted 1 line
Quoted 132 lines
Quoted 2 lines

Is there a reason why this change is needed? Does updating the bank address not work with the old code?

It doesn't effect with banking.

Thanks,
Jagan.

Quoted 124 lines

It is find to move the spi_flash_cmd_poll_bit() function into spi_flash_cmd_wait_ready() - I am not worried about that. I am only worried about your change of algorithm as above.

Regards,
Simon

Quoted 115 lines

Thanks,
Jagan.

Quoted 110 lines

Do we need to change this?

Quoted 106 lines

--
Thanks,
Jagan.

Quoted 97 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 v2:
- none

 drivers/mtd/spi/spi_flash.c          | 15 ++++++++++++---
 drivers/mtd/spi/spi_flash_internal.h |  3 +++
 2 files changed, 15 insertions(+), 3 deletions(-)
drivers/mtd/spi/spi_flash.c +12 -3
index 527423d..8cd2988 100644
@@ -195,25 +195,34 @@ 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;
 
+       if ((flash->idcode0 == 0x20) &&
+                       (flash->size >= SPI_FLASH_512MB_STMIC)) {
+               poll_bit = STATUS_PEC;
+               check_status = poll_bit;
+               cmd = CMD_FLAG_STATUS;
+       }
+
        timebase = get_timer(0);
        do {
                WATCHDOG_RESET();
 
                ret = spi_flash_read_common(flash, &cmd, 1, &status,
 1);
                if (ret < 0) {
-                       debug("SF: fail to read read status
 register\n");
+                       debug("SF: fail to read %s status
 register\n",
+                               cmd == CMD_READ_STATUS ? "read" :
 "flag");
                        return ret;
                }
 
-               if ((status & poll_bit) == 0)
+               if ((status & poll_bit) == check_status)
                        break;
 
        } while (get_timer(timebase) < timeout);
 
-       if ((status & poll_bit) == 0)
+       if ((status & poll_bit) == check_status)
                return 0;
 
        /* Timed out */
drivers/mtd/spi/spi_flash_internal.h +3 -0
index ac4530f..cb7a505 100644
@@ -13,6 +13,7 @@
 #define SPI_FLASH_SECTOR_ERASE_TIMEOUT (10 * CONFIG_SYS_HZ)
 
 #define SPI_FLASH_16MB_BOUN            0x1000000
+#define SPI_FLASH_512MB_STMIC          0x4000000
 
 /* Common commands */
 #define CMD_READ_ID                    0x9f
@@ -24,6 +25,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
@@ -38,6 +40,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);
--
1.8.3

May be I will explore much for this, update the changes later. and i will remains the code as before as of now.

Do you have any more comments on this series.
I will going to send v3 and planning to apply.

--
Thanks,
Jagan.

#36 lore raw

PATCH v2 16/16 sf: Add Flag status register polling support

Hi Jagan,

Quoted 245 lines · Jagan Teki

Hi Simon,

Quoted 6 lines · Jagan Teki

Hi Simon,

Quoted 3 lines · Simon Glass

Hi Jagan,

On Sat, Jun 8, 2013 at 7:44 AM, Jagan Teki <[email protected]>

Quoted 21 lines · wrote:
Quoted 21 lines
Quoted 21 lines

Hi Simon,

Quoted 17 lines · Simon Glass

Hi Jagan,

On Sat, Jun 8, 2013 at 1:32 AM, Jagan Teki <[email protected]

Quoted 12 lines · wrote:

Hi Simon,

Please let know your comments.

I have changed the logic, but removed spi_flash_cmd_poll_bit() use poll code on spi_flash_cmd_wait_ready()
as no other call for spi_flash_cmd_poll_bit() this.

And also for read_status the check_status i assigned as 0,earlier it has direct 0 (w/o check_status variable).

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 4 lines

To add the support for flag status on the same code, i define this check_status.
I don't see any coding functionality change for now, compared to before.

This is not the right patch, but in one of them you remove spi_flash_cmd_poll_bit(), so that it no longer works the same way.

You

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

will
get lots of individual SPI transactions on the bus instead of a

single

Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
Quoted 2 lines

one
that reads the status byte continuously.

I couldn't understand you clearly.

Earlier all erase/write they were calling spi_flash_cmd_wait_ready with flash, timeout values.
spi_flash_cmd_wait_ready() is intern call to spi_flash_cmd_poll_bit() with CMD_READ_STATUS and STATUS_WIP.

In my changes I have removed spi_flash_cmd_poll_bit() as there is no other caller except spi_flash_cmd_wait_ready()
so all polling stuff on spi_flash_cmd_wait_ready() means, still erase/program can call spi_flash_cmd_wait_ready() with flash, timeout and CMD_READ_STATUS and STAUS_WIP were use directly used on spi_flash_cmd_wait_ready() instead
of passing through spi_flash_cmd_poll_bit().

Quoted 4 lines
Quoted 4 lines
Quoted 1 line

Any wrong here, please comment.

You have changed the implementation of spi_flash_cmd_wait_ready() so

that

Quoted 1 line
Quoted 1 line

instead of polling for the bit within a single SPI transaction (CS

staying

Quoted 3 lines
Quoted 3 lines

asserted) you are now doing multiple transactions.

The old code for spi_flash_cmd_wait_ready() ended up with an algorithm

like

Quoted 11 lines
Quoted 11 lines

this, when you look inside the nested functions:

spi_claim_bus(spi);
ret = spi_xfer(spi, cmd_len * 8, cmd, NULL, SPI_XFER_BEGIN); do {

ret = spi_xfer(spi, 8, NULL, &status, 0);
        ...
}

spi_xfer(spi, 0, NULL, NULL, SPI_XFER_END);
spi_release_bus(spi);

Quoted 6 lines
Quoted 6 lines

The new code is:

do {
spi_claim_bus(spi);
ret = spi_xfer(spi, cmd_len * 8, cmd, NULL, SPI_XFER_BEGIN); ret = spi_xfer(spi, data_len * 8, data_out, data_in,

SPI_XFER_END);

Quoted 10 lines
Quoted 7 lines
spi_release_bus(spi);
        ...
} while (...)

Can you see the difference? The bus clain and SPI_XFER_BEGIN/END is now inside the loop.

Understand, i thought as we do _END transfer in old code as well. It could be fine to go with using common function as it will do _BEGIN

and _END.

Quoted 5 lines

What could be the problem you see if we do _BEGIN and _END on loop...?

Quoted 2 lines

Is there a reason why this change is needed? Does updating the bank

address

Quoted 10 lines
Quoted 1 line

not work with the old code?

It doesn't effect with banking.

Thanks,
Jagan.

Quoted 3 lines

It is find to move the spi_flash_cmd_poll_bit() function into spi_flash_cmd_wait_ready() - I am not worried about that. I am only

worried

Quoted 20 lines
Quoted 20 lines

about your change of algorithm as above.

Regards,
Simon

Quoted 15 lines

Thanks,
Jagan.

Quoted 10 lines

Do we need to change this?

Quoted 6 lines

--
Thanks,
Jagan.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 4 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,

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines

spi_flash_cmd_wait_ready will poll for PEC(Program-Erase-Control) bit in flag status register.

---
Changes for v2:
- none

 drivers/mtd/spi/spi_flash.c          | 15 ++++++++++++---
 drivers/mtd/spi/spi_flash_internal.h |  3 +++
 2 files changed, 15 insertions(+), 3 deletions(-)
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

drivers/mtd/spi/spi_flash.c int spi_flash_cmd_wait_ready(struct

Quoted 6 lines
drivers/mtd/spi/spi_flash.c +0 -0
index 527423d..8cd2988 100644
@@ -195,25 +195,34 @@ int spi_flash_cmd_wait_ready(struct

spi_flash

Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
drivers/mtd/spi/spi_flash.c +8 -0
 *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;
 
+       if ((flash->idcode0 == 0x20) &&
+                       (flash->size >= SPI_FLASH_512MB_STMIC)) {
+               poll_bit = STATUS_PEC;
+               check_status = poll_bit;
+               cmd = CMD_FLAG_STATUS;
+       }
+
        timebase = get_timer(0);
        do {
                WATCHDOG_RESET();
 
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

drivers/mtd/spi/spi_flash.c int spi_flash_cmd_wait_ready(struct · line 214

Quoted 1 line
drivers/mtd/spi/spi_flash.c +0 -0
                ret = spi_flash_read_common(flash, &cmd, 1,

&status,

Quoted 45 lines
Quoted 45 lines
Quoted 45 lines
Quoted 45 lines
Quoted 45 lines
Quoted 45 lines
drivers/mtd/spi/spi_flash.c +4 -3
 1);
                if (ret < 0) {
-                       debug("SF: fail to read read status
 register\n");
+                       debug("SF: fail to read %s status
 register\n",
+                               cmd == CMD_READ_STATUS ? "read" :
 "flag");
                        return ret;
                }
 
-               if ((status & poll_bit) == 0)
+               if ((status & poll_bit) == check_status)
                        break;
 
        } while (get_timer(timebase) < timeout);
 
-       if ((status & poll_bit) == 0)
+       if ((status & poll_bit) == check_status)
                return 0;
 
        /* Timed out */
drivers/mtd/spi/spi_flash_internal.h +2 -0
index ac4530f..cb7a505 100644
@@ -13,6 +13,7 @@
 #define SPI_FLASH_SECTOR_ERASE_TIMEOUT (10 * CONFIG_SYS_HZ)
 
 #define SPI_FLASH_16MB_BOUN            0x1000000
+#define SPI_FLASH_512MB_STMIC          0x4000000
 
 /* Common commands */
 #define CMD_READ_ID                    0x9f
@@ -24,6 +25,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
@@ -38,6 +40,7 @@
 
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

drivers/mtd/spi/spi_flash_internal.h line 45

Quoted 5 lines
drivers/mtd/spi/spi_flash_internal.h +1 -0
 /* Common status */
 #define STATUS_WIP                     0x01
+#define STATUS_PEC                     0x80
 
 /* Send a single-byte command to the device and read the

response */

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
drivers/mtd/spi/spi_flash_internal.h +0 -0
 int spi_flash_cmd(struct spi_slave *spi, u8 cmd, void *response,

size_t
len);
--
1.8.3

Quoted 3 lines

May be I will explore much for this, update the changes later. and i will remains the code as before as of now.

Do you mean you will keep the old status-reading algorithm, or change to your new one?

Quoted 4 lines

Do you have any more comments on this series.
I will going to send v3 and planning to apply.

I don't have any other comments.

Quoted 5 lines

--
Thanks,
Jagan.

#37 lore raw

PATCH v2 16/16 sf: Add Flag status register polling support

Quoted 251 lines · Simon Glass

Hi Jagan,

Quoted 247 lines · Jagan Teki

Hi Simon,

Quoted 241 lines · Jagan Teki

Hi Simon,

Quoted 85 lines · Simon Glass

Hi Jagan,

Quoted 52 lines · Jagan Teki

Hi Simon,

Quoted 24 lines · Simon Glass

Hi Jagan,

Quoted 9 lines · Jagan Teki

Hi Simon,

Please let know your comments.

I have changed the logic, but removed spi_flash_cmd_poll_bit() use poll code on spi_flash_cmd_wait_ready()
as no other call for spi_flash_cmd_poll_bit() this.

Quoted 8 lines

And also for read_status the check_status i assigned as 0,earlier it
has direct 0 (w/o check_status variable).

To add the support for flag status on the same code, i define this check_status.
I don't see any coding functionality change for now, compared to before.

Quoted 8 lines

This is not the right patch, but in one of them you remove spi_flash_cmd_poll_bit(), so that it no longer works the same way. You
will
get lots of individual SPI transactions on the bus instead of a single
one
that reads the status byte continuously.

I couldn't understand you clearly.

Earlier all erase/write they were calling spi_flash_cmd_wait_ready with flash, timeout values.
spi_flash_cmd_wait_ready() is intern call to spi_flash_cmd_poll_bit() with CMD_READ_STATUS and STATUS_WIP.

In my changes I have removed spi_flash_cmd_poll_bit() as there is no other caller except spi_flash_cmd_wait_ready()
so all polling stuff on spi_flash_cmd_wait_ready() means, still erase/program can call spi_flash_cmd_wait_ready() with flash, timeout and CMD_READ_STATUS and STAUS_WIP were use directly used on spi_flash_cmd_wait_ready() instead
of passing through spi_flash_cmd_poll_bit().

Quoted 1 line

Any wrong here, please comment.

You have changed the implementation of spi_flash_cmd_wait_ready() so that
instead of polling for the bit within a single SPI transaction (CS staying
asserted) you are now doing multiple transactions.

The old code for spi_flash_cmd_wait_ready() ended up with an algorithm like
this, when you look inside the nested functions:

spi_claim_bus(spi);
ret = spi_xfer(spi, cmd_len * 8, cmd, NULL, SPI_XFER_BEGIN); do {

ret = spi_xfer(spi, 8, NULL, &status, 0);
        ...
}

spi_xfer(spi, 0, NULL, NULL, SPI_XFER_END);
spi_release_bus(spi);

The new code is:

do {
spi_claim_bus(spi);
ret = spi_xfer(spi, cmd_len * 8, cmd, NULL, SPI_XFER_BEGIN); ret = spi_xfer(spi, data_len * 8, data_out, data_in,
SPI_XFER_END);

Quoted 7 lines
spi_release_bus(spi);
        ...
} while (...)

Can you see the difference? The bus clain and SPI_XFER_BEGIN/END is now inside the loop.

Understand, i thought as we do _END transfer in old code as well. It could be fine to go with using common function as it will do _BEGIN and _END.

What could be the problem you see if we do _BEGIN and _END on loop...?

Quoted 4 lines

Is there a reason why this change is needed? Does updating the bank address
not work with the old code?

It doesn't effect with banking.

Thanks,
Jagan.

Quoted 129 lines

It is find to move the spi_flash_cmd_poll_bit() function into spi_flash_cmd_wait_ready() - I am not worried about that. I am only worried
about your change of algorithm as above.

Regards,
Simon

Quoted 119 lines

Thanks,
Jagan.

Quoted 114 lines

Do we need to change this?

Quoted 110 lines

--
Thanks,
Jagan.

Quoted 101 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 v2:
- none

 drivers/mtd/spi/spi_flash.c          | 15 ++++++++++++---
 drivers/mtd/spi/spi_flash_internal.h |  3 +++
 2 files changed, 15 insertions(+), 3 deletions(-)
drivers/mtd/spi/spi_flash.c +0 -0
index 527423d..8cd2988 100644
@@ -195,25 +195,34 @@ int spi_flash_cmd_wait_ready(struct

spi_flash
*flash, unsigned long timeout)

        unsigned long timebase;
        int ret;
        u8 status;
drivers/mtd/spi/spi_flash.c +8 -0
+       u8 check_status = 0x0;
        u8 poll_bit = STATUS_WIP;
        u8 cmd = CMD_READ_STATUS;
 
+       if ((flash->idcode0 == 0x20) &&
+                       (flash->size >= SPI_FLASH_512MB_STMIC)) {
+               poll_bit = STATUS_PEC;
+               check_status = poll_bit;
+               cmd = CMD_FLAG_STATUS;
+       }
+
        timebase = get_timer(0);
        do {
                WATCHDOG_RESET();
 
                ret = spi_flash_read_common(flash, &cmd, 1,

&status,

1);
                if (ret < 0) {

- debug("SF: fail to read read status
register\n");
+ debug("SF: fail to read %s status
register\n",
+ cmd == CMD_READ_STATUS ? "read" :

"flag");
                        return ret;
                }
drivers/mtd/spi/spi_flash.c +2 -2
-               if ((status & poll_bit) == 0)
+               if ((status & poll_bit) == check_status)
                        break;
 
        } while (get_timer(timebase) < timeout);
 
-       if ((status & poll_bit) == 0)
+       if ((status & poll_bit) == check_status)
                return 0;
 
        /* Timed out */
drivers/mtd/spi/spi_flash_internal.h +3 -0
index ac4530f..cb7a505 100644
@@ -13,6 +13,7 @@
 #define SPI_FLASH_SECTOR_ERASE_TIMEOUT (10 * CONFIG_SYS_HZ)
 
 #define SPI_FLASH_16MB_BOUN            0x1000000
+#define SPI_FLASH_512MB_STMIC          0x4000000
 
 /* Common commands */
 #define CMD_READ_ID                    0x9f
@@ -24,6 +25,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
@@ -38,6 +40,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);
--
1.8.3

Quoted 6 lines
Quoted 2 lines

May be I will explore much for this, update the changes later. and i will remains the code as before as of now.

Do you mean you will keep the old status-reading algorithm, or change to your new one?

Will keep the old status-read algo.

--
Thanks,
Jagan.

Quoted 16 lines
Quoted 5 lines

Do you have any more comments on this series.
I will going to send v3 and planning to apply.

I don't have any other comments.

Quoted 5 lines

--
Thanks,
Jagan.