Skip to content

Commit 3f55400

Browse files
Merge tag 'spi-nor/for-5.8' of git://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux into mtd/next
SPI NOR core changes: - add, update support and fix few flashes - prepare BFPT parsing for JESD216 rev D - kernel doc fixes
2 parents a8dfb61 + e8aec15 commit 3f55400

File tree

13 files changed

+134
-56
lines changed

13 files changed

+134
-56
lines changed

drivers/mtd/spi-nor/Kconfig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# SPDX-License-Identifier: GPL-2.0-only
22
menuconfig MTD_SPI_NOR
3-
tristate "SPI-NOR device support"
3+
tristate "SPI NOR device support"
44
depends on MTD
55
depends on MTD && SPI_MASTER
66
select SPI_MEM
77
help
88
This is the framework for the SPI NOR which can be used by the SPI
9-
device drivers and the SPI-NOR device driver.
9+
device drivers and the SPI NOR device driver.
1010

1111
if MTD_SPI_NOR
1212

drivers/mtd/spi-nor/controllers/Kconfig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ config SPI_CADENCE_QUADSPI
2121
Flash as an MTD device.
2222

2323
config SPI_HISI_SFC
24-
tristate "Hisilicon FMC SPI-NOR Flash Controller(SFC)"
24+
tristate "Hisilicon FMC SPI NOR Flash Controller(SFC)"
2525
depends on ARCH_HISI || COMPILE_TEST
2626
depends on HAS_IOMEM
2727
help
28-
This enables support for HiSilicon FMC SPI-NOR flash controller.
28+
This enables support for HiSilicon FMC SPI NOR flash controller.
2929

3030
config SPI_NXP_SPIFI
3131
tristate "NXP SPI Flash Interface (SPIFI)"

drivers/mtd/spi-nor/controllers/aspeed-smc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ static int aspeed_smc_chip_setup_finish(struct aspeed_smc_chip *chip)
727727

