Skip to content

Commit aa517a2

Browse files
committed
mtd: spi-nor: spansion: switch cypress_nor_get_page_size() to use vreg_offset
All users of cypress_nor_get_page_size() but S25FS256T retrieve n_dice and vreg_offset from SFDP. S25FS256T does not define the SCCR map to retrive the vreg_offset, but it does support it: SPINOR_REG_CYPRESS_VREG. Switch cypress_nor_get_page_size() to always use vreg_offset so that we use the same code base for both single and multi chip package flashes. cypress_nor_get_page_size() is now called in the post_sfdp() hook instead of post_bfpt(), as vreg_offset and n_dice are parsed after BFPT. Consequently the null checks on n_dice and vreg_offset are moved to the post_sfdp() hook. Tested-by: Takahiro Kuwano <Takahiro.Kuwano@infineon.com> Link: https://lore.kernel.org/r/20230726075257.12985-12-tudor.ambarus@linaro.org Signed-off-by: Tudor Ambarus <tudor.ambarus@linaro.org>
1 parent fb63bfa commit aa517a2

File tree

1 file changed

+48
-65
lines changed

1 file changed

+48
-65
lines changed

drivers/mtd/spi-nor/spansion.c

Lines changed: 48 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@
3232
#define SPINOR_REG_CYPRESS_CFR2_MEMLAT_11_24 0xb
3333
#define SPINOR_REG_CYPRESS_CFR2_ADRBYT BIT(7)
3434
#define SPINOR_REG_CYPRESS_CFR3 0x4
35-
#define SPINOR_REG_CYPRESS_CFR3V \
36-
(SPINOR_REG_CYPRESS_VREG + SPINOR_REG_CYPRESS_CFR3)
3735
#define SPINOR_REG_CYPRESS_CFR3_PGSZ BIT(4) /* Page size. */
3836
#define SPINOR_REG_CYPRESS_CFR5 0x6
3937
#define SPINOR_REG_CYPRESS_CFR5_BIT6 BIT(6)
@@ -467,28 +465,17 @@ static int cypress_nor_set_addr_mode_nbytes(struct spi_nor *nor)
467465
return 0;
468466
}
469467

