Skip to contentSkip to conversation

cmd_sf: Add print messages on flash erase command

PATCH New Jagannadha Sutradharudu Teki 3 participants 20 messages Dec 19, 2012 – Feb 1, 2013 Memory technology devices (MTD)

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/6 cmd_sf: Add print messages on flash erase command

This patch adds a print messages while using 'sf erase' command to make sure that how many bytes erased in flash device.

---
Changes in v2:
Move print messages from spi_flash.c into cmd_sf.c

 common/cmd_sf.c             |   11 ++++++-----
 drivers/mtd/spi/spi_flash.c |    2 --
 2 files changed, 6 insertions(+), 7 deletions(-)
common/cmd_sf.c +6 -5
index 5ac1d0c..ddb1a65 100644
@@ -266,13 +266,14 @@ static int do_spi_flash_erase(int argc, char * const argv[])
 		return 1;
 	}
 
+	printf("SF: Erasing flash... ");
+
 	ret = spi_flash_erase(flash, offset, len);
-	if (ret) {
-		printf("SPI flash %s failed\n", argv[0]);
-		return 1;
-	}
 
-	return 0;
+	printf("%zu bytes @ %#x erased: %s\n", (size_t)len, (u32)offset,
+			ret ? "ERROR" : "OK");
+
+	return ret == 0 ? 0 : 1;
 }
 
 static int do_spi_flash(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
drivers/mtd/spi/spi_flash.c +0 -2
index 00aece9..43e0334 100644
@@ -235,8 +235,6 @@ int spi_flash_cmd_erase(struct spi_flash *flash, u32 offset, size_t len)
 			goto out;
 	}
 
-	debug("SF: Successfully erased %zu bytes @ %#x\n", len, start);
-
  out:
 	spi_release_bus(flash->spi);
 	return ret;
Signature · 1 line
1.7.0.4
#1 lore raw

PATCH v2 2/6 cmd_sf: Add print messages on flash read/write commands

This patch adds a print messages while using 'sf read' and 'sf write' commands to make sure that how many bytes read/written from/into flash device.

---
Changes in v2:
Move print messages from spi_flash.c into cmd_sf.c

 common/cmd_sf.c             |   26 ++++++++++++++++----------
 drivers/mtd/spi/spi_flash.c |    3 ---
 2 files changed, 16 insertions(+), 13 deletions(-)
common/cmd_sf.c +16 -10
index ddb1a65..efdd640 100644
@@ -196,7 +196,7 @@ static int do_spi_flash_read_write(int argc, char * const argv[])
 	unsigned long len;
 	void *buf;
 	char *endp;
-	int ret;
+	int ret = 0;
 
 	if (argc < 4)
 		return -1;
@@ -226,19 +226,25 @@ static int do_spi_flash_read_write(int argc, char * const argv[])
 
 	if (strcmp(argv[0], "update") == 0)
 		ret = spi_flash_update(flash, offset, len, buf);
-	else if (strcmp(argv[0], "read") == 0)
-		ret = spi_flash_read(flash, offset, len, buf);
-	else
-		ret = spi_flash_write(flash, offset, len, buf);
+	else if (strncmp(argv[0], "read", 4) == 0 ||
+			strncmp(argv[0], "write", 5) == 0) {
+		int read;
 
-	unmap_physmem(buf, len);
+		read = strncmp(argv[0], "read", 4) == 0;
+		printf("SF: %s flash... ", read ? "Reading" : "Writing");
 
-	if (ret) {
-		printf("SPI flash %s failed\n", argv[0]);
-		return 1;
+		if (read)
+			ret = spi_flash_read(flash, offset, len, buf);
+		else
+			ret = spi_flash_write(flash, offset, len, buf);
+
+		printf("%zu bytes @ %#x %s: %s\n", (size_t)len, (u32)offset,
+			read ? "read" : "written", ret ? "ERROR" : "OK");
 	}
 
-	return 0;
+	unmap_physmem(buf, len);
+
+	return ret == 0 ? 0 : 1;
 }
 
 static int do_spi_flash_erase(int argc, char * const argv[])
drivers/mtd/spi/spi_flash.c +0 -3
index 43e0334..9e8939c 100644
@@ -115,9 +115,6 @@ int spi_flash_cmd_write_multi(struct spi_flash *flash, u32 offset,
 		byte_addr = 0;
 	}
 
-	debug("SF: program %s %zu bytes @ %#x\n",
-	      ret ? "failure" : "success", len, offset);
-
 	spi_release_bus(flash->spi);
 	return ret;
 }
Signature · 1 line
1.7.0.4
#2 lore raw

PATCH v2 2/6 cmd_sf: Add print messages on flash read/write commands

Dear Jagannadha Sutradharudu Teki,

Quoted 8 lines · In message <[email protected]> you…

This patch adds a print messages while using 'sf read' and 'sf write' commands to make sure that how many bytes read/written from/into flash device.

---
Changes in v2:
Move print messages from spi_flash.c into cmd_sf.c

Please see previous comments, especially

