mtd: spi-nor: Make sure SFDP-based 4B_OPCODE support detection works correctly
Subsystems (2)
PATCH v3 1/2 mtd: spi-nor: Make sure SFDP-based 4B_OPCODE support detection works correctly
Some flash_info entries have the SPI_NOR_4B_OPCODES flag set to let the core know that the flash supports 4B opcode. While this solution works fine for id-based caps detection, it doesn't work that well when relying on SFDP-based caps detection. Let's add an SNOR_F_4B_OPCODES flag so that spi_nor_parse_bfpt() can add it when the BFPT_DWORD1_ADDRESS_BYTES field is set to BFPT_DWORD1_ADDRESS_BYTES_4_ONLY.
---
Changes in v3:
- Clear SNOR_F_4B_OPCODES flag when SFDP fails
- Add Alexandre R-b
Changes in v2:
- Fix the commit message
- Fix the ->addr_width check
- Add a comma at the end of the SNOR_F_4B_OPCODES definition
--- drivers/mtd/spi-nor/spi-nor.c | 12 +++++++++--- include/linux/mtd/spi-nor.h | 1 + 2 files changed, 10 insertions(+), 3 deletions(-)
drivers/mtd/spi-nor/spi-nor.c +9 -3
@@ -2643,6 +2643,7 @@ static int spi_nor_parse_bfpt(struct spi_nor *nor,break ;case BFPT_DWORD1_ADDRESS_BYTES_4_ONLY : + nor->flags |=SNOR_F_4B_OPCODES ; nor->addr_width =4 ;break ;
@@ -3252,6 +3253,7 @@ static int spi_nor_init_params(struct spi_nor *nor,if (spi_nor_parse_sfdp (nor, &sfdp_params)) { nor->addr_width =0 ; + nor->flags &= ~SNOR_F_4B_OPCODES ;/* restore previous erase map */ memcpy (&nor->erase_map, &prev_map,sizeof (nor->erase_map));
@@ -3554,7 +3556,7 @@ static int spi_nor_init(struct spi_nor *nor)if ((nor->addr_width ==4 ) && (JEDEC_MFR (nor->info) !=SNOR_MFR_SPANSION ) && - !(nor->info->flags &SPI_NOR_4B_OPCODES )) { + !(nor->flags &SNOR_F_4B_OPCODES )) {/* * If the RESET# pin isn't hooked up properly, or the system * otherwise doesn't perform a reset command in the boot
@@ -3588,7 +3590,7 @@ void spi_nor_restore(struct spi_nor *nor)/* restore the addressing mode */ if ((nor->addr_width ==4 ) && (JEDEC_MFR (nor->info) !=SNOR_MFR_SPANSION ) && - !(nor->info->flags &SPI_NOR_4B_OPCODES ) && + !(nor->flags &SNOR_F_4B_OPCODES ) && (nor->flags &SNOR_F_BROKEN_RESET ))set_4byte (nor, nor->info,0 ); }
@@ -3746,11 +3748,15 @@ int spi_nor_scan(struct spi_nor *nor, const char *name, nor->addr_width =4 ;if (JEDEC_MFR (info) ==SNOR_MFR_SPANSION || info->flags &SPI_NOR_4B_OPCODES ) -spi_nor_set_4byte_opcodes (nor, info); + nor->flags |=SNOR_F_4B_OPCODES ; }else { nor->addr_width =3 ; } +if (nor->addr_width ==4 && + nor->flags &SNOR_F_4B_OPCODES ) +spi_nor_set_4byte_opcodes (nor, info); +if (nor->addr_width >SPI_NOR_MAX_ADDR_WIDTH ) {dev_err (dev,"address width is too large: %u\n" , nor->addr_width);
include/linux/mtd/spi-nor.h +1 -0
@@ -236,6 +236,7 @@ enum spi_nor_option_flags {SNOR_F_READY_XSR_RDY =BIT (4 ),SNOR_F_USE_CLSR =BIT (5 ),SNOR_F_BROKEN_RESET =BIT (6 ), + SNOR_F_4B_OPCODES = BIT(7), };/**
Signature · 1 line
2.17.1
PATCH v3 2/2 mtd: spi-nor: Use 4B opcodes when the NOR advertises both 3B and 4B
When the NOR supports 4 bytes opcodes we should use those instead of switching the flash in 4-bytes mode. This way, we don't have to restore the addressing mode when resetting the board.
---
Changes in v3:
- Add Alexandre R-b+T-b
- Add Cyrille R-b
Changes in v2
- None
--- drivers/mtd/spi-nor/spi-nor.c | 1 + 1 file changed, 1 insertion(+)
drivers/mtd/spi-nor/spi-nor.c +1 -0
@@ -2643,6 +2643,7 @@ static int spi_nor_parse_bfpt(struct spi_nor *nor,break ;case BFPT_DWORD1_ADDRESS_BYTES_4_ONLY : +case BFPT_DWORD1_ADDRESS_BYTES_3_OR_4 : nor->flags |=SNOR_F_4B_OPCODES ; nor->addr_width =4 ;break ;
Signature · 1 line
2.17.1
Quoted 63 lines · Boris Brezillon
Some
flash_infoentries have theSPI_NOR_4B_OPCODESflag set to let the core know that the flash supports 4B opcode. While this solution works fine for id-based caps detection, it doesn't work that well when relying on SFDP-based caps detection. Let's add anSNOR_F_4B_OPCODESflag so thatspi_nor_parse_bfpt()can add it when theBFPT_DWORD1_ADDRESS_BYTESfield is set toBFPT_DWORD1_ADDRESS_BYTES_4_ONLY.Reported-by Alexandre Belloni <[email protected]>Signed-off-by Boris Brezillon <[email protected]>Tested-by Alexandre Belloni <[email protected]>---
Changes in v3:
- ClearSNOR_F_4B_OPCODESflag when SFDP fails
- Add Alexandre R-bChanges in v2:
- Fix the commit message
- Fix the ->addr_width check
- Add a comma at the end of theSNOR_F_4B_OPCODESdefinition--- drivers/mtd/spi-nor/spi-nor.c | 12 +++++++++--- include/linux/mtd/spi-nor.h | 1 + 2 files changed, 10 insertions(+), 3 deletions(-)drivers/mtd/spi-nor/spi-nor.c +4
-2@@ -2643,6 +2643,7 @@ static int spi_nor_parse_bfpt(struct spi_nor *nor,break ;case BFPT_DWORD1_ADDRESS_BYTES_4_ONLY : + nor->flags |=SNOR_F_4B_OPCODES ; nor->addr_width =4 ;break ;@@ -3252,6 +3253,7 @@ static int spi_nor_init_params(struct spi_nor *nor,if (spi_nor_parse_sfdp (nor, &sfdp_params)) { nor->addr_width =0 ; + nor->flags &= ~SNOR_F_4B_OPCODES ;/* restore previous erase map */ memcpy (&nor->erase_map, &prev_map,sizeof (nor->erase_map));@@ -3554,7 +3556,7 @@ static int spi_nor_init(struct spi_nor *nor)if ((nor->addr_width ==4 ) && (JEDEC_MFR (nor->info) !=SNOR_MFR_SPANSION ) && - !(nor->info->flags &SPI_NOR_4B_OPCODES )) { + !(nor->flags &SNOR_F_4B_OPCODES )) {/* * If the RESET# pin isn't hooked up properly, or the system * otherwise doesn't perform a reset command in the boot @@ -3588,7 +3590,7 @@ void spi_nor_restore(struct spi_nor *nor)/* restore the addressing mode */ if ((nor->addr_width ==4 ) && (JEDEC_MFR (nor->info) !=SNOR_MFR_SPANSION ) && - !(nor->info->flags &SPI_NOR_4B_OPCODES ) && + !(nor->flags &SNOR_F_4B_OPCODES ) && (nor->flags &SNOR_F_BROKEN_RESET ))set_4byte (nor, nor->info,0 ); }
drivers/mtd/spi-nor/spi-nor.c int spi_nor_scan(struct spi_nor *nor, const char *name, · line 3756
Quoted 10 lines
drivers/mtd/spi-nor/spi-nor.c +2
-1@@ -3746,11 +3748,15 @@ int spi_nor_scan(struct spi_nor *nor, const char *name, nor->addr_width =4 ;if (JEDEC_MFR (info) ==SNOR_MFR_SPANSION || info->flags &SPI_NOR_4B_OPCODES ) -spi_nor_set_4byte_opcodes (nor, info); + nor->flags |=SNOR_F_4B_OPCODES ; }else { nor->addr_width =3 ; } + if (nor->addr_width == 4 &&
Shouldn't SNOR_F_4B_OPCODES already imply nor->addr_width == 4?
When SNOR_F_4B_OPCODES comes from bfpt, addr_width is set to 4. For the id-based caps detection, when mtd->size > 0x1000000, we set nor->addr_width = 4 too.
The only uncovered case would be when
} else if (info->addr_width) {
nor->addr_width = info->addr_width;but this can be solved by reordering the else if cases.
if (nor->addr_width) {
/* already configured from SFDP */
} else if (mtd->size > 0x1000000) {
...
} else if (info->addr_width) {
nor->addr_width = info->addr_width;
} else {
nor->addr_width = 3;
}What do you think?
Quoted 19 lines
drivers/mtd/spi-nor/spi-nor.c +3
-0+ nor->flags & SNOR_F_4B_OPCODES) +spi_nor_set_4byte_opcodes (nor, info); +if (nor->addr_width >SPI_NOR_MAX_ADDR_WIDTH ) {dev_err (dev,"address width is too large: %u\n" , nor->addr_width);include/linux/mtd/spi-nor.h +1
-0@@ -236,6 +236,7 @@ enum spi_nor_option_flags {SNOR_F_READY_XSR_RDY =BIT (4 ),SNOR_F_USE_CLSR =BIT (5 ),SNOR_F_BROKEN_RESET =BIT (6 ), + SNOR_F_4B_OPCODES = BIT(7), };/**
Quoted 73 lines · On Thu, 8 Nov 2018 16:55:29 +0000 <[email protected]> wrote:
Quoted 72 lines · Boris Brezillon
Some
flash_infoentries have theSPI_NOR_4B_OPCODESflag set to let the core know that the flash supports 4B opcode. While this solution works fine for id-based caps detection, it doesn't work that well when relying on SFDP-based caps detection. Let's add anSNOR_F_4B_OPCODESflag so thatspi_nor_parse_bfpt()can add it when theBFPT_DWORD1_ADDRESS_BYTESfield is set toBFPT_DWORD1_ADDRESS_BYTES_4_ONLY.Reported-by Alexandre Belloni <[email protected]>Signed-off-by Boris Brezillon <[email protected]>Tested-by Alexandre Belloni <[email protected]>---
Changes in v3:
- ClearSNOR_F_4B_OPCODESflag when SFDP fails
- Add Alexandre R-bChanges in v2:
- Fix the commit message
- Fix the ->addr_width check
- Add a comma at the end of theSNOR_F_4B_OPCODESdefinition--- drivers/mtd/spi-nor/spi-nor.c | 12 +++++++++--- include/linux/mtd/spi-nor.h | 1 + 2 files changed, 10 insertions(+), 3 deletions(-)drivers/mtd/spi-nor/spi-nor.c +5
-3@@ -2643,6 +2643,7 @@ static int spi_nor_parse_bfpt(struct spi_nor *nor,break ;case BFPT_DWORD1_ADDRESS_BYTES_4_ONLY : + nor->flags |=SNOR_F_4B_OPCODES ; nor->addr_width =4 ;break ;@@ -3252,6 +3253,7 @@ static int spi_nor_init_params(struct spi_nor *nor,if (spi_nor_parse_sfdp (nor, &sfdp_params)) { nor->addr_width =0 ; + nor->flags &= ~SNOR_F_4B_OPCODES ;/* restore previous erase map */ memcpy (&nor->erase_map, &prev_map,sizeof (nor->erase_map));@@ -3554,7 +3556,7 @@ static int spi_nor_init(struct spi_nor *nor)if ((nor->addr_width ==4 ) && (JEDEC_MFR (nor->info) !=SNOR_MFR_SPANSION ) && - !(nor->info->flags &SPI_NOR_4B_OPCODES )) { + !(nor->flags &SNOR_F_4B_OPCODES )) {/* * If the RESET# pin isn't hooked up properly, or the system * otherwise doesn't perform a reset command in the boot @@ -3588,7 +3590,7 @@ void spi_nor_restore(struct spi_nor *nor)/* restore the addressing mode */ if ((nor->addr_width ==4 ) && (JEDEC_MFR (nor->info) !=SNOR_MFR_SPANSION ) && - !(nor->info->flags &SPI_NOR_4B_OPCODES ) && + !(nor->flags &SNOR_F_4B_OPCODES ) && (nor->flags &SNOR_F_BROKEN_RESET ))set_4byte (nor, nor->info,0 ); }@@ -3746,11 +3748,15 @@ int spi_nor_scan(struct spi_nor *nor, const char *name, nor->addr_width =4 ;if (JEDEC_MFR (info) ==SNOR_MFR_SPANSION || info->flags &SPI_NOR_4B_OPCODES ) -spi_nor_set_4byte_opcodes (nor, info); + nor->flags |=SNOR_F_4B_OPCODES ; }else { nor->addr_width =3 ; }
Quoted 3 lines
drivers/mtd/spi-nor/spi-nor.c int spi_nor_scan(struct spi_nor *nor, const char *name, · line 3756
Quoted 1 line
drivers/mtd/spi-nor/spi-nor.c +1
-0+ if (nor->addr_width == 4 &&Shouldn't
SNOR_F_4B_OPCODESalready implynor->addr_width== 4?
Can't we have NORs supporting 4B opcodes but are less than 16MB? In this case SNOR_F_4B_OPCODES would be set and ->addr_width would be 3.
Quoted 19 lines
When
SNOR_F_4B_OPCODEScomes from bfpt,addr_widthis set to 4. For the id-based caps detection, whenmtd->size>0x1000000, we setnor->addr_width= 4 too.The only uncovered case would be when
} else if (info->addr_width) { nor->addr_width = info->addr_width;but this can be solved by reordering the else if cases.
if (nor->addr_width) { /* already configured from SFDP */ } else if (mtd->size > 0x1000000) { ... } else if (info->addr_width) { nor->addr_width = info->addr_width; } else { nor->addr_width = 3; }
Quoted 1 line
What do you think?
I'd rather not change that in this patch, but feel free to propose a patch on top of mine to simplify the logic if you think it's needed.
Quoted 20 lines
Quoted 20 lines
drivers/mtd/spi-nor/spi-nor.c +3
-0+ nor->flags & SNOR_F_4B_OPCODES) +spi_nor_set_4byte_opcodes (nor, info); +if (nor->addr_width >SPI_NOR_MAX_ADDR_WIDTH ) {dev_err (dev,"address width is too large: %u\n" , nor->addr_width);include/linux/mtd/spi-nor.h +1
-0@@ -236,6 +236,7 @@ enum spi_nor_option_flags {SNOR_F_READY_XSR_RDY =BIT (4 ),SNOR_F_USE_CLSR =BIT (5 ),SNOR_F_BROKEN_RESET =BIT (6 ), + SNOR_F_4B_OPCODES = BIT(7), };/**
Quoted 76 lines · Boris Brezillon
Quoted 73 lines · On Thu, 8 Nov 2018 16:55:29 +0000 <[email protected]> wrote:
Quoted 72 lines · Boris Brezillon
Some
flash_infoentries have theSPI_NOR_4B_OPCODESflag set to let the core know that the flash supports 4B opcode. While this solution works fine for id-based caps detection, it doesn't work that well when relying on SFDP-based caps detection. Let's add anSNOR_F_4B_OPCODESflag so thatspi_nor_parse_bfpt()can add it when theBFPT_DWORD1_ADDRESS_BYTESfield is set toBFPT_DWORD1_ADDRESS_BYTES_4_ONLY.Reported-by Alexandre Belloni <[email protected]>Signed-off-by Boris Brezillon <[email protected]>Tested-by Alexandre Belloni <[email protected]>---
Changes in v3:
- ClearSNOR_F_4B_OPCODESflag when SFDP fails
- Add Alexandre R-bChanges in v2:
- Fix the commit message
- Fix the ->addr_width check
- Add a comma at the end of theSNOR_F_4B_OPCODESdefinition--- drivers/mtd/spi-nor/spi-nor.c | 12 +++++++++--- include/linux/mtd/spi-nor.h | 1 + 2 files changed, 10 insertions(+), 3 deletions(-)drivers/mtd/spi-nor/spi-nor.c +5
-3@@ -2643,6 +2643,7 @@ static int spi_nor_parse_bfpt(struct spi_nor *nor,break ;case BFPT_DWORD1_ADDRESS_BYTES_4_ONLY : + nor->flags |=SNOR_F_4B_OPCODES ; nor->addr_width =4 ;break ;@@ -3252,6 +3253,7 @@ static int spi_nor_init_params(struct spi_nor *nor,if (spi_nor_parse_sfdp (nor, &sfdp_params)) { nor->addr_width =0 ; + nor->flags &= ~SNOR_F_4B_OPCODES ;/* restore previous erase map */ memcpy (&nor->erase_map, &prev_map,sizeof (nor->erase_map));@@ -3554,7 +3556,7 @@ static int spi_nor_init(struct spi_nor *nor)if ((nor->addr_width ==4 ) && (JEDEC_MFR (nor->info) !=SNOR_MFR_SPANSION ) && - !(nor->info->flags &SPI_NOR_4B_OPCODES )) { + !(nor->flags &SNOR_F_4B_OPCODES )) {/* * If the RESET# pin isn't hooked up properly, or the system * otherwise doesn't perform a reset command in the boot @@ -3588,7 +3590,7 @@ void spi_nor_restore(struct spi_nor *nor)/* restore the addressing mode */ if ((nor->addr_width ==4 ) && (JEDEC_MFR (nor->info) !=SNOR_MFR_SPANSION ) && - !(nor->info->flags &SPI_NOR_4B_OPCODES ) && + !(nor->flags &SNOR_F_4B_OPCODES ) && (nor->flags &SNOR_F_BROKEN_RESET ))set_4byte (nor, nor->info,0 ); }@@ -3746,11 +3748,15 @@ int spi_nor_scan(struct spi_nor *nor, const char *name, nor->addr_width =4 ;if (JEDEC_MFR (info) ==SNOR_MFR_SPANSION || info->flags &SPI_NOR_4B_OPCODES ) -spi_nor_set_4byte_opcodes (nor, info); + nor->flags |=SNOR_F_4B_OPCODES ; }else { nor->addr_width =3 ; }
Quoted 6 lines
Quoted 3 lines
drivers/mtd/spi-nor/spi-nor.c int spi_nor_scan(struct spi_nor *nor, const char *name, · line 3756
Quoted 1 line
drivers/mtd/spi-nor/spi-nor.c +1
-0+ if (nor->addr_width == 4 &&Shouldn't
SNOR_F_4B_OPCODESalready implynor->addr_width== 4?Can't we have NORs supporting 4B opcodes but are less than 16MB? In this case
SNOR_F_4B_OPCODESwould be set and ->addr_width would be 3.
I guess not, it wouldn't make sense, but who knows ... :)
The 4-byte opcodes indicate that 4-bytes of address follow the instruction. And 4-byte addresses make sense for spi memories that exceed the 16MB density.
Quoted 20 lines
Quoted 20 lines
When
SNOR_F_4B_OPCODEScomes from bfpt,addr_widthis set to 4. For the id-based caps detection, whenmtd->size>0x1000000, we setnor->addr_width= 4 too.The only uncovered case would be when
} else if (info->addr_width) { nor->addr_width = info->addr_width;but this can be solved by reordering the else if cases.
if (nor->addr_width) { /* already configured from SFDP */ } else if (mtd->size > 0x1000000) { ... } else if (info->addr_width) { nor->addr_width = info->addr_width; } else { nor->addr_width = 3; }
Quoted 6 lines
Quoted 1 line
What do you think?
I'd rather not change that in this patch, but feel free to propose a patch on top of mine to simplify the logic if you think it's needed.
yeah, it can be made in a separate patch.
Cheers,
ta
Quoted 10 lines · Boris Brezillon
Some
flash_infoentries have theSPI_NOR_4B_OPCODESflag set to let the core know that the flash supports 4B opcode. While this solution works fine for id-based caps detection, it doesn't work that well when relying on SFDP-based caps detection. Let's add anSNOR_F_4B_OPCODESflag so thatspi_nor_parse_bfpt()can add it when theBFPT_DWORD1_ADDRESS_BYTESfield is set toBFPT_DWORD1_ADDRESS_BYTES_4_ONLY.Reported-by Alexandre Belloni <[email protected]>Signed-off-by Boris Brezillon <[email protected]>Tested-by Alexandre Belloni <[email protected]>
Quoted 82 lines
---
Changes in v3:
- ClearSNOR_F_4B_OPCODESflag when SFDP fails
- Add Alexandre R-bChanges in v2:
- Fix the commit message
- Fix the ->addr_width check
- Add a comma at the end of theSNOR_F_4B_OPCODESdefinition--- drivers/mtd/spi-nor/spi-nor.c | 12 +++++++++--- include/linux/mtd/spi-nor.h | 1 + 2 files changed, 10 insertions(+), 3 deletions(-)drivers/mtd/spi-nor/spi-nor.c +9
-3@@ -2643,6 +2643,7 @@ static int spi_nor_parse_bfpt(struct spi_nor *nor,break ;case BFPT_DWORD1_ADDRESS_BYTES_4_ONLY : + nor->flags |=SNOR_F_4B_OPCODES ; nor->addr_width =4 ;break ;@@ -3252,6 +3253,7 @@ static int spi_nor_init_params(struct spi_nor *nor,if (spi_nor_parse_sfdp (nor, &sfdp_params)) { nor->addr_width =0 ; + nor->flags &= ~SNOR_F_4B_OPCODES ;/* restore previous erase map */ memcpy (&nor->erase_map, &prev_map,sizeof (nor->erase_map));@@ -3554,7 +3556,7 @@ static int spi_nor_init(struct spi_nor *nor)if ((nor->addr_width ==4 ) && (JEDEC_MFR (nor->info) !=SNOR_MFR_SPANSION ) && - !(nor->info->flags &SPI_NOR_4B_OPCODES )) { + !(nor->flags &SNOR_F_4B_OPCODES )) {/* * If the RESET# pin isn't hooked up properly, or the system * otherwise doesn't perform a reset command in the boot @@ -3588,7 +3590,7 @@ void spi_nor_restore(struct spi_nor *nor)/* restore the addressing mode */ if ((nor->addr_width ==4 ) && (JEDEC_MFR (nor->info) !=SNOR_MFR_SPANSION ) && - !(nor->info->flags &SPI_NOR_4B_OPCODES ) && + !(nor->flags &SNOR_F_4B_OPCODES ) && (nor->flags &SNOR_F_BROKEN_RESET ))set_4byte (nor, nor->info,0 ); }@@ -3746,11 +3748,15 @@ int spi_nor_scan(struct spi_nor *nor, const char *name, nor->addr_width =4 ;if (JEDEC_MFR (info) ==SNOR_MFR_SPANSION || info->flags &SPI_NOR_4B_OPCODES ) -spi_nor_set_4byte_opcodes (nor, info); + nor->flags |=SNOR_F_4B_OPCODES ; }else { nor->addr_width =3 ; } +if (nor->addr_width ==4 && + nor->flags &SNOR_F_4B_OPCODES ) +spi_nor_set_4byte_opcodes (nor, info); +if (nor->addr_width >SPI_NOR_MAX_ADDR_WIDTH ) {dev_err (dev,"address width is too large: %u\n" , nor->addr_width);include/linux/mtd/spi-nor.h +1
-0@@ -236,6 +236,7 @@ enum spi_nor_option_flags {SNOR_F_READY_XSR_RDY =BIT (4 ),SNOR_F_USE_CLSR =BIT (5 ),SNOR_F_BROKEN_RESET =BIT (6 ), + SNOR_F_4B_OPCODES = BIT(7), };/**
Quoted 77 lines · On Fri, 9 Nov 2018 09:57:13 +0000 <[email protected]> wrote:
Quoted 76 lines · Boris Brezillon
Quoted 73 lines · On Thu, 8 Nov 2018 16:55:29 +0000 <[email protected]> wrote:
Quoted 72 lines · Boris Brezillon
Some
flash_infoentries have theSPI_NOR_4B_OPCODESflag set to let the core know that the flash supports 4B opcode. While this solution works fine for id-based caps detection, it doesn't work that well when relying on SFDP-based caps detection. Let's add anSNOR_F_4B_OPCODESflag so thatspi_nor_parse_bfpt()can add it when theBFPT_DWORD1_ADDRESS_BYTESfield is set toBFPT_DWORD1_ADDRESS_BYTES_4_ONLY.Reported-by Alexandre Belloni <[email protected]>Signed-off-by Boris Brezillon <[email protected]>Tested-by Alexandre Belloni <[email protected]>---
Changes in v3:
- ClearSNOR_F_4B_OPCODESflag when SFDP fails
- Add Alexandre R-bChanges in v2:
- Fix the commit message
- Fix the ->addr_width check
- Add a comma at the end of theSNOR_F_4B_OPCODESdefinition--- drivers/mtd/spi-nor/spi-nor.c | 12 +++++++++--- include/linux/mtd/spi-nor.h | 1 + 2 files changed, 10 insertions(+), 3 deletions(-)drivers/mtd/spi-nor/spi-nor.c +5
-3@@ -2643,6 +2643,7 @@ static int spi_nor_parse_bfpt(struct spi_nor *nor,break ;case BFPT_DWORD1_ADDRESS_BYTES_4_ONLY : + nor->flags |=SNOR_F_4B_OPCODES ; nor->addr_width =4 ;break ;@@ -3252,6 +3253,7 @@ static int spi_nor_init_params(struct spi_nor *nor,if (spi_nor_parse_sfdp (nor, &sfdp_params)) { nor->addr_width =0 ; + nor->flags &= ~SNOR_F_4B_OPCODES ;/* restore previous erase map */ memcpy (&nor->erase_map, &prev_map,sizeof (nor->erase_map));@@ -3554,7 +3556,7 @@ static int spi_nor_init(struct spi_nor *nor)if ((nor->addr_width ==4 ) && (JEDEC_MFR (nor->info) !=SNOR_MFR_SPANSION ) && - !(nor->info->flags &SPI_NOR_4B_OPCODES )) { + !(nor->flags &SNOR_F_4B_OPCODES )) {/* * If the RESET# pin isn't hooked up properly, or the system * otherwise doesn't perform a reset command in the boot @@ -3588,7 +3590,7 @@ void spi_nor_restore(struct spi_nor *nor)/* restore the addressing mode */ if ((nor->addr_width ==4 ) && (JEDEC_MFR (nor->info) !=SNOR_MFR_SPANSION ) && - !(nor->info->flags &SPI_NOR_4B_OPCODES ) && + !(nor->flags &SNOR_F_4B_OPCODES ) && (nor->flags &SNOR_F_BROKEN_RESET ))set_4byte (nor, nor->info,0 ); }@@ -3746,11 +3748,15 @@ int spi_nor_scan(struct spi_nor *nor, const char *name, nor->addr_width =4 ;if (JEDEC_MFR (info) ==SNOR_MFR_SPANSION || info->flags &SPI_NOR_4B_OPCODES ) -spi_nor_set_4byte_opcodes (nor, info); + nor->flags |=SNOR_F_4B_OPCODES ; }else { nor->addr_width =3 ; }
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
drivers/mtd/spi-nor/spi-nor.c int spi_nor_scan(struct spi_nor *nor, const char *name, · line 3756
Quoted 1 line
drivers/mtd/spi-nor/spi-nor.c +1
-0+ if (nor->addr_width == 4 &&Shouldn't
SNOR_F_4B_OPCODESalready implynor->addr_width== 4?Can't we have NORs supporting 4B opcodes but are less than 16MB? In this case
SNOR_F_4B_OPCODESwould be set and ->addr_width would be 3.I guess not, it wouldn't make sense, but who knows ... :)
Don't under-estimate flash manufacturers :-).
Quoted 3 lines
The 4-byte opcodes indicate that 4-bytes of address follow the instruction. And 4-byte addresses make sense for spi memories that exceed the 16MB density.
I'm pretty sure they use the same controller for <=16MB and >16MB chips, so I wouldn't be surprised if some of their modern <=16MB chips support 4B opcodes even if it's not needed.
Quoted 19 lines · On Fri, 9 Nov 2018 09:57:13 +0000 <[email protected]> wrote:
Quoted 19 lines
Quoted 19 lines
When
SNOR_F_4B_OPCODEScomes from bfpt,addr_widthis set to 4. For the id-based caps detection, whenmtd->size>0x1000000, we setnor->addr_width= 4 too.The only uncovered case would be when
} else if (info->addr_width) { nor->addr_width = info->addr_width;but this can be solved by reordering the else if cases.
if (nor->addr_width) { /* already configured from SFDP */ } else if (mtd->size > 0x1000000) { ... } else if (info->addr_width) { nor->addr_width = info->addr_width; } else { nor->addr_width = 3; }
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
What do you think?
I'd rather not change that in this patch, but feel free to propose a patch on top of mine to simplify the logic if you think it's needed.
yeah, it can be made in a separate patch.
If you're okay with the current version, can you add a R-b?
Thanks,
Boris
Re: [PATCH v3 2/2] mtd: spi-nor: Use 4B opcodes when the NOR advertises both 3B and 4B
In reply to Boris BrezillonQuoted 8 lines · Boris Brezillon
When the NOR supports 4 bytes opcodes we should use those instead of switching the flash in 4-bytes mode. This way, we don't have to restore the addressing mode when resetting the board.
Reported-by Alexandre Belloni <[email protected]>Signed-off-by Boris Brezillon <[email protected]>Tested-by Alexandre Belloni <[email protected]>Reviewed-by Cyrille Pitchen <[email protected]>
Quoted 24 lines
---
Changes in v3:
- Add Alexandre R-b+T-b
- Add Cyrille R-bChanges in v2
- None--- drivers/mtd/spi-nor/spi-nor.c | 1 + 1 file changed, 1 insertion(+)drivers/mtd/spi-nor/spi-nor.c +1
-0@@ -2643,6 +2643,7 @@ static int spi_nor_parse_bfpt(struct spi_nor *nor,break ;case BFPT_DWORD1_ADDRESS_BYTES_4_ONLY : +case BFPT_DWORD1_ADDRESS_BYTES_3_OR_4 : nor->flags |=SNOR_F_4B_OPCODES ; nor->addr_width =4 ;break ;
Re: [PATCH v3 2/2] mtd: spi-nor: Use 4B opcodes when the NOR advertises both 3B and 4B
Quoted 7 lines · On 11/09/2018 12:49 PM, [email protected] wrote:
Quoted 4 lines · Boris Brezillon
When the NOR supports 4 bytes opcodes we should use those instead of switching the flash in 4-bytes mode. This way, we don't have to restore the addressing mode when resetting the board.
Quoted 7 lines
Quoted 4 lines
Reported-by Alexandre Belloni <[email protected]>Signed-off-by Boris Brezillon <[email protected]>Tested-by Alexandre Belloni <[email protected]>Reviewed-by Cyrille Pitchen <[email protected]>Reviewed-by Tudor Ambarus <[email protected]>
I propose to stall this patch for a week or so, until we will have a clearer view on how are defined the flashes that don't have 4B opcodes, but can enter the 4-Byte mode on command.
Quoted 18 lines
Quoted 18 lines
---
Changes in v3:
- Add Alexandre R-b+T-b
- Add Cyrille R-bChanges in v2
- None--- drivers/mtd/spi-nor/spi-nor.c | 1 + 1 file changed, 1 insertion(+)drivers/mtd/spi-nor/spi-nor.c +0
-0@@ -2643,6 +2643,7 @@ static int spi_nor_parse_bfpt(struct spi_nor *nor,break ;
Quoted 3 lines
drivers/mtd/spi-nor/spi-nor.c static int spi_nor_parse_bfpt(struct spi_nor *nor, · line 2647
Quoted 3 lines
drivers/mtd/spi-nor/spi-nor.c +1
-0case BFPT_DWORD1_ADDRESS_BYTES_4_ONLY : +case BFPT_DWORD1_ADDRESS_BYTES_3_OR_4 : nor->flags |=SNOR_F_4B_OPCODES ;
Maybe we will also want to check that BFPT DWORD16[31:24] has value xx1x_xxxxb - it indicates that 4B opcodes are supported.
Cheers,
ta
Quoted 7 lines
drivers/mtd/spi-nor/spi-nor.c static int spi_nor_parse_bfpt(struct spi_nor *nor, · line 2649
Quoted 3 lines
drivers/mtd/spi-nor/spi-nor.c +0
-0nor->addr_width =4 ;break ;______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
Re: [PATCH v3 2/2] mtd: spi-nor: Use 4B opcodes when the NOR advertises both 3B and 4B
Quoted 15 lines · On 16/11/2018 11:57:10+0000, [email protected] wrote:
Quoted 12 lines · On 11/09/2018 12:49 PM, [email protected] wrote:
Quoted 8 lines · Boris Brezillon
When the NOR supports 4 bytes opcodes we should use those instead of switching the flash in 4-bytes mode. This way, we don't have to restore the addressing mode when resetting the board.
Reported-by Alexandre Belloni <[email protected]>Signed-off-by Boris Brezillon <[email protected]>Tested-by Alexandre Belloni <[email protected]>Reviewed-by Cyrille Pitchen <[email protected]>
Quoted 7 lines
Quoted 2 lines
Reviewed-by Tudor Ambarus <[email protected]>I propose to stall this patch for a week or so, until we will have a clearer view on how are defined the flashes that don't have 4B opcodes, but can enter the 4-Byte mode on command.
Note that this patch is badly needed for some of our boards. without it, they can't reboot properly. I would very much like to see it enter upstream and be backported sooner than later.
Quoted 36 lines
Quoted 18 lines
Quoted 18 lines
---
Changes in v3:
- Add Alexandre R-b+T-b
- Add Cyrille R-bChanges in v2
- None--- drivers/mtd/spi-nor/spi-nor.c | 1 + 1 file changed, 1 insertion(+)drivers/mtd/spi-nor/spi-nor.c +0
-0@@ -2643,6 +2643,7 @@ static int spi_nor_parse_bfpt(struct spi_nor *nor,break ;Quoted 3 lines
drivers/mtd/spi-nor/spi-nor.c static int spi_nor_parse_bfpt(struct spi_nor *nor, · line 2647
Quoted 3 lines
drivers/mtd/spi-nor/spi-nor.c +1
-0case BFPT_DWORD1_ADDRESS_BYTES_4_ONLY : +case BFPT_DWORD1_ADDRESS_BYTES_3_OR_4 : nor->flags |=SNOR_F_4B_OPCODES ;Maybe we will also want to check that BFPT DWORD16[31:24] has value
xx1x_xxxxb- it indicates that 4B opcodes are supported.Cheers,
taQuoted 7 lines
drivers/mtd/spi-nor/spi-nor.c static int spi_nor_parse_bfpt(struct spi_nor *nor, · line 2649
Quoted 3 lines
drivers/mtd/spi-nor/spi-nor.c +0
-0nor->addr_width =4 ;break ;______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
Signature · 3 lines
Alexandre Belloni, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
Re: [PATCH v3 2/2] mtd: spi-nor: Use 4B opcodes when the NOR advertises both 3B and 4B
Hi, Alexandre,
Quoted 19 lines · Alexandre Belloni
Quoted 18 lines · On 16/11/2018 11:57:10+0000, [email protected] wrote:
Quoted 14 lines · On 11/09/2018 12:49 PM, [email protected] wrote:
Quoted 8 lines · Boris Brezillon
When the NOR supports 4 bytes opcodes we should use those instead of switching the flash in 4-bytes mode. This way, we don't have to restore the addressing mode when resetting the board.
Reported-by Alexandre Belloni <[email protected]>Signed-off-by Boris Brezillon <[email protected]>Tested-by Alexandre Belloni <[email protected]>Reviewed-by Cyrille Pitchen <[email protected]>Reviewed-by Tudor Ambarus <[email protected]>
Quoted 8 lines
Quoted 4 lines
I propose to stall this patch for a week or so, until we will have a clearer view on how are defined the flashes that don't have 4B opcodes, but can enter the 4-Byte mode on command.
Note that this patch is badly needed for some of our boards. without it, they can't reboot properly. I would very much like to see it enter upstream and be backported sooner than later.
What flash do the boards use? Does your flash support SFDP 4-Byte Instruction table? If yes, the following patch should solve your problem indirectly:
https://lore.kernel.org/patchwork/patch/1015036/
You should also apply the following if you want to test it:
https://lore.kernel.org/patchwork/patch/1013294/
Cheers,
ta
Re: [PATCH v3 2/2] mtd: spi-nor: Use 4B opcodes when the NOR advertises both 3B and 4B
Quoted 27 lines · On 20/11/2018 13:18:49+0000, [email protected] wrote:
Hi, Alexandre,
Quoted 24 lines · Alexandre Belloni
Quoted 22 lines · On 16/11/2018 11:57:10+0000, [email protected] wrote:
Quoted 7 lines · On 11/09/2018 12:49 PM, [email protected] wrote:
Quoted 4 lines · Boris Brezillon
When the NOR supports 4 bytes opcodes we should use those instead of switching the flash in 4-bytes mode. This way, we don't have to restore the addressing mode when resetting the board.
Quoted 7 lines
Quoted 4 lines
Reported-by Alexandre Belloni <[email protected]>Signed-off-by Boris Brezillon <[email protected]>Tested-by Alexandre Belloni <[email protected]>Reviewed-by Cyrille Pitchen <[email protected]>Reviewed-by Tudor Ambarus <[email protected]>I propose to stall this patch for a week or so, until we will have a clearer view on how are defined the flashes that don't have 4B opcodes, but can enter the 4-Byte mode on command.
Quoted 7 lines
Quoted 3 lines
Note that this patch is badly needed for some of our boards. without it, they can't reboot properly. I would very much like to see it enter upstream and be backported sooner than later.
What flash do the boards use? Does your flash support SFDP 4-Byte Instruction table? If yes, the following patch should solve your problem indirectly:
It is a MX25L25635FMI-10G
Quoted 6 lines
https://lore.kernel.org/patchwork/patch/1015036/
You should also apply the following if you want to test it:
Applying those two patches only doesn't fix the reboot issue.
spi_nor_parse_4bait() is never called.
Signature · 3 lines
Alexandre Belloni, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
Re: [PATCH v3 2/2] mtd: spi-nor: Use 4B opcodes when the NOR advertises both 3B and 4B
In reply to [email protected]Quoted 38 lines · On Fri, 16 Nov 2018 11:57:10 +0000 <[email protected]> wrote:
Quoted 7 lines · On 11/09/2018 12:49 PM, [email protected] wrote:
Quoted 4 lines · Boris Brezillon
When the NOR supports 4 bytes opcodes we should use those instead of switching the flash in 4-bytes mode. This way, we don't have to restore the addressing mode when resetting the board.
Quoted 7 lines
Quoted 4 lines
Reported-by Alexandre Belloni <[email protected]>Signed-off-by Boris Brezillon <[email protected]>Tested-by Alexandre Belloni <[email protected]>Reviewed-by Cyrille Pitchen <[email protected]>Reviewed-by Tudor Ambarus <[email protected]>I propose to stall this patch for a week or so, until we will have a clearer view on how are defined the flashes that don't have 4B opcodes, but can enter the 4-Byte mode on command.
Quoted 18 lines
Quoted 18 lines
---
Changes in v3:
- Add Alexandre R-b+T-b
- Add Cyrille R-bChanges in v2
- None--- drivers/mtd/spi-nor/spi-nor.c | 1 + 1 file changed, 1 insertion(+)drivers/mtd/spi-nor/spi-nor.c +0
-0@@ -2643,6 +2643,7 @@ static int spi_nor_parse_bfpt(struct spi_nor *nor,break ;
Quoted 7 lines
Quoted 3 lines
drivers/mtd/spi-nor/spi-nor.c static int spi_nor_parse_bfpt(struct spi_nor *nor, · line 2647
Quoted 3 lines
drivers/mtd/spi-nor/spi-nor.c +1
-0case BFPT_DWORD1_ADDRESS_BYTES_4_ONLY : +case BFPT_DWORD1_ADDRESS_BYTES_3_OR_4 : nor->flags |=SNOR_F_4B_OPCODES ;Maybe we will also want to check that BFPT DWORD16[31:24] has value
xx1x_xxxxb- it indicates that 4B opcodes are supported.
Alexandre tested that, and it seems DWORD16 is not properly populated. We also considered setting the SPI_NOR_4B_OPCODES flag to the flash_id entry, but Macronix use the same device ID for both MX25L25635E and MX25L25635F, and only the F revision supports 4B opcodes.
Not the first time this sort of things happen, so I guess we have one more reason to add the ->fixup() we talked about multiple times ;-).