[PATCH] Add SPI Flash STMicro's N25Q512A & add flag status check during SPI Flash write
Insop Song
insop.song at cohere.net
Sun Jun 2 22:33:37 CEST 2013
Signed-off-by: Insop Song <insop.song at cohere.net>
---
drivers/mtd/spi/spi_flash.c | 25 +++++++++++++++++++++++++
drivers/mtd/spi/spi_flash_internal.h | 1 +
drivers/mtd/spi/stmicro.c | 6 ++++++
3 files changed, 32 insertions(+)
diff --git a/drivers/mtd/spi/spi_flash.c b/drivers/mtd/spi/spi_flash.c
index 00aece9..f53756d 100644
--- a/drivers/mtd/spi/spi_flash.c
+++ b/drivers/mtd/spi/spi_flash.c
@@ -72,6 +72,7 @@ int spi_flash_cmd_write_multi(struct spi_flash *flash, u3=
2 offset,
size_t chunk_len, actual;
int ret;
u8 cmd[4];
+ u8 flag_status;
=20
page_size =3D flash->page_size;
page_addr =3D offset / page_size;
@@ -83,6 +84,18 @@ int spi_flash_cmd_write_multi(struct spi_flash *flash, u=
32 offset,
return ret;
}
=20
+wait_flag:
+ ret =3D spi_flash_cmd(flash->spi, CMD_READ_FLAG_STATUS, &flag_status, siz=
eof(flag_status));
+ if (ret < 0) {
+ printf("SF: reading flag failed\n");
+ return ret;
+ }
+ debug("flag_status %d\n", flag_status);
+ if ((flag_status & 0x80) =3D=3D 0) {
+ udelay(10);
+ goto wait_flag;
+ }
+
cmd[0] =3D CMD_PAGE_PROGRAM;
for (actual =3D 0; actual < len; actual +=3D chunk_len) {
chunk_len =3D min(len - actual, page_size - byte_addr);
@@ -106,6 +119,18 @@ int spi_flash_cmd_write_multi(struct spi_flash *flash,=
u32 offset,
debug("SF: write failed\n");
break;
}
+ /* check status */
+flag_check:
+ ret =3D spi_flash_cmd(flash->spi, CMD_READ_FLAG_STATUS, &flag_status, si=
zeof(flag_status));
+ if (ret < 0) {
+ printf("SF: reading flag failed\n");
+ break;
+ }
+ debug("flag_status %d\n", flag_status);
+ if (!(flag_status & 0x80)) {
+ udelay(100);
+ goto flag_check;
+ }
=20
ret =3D spi_flash_cmd_wait_ready(flash, SPI_FLASH_PROG_TIMEOUT);
if (ret)
diff --git a/drivers/mtd/spi/spi_flash_internal.h b/drivers/mtd/spi/spi_fla=
sh_internal.h
index 141cfa8..90b6993 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_FLAG_STATUS 0x70
#define CMD_WRITE_ENABLE 0x06
#define CMD_ERASE_4K 0x20
#define CMD_ERASE_32K 0x52
diff --git a/drivers/mtd/spi/stmicro.c b/drivers/mtd/spi/stmicro.c
index 30b626a..ad94ad2 100644
--- a/drivers/mtd/spi/stmicro.c
+++ b/drivers/mtd/spi/stmicro.c
@@ -110,6 +110,12 @@ static const struct stmicro_spi_flash_params stmicro_s=
pi_flash_table[] =3D {
.nr_sectors =3D 512,
.name =3D "N25Q256",
},
+ {
+ .id =3D 0xba20,
+ .pages_per_sector =3D 256,
+ .nr_sectors =3D 1024,
+ .name =3D "N25Q512A",
+ },
};
=20
struct spi_flash *spi_flash_probe_stmicro(struct spi_slave *spi, u8 * idco=
de)
--=20
1.7.9.5
--_002_63c878bfad3346a08c80dcd344ca79dbBLUPR07MB002namprd07pro_
Content-Type: application/octet-stream;
name="0001-Add-SPI-Flash-STMicro-s-N25Q512A-add-flag-status-che.patch"
Content-Description: 0001-Add-SPI-Flash-STMicro-s-N25Q512A-add-flag-status-che.patch
Content-Disposition: attachment;
filename="0001-Add-SPI-Flash-STMicro-s-N25Q512A-add-flag-status-che.patch";
size=2936; creation-date="Mon, 03 Jun 2013 16:41:06 GMT";
modification-date="Sun, 02 Jun 2013 20:34:20 GMT"
Content-Transfer-Encoding: base64
RnJvbSA5NzU3MmIzMmM0OWQwNmNhNmY4NTQ4ZWQ4OGU2ZTM4MWZiNzE5YTA4IE1vbiBTZXAgMTcg
MDA6MDA6MDAgM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