http://article.gmane.org/gmane.comp.boot-loaders.u-boot/149663
http://article.gmane.org/gmane.comp.boot-loaders.u-boot/149665

I object against adding more and more verbosity and code size, and in an inconsistent way.

Best regards,

Wolfgang Denk

Signature · 4 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
F u cn rd ths u cnt spl wrth a dm!
author
#3 lore raw

PATCH v2 2/6 cmd_sf: Add print messages on flash read/write commands

Hi Wolfgang Denk,

Quoted 12 lines · Wolfgang Denk

Dear Jagannadha Sutradharudu Teki,

Quoted 8 lines · In message <[email protected]> you…

This patch adds a print messages while using 'sf read' and 'sf write' commands to make sure that how many bytes read/written from/into flash device.

---
Changes in v2:
Move print messages from spi_flash.c into cmd_sf.c

Quoted 7 lines

Please see previous comments, especially

http://article.gmane.org/gmane.comp.boot-loaders.u-boot/149663
http://article.gmane.org/gmane.comp.boot-loaders.u-boot/149665

I object against adding more and more verbosity and code size, and in an inconsistent way.

Please see my comments on previous patch.
http://article.gmane.org/gmane.comp.boot-loaders.u-boot/149698

Thanks,
Jagan.

Quoted 10 lines

Best regards,

Wolfgang Denk

--
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de F u cn rd ths u cnt spl wrth a dm!

#4 lore raw

PATCH v2 3/6 sf: Add status register reading support

In reply to Jagannadha Sutradharudu Teki

This patch provides support to read a flash status register.

Status register contains a control bits used to verify the progress of flash program and erase operations.

User need to get the data through spi_flash_cmd_read_status() based on their usage.

---
Changes in v2:none

 drivers/mtd/spi/spi_flash.c          |   15 +++++++++++++++
 drivers/mtd/spi/spi_flash_internal.h |    3 +++
 2 files changed, 18 insertions(+), 0 deletions(-)
drivers/mtd/spi/spi_flash.c +15 -0
index 9e8939c..bf5ec4a 100644
@@ -264,6 +264,21 @@ int spi_flash_cmd_write_status(struct spi_flash *flash, u8 sr)
 	return 0;
 }
 
+int spi_flash_cmd_read_status(struct spi_flash *flash, void *data)
+{
+	u8 cmd;
+	int ret;
+
+	cmd = CMD_READ_STATUS;
+	ret = spi_flash_read_common(flash, &cmd, sizeof(cmd), (void *)data, 1);
+	if (ret < 0) {
+		debug("SF: fail to read status register\n");
+		return ret;
+	}
+
+	return 0;
+}
+
 /*
  * The following table holds all device probe functions
  *
drivers/mtd/spi/spi_flash_internal.h +3 -0
index 141cfa8..8232595 100644
@@ -77,6 +77,9 @@ static inline int spi_flash_cmd_write_disable(struct spi_flash *flash)
 /* Program the status register. */
 int spi_flash_cmd_write_status(struct spi_flash *flash, u8 sr);
 
+/* Read the status register */
+int spi_flash_cmd_read_status(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.7.0.4
author
#5 lore raw

PATCH v2 3/6 sf: Add status register reading support

Tested on real hardware, works fine.

Thanks,
Jagan.

Quoted 59 lines · Jagannadha Sutradharudu Teki

This patch provides support to read a flash status register.

Status register contains a control bits used to verify the progress of flash program and erase operations.

User need to get the data through spi_flash_cmd_read_status() based on their usage.

---
Changes in v2:none

 drivers/mtd/spi/spi_flash.c          |   15 +++++++++++++++
 drivers/mtd/spi/spi_flash_internal.h |    3 +++
 2 files changed, 18 insertions(+), 0 deletions(-)
drivers/mtd/spi/spi_flash.c +15 -0
index 9e8939c..bf5ec4a 100644
@@ -264,6 +264,21 @@ int spi_flash_cmd_write_status(struct spi_flash *flash, u8 sr)
        return 0;
 }
 
+int spi_flash_cmd_read_status(struct spi_flash *flash, void *data)
+{
+       u8 cmd;
+       int ret;
+
+       cmd = CMD_READ_STATUS;
+       ret = spi_flash_read_common(flash, &cmd, sizeof(cmd), (void *)data, 1);
+       if (ret < 0) {
+               debug("SF: fail to read status register\n");
+               return ret;
+       }
+
+       return 0;
+}
+
 /*
  * The following table holds all device probe functions
  *
drivers/mtd/spi/spi_flash_internal.h +3 -1
index 141cfa8..8232595 100644
@@ -77,6 +77,9 @@ static inline int spi_flash_cmd_write_disable(struct spi_flash *flash)
 /* Program the status register. */
 int spi_flash_cmd_write_status(struct spi_flash *flash, u8 sr);
 
