Skip to contentSkip to conversation

sf: Add bank address register writing support

PATCH Superseded Jagannadha Sutradharudu Teki 5 participants 39 messages Jun 11, 2013 – Jun 13, 2013 1 message not in the archive

Subsystems (2)

v3 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 v3 1/17 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 v3:
- none
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 v3 1/17 sf: Add bank address register writing support

Hi Jagan,

Quoted 6 lines · Jagannadha Sutradharudu Teki

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.

Quoted 9 lines

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

See comment below, perhaps a follow-on patch so you can get this in first?

Quoted 19 lines

---
Changes for v3:
- none
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 +0 -0
index 0e38f59..7aba520 100644
@@ -278,6 +278,40 @@ int spi_flash_cmd_write_status(struct spi_flash
 *flash, u8 sr)
        return 0;

drivers/mtd/spi/spi_flash.c int spi_flash_cmd_write_status(struct spi_flash · line 289

Quoted 10 lines
drivers/mtd/spi/spi_flash.c +7 -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) {
 

I wonder why you need this to be hard-coded here? As a follow-on patch, I suggest you have something in the probe function which decides which bank addressing algorithm to use (e.g. winbond, ST, none). and then this code can be:

switch (flash->bank_addr_algo) {
case SF_ALGO_WINBOND:
...
case SF_ALGO_ST:
...
}

Quoted 83 lines
drivers/mtd/spi/spi_flash.c +27 -0
+               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) {

drivers/mtd/spi/spi_flash.c +3 -0
@@ -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 -1
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,
--

1.8.3

Quoted 1 line

Regards,

Simon

#3 lore raw

PATCH v3 1/17 sf: Add bank address register writing support

Hi Simon,

Quoted 61 lines · Simon Glass

Hi Jagan,

Quoted 7 lines · Jagannadha Sutradharudu Teki

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.

Quoted 8 lines

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

See comment below, perhaps a follow-on patch so you can get this in first?

Quoted 19 lines

---
Changes for v3:
- none
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 +0 -0
index 0e38f59..7aba520 100644
@@ -278,6 +278,40 @@ int spi_flash_cmd_write_status(struct spi_flash
 *flash, u8 sr)

drivers/mtd/spi/spi_flash.c int spi_flash_cmd_write_status(struct spi_flash · line 288

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

I wonder why you need this to be hard-coded here? As a follow-on patch, I suggest you have something in the probe function which decides which bank addressing algorithm to use (e.g. winbond, ST, none). and then this code can be:

Quoted 6 lines

switch (flash->bank_addr_algo) {
case SF_ALGO_WINBOND:

   ...

case SF_ALGO_ST:
...
}

Means in probe time we can assign particular bank commands something like

switch (*idp) {
case SF_WINBOND_IDCODE0:

     flash->bank_wr_cmd = ;
     flash->bank_rd_cmd = ;
case SF_SPAN_IDCODE0:
    flash->bank_wr_cmd = ;
    flash->bank_rd_cmd = ;
}

Please let me know your comments.

--
Thanks,
Jagan.

Quoted 92 lines
Quoted 87 lines
drivers/mtd/spi/spi_flash.c +27 -0
+               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)

{

drivers/mtd/spi/spi_flash.c +3 -0
@@ -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,
--
1.8.3

Quoted 1 line

Regards,

Simon

#4 lore raw

PATCH v3 1/17 sf: Add bank address register writing support

Quoted 75 lines · Jagan Teki

Hi Simon,

Quoted 61 lines · Simon Glass

Hi Jagan,

Quoted 7 lines · Jagannadha Sutradharudu Teki

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.

Quoted 8 lines

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

See comment below, perhaps a follow-on patch so you can get this in first?

Quoted 19 lines

---
Changes for v3:
- none
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 +0 -0
index 0e38f59..7aba520 100644
@@ -278,6 +278,40 @@ int spi_flash_cmd_write_status(struct spi_flash
 *flash, u8 sr)

drivers/mtd/spi/spi_flash.c int spi_flash_cmd_write_status(struct spi_flash · line 288

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

I wonder why you need this to be hard-coded here? As a follow-on patch, I suggest you have something in the probe function which decides which bank addressing algorithm to use (e.g. winbond, ST, none). and then this code can be:

Quoted 6 lines

switch (flash->bank_addr_algo) {
case SF_ALGO_WINBOND:

   ...

case SF_ALGO_ST:
...
}

Means in probe time we can assign particular bank commands something like

switch (*idp) {
case SF_WINBOND_IDCODE0:

Quoted 8 lines
     flash->bank_wr_cmd = ;
     flash->bank_rd_cmd = ;
case SF_SPAN_IDCODE0:
    flash->bank_wr_cmd = ;
    flash->bank_rd_cmd = ;
}

Please let me know your comments.

Correct, and similar to how some of the filesystem code works. Looks good to me.

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/20130613/4f608164/attachment.pgp>
#5 lore raw

PATCH v3 1/17 sf: Add bank address register writing support

Quoted 83 lines · Tom Rini
Quoted 82 lines · Jagan Teki

Hi Simon,

Quoted 61 lines · Simon Glass

Hi Jagan,

Quoted 7 lines · Jagannadha Sutradharudu Teki

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.

Quoted 8 lines

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

See comment below, perhaps a follow-on patch so you can get this in first?

Quoted 19 lines

---
Changes for v3:
- none
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 +0 -0
index 0e38f59..7aba520 100644
@@ -278,6 +278,40 @@ int spi_flash_cmd_write_status(struct spi_flash
 *flash, u8 sr)

drivers/mtd/spi/spi_flash.c int spi_flash_cmd_write_status(struct spi_flash · line 288

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

I wonder why you need this to be hard-coded here? As a follow-on patch, I suggest you have something in the probe function which decides which bank addressing algorithm to use (e.g. winbond, ST, none). and then this code can be:

Quoted 6 lines

switch (flash->bank_addr_algo) {
case SF_ALGO_WINBOND:

   ...

case SF_ALGO_ST:
...
}

Means in probe time we can assign particular bank commands something like

switch (*idp) {
case SF_WINBOND_IDCODE0:

     flash->bank_wr_cmd = ;
     flash->bank_rd_cmd = ;
case SF_SPAN_IDCODE0:
    flash->bank_wr_cmd = ;
    flash->bank_rd_cmd = ;
}
Quoted 4 lines
Quoted 1 line

Please let me know your comments.

Correct, and similar to how some of the filesystem code works. Looks good to me.

Thank you, I am sending the respective changes on v4.

--
Thanks,
Jagan.

#6 lore raw

PATCH v3 2/17 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 v3:
- none
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
#7 lore raw

PATCH v3 2/17 sf: Add bank address register reading support

Quoted 6 lines · Jagannadha Sutradharudu Teki

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.

Quoted 9 lines

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

(same comment as previous patch)

---

Quoted 65 lines

Changes for v3:
- none
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.
--
1.8.3

#8 lore raw

PATCH v3 3/17 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 v3:
- none
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
#9 lore raw

PATCH v3 3/17 sf: Add extended addr write support for winbond|stmicro

Quoted 5 lines · Jagannadha Sutradharudu Teki

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

Looks good, same comment as previous patch.

Quoted 42 lines

---
Changes for v3:
- none
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 -1
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
--

1.8.3

#10 lore raw

PATCH v3 4/17 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 v3:
- none
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
#11 lore raw

PATCH v3 4/17 sf: Add extended addr read support for winbond|stmicro

Quoted 5 lines · Jagannadha Sutradharudu Teki

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

Same comment as previous patch.

Quoted 42 lines

---
Changes for v3:
- none
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 -1
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
--

1.8.3

#12 lore raw

PATCH v3 5/17 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 v3:
- none
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
#13 lore raw

PATCH v3 5/17 sf: read flash bank addr register at probe time

Quoted 4 lines · Jagannadha Sutradharudu Teki

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.

Quoted 8 lines

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.

Quoted 96 lines

---
Changes for v3:
- none
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 +5 -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;
drivers/mtd/spi/spi_flash.c +1 -0
@@ -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) {
drivers/mtd/spi/spi_flash.c +1 -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) {
drivers/mtd/spi/spi_flash.c +10 -0
@@ -491,6 +498,16 @@ struct spi_flash *spi_flash_probe(unsigned int bus,
 unsigned int cs,
                printf(", mapped at %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 -1
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,
--

1.8.3

#14 lore raw

PATCH v3 6/17 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 v3:
- none
Changes for v2:
- none

 drivers/mtd/spi/spi_flash.c | 39 ++++++++++++++++++++++++++-------------
 1 file changed, 26 insertions(+), 13 deletions(-)
drivers/mtd/spi/spi_flash.c +26 -13
index 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
#15 lore raw

PATCH v3 6/17 sf: Update sf to support all sizes of flashes

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.

#16 lore raw

PATCH v3 7/17 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 v3:
- none
Changes for v2:
- none

 drivers/mtd/spi/spi_flash.c | 36 +++++++++++++++++++++++++++++++++---
 1 file changed, 33 insertions(+), 3 deletions(-)
drivers/mtd/spi/spi_flash.c +33 -3
index 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
#17 lore raw

PATCH v3 7/17 sf: Update sf read to support all sizes of flashes

Quoted 30 lines · Jagannadha Sutradharudu Teki

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

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

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

Quoted 2 lines
#18 lore raw

PATCH v3 8/17 sf: Add bank addr code in CONFIG_SPI_FLASH_BAR

In reply to a message not in the archive

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

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

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

 README                               |  5 +++++
 drivers/mtd/spi/spi_flash.c          | 41 ++++++++++++++++++++++--------------
 drivers/mtd/spi/spi_flash_internal.h | 14 ++++++------
 include/spi_flash.h                  |  3 ++-
 4 files changed, 40 insertions(+), 23 deletions(-)
README +5 -0
index 3d81092..a2b956e 100644
@@ -2489,6 +2489,11 @@ CBFS (Coreboot Filesystem) support
 		Define this option to include a destructive SPI flash
 		test ('sf test').
 
+		CONFIG_SPI_FLASH_BAR		Ban/Extended Addr Reg
+
+		Define this option to use the Bank addr/Extended addr
+		support on SPI flashes which has size > 16Mbytes.
+
 - SystemACE Support:
 		CONFIG_SYSTEMACE
 
drivers/mtd/spi/spi_flash.c +25 -16

122 lines not on this page · raw message

drivers/mtd/spi/spi_flash_internal.h +8 -6
index 455dc02..12d49a8 100644
@@ -12,8 +12,6 @@
 #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
 
@@ -30,11 +28,15 @@
 #define CMD_ERASE_64K			0xd8
 #define CMD_ERASE_CHIP			0xc7
 
+#define SPI_FLASH_16MB_BOUN		0x1000000
+
 /* Bank addr acess commands */
-#define CMD_BANKADDR_BRWR		0x17
-#define CMD_BANKADDR_BRRD		0x16
-#define CMD_EXTNADDR_WREAR		0xC5
-#define CMD_EXTNADDR_RDEAR		0xC8
+#ifdef CONFIG_SPI_FLASH_BAR
+# define CMD_BANKADDR_BRWR		0x17
+# define CMD_BANKADDR_BRRD		0x16
+# define CMD_EXTNADDR_WREAR		0xC5
+# define CMD_EXTNADDR_RDEAR		0xC8
+#endif
 
 /* Common status */
 #define STATUS_WIP			0x01
include/spi_flash.h +2 -1
index acac17a..5de50c2 100644
@@ -38,11 +38,12 @@ struct spi_flash {
 	u32		page_size;
 	/* Erase (sector) size */
 	u32		sector_size;
+#ifdef CONFIG_SPI_FLASH_BAR
 	/* ID code0 */
 	u8              idcode0;
 	/* Current flash bank */
 	u8		bank_curr;
-
+#endif
 	void *memory_map;	/* Address of read-only SPI flash access */
 	int		(*read)(struct spi_flash *flash, u32 offset,
 				size_t len, void *buf);
Signature · 1 line
1.8.3
#20 lore raw

PATCH v3 9/17 sf: Initialize bank_sel to zero for read ops

In reply to a message not in the archive

Initialized bank_sel variable to 0 to support the updated read ops for flashes which has < 16Mbytes.

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

 drivers/mtd/spi/spi_flash.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/spi/spi_flash.c +1 -1
index ee959fc..96b8733 100644
@@ -151,7 +151,7 @@ int spi_flash_read_common(struct spi_flash *flash, const u8 *cmd,
 int spi_flash_cmd_read_fast(struct spi_flash *flash, u32 offset,
 		size_t len, void *data)
 {
-	u8 cmd[5], bank_sel;
+	u8 cmd[5], bank_sel = 0;
 	u32 remain_len, read_len;
 	int ret = -1;
 
Signature · 1 line
1.8.3
#22 lore raw

PATCH v3 9/17 sf: Initialize bank_sel to zero for read ops

Quoted 6 lines · Simon Glass
Quoted 4 lines · Jagannadha Sutradharudu Teki

Initialized bank_sel variable to 0 to support the updated read ops for flashes which has < 16Mbytes.

Quoted 7 lines
Quoted 1 line

(This seems like it could be merged with an early patch?)

Merged with previous patch, thanks

--
Thanks,
Jagan.

#23 lore raw

PATCH v3 10/17 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 v3:
- none
Changes for v2:
- none

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

PATCH v3 11/17 sf: stmicro: Add support for N25Q512

In reply to a message not in the archive

Add support for Numonyx N25Q512 SPI flash.

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

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

PATCH v3 12/17 sf: stmicro: Add support for N25Q512A

In reply to a message not in the archive

Add support for Numonyx N25Q512A SPI flash.

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

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

PATCH v3 13/17 sf: stmicro: Add support for N25Q1024

In reply to a message not in the archive

Add support for Numonyx N25Q1024 SPI flash.

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

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

PATCH v3 14/17 sf: stmicro: Add support for N25Q1024A

In reply to a message not in the archive

Add support for Numonyx N25Q1024A SPI flash.

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

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

PATCH v3 15/17 sf: spansion: Add support for S25FL512S_64K

In reply to a message not in the archive

Add support for Spansion S25FL512S_64K SPI flash.

---
Changes for v3:
- Added 64K sector part
Changes for v2:
- none

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

PATCH v3 16/17 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 v3:
- none
Changes for v2:
- none

 drivers/mtd/spi/spi_flash.c          | 11 +++--------
 drivers/mtd/spi/spi_flash_internal.h |  4 ----
 2 files changed, 3 insertions(+), 12 deletions(-)
drivers/mtd/spi/spi_flash.c +3 -8
index 57a695a..bb37f54 100644
@@ -194,13 +194,14 @@ int spi_flash_cmd_read_fast(struct spi_flash *flash, u32 offset,
 	return ret;
 }
 
-int spi_flash_cmd_poll_bit(struct spi_flash *flash, unsigned long timeout,
-			   u8 cmd, u8 poll_bit)
+int spi_flash_cmd_wait_ready(struct spi_flash *flash, unsigned long timeout)
 {
 	struct spi_slave *spi = flash->spi;
 	unsigned long timebase;
 	int ret;
 	u8 status;
+	u8 poll_bit = STATUS_WIP;
+	u8 cmd = CMD_READ_STATUS;
 
 	ret = spi_xfer(spi, 8, &cmd, NULL, SPI_XFER_BEGIN);
 	if (ret) {
@@ -231,12 +232,6 @@ int spi_flash_cmd_poll_bit(struct spi_flash *flash, unsigned long timeout,
 	return -1;
 }
 
-int spi_flash_cmd_wait_ready(struct spi_flash *flash, unsigned long timeout)
-{
-	return spi_flash_cmd_poll_bit(flash, timeout,
-		CMD_READ_STATUS, STATUS_WIP);
-}
-
 int spi_flash_cmd_erase(struct spi_flash *flash, u32 offset, size_t len)
 {
 	u32 erase_size;
drivers/mtd/spi/spi_flash_internal.h +0 -4
index 12d49a8..cf6aaf3 100644
@@ -100,10 +100,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
#31 lore raw

PATCH v3 16/17 sf: Remove spi_flash_cmd_poll_bit()

Quoted 6 lines · Jagannadha Sutradharudu Teki

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.

Quoted 4 lines

---
Changes for v3:
- none

Really? It seems different.

Quoted 8 lines

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(-)
#32 lore raw

PATCH v3 16/17 sf: Remove spi_flash_cmd_poll_bit()

Hi Simon,

Quoted 13 lines · Simon Glass
Quoted 6 lines · Jagannadha Sutradharudu Teki

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.

Quoted 1 line
Quoted 6 lines
Quoted 3 lines

---
Changes for v3:
- none

Really? It seems different.

Can you please tell me what is the difference.
As there is no changes in v2 to v3 i have written none was there any wrong with code style or something?

Thanks,
Jagan.

#33 lore raw

PATCH v3 17/17 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 v3:
- define the flag status code on CONFIG_SPI_FLASH_STMICRO
Changes for v2:
- none

 drivers/mtd/spi/spi_flash.c          | 16 +++++++++++++---
 drivers/mtd/spi/spi_flash_internal.h |  2 ++
 2 files changed, 15 insertions(+), 3 deletions(-)
drivers/mtd/spi/spi_flash.c +13 -3
index bb37f54..4f97fab0 100644
@@ -200,12 +200,22 @@ 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;
 
+#ifdef CONFIG_SPI_FLASH_STMICRO
+	if (flash->size >= 0x4000000) {
+		poll_bit = STATUS_PEC;
+		check_status = poll_bit;
+		cmd = CMD_FLAG_STATUS;
+	}
+#endif
+
 	ret = spi_xfer(spi, 8, &cmd, NULL, SPI_XFER_BEGIN);
 	if (ret) {
-		debug("SF: Failed to send command %02x: %d\n", cmd, ret);
+		debug("SF: fail to read %s status register\n",
+			cmd == CMD_READ_STATUS ? "read" : "flag");
 		return ret;
 	}
 
@@ -217,14 +227,14 @@ int spi_flash_cmd_wait_ready(struct spi_flash *flash, unsigned long timeout)
 		if (ret)
 			return -1;
 
-		if ((status & poll_bit) == 0)
+		if ((status & poll_bit) == check_status)
 			break;
 
 	} while (get_timer(timebase) < timeout);
 
 	spi_xfer(spi, 0, NULL, NULL, SPI_XFER_END);
 
-	if ((status & poll_bit) == 0)
+	if ((status & poll_bit) == check_status)
 		return 0;
 
 	/* Timed out */
drivers/mtd/spi/spi_flash_internal.h +2 -0
index cf6aaf3..1d4fb23 100644
@@ -22,6 +22,7 @@
 #define CMD_PAGE_PROGRAM		0x02
 #define CMD_WRITE_DISABLE		0x04
 #define CMD_READ_STATUS			0x05
+#define CMD_FLAG_STATUS			0x70
 #define CMD_WRITE_ENABLE		0x06
 #define CMD_ERASE_4K			0x20
 #define CMD_ERASE_32K			0x52
@@ -40,6 +41,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
#34 lore raw

PATCH v3 17/17 sf: Add Flag status register polling support

Hi Jagan,

Quoted 8 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.

---

Quoted 21 lines

Changes for v3:
- define the flag status code on CONFIG_SPI_FLASH_STMICRO
Changes for v2:
- none

 drivers/mtd/spi/spi_flash.c          | 16 +++++++++++++---
 drivers/mtd/spi/spi_flash_internal.h |  2 ++
 2 files changed, 15 insertions(+), 3 deletions(-)
drivers/mtd/spi/spi_flash.c +1 -0
index bb37f54..4f97fab0 100644
@@ -200,12 +200,22 @@ 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;

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

Quoted 10 lines
drivers/mtd/spi/spi_flash.c +8 -0
 
+#ifdef CONFIG_SPI_FLASH_STMICRO
+       if (flash->size >= 0x4000000) {
+               poll_bit = STATUS_PEC;
+               check_status = poll_bit;
+               cmd = CMD_FLAG_STATUS;
+       }
+#endif
+
 

Similarly to the bank addressing I think this might be better done as a 'poll method' rather than a hack for a particular flash type.

Also I worry that in a system with more than one type of flash, this code will fire for all flash types.

Regards,
Simon

#35 lore raw

PATCH v3 17/17 sf: Add Flag status register polling support

Quoted 50 lines · Simon Glass

Hi Jagan,

Quoted 8 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.

---

Quoted 21 lines

Changes for v3:
- define the flag status code on CONFIG_SPI_FLASH_STMICRO
Changes for v2:
- none

 drivers/mtd/spi/spi_flash.c          | 16 +++++++++++++---
 drivers/mtd/spi/spi_flash_internal.h |  2 ++
 2 files changed, 15 insertions(+), 3 deletions(-)
drivers/mtd/spi/spi_flash.c +1 -0
index bb37f54..4f97fab0 100644
@@ -200,12 +200,22 @@ 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;

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

Quoted 10 lines
drivers/mtd/spi/spi_flash.c +8 -0
 
+#ifdef CONFIG_SPI_FLASH_STMICRO
+       if (flash->size >= 0x4000000) {
+               poll_bit = STATUS_PEC;
+               check_status = poll_bit;
+               cmd = CMD_FLAG_STATUS;
+       }
+#endif
+
 

Similarly to the bank addressing I think this might be better done as a 'poll method' rather than a hack for a particular flash type.

Quoted 3 lines

Also I worry that in a system with more than one type of flash, this code will fire for all flash types.

Also just a note that I tested this series on snow and it seems to have no ill effects.

The series:

Quoted 4 lines

Regards,
Simon

#36 lore raw

PATCH v3 17/17 sf: Add Flag status register polling support

In reply to Simon Glass

Hi Simon,

Quoted 37 lines · Simon Glass

Hi Jagan,

Quoted 33 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 v3:
- define the flag status code on CONFIG_SPI_FLASH_STMICRO
Changes for v2:
- none

 drivers/mtd/spi/spi_flash.c          | 16 +++++++++++++---
 drivers/mtd/spi/spi_flash_internal.h |  2 ++
 2 files changed, 15 insertions(+), 3 deletions(-)
drivers/mtd/spi/spi_flash.c +1 -0
index bb37f54..4f97fab0 100644
@@ -200,12 +200,22 @@ 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;
 
Quoted 13 lines

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

Quoted 8 lines
drivers/mtd/spi/spi_flash.c +8 -0
+#ifdef CONFIG_SPI_FLASH_STMICRO
+       if (flash->size >= 0x4000000) {
+               poll_bit = STATUS_PEC;
+               check_status = poll_bit;
+               cmd = CMD_FLAG_STATUS;
+       }
+#endif
+

Similarly to the bank addressing I think this might be better done as a 'poll method' rather than a hack for a particular flash type.

You mean to say read_status cmd and flag_status cmd need to find it on probe it self.?
Can you please explain "better done as a 'poll method' '

Quoted 2 lines

Also I worry that in a system with more than one type of flash, this code will fire for all flash types.

Even if the system has multiple flashes of different size, we can probe once at a time, right?

--
Thanks,
Jagan.

#37 lore raw

PATCH v3 17/17 sf: Add Flag status register polling support

Hi Jagan, Simon - Adding Bacem and Gernot from Spansion. Would you be able to add them to the other open threads as well? --Max

-------------------------------------------------
Max Willis, PhD
Division Marketing Manager
Software Marketing
Spansion Inc.
-------------------------------------------------

-----Original Message-----
From: Jagan Teki [mailto:jagannadh.teki at gmail.com]
Sent: Wednesday, June 12, 2013 10:32 PM
To: Simon Glass
Cc: Jagannadha Sutradharudu Teki; U-Boot Mailing List; Michal Simek; Tom Rini; Rajeshwari Shinde; Syed Hussain; Willis, Max; Todd Legler (tlegler); Jagannadha Sutradharudu Teki
Subject: Re: [PATCH v3 17/17] sf: Add Flag status register polling support

Hi Simon,

Quoted 37 lines · Simon Glass

Hi Jagan,

Quoted 33 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 v3:
- define the flag status code on CONFIG_SPI_FLASH_STMICRO
Changes for v2:
- none

 drivers/mtd/spi/spi_flash.c          | 16 +++++++++++++---
 drivers/mtd/spi/spi_flash_internal.h |  2 ++
 2 files changed, 15 insertions(+), 3 deletions(-)
(quoted diff) +0 -0

b/drivers/mtd/spi/spi_flash.c index bb37f54..4f97fab0 100644

drivers/mtd/spi/spi_flash.c +1 -0
@@ -200,12 +200,22 @@ 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;
 
Quoted 13 lines

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

Quoted 8 lines
drivers/mtd/spi/spi_flash.c +8 -0
+#ifdef CONFIG_SPI_FLASH_STMICRO
+       if (flash->size >= 0x4000000) {
+               poll_bit = STATUS_PEC;
+               check_status = poll_bit;
+               cmd = CMD_FLAG_STATUS;
+       }
+#endif
+

Similarly to the bank addressing I think this might be better done as a 'poll method' rather than a hack for a particular flash type.

You mean to say read_status cmd and flag_status cmd need to find it on probe it self.? Can you please explain "better done as a 'poll method' '

Quoted 2 lines

Also I worry that in a system with more than one type of flash, this code will fire for all flash types.

Even if the system has multiple flashes of different size, we can probe once at a time, right?

--
Thanks,
Jagan.

#38 lore raw

PATCH v3 17/17 sf: Add Flag status register polling support

Hi Jagan,

Quoted 73 lines · Max

Hi Jagan, Simon - Adding Bacem and Gernot from Spansion. Would you be able to add them to the other open threads as well? --Max

-------------------------------------------------
Max Willis, PhD
Division Marketing Manager
Software Marketing
Spansion Inc.
-------------------------------------------------

-----Original Message-----
From: Jagan Teki [mailto:jagannadh.teki at gmail.com]
Sent: Wednesday, June 12, 2013 10:32 PM
To: Simon Glass
Cc: Jagannadha Sutradharudu Teki; U-Boot Mailing List; Michal Simek; Tom Rini; Rajeshwari Shinde; Syed Hussain; Willis, Max; Todd Legler (tlegler); Jagannadha Sutradharudu Teki
Subject: Re: [PATCH v3 17/17] sf: Add Flag status register polling support

Hi Simon,

Quoted 37 lines · Simon Glass

Hi Jagan,

Quoted 33 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 v3:
- define the flag status code on CONFIG_SPI_FLASH_STMICRO
Changes for v2:
- none

 drivers/mtd/spi/spi_flash.c          | 16 +++++++++++++---
 drivers/mtd/spi/spi_flash_internal.h |  2 ++
 2 files changed, 15 insertions(+), 3 deletions(-)
(quoted diff) +0 -0

b/drivers/mtd/spi/spi_flash.c index bb37f54..4f97fab0 100644

drivers/mtd/spi/spi_flash.c +1 -0
@@ -200,12 +200,22 @@ 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;
 
Quoted 13 lines

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

Quoted 8 lines
drivers/mtd/spi/spi_flash.c +8 -0
+#ifdef CONFIG_SPI_FLASH_STMICRO
+       if (flash->size >= 0x4000000) {
+               poll_bit = STATUS_PEC;
+               check_status = poll_bit;
+               cmd = CMD_FLAG_STATUS;
+       }
+#endif
+

Similarly to the bank addressing I think this might be better done as a 'poll method' rather than a hack for a particular flash type.

Quoted 4 lines

You mean to say read_status cmd and flag_status cmd need to find it on probe it self.?
Can you please explain "better done as a 'poll method' '

What I mean is that spi_flash_cmd_wait_ready() is in generic code.

CONFIG_SPI_FLASH_STMICRO means that U-Boot will support that flash, but it does not mean that it is the only flash. You have added a device-specific thing into generic code. If someone compiles a U-Boot with ST and Winbond flash, then both types of flash will use the code you added (the ST code above).

Quoted 4 lines
Quoted 3 lines

Also I worry that in a system with more than one type of flash, this code will fire for all flash types.

Quoted 8 lines

Even if the system has multiple flashes of different size, we can probe once at a time, right?

--
Thanks,
Jagan.

Regards,
Simon

#39 lore raw

PATCH v3 17/17 sf: Add Flag status register polling support

Hi Simon,

Quoted 83 lines · Simon Glass

Hi Jagan,

Quoted 74 lines · Max

Hi Jagan, Simon - Adding Bacem and Gernot from Spansion. Would you be able to add them to the other open threads as well? --Max

-------------------------------------------------
Max Willis, PhD
Division Marketing Manager
Software Marketing
Spansion Inc.
-------------------------------------------------

-----Original Message-----
From: Jagan Teki [mailto:jagannadh.teki at gmail.com]
Sent: Wednesday, June 12, 2013 10:32 PM
To: Simon Glass
Cc: Jagannadha Sutradharudu Teki; U-Boot Mailing List; Michal Simek; Tom Rini; Rajeshwari Shinde; Syed Hussain; Willis, Max; Todd Legler (tlegler); Jagannadha Sutradharudu Teki
Subject: Re: [PATCH v3 17/17] sf: Add Flag status register polling support

Hi Simon,

Quoted 37 lines · Simon Glass

Hi Jagan,

Quoted 33 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 v3:
- define the flag status code on CONFIG_SPI_FLASH_STMICRO
Changes for v2:
- none

 drivers/mtd/spi/spi_flash.c          | 16 +++++++++++++---
 drivers/mtd/spi/spi_flash_internal.h |  2 ++
 2 files changed, 15 insertions(+), 3 deletions(-)
(quoted diff) +0 -0

b/drivers/mtd/spi/spi_flash.c index bb37f54..4f97fab0 100644

drivers/mtd/spi/spi_flash.c +1 -0
@@ -200,12 +200,22 @@ 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;
 
Quoted 13 lines

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

Quoted 8 lines
drivers/mtd/spi/spi_flash.c +8 -0
+#ifdef CONFIG_SPI_FLASH_STMICRO
+       if (flash->size >= 0x4000000) {
+               poll_bit = STATUS_PEC;
+               check_status = poll_bit;
+               cmd = CMD_FLAG_STATUS;
+       }
+#endif
+

Similarly to the bank addressing I think this might be better done as a 'poll method' rather than a hack for a particular flash type.

Quoted 3 lines

You mean to say read_status cmd and flag_status cmd need to find it on probe it self.?
Can you please explain "better done as a 'poll method' '

Quoted 7 lines

What I mean is that spi_flash_cmd_wait_ready() is in generic code.

CONFIG_SPI_FLASH_STMICRO means that U-Boot will support that flash, but it does not mean that it is the only flash. You have added a device-specific thing into generic code. If someone compiles a U-Boot with ST and Winbond flash, then both types of flash will use the code you added (the ST code above).

Understand.

Yes, initially i did this in runtime manner like

        if ((flash->idcode0 == 0x20) &&
			(flash->size >= 0x4000000)) {
		poll_bit = STATUS_PEC;
		check_status = poll_bit;
		cmd = CMD_FLAG_STATUS;
	}

I think even if we assign the read_status and flasg_status at probe time the poll_bit and
check_status are different in these read and flag status reg'.

Any comments.

--
Thanks,
Jagan.