[U-Boot] [RFC] [PATCH 3/4] FSL eSPI support for the Spansion Flash driver
Can Aydin
can.aydin at locatacorp.com
Tue Sep 28 11:57:01 CEST 2010
Modify Spansion flash driver to add support for the FSL eSPI controller.
Due to the nature of the eSPI controller the upper level drivers must
ensure to use single frame transactions (i.e. that have begin and end
flags set) and keep the size of each frame below maximum length.
Signed-off-by: Can Aydin<can.aydin at locatacorp.com>
---
drivers/mtd/spi/spansion.c | 60 ++++++++++++++++++++++++++++++++++++++++---
1 files changed, 55 insertions(+), 5 deletions(-)
mode change 100644 => 100755 drivers/mtd/spi/spansion.c
diff --git a/drivers/mtd/spi/spansion.c b/drivers/mtd/spi/spansion.c
old mode 100644
new mode 100755
index d6c1a5f..d66f4e0
--- a/drivers/mtd/spi/spansion.c
+++ b/drivers/mtd/spi/spansion.c
@@ -31,6 +31,10 @@
#include "spi_flash_internal.h"
+#ifdef CONFIG_FSL_ESPI
+#include<fsl_espi.h>
+#endif
+
/* S25FLxx-specific commands */
#define CMD_S25FLXX_READ 0x03 /* Read Data Bytes */
#define CMD_S25FLXX_FAST_READ 0x0b /* Read Data Bytes at Higher Speed */
@@ -135,7 +139,13 @@ static int spansion_wait_ready(struct spi_flash *flash, unsigned long timeout)
timebase = get_timer(0);
do {
+#ifdef CONFIG_FSL_ESPI
+ u8 cmd = CMD_S25FLXX_RDSR;
+ ret = spi_flash_cmd_rw_frame(spi,&(cmd), sizeof(cmd),
+ &status, sizeof(status));
+#else
ret = spi_flash_cmd(spi, CMD_S25FLXX_RDSR,&status, sizeof(status));
+#endif
if (ret)
return -1;
@@ -158,22 +168,56 @@ static int spansion_read_fast(struct spi_flash *flash,
struct spansion_spi_flash *spsn = to_spansion_spi_flash(flash);
unsigned long page_addr;
unsigned long page_size;
+ int ret = 0;
u8 cmd[5];
page_size = spsn->params->page_size;
- page_addr = offset / page_size;
+
+#ifdef CONFIG_FSL_ESPI
+ /* Break up read into ESPI_MAX_TRANLEN size chunks */
+ while (( len )&& (!ret))
+ {
+ unsigned int tranlen;
+ if ( len + sizeof(cmd)>= ESPI_MAX_TRANLEN ) {
+ tranlen = ESPI_MAX_TRANLEN - sizeof(cmd);
+ len -= tranlen;
+ } else {
+ tranlen = len;
+ len = 0;
+ }
+
+ page_addr = offset / page_size;
+
+ cmd[0] = CMD_READ_ARRAY_FAST;
+ cmd[1] = page_addr>> 8;
+ cmd[2] = page_addr;
+ cmd[3] = offset % page_size;
+ cmd[4] = 0x00;
+
+ debug ("READ: 0x%x => cmd = { 0x%02x 0x%02x%02x%02x%02x } len = 0x%x\n",
+ offset, cmd[0], cmd[1], cmd[2], cmd[3], cmd[4], tranlen);
+
+ ret = spi_flash_cmd_rw_frame(flash->spi, cmd, sizeof(cmd), buf, tranlen);
+ offset += tranlen;
+ buf += tranlen;
+ }
+ return ret;
+#else
+ page_addr = offset / page_size;
+
cmd[0] = CMD_READ_ARRAY_FAST;
cmd[1] = page_addr>> 8;
cmd[2] = page_addr;
cmd[3] = offset % page_size;
cmd[4] = 0x00;
-
+
debug
("READ: 0x%x => cmd = { 0x%02x 0x%02x%02x%02x%02x } len = 0x%x\n",
offset, cmd[0], cmd[1], cmd[2], cmd[3], cmd[4], len);
return spi_flash_read_common(flash, cmd, sizeof(cmd), buf, len);
+#endif
}
static int spansion_write(struct spi_flash *flash,
@@ -187,6 +231,7 @@ static int spansion_write(struct spi_flash *flash,
size_t actual;
int ret;
u8 cmd[4];
+ u8 cmd_wren = CMD_S25FLXX_WREN;
page_size = spsn->params->page_size;
page_addr = offset / page_size;
@@ -216,9 +261,13 @@ static int spansion_write(struct spi_flash *flash,
debug("SF: Enabling Write failed\n");
break;
}
-
- ret = spi_flash_cmd_write(flash->spi, cmd, 4,
+#ifdef CONFIG_FSL_ESPI
+ ret = spi_flash_cmd_rw_frame(flash->spi, cmd, sizeof(cmd),
+ buf + actual, chunk_len);
+#else
+ ret = spi_flash_cmd_write(flash->spi, cmd, sizeof(cmd),
buf + actual, chunk_len);
+#endif
if (ret< 0) {
debug("SF: SPANSION Page Program failed\n");
break;
@@ -258,7 +307,8 @@ int spansion_erase(struct spi_flash *flash, u32 offset, size_t len)
sector_size = spsn->params->page_size * spsn->params->pages_per_sector;
if (offset % sector_size || len % sector_size) {
- debug("SF: Erase offset/length not multiple of sector size\n");
+ debug("SF: Erase offset/length not multiple of sector size (0x%x)\n",
+ sector_size);
return -1;
}
--
1.7.0.4
More information about the U-Boot
mailing list