[U-Boot] [U-Boot, 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.
Signed-off-by: Jagannadha Sutradharudu Teki jagannadh.teki@gmail.com --- 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(-)
diff --git a/common/cmd_sf.c b/common/cmd_sf.c index 5ac1d0c..ddb1a65 100644 --- a/common/cmd_sf.c +++ b/common/cmd_sf.c @@ -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[]) diff --git a/drivers/mtd/spi/spi_flash.c b/drivers/mtd/spi/spi_flash.c index 00aece9..43e0334 100644 --- a/drivers/mtd/spi/spi_flash.c +++ b/drivers/mtd/spi/spi_flash.c @@ -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;

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.
Signed-off-by: Jagannadha Sutradharudu Teki jagannadh.teki@gmail.com --- 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(-)
diff --git a/common/cmd_sf.c b/common/cmd_sf.c index ddb1a65..efdd640 100644 --- a/common/cmd_sf.c +++ b/common/cmd_sf.c @@ -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[]) diff --git a/drivers/mtd/spi/spi_flash.c b/drivers/mtd/spi/spi_flash.c index 43e0334..9e8939c 100644 --- a/drivers/mtd/spi/spi_flash.c +++ b/drivers/mtd/spi/spi_flash.c @@ -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; }

Dear Jagannadha Sutradharudu Teki,
In message 1355934463-24319-2-git-send-email-jagannadh.teki@gmail.com you wrote:
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.
Signed-off-by: Jagannadha Sutradharudu Teki jagannadh.teki@gmail.com
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

Hi Wolfgang Denk,
On Thu, Dec 20, 2012 at 4:48 AM, Wolfgang Denk wd@denx.de wrote:
Dear Jagannadha Sutradharudu Teki,
In message 1355934463-24319-2-git-send-email-jagannadh.teki@gmail.com you wrote:
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.
Signed-off-by: Jagannadha Sutradharudu Teki jagannadh.teki@gmail.com
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.
Please see my comments on previous patch. http://article.gmane.org/gmane.comp.boot-loaders.u-boot/149698
Thanks, Jagan.
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@denx.de F u cn rd ths u cnt spl wrth a dm!

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.
Signed-off-by: Jagannadha Sutradharudu Teki jagannadh.teki@gmail.com --- 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(-)
diff --git a/drivers/mtd/spi/spi_flash.c b/drivers/mtd/spi/spi_flash.c index 9e8939c..bf5ec4a 100644 --- a/drivers/mtd/spi/spi_flash.c +++ b/drivers/mtd/spi/spi_flash.c @@ -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 * diff --git a/drivers/mtd/spi/spi_flash_internal.h b/drivers/mtd/spi/spi_flash_internal.h index 141cfa8..8232595 100644 --- a/drivers/mtd/spi/spi_flash_internal.h +++ b/drivers/mtd/spi/spi_flash_internal.h @@ -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.

Tested on real hardware, works fine.
Tested-by: Jagannadha Sutradharudu Teki jagannadh.teki@gmail.com
Thanks, Jagan.
On Wed, Dec 19, 2012 at 9:57 PM, Jagannadha Sutradharudu Teki jagannadh.teki@gmail.com wrote:
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.
Signed-off-by: Jagannadha Sutradharudu Teki jagannadh.teki@gmail.com
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(-)
diff --git a/drivers/mtd/spi/spi_flash.c b/drivers/mtd/spi/spi_flash.c index 9e8939c..bf5ec4a 100644 --- a/drivers/mtd/spi/spi_flash.c +++ b/drivers/mtd/spi/spi_flash.c @@ -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
diff --git a/drivers/mtd/spi/spi_flash_internal.h b/drivers/mtd/spi/spi_flash_internal.h index 141cfa8..8232595 100644 --- a/drivers/mtd/spi/spi_flash_internal.h +++ b/drivers/mtd/spi/spi_flash_internal.h @@ -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

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.
Signed-off-by: Jagannadha Sutradharudu Teki jagannadh.teki@gmail.com --- 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(-)
diff --git a/drivers/mtd/spi/spi_flash.c b/drivers/mtd/spi/spi_flash.c index bf5ec4a..cad6c40 100644 --- a/drivers/mtd/spi/spi_flash.c +++ b/drivers/mtd/spi/spi_flash.c @@ -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 * diff --git a/drivers/mtd/spi/spi_flash_internal.h b/drivers/mtd/spi/spi_flash_internal.h index 8232595..825b398 100644 --- a/drivers/mtd/spi/spi_flash_internal.h +++ b/drivers/mtd/spi/spi_flash_internal.h @@ -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.

