Skip to content

Commit d7931a2

Browse files
committed
mtd: spi-nor: core: Track flash's internal address mode
We need to track the flash's internal address mode as there are flashes that can operate with 4B opcodes but unfortunately do not have a 4B opcode correspondent for all the 3B opcodes. Such an example is the Infineon Semper chips which provide 4B opcodes for read/program/erase but do not provide 4B opcodes for Read/Write Any Register. These registers are indexed by address and require the internal address mode of the flash before Read/Write Any Register opcodes are issued. 4B opcodes are preferred over changing the flash's address mode to 4byte, as set_4byte_addr_mode could be done in a non-volatile way and could break the boot sequence. Thus we need to track the flash's internal address mode so that we can use 4B opcodes together with opcodes that don't have a 4B opcode correspondent. Track flash's internal address mode. addr_mode_nbytes is discovered when parsing BFPT. For the BFPT_DWORD1_ADDRESS_BYTES_3_OR_4 case, one could introduce a method that queries the flash's internal address mode at run-time (works for Winbond). If a run-time querying can not be accomplished or if SFDP is not defined at all, but the address mode is volatile and resets to a default known value at boot, one can change the default addr_mode_nbytes value of 3 by introducing a flash_info flag. If the address mode can not be queried, discovered and it is configured via a non-volatile register, we may introduce a dt property, but it will harm the generic approach of the jedec,spi-nor compatible. All this complexity is not needed now, so let it for future development. Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com> Reviewed-by: Takahiro Kuwano <Takahiro.Kuwano@infineon.com> Reviewed-by: Michael Walle <michael@walle.cc> Link: https://lore.kernel.org/r/20220725092505.446315-6-tudor.ambarus@microchip.com
1 parent 08412e7 commit d7931a2

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

drivers/mtd/spi-nor/core.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,10 @@ struct spi_nor_otp {
341341
* ECC unit size for ECC-ed flashes.
342342
* @page_size: the page size of the SPI NOR flash memory.
343343
* @addr_nbytes: number of address bytes to send.
344+
* @addr_mode_nbytes: number of address bytes of current address mode. Useful
345+
* when the flash operates with 4B opcodes but needs the
346+
* internal address mode for opcodes that don't have a 4B
347+
* opcode correspondent.
344348
* @rdsr_dummy: dummy cycles needed for Read Status Register command
345349
* in octal DTR mode.
346350
* @rdsr_addr_nbytes: dummy address bytes needed for Read Status Register
@@ -374,6 +378,7 @@ struct spi_nor_flash_parameter {
374378
u32 writesize;
375379
u32 page_size;
376380
u8 addr_nbytes;
381+
u8 addr_mode_nbytes;
377382
u8 rdsr_dummy;
378383
u8 rdsr_addr_nbytes;
379384

drivers/mtd/spi-nor/sfdp.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,10 +463,12 @@ static int spi_nor_parse_bfpt(struct spi_nor *nor,
463463
case BFPT_DWORD1_ADDRESS_BYTES_3_ONLY:
464464
case BFPT_DWORD1_ADDRESS_BYTES_3_OR_4:
465465
params->addr_nbytes = 3;
466+
params->addr_mode_nbytes = 3;
466467
break;
467468

468469
case BFPT_DWORD1_ADDRESS_BYTES_4_ONLY:
469470
params->addr_nbytes = 4;
471+
params->addr_mode_nbytes = 4;
470472
break;
471473

472474
default:
@@ -653,7 +655,7 @@ static u8 spi_nor_smpt_addr_nbytes(const struct spi_nor *nor, const u32 settings
653655
return 4;
654656
case SMPT_CMD_ADDRESS_LEN_USE_CURRENT:
655657
default:
656-
return nor->params->addr_nbytes;
658+
return nor->params->addr_mode_nbytes;
657659
}
658660
}
659661

0 commit comments

Comments
 (0)