470-
static int cypress_nor_get_page_size_single_chip(struct spi_nor *nor)
471-
{
472-
struct spi_mem_op op =
473-
CYPRESS_NOR_RD_ANY_REG_OP(nor->params->addr_mode_nbytes,
474-
SPINOR_REG_CYPRESS_CFR3V, 0,
475-
nor->bouncebuf);
476-
int ret;
477-
478-
ret = spi_nor_read_any_reg(nor, &op, nor->reg_proto);
479-
if (ret)
480-
return ret;
481-
482-
if (nor->bouncebuf[0] & SPINOR_REG_CYPRESS_CFR3_PGSZ)
483-
nor->params->page_size = 512;
484-
else
485-
nor->params->page_size = 256;
486-
487-
return 0;
488-
}
489-
490-
491-
static int cypress_nor_get_page_size_mcp(struct spi_nor *nor)
468+
/**
469+
* cypress_nor_get_page_size() - Get flash page size configuration.
470+
* @nor: pointer to a 'struct spi_nor'
471+
*
472+
* The BFPT table advertises a 512B or 256B page size depending on part but the
473+
* page size is actually configurable (with the default being 256B). Read from
474+
* CFR3V[4] and set the correct size.
475+
*
476+
* Return: 0 on success, -errno otherwise.
477+
*/
478+
static int cypress_nor_get_page_size(struct spi_nor *nor)
492479
{
493480
struct spi_mem_op op =
494481
CYPRESS_NOR_RD_ANY_REG_OP(nor->params->addr_mode_nbytes,
@@ -518,23 +505,6 @@ static int cypress_nor_get_page_size_mcp(struct spi_nor *nor)
518505
return 0;
519506
}
520507

521-
/**
522-
* cypress_nor_get_page_size() - Get flash page size configuration.
523-
* @nor: pointer to a 'struct spi_nor'
524-
*
525-
* The BFPT table advertises a 512B or 256B page size depending on part but the
526-
* page size is actually configurable (with the default being 256B). Read from
527-
* CFR3V[4] and set the correct size.
528-
*
529-
* Return: 0 on success, -errno otherwise.
530-
*/
531-
static int cypress_nor_get_page_size(struct spi_nor *nor)
532-
{
533-
if (nor->params->n_dice)
534-
return cypress_nor_get_page_size_mcp(nor);
535-
return cypress_nor_get_page_size_single_chip(nor);
536-
}
537-
538508
static void cypress_nor_ecc_init(struct spi_nor *nor)
539509
{
540510
/*
@@ -571,20 +541,32 @@ s25fs256t_post_bfpt_fixup(struct spi_nor *nor,
571541
if (nor->bouncebuf[0])
572542
return -ENODEV;
573543

574-
return cypress_nor_get_page_size(nor);
544+
return 0;
575545
}
576546

577547
static int s25fs256t_post_sfdp_fixup(struct spi_nor *nor)
578548
{
579549
struct spi_nor_flash_parameter *params = nor->params;
580550

551+
/*
552+
* S25FS256T does not define the SCCR map, but we would like to use the
553+
* same code base for both single and multi chip package devices, thus
554+
* set the vreg_offset and n_dice to be able to do so.
555+
*/
556+
params->vreg_offset = devm_kmalloc(nor->dev, sizeof(u32), GFP_KERNEL);
557+
if (!params->vreg_offset)
558+
return -ENOMEM;
559+
560+
params->vreg_offset[0] = SPINOR_REG_CYPRESS_VREG;
561+
params->n_dice = 1;
562+
581563
/* PP_1_1_4_4B is supported but missing in 4BAIT. */
582564
params->hwcaps.mask |= SNOR_HWCAPS_PP_1_1_4;
583565
spi_nor_set_pp_settings(&params->page_programs[SNOR_CMD_PP_1_1_4],
584566
SPINOR_OP_PP_1_1_4_4B,
585567
SNOR_PROTO_1_1_4);
586568

587-
return 0;
569+
return cypress_nor_get_page_size(nor);
588570
}
589571

590572
static int s25fs256t_late_init(struct spi_nor *nor)
@@ -619,10 +601,20 @@ s25hx_t_post_bfpt_fixup(struct spi_nor *nor,
619601

620602
static int s25hx_t_post_sfdp_fixup(struct spi_nor *nor)
621603
{
622-
struct spi_nor_erase_type *erase_type =
623-
nor->params->erase_map.erase_type;
604+
struct spi_nor_flash_parameter *params = nor->params;
605+
struct spi_nor_erase_type *erase_type = params->erase_map.erase_type;
624606
unsigned int i;
625607

608+
if (!params->n_dice || !params->vreg_offset) {
609+
dev_err(nor->dev, "%s failed. The volatile register offset could not be retrieved from SFDP.\n",
610+
__func__);
611+
return -EOPNOTSUPP;
612+
}
613+
614+
/* The 2 Gb parts duplicate info and advertise 4 dice instead of 2. */
615+
if (params->size == SZ_256M)
616+
params->n_dice = 2;
617+
626618
/*
627619
* In some parts, 3byte erase opcodes are advertised by 4BAIT.
628620
* Convert them to 4byte erase opcodes.
@@ -640,23 +632,13 @@ static int s25hx_t_post_sfdp_fixup(struct spi_nor *nor)
640632
}
641633
}
642634

643-
/* The 2 Gb parts duplicate info and advertise 4 dice instead of 2. */
644-
if (nor->params->size == SZ_256M)
645-
nor->params->n_dice = 2;
646-
647635
return cypress_nor_get_page_size(nor);
648636
}
649637

650638
static int s25hx_t_late_init(struct spi_nor *nor)
651639
{
652640
struct spi_nor_flash_parameter *params = nor->params;
653641

654-
if (!params->n_dice || !params->vreg_offset) {
655-
dev_err(nor->dev, "%s failed. The volatile register offset could not be retrieved from SFDP.\n",
656-
__func__);
657-
return -EOPNOTSUPP;
658-
}
659-
660642
/* Fast Read 4B requires mode cycles */
661643
params->reads[SNOR_CMD_READ_FAST].num_mode_clocks = 8;
662644
params->ready = cypress_nor_sr_ready_and_clear;
@@ -690,6 +672,17 @@ static int cypress_nor_set_octal_dtr(struct spi_nor *nor, bool enable)
690672
static int s28hx_t_post_sfdp_fixup(struct spi_nor *nor)
691673
{
692674
struct spi_nor_flash_parameter *params = nor->params;
675+
676+
if (!params->n_dice || !params->vreg_offset) {
677+
dev_err(nor->dev, "%s failed. The volatile register offset could not be retrieved from SFDP.\n",
678+
__func__);
679+
return -EOPNOTSUPP;
680+
}
681+
682+
/* The 2 Gb parts duplicate info and advertise 4 dice instead of 2. */
683+
if (params->size == SZ_256M)
684+
params->n_dice = 2;
685+
693686
/*
694687
* On older versions of the flash the xSPI Profile 1.0 table has the
695688
* 8D-8D-8D Fast Read opcode as 0x00. But it actually should be 0xEE.
@@ -715,10 +708,6 @@ static int s28hx_t_post_sfdp_fixup(struct spi_nor *nor)
715708
*/
716709
params->rdsr_addr_nbytes = 4;
717710

718-
/* The 2 Gb parts duplicate info and advertise 4 dice instead of 2. */
719-
if (params->size == SZ_256M)
720-
params->n_dice = 2;
721-
722711
return cypress_nor_get_page_size(nor);
723712
}
724713

@@ -733,12 +722,6 @@ static int s28hx_t_late_init(struct spi_nor *nor)
733722
{
734723
struct spi_nor_flash_parameter *params = nor->params;
735724

736-
if (!params->n_dice || !params->vreg_offset) {
737-
dev_err(nor->dev, "%s failed. The volatile register offset could not be retrieved from SFDP.\n",
738-
__func__);
739-
return -EOPNOTSUPP;
740-
}
741-
742725
params->set_octal_dtr = cypress_nor_set_octal_dtr;
743726
params->ready = cypress_nor_sr_ready_and_clear;
744727
cypress_nor_ecc_init(nor);

0 commit comments

Comments
 (0)