Tested on real hardware, works fine.
Tested-by: Jagannadha Sutradharudu Teki jagannadh.teki@gmail.com
Thanks, Jagan.
On Wed, Dec 19, 2012 at 9:57 PM, Jagannadha Sutradharudu Teki jagannadh.teki@gmail.com wrote:
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.
Signed-off-by: Jagannadha Sutradharudu Teki jagannadh.teki@gmail.com
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(-)
diff --git a/drivers/mtd/spi/spi_flash.c b/drivers/mtd/spi/spi_flash.c index bf5ec4a..cad6c40 100644 --- a/drivers/mtd/spi/spi_flash.c +++ b/drivers/mtd/spi/spi_flash.c @@ -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
diff --git a/drivers/mtd/spi/spi_flash_internal.h b/drivers/mtd/spi/spi_flash_internal.h index 8232595..825b398 100644 --- a/drivers/mtd/spi/spi_flash_internal.h +++ b/drivers/mtd/spi/spi_flash_internal.h @@ -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

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.
Signed-off-by: Jagannadha Sutradharudu Teki jagannadh.teki@gmail.com --- 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(-)
diff --git a/drivers/mtd/spi/spi_flash.c b/drivers/mtd/spi/spi_flash.c index cad6c40..5bddde4 100644 --- a/drivers/mtd/spi/spi_flash.c +++ b/drivers/mtd/spi/spi_flash.c @@ -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 * diff --git a/drivers/mtd/spi/spi_flash_internal.h b/drivers/mtd/spi/spi_flash_internal.h index 825b398..844e82e 100644 --- a/drivers/mtd/spi/spi_flash_internal.h +++ b/drivers/mtd/spi/spi_flash_internal.h @@ -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.

Tested on real hardware, works fine.
Tested-by: Jagannadha Sutradharudu Teki jagannadh.teki@gmail.com
Thanks, Jagan.
On Wed, Dec 19, 2012 at 9:57 PM, Jagannadha Sutradharudu Teki jagannadh.teki@gmail.com wrote:
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.
Signed-off-by: Jagannadha Sutradharudu Teki jagannadh.teki@gmail.com
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(-)
diff --git a/drivers/mtd/spi/spi_flash.c b/drivers/mtd/spi/spi_flash.c index cad6c40..5bddde4 100644 --- a/drivers/mtd/spi/spi_flash.c +++ b/drivers/mtd/spi/spi_flash.c @@ -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
diff --git a/drivers/mtd/spi/spi_flash_internal.h b/drivers/mtd/spi/spi_flash_internal.h index 825b398..844e82e 100644 --- a/drivers/mtd/spi/spi_flash_internal.h +++ b/drivers/mtd/spi/spi_flash_internal.h @@ -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

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.
Signed-off-by: Jagannadha Sutradharudu Teki jagannadh.teki@gmail.com --- 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(-)
diff --git a/drivers/mtd/spi/spi_flash.c b/drivers/mtd/spi/spi_flash.c index 5bddde4..675a0bf 100644 --- a/drivers/mtd/spi/spi_flash.c +++ b/drivers/mtd/spi/spi_flash.c @@ -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 * diff --git a/drivers/mtd/spi/spi_flash_internal.h b/drivers/mtd/spi/spi_flash_internal.h index 844e82e..15c7ac4 100644 --- a/drivers/mtd/spi/spi_flash_internal.h +++ b/drivers/mtd/spi/spi_flash_internal.h @@ -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.

Tested on real hardware, works fine.
Tested-by: Jagannadha Sutradharudu Teki jagannadh.teki@gmail.com
Thanks, Jagan.
On Wed, Dec 19, 2012 at 9:57 PM, Jagannadha Sutradharudu Teki jagannadh.teki@gmail.com wrote:
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.
Signed-off-by: Jagannadha Sutradharudu Teki jagannadh.teki@gmail.com
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(-)
diff --git a/drivers/mtd/spi/spi_flash.c b/drivers/mtd/spi/spi_flash.c index 5bddde4..675a0bf 100644 --- a/drivers/mtd/spi/spi_flash.c +++ b/drivers/mtd/spi/spi_flash.c @@ -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
diff --git a/drivers/mtd/spi/spi_flash_internal.h b/drivers/mtd/spi/spi_flash_internal.h index 844e82e..15c7ac4 100644 --- a/drivers/mtd/spi/spi_flash_internal.h +++ b/drivers/mtd/spi/spi_flash_internal.h @@ -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

Hi Mike/Simon,
Any further comments on this.
I have tested on real h/w target as well.
Thanks, Jagan.
On Sun, Dec 23, 2012 at 11:23 PM, Jagan Teki jagannadh.teki@gmail.com wrote:
Tested on real hardware, works fine.
Tested-by: Jagannadha Sutradharudu Teki jagannadh.teki@gmail.com
Thanks, Jagan.
On Wed, Dec 19, 2012 at 9:57 PM, Jagannadha Sutradharudu Teki jagannadh.teki@gmail.com wrote:
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.
Signed-off-by: Jagannadha Sutradharudu Teki jagannadh.teki@gmail.com
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(-)
diff --git a/drivers/mtd/spi/spi_flash.c b/drivers/mtd/spi/spi_flash.c index 5bddde4..675a0bf 100644 --- a/drivers/mtd/spi/spi_flash.c +++ b/drivers/mtd/spi/spi_flash.c @@ -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
diff --git a/drivers/mtd/spi/spi_flash_internal.h b/drivers/mtd/spi/spi_flash_internal.h index 844e82e..15c7ac4 100644 --- a/drivers/mtd/spi/spi_flash_internal.h +++ b/drivers/mtd/spi/spi_flash_internal.h @@ -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