+/* Read the status register */
+int spi_flash_cmd_read_status(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.7.0.4

#6 lore raw

PATCH v2 4/6 sf: Add configuration register writing support

In reply to Jagannadha Sutradharudu Teki

This patch provides support to program a flash config register.

Configuration register contains the control bits used to configure the different configurations and security features of a device.

User need to set these bits through spi_flash_cmd_write_config() based on their usage.

---
Changes in v2:
Improved code logic

 drivers/mtd/spi/spi_flash.c          |   35 ++++++++++++++++++++++++++++++++++
 drivers/mtd/spi/spi_flash_internal.h |    3 ++
 2 files changed, 38 insertions(+), 0 deletions(-)
drivers/mtd/spi/spi_flash.c +35 -0
index bf5ec4a..cad6c40 100644
@@ -279,6 +279,41 @@ int spi_flash_cmd_read_status(struct spi_flash *flash, void *data)
 	return 0;
 }
 
+int spi_flash_cmd_write_config(struct spi_flash *flash, u8 cr)
+{
+	u8 data[2];
+	u8 cmd;
+	int ret;
+
+	ret = spi_flash_cmd_read_status(flash, (void *)&data[0]);
+	if (ret < 0) {
+		debug("SF: fail to read status register\n");
+		return ret;
+	}
+
+	ret = spi_flash_cmd_write_enable(flash);
+	if (ret < 0) {
+		debug("SF: enabling write failed\n");
+		return ret;
+	}
+
+	cmd = CMD_WRITE_STATUS;
+	data[1] = cr;
+	ret = spi_flash_cmd_write(flash->spi, &cmd, 1, &data, 2);
+	if (ret) {
+		debug("SF: fail to write config register\n");
+		return ret;
+	}
+
+	ret = spi_flash_cmd_wait_ready(flash, SPI_FLASH_PROG_TIMEOUT);
+	if (ret < 0) {
+		debug("SF: write config register timed out\n");
+		return ret;
+	}
+
+	return 0;
+}
+
 /*
  * The following table holds all device probe functions
  *
drivers/mtd/spi/spi_flash_internal.h +3 -0
index 8232595..825b398 100644
@@ -80,6 +80,9 @@ int spi_flash_cmd_write_status(struct spi_flash *flash, u8 sr);
 /* Read the status register */
 int spi_flash_cmd_read_status(struct spi_flash *flash, void *data);
 
+/* Program the config register. */
+int spi_flash_cmd_write_config(struct spi_flash *flash, u8 cr);
+
 /*
  * 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.7.0.4
author
#7 lore raw

PATCH v2 4/6 sf: Add configuration register writing support

Tested on real hardware, works fine.

Thanks,
Jagan.

Quoted 80 lines · Jagannadha Sutradharudu Teki

This patch provides support to program a flash config register.

Configuration register contains the control bits used to configure the different configurations and security features of a device.

User need to set these bits through spi_flash_cmd_write_config() based on their usage.

---
Changes in v2:
Improved code logic

 drivers/mtd/spi/spi_flash.c          |   35 ++++++++++++++++++++++++++++++++++
 drivers/mtd/spi/spi_flash_internal.h |    3 ++
 2 files changed, 38 insertions(+), 0 deletions(-)
drivers/mtd/spi/spi_flash.c +35 -0
index bf5ec4a..cad6c40 100644
@@ -279,6 +279,41 @@ int spi_flash_cmd_read_status(struct spi_flash *flash, void *data)
        return 0;
 }
 
+int spi_flash_cmd_write_config(struct spi_flash *flash, u8 cr)
+{
+       u8 data[2];
+       u8 cmd;
+       int ret;
+
+       ret = spi_flash_cmd_read_status(flash, (void *)&data[0]);
+       if (ret < 0) {
+               debug("SF: fail to read status register\n");
+               return ret;
+       }
+
+       ret = spi_flash_cmd_write_enable(flash);
+       if (ret < 0) {
+               debug("SF: enabling write failed\n");
+               return ret;
+       }
+
+       cmd = CMD_WRITE_STATUS;
+       data[1] = cr;
+       ret = spi_flash_cmd_write(flash->spi, &cmd, 1, &data, 2);
+       if (ret) {
+               debug("SF: fail to write config register\n");
+               return ret;
+       }
+
+       ret = spi_flash_cmd_wait_ready(flash, SPI_FLASH_PROG_TIMEOUT);
+       if (ret < 0) {
+               debug("SF: write config register timed out\n");
+               return ret;
+       }
+
+       return 0;
+}
+
 /*
  * The following table holds all device probe functions
  *
drivers/mtd/spi/spi_flash_internal.h +3 -1
index 8232595..825b398 100644
@@ -80,6 +80,9 @@ int spi_flash_cmd_write_status(struct spi_flash *flash, u8 sr);
 /* Read the status register */
 int spi_flash_cmd_read_status(struct spi_flash *flash, void *data);
 