728728
/*
729729
* TODO: Adjust clocks if fast read is supported and interpret
730-
* SPI-NOR flags to adjust controller settings.
730+
* SPI NOR flags to adjust controller settings.
731731
*/
732732
if (chip->nor.read_proto == SNOR_PROTO_1_1_1) {
733733
if (chip->nor.read_dummy == 0)

drivers/mtd/spi-nor/controllers/hisi-sfc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// SPDX-License-Identifier: GPL-2.0-or-later
22
/*
3-
* HiSilicon FMC SPI-NOR flash controller driver
3+
* HiSilicon FMC SPI NOR flash controller driver
44
*
55
* Copyright (c) 2015-2016 HiSilicon Technologies Co., Ltd.
66
*/

drivers/mtd/spi-nor/controllers/nxp-spifi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// SPDX-License-Identifier: GPL-2.0-only
22
/*
3-
* SPI-NOR driver for NXP SPI Flash Interface (SPIFI)
3+
* SPI NOR driver for NXP SPI Flash Interface (SPIFI)
44
*
55
* Copyright (C) 2015 Joachim Eastwood <[email protected]>
66
*

drivers/mtd/spi-nor/core.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ int spi_nor_xread_sr(struct spi_nor *nor, u8 *sr)
499499
* the flash is ready for new commands.
500500
* @nor: pointer to 'struct spi_nor'.
501501
*
502-
* Return: 0 on success, -errno otherwise.
502+
* Return: 1 if ready, 0 if not ready, -errno on errors.
503503
*/
504504
static int spi_nor_xsr_ready(struct spi_nor *nor)
505505
{
@@ -542,7 +542,7 @@ static void spi_nor_clear_sr(struct spi_nor *nor)
542542
* for new commands.
543543
* @nor: pointer to 'struct spi_nor'.
544544
*
545-
* Return: 0 on success, -errno otherwise.
545+
* Return: 1 if ready, 0 if not ready, -errno on errors.
546546
*/
547547
static int spi_nor_sr_ready(struct spi_nor *nor)
548548
{
@@ -606,7 +606,7 @@ static void spi_nor_clear_fsr(struct spi_nor *nor)
606606
* ready for new commands.
607607
* @nor: pointer to 'struct spi_nor'.
608608
*
609-
* Return: 0 on success, -errno otherwise.
609+
* Return: 1 if ready, 0 if not ready, -errno on errors.
610610
*/
611611
static int spi_nor_fsr_ready(struct spi_nor *nor)
612612
{
@@ -640,14 +640,14 @@ static int spi_nor_fsr_ready(struct spi_nor *nor)
640640
return -EIO;
641641
}
642642

643-
return nor->bouncebuf[0] & FSR_READY;
643+
return !!(nor->bouncebuf[0] & FSR_READY);
644644
}
645645

646646
/**
647647
* spi_nor_ready() - Query the flash to see if it is ready for new commands.
648648
* @nor: pointer to 'struct spi_nor'.
649649
*
650-
* Return: 0 on success, -errno otherwise.
650+
* Return: 1 if ready, 0 if not ready, -errno on errors.
651651
*/
652652
static int spi_nor_ready(struct spi_nor *nor)
653653
{
@@ -2469,7 +2469,7 @@ static int spi_nor_select_read(struct spi_nor *nor,
24692469
nor->read_proto = read->proto;
24702470

24712471
/*
2472-
* In the spi-nor framework, we don't need to make the difference
2472+
* In the SPI NOR framework, we don't need to make the difference
24732473
* between mode clock cycles and wait state clock cycles.
24742474
* Indeed, the value of the mode clock cycles is used by a QSPI
24752475
* flash memory to know whether it should enter or leave its 0-4-4
@@ -2675,7 +2675,7 @@ static int spi_nor_setup(struct spi_nor *nor,
26752675
/**
26762676
* spi_nor_manufacturer_init_params() - Initialize the flash's parameters and
26772677
* settings based on MFR register and ->default_init() hook.
2678-
* @nor: pointer to a 'struct spi-nor'.
2678+
* @nor: pointer to a 'struct spi_nor'.
26792679
*/
26802680
static void spi_nor_manufacturer_init_params(struct spi_nor *nor)
26812681
{
@@ -2690,7 +2690,7 @@ static void spi_nor_manufacturer_init_params(struct spi_nor *nor)
26902690
/**
26912691
* spi_nor_sfdp_init_params() - Initialize the flash's parameters and settings
26922692
* based on JESD216 SFDP standard.
2693-
* @nor: pointer to a 'struct spi-nor'.
2693+
* @nor: pointer to a 'struct spi_nor'.
26942694
*
26952695
* The method has a roll-back mechanism: in case the SFDP parsing fails, the
26962696
* legacy flash parameters and settings will be restored.
@@ -2712,7 +2712,7 @@ static void spi_nor_sfdp_init_params(struct spi_nor *nor)
27122712
/**
27132713
* spi_nor_info_init_params() - Initialize the flash's parameters and settings
27142714
* based on nor->info data.
2715-
* @nor: pointer to a 'struct spi-nor'.
2715+
* @nor: pointer to a 'struct spi_nor'.
27162716
*/
27172717
static void spi_nor_info_init_params(struct spi_nor *nor)
27182718
{
@@ -2841,7 +2841,7 @@ static void spi_nor_late_init_params(struct spi_nor *nor)
28412841

28422842
/**
28432843
* spi_nor_init_params() - Initialize the flash's parameters and settings.
2844-
* @nor: pointer to a 'struct spi-nor'.
2844+
* @nor: pointer to a 'struct spi_nor'.
28452845
*
28462846
* The flash parameters and settings are initialized based on a sequence of
28472847
* calls that are ordered by priority:
@@ -3126,7 +3126,7 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,
31263126
/*
31273127
* Make sure the XSR_RDY flag is set before calling
31283128
* spi_nor_wait_till_ready(). Xilinx S3AN share MFR
3129-
* with Atmel spi-nor
3129+
* with Atmel SPI NOR.
31303130
*/
31313131
if (info->flags & SPI_NOR_XSR_RDY)
31323132
nor->flags |= SNOR_F_READY_XSR_RDY;

drivers/mtd/spi-nor/macronix.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,16 @@ static const struct flash_info macronix_parts[] = {
6363
.fixups = &mx25l25635_fixups },
6464
{ "mx25u25635f", INFO(0xc22539, 0, 64 * 1024, 512,
6565
SECT_4K | SPI_NOR_4B_OPCODES) },
66+
{ "mx25u51245g", INFO(0xc2253a, 0, 64 * 1024, 1024,
67+
SECT_4K | SPI_NOR_DUAL_READ |
68+
SPI_NOR_QUAD_READ | SPI_NOR_4B_OPCODES) },
6669
{ "mx25v8035f", INFO(0xc22314, 0, 64 * 1024, 16,
6770
SECT_4K | SPI_NOR_DUAL_READ |
6871
SPI_NOR_QUAD_READ) },
6972
{ "mx25l25655e", INFO(0xc22619, 0, 64 * 1024, 512, 0) },
73+
{ "mx25l51245g", INFO(0xc2201a, 0, 64 * 1024, 1024,
74+
SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ |
75+
SPI_NOR_4B_OPCODES) },
7076
{ "mx66l51235l", INFO(0xc2201a, 0, 64 * 1024, 1024,
7177
SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ |
7278
SPI_NOR_4B_OPCODES) },

drivers/mtd/spi-nor/micron-st.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ static const struct flash_info st_parts[] = {
2929
{ "n25q064a", INFO(0x20bb17, 0, 64 * 1024, 128,
3030
SECT_4K | SPI_NOR_QUAD_READ) },
3131
{ "n25q128a11", INFO(0x20bb18, 0, 64 * 1024, 256,
32-
SECT_4K | USE_FSR | SPI_NOR_QUAD_READ) },
32+
SECT_4K | USE_FSR | SPI_NOR_QUAD_READ |
33+
SPI_NOR_HAS_LOCK | SPI_NOR_HAS_TB |
34+
SPI_NOR_4BIT_BP | SPI_NOR_BP3_SR_BIT6) },
3335
{ "n25q128a13", INFO(0x20ba18, 0, 64 * 1024, 256,
3436
SECT_4K | USE_FSR | SPI_NOR_QUAD_READ) },
3537
{ "mt25ql256a", INFO6(0x20ba19, 0x104400, 64 * 1024, 512,
@@ -59,6 +61,8 @@ static const struct flash_info st_parts[] = {
5961
SPI_NOR_4BIT_BP | SPI_NOR_BP3_SR_BIT6) },
6062
{ "n25q00", INFO(0x20ba21, 0, 64 * 1024, 2048,
6163
SECT_4K | USE_FSR | SPI_NOR_QUAD_READ |
64+
SPI_NOR_HAS_LOCK | SPI_NOR_HAS_TB |
65+
SPI_NOR_4BIT_BP | SPI_NOR_BP3_SR_BIT6 |
6266
NO_CHIP_ERASE) },
6367
{ "n25q00a", INFO(0x20bb21, 0, 64 * 1024, 2048,
6468
SECT_4K | USE_FSR | SPI_NOR_QUAD_READ |

drivers/mtd/spi-nor/sfdp.c

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@
2121
#define SFDP_4BAIT_ID 0xff84 /* 4-byte Address Instruction Table */
2222

2323
#define SFDP_SIGNATURE 0x50444653U
24-
#define SFDP_JESD216_MAJOR 1
25-
#define SFDP_JESD216_MINOR 0
26-
#define SFDP_JESD216A_MINOR 5
27-
#define SFDP_JESD216B_MINOR 6
2824

2925
struct sfdp_header {
3026
u32 signature; /* Ox50444653U <=> "SFDP" */
@@ -437,7 +433,7 @@ static int spi_nor_parse_bfpt(struct spi_nor *nor,
437433
struct sfdp_bfpt bfpt;
438434
size_t len;
439435
int i, cmd, err;
440-
u32 addr;
436+
u32 addr, val;
441437
u16 half;
442438
u8 erase_mask;
443439

@@ -460,6 +456,7 @@ static int spi_nor_parse_bfpt(struct spi_nor *nor,
460456
/* Number of address bytes. */
461457
switch (bfpt.dwords[BFPT_DWORD(1)] & BFPT_DWORD1_ADDRESS_BYTES_MASK) {
462458
case BFPT_DWORD1_ADDRESS_BYTES_3_ONLY:
459+
case BFPT_DWORD1_ADDRESS_BYTES_3_OR_4:
463460
nor->addr_width = 3;
464461
break;
465462

@@ -472,21 +469,21 @@ static int spi_nor_parse_bfpt(struct spi_nor *nor,
472469
}
473470

474471
/* Flash Memory Density (in bits). */
475-
params->size = bfpt.dwords[BFPT_DWORD(2)];
476-
if (params->size & BIT(31)) {
477-
params->size &= ~BIT(31);
472+
val = bfpt.dwords[BFPT_DWORD(2)];
473+
if (val & BIT(31)) {
474+
val &= ~BIT(31);
478475

479476
/*
480477
* Prevent overflows on params->size. Anyway, a NOR of 2^64
481478
* bits is unlikely to exist so this error probably means
482479
* the BFPT we are reading is corrupted/wrong.
483480
*/
484-
if (params->size > 63)
481+
if (val > 63)
485482
return -EINVAL;
486483

487-
params->size = 1ULL << params->size;
484+
params->size = 1ULL << val;
488485
} else {
489-
params->size++;
486+
params->size = val + 1;
490487
}
491488
params->size >>= 3; /* Convert to bytes. */
492489

@@ -548,15 +545,15 @@ static int spi_nor_parse_bfpt(struct spi_nor *nor,
548545
SNOR_ERASE_TYPE_MASK;
549546

550547
/* Stop here if not JESD216 rev A or later. */
551-
if (bfpt_header->length < BFPT_DWORD_MAX)
548+
if (bfpt_header->length == BFPT_DWORD_MAX_JESD216)
552549
return spi_nor_post_bfpt_fixups(nor, bfpt_header, &bfpt,
553550
params);
554551

555552
/* Page size: this field specifies 'N' so the page size = 2^N bytes. */
556-
params->page_size = bfpt.dwords[BFPT_DWORD(11)];
557-
params->page_size &= BFPT_DWORD11_PAGE_SIZE_MASK;
558-
params->page_size >>= BFPT_DWORD11_PAGE_SIZE_SHIFT;
559-
params->page_size = 1U << params->page_size;
553+
val = bfpt.dwords[BFPT_DWORD(11)];
554+
val &= BFPT_DWORD11_PAGE_SIZE_MASK;
555+
val >>= BFPT_DWORD11_PAGE_SIZE_SHIFT;
556+
params->page_size = 1U << val;
560557

561558
/* Quad Enable Requirements. */
562559
switch (bfpt.dwords[BFPT_DWORD(15)] & BFPT_DWORD15_QER_MASK) {
@@ -604,6 +601,11 @@ static int spi_nor_parse_bfpt(struct spi_nor *nor,
604601
return -EINVAL;
605602
}
606603

604+
/* Stop here if not JESD216 rev C or later. */
605+
if (bfpt_header->length == BFPT_DWORD_MAX_JESD216B)
606+
return spi_nor_post_bfpt_fixups(nor, bfpt_header, &bfpt,
607+
params);
608+
607609
return spi_nor_post_bfpt_fixups(nor, bfpt_header, &bfpt, params);
608610
}
609611

drivers/mtd/spi-nor/sfdp.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,28 @@
77
#ifndef __LINUX_MTD_SFDP_H
88
#define __LINUX_MTD_SFDP_H
99

10+
/* SFDP revisions */
11+
#define SFDP_JESD216_MAJOR 1
12+
#define SFDP_JESD216_MINOR 0
13+
#define SFDP_JESD216A_MINOR 5
14+
#define SFDP_JESD216B_MINOR 6
15+
1016
/* Basic Flash Parameter Table */
1117

1218
/*
13-
* JESD216 rev B defines a Basic Flash Parameter Table of 16 DWORDs.
19+
* JESD216 rev D defines a Basic Flash Parameter Table of 20 DWORDs.
1420
* They are indexed from 1 but C arrays are indexed from 0.
1521
*/
1622
#define BFPT_DWORD(i) ((i) - 1)
17-
#define BFPT_DWORD_MAX 16
23+
#define BFPT_DWORD_MAX 20
1824

1925
struct sfdp_bfpt {
2026
u32 dwords[BFPT_DWORD_MAX];
2127
};
2228

2329
/* The first version of JESD216 defined only 9 DWORDs. */
2430
#define BFPT_DWORD_MAX_JESD216 9
31+
#define BFPT_DWORD_MAX_JESD216B 16
2532

2633
/* 1st DWORD. */
2734
#define BFPT_DWORD1_FAST_READ_1_1_2 BIT(16)

0 commit comments

Comments
 (0)