1 From c03c545e064a81515fe109ddcc4ecb3895528e58 Mon Sep 17 00:00:00 2001
2 From: Yangbo Lu <yangbo.lu@nxp.com>
3 Date: Fri, 6 Jul 2018 15:32:05 +0800
4 Subject: [PATCH] mtd: spi-nor: support layerscape
6 This is an integrated patch for layerscape qspi support.
8 Signed-off-by: Suresh Gupta <suresh.gupta@nxp.com>
9 Signed-off-by: Yunhui Cui <B56489@freescale.com>
10 Signed-off-by: mar.krzeminski <mar.krzeminski@gmail.com>
11 Signed-off-by: Alison Wang <b18965@freescale.com>
12 Signed-off-by: Nobuhiro Iwamatsu <nobuhiro.iwamatsu.kw@hitachi.com>
13 Signed-off-by: LABBE Corentin <clabbe.montjoie@gmail.com>
14 Signed-off-by: Yuan Yao <yao.yuan@nxp.com>
15 Signed-off-by: Alexander Kurz <akurz@blala.de>
16 Signed-off-by: L. D. Pinney <ldpinney@gmail.com>
17 Signed-off-by: Ash Benz <ash.benz@bk.ru>
18 Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
20 drivers/mtd/devices/m25p80.c | 3 +-
21 drivers/mtd/mtdchar.c | 2 +-
22 drivers/mtd/spi-nor/fsl-quadspi.c | 327 ++++++++++++++++++++++++------
23 drivers/mtd/spi-nor/spi-nor.c | 141 ++++++++++++-
24 include/linux/mtd/spi-nor.h | 14 +-
25 5 files changed, 416 insertions(+), 71 deletions(-)
27 --- a/drivers/mtd/mtdchar.c
28 +++ b/drivers/mtd/mtdchar.c
29 @@ -455,7 +455,7 @@ static int mtdchar_readoob(struct file *
30 * data. For our userspace tools it is important to dump areas
32 * For kernel internal usage it also might return -EUCLEAN
33 - * to signal the caller that a bitflip has occured and has
34 + * to signal the caller that a bitflip has occurred and has
35 * been corrected by the ECC algorithm.
37 * Note: currently the standard NAND function, nand_read_oob_std,
38 --- a/drivers/mtd/spi-nor/fsl-quadspi.c
39 +++ b/drivers/mtd/spi-nor/fsl-quadspi.c
41 #define QUADSPI_QUIRK_TKT253890 (1 << 2)
42 /* Controller cannot wake up from wait mode, TKT245618 */
43 #define QUADSPI_QUIRK_TKT245618 (1 << 3)
44 +/* QSPI_AMBA_BASE is internally added by SOC design */
45 +#define QUADSPI_AMBA_BASE_INTERNAL (0x10000)
48 #define QUADSPI_MCR 0x00
50 #define QUADSPI_LUT_NUM 64
52 /* SEQID -- we can have 16 seqids at most. */
53 -#define SEQID_QUAD_READ 0
62 +#define SEQID_RDAR_OR_RD_EVCR 12
63 +#define SEQID_WRAR 13
64 +#define SEQID_WD_EVCR 14
66 #define QUADSPI_MIN_IOMAP SZ_4M
68 +#define FLASH_VENDOR_SPANSION_FS "s25fs"
69 +#define SPANSION_S25FS_FAMILY (1 << 1)
71 enum fsl_qspi_devtype {
77 + FSL_QUADSPI_LS2080A,
80 struct fsl_qspi_devtype_data {
81 @@ -224,7 +233,7 @@ struct fsl_qspi_devtype_data {
85 -static struct fsl_qspi_devtype_data vybrid_data = {
86 +static const struct fsl_qspi_devtype_data vybrid_data = {
87 .devtype = FSL_QUADSPI_VYBRID,
90 @@ -232,7 +241,7 @@ static struct fsl_qspi_devtype_data vybr
91 .driver_data = QUADSPI_QUIRK_SWAP_ENDIAN,
94 -static struct fsl_qspi_devtype_data imx6sx_data = {
95 +static const struct fsl_qspi_devtype_data imx6sx_data = {
96 .devtype = FSL_QUADSPI_IMX6SX,
99 @@ -241,7 +250,7 @@ static struct fsl_qspi_devtype_data imx6
100 | QUADSPI_QUIRK_TKT245618,
103 -static struct fsl_qspi_devtype_data imx7d_data = {
104 +static const struct fsl_qspi_devtype_data imx7d_data = {
105 .devtype = FSL_QUADSPI_IMX7D,
108 @@ -250,7 +259,7 @@ static struct fsl_qspi_devtype_data imx7
109 | QUADSPI_QUIRK_4X_INT_CLK,
112 -static struct fsl_qspi_devtype_data imx6ul_data = {
113 +static const struct fsl_qspi_devtype_data imx6ul_data = {
114 .devtype = FSL_QUADSPI_IMX6UL,
117 @@ -267,6 +276,14 @@ static struct fsl_qspi_devtype_data ls10
121 +static struct fsl_qspi_devtype_data ls2080a_data = {
122 + .devtype = FSL_QUADSPI_LS2080A,
125 + .ahb_buf_size = 1024,
126 + .driver_data = QUADSPI_AMBA_BASE_INTERNAL | QUADSPI_QUIRK_TKT253890,
129 #define FSL_QSPI_MAX_CHIP 4
131 struct spi_nor nor[FSL_QSPI_MAX_CHIP];
132 @@ -282,6 +299,7 @@ struct fsl_qspi {
137 unsigned int chip_base_addr; /* We may support two chips. */
138 bool has_second_chip;
140 @@ -309,6 +327,23 @@ static inline int needs_wakeup_wait_mode
141 return q->devtype_data->driver_data & QUADSPI_QUIRK_TKT245618;
144 +static inline int has_added_amba_base_internal(struct fsl_qspi *q)
146 + return q->devtype_data->driver_data & QUADSPI_AMBA_BASE_INTERNAL;
149 +static u32 fsl_get_nor_vendor(struct spi_nor *nor)
154 + if (memcmp(nor->vendor, FLASH_VENDOR_SPANSION_FS,
155 + sizeof(FLASH_VENDOR_SPANSION_FS) - 1))
156 + vendor_id = SPANSION_S25FS_FAMILY;
162 * R/W functions for big- or little-endian registers:
163 * The qSPI controller's endian is independent of the CPU core's endian.
164 @@ -331,6 +366,31 @@ static u32 qspi_readl(struct fsl_qspi *q
165 return ioread32(addr);
168 +static inline u32 *u8tou32(u32 *dest, const u8 *src, size_t n)
174 + for (i = 0; i < n; i++)
175 + *dest |= *src++ << i * 8;
181 +static inline u8 *u32tou8(u8 *dest, const u32 *src, size_t n)
187 + for (i = 0; i < n; i++)
188 + *xdest++ = *src >> i * 8;
194 * An IC bug makes us to re-arrange the 32-bit data.
195 * The following chips, such as IMX6SLX, have fixed this bug.
196 @@ -373,8 +433,15 @@ static void fsl_qspi_init_lut(struct fsl
197 void __iomem *base = q->iobase;
198 int rxfifo = q->devtype_data->rxfifo;
200 - u8 cmd, addrlen, dummy;
204 + struct spi_nor *nor = &q->nor[0];
205 + u8 addrlen = (nor->addr_width == 3) ? ADDR24BIT : ADDR32BIT;
206 + u8 read_op = nor->read_opcode;
207 + u8 read_dm = nor->read_dummy;
209 + vendor = fsl_get_nor_vendor(nor);
211 fsl_qspi_unlock_lut(q);
213 @@ -382,24 +449,50 @@ static void fsl_qspi_init_lut(struct fsl
214 for (i = 0; i < QUADSPI_LUT_NUM; i++)
215 qspi_writel(q, 0, base + QUADSPI_LUT_BASE + i * 4);
218 - lut_base = SEQID_QUAD_READ * 4;
220 + lut_base = SEQID_READ * 4;
222 - if (q->nor_size <= SZ_16M) {
223 - cmd = SPINOR_OP_READ_1_1_4;
224 - addrlen = ADDR24BIT;
227 - /* use the 4-byte address */
228 - cmd = SPINOR_OP_READ_1_1_4;
229 - addrlen = ADDR32BIT;
233 - qspi_writel(q, LUT0(CMD, PAD1, cmd) | LUT1(ADDR, PAD1, addrlen),
234 + if (nor->flash_read == SPI_NOR_FAST) {
235 + qspi_writel(q, LUT0(CMD, PAD1, read_op) |
236 + LUT1(ADDR, PAD1, addrlen),
237 + base + QUADSPI_LUT(lut_base));
238 + qspi_writel(q, LUT0(DUMMY, PAD1, read_dm) |
239 + LUT1(FSL_READ, PAD1, rxfifo),
240 + base + QUADSPI_LUT(lut_base + 1));
241 + } else if (nor->flash_read == SPI_NOR_QUAD) {
242 + if (q->nor_size == 0x4000000) {
245 + LUT0(CMD, PAD1, read_op) | LUT1(ADDR, PAD4, addrlen),
246 base + QUADSPI_LUT(lut_base));
247 - qspi_writel(q, LUT0(DUMMY, PAD1, dummy) | LUT1(FSL_READ, PAD4, rxfifo),
249 + LUT0(MODE, PAD4, 0xff) | LUT1(DUMMY, PAD4, read_dm),
250 base + QUADSPI_LUT(lut_base + 1));
252 + LUT0(FSL_READ, PAD4, rxfifo),
253 + base + QUADSPI_LUT(lut_base + 2));
255 + qspi_writel(q, LUT0(CMD, PAD1, read_op) |
256 + LUT1(ADDR, PAD1, addrlen),
257 + base + QUADSPI_LUT(lut_base));
258 + qspi_writel(q, LUT0(DUMMY, PAD1, read_dm) |
259 + LUT1(FSL_READ, PAD4, rxfifo),
260 + base + QUADSPI_LUT(lut_base + 1));
262 + } else if (nor->flash_read == SPI_NOR_DDR_QUAD) {
263 + /* read mode : 1-4-4, such as Spansion s25fl128s. */
264 + qspi_writel(q, LUT0(CMD, PAD1, read_op)
265 + | LUT1(ADDR_DDR, PAD4, addrlen),
266 + base + QUADSPI_LUT(lut_base));
268 + qspi_writel(q, LUT0(MODE_DDR, PAD4, 0xff)
269 + | LUT1(DUMMY, PAD1, read_dm),
270 + base + QUADSPI_LUT(lut_base + 1));
272 + qspi_writel(q, LUT0(FSL_READ_DDR, PAD4, rxfifo)
273 + | LUT1(JMP_ON_CS, PAD1, 0),
274 + base + QUADSPI_LUT(lut_base + 2));
278 lut_base = SEQID_WREN * 4;
279 @@ -409,16 +502,8 @@ static void fsl_qspi_init_lut(struct fsl
281 lut_base = SEQID_PP * 4;
283 - if (q->nor_size <= SZ_16M) {
284 - cmd = SPINOR_OP_PP;
285 - addrlen = ADDR24BIT;
287 - /* use the 4-byte address */
288 - cmd = SPINOR_OP_PP;
289 - addrlen = ADDR32BIT;
292 - qspi_writel(q, LUT0(CMD, PAD1, cmd) | LUT1(ADDR, PAD1, addrlen),
293 + qspi_writel(q, LUT0(CMD, PAD1, nor->program_opcode) |
294 + LUT1(ADDR, PAD1, addrlen),
295 base + QUADSPI_LUT(lut_base));
296 qspi_writel(q, LUT0(FSL_WRITE, PAD1, 0),
297 base + QUADSPI_LUT(lut_base + 1));
298 @@ -432,10 +517,8 @@ static void fsl_qspi_init_lut(struct fsl
300 lut_base = SEQID_SE * 4;
302 - cmd = q->nor[0].erase_opcode;
303 - addrlen = q->nor_size <= SZ_16M ? ADDR24BIT : ADDR32BIT;
305 - qspi_writel(q, LUT0(CMD, PAD1, cmd) | LUT1(ADDR, PAD1, addrlen),
306 + qspi_writel(q, LUT0(CMD, PAD1, nor->erase_opcode) |
307 + LUT1(ADDR, PAD1, addrlen),
308 base + QUADSPI_LUT(lut_base));
310 /* Erase the whole chip */
311 @@ -476,6 +559,44 @@ static void fsl_qspi_init_lut(struct fsl
312 qspi_writel(q, LUT0(CMD, PAD1, SPINOR_OP_BRWR),
313 base + QUADSPI_LUT(lut_base));
317 + * Flash Micron and Spansion command confilict
318 + * use the same value 0x65. But it indicates different meaning.
320 + lut_base = SEQID_RDAR_OR_RD_EVCR * 4;
322 + if (vendor == SPANSION_S25FS_FAMILY) {
324 + * Read any device register.
325 + * Used for Spansion S25FS-S family flash only.
327 + qspi_writel(q, LUT0(CMD, PAD1, SPINOR_OP_SPANSION_RDAR) |
328 + LUT1(ADDR, PAD1, ADDR24BIT),
329 + base + QUADSPI_LUT(lut_base));
330 + qspi_writel(q, LUT0(DUMMY, PAD1, 8) | LUT1(FSL_READ, PAD1, 1),
331 + base + QUADSPI_LUT(lut_base + 1));
333 + qspi_writel(q, LUT0(CMD, PAD1, SPINOR_OP_RD_EVCR),
334 + base + QUADSPI_LUT(lut_base));
338 + * Write any device register.
339 + * Used for Spansion S25FS-S family flash only.
341 + lut_base = SEQID_WRAR * 4;
342 + qspi_writel(q, LUT0(CMD, PAD1, SPINOR_OP_SPANSION_WRAR) |
343 + LUT1(ADDR, PAD1, ADDR24BIT),
344 + base + QUADSPI_LUT(lut_base));
345 + qspi_writel(q, LUT0(FSL_WRITE, PAD1, 1),
346 + base + QUADSPI_LUT(lut_base + 1));
348 + /* Write EVCR register */
349 + lut_base = SEQID_WD_EVCR * 4;
350 + qspi_writel(q, LUT0(CMD, PAD1, SPINOR_OP_WD_EVCR),
351 + base + QUADSPI_LUT(lut_base));
353 fsl_qspi_lock_lut(q);
356 @@ -483,8 +604,24 @@ static void fsl_qspi_init_lut(struct fsl
357 static int fsl_qspi_get_seqid(struct fsl_qspi *q, u8 cmd)
360 + case SPINOR_OP_READ_1_4_4_D:
361 + case SPINOR_OP_READ4_1_4_4_D:
362 + case SPINOR_OP_READ4_1_1_4:
363 case SPINOR_OP_READ_1_1_4:
364 - return SEQID_QUAD_READ;
365 + case SPINOR_OP_READ_FAST:
366 + case SPINOR_OP_READ4_FAST:
369 + * Spansion & Micron use the same command value 0x65
370 + * Spansion: SPINOR_OP_SPANSION_RDAR, read any register.
371 + * Micron: SPINOR_OP_RD_EVCR,
372 + * read enhanced volatile configuration register.
373 + * case SPINOR_OP_RD_EVCR:
375 + case SPINOR_OP_SPANSION_RDAR:
376 + return SEQID_RDAR_OR_RD_EVCR;
377 + case SPINOR_OP_SPANSION_WRAR:
382 @@ -496,6 +633,7 @@ static int fsl_qspi_get_seqid(struct fsl
383 case SPINOR_OP_CHIP_ERASE:
384 return SEQID_CHIP_ERASE;
386 + case SPINOR_OP_PP_4B:
390 @@ -507,6 +645,8 @@ static int fsl_qspi_get_seqid(struct fsl
394 + case SPINOR_OP_WD_EVCR:
395 + return SEQID_WD_EVCR;
397 if (cmd == q->nor[0].erase_opcode)
399 @@ -531,8 +671,11 @@ fsl_qspi_runcmd(struct fsl_qspi *q, u8 c
401 reg = qspi_readl(q, base + QUADSPI_MCR);
403 - qspi_writel(q, q->memmap_phy + q->chip_base_addr + addr,
404 - base + QUADSPI_SFAR);
405 + if (has_added_amba_base_internal(q))
406 + qspi_writel(q, q->chip_base_addr + addr, base + QUADSPI_SFAR);
408 + qspi_writel(q, q->memmap_phy + q->chip_base_addr + addr,
409 + base + QUADSPI_SFAR);
410 qspi_writel(q, QUADSPI_RBCT_WMRK_MASK | QUADSPI_RBCT_RXBRD_USEIPS,
411 base + QUADSPI_RBCT);
412 qspi_writel(q, reg | QUADSPI_MCR_CLR_RXF_MASK, base + QUADSPI_MCR);
413 @@ -582,10 +725,10 @@ static void fsl_qspi_read_data(struct fs
414 q->chip_base_addr, tmp);
417 - *((u32 *)rxbuf) = tmp;
418 + u32tou8(rxbuf, &tmp, 4);
421 - memcpy(rxbuf, &tmp, len);
422 + u32tou8(rxbuf, &tmp, len);
426 @@ -619,11 +762,12 @@ static inline void fsl_qspi_invalid(stru
429 static ssize_t fsl_qspi_nor_write(struct fsl_qspi *q, struct spi_nor *nor,
430 - u8 opcode, unsigned int to, u32 *txbuf,
431 + u8 opcode, unsigned int to, u8 *txbuf,
438 dev_dbg(q->dev, "to 0x%.8x:0x%.8x, len : %d\n",
439 q->chip_base_addr, to, count);
440 @@ -633,10 +777,13 @@ static ssize_t fsl_qspi_nor_write(struct
441 qspi_writel(q, tmp | QUADSPI_MCR_CLR_TXF_MASK, q->iobase + QUADSPI_MCR);
443 /* fill the TX data to the FIFO */
445 for (j = 0, i = ((count + 3) / 4); j < i; j++) {
446 - tmp = fsl_qspi_endian_xchg(q, *txbuf);
447 + u8tou32(&tmp, txbuf, byts);
448 + tmp = fsl_qspi_endian_xchg(q, tmp);
449 qspi_writel(q, tmp, q->iobase + QUADSPI_TBDR);
455 /* fill the TXFIFO upto 16 bytes for i.MX7d */
456 @@ -657,11 +804,43 @@ static void fsl_qspi_set_map_addr(struct
458 int nor_size = q->nor_size;
459 void __iomem *base = q->iobase;
462 + if (has_added_amba_base_internal(q))
465 + mem_base = q->memmap_phy;
467 + qspi_writel(q, nor_size + mem_base, base + QUADSPI_SFA1AD);
468 + qspi_writel(q, nor_size * 2 + mem_base, base + QUADSPI_SFA2AD);
469 + qspi_writel(q, nor_size * 3 + mem_base, base + QUADSPI_SFB1AD);
470 + qspi_writel(q, nor_size * 4 + mem_base, base + QUADSPI_SFB2AD);
474 + * enable controller ddr quad mode to support different
475 + * vender flashes ddr quad mode.
477 +static void set_ddr_quad_mode(struct fsl_qspi *q)
481 + reg = qspi_readl(q, q->iobase + QUADSPI_MCR);
483 + /* Firstly, disable the module */
484 + qspi_writel(q, reg | QUADSPI_MCR_MDIS_MASK, q->iobase + QUADSPI_MCR);
486 + /* Set the Sampling Register for DDR */
487 + reg2 = qspi_readl(q, q->iobase + QUADSPI_SMPR);
488 + reg2 &= ~QUADSPI_SMPR_DDRSMP_MASK;
489 + reg2 |= (((q->ddr_smp) << QUADSPI_SMPR_DDRSMP_SHIFT) &
490 + QUADSPI_SMPR_DDRSMP_MASK);
491 + qspi_writel(q, reg2, q->iobase + QUADSPI_SMPR);
493 + /* Enable the module again (enable the DDR too) */
494 + reg |= QUADSPI_MCR_DDR_EN_MASK;
495 + qspi_writel(q, reg, q->iobase + QUADSPI_MCR);
497 - qspi_writel(q, nor_size + q->memmap_phy, base + QUADSPI_SFA1AD);
498 - qspi_writel(q, nor_size * 2 + q->memmap_phy, base + QUADSPI_SFA2AD);
499 - qspi_writel(q, nor_size * 3 + q->memmap_phy, base + QUADSPI_SFB1AD);
500 - qspi_writel(q, nor_size * 4 + q->memmap_phy, base + QUADSPI_SFB2AD);
504 @@ -704,6 +883,11 @@ static void fsl_qspi_init_abh_read(struc
505 seqid = fsl_qspi_get_seqid(q, q->nor[0].read_opcode);
506 qspi_writel(q, seqid << QUADSPI_BFGENCR_SEQID_SHIFT,
507 q->iobase + QUADSPI_BFGENCR);
509 + /* enable the DDR quad read */
510 + if (q->nor->flash_read == SPI_NOR_DDR_QUAD)
511 + set_ddr_quad_mode(q);
515 /* This function was used to prepare and enable QSPI clock */
516 @@ -822,6 +1006,7 @@ static const struct of_device_id fsl_qsp
517 { .compatible = "fsl,imx7d-qspi", .data = (void *)&imx7d_data, },
518 { .compatible = "fsl,imx6ul-qspi", .data = (void *)&imx6ul_data, },
519 { .compatible = "fsl,ls1021a-qspi", .data = (void *)&ls1021a_data, },
520 + { .compatible = "fsl,ls2080a-qspi", .data = (void *)&ls2080a_data, },
523 MODULE_DEVICE_TABLE(of, fsl_qspi_dt_ids);
524 @@ -835,8 +1020,12 @@ static int fsl_qspi_read_reg(struct spi_
527 struct fsl_qspi *q = nor->priv;
530 - ret = fsl_qspi_runcmd(q, opcode, 0, len);
531 + if (opcode == SPINOR_OP_SPANSION_RDAR)
532 + u8tou32(&to, nor->cmd_buf, 4);
534 + ret = fsl_qspi_runcmd(q, opcode, to, len);
538 @@ -848,9 +1037,13 @@ static int fsl_qspi_write_reg(struct spi
540 struct fsl_qspi *q = nor->priv;
544 + if (opcode == SPINOR_OP_SPANSION_WRAR)
545 + u8tou32(&to, nor->cmd_buf, 4);
548 - ret = fsl_qspi_runcmd(q, opcode, 0, 1);
549 + ret = fsl_qspi_runcmd(q, opcode, to, 1);
553 @@ -859,7 +1052,7 @@ static int fsl_qspi_write_reg(struct spi
555 } else if (len > 0) {
556 ret = fsl_qspi_nor_write(q, nor, opcode, 0,
562 @@ -875,7 +1068,7 @@ static ssize_t fsl_qspi_write(struct spi
564 struct fsl_qspi *q = nor->priv;
565 ssize_t ret = fsl_qspi_nor_write(q, nor, nor->program_opcode, to,
569 /* invalid the data in the AHB buffer. */
571 @@ -922,7 +1115,7 @@ static ssize_t fsl_qspi_read(struct spi_
574 /* Read out the data directly from the AHB buffer.*/
575 - memcpy(buf, q->ahb_addr + q->chip_base_addr + from - q->memmap_offs,
576 + memcpy_toio(buf, q->ahb_addr + q->chip_base_addr + from - q->memmap_offs,
580 @@ -980,6 +1173,8 @@ static int fsl_qspi_probe(struct platfor
582 struct mtd_info *mtd;
585 + enum read_mode mode = SPI_NOR_QUAD;
587 q = devm_kzalloc(dev, sizeof(*q), GFP_KERNEL);
589 @@ -1027,6 +1222,12 @@ static int fsl_qspi_probe(struct platfor
593 + /* find ddrsmp value */
594 + ret = of_property_read_u32(dev->of_node, "fsl,ddr-sampling-point",
600 ret = platform_get_irq(pdev, 0);
602 @@ -1050,6 +1251,7 @@ static int fsl_qspi_probe(struct platfor
604 mutex_init(&q->lock);
607 /* iterate the subnodes. */
608 for_each_available_child_of_node(dev->of_node, np) {
610 @@ -1076,18 +1278,25 @@ static int fsl_qspi_probe(struct platfor
611 ret = of_property_read_u32(np, "spi-max-frequency",
617 /* set the chip address for READID */
618 fsl_qspi_set_base_addr(q, nor);
620 - ret = spi_nor_scan(nor, NULL, SPI_NOR_QUAD);
621 + ret = of_property_read_bool(np, "m25p,fast-read");
622 + mode = (ret) ? SPI_NOR_FAST : SPI_NOR_QUAD;
623 + /* Can we enable the DDR Quad Read? */
624 + ret = of_property_read_bool(np, "ddr-quad-read");
627 + mode = SPI_NOR_DDR_QUAD;
629 + ret = spi_nor_scan(nor, NULL, mode);
633 ret = mtd_device_register(mtd, NULL, 0);
638 /* Set the correct NOR size now. */
639 if (q->nor_size == 0) {
640 @@ -1110,8 +1319,12 @@ static int fsl_qspi_probe(struct platfor
641 nor->page_size = q->devtype_data->txfifo;
647 + if (find_node == 0)
650 /* finish the rest init. */
651 ret = fsl_qspi_nor_setup_last(q);
653 --- a/drivers/mtd/spi-nor/spi-nor.c
654 +++ b/drivers/mtd/spi-nor/spi-nor.c
656 #define SPI_NOR_MAX_ID_LEN 6
657 #define SPI_NOR_MAX_ADDR_WIDTH 4
659 +#define SPI_NOR_MICRON_WRITE_ENABLE 0x7f
660 +/* Added for S25FS-S family flash */
661 +#define SPINOR_CONFIG_REG3_OFFSET 0x800004
662 +#define CR3V_4KB_ERASE_UNABLE 0x8
663 +#define SPINOR_S25FS_FAMILY_ID 0x81
669 @@ -68,7 +75,8 @@ struct flash_info {
670 #define SECT_4K_PMC BIT(4) /* SPINOR_OP_BE_4K_PMC works uniformly */
671 #define SPI_NOR_DUAL_READ BIT(5) /* Flash supports Dual Read */
672 #define SPI_NOR_QUAD_READ BIT(6) /* Flash supports Quad Read */
673 -#define USE_FSR BIT(7) /* use flag status register */
674 +#define USE_FSR BIT(13) /* use flag status register */
675 +#define SPI_NOR_DDR_QUAD_READ BIT(7) /* Flash supports DDR Quad Read */
676 #define SPI_NOR_HAS_LOCK BIT(8) /* Flash supports lock/unlock via SR */
677 #define SPI_NOR_HAS_TB BIT(9) /*
678 * Flash SR has Top/Bottom (TB) protect
679 @@ -85,9 +93,11 @@ struct flash_info {
680 * Use dedicated 4byte address op codes
681 * to support memory size above 128Mib.
683 +#define NO_CHIP_ERASE BIT(12) /* Chip does not support chip erase */
686 #define JEDEC_MFR(info) ((info)->id[0])
687 +#define EXT_ID(info) ((info)->id[5])
689 static const struct flash_info *spi_nor_match_id(const char *name);
691 @@ -132,7 +142,7 @@ static int read_fsr(struct spi_nor *nor)
693 * Read configuration register, returning its value in the
694 * location. Return the configuration register value.
695 - * Returns negative if error occured.
696 + * Returns negative if error occurred.
698 static int read_cr(struct spi_nor *nor)
700 @@ -160,6 +170,8 @@ static inline int spi_nor_read_dummy_cyc
704 + case SPI_NOR_DDR_QUAD:
709 @@ -962,6 +974,8 @@ static const struct flash_info spi_nor_i
712 { "f25l32pa", INFO(0x8c2016, 0, 64 * 1024, 64, SECT_4K | SPI_NOR_HAS_LOCK) },
713 + { "f25l32qa", INFO(0x8c4116, 0, 64 * 1024, 64, SECT_4K | SPI_NOR_HAS_LOCK) },
714 + { "f25l64qa", INFO(0x8c4117, 0, 64 * 1024, 128, SECT_4K | SPI_NOR_HAS_LOCK) },
717 { "mr25h256", CAT25_INFO( 32 * 1024, 1, 256, 2, SPI_NOR_NO_ERASE | SPI_NOR_NO_FR) },
718 @@ -1015,12 +1029,15 @@ static const struct flash_info spi_nor_i
719 { "mx25l3205d", INFO(0xc22016, 0, 64 * 1024, 64, SECT_4K) },
720 { "mx25l3255e", INFO(0xc29e16, 0, 64 * 1024, 64, SECT_4K) },
721 { "mx25l6405d", INFO(0xc22017, 0, 64 * 1024, 128, SECT_4K) },
722 + { "mx25u2033e", INFO(0xc22532, 0, 64 * 1024, 4, SECT_4K) },
723 + { "mx25u4035", INFO(0xc22533, 0, 64 * 1024, 8, SECT_4K) },
724 + { "mx25u8035", INFO(0xc22534, 0, 64 * 1024, 16, SECT_4K) },
725 { "mx25u3235f", INFO(0xc22536, 0, 64 * 1024, 64, 0) },
726 { "mx25u6435f", INFO(0xc22537, 0, 64 * 1024, 128, SECT_4K) },
727 { "mx25l12805d", INFO(0xc22018, 0, 64 * 1024, 256, 0) },
728 { "mx25l12855e", INFO(0xc22618, 0, 64 * 1024, 256, 0) },
729 { "mx25l25635e", INFO(0xc22019, 0, 64 * 1024, 512, 0) },
730 - { "mx25u25635f", INFO(0xc22539, 0, 64 * 1024, 512, SECT_4K | SPI_NOR_4B_OPCODES) },
731 + { "mx25u25635f", INFO(0xc22539, 0, 64 * 1024, 512, SECT_4K) },
732 { "mx25l25655e", INFO(0xc22619, 0, 64 * 1024, 512, 0) },
733 { "mx66l51235l", INFO(0xc2201a, 0, 64 * 1024, 1024, SPI_NOR_QUAD_READ) },
734 { "mx66l1g55g", INFO(0xc2261b, 0, 64 * 1024, 2048, SPI_NOR_QUAD_READ) },
735 @@ -1034,10 +1051,11 @@ static const struct flash_info spi_nor_i
736 { "n25q128a11", INFO(0x20bb18, 0, 64 * 1024, 256, SECT_4K | SPI_NOR_QUAD_READ) },
737 { "n25q128a13", INFO(0x20ba18, 0, 64 * 1024, 256, SECT_4K | SPI_NOR_QUAD_READ) },
738 { "n25q256a", INFO(0x20ba19, 0, 64 * 1024, 512, SECT_4K | SPI_NOR_QUAD_READ) },
739 + { "n25q256ax1", INFO(0x20bb19, 0, 64 * 1024, 512, SECT_4K | SPI_NOR_QUAD_READ) },
740 { "n25q512a", INFO(0x20bb20, 0, 64 * 1024, 1024, SECT_4K | USE_FSR | SPI_NOR_QUAD_READ) },
741 { "n25q512ax3", INFO(0x20ba20, 0, 64 * 1024, 1024, SECT_4K | USE_FSR | SPI_NOR_QUAD_READ) },
742 - { "n25q00", INFO(0x20ba21, 0, 64 * 1024, 2048, SECT_4K | USE_FSR | SPI_NOR_QUAD_READ) },
743 - { "n25q00a", INFO(0x20bb21, 0, 64 * 1024, 2048, SECT_4K | USE_FSR | SPI_NOR_QUAD_READ) },
744 + { "n25q00", INFO(0x20ba21, 0, 64 * 1024, 2048, SECT_4K | USE_FSR | SPI_NOR_QUAD_READ | NO_CHIP_ERASE) },
745 + { "n25q00a", INFO(0x20bb21, 0, 64 * 1024, 2048, SECT_4K | USE_FSR | SPI_NOR_QUAD_READ | NO_CHIP_ERASE) },
748 { "pm25lv512", INFO(0, 0, 32 * 1024, 2, SECT_4K_PMC) },
749 @@ -1055,8 +1073,11 @@ static const struct flash_info spi_nor_i
750 { "s70fl01gs", INFO(0x010221, 0x4d00, 256 * 1024, 256, 0) },
751 { "s25sl12800", INFO(0x012018, 0x0300, 256 * 1024, 64, 0) },
752 { "s25sl12801", INFO(0x012018, 0x0301, 64 * 1024, 256, 0) },
753 - { "s25fl128s", INFO6(0x012018, 0x4d0180, 64 * 1024, 256, SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) },
754 + { "s25fs256s1", INFO6(0x010219, 0x4d0181, 64 * 1024, 512, 0)},
755 + { "s25fl128s", INFO6(0x012018, 0x4d0180, 64 * 1024, 256, SPI_NOR_QUAD_READ
756 + | SPI_NOR_DDR_QUAD_READ) },
757 { "s25fl129p0", INFO(0x012018, 0x4d00, 256 * 1024, 64, SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) },
758 + { "s25fs512s", INFO6(0x010220, 0x4d0081, 256 * 1024, 256, SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ)},
759 { "s25fl129p1", INFO(0x012018, 0x4d01, 64 * 1024, 256, SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) },
760 { "s25sl004a", INFO(0x010212, 0, 64 * 1024, 8, 0) },
761 { "s25sl008a", INFO(0x010213, 0, 64 * 1024, 16, 0) },
762 @@ -1130,7 +1151,15 @@ static const struct flash_info spi_nor_i
763 { "w25x40", INFO(0xef3013, 0, 64 * 1024, 8, SECT_4K) },
764 { "w25x80", INFO(0xef3014, 0, 64 * 1024, 16, SECT_4K) },
765 { "w25x16", INFO(0xef3015, 0, 64 * 1024, 32, SECT_4K) },
767 + "w25q16dw", INFO(0xef6015, 0, 64 * 1024, 32,
768 + SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ |
769 + SPI_NOR_HAS_LOCK | SPI_NOR_HAS_TB)
771 { "w25x32", INFO(0xef3016, 0, 64 * 1024, 64, SECT_4K) },
772 + { "w25q20cl", INFO(0xef4012, 0, 64 * 1024, 4, SECT_4K) },
773 + { "w25q20bw", INFO(0xef5012, 0, 64 * 1024, 4, SECT_4K) },
774 + { "w25q20ew", INFO(0xef6012, 0, 64 * 1024, 4, SECT_4K) },
775 { "w25q32", INFO(0xef4016, 0, 64 * 1024, 64, SECT_4K) },
777 "w25q32dw", INFO(0xef6016, 0, 64 * 1024, 64,
778 @@ -1197,6 +1226,53 @@ static const struct flash_info *spi_nor_
779 id[0], id[1], id[2]);
780 return ERR_PTR(-ENODEV);
783 + * The S25FS-S family physical sectors may be configured as a
784 + * hybrid combination of eight 4-kB parameter sectors
785 + * at the top or bottom of the address space with all
786 + * but one of the remaining sectors being uniform size.
787 + * The Parameter Sector Erase commands (20h or 21h) must
788 + * be used to erase the 4-kB parameter sectors individually.
789 + * The Sector (uniform sector) Erase commands (D8h or DCh)
790 + * must be used to erase any of the remaining
791 + * sectors, including the portion of highest or lowest address
792 + * sector that is not overlaid by the parameter sectors.
793 + * The uniform sector erase command has no effect on parameter sectors.
795 +static int spansion_s25fs_disable_4kb_erase(struct spi_nor *nor)
797 + struct fsl_qspi *q;
798 + u32 cr3v_addr = SPINOR_CONFIG_REG3_OFFSET;
804 + nor->cmd_buf[2] = cr3v_addr >> 16;
805 + nor->cmd_buf[1] = cr3v_addr >> 8;
806 + nor->cmd_buf[0] = cr3v_addr >> 0;
808 + ret = nor->read_reg(nor, SPINOR_OP_SPANSION_RDAR, &cr3v, 1);
811 + if (cr3v & CR3V_4KB_ERASE_UNABLE)
813 + ret = nor->write_reg(nor, SPINOR_OP_WREN, NULL, 0);
816 + cr3v = CR3V_4KB_ERASE_UNABLE;
817 + nor->program_opcode = SPINOR_OP_SPANSION_WRAR;
818 + nor->write(nor, cr3v_addr, 1, &cr3v);
820 + ret = nor->read_reg(nor, SPINOR_OP_SPANSION_RDAR, &cr3v, 1);
823 + if (!(cr3v & CR3V_4KB_ERASE_UNABLE))
830 static int spi_nor_read(struct mtd_info *mtd, loff_t from, size_t len,
831 size_t *retlen, u_char *buf)
832 @@ -1416,7 +1492,7 @@ static int macronix_quad_enable(struct s
833 * Write status Register and configuration register with 2 bytes
834 * The first byte will be written to the status register, while the
835 * second byte will be written to the configuration register.
836 - * Return negative if error occured.
837 + * Return negative if error occurred.
839 static int write_sr_cr(struct spi_nor *nor, u16 val)
841 @@ -1464,6 +1540,24 @@ static int spansion_quad_enable(struct s
845 +static int set_ddr_quad_mode(struct spi_nor *nor, const struct flash_info *info)
849 + switch (JEDEC_MFR(info)) {
850 + case SNOR_MFR_SPANSION:
851 + status = spansion_quad_enable(nor);
853 + dev_err(nor->dev, "Spansion DDR quad-read not enabled\n");
863 static int set_quad_mode(struct spi_nor *nor, const struct flash_info *info)
866 @@ -1610,9 +1704,25 @@ int spi_nor_scan(struct spi_nor *nor, co
868 spi_nor_wait_till_ready(nor);
870 + if (JEDEC_MFR(info) == SNOR_MFR_MICRON) {
871 + ret = read_sr(nor);
872 + ret &= SPI_NOR_MICRON_WRITE_ENABLE;
875 + write_sr(nor, ret);
878 + if (EXT_ID(info) == SPINOR_S25FS_FAMILY_ID) {
879 + ret = spansion_s25fs_disable_4kb_erase(nor);
886 mtd->name = dev_name(dev);
888 + nor->vendor = info->name;
890 mtd->type = MTD_NORFLASH;
892 @@ -1646,6 +1756,8 @@ int spi_nor_scan(struct spi_nor *nor, co
893 nor->flags |= SNOR_F_USE_FSR;
894 if (info->flags & SPI_NOR_HAS_TB)
895 nor->flags |= SNOR_F_HAS_SR_TB;
896 + if (info->flags & NO_CHIP_ERASE)
897 + nor->flags |= SNOR_F_NO_OP_CHIP_ERASE;
899 #ifdef CONFIG_MTD_SPI_NOR_USE_4K_SECTORS
900 /* prefer "small sector" erase if possible */
901 @@ -1685,9 +1797,15 @@ int spi_nor_scan(struct spi_nor *nor, co
902 /* Some devices cannot do fast-read, no matter what DT tells us */
903 if (info->flags & SPI_NOR_NO_FR)
904 nor->flash_read = SPI_NOR_NORMAL;
906 - /* Quad/Dual-read mode takes precedence over fast/normal */
907 - if (mode == SPI_NOR_QUAD && info->flags & SPI_NOR_QUAD_READ) {
908 + /* DDR Quad/Quad/Dual-read mode takes precedence over fast/normal */
909 + if (mode == SPI_NOR_DDR_QUAD && info->flags & SPI_NOR_DDR_QUAD_READ) {
910 + ret = set_ddr_quad_mode(nor, info);
912 + dev_err(dev, "DDR quad mode not supported\n");
915 + nor->flash_read = SPI_NOR_DDR_QUAD;
916 + } else if (mode == SPI_NOR_QUAD && info->flags & SPI_NOR_QUAD_READ) {
917 ret = set_quad_mode(nor, info);
919 dev_err(dev, "quad mode not supported\n");
920 @@ -1700,6 +1818,9 @@ int spi_nor_scan(struct spi_nor *nor, co
922 /* Default commands */
923 switch (nor->flash_read) {
924 + case SPI_NOR_DDR_QUAD:
925 + nor->read_opcode = SPINOR_OP_READ4_1_4_4_D;
928 nor->read_opcode = SPINOR_OP_READ_1_1_4;
930 --- a/include/linux/mtd/spi-nor.h
931 +++ b/include/linux/mtd/spi-nor.h
935 * Note on opcode nomenclature: some opcodes have a format like
936 - * SPINOR_OP_FUNCTION{4,}_x_y_z. The numbers x, y, and z stand for the number
937 + * SPINOR_OP_FUNCTION{4,}_x_y_z{_D}. The numbers x, y,and z stand for the number
938 * of I/O lines used for the opcode, address, and data (respectively). The
939 * FUNCTION has an optional suffix of '4', to represent an opcode which
940 - * requires a 4-byte (32-bit) address.
941 + * requires a 4-byte (32-bit) address. The suffix of 'D' stands for the
946 #define SPINOR_OP_READ_1_1_2 0x3b /* Read data bytes (Dual Output SPI) */
947 #define SPINOR_OP_READ_1_2_2 0xbb /* Read data bytes (Dual I/O SPI) */
948 #define SPINOR_OP_READ_1_1_4 0x6b /* Read data bytes (Quad Output SPI) */
949 +#define SPINOR_OP_READ_1_4_4_D 0xed /* Read data bytes (DDR Quad SPI) */
950 #define SPINOR_OP_READ_1_4_4 0xeb /* Read data bytes (Quad I/O SPI) */
951 +#define SPINOR_OP_READ4_1_4_4_D 0xee /* Read data bytes (DDR Quad SPI) */
952 #define SPINOR_OP_PP 0x02 /* Page program (up to 256 bytes) */
953 #define SPINOR_OP_PP_1_1_4 0x32 /* Quad page program */
954 #define SPINOR_OP_PP_1_4_4 0x38 /* Quad page program */
956 /* 4-byte address opcodes - used on Spansion and some Macronix flashes. */
957 #define SPINOR_OP_READ_4B 0x13 /* Read data bytes (low frequency) */
958 #define SPINOR_OP_READ_FAST_4B 0x0c /* Read data bytes (high frequency) */
959 +#define SPINOR_OP_READ4_FAST 0x0c /* Read data bytes (high frequency) */
960 #define SPINOR_OP_READ_1_1_2_4B 0x3c /* Read data bytes (Dual Output SPI) */
961 #define SPINOR_OP_READ_1_2_2_4B 0xbc /* Read data bytes (Dual I/O SPI) */
962 #define SPINOR_OP_READ_1_1_4_4B 0x6c /* Read data bytes (Quad Output SPI) */
963 +#define SPINOR_OP_READ4_1_1_4 0x6c /* Read data bytes (Quad SPI) */
964 #define SPINOR_OP_READ_1_4_4_4B 0xec /* Read data bytes (Quad I/O SPI) */
965 #define SPINOR_OP_PP_4B 0x12 /* Page program (up to 256 bytes) */
966 #define SPINOR_OP_PP_1_1_4_4B 0x34 /* Quad page program */
968 /* Used for Spansion flashes only. */
969 #define SPINOR_OP_BRWR 0x17 /* Bank register write */
971 +/* Used for Spansion S25FS-S family flash only. */
972 +#define SPINOR_OP_SPANSION_RDAR 0x65 /* Read any device register */
973 +#define SPINOR_OP_SPANSION_WRAR 0x71 /* Write any device register */
975 /* Used for Micron flashes only. */
976 #define SPINOR_OP_RD_EVCR 0x65 /* Read EVCR register */
977 #define SPINOR_OP_WD_EVCR 0x61 /* Write EVCR register */
978 @@ -124,6 +132,7 @@ enum read_mode {
985 #define SPI_NOR_MAX_CMD_SIZE 8
986 @@ -189,6 +198,7 @@ struct spi_nor {
987 bool sst_write_second;
989 u8 cmd_buf[SPI_NOR_MAX_CMD_SIZE];
992 int (*prepare)(struct spi_nor *nor, enum spi_nor_ops ops);
993 void (*unprepare)(struct spi_nor *nor, enum spi_nor_ops ops);