+/* Program the config register. */
+int spi_flash_cmd_write_config(struct spi_flash *flash, u8 cr);
+
 /*
  * Same as spi_flash_cmd_read() except it also claims/releases the SPI
  * bus. Used as common part of the ->read() operation.
--

1.7.0.4

#8 lore raw

PATCH v2 5/6 sf: Add config register reading support

In reply to Jagannadha Sutradharudu Teki

This patch provides support to read a flash config register.

Config register contains a control bits used to verify the different configurations and security features of a device.

User need to get the data through spi_flash_cmd_read_config() based on their usage.

---
Changes in v2: none

 drivers/mtd/spi/spi_flash.c          |   15 +++++++++++++++
 drivers/mtd/spi/spi_flash_internal.h |    4 ++++
 2 files changed, 19 insertions(+), 0 deletions(-)
drivers/mtd/spi/spi_flash.c +15 -0
index cad6c40..5bddde4 100644
@@ -314,6 +314,21 @@ int spi_flash_cmd_write_config(struct spi_flash *flash, u8 cr)
 	return 0;
 }
 
+int spi_flash_cmd_read_config(struct spi_flash *flash, void *data)
+{
+	u8 cmd;
+	int ret;
+
+	cmd = CMD_READ_CONFIG;
+	ret = spi_flash_read_common(flash, &cmd, sizeof(cmd), (void *)data, 1);
+	if (ret < 0) {
+		debug("SF: fail to read config register\n");
+		return ret;
+	}
+
+	return 0;
+}
+
 /*
  * The following table holds all device probe functions
  *
drivers/mtd/spi/spi_flash_internal.h +4 -0
index 825b398..844e82e 100644
@@ -22,6 +22,7 @@
 #define CMD_PAGE_PROGRAM		0x02
 #define CMD_WRITE_DISABLE		0x04
 #define CMD_READ_STATUS			0x05
+#define CMD_READ_CONFIG			0x35
 #define CMD_WRITE_ENABLE		0x06
 #define CMD_ERASE_4K			0x20
 #define CMD_ERASE_32K			0x52
@@ -83,6 +84,9 @@ int spi_flash_cmd_read_status(struct spi_flash *flash, void *data);
 /* Program the config register. */
 int spi_flash_cmd_write_config(struct spi_flash *flash, u8 cr);
 
+/* Read the config register */
+int spi_flash_cmd_read_config(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.7.0.4
author
#9 lore raw

PATCH v2 5/6 sf: Add config register reading support

Tested on real hardware, works fine.

Thanks,
Jagan.

Quoted 67 lines · Jagannadha Sutradharudu Teki

This patch provides support to read a flash config register.

Config register contains a control bits used to verify the different configurations and security features of a device.

User need to get the data through spi_flash_cmd_read_config() based on their usage.

---
Changes in v2: none

 drivers/mtd/spi/spi_flash.c          |   15 +++++++++++++++
 drivers/mtd/spi/spi_flash_internal.h |    4 ++++
 2 files changed, 19 insertions(+), 0 deletions(-)
drivers/mtd/spi/spi_flash.c +15 -0
index cad6c40..5bddde4 100644
@@ -314,6 +314,21 @@ int spi_flash_cmd_write_config(struct spi_flash *flash, u8 cr)
        return 0;
 }
 
+int spi_flash_cmd_read_config(struct spi_flash *flash, void *data)
+{
+       u8 cmd;
+       int ret;
+
+       cmd = CMD_READ_CONFIG;
+       ret = spi_flash_read_common(flash, &cmd, sizeof(cmd), (void *)data, 1);
+       if (ret < 0) {
+               debug("SF: fail to read config register\n");
+               return ret;
+       }
+
+       return 0;
+}
+
 /*
  * The following table holds all device probe functions
  *
drivers/mtd/spi/spi_flash_internal.h +4 -1
index 825b398..844e82e 100644
@@ -22,6 +22,7 @@
 #define CMD_PAGE_PROGRAM               0x02
 #define CMD_WRITE_DISABLE              0x04
 #define CMD_READ_STATUS                        0x05
+#define CMD_READ_CONFIG                        0x35
 #define CMD_WRITE_ENABLE               0x06
 #define CMD_ERASE_4K                   0x20
 #define CMD_ERASE_32K                  0x52
@@ -83,6 +84,9 @@ int spi_flash_cmd_read_status(struct spi_flash *flash, void *data);
 /* Program the config register. */
 int spi_flash_cmd_write_config(struct spi_flash *flash, u8 cr);
 
+/* Read the config register */
+int spi_flash_cmd_read_config(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.7.0.4

#10 lore raw

PATCH v2 6/6 sf: Set QUAD enable bit support

In reply to Jagannadha Sutradharudu Teki

This patch provides support to set the QUAD enable bit on flash.

QUAD enable bit needs to set before performing any QUAD IO operations on respective SPI flashes.

User need to use spi_flash_set_quad_enable_bit() to set the QUAD enable bit based on their usage.

---
Changes in v2:
Improved code logic

 drivers/mtd/spi/spi_flash.c          |   31 +++++++++++++++++++++++++++++++
 drivers/mtd/spi/spi_flash_internal.h |    4 ++++
 2 files changed, 35 insertions(+), 0 deletions(-)
drivers/mtd/spi/spi_flash.c +31 -0
index 5bddde4..675a0bf 100644
@@ -329,6 +329,37 @@ int spi_flash_cmd_read_config(struct spi_flash *flash, void *data)
 	return 0;
 }
 
