4byte addressing mode on Micron n25q256a vs write enable
Hello,
I pulled a the " m25p80: Micron SPI uses Macronix-style 4-byte addressing" from Linux-next (see (1) and (2) ) and applied it on my 3.9 tree in order to get a Micron n25q256a (N25Q256A13ESF40F to be complete) functional on custom board with an i.mx28. The patch came close to get this combination functional but it lacked something. If we look at the n25q256a datasheet (3) page 68 contains in paragraph "ENTER or EXIT 4-BYTE ADDRESS MODE Command" the following:
<quote>
To enter or exit the 4-byte address mode, the WRITE ENABLE command must be executed to set the write enable latch bit to 1. (Note: The WRITE ENABLE command must NOT be executed on the N25Q256A83ESF40x and N25Q256A83E1240x devices.) S# must be driven LOW. The effect of the command is immediate; after the command has been executed, the write enable latch bit is cleared to 0.
</quote>
So with just your patch (1), (2) applied:
switch (JEDEC_MFR(jedec_id)) {
case CFI_MFR_MACRONIX:
+ case CFI_MFR_ST: /* Micron, actually */
case 0xEF /* winbond */:
The result is that the SPI flash does not enter 4byte mode. If I however rework this patch as:
switch (JEDEC_MFR(jedec_id)) {
+ case CFI_MFR_ST: /* Micron, actually */
+ write_enable(flash);
case CFI_MFR_MACRONIX:
case 0xEF /* winbond */:
It just-seems-to-work, but I have no idea how general this patch is for other Micron devices which support the 4byte mode.
my 2 cents.
E.
References:
(1) https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/commit/drivers/mtd/devices/m25p80.c?id=7b9497fcaaceb84acbb62e80e04eba2e36ee5ed4
(2) http://patchwork.ozlabs.org/patch/266130/
(3) http://www.micron.com/~/media/Documents/Products/Data%20Sheet/NOR%20Flash/Serial%20NOR/N25Q/n25q_256mb_3v_65nm.pdf
Signature · 1 line
Elie De Brauwer
Hi Elie,
Quoted 29 lines · Elie De Brauwer
Hello,
I pulled a the " m25p80: Micron SPI uses Macronix-style 4-byte addressing" from Linux-next (see (1) and (2) ) and applied it on my 3.9 tree in order to get a Micron n25q256a (N25Q256A13ESF40F to be complete) functional on custom board with an i.mx28. The patch came close to get this combination functional but it lacked something. If we look at the n25q256a datasheet (3) page 68 contains in paragraph "ENTER or EXIT 4-BYTE ADDRESS MODE Command" the following:
<quote>
To enter or exit the 4-byte address mode, the WRITE ENABLE command must be executed to set the write enable latch bit to 1. (Note: The WRITE ENABLE command must NOT be executed on the N25Q256A83ESF40x and N25Q256A83E1240x devices.) S# must be driven LOW. The effect of the command is immediate; after the command has been executed, the write enable latch bit is cleared to 0.
</quote>So with just your patch (1), (2) applied:
switch (
JEDEC_MFR(jedec_id)) {
caseCFI_MFR_MACRONIX:
+ caseCFI_MFR_ST: /* Micron, actually */
case0xEF/* winbond */:The result is that the SPI flash does not enter 4byte mode. If I however rework this patch as:
Quoted 8 lines
switch (
JEDEC_MFR(jedec_id)) {
+ caseCFI_MFR_ST: /* Micron, actually */
+write_enable(flash);
caseCFI_MFR_MACRONIX:
case0xEF/* winbond */:It just-seems-to-work, but I have no idea how general this patch is for other Micron devices which support the 4byte mode.
Hmm, that's interesting. I overlooked the note about WRITE ENABLE, and it so happens I am working on the N25Q256A83ESF40x, so I am happily oblivious.
Heeding the note in the quote there, though, I would hesitate to apply WRITE ENABLE to all Micron 4-byte addressed flash. I am contacting Micron about this unusual inconsistency, since it's not very easy to programmatically discover which Micron flash need WRITE ENABLE and which don't.
I'll try to get around to testing your patch on my N25Q256A83ESF40x sometime, just to see what happens when I disobey the datasheet.
Quoted 7 lines
my 2 cents.
E.References:
(1) https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/commit/drivers/mtd/devices/m25p80.c?id=7b9497fcaaceb84acbb62e80e04eba2e36ee5ed4
(2) http://patchwork.ozlabs.org/patch/266130/
(3) http://www.micron.com/~/media/Documents/Products/Data%20Sheet/NOR%20Flash/Serial%20NOR/N25Q/n25q_256mb_3v_65nm.pdf
Thanks for the detailed report.
Brian
Hi Elie,
Quoted 41 lines · Brian Norris
Quoted 27 lines · Elie De Brauwer
I pulled a the " m25p80: Micron SPI uses Macronix-style 4-byte addressing" from Linux-next (see (1) and (2) ) and applied it on my 3.9 tree in order to get a Micron n25q256a (N25Q256A13ESF40F to be complete) functional on custom board with an i.mx28. The patch came close to get this combination functional but it lacked something. If we look at the n25q256a datasheet (3) page 68 contains in paragraph "ENTER or EXIT 4-BYTE ADDRESS MODE Command" the following:
<quote>
To enter or exit the 4-byte address mode, the WRITE ENABLE command must be executed to set the write enable latch bit to 1. (Note: The WRITE ENABLE command must NOT be executed on the N25Q256A83ESF40x and N25Q256A83E1240x devices.) S# must be driven LOW. The effect of the command is immediate; after the command has been executed, the write enable latch bit is cleared to 0.
</quote>So with just your patch (1), (2) applied:
switch (
JEDEC_MFR(jedec_id)) {
caseCFI_MFR_MACRONIX:
+ caseCFI_MFR_ST: /* Micron, actually */
case0xEF/* winbond */:The result is that the SPI flash does not enter 4byte mode. If I however rework this patch as:
Quoted 8 lines
switch (
JEDEC_MFR(jedec_id)) {
+ caseCFI_MFR_ST: /* Micron, actually */
+write_enable(flash);
caseCFI_MFR_MACRONIX:
case0xEF/* winbond */:It just-seems-to-work, but I have no idea how general this patch is for other Micron devices which support the 4byte mode.
Hmm, that's interesting. I overlooked the note about WRITE ENABLE, and it so happens I am working on the N25Q256A83ESF40x, so I am happily oblivious.
Quoted 5 lines
Heeding the note in the quote there, though, I would hesitate to apply WRITE ENABLE to all Micron 4-byte addressed flash. I am contacting Micron about this unusual inconsistency, since it's not very easy to programmatically discover which Micron flash need WRITE ENABLE and which don't.
I have some word back from Micron. Apparently the A8 parts were made to be compatible with Macronix, which didn't need the WREN command. They will still accept the command fine, but it's not required.
They recommended that if we want to be generic to all types of Micron flash, we should do the following sequence (to avoid leaving the flash in a write-able state):
WREN
EN4B
WRDI
So feel free to send a patch that does this sequence for all Micron SPI flash.
Thanks,
Brian
PATCH 1/1 mtd: m25p80: Fix 4 byte addressing mode for Micron devices.
According to the datasheet for Micron n25q256a (N25Q256A13ESF40F) 4-byte addressing mode should be entered as follows:
<quote>
To enter or exit the 4-byte address mode, the WRITE ENABLE command must be executed to set the write enable latch bit to 1. (Note: The WRITE ENABLE command must NOT be executed on the N25Q256A83ESF40x and N25Q256A83E1240x devices.) S# must be driven LOW. The effect of the command is immediate; after the command has been executed, the write enable latch bit is cleared to 0.
</quote>
Micron's portable way to perform this for all types of Micron flash is to first issue a write enable, then switch the addressing mode followed by a write disable to avoid leaving the flash in a write- able state.
--- drivers/mtd/devices/m25p80.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/mtd/devices/m25p80.c +9 -1
@@ -169,8 +169,16 @@ static inline int write_disable(struct m25p *flash)static inline int set_4byte (struct m25p *flash,u32 jedec_id,int enable) {switch (JEDEC_MFR (jedec_id)) { -case CFI_MFR_MACRONIX :case CFI_MFR_ST :/* Micron, actually */ + { +int status; +write_enable (flash); + flash->command[0 ] = enable ?OPCODE_EN4B :OPCODE_EX4B ; + status =spi_write (flash->spi, flash->command,1 ); +write_disable (flash); +return status; + } +case CFI_MFR_MACRONIX :case 0xEF /* winbond */ : flash->command[0 ] = enable ?OPCODE_EN4B :OPCODE_EX4B ;return spi_write (flash->spi, flash->command,1 );
Signature · 1 line
1.7.10.4
Re: [PATCH] mtd: m25p80: Fix 4 byte addressing mode for Micron devices.
Quoted 12 lines · Elie De Brauwer
According to the datasheet for Micron n25q256a (N25Q256A13ESF40F) 4-byte addressing mode should be entered as follows:
<quote>
To enter or exit the 4-byte address mode, the WRITE ENABLE command must be executed to set the write enable latch bit to 1. (Note: The WRITE ENABLE command must NOT be executed on the N25Q256A83ESF40x and N25Q256A83E1240x devices.) S# must be driven LOW. The effect of the command is immediate; after the command has been executed, the write enable latch bit is cleared to 0.
</quote>
Quoted 4 lines
Micron's portable way to perform this for all types of Micron flash is to first issue a write enable, then switch the addressing mode followed by a write disable to avoid leaving the flash in a write- able state.
I just noticed, you're missing a
"Signed-off-by: Your Name <[email protected]>"
If you reply with a line like that, I can past it into the commit.
Quoted 16 lines
--- drivers/mtd/devices/m25p80.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)drivers/mtd/devices/m25p80.c +2
-1@@ -169,8 +169,16 @@ static inline int write_disable(struct m25p *flash)static inline int set_4byte (struct m25p *flash,u32 jedec_id,int enable) {switch (JEDEC_MFR (jedec_id)) { -case CFI_MFR_MACRONIX :case CFI_MFR_ST :/* Micron, actually */ + { +int status;
drivers/mtd/devices/m25p80.c static inline int write_disable(struct m25p *flash) · line 184
Quoted 10 lines
drivers/mtd/devices/m25p80.c +7
-0+write_enable (flash); + flash->command[0 ] = enable ?OPCODE_EN4B :OPCODE_EX4B ; + status =spi_write (flash->spi, flash->command,1 ); +write_disable (flash); +return status; + } +case CFI_MFR_MACRONIX :case 0xEF /* winbond */ : flash->command[0 ] = enable ?OPCODE_EN4B :OPCODE_EX4B ;return spi_write (flash->spi, flash->command,1 );
I personally don't like the code duplication from the Macronix and Winbond cases, and the extra context braces may not be needed. How about the following? If it's OK, I'll just squash your description and my patch.
Brian
drivers/mtd/devices/m25p80.c +15 -2
@@ -168,12 +168,25 @@ static inline int write_disable(struct m25p *flash)*/ static inline int set_4byte (struct m25p *flash,u32 jedec_id,int enable) { +int status; +bool need_wren = false; +switch (JEDEC_MFR (jedec_id)) { -case CFI_MFR_MACRONIX :case CFI_MFR_ST :/* Micron, actually */ +/* Some Micron need WREN command; all will accept it */ + need_wren = true; +case CFI_MFR_MACRONIX :case 0xEF /* winbond */ : +if (need_wren) +write_enable (flash); + flash->command[0 ] = enable ?OPCODE_EN4B :OPCODE_EX4B ; -return spi_write (flash->spi, flash->command,1 ); + status =spi_write (flash->spi, flash->command,1 ); + +if (need_wren) +write_disable (flash); + +return status;default :/* Spansion style */ flash->command[0 ] =OPCODE_BRWR ;
A message that is not in the archive (sent off-list or not yet received): CAGWqfijXn6DWXiZBc7Kwsz=XK2WYdFY97EL9v7s6Ghxf85Tqgw@mail.gmail.com
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH] mtd: m25p80: Fix 4 byte addressing mode for Micron devices.
Quoted 1 line · Brian Norris
Re-include linux-mtd
Whoops, forgot to actually include linux-mtd!
Quoted 74 lines · Elie De Brauwer
Quoted 15 lines
Quoted 13 lines · Brian Norris
Quoted 12 lines · Elie De Brauwer
According to the datasheet for Micron n25q256a (N25Q256A13ESF40F) 4-byte addressing mode should be entered as follows:
<quote>
To enter or exit the 4-byte address mode, the WRITE ENABLE command must be executed to set the write enable latch bit to 1. (Note: The WRITE ENABLE command must NOT be executed on the N25Q256A83ESF40x and N25Q256A83E1240x devices.) S# must be driven LOW. The effect of the command is immediate; after the command has been executed, the write enable latch bit is cleared to 0.
</quote>Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Micron's portable way to perform this for all types of Micron flash is to first issue a write enable, then switch the addressing mode followed by a write disable to avoid leaving the flash in a write- able state.
BTW, I just tested this myself on my N25Q256A83ESF40F, and the extra write-enable/write-disable doesn't seem to cause problems.
Quoted 5 lines
Quoted 3 lines
I just noticed, you're missing a
"Signed-off-by: Your Name <[email protected]>"
Oops, my -s went missing in action:
As did your Cc: [email protected] ;)
Quoted 37 lines
Signed-off-by Elie De Brauwer <[email protected]>Quoted 26 lines
If you reply with a line like that, I can past it into the commit.
Quoted 23 lines
--- drivers/mtd/devices/m25p80.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)drivers/mtd/devices/m25p80.c +9
-1@@ -169,8 +169,16 @@ static inline int write_disable(struct m25p *flash)static inline int set_4byte (struct m25p *flash,u32 jedec_id,int enable) {switch (JEDEC_MFR (jedec_id)) { -case CFI_MFR_MACRONIX :case CFI_MFR_ST :/* Micron, actually */ + { +int status; +write_enable (flash); + flash->command[0 ] = enable ?OPCODE_EN4B :OPCODE_EX4B ; + status =spi_write (flash->spi, flash->command,1 ); +write_disable (flash); +return status; + } +case CFI_MFR_MACRONIX :Quoted 8 lines
drivers/mtd/devices/m25p80.c static inline int write_disable(struct m25p *flash)
Quoted 3 lines
drivers/mtd/devices/m25p80.c +0
-0case 0xEF /* winbond */ : flash->command[0 ] = enable ?OPCODE_EN4B :OPCODE_EX4B ;return spi_write (flash->spi, flash->command,1 );I personally don't like the code duplication from the Macronix and Winbond cases, and the extra context braces may not be needed. How about the following? If it's OK, I'll just squash your description and my patch.
Quoted 1 line
Fine with me, squash em !.
Squashed and pushed to l2-mtd.git. Thanks!
Brian