Skip to content

Commit b93f410

Browse files
committed
Merge tag 'spi-nor/for-6.11' into mtd/next
SPI NOR changes for 6.11 Notable changes: - Drop support for Xilinx S3AN flashes. These flashes are for the very old Xilinx Spartan 3 FPGAs and they need some awkward code in the core to support. Drop support for these flashes, along with the special handling we needed for them in the core like non-power-of-2 page size handling and the .setup() callback. - Fix regression for old w25q128 flashes without SFDP tables. Commit 83e824a ("mtd: spi-nor: Correct flags for Winbond w25q128") dropped support for such devices under the assumption that they aren't being used anymore. Users have now surfaced [0] so fix the regression by supporting both kind of devices. - Core cleanups including removal of SPI_NOR_NO_FR flag and simplification of spi_nor_get_flash_info(). [0] https://lore.kernel.org/r/CALxbwRo_-9CaJmt7r7ELgu+vOcgk=xZcGHobnKf=oT2=u4d4aA@mail.gmail.com/ Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
2 parents 2538af0 + d35df77 commit b93f410

File tree

6 files changed

+89
-302
lines changed

6 files changed

+89
-302
lines changed

drivers/mtd/spi-nor/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ spi-nor-objs += micron-st.o
1313
spi-nor-objs += spansion.o
1414
spi-nor-objs += sst.o
1515
spi-nor-objs += winbond.o
16-
spi-nor-objs += xilinx.o
1716
spi-nor-objs += xmc.o
1817
spi-nor-$(CONFIG_DEBUG_FS) += debugfs.o
1918
obj-$(CONFIG_MTD_SPI_NOR) += spi-nor.o

drivers/mtd/spi-nor/core.c

Lines changed: 72 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -1463,23 +1463,13 @@ static void spi_nor_unlock_and_unprep_rd(struct spi_nor *nor, loff_t start, size
14631463
spi_nor_unprep(nor);
14641464
}
14651465