+int spi_flash_set_quad_enable_bit(struct spi_flash *flash)
+{
+	u8 data = 0, write_done = 0;
+	int ret, pass;
+
+	for (pass = 0; pass < 2; pass++) {
+		ret = spi_flash_cmd_read_config(flash, (void *)&data);
+		if (ret < 0) {
+			debug("SF: fail to read config register\n");
+			return ret;
+		}
+
+		if (data & STATUS_QEB) {
+			debug("SF: quad enable bit is set.\n");
+			return ret;
+		} else if (write_done != 1) {
+			debug("SF: need to set quad enable bit\n");
+
+			write_done = 1;
+			ret = spi_flash_cmd_write_config(flash, STATUS_QEB);
+			if (ret < 0) {
+				debug("SF: fail to write quad enable bit\n");
+				return ret;
+			}
+		}
+	}
+
+	debug("SF: fail to set quad enable bit\n");
+	return -1;
+}
+
 /*
  * The following table holds all device probe functions
  *
drivers/mtd/spi/spi_flash_internal.h +4 -0
index 844e82e..15c7ac4 100644
@@ -31,6 +31,7 @@
 
 /* Common status */
 #define STATUS_WIP			0x01
+#define STATUS_QEB			0x02
 
 /* 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);
@@ -87,6 +88,9 @@ int spi_flash_cmd_write_config(struct spi_flash *flash, u8 cr);
 /* Read the config register */
 int spi_flash_cmd_read_config(struct spi_flash *flash, void *data);
 
+/* Set the QUAD enable bit */
+int spi_flash_set_quad_enable_bit(struct spi_flash *flash);
+
 /*
  * 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.7.0.4
author
#11 lore raw

PATCH v2 6/6 sf: Set QUAD enable bit support

Tested on real hardware, works fine.

Thanks,
Jagan.

Quoted 84 lines · Jagannadha Sutradharudu Teki

This patch provides support to set the QUAD enable bit on flash.

QUAD enable bit needs to set before performing any QUAD IO operations on respective SPI flashes.

User need to use spi_flash_set_quad_enable_bit() to set the QUAD enable bit based on their usage.

---
Changes in v2:
Improved code logic

 drivers/mtd/spi/spi_flash.c          |   31 +++++++++++++++++++++++++++++++
 drivers/mtd/spi/spi_flash_internal.h |    4 ++++
 2 files changed, 35 insertions(+), 0 deletions(-)
drivers/mtd/spi/spi_flash.c +31 -0
index 5bddde4..675a0bf 100644
@@ -329,6 +329,37 @@ int spi_flash_cmd_read_config(struct spi_flash *flash, void *data)
        return 0;
 }
 
+int spi_flash_set_quad_enable_bit(struct spi_flash *flash)
+{
+       u8 data = 0, write_done = 0;
+       int ret, pass;
+
+       for (pass = 0; pass < 2; pass++) {
+               ret = spi_flash_cmd_read_config(flash, (void *)&data);
+               if (ret < 0) {
+                       debug("SF: fail to read config register\n");
+                       return ret;
+               }
+
+               if (data & STATUS_QEB) {
+                       debug("SF: quad enable bit is set.\n");
+                       return ret;
+               } else if (write_done != 1) {
+                       debug("SF: need to set quad enable bit\n");
+
+                       write_done = 1;
+                       ret = spi_flash_cmd_write_config(flash, STATUS_QEB);
+                       if (ret < 0) {
+                               debug("SF: fail to write quad enable bit\n");
+                               return ret;
+                       }
+               }
+       }
+
+       debug("SF: fail to set quad enable bit\n");
+       return -1;
+}
+
 /*
  * The following table holds all device probe functions
  *
drivers/mtd/spi/spi_flash_internal.h +4 -1
index 844e82e..15c7ac4 100644
@@ -31,6 +31,7 @@
 
 /* Common status */
 #define STATUS_WIP                     0x01
+#define STATUS_QEB                     0x02
 
 /* 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);
@@ -87,6 +88,9 @@ int spi_flash_cmd_write_config(struct spi_flash *flash, u8 cr);
 /* Read the config register */
 int spi_flash_cmd_read_config(struct spi_flash *flash, void *data);
 
