Skip to content

Commit a34506e

Browse files
committed
Merge tag 'spi-nor/for-6.2' into mtd/next
SPI NOR core changes: * Add support for flash reset using the dt reset-gpios property. * Update hwcaps.mask to include 8D-8D-8D read and page program ops when xSPI profile 1.0 table is defined. * Bypass zero erase size in spi_nor_find_best_erase_type(). * Fix select_uniform_erase to skip 0 erase size * Add generic flash driver. If a flash is not found in the flash_info array, fall back to the generic flash driver which is described solely by the flash's SFDP tables. * Fix the number of bytes for the dummy cycles in spi_nor_spimem_check_readop(). * Introduce SPI_NOR_QUAD_PP flag, as PP_1_1_4 is not SFDP discoverable. SPI NOR manufacturer drivers changes: * Spansion: - use PARSE_SFDP for s28hs512t, - add support for s28hl512t, s28hl01gt, and s28hs01gt. * Gigadevice: Replace default_init() with post_bfpt() for gd25q256. * Micron - ST: Enable locking for mt25qu256a. * Winbond: Add support for W25Q512NW-IQ. * ISSI: Use PARSE_SFDP and SPI_NOR_QUAD_PP. Fix merge conflict in the jedec,spi-nor bindings. Signed-off-by: Miquel Raynal <[email protected]>
2 parents 1d46f1a + 1799cd8 commit a34506e

File tree

14 files changed

+228
-45
lines changed

14 files changed

+228
-45
lines changed

Documentation/ABI/testing/sysfs-bus-spi-devices-spi-nor

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,19 @@ Contact: [email protected]
55
Description: (RO) The JEDEC ID of the SPI NOR flash as reported by the
66
flash device.
77

8+
The attribute is not present if the flash doesn't support
9+
the "Read JEDEC ID" command (9Fh). This is the case for
10+
non-JEDEC compliant flashes.
811

912
What: /sys/bus/spi/devices/.../spi-nor/manufacturer
1013
Date: April 2021
1114
KernelVersion: 5.14
1215
1316
Description: (RO) Manufacturer of the SPI NOR flash.
1417

18+
The attribute is not present if the flash device isn't
19+
known to the kernel and is only probed by its SFDP
20+
tables.
1521

1622
What: /sys/bus/spi/devices/.../spi-nor/partname
1723
Date: April 2021

Documentation/devicetree/bindings/mtd/jedec,spi-nor.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,17 @@ properties:
7070
be used on such systems, to denote the absence of a reliable reset
7171
mechanism.
7272

73+
reset-gpios:
74+
description:
75+
A GPIO line connected to the RESET (active low) signal of the device.
76+
If "broken-flash-reset" is present then having this property does not
77+
make any difference.
78+
7379
unevaluatedProperties: false
7480

7581
examples:
7682
- |
83+
#include <dt-bindings/gpio/gpio.h>
7784
spi {
7885
#address-cells = <1>;
7986
#size-cells = <0>;
@@ -83,6 +90,7 @@ examples:
8390
reg = <0>;
8491
spi-max-frequency = <40000000>;
8592
m25p,fast-read;
93+
reset-gpios = <&gpio 12 GPIO_ACTIVE_LOW>;
8694
};
8795
};
8896
...

drivers/mtd/spi-nor/core.c

