Skip to content

Commit 47c6f8a

Browse files
committed
mtd: spi-nor: Do not change nor->addr_nbytes at SFDP parsing time
At the SFDP parsing time we should not change members of struct spi_nor, but instead fill members of struct spi_nor_flash_parameters which could later on be used by callers. The caller will then decide if SFDP params should be used and more importantly when they should be used. Clean the code flow and don't initialize nor->addr_nbytes at SFDP parsing time. Signed-off-by: Tudor Ambarus <[email protected]> Tested-by: Takahiro Kuwano <[email protected]> Reviewed-by: Michael Walle <[email protected]> Reviewed-by: Pratyush Yadav <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent aa5d980 commit 47c6f8a

File tree

4 files changed

+9
-8
lines changed

4 files changed

+9
-8
lines changed

drivers/mtd/spi-nor/core.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2251,8 +2251,8 @@ static int spi_nor_default_setup(struct spi_nor *nor,
22512251

22522252
static int spi_nor_set_addr_nbytes(struct spi_nor *nor)
22532253
{
2254-
if (nor->addr_nbytes) {
2255-
/* already configured from SFDP */
2254+
if (nor->params->addr_nbytes) {
2255+
nor->addr_nbytes = nor->params->addr_nbytes;
22562256
} else if (nor->read_proto == SNOR_PROTO_8_8_8_DTR) {
22572257
/*
22582258
* In 8D-8D-8D mode, one byte takes half a cycle to transfer. So
@@ -2492,7 +2492,6 @@ static void spi_nor_sfdp_init_params_deprecated(struct spi_nor *nor)
24922492

24932493
if (spi_nor_parse_sfdp(nor)) {
24942494
memcpy(nor->params, &sfdp_params, sizeof(*nor->params));
2495-
nor->addr_nbytes = 0;
24962495
nor->flags &= ~SNOR_F_4B_OPCODES;
24972496
}
24982497
}

drivers/mtd/spi-nor/core.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ struct spi_nor_otp {
340340
* @writesize Minimal writable flash unit size. Defaults to 1. Set to
341341
* ECC unit size for ECC-ed flashes.
342342
* @page_size: the page size of the SPI NOR flash memory.
343+
* @addr_nbytes: number of address bytes to send.
343344
* @rdsr_dummy: dummy cycles needed for Read Status Register command
344345
* in octal DTR mode.
345346
* @rdsr_addr_nbytes: dummy address bytes needed for Read Status Register
@@ -372,6 +373,7 @@ struct spi_nor_flash_parameter {
372373
u64 size;
373374
u32 writesize;
374375
u32 page_size;
376+
u8 addr_nbytes;
375377
u8 rdsr_dummy;
376378
u8 rdsr_addr_nbytes;
377379

drivers/mtd/spi-nor/issi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ is25lp256_post_bfpt_fixups(struct spi_nor *nor,
2020
*/
2121
if ((bfpt->dwords[BFPT_DWORD(1)] & BFPT_DWORD1_ADDRESS_BYTES_MASK) ==
2222
BFPT_DWORD1_ADDRESS_BYTES_3_ONLY)
23-
nor->addr_nbytes = 4;
23+
nor->params->addr_nbytes = 4;
2424

2525
return 0;
2626
}

drivers/mtd/spi-nor/sfdp.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -462,11 +462,11 @@ static int spi_nor_parse_bfpt(struct spi_nor *nor,
462462
switch (bfpt.dwords[BFPT_DWORD(1)] & BFPT_DWORD1_ADDRESS_BYTES_MASK) {
463463
case BFPT_DWORD1_ADDRESS_BYTES_3_ONLY:
464464
case BFPT_DWORD1_ADDRESS_BYTES_3_OR_4:
465-
nor->addr_nbytes = 3;
465+
params->addr_nbytes = 3;
466466
break;
467467

468468
case BFPT_DWORD1_ADDRESS_BYTES_4_ONLY:
469-
nor->addr_nbytes = 4;
469+
params->addr_nbytes = 4;
470470
break;
471471

472472
default:
@@ -653,7 +653,7 @@ static u8 spi_nor_smpt_addr_nbytes(const struct spi_nor *nor, const u32 settings
653653
return 4;
654654
case SMPT_CMD_ADDRESS_LEN_USE_CURRENT:
655655
default:
656-
return nor->addr_nbytes;
656+
return nor->params->addr_nbytes;
657657
}
658658
}
659659

@@ -1098,7 +1098,7 @@ static int spi_nor_parse_4bait(struct spi_nor *nor,
10981098
* Spansion memory. However this quirk is no longer needed with new
10991099
* SFDP compliant memories.
11001100
*/
1101-
nor->addr_nbytes = 4;
1101+
params->addr_nbytes = 4;
11021102
nor->flags |= SNOR_F_4B_OPCODES | SNOR_F_HAS_4BAIT;
11031103

11041104
/* fall through */

0 commit comments

Comments
 (0)