+/* Set the QUAD enable bit */
+int spi_flash_set_quad_enable_bit(struct spi_flash *flash);
+
 /*
  * Same as spi_flash_cmd_read() except it also claims/releases the SPI
  * bus. Used as common part of the ->read() operation.
--

1.7.0.4

author
#12 lore raw

PATCH v2 6/6 sf: Set QUAD enable bit support

Hi Mike/Simon,

Any further comments on this.

I have tested on real h/w target as well.

Thanks,
Jagan.

Quoted 93 lines · Jagan Teki

Tested on real hardware, works fine.

Thanks,
Jagan.

Quoted 84 lines · Jagannadha Sutradharudu Teki

This patch provides support to set the QUAD enable bit on flash.

QUAD enable bit needs to set before performing any QUAD IO operations on respective SPI flashes.

User need to use spi_flash_set_quad_enable_bit() to set the QUAD enable bit based on their usage.

---
Changes in v2:
Improved code logic

 drivers/mtd/spi/spi_flash.c          |   31 +++++++++++++++++++++++++++++++
 drivers/mtd/spi/spi_flash_internal.h |    4 ++++
 2 files changed, 35 insertions(+), 0 deletions(-)
drivers/mtd/spi/spi_flash.c +31 -0
index 5bddde4..675a0bf 100644
@@ -329,6 +329,37 @@ int spi_flash_cmd_read_config(struct spi_flash *flash, void *data)
        return 0;
 }
 
+int spi_flash_set_quad_enable_bit(struct spi_flash *flash)
+{
+       u8 data = 0, write_done = 0;
+       int ret, pass;
+
+       for (pass = 0; pass < 2; pass++) {
+               ret = spi_flash_cmd_read_config(flash, (void *)&data);
+               if (ret < 0) {
+                       debug("SF: fail to read config register\n");
+                       return ret;
+               }
+
+               if (data & STATUS_QEB) {
+                       debug("SF: quad enable bit is set.\n");
+                       return ret;
+               } else if (write_done != 1) {
+                       debug("SF: need to set quad enable bit\n");
+
+                       write_done = 1;
+                       ret = spi_flash_cmd_write_config(flash, STATUS_QEB);
+                       if (ret < 0) {
+                               debug("SF: fail to write quad enable bit\n");
+                               return ret;
+                       }
+               }
+       }
+
+       debug("SF: fail to set quad enable bit\n");
+       return -1;
+}
+
 /*
  * The following table holds all device probe functions
  *
drivers/mtd/spi/spi_flash_internal.h +4 -1
index 844e82e..15c7ac4 100644
@@ -31,6 +31,7 @@
 
 /* Common status */
 #define STATUS_WIP                     0x01
+#define STATUS_QEB                     0x02
 
 /* 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);
@@ -87,6 +88,9 @@ int spi_flash_cmd_write_config(struct spi_flash *flash, u8 cr);
 /* Read the config register */
 int spi_flash_cmd_read_config(struct spi_flash *flash, void *data);
 
+/* Set the QUAD enable bit */
+int spi_flash_set_quad_enable_bit(struct spi_flash *flash);
+
 /*
  * Same as spi_flash_cmd_read() except it also claims/releases the SPI
  * bus. Used as common part of the ->read() operation.
--

1.7.0.4

#13 lore raw

PATCH v2 6/6 sf: Set QUAD enable bit support

Hi,

Quoted 3 lines · Jagan Teki

Hi Mike/Simon,

Any further comments on this.

No further comment. It looks OK to me.

For all the other patches, it might be worth putting them in a single series and sending them again once comments are addressed.

Regards,
Simon

Quoted 100 lines

I have tested on real h/w target as well.

Thanks,
Jagan.

Quoted 93 lines · Jagan Teki

Tested on real hardware, works fine.

Thanks,
Jagan.

Quoted 84 lines · Jagannadha Sutradharudu Teki

This patch provides support to set the QUAD enable bit on flash.

QUAD enable bit needs to set before performing any QUAD IO operations on respective SPI flashes.

User need to use spi_flash_set_quad_enable_bit() to set the QUAD enable bit based on their usage.

---
Changes in v2:
Improved code logic

 drivers/mtd/spi/spi_flash.c          |   31 +++++++++++++++++++++++++++++++
 drivers/mtd/spi/spi_flash_internal.h |    4 ++++
 2 files changed, 35 insertions(+), 0 deletions(-)
drivers/mtd/spi/spi_flash.c +31 -0
index 5bddde4..675a0bf 100644
@@ -329,6 +329,37 @@ int spi_flash_cmd_read_config(struct spi_flash *flash, void *data)
        return 0;
 }
 
+int spi_flash_set_quad_enable_bit(struct spi_flash *flash)
+{
+       u8 data = 0, write_done = 0;
+       int ret, pass;
+
+       for (pass = 0; pass < 2; pass++) {
+               ret = spi_flash_cmd_read_config(flash, (void *)&data);
+               if (ret < 0) {
+                       debug("SF: fail to read config register\n");
+                       return ret;
+               }
+
+               if (data & STATUS_QEB) {
+                       debug("SF: quad enable bit is set.\n");
+                       return ret;
+               } else if (write_done != 1) {
+                       debug("SF: need to set quad enable bit\n");
+
+                       write_done = 1;
+                       ret = spi_flash_cmd_write_config(flash, STATUS_QEB);
+                       if (ret < 0) {
+                               debug("SF: fail to write quad enable bit\n");
+                               return ret;
+                       }
+               }
+       }
+
+       debug("SF: fail to set quad enable bit\n");
+       return -1;
+}
+
 /*
  * The following table holds all device probe functions
  *
drivers/mtd/spi/spi_flash_internal.h +4 -1
index 844e82e..15c7ac4 100644
@@ -31,6 +31,7 @@
 
 /* Common status */
 #define STATUS_WIP                     0x01