Lines changed: 80 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,6 +1184,8 @@ spi_nor_find_best_erase_type(const struct spi_nor_erase_map *map,
11841184
continue;
11851185

11861186
erase = &map->erase_type[i];
1187+
if (!erase->size)
1188+
continue;
11871189

11881190
/* Alignment is not mandatory for overlaid regions */
11891191
if (region->offset & SNOR_OVERLAID_REGION &&
@@ -1632,6 +1634,16 @@ static const struct spi_nor_manufacturer *manufacturers[] = {
16321634
&spi_nor_xmc,
16331635
};
16341636

1637+
static const struct flash_info spi_nor_generic_flash = {
1638+
.name = "spi-nor-generic",
1639+
/*
1640+
* JESD216 rev A doesn't specify the page size, therefore we need a
1641+
* sane default.
1642+
*/
1643+
.page_size = 256,
1644+
.parse_sfdp = true,
1645+
};
1646+
16351647
static const struct flash_info *spi_nor_match_id(struct spi_nor *nor,
16361648
const u8 *id)
16371649
{
@@ -1664,7 +1676,20 @@ static const struct flash_info *spi_nor_detect(struct spi_nor *nor)
16641676
return ERR_PTR(ret);
16651677
}
16661678

1679+
/* Cache the complete flash ID. */
1680+
nor->id = devm_kmemdup(nor->dev, id, SPI_NOR_MAX_ID_LEN, GFP_KERNEL);
1681+
if (!nor->id)
1682+
return ERR_PTR(-ENOMEM);
1683+
16671684
info = spi_nor_match_id(nor, id);
1685+
1686+
/* Fallback to a generic flash described only by its SFDP data. */
1687+
if (!info) {
1688+
ret = spi_nor_check_sfdp_signature(nor);
1689+
if (!ret)
1690+
info = &spi_nor_generic_flash;
1691+
}
1692+
16681693
if (!info) {
16691694
dev_err(nor->dev, "unrecognized JEDEC id bytes: %*ph\n",
16701695
SPI_NOR_MAX_ID_LEN, id);
@@ -1914,7 +1939,8 @@ static int spi_nor_spimem_check_readop(struct spi_nor *nor,
19141939
spi_nor_spimem_setup_op(nor, &op, read->proto);
19151940

19161941
/* convert the dummy cycles to the number of bytes */
1917-
op.dummy.nbytes = (nor->read_dummy * op.dummy.buswidth) / 8;
1942+
op.dummy.nbytes = (read->num_mode_clocks + read->num_wait_states) *
1943+
op.dummy.buswidth / 8;
19181944
if (spi_nor_protocol_is_dtr(nor->read_proto))
19191945
op.dummy.nbytes *= 2;
19201946

@@ -2091,8 +2117,12 @@ static int spi_nor_select_pp(struct spi_nor *nor,
20912117
* spi_nor_select_uniform_erase() - select optimum uniform erase type
20922118
* @map: the erase map of the SPI NOR
20932119
* @wanted_size: the erase type size to search for. Contains the value of
2094-
* info->sector_size or of the "small sector" size in case
2095-
* CONFIG_MTD_SPI_NOR_USE_4K_SECTORS is defined.
2120+
* info->sector_size, the "small sector" size in case
2121+
* CONFIG_MTD_SPI_NOR_USE_4K_SECTORS is defined or 0 if
2122+
* there is no information about the sector size. The
2123+
* latter is the case if the flash parameters are parsed
2124+
* solely by SFDP, then the largest supported erase type
2125+
* is selected.
20962126
*
20972127
* Once the optimum uniform sector erase command is found, disable all the
20982128
* other.
@@ -2113,6 +2143,10 @@ spi_nor_select_uniform_erase(struct spi_nor_erase_map *map,
21132143

21142144
tested_erase = &map->erase_type[i];
21152145

2146+
/* Skip masked erase types. */
2147+
if (!tested_erase->size)
2148+
continue;
2149+
21162150
/*
21172151
* If the current erase size is the one, stop here:
21182152
* we have found the right uniform Sector Erase command.
@@ -2565,6 +2599,12 @@ static void spi_nor_init_default_params(struct spi_nor *nor)
25652599
params->hwcaps.mask |= SNOR_HWCAPS_PP;
25662600
spi_nor_set_pp_settings(&params->page_programs[SNOR_CMD_PP],
25672601
SPINOR_OP_PP, SNOR_PROTO_1_1_1);
2602+
2603+
if (info->flags & SPI_NOR_QUAD_PP) {
2604+
params->hwcaps.mask |= SNOR_HWCAPS_PP_1_1_4;
2605+
spi_nor_set_pp_settings(&params->page_programs[SNOR_CMD_PP_1_1_4],
2606+
SPINOR_OP_PP_1_1_4, SNOR_PROTO_1_1_4);
2607+
}
25682608
}
25692609

25702610
/**
@@ -2840,10 +2880,20 @@ static void spi_nor_put_device(struct mtd_info *mtd)
28402880

28412881
void spi_nor_restore(struct spi_nor *nor)
28422882
{
2883+
int ret;
2884+
28432885
/* restore the addressing mode */
28442886
if (nor->addr_nbytes == 4 && !(nor->flags & SNOR_F_4B_OPCODES) &&
2845-
nor->flags & SNOR_F_BROKEN_RESET)
2846-
nor->params->set_4byte_addr_mode(nor, false);
2887+
nor->flags & SNOR_F_BROKEN_RESET) {
2888+
ret = nor->params->set_4byte_addr_mode(nor, false);
2889+
if (ret)
2890+
/*
2891+
* Do not stop the execution in the hope that the flash
2892+
* will default to the 3-byte address mode after the
2893+
* software reset.
2894+
*/
2895+
dev_err(nor->dev, "Failed to exit 4-byte address mode, err = %d\n", ret);
2896+
}
28472897

28482898
if (nor->flags & SNOR_F_SOFT_RESET)
28492899
spi_nor_soft_reset(nor);
@@ -2935,6 +2985,27 @@ static void spi_nor_set_mtd_info(struct spi_nor *nor)
29352985
mtd->_put_device = spi_nor_put_device;
29362986
}
29372987

2988+
static int spi_nor_hw_reset(struct spi_nor *nor)
2989+
{
2990+
struct gpio_desc *reset;
2991+
2992+
reset = devm_gpiod_get_optional(nor->dev, "reset", GPIOD_OUT_LOW);
2993+
if (IS_ERR_OR_NULL(reset))
2994+
return PTR_ERR_OR_ZERO(reset);
2995+
2996+
/*
2997+
* Experimental delay values by looking at different flash device
2998+
* vendors datasheets.
2999+
*/
3000+
usleep_range(1, 5);
3001+
gpiod_set_value_cansleep(reset, 1);
3002+
usleep_range(100, 150);
3003+
gpiod_set_value_cansleep(reset, 0);
3004+
usleep_range(1000, 1200);
3005+
3006+
return 0;
3007+
}
3008+
29383009
int spi_nor_scan(struct spi_nor *nor, const char *name,
29393010
const struct spi_nor_hwcaps *hwcaps)
29403011
{
@@ -2967,6 +3038,10 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,
29673038
if (!nor->bouncebuf)
29683039
return -ENOMEM;
29693040

3041+
ret = spi_nor_hw_reset(nor);
3042+
if (ret)
3043+
return ret;
3044+
29703045
info = spi_nor_get_flash_info(nor, name);
29713046
if (IS_ERR(info))
29723047
return PTR_ERR(info);

drivers/mtd/spi-nor/core.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,7 @@ struct spi_nor_fixups {
458458
* SPI_NOR_NO_ERASE: no erase command needed.
459459
* NO_CHIP_ERASE: chip does not support chip erase.
460460
* SPI_NOR_NO_FR: can't do fastread.
461+
* SPI_NOR_QUAD_PP: flash supports Quad Input Page Program.
461462
*
462463
* @no_sfdp_flags: flags that indicate support that can be discovered via SFDP.
463464
* Used when SFDP tables are not defined in the flash. These
@@ -507,6 +508,7 @@ struct flash_info {
507508
#define SPI_NOR_NO_ERASE BIT(6)
508509
#define NO_CHIP_ERASE BIT(7)
509510
#define SPI_NOR_NO_FR BIT(8)
511+
#define SPI_NOR_QUAD_PP BIT(9)
510512

511513
u8 no_sfdp_flags;
512514
#define SPI_NOR_SKIP_SFDP BIT(0)
@@ -701,6 +703,9 @@ int spi_nor_controller_ops_read_reg(struct spi_nor *nor, u8 opcode,
701703
int spi_nor_controller_ops_write_reg(struct spi_nor *nor, u8 opcode,
702704
const u8 *buf, size_t len);
703705

706+
int spi_nor_check_sfdp_signature(struct spi_nor *nor);
707+
int spi_nor_parse_sfdp(struct spi_nor *nor);
708+
704709
static inline struct spi_nor *mtd_to_spi_nor(struct mtd_info *mtd)
705710
{
706711
return container_of(mtd, struct spi_nor, mtd);

drivers/mtd/spi-nor/debugfs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ static int spi_nor_params_show(struct seq_file *s, void *data)
8181
int i;
8282

8383
seq_printf(s, "name\t\t%s\n", info->name);
84-
seq_printf(s, "id\t\t%*ph\n", info->id_len, info->id);
84+
seq_printf(s, "id\t\t%*ph\n", SPI_NOR_MAX_ID_LEN, nor->id);
8585
string_get_size(params->size, 1, STRING_UNITS_2, buf, sizeof(buf));
8686
seq_printf(s, "size\t\t%s\n", buf);
8787
seq_printf(s, "write size\t%u\n", params->writesize);

drivers/mtd/spi-nor/gigadevice.c

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,29 @@
88

99
#include "core.h"
1010

11-
static void gd25q256_default_init(struct spi_nor *nor)
11+
static int
12+
gd25q256_post_bfpt(struct spi_nor *nor,
13+
const struct sfdp_parameter_header *bfpt_header,
14+
const struct sfdp_bfpt *bfpt)
1215
{
1316
/*
14-
* Some manufacturer like GigaDevice may use different
15-
* bit to set QE on different memories, so the MFR can't
16-
* indicate the quad_enable method for this case, we need
17-
* to set it in the default_init fixup hook.
17+
* GD25Q256C supports the first version of JESD216 which does not define
18+
* the Quad Enable methods. Overwrite the default Quad Enable method.
19+
*
20+
* GD25Q256 GENERATION | SFDP MAJOR VERSION | SFDP MINOR VERSION
21+
* GD25Q256C | SFDP_JESD216_MAJOR | SFDP_JESD216_MINOR
22+
* GD25Q256D | SFDP_JESD216_MAJOR | SFDP_JESD216B_MINOR
23+
* GD25Q256E | SFDP_JESD216_MAJOR | SFDP_JESD216B_MINOR
1824
*/
19-
nor->params->quad_enable = spi_nor_sr1_bit6_quad_enable;
25+
if (bfpt_header->major == SFDP_JESD216_MAJOR &&
26+
bfpt_header->minor == SFDP_JESD216_MINOR)
27+
nor->params->quad_enable = spi_nor_sr1_bit6_quad_enable;
28+
29+
return 0;
2030
}
2131

2232
static const struct spi_nor_fixups gd25q256_fixups = {
23-
.default_init = gd25q256_default_init,
33+
.post_bfpt = gd25q256_post_bfpt,
2434
};
2535

2636
static const struct flash_info gigadevice_nor_parts[] = {

drivers/mtd/spi-nor/issi.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,10 @@ static const struct flash_info issi_nor_parts[] = {
7070
NO_SFDP_FLAGS(SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) },
7171
{ "is25wp128", INFO(0x9d7018, 0, 64 * 1024, 256)
7272
NO_SFDP_FLAGS(SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) },
73-
{ "is25wp256", INFO(0x9d7019, 0, 64 * 1024, 512)
74-
NO_SFDP_FLAGS(SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ)
73+
{ "is25wp256", INFO(0x9d7019, 0, 0, 0)
74+
PARSE_SFDP
7575
FIXUP_FLAGS(SPI_NOR_4B_OPCODES)
76+
FLAGS(SPI_NOR_QUAD_PP)
7677
.fixups = &is25lp256_fixups },
7778

7879
/* PMC */

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,21 @@ static int micron_st_nor_octal_dtr_en(struct spi_nor *nor)
5252
struct spi_mem_op op;
5353
u8 *buf = nor->bouncebuf;
5454
int ret;
55+
u8 addr_mode_nbytes = nor->params->addr_mode_nbytes;
5556

5657
/* Use 20 dummy cycles for memory array reads. */
5758
*buf = 20;
5859
op = (struct spi_mem_op)
59-
MICRON_ST_NOR_WR_ANY_REG_OP(3, SPINOR_REG_MT_CFR1V, 1, buf);
60+
MICRON_ST_NOR_WR_ANY_REG_OP(addr_mode_nbytes,
61+
SPINOR_REG_MT_CFR1V, 1, buf);
6062
ret = spi_nor_write_any_volatile_reg(nor, &op, nor->reg_proto);
6163
if (ret)
6264
return ret;
6365

6466
buf[0] = SPINOR_MT_OCT_DTR;
6567
op = (struct spi_mem_op)
66-
MICRON_ST_NOR_WR_ANY_REG_OP(3, SPINOR_REG_MT_CFR0V, 1, buf);
68+
MICRON_ST_NOR_WR_ANY_REG_OP(addr_mode_nbytes,
69+
SPINOR_REG_MT_CFR0V, 1, buf);
6770
ret = spi_nor_write_any_volatile_reg(nor, &op, nor->reg_proto);
6871
if (ret)
6972
return ret;
@@ -98,7 +101,8 @@ static int micron_st_nor_octal_dtr_dis(struct spi_nor *nor)
98101
buf[0] = SPINOR_MT_EXSPI;
99102
buf[1] = SPINOR_REG_MT_CFR1V_DEF;
100103
op = (struct spi_mem_op)
101-
MICRON_ST_NOR_WR_ANY_REG_OP(4, SPINOR_REG_MT_CFR0V, 2, buf);
104+
MICRON_ST_NOR_WR_ANY_REG_OP(nor->addr_nbytes,
105+
SPINOR_REG_MT_CFR0V, 2, buf);
102106
ret = spi_nor_write_any_volatile_reg(nor, &op, SNOR_PROTO_8_8_8_DTR);
103107
if (ret)
104108
return ret;
@@ -201,6 +205,8 @@ static const struct flash_info st_nor_parts[] = {
201205
MFR_FLAGS(USE_FSR)
202206
},
203207
{ "mt25qu256a", INFO6(0x20bb19, 0x104400, 64 * 1024, 512)
208+
FLAGS(SPI_NOR_HAS_LOCK | SPI_NOR_HAS_TB | SPI_NOR_4BIT_BP |
209+
SPI_NOR_BP3_SR_BIT6)
204210
NO_SFDP_FLAGS(SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ)
205211
FIXUP_FLAGS(SPI_NOR_4B_OPCODES)
206212
MFR_FLAGS(USE_FSR)

drivers/mtd/spi-nor/sfdp.c

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,7 @@ struct sfdp_4bait {
135135
/**
136136
* spi_nor_read_raw() - raw read of serial flash memory. read_opcode,
137137
* addr_nbytes and read_dummy members of the struct spi_nor
138-
* should be previously
139-
* set.
138+
* should be previously set.
140139
* @nor: pointer to a 'struct spi_nor'
141140
* @addr: offset in the serial flash memory
142141
* @len: number of bytes to read
@@ -1183,10 +1182,17 @@ static int spi_nor_parse_profile1(struct spi_nor *nor,
11831182
dummy = round_up(dummy, 2);
11841183

11851184
/* Update the fast read settings. */
1185+
nor->params->hwcaps.mask |= SNOR_HWCAPS_READ_8_8_8_DTR;
11861186
spi_nor_set_read_settings(&nor->params->reads[SNOR_CMD_READ_8_8_8_DTR],
11871187
0, dummy, opcode,
11881188
SNOR_PROTO_8_8_8_DTR);
11891189

1190+
/*
1191+
* Page Program is "Required Command" in the xSPI Profile 1.0. Update
1192+
* the params->hwcaps.mask here.
1193+
*/
1194+
nor->params->hwcaps.mask |= SNOR_HWCAPS_PP_8_8_8_DTR;
1195+
11901196
out:
11911197
kfree(dwords);
11921198
return ret;
@@ -1249,6 +1255,33 @@ static void spi_nor_post_sfdp_fixups(struct spi_nor *nor)
12491255
nor->info->fixups->post_sfdp(nor);
12501256
}
12511257

1258+
/**
1259+
* spi_nor_check_sfdp_signature() - check for a valid SFDP signature
1260+
* @nor: pointer to a 'struct spi_nor'
1261+
*
1262+
* Used to detect if the flash supports the RDSFDP command as well as the
1263+
* presence of a valid SFDP table.
1264+
*
1265+
* Return: 0 on success, -errno otherwise.
1266+
*/
1267+
int spi_nor_check_sfdp_signature(struct spi_nor *nor)
1268+
{
1269+
u32 signature;
1270+
int err;
1271+
1272+
/* Get the SFDP header. */
1273+
err = spi_nor_read_sfdp_dma_unsafe(nor, 0, sizeof(signature),
1274+
&signature);
1275+
if (err < 0)
1276+
return err;
1277+
1278+
/* Check the SFDP signature. */
1279+
if (le32_to_cpu(signature) != SFDP_SIGNATURE)
1280+
return -EINVAL;
1281+
1282+
return 0;
1283+
}
1284+
12521285
/**
12531286
* spi_nor_parse_sfdp() - parse the Serial Flash Discoverable Parameters.
12541287
* @nor: pointer to a 'struct spi_nor'

0 commit comments

Comments
 (0)