Skip to content

Commit a6b50aa

Browse files
Kuwano-sanambarus
authored andcommitted
mtd: spi-nor: spansion: Add local function to discover page size
The page size check in s28hs512t fixup can be used for s25hs/hl-t as well. Move that to a newly created local function. Signed-off-by: Takahiro Kuwano <Takahiro.Kuwano@infineon.com> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com> Reviewed-by: Michael Walle <michael@walle.cc> Link: https://lore.kernel.org/r/20220725092505.446315-7-tudor.ambarus@microchip.com
1 parent d7931a2 commit a6b50aa

File tree

1 file changed

+31
-22
lines changed

1 file changed

+31
-22
lines changed

drivers/mtd/spi-nor/spansion.c

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,36 @@ static int cypress_nor_octal_dtr_dis(struct spi_nor *nor)
113113
return 0;
114114
}
115115

116+
/**
117+
* cypress_nor_set_page_size() - Set page size which corresponds to the flash
118+
* configuration.
119+
* @nor: pointer to a 'struct spi_nor'
120+
*
121+
* The BFPT table advertises a 512B or 256B page size depending on part but the
122+
* page size is actually configurable (with the default being 256B). Read from
123+
* CFR3V[4] and set the correct size.
124+
*
125+
* Return: 0 on success, -errno otherwise.
126+
*/
127+
static int cypress_nor_set_page_size(struct spi_nor *nor)
128+
{
129+
struct spi_mem_op op =
130+
CYPRESS_NOR_RD_ANY_REG_OP(3, SPINOR_REG_CYPRESS_CFR3V,
131+
nor->bouncebuf);
132+
int ret;
133+
134+
ret = spi_nor_read_any_reg(nor, &op, nor->reg_proto);
135+
if (ret)
136+
return ret;
137+
138+
if (nor->bouncebuf[0] & SPINOR_REG_CYPRESS_CFR3V_PGSZ)
139+
nor->params->page_size = 512;
140+
else
141+
nor->params->page_size = 256;
142+
143+
return 0;
144+
}
145+
116146
/**
117147
* cypress_nor_octal_dtr_enable() - Enable octal DTR on Cypress flashes.
118148
* @nor: pointer to a 'struct spi_nor'
@@ -167,28 +197,7 @@ static int s28hs512t_post_bfpt_fixup(struct spi_nor *nor,
167197
const struct sfdp_parameter_header *bfpt_header,
168198
const struct sfdp_bfpt *bfpt)
169199
{
170-
/*
171-
* The BFPT table advertises a 512B page size but the page size is
172-
* actually configurable (with the default being 256B). Read from
173-
* CFR3V[4] and set the correct size.
174-
*/
175-
struct spi_mem_op op =
176-
CYPRESS_NOR_RD_ANY_REG_OP(3, SPINOR_REG_CYPRESS_CFR3V,
177-
nor->bouncebuf);
178-
int ret;
179-
180-
spi_nor_spimem_setup_op(nor, &op, nor->reg_proto);
181-
182-
ret = spi_mem_exec_op(nor->spimem, &op);
183-
if (ret)
184-
return ret;
185-
186-
if (nor->bouncebuf[0] & SPINOR_REG_CYPRESS_CFR3V_PGSZ)
187-
nor->params->page_size = 512;
188-
else
189-
nor->params->page_size = 256;
190-
191-
return 0;
200+
return cypress_nor_set_page_size(nor);
192201
}
193202

194203
static const struct spi_nor_fixups s28hs512t_fixups = {

0 commit comments

Comments
 (0)