+#define STATUS_QEB                     0x02
 
 /* 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);
@@ -87,6 +88,9 @@ int spi_flash_cmd_write_config(struct spi_flash *flash, u8 cr);
 /* Read the config register */
 int spi_flash_cmd_read_config(struct spi_flash *flash, void *data);
 
+/* Set the QUAD enable bit */
+int spi_flash_set_quad_enable_bit(struct spi_flash *flash);
+
 /*
  * Same as spi_flash_cmd_read() except it also claims/releases the SPI
  * bus. Used as common part of the ->read() operation.
--

1.7.0.4

author
#14 lore raw

PATCH v2 6/6 sf: Set QUAD enable bit support

Hi Simon,

Quoted 11 lines · Simon Glass

Hi,

Quoted 3 lines · Jagan Teki

Hi Mike/Simon,

Any further comments on this.

No further comment. It looks OK to me.

For all the other patches, it might be worth putting them in a single series and sending them again once comments are addressed.

Thanks for your quick response.

I will pack all the patches in one series and send.

Thanks,
Jagan.

Quoted 106 lines

Regards,
Simon

Quoted 100 lines

I have tested on real h/w target as well.

Thanks,
Jagan.

Quoted 93 lines · Jagan Teki

Tested on real hardware, works fine.

Thanks,
Jagan.

Quoted 84 lines · Jagannadha Sutradharudu Teki

This patch provides support to set the QUAD enable bit on flash.

QUAD enable bit needs to set before performing any QUAD IO operations on respective SPI flashes.

User need to use spi_flash_set_quad_enable_bit() to set the QUAD enable bit based on their usage.

---
Changes in v2:
Improved code logic

 drivers/mtd/spi/spi_flash.c          |   31 +++++++++++++++++++++++++++++++
 drivers/mtd/spi/spi_flash_internal.h |    4 ++++
 2 files changed, 35 insertions(+), 0 deletions(-)
drivers/mtd/spi/spi_flash.c +31 -0
index 5bddde4..675a0bf 100644
@@ -329,6 +329,37 @@ int spi_flash_cmd_read_config(struct spi_flash *flash, void *data)
        return 0;
 }
 
+int spi_flash_set_quad_enable_bit(struct spi_flash *flash)
+{
+       u8 data = 0, write_done = 0;
+       int ret, pass;
+
+       for (pass = 0; pass < 2; pass++) {
+               ret = spi_flash_cmd_read_config(flash, (void *)&data);
+               if (ret < 0) {
+                       debug("SF: fail to read config register\n");
+                       return ret;
+               }
+
+               if (data & STATUS_QEB) {
+                       debug("SF: quad enable bit is set.\n");
+                       return ret;
+               } else if (write_done != 1) {
+                       debug("SF: need to set quad enable bit\n");
+
+                       write_done = 1;
+                       ret = spi_flash_cmd_write_config(flash, STATUS_QEB);
+                       if (ret < 0) {
+                               debug("SF: fail to write quad enable bit\n");
+                               return ret;
+                       }
+               }
+       }
+
+       debug("SF: fail to set quad enable bit\n");
+       return -1;
+}
+
 /*
  * The following table holds all device probe functions
  *
drivers/mtd/spi/spi_flash_internal.h +4 -1
index 844e82e..15c7ac4 100644
@@ -31,6 +31,7 @@
 
 /* Common status */
 #define STATUS_WIP                     0x01
+#define STATUS_QEB                     0x02
 
 /* 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);
@@ -87,6 +88,9 @@ int spi_flash_cmd_write_config(struct spi_flash *flash, u8 cr);
 /* Read the config register */
 int spi_flash_cmd_read_config(struct spi_flash *flash, void *data);
 