1466-
static u32 spi_nor_convert_addr(struct spi_nor *nor, loff_t addr)
1467-
{
1468-
if (!nor->params->convert_addr)
1469-
return addr;
1470-
1471-
return nor->params->convert_addr(nor, addr);
1472-
}
1473-
14741466
/*
14751467
* Initiate the erasure of a single sector
14761468
*/
14771469
int spi_nor_erase_sector(struct spi_nor *nor, u32 addr)
14781470
{
14791471
int i;
14801472

1481-
addr = spi_nor_convert_addr(nor, addr);
1482-
14831473
if (nor->spimem) {
14841474
struct spi_mem_op op =
14851475
SPI_NOR_SECTOR_ERASE_OP(nor->erase_opcode,
@@ -1986,7 +1976,6 @@ static const struct spi_nor_manufacturer *manufacturers[] = {
19861976
&spi_nor_spansion,
19871977
&spi_nor_sst,
19881978
&spi_nor_winbond,
1989-
&spi_nor_xilinx,
19901979
&spi_nor_xmc,
19911980
};
19921981

@@ -2065,8 +2054,6 @@ static int spi_nor_read(struct mtd_info *mtd, loff_t from, size_t len,
20652054
while (len) {
20662055
loff_t addr = from;
20672056

2068-
addr = spi_nor_convert_addr(nor, addr);
2069-
20702057
ret = spi_nor_read_data(nor, addr, len, buf);
20712058
if (ret == 0) {
20722059
/* We shouldn't see 0-length reads */
@@ -2099,7 +2086,7 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len,
20992086
size_t *retlen, const u_char *buf)
21002087
{
21012088
struct spi_nor *nor = mtd_to_spi_nor(mtd);
2102-
size_t page_offset, page_remain, i;
2089+
size_t i;
21032090
ssize_t ret;
21042091
u32 page_size = nor->params->page_size;
21052092

@@ -2112,23 +2099,9 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len,
21122099
for (i = 0; i < len; ) {
21132100
ssize_t written;
21142101
loff_t addr = to + i;
2115-
2116-
/*
2117-
* If page_size is a power of two, the offset can be quickly
2118-
* calculated with an AND operation. On the other cases we
2119-
* need to do a modulus operation (more expensive).
2120-
*/
2121-
if (is_power_of_2(page_size)) {
2122-
page_offset = addr & (page_size - 1);
2123-
} else {
2124-
u64 aux = addr;
2125-
2126-
page_offset = do_div(aux, page_size);
2127-
}
2102+
size_t page_offset = addr & (page_size - 1);
21282103
/* the size of data remaining on the first page */
2129-
page_remain = min_t(size_t, page_size - page_offset, len - i);
2130-
2131-
addr = spi_nor_convert_addr(nor, addr);
2104+
size_t page_remain = min_t(size_t, page_size - page_offset, len - i);
21322105

21332106
ret = spi_nor_lock_device(nor);
21342107
if (ret)
@@ -2581,8 +2554,51 @@ static int spi_nor_select_erase(struct spi_nor *nor)
25812554
return 0;
25822555
}
25832556

2584-
static int spi_nor_default_setup(struct spi_nor *nor,
2585-
const struct spi_nor_hwcaps *hwcaps)
2557+
static int spi_nor_set_addr_nbytes(struct spi_nor *nor)
2558+
{
2559+
if (nor->params->addr_nbytes) {
2560+
nor->addr_nbytes = nor->params->addr_nbytes;
2561+
} else if (nor->read_proto == SNOR_PROTO_8_8_8_DTR) {
2562+
/*
2563+
* In 8D-8D-8D mode, one byte takes half a cycle to transfer. So
2564+
* in this protocol an odd addr_nbytes cannot be used because
2565+
* then the address phase would only span a cycle and a half.
2566+
* Half a cycle would be left over. We would then have to start
2567+
* the dummy phase in the middle of a cycle and so too the data
2568+
* phase, and we will end the transaction with half a cycle left
2569+
* over.
2570+
*
2571+
* Force all 8D-8D-8D flashes to use an addr_nbytes of 4 to
2572+
* avoid this situation.
2573+
*/
2574+
nor->addr_nbytes = 4;
2575+
} else if (nor->info->addr_nbytes) {
2576+
nor->addr_nbytes = nor->info->addr_nbytes;
2577+
} else {
2578+
nor->addr_nbytes = 3;
2579+
}
2580+
2581+
if (nor->addr_nbytes == 3 && nor->params->size > 0x1000000) {
2582+
/* enable 4-byte addressing if the device exceeds 16MiB */
2583+
nor->addr_nbytes = 4;
2584+
}
2585+
2586+
if (nor->addr_nbytes > SPI_NOR_MAX_ADDR_NBYTES) {
2587+
dev_dbg(nor->dev, "The number of address bytes is too large: %u\n",
2588+
nor->addr_nbytes);
2589+
return -EINVAL;
2590+
}
2591+
2592+
/* Set 4byte opcodes when possible. */
2593+
if (nor->addr_nbytes == 4 && nor->flags & SNOR_F_4B_OPCODES &&
2594+
!(nor->flags & SNOR_F_HAS_4BAIT))
2595+
spi_nor_set_4byte_opcodes(nor);
2596+
2597+
return 0;
2598+
}
2599+
2600+
static int spi_nor_setup(struct spi_nor *nor,
2601+
const struct spi_nor_hwcaps *hwcaps)
25862602
{
25872603
struct spi_nor_flash_parameter *params = nor->params;
25882604
u32 ignored_mask, shared_mask;
@@ -2639,64 +2655,6 @@ static int spi_nor_default_setup(struct spi_nor *nor,
26392655
return err;
26402656
}
26412657

2642-
return 0;
2643-
}
2644-
2645-
static int spi_nor_set_addr_nbytes(struct spi_nor *nor)
2646-
{
2647-
if (nor->params->addr_nbytes) {
2648-
nor->addr_nbytes = nor->params->addr_nbytes;
2649-
} else if (nor->read_proto == SNOR_PROTO_8_8_8_DTR) {
2650-
/*
2651-
* In 8D-8D-8D mode, one byte takes half a cycle to transfer. So
2652-
* in this protocol an odd addr_nbytes cannot be used because
2653-
* then the address phase would only span a cycle and a half.
2654-
* Half a cycle would be left over. We would then have to start
2655-
* the dummy phase in the middle of a cycle and so too the data
2656-
* phase, and we will end the transaction with half a cycle left
2657-
* over.
2658-
*
2659-
* Force all 8D-8D-8D flashes to use an addr_nbytes of 4 to
2660-
* avoid this situation.
2661-
*/
2662-
nor->addr_nbytes = 4;
2663-
} else if (nor->info->addr_nbytes) {
2664-
nor->addr_nbytes = nor->info->addr_nbytes;
2665-
} else {
2666-
nor->addr_nbytes = 3;
2667-
}
2668-
2669-
if (nor->addr_nbytes == 3 && nor->params->size > 0x1000000) {
2670-
/* enable 4-byte addressing if the device exceeds 16MiB */
2671-
nor->addr_nbytes = 4;
2672-
}
2673-
2674-
if (nor->addr_nbytes > SPI_NOR_MAX_ADDR_NBYTES) {
2675-
dev_dbg(nor->dev, "The number of address bytes is too large: %u\n",
2676-
nor->addr_nbytes);
2677-
return -EINVAL;
2678-
}
2679-
2680-
/* Set 4byte opcodes when possible. */
2681-
if (nor->addr_nbytes == 4 && nor->flags & SNOR_F_4B_OPCODES &&
2682-
!(nor->flags & SNOR_F_HAS_4BAIT))
2683-
spi_nor_set_4byte_opcodes(nor);
2684-
2685-
return 0;
2686-
}
2687-
2688-
static int spi_nor_setup(struct spi_nor *nor,
2689-
const struct spi_nor_hwcaps *hwcaps)
2690-
{
2691-
int ret;
2692-
2693-
if (nor->params->setup)
2694-
ret = nor->params->setup(nor, hwcaps);
2695-
else
2696-
ret = spi_nor_default_setup(nor, hwcaps);
2697-
if (ret)
2698-
return ret;
2699-
27002658
return spi_nor_set_addr_nbytes(nor);
27012659
}
27022660

@@ -2965,15 +2923,10 @@ static void spi_nor_init_default_params(struct spi_nor *nor)
29652923
params->page_size = info->page_size ?: SPI_NOR_DEFAULT_PAGE_SIZE;
29662924
params->n_banks = info->n_banks ?: SPI_NOR_DEFAULT_N_BANKS;
29672925

2968-
if (!(info->flags & SPI_NOR_NO_FR)) {
2969-
/* Default to Fast Read for DT and non-DT platform devices. */
2926+
/* Default to Fast Read for non-DT and enable it if requested by DT. */
2927+
if (!np || of_property_read_bool(np, "m25p,fast-read"))
29702928
params->hwcaps.mask |= SNOR_HWCAPS_READ_FAST;
29712929

2972-
/* Mask out Fast Read if not requested at DT instantiation. */
2973-
if (np && !of_property_read_bool(np, "m25p,fast-read"))
2974-
params->hwcaps.mask &= ~SNOR_HWCAPS_READ_FAST;
2975-
}
2976-
29772930
/* (Fast) Read settings. */
29782931
params->hwcaps.mask |= SNOR_HWCAPS_READ;
29792932
spi_nor_set_read_settings(&params->reads[SNOR_CMD_READ],
@@ -3055,7 +3008,14 @@ static int spi_nor_init_params(struct spi_nor *nor)
30553008
spi_nor_init_params_deprecated(nor);
30563009
}
30573010

3058-
return spi_nor_late_init_params(nor);
3011+
ret = spi_nor_late_init_params(nor);
3012+
if (ret)
3013+
return ret;
3014+
3015+
if (WARN_ON(!is_power_of_2(nor->params->page_size)))
3016+
return -EINVAL;
3017+
3018+
return 0;
30593019
}
30603020

30613021
/** spi_nor_set_octal_dtr() - enable or disable Octal DTR I/O.
@@ -3338,32 +3298,28 @@ static const struct flash_info *spi_nor_get_flash_info(struct spi_nor *nor,
33383298

33393299
if (name)
33403300
info = spi_nor_match_name(nor, name);
3341-
/* Try to auto-detect if chip name wasn't specified or not found */
3342-
if (!info)
3343-
return spi_nor_detect(nor);
3344-
33453301
/*
3346-
* If caller has specified name of flash model that can normally be
3347-
* detected using JEDEC, let's verify it.
3302+
* Auto-detect if chip name wasn't specified or not found, or the chip
3303+
* has an ID. If the chip supposedly has an ID, we also do an
3304+
* auto-detection to compare it later.
33483305
*/
3349-
if (name && info->id) {
3306+
if (!info || info->id) {
33503307
const struct flash_info *jinfo;
33513308

33523309
jinfo = spi_nor_detect(nor);
3353-
if (IS_ERR(jinfo)) {
3310+
if (IS_ERR(jinfo))
33543311
return jinfo;
3355-
} else if (jinfo != info) {
3356-
/*
3357-
* JEDEC knows better, so overwrite platform ID. We
3358-
* can't trust partitions any longer, but we'll let
3359-
* mtd apply them anyway, since some partitions may be
3360-
* marked read-only, and we don't want to loose that
3361-
* information, even if it's not 100% accurate.
3362-
*/
3312+
3313+
/*
3314+
* If caller has specified name of flash model that can normally
3315+
* be detected using JEDEC, let's verify it.
3316+
*/
3317+
if (info && jinfo != info)
33633318
dev_warn(nor->dev, "found %s, expected %s\n",
33643319
jinfo->name, info->name);
3365-
info = jinfo;
3366-
}
3320+
3321+
/* If info was set before, JEDEC knows better. */
3322+
info = jinfo;
33673323
}
33683324

33693325
return info;

drivers/mtd/spi-nor/core.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -366,13 +366,6 @@ struct spi_nor_otp {
366366
* @set_octal_dtr: enables or disables SPI NOR octal DTR mode.
367367
* @quad_enable: enables SPI NOR quad mode.
368368
* @set_4byte_addr_mode: puts the SPI NOR in 4 byte addressing mode.
369-
* @convert_addr: converts an absolute address into something the flash
370-
* will understand. Particularly useful when pagesize is
371-
* not a power-of-2.
372-
* @setup: (optional) configures the SPI NOR memory. Useful for
373-
* SPI NOR flashes that have peculiarities to the SPI NOR
374-
* standard e.g. different opcodes, specific address
375-
* calculation, page size, etc.
376369
* @ready: (optional) flashes might use a different mechanism
377370
* than reading the status register to indicate they
378371
* are ready for a new command
@@ -403,8 +396,6 @@ struct spi_nor_flash_parameter {
403396
int (*set_octal_dtr)(struct spi_nor *nor, bool enable);
404397
int (*quad_enable)(struct spi_nor *nor);
405398
int (*set_4byte_addr_mode)(struct spi_nor *nor, bool enable);
406-
u32 (*convert_addr)(struct spi_nor *nor, u32 addr);
407-
int (*setup)(struct spi_nor *nor, const struct spi_nor_hwcaps *hwcaps);
408399
int (*ready)(struct spi_nor *nor);
409400

410401
const struct spi_nor_locking_ops *locking_ops;
@@ -479,7 +470,6 @@ struct spi_nor_id {
479470
* Usually these will power-up in a write-protected
480471
* state.
481472
* SPI_NOR_NO_ERASE: no erase command needed.
482-
* SPI_NOR_NO_FR: can't do fastread.
483473
* SPI_NOR_QUAD_PP: flash supports Quad Input Page Program.
484474
* SPI_NOR_RWW: flash supports reads while write.
485475
*
@@ -528,7 +518,6 @@ struct flash_info {
528518
#define SPI_NOR_BP3_SR_BIT6 BIT(4)
529519
#define SPI_NOR_SWP_IS_VOLATILE BIT(5)
530520
#define SPI_NOR_NO_ERASE BIT(6)
531-
#define SPI_NOR_NO_FR BIT(7)
532521
#define SPI_NOR_QUAD_PP BIT(8)
533522
#define SPI_NOR_RWW BIT(9)
534523

@@ -603,7 +592,6 @@ extern const struct spi_nor_manufacturer spi_nor_st;
603592
extern const struct spi_nor_manufacturer spi_nor_spansion;
604593
extern const struct spi_nor_manufacturer spi_nor_sst;
605594
extern const struct spi_nor_manufacturer spi_nor_winbond;
606-
extern const struct spi_nor_manufacturer spi_nor_xilinx;
607595
extern const struct spi_nor_manufacturer spi_nor_xmc;
608596

609597
extern const struct attribute_group *spi_nor_sysfs_groups[];

drivers/mtd/spi-nor/everspin.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,39 @@ static const struct flash_info everspin_nor_parts[] = {
1414
.size = SZ_16K,
1515
.sector_size = SZ_16K,
1616
.addr_nbytes = 2,
17-
.flags = SPI_NOR_NO_ERASE | SPI_NOR_NO_FR,
17+
.flags = SPI_NOR_NO_ERASE,
1818
}, {
1919
.name = "mr25h256",
2020
.size = SZ_32K,
2121
.sector_size = SZ_32K,
2222
.addr_nbytes = 2,
23-
.flags = SPI_NOR_NO_ERASE | SPI_NOR_NO_FR,
23+
.flags = SPI_NOR_NO_ERASE,
2424
}, {
2525
.name = "mr25h10",
2626
.size = SZ_128K,
2727
.sector_size = SZ_128K,
28-
.flags = SPI_NOR_NO_ERASE | SPI_NOR_NO_FR,
28+
.flags = SPI_NOR_NO_ERASE,
2929
}, {
3030
.name = "mr25h40",
3131
.size = SZ_512K,
3232
.sector_size = SZ_512K,
33-
.flags = SPI_NOR_NO_ERASE | SPI_NOR_NO_FR,
33+
.flags = SPI_NOR_NO_ERASE,
3434
}
3535
};
3636

37+
static void everspin_nor_default_init(struct spi_nor *nor)
38+
{
39+
/* Everspin FRAMs don't support the fast read opcode. */
40+
nor->params->hwcaps.mask &= ~SNOR_HWCAPS_READ_FAST;
41+
}
42+
43+
static const struct spi_nor_fixups everspin_nor_fixups = {
44+
.default_init = everspin_nor_default_init,
45+
};
46+
3747
const struct spi_nor_manufacturer spi_nor_everspin = {
3848
.name = "everspin",
3949
.parts = everspin_nor_parts,
4050
.nparts = ARRAY_SIZE(everspin_nor_parts),
51+
.fixups = &everspin_nor_fixups,
4152
};

drivers/mtd/spi-nor/winbond.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ static const struct flash_info winbond_nor_parts[] = {
105105
}, {
106106
.id = SNOR_ID(0xef, 0x40, 0x18),
107107
.name = "w25q128",
108+
.size = SZ_16M,
108109
.flags = SPI_NOR_HAS_LOCK | SPI_NOR_HAS_TB,
110+
.no_sfdp_flags = SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ,
109111
}, {
110112
.id = SNOR_ID(0xef, 0x40, 0x19),
111113
.name = "w25q256",

0 commit comments

Comments
 (0)