Skip to content

Commit

Permalink
mtd: spi-nor: Avoid updating the flash_info struct in dual and stacke…
Browse files Browse the repository at this point in the history
…d modes

flash_info structure is declared as const by default but the const
declaration is removed to support dual parallel and stacked modes where
page size, sector size and number of sectors information updating in
the flash_info structure based on the connection mode.
This patch avoid/removed updating page size, sector size and number of
sectors information in the flash_info structure and bring back the const
declaration to the flash_info structures.
Based on the 'isparallel' and 'isstacked' flags, page size, sector size
and number of sectors information is handled wherever they are being used.

Signed-off-by: Sai Krishna Potthuri <lakshmi.sai.krishna.potthuri@xilinx.com>
  • Loading branch information
Sai Krishna Potthuri authored and Michal Simek committed Mar 9, 2022
1 parent fd48054 commit 9c7d4b0
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 21 deletions.
37 changes: 26 additions & 11 deletions drivers/mtd/spi-nor/core.c
Expand Up @@ -1361,12 +1361,17 @@ static bool spi_nor_has_uniform_erase(const struct spi_nor *nor)

static void spi_nor_set_4byte_opcodes(struct spi_nor *nor)
{
u32 sector_size = nor->info->sector_size;

/* Do some manufacturer fixups first */
switch (nor->jedec_id) {
case CFI_MFR_AMD:
/* No small sector erase for 4-byte command set */
nor->erase_opcode = SPINOR_OP_SE;
nor->mtd.erasesize = nor->info->sector_size;
if (nor->isparallel)
sector_size <<= 1;

nor->mtd.erasesize = sector_size;
break;
default:
break;
Expand Down Expand Up @@ -2689,6 +2694,9 @@ static int spi_nor_select_erase(struct spi_nor *nor)
u32 wanted_size = nor->info->sector_size;
int i;

if (nor->isparallel)
wanted_size <<= 1;

if (mtd->erasesize &&
nor->jedec_id != CFI_MFR_AMD)
return 0;
Expand Down Expand Up @@ -2853,6 +2861,9 @@ static void spi_nor_info_init_params(struct spi_nor *nor)
const struct flash_info *info = nor->info;
struct device_node *np = spi_nor_get_flash_node(nor);
u8 i, erase_mask;
u32 n_sectors = info->n_sectors;
u32 sector_size = info->sector_size;
u32 page_size = info->page_size;

/* Initialize default flash parameters and settings. */
params->quad_enable = spi_nor_sr2_bit1_quad_enable;
Expand All @@ -2865,8 +2876,16 @@ static void spi_nor_info_init_params(struct spi_nor *nor)

/* Set SPI NOR sizes. */
params->writesize = 1;
params->size = (u64)info->sector_size * info->n_sectors;
params->page_size = info->page_size;
if (nor->isstacked)
n_sectors <<= 1;

if (nor->isparallel) {
sector_size <<= 1;
page_size <<= 1;
}

params->size = (u64)sector_size * n_sectors;
params->page_size = page_size;

if (!(info->flags & SPI_NOR_NO_FR)) {
/* Default to Fast Read for DT and non-DT platform devices. */
Expand Down Expand Up @@ -2949,7 +2968,7 @@ static void spi_nor_info_init_params(struct spi_nor *nor)
i++;
}
erase_mask |= BIT(i);
spi_nor_set_erase_type(&map->erase_type[i], info->sector_size,
spi_nor_set_erase_type(&map->erase_type[i], sector_size,
SPINOR_OP_SE);
spi_nor_init_uniform_erase_map(map, erase_mask, params->size);
}
Expand Down Expand Up @@ -3480,7 +3499,7 @@ static const struct flash_info *spi_nor_get_flash_info(struct spi_nor *nor,
int spi_nor_scan(struct spi_nor *nor, const char *name,
const struct spi_nor_hwcaps *hwcaps)
{
struct flash_info *info = NULL;
const struct flash_info *info = NULL;
struct device *dev = nor->dev;
struct mtd_info *mtd = &nor->mtd;
struct device_node *np = spi_nor_get_flash_node(nor);
Expand Down Expand Up @@ -3512,7 +3531,7 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,
if (!nor->bouncebuf)
return -ENOMEM;

info = (struct flash_info *)spi_nor_get_flash_info(nor, name);
info = spi_nor_get_flash_info(nor, name);
if (IS_ERR(info))
return PTR_ERR(info);

Expand Down Expand Up @@ -3574,9 +3593,7 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,
if (is_dual == 1) {
/* dual parallel */
nor->shift = 1;
info->sector_size <<= nor->shift;
info->page_size <<= nor->shift;
nor->page_size = info->page_size;
nor->page_size = info->page_size << nor->shift;
mtd->size <<= nor->shift;
nor->isparallel = 1;
nor->isstacked = 0;
Expand All @@ -3588,7 +3605,6 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,
/* dual stacked */
nor->shift = 0;
mtd->size <<= 1;
info->n_sectors <<= 1;
nor->isstacked = 1;
nor->isparallel = 0;
#else
Expand All @@ -3603,7 +3619,6 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,
/* dual stacked */
nor->shift = 0;
mtd->size <<= 1;
info->n_sectors <<= 1;
nor->isstacked = 1;
nor->isparallel = 0;
} else {
Expand Down
2 changes: 1 addition & 1 deletion drivers/mtd/spi-nor/issi.c
Expand Up @@ -159,7 +159,7 @@ static struct spi_nor_fixups is25lp256_fixups = {
.post_bfpt = is25lp256_post_bfpt_fixups,
};

static struct flash_info issi_parts[] = {
static const struct flash_info issi_parts[] = {
/* ISSI */
{ "is25wp080d", INFO(0x9d7014, 0, 64 * 1024, 32, SECT_4K |
SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ | SPI_NOR_HAS_LOCK) },
Expand Down
8 changes: 6 additions & 2 deletions drivers/mtd/spi-nor/macronix.c
Expand Up @@ -83,6 +83,7 @@ static int mx25um51345g_set_4byte(struct spi_nor *nor, bool enable)
static void mx25um51345g_default_init_fixups(struct spi_nor *nor)
{
u8 id_byte1, id_byte2;
u32 sector_size = nor->info->sector_size;

nor->params->set_4byte_addr_mode = mx25um51345g_set_4byte;

Expand All @@ -99,8 +100,11 @@ static void mx25um51345g_default_init_fixups(struct spi_nor *nor)
nor->spimem->device_id[4] = id_byte2;
nor->spimem->device_id[5] = id_byte2;

if (nor->isparallel)
sector_size <<= 1;

spi_nor_set_erase_type(&nor->params->erase_map.erase_type[1],
nor->info->sector_size, SPINOR_OP_BE_4K_4B);
sector_size, SPINOR_OP_BE_4K_4B);
nor->params->page_programs[SNOR_CMD_PP_8_8_8_DTR].opcode =
SPINOR_OP_PP_4B;

Expand Down Expand Up @@ -156,7 +160,7 @@ static struct spi_nor_fixups mx25l25635_fixups = {
.post_bfpt = mx25l25635_post_bfpt_fixups,
};

static struct flash_info macronix_parts[] = {
static const struct flash_info macronix_parts[] = {
/* Macronix */
{ "mx25l512e", INFO(0xc22010, 0, 64 * 1024, 1, SECT_4K) },
{ "mx25l2005a", INFO(0xc22012, 0, 64 * 1024, 4, SECT_4K) },
Expand Down
2 changes: 1 addition & 1 deletion drivers/mtd/spi-nor/micron-st.c
Expand Up @@ -143,7 +143,7 @@ static const struct flash_info micron_parts[] = {
.fixups = &mt35xu512aba_fixups},
};

static struct flash_info st_parts[] = {
static const struct flash_info st_parts[] = {
{ "n25q016a", INFO(0x20bb15, 0, 64 * 1024, 32,
SECT_4K | SPI_NOR_QUAD_READ) },
{ "n25q032", INFO(0x20ba16, 0, 64 * 1024, 64,
Expand Down
9 changes: 7 additions & 2 deletions drivers/mtd/spi-nor/spansion.c
Expand Up @@ -194,7 +194,7 @@ static struct spi_nor_fixups s25fs_s_fixups = {
.post_bfpt = s25fs_s_post_bfpt_fixups,
};

static struct flash_info spansion_parts[] = {
static const struct flash_info spansion_parts[] = {
/* Spansion/Cypress -- single (large) sector size only, at least
* for the chips listed here (without boot sectors).
*/
Expand Down Expand Up @@ -278,13 +278,18 @@ static struct flash_info spansion_parts[] = {

static void spansion_post_sfdp_fixups(struct spi_nor *nor)
{
u32 sector_size = nor->info->sector_size;

if (nor->params->size <= SZ_16M)
return;

if (nor->isparallel)
sector_size <<= 1;

nor->flags |= SNOR_F_4B_OPCODES;
/* No small sector erase for 4-byte command set */
nor->erase_opcode = SPINOR_OP_SE;
nor->mtd.erasesize = nor->info->sector_size;
nor->mtd.erasesize = sector_size;
}

static const struct spi_nor_fixups spansion_fixups = {
Expand Down
14 changes: 11 additions & 3 deletions drivers/mtd/spi-nor/swp.c
Expand Up @@ -37,16 +37,24 @@ static u64 spi_nor_get_min_prot_length_sr(struct spi_nor *nor)
{
unsigned int bp_slots, bp_slots_needed;
u8 mask = spi_nor_get_sr_bp_mask(nor);
u32 n_sectors = nor->info->n_sectors;
u32 sector_size = nor->info->sector_size;

if (nor->isstacked)
n_sectors <<= 1;

if (nor->isparallel)
sector_size <<= 1;

/* Reserved one for "protect none" and one for "protect all". */
bp_slots = (1 << hweight8(mask)) - 2;
bp_slots_needed = ilog2(nor->info->n_sectors);
bp_slots_needed = ilog2(n_sectors);

if (bp_slots_needed > bp_slots)
return nor->info->sector_size <<
return sector_size <<
(bp_slots_needed - bp_slots);
else
return nor->info->sector_size;
return sector_size;
}

static void spi_nor_get_locked_range_sr(struct spi_nor *nor, u8 sr, loff_t *ofs,
Expand Down
2 changes: 1 addition & 1 deletion drivers/mtd/spi-nor/winbond.c
Expand Up @@ -32,7 +32,7 @@ static struct spi_nor_fixups w25q256_fixups = {
.post_bfpt = w25q256_post_bfpt_fixups,
};

static struct flash_info winbond_parts[] = {
static const struct flash_info winbond_parts[] = {
/* Winbond -- w25x "blocks" are 64K, "sectors" are 4KiB */
{ "w25x05", INFO(0xef3010, 0, 64 * 1024, 1, SECT_4K) },
{ "w25x10", INFO(0xef3011, 0, 64 * 1024, 2, SECT_4K) },
Expand Down

0 comments on commit 9c7d4b0

Please sign in to comment.