+/* Set the QUAD enable bit */
+int spi_flash_set_quad_enable_bit(struct spi_flash *flash);
+
 /*
  * Same as spi_flash_cmd_read() except it also claims/releases the SPI
  * bus. Used as common part of the ->read() operation.
--

1.7.0.4

#15 lore raw

PATCH v2 1/6 cmd_sf: Add print messages on flash erase command

In reply to Jagannadha Sutradharudu Teki

Dear Jagannadha Sutradharudu Teki,

Quoted 7 lines · In message <[email protected]> you…

This patch adds a print messages while using 'sf erase' command to make sure that how many bytes erased in flash device.

---
Changes in v2:
Move print messages from spi_flash.c into cmd_sf.c

This makes little sense to me. Please see all comments here:

http://article.gmane.org/gmane.comp.boot-loaders.u-boot/149663

and here:

http://article.gmane.org/gmane.comp.boot-loaders.u-boot/149665

Best regards,

Wolfgang Denk

Signature · 6 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Programmer's Lament: (Shakespeare, Macbeth, Act I, Scene vii)
        "That we but teach bloody instructions,
        which, being taught, return to plague the inventor..."
author
#16 lore raw

PATCH v2 1/6 cmd_sf: Add print messages on flash erase command

Hi Wolfgang Denk,

Quoted 11 lines · Wolfgang Denk

Dear Jagannadha Sutradharudu Teki,

Quoted 7 lines · In message <[email protected]> you…

This patch adds a print messages while using 'sf erase' command to make sure that how many bytes erased in flash device.

---
Changes in v2:
Move print messages from spi_flash.c into cmd_sf.c

Quoted 7 lines

This makes little sense to me. Please see all comments here:

http://article.gmane.org/gmane.comp.boot-loaders.u-boot/149663

and here:

http://article.gmane.org/gmane.comp.boot-loaders.u-boot/149665

I thought these are useful verbose prints for sf read/write/erase commands as there is no verbose support before.

Like NOR, NAND and SD have some verbose prints while executing respective commands
This is the only way to know the user whether these commands are
- executed properly
- what is the status after executing (success/fail, how many bytes read/write/erase. etc)

Due to the above reasons I have added these verbose support.

Apart from this sometimes (very rare) due to the slowness of UART or SPI flash even if we run the sf commands it will not execute the actual code just terminate with showing
u-boot prompt, so the user assumes that this command is happen properly. [but actually command is not done]

I thought these verbose prints will help such wild scenarios.

Correct me if am wrong with my thinking.

Thanks,
Jagan.

Quoted 14 lines

Best regards,

Wolfgang Denk

--
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de Programmer's Lament: (Shakespeare, Macbeth, Act I, Scene vii)
"That we but teach bloody instructions,
which, being taught, return to plague the inventor..."

#17 lore raw

PATCH v2 1/6 cmd_sf: Add print messages on flash erase command

Dear Jagan Teki,

Quoted 6 lines · In message <CAD6G_RRw=YgbYtkwaZMC=KaS_5Lbfbm+fR-=LV96aOY72W383w@mail.gmail.com>…

Apart from this sometimes (very rare) due to the slowness of UART or SPI flash even if we run the sf commands it will not execute the actual code just terminate with showing
u-boot prompt, so the user assumes that this command is happen properly. [but actually command is not done]

But that would be a different thing - if there are errors without clear error messages, this is a bug that needs fixing. [But I do not see which part of your patch would address such an issue. Am I missing something?]

Adding verbose progress messages is a different thing, though.

Best regards,

Wolfgang Denk

Signature · 4 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
It is much easier to suggest solutions when you know nothing
author
#18 lore raw

PATCH v2 1/6 cmd_sf: Add print messages on flash erase command

Hi Wolfgang Denk,

Quoted 10 lines · Wolfgang Denk

Dear Jagan Teki,

Quoted 6 lines · In message <CAD6G_RRw=YgbYtkwaZMC=KaS_5Lbfbm+fR-=LV96aOY72W383w@mail.gmail.com>…

Apart from this sometimes (very rare) due to the slowness of UART or SPI flash even if we run the sf commands it will not execute the actual code just terminate with showing
u-boot prompt, so the user assumes that this command is happen properly. [but actually command is not done]

Quoted 4 lines

But that would be a different thing - if there are errors without clear error messages, this is a bug that needs fixing. [But I do not see which part of your patch would address such an issue. Am I missing something?]

Basically if there is an error while executing these commands, then this print will show an :ERROR based on the return value from spi_flash_erase.
---- of-course there is a verbose print already if spi_flash_erase returns 1 (error case).

OK, I agree my patch will show only verbose prints for both in Success and Failure cases.

I thought it could be a good progress prints for sf read/write/erase commands as we didn't have
these verbose prints before.

Do you think these are useful/required messages?, please take my above concerns.

Thanks,
Jagan.

Quoted 12 lines

Adding verbose progress messages is a different thing, though.

Best regards,

Wolfgang Denk

--
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de It is much easier to suggest solutions when you know nothing

#19 lore raw

PATCH v2 1/6 cmd_sf: Add print messages on flash erase command

Dear Jagan Teki,

Quoted 6 lines · In message <CAD6G_RQtZZinzcx0haLqR-JD4cjM8WyjZZGgarZ-+DwaZJnR2g@mail.gmail.com>…

I thought it could be a good progress prints for sf read/write/erase commands as we didn't have
these verbose prints before.

Do you think these are useful/required messages?, please take my above concerns.

Some people will like such verbocity, others will dislike it. Also, some people will dislike th memory footprint that comes with the added code. So in any case this should be configurable.

But most of all: SF is just one storage device out of a much larger list. If we add such a feature, it should be done in common code and in a generic way that all similar devices can use as well.

Please see again the other thread, and Simon's response. I think it makes sense to handle these things together, as a common set of patches.

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
The only person who always got his work done by Friday
                                                 was Robinson Crusoe.