Hi,
On Thu, Jan 31, 2013 at 10:49 AM, Jagan Teki jagannadh.teki@gmail.com wrote:
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.
Acked-by: Simon Glass sjg@chromium.org
Regards, Simon
I have tested on real h/w target as well.
Thanks, Jagan.
On Sun, Dec 23, 2012 at 11:23 PM, Jagan Teki jagannadh.teki@gmail.com wrote:
Tested on real hardware, works fine.
Tested-by: Jagannadha Sutradharudu Teki jagannadh.teki@gmail.com
Thanks, Jagan.
On Wed, Dec 19, 2012 at 9:57 PM, Jagannadha Sutradharudu Teki jagannadh.teki@gmail.com wrote:
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.
Signed-off-by: Jagannadha Sutradharudu Teki jagannadh.teki@gmail.com
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(-)
diff --git a/drivers/mtd/spi/spi_flash.c b/drivers/mtd/spi/spi_flash.c index 5bddde4..675a0bf 100644 --- a/drivers/mtd/spi/spi_flash.c +++ b/drivers/mtd/spi/spi_flash.c @@ -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
diff --git a/drivers/mtd/spi/spi_flash_internal.h b/drivers/mtd/spi/spi_flash_internal.h index 844e82e..15c7ac4 100644 --- a/drivers/mtd/spi/spi_flash_internal.h +++ b/drivers/mtd/spi/spi_flash_internal.h @@ -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

Hi Simon,
On Fri, Feb 1, 2013 at 10:00 AM, Simon Glass sjg@chromium.org wrote:
Hi,
On Thu, Jan 31, 2013 at 10:49 AM, Jagan Teki jagannadh.teki@gmail.com wrote:
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.
Acked-by: Simon Glass sjg@chromium.org
Regards, Simon
I have tested on real h/w target as well.
Thanks, Jagan.
On Sun, Dec 23, 2012 at 11:23 PM, Jagan Teki jagannadh.teki@gmail.com wrote:
Tested on real hardware, works fine.
Tested-by: Jagannadha Sutradharudu Teki jagannadh.teki@gmail.com
Thanks, Jagan.
On Wed, Dec 19, 2012 at 9:57 PM, Jagannadha Sutradharudu Teki jagannadh.teki@gmail.com wrote:
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.
Signed-off-by: Jagannadha Sutradharudu Teki jagannadh.teki@gmail.com
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(-)
diff --git a/drivers/mtd/spi/spi_flash.c b/drivers/mtd/spi/spi_flash.c index 5bddde4..675a0bf 100644 --- a/drivers/mtd/spi/spi_flash.c +++ b/drivers/mtd/spi/spi_flash.c @@ -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
diff --git a/drivers/mtd/spi/spi_flash_internal.h b/drivers/mtd/spi/spi_flash_internal.h index 844e82e..15c7ac4 100644 --- a/drivers/mtd/spi/spi_flash_internal.h +++ b/drivers/mtd/spi/spi_flash_internal.h @@ -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

Dear Jagannadha Sutradharudu Teki,
In message 1355934463-24319-1-git-send-email-jagannadh.teki@gmail.com you wrote:
This patch adds a print messages while using 'sf erase' command to make sure that how many bytes erased in flash device.
Signed-off-by: Jagannadha Sutradharudu Teki jagannadh.teki@gmail.com
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

Hi Wolfgang Denk,
On Thu, Dec 20, 2012 at 4:46 AM, Wolfgang Denk wd@denx.de wrote:
Dear Jagannadha Sutradharudu Teki,
In message 1355934463-24319-1-git-send-email-jagannadh.teki@gmail.com you wrote:
This patch adds a print messages while using 'sf erase' command to make sure that how many bytes erased in flash device.
Signed-off-by: Jagannadha Sutradharudu Teki jagannadh.teki@gmail.com
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
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.
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@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..."

Dear Jagan Teki,
In message CAD6G_RRw=YgbYtkwaZMC=KaS_5Lbfbm+fR-=LV96aOY72W383w@mail.gmail.com you wrote:
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

Hi Wolfgang Denk,
On Thu, Dec 20, 2012 at 6:19 PM, Wolfgang Denk wd@denx.de wrote:
Dear Jagan Teki,
In message CAD6G_RRw=YgbYtkwaZMC=KaS_5Lbfbm+fR-=LV96aOY72W383w@mail.gmail.com you wrote:
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?]
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.
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@denx.de It is much easier to suggest solutions when you know nothing

Dear Jagan Teki,
In message CAD6G_RQtZZinzcx0haLqR-JD4cjM8WyjZZGgarZ-+DwaZJnR2g@mail.gmail.com you wrote:
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
participants (4)
-
Jagan Teki
-
Jagannadha Sutradharudu Teki
-
Simon Glass
-
Wolfgang Denk