1 From 60eee49f37b77bc2d5f46c5db5a5c24d0c31bd02 Mon Sep 17 00:00:00 2001
2 From: Biwen Li <biwen.li@nxp.com>
3 Date: Tue, 20 Nov 2018 15:36:57 +0800
4 Subject: [PATCH] qspi: support layerscape
6 This is an integrated patch of qspi for layerscape
8 Signed-off-by: Abhimanyu Saini <abhimanyu.saini@nxp.com>
9 Signed-off-by: Cyrille Pitchen <cyrille.pitchen@wedev4u.fr>
10 Signed-off-by: Neil Armstrong <narmstrong@baylibre.com>
11 Signed-off-by: Prabhakar Kushwaha <prabhakar.kushwaha@nxp.com>
12 Signed-off-by: Suresh Gupta <suresh.gupta@nxp.com>
13 Signed-off-by: Yogesh Gaur <yogeshnarayan.gaur@nxp.com>
14 Signed-off-by: Biwen Li <biwen.li@nxp.com>
15 Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
17 .../devicetree/bindings/mtd/fsl-quadspi.txt | 31 ++
18 drivers/mtd/spi-nor/fsl-quadspi.c | 444 +++++++++++-------
19 drivers/mtd/spi-nor/spi-nor.c | 5 +
20 3 files changed, 320 insertions(+), 160 deletions(-)
22 --- a/Documentation/devicetree/bindings/mtd/fsl-quadspi.txt
23 +++ b/Documentation/devicetree/bindings/mtd/fsl-quadspi.txt
24 @@ -7,6 +7,7 @@ Required properties:
26 "fsl,ls2080a-qspi" followed by "fsl,ls1021a-qspi",
27 "fsl,ls1043a-qspi" followed by "fsl,ls1021a-qspi"
28 + "fsl,ls2080a-qspi" followed by "fsl,ls1088a-qspi",
29 - reg : the first contains the register location and length,
30 the second contains the memory mapping address and length
31 - reg-names: Should contain the reg names "QuadSPI" and "QuadSPI-memory"
32 @@ -39,3 +40,33 @@ qspi0: quadspi@40044000 {
37 +qspi1: quadspi@20c0000 {
38 + #address-cells = <1>;
40 + reg = <0x0 0x20c0000 0x0 0x10000>,
41 + <0x0 0x20000000 0x0 0x10000000>;
42 + reg-names = "QuadSPI", "QuadSPI-memory";
43 + interrupts = <0 25 0x4>; /* Level high type */
44 + clocks = <&clockgen 4 3>, <&clockgen 4 3>;
45 + clock-names = "qspi_en", "qspi";
48 + qflash0: s25fs512s@0 {
49 + #address-cells = <1>;
51 + spi-max-frequency = <20000000>;
53 + spi-rx-bus-width = <4>;
54 + spi-tx-bus-width = <4>;
57 + qflash1: s25fs512s@1 {
58 + #address-cells = <1>;
60 + spi-max-frequency = <20000000>;
62 + spi-rx-bus-width = <4>;
63 + spi-tx-bus-width = <4>;
66 --- a/drivers/mtd/spi-nor/fsl-quadspi.c
67 +++ b/drivers/mtd/spi-nor/fsl-quadspi.c
69 #define QUADSPI_QUIRK_TKT253890 (1 << 2)
70 /* Controller cannot wake up from wait mode, TKT245618 */
71 #define QUADSPI_QUIRK_TKT245618 (1 << 3)
72 +#define QUADSPI_ADDR_REMAP (1 << 4)
75 #define QUADSPI_MCR 0x00
78 /* Macros for constructing the LUT register. */
79 #define LUT0(ins, pad, opr) \
80 - (((opr) << OPRND0_SHIFT) | ((LUT_##pad) << PAD0_SHIFT) | \
81 + (((opr) << OPRND0_SHIFT) | ((pad) << PAD0_SHIFT) | \
82 ((LUT_##ins) << INSTR0_SHIFT))
84 #define LUT1(ins, pad, opr) (LUT0(ins, pad, opr) << OPRND1_SHIFT)
86 #define QUADSPI_LUT_NUM 64
88 /* SEQID -- we can have 16 seqids at most. */
94 -#define SEQID_CHIP_ERASE 5
99 -#define SEQID_EN4B 10
100 -#define SEQID_BRWR 11
101 +/* LUT0 programmed by bootloader, for run-time create entry for LUT seqid 1 */
102 +#define SEQID_LUT0_BOOTLOADER 0
103 +#define SEQID_LUT1_RUNTIME 1
104 +#define SEQID_LUT2_AHBREAD 2
106 #define QUADSPI_MIN_IOMAP SZ_4M
109 + FSL_QSPI_OPS_READ = 0,
110 + FSL_QSPI_OPS_WRITE,
111 + FSL_QSPI_OPS_ERASE,
112 + FSL_QSPI_OPS_READ_REG,
113 + FSL_QSPI_OPS_WRITE_REG,
114 + FSL_QSPI_OPS_WRITE_BUF_REG,
117 enum fsl_qspi_devtype {
123 + FSL_QUADSPI_LS2080A,
126 struct fsl_qspi_devtype_data {
127 @@ -267,6 +270,15 @@ static struct fsl_qspi_devtype_data ls10
131 +static const struct fsl_qspi_devtype_data ls2080a_data = {
132 + .devtype = FSL_QUADSPI_LS2080A,
135 + .ahb_buf_size = 1024,
136 + .driver_data = QUADSPI_QUIRK_TKT253890 | QUADSPI_ADDR_REMAP,
140 #define FSL_QSPI_MAX_CHIP 4
142 struct spi_nor nor[FSL_QSPI_MAX_CHIP];
143 @@ -310,6 +322,22 @@ static inline int needs_wakeup_wait_mode
147 + * QSPI memory regions split into two parts: a 256MB region that is located
148 + * in the least significant 4GB of the SoC address space and a 3.75GB region
149 + * that is located above the least significant 4GB of the SoC address space.
151 + * The 4GB QSPI address space map is shown below.
153 + * SoC Address QSPI Address
154 + * 0x00_2000_0000-0x00_2FFF_FFFF 0x00_0000_0000-0x00_0FFF_FFFF First 256MB
155 + * 0x04_1000_0000-0x04_FFFF_FFFF 0x00_1000_0000-0x00_FFFF_FFFF Last 3.75GB
157 +static inline int need_address_remap(struct fsl_qspi *q)
159 + return q->devtype_data->driver_data & QUADSPI_ADDR_REMAP;
163 * R/W functions for big- or little-endian registers:
164 * The qSPI controller's endian is independent of the CPU core's endian.
165 * So far, although the CPU core is little-endian but the qSPI have two
166 @@ -368,137 +396,160 @@ static irqreturn_t fsl_qspi_irq_handler(
170 -static void fsl_qspi_init_lut(struct fsl_qspi *q)
171 +static inline s8 pad_count(s8 pad_val)
186 + * Prepare LUT entry for the input cmd.
187 + * Protocol info is present in instance of struct spi_nor, using which fields
188 + * like cmd, data, addrlen along with pad info etc can be parsed.
190 +static void fsl_qspi_prepare_lut(struct spi_nor *nor,
191 + enum fsl_qspi_ops ops, u8 cmd)
193 + struct fsl_qspi *q = nor->priv;
194 void __iomem *base = q->iobase;
195 int rxfifo = q->devtype_data->rxfifo;
196 + int txfifo = q->devtype_data->txfifo;
199 + u8 cmd_pad, addr_pad, data_pad, dummy_pad;
200 + enum spi_nor_protocol protocol = 0;
202 + u8 read_dm, opcode;
205 + read_dm = opcode = cmd_pad = addr_pad = data_pad = dummy_pad = 0;
208 + case FSL_QSPI_OPS_READ_REG:
209 + case FSL_QSPI_OPS_WRITE_REG:
210 + case FSL_QSPI_OPS_WRITE_BUF_REG:
212 + protocol = nor->reg_proto;
214 + case FSL_QSPI_OPS_READ:
216 + read_dm = nor->read_dummy;
217 + protocol = nor->read_proto;
219 + case FSL_QSPI_OPS_WRITE:
221 + protocol = nor->write_proto;
223 + case FSL_QSPI_OPS_ERASE:
227 + dev_err(q->dev, "Unsupported operation 0x%.2x\n", ops);
232 + cmd_pad = spi_nor_get_protocol_inst_nbits(protocol);
233 + addr_pad = spi_nor_get_protocol_addr_nbits(protocol);
234 + data_pad = spi_nor_get_protocol_data_nbits(protocol);
237 + dummy_pad = data_pad;
239 - struct spi_nor *nor = &q->nor[0];
240 - u8 addrlen = (nor->addr_width == 3) ? ADDR24BIT : ADDR32BIT;
241 - u8 read_op = nor->read_opcode;
242 - u8 read_dm = nor->read_dummy;
243 + dev_dbg(q->dev, "ops:%x opcode:%x pad[cmd:%d, addr:%d, data:%d]\n",
244 + ops, opcode, cmd_pad, addr_pad, data_pad);
246 fsl_qspi_unlock_lut(q);
248 - /* Clear all the LUT table */
249 - for (i = 0; i < QUADSPI_LUT_NUM; i++)
250 - qspi_writel(q, 0, base + QUADSPI_LUT_BASE + i * 4);
253 - lut_base = SEQID_READ * 4;
255 - qspi_writel(q, LUT0(CMD, PAD1, read_op) | LUT1(ADDR, PAD1, addrlen),
256 - base + QUADSPI_LUT(lut_base));
257 - qspi_writel(q, LUT0(DUMMY, PAD1, read_dm) |
258 - LUT1(FSL_READ, PAD4, rxfifo),
259 - base + QUADSPI_LUT(lut_base + 1));
262 - lut_base = SEQID_WREN * 4;
263 - qspi_writel(q, LUT0(CMD, PAD1, SPINOR_OP_WREN),
264 - base + QUADSPI_LUT(lut_base));
267 - lut_base = SEQID_PP * 4;
269 - qspi_writel(q, LUT0(CMD, PAD1, nor->program_opcode) |
270 - LUT1(ADDR, PAD1, addrlen),
271 - base + QUADSPI_LUT(lut_base));
272 - qspi_writel(q, LUT0(FSL_WRITE, PAD1, 0),
273 - base + QUADSPI_LUT(lut_base + 1));
276 - lut_base = SEQID_RDSR * 4;
277 - qspi_writel(q, LUT0(CMD, PAD1, SPINOR_OP_RDSR) |
278 - LUT1(FSL_READ, PAD1, 0x1),
279 - base + QUADSPI_LUT(lut_base));
281 - /* Erase a sector */
282 - lut_base = SEQID_SE * 4;
284 - qspi_writel(q, LUT0(CMD, PAD1, nor->erase_opcode) |
285 - LUT1(ADDR, PAD1, addrlen),
286 - base + QUADSPI_LUT(lut_base));
288 - /* Erase the whole chip */
289 - lut_base = SEQID_CHIP_ERASE * 4;
290 - qspi_writel(q, LUT0(CMD, PAD1, SPINOR_OP_CHIP_ERASE),
291 - base + QUADSPI_LUT(lut_base));
294 - lut_base = SEQID_RDID * 4;
295 - qspi_writel(q, LUT0(CMD, PAD1, SPINOR_OP_RDID) |
296 - LUT1(FSL_READ, PAD1, 0x8),
297 - base + QUADSPI_LUT(lut_base));
299 - /* Write Register */
300 - lut_base = SEQID_WRSR * 4;
301 - qspi_writel(q, LUT0(CMD, PAD1, SPINOR_OP_WRSR) |
302 - LUT1(FSL_WRITE, PAD1, 0x2),
303 - base + QUADSPI_LUT(lut_base));
305 - /* Read Configuration Register */
306 - lut_base = SEQID_RDCR * 4;
307 - qspi_writel(q, LUT0(CMD, PAD1, SPINOR_OP_RDCR) |
308 - LUT1(FSL_READ, PAD1, 0x1),
309 - base + QUADSPI_LUT(lut_base));
311 - /* Write disable */
312 - lut_base = SEQID_WRDI * 4;
313 - qspi_writel(q, LUT0(CMD, PAD1, SPINOR_OP_WRDI),
314 - base + QUADSPI_LUT(lut_base));
316 - /* Enter 4 Byte Mode (Micron) */
317 - lut_base = SEQID_EN4B * 4;
318 - qspi_writel(q, LUT0(CMD, PAD1, SPINOR_OP_EN4B),
319 - base + QUADSPI_LUT(lut_base));
321 - /* Enter 4 Byte Mode (Spansion) */
322 - lut_base = SEQID_BRWR * 4;
323 - qspi_writel(q, LUT0(CMD, PAD1, SPINOR_OP_BRWR),
324 - base + QUADSPI_LUT(lut_base));
326 + lut_base = SEQID_LUT1_RUNTIME * 4;
327 + if (ops == FSL_QSPI_OPS_READ)
328 + lut_base = SEQID_LUT2_AHBREAD * 4;
330 + /* default, STOP instruction to be programmed in (lut_base + 1) reg */
333 + case FSL_QSPI_OPS_READ_REG:
334 + qspi_writel(q, LUT0(CMD, pad_count(cmd_pad), opcode) |
335 + LUT1(FSL_READ, pad_count(data_pad), rxfifo),
336 + base + QUADSPI_LUT(lut_base));
338 + case FSL_QSPI_OPS_WRITE_REG:
339 + qspi_writel(q, LUT0(CMD, pad_count(cmd_pad), opcode),
340 + base + QUADSPI_LUT(lut_base));
342 + case FSL_QSPI_OPS_WRITE_BUF_REG:
343 + qspi_writel(q, LUT0(CMD, pad_count(cmd_pad), opcode) |
344 + LUT1(FSL_WRITE, pad_count(data_pad), txfifo),
345 + base + QUADSPI_LUT(lut_base));
347 + case FSL_QSPI_OPS_READ:
348 + case FSL_QSPI_OPS_WRITE:
349 + case FSL_QSPI_OPS_ERASE:
350 + /* Common for Read, Write and Erase ops. */
352 + addrlen = (nor->addr_width == 3) ? ADDR24BIT : ADDR32BIT;
354 + qspi_writel(q, LUT0(CMD, pad_count(cmd_pad), opcode) |
355 + LUT1(ADDR, pad_count(addr_pad), addrlen),
356 + base + QUADSPI_LUT(lut_base));
358 + * For Erase ops - Data and Dummy not required.
359 + * For Write ops - Dummy not required.
362 - fsl_qspi_lock_lut(q);
364 + if (ops == FSL_QSPI_OPS_READ) {
366 -/* Get the SEQID for the command */
367 -static int fsl_qspi_get_seqid(struct fsl_qspi *q, u8 cmd)
370 - case SPINOR_OP_READ_1_1_4:
371 - case SPINOR_OP_READ_1_1_4_4B:
373 - case SPINOR_OP_WREN:
375 - case SPINOR_OP_WRDI:
377 - case SPINOR_OP_RDSR:
381 - case SPINOR_OP_CHIP_ERASE:
382 - return SEQID_CHIP_ERASE;
385 - case SPINOR_OP_RDID:
387 - case SPINOR_OP_WRSR:
389 - case SPINOR_OP_RDCR:
391 - case SPINOR_OP_EN4B:
393 - case SPINOR_OP_BRWR:
396 + * For cmds SPINOR_OP_READ and SPINOR_OP_READ_4B value
397 + * of dummy cycles are 0.
401 + LUT0(DUMMY, pad_count(dummy_pad),
403 + LUT1(FSL_READ, pad_count(data_pad),
405 + base + QUADSPI_LUT(lut_base + 1));
408 + LUT0(FSL_READ, pad_count(data_pad),
410 + base + QUADSPI_LUT(lut_base + 1));
414 + /* TODO Add condition to check if READ is IP/AHB. */
416 + /* For AHB read, add seqid in BFGENCR register. */
418 + SEQID_LUT2_AHBREAD <<
419 + QUADSPI_BFGENCR_SEQID_SHIFT,
420 + q->iobase + QUADSPI_BFGENCR);
423 + if (ops == FSL_QSPI_OPS_WRITE) {
424 + qspi_writel(q, LUT0(FSL_WRITE, pad_count(data_pad), 0),
425 + base + QUADSPI_LUT(lut_base + 1));
430 - if (cmd == q->nor[0].erase_opcode)
432 - dev_err(q->dev, "Unsupported cmd 0x%.2x\n", cmd);
433 + dev_err(q->dev, "Unsupported operation 0x%.2x\n", ops);
438 + /* prepare LUT for STOP instruction. */
439 + qspi_writel(q, 0, base + QUADSPI_LUT(lut_base + stop_lut));
441 + fsl_qspi_lock_lut(q);
445 @@ -508,6 +559,10 @@ fsl_qspi_runcmd(struct fsl_qspi *q, u8 c
449 + u32 memmap_phyadd = q->memmap_phy;
451 + if (need_address_remap(q))
454 init_completion(&q->c);
455 dev_dbg(q->dev, "to 0x%.8x:0x%.8x, len:%d, cmd:%.2x\n",
456 @@ -516,7 +571,7 @@ fsl_qspi_runcmd(struct fsl_qspi *q, u8 c
458 reg = qspi_readl(q, base + QUADSPI_MCR);
460 - qspi_writel(q, q->memmap_phy + q->chip_base_addr + addr,
461 + qspi_writel(q, memmap_phyadd + q->chip_base_addr + addr,
462 base + QUADSPI_SFAR);
463 qspi_writel(q, QUADSPI_RBCT_WMRK_MASK | QUADSPI_RBCT_RXBRD_USEIPS,
464 base + QUADSPI_RBCT);
465 @@ -533,7 +588,7 @@ fsl_qspi_runcmd(struct fsl_qspi *q, u8 c
468 /* trigger the LUT now */
469 - seqid = fsl_qspi_get_seqid(q, cmd);
470 + seqid = SEQID_LUT1_RUNTIME;
471 qspi_writel(q, (seqid << QUADSPI_IPCR_SEQID_SHIFT) | len,
472 base + QUADSPI_IPCR);
474 @@ -609,6 +664,7 @@ static ssize_t fsl_qspi_nor_write(struct
480 dev_dbg(q->dev, "to 0x%.8x:0x%.8x, len : %d\n",
481 q->chip_base_addr, to, count);
482 @@ -618,10 +674,18 @@ static ssize_t fsl_qspi_nor_write(struct
483 qspi_writel(q, tmp | QUADSPI_MCR_CLR_TXF_MASK, q->iobase + QUADSPI_MCR);
485 /* fill the TX data to the FIFO */
487 for (j = 0, i = ((count + 3) / 4); j < i; j++) {
488 - tmp = fsl_qspi_endian_xchg(q, *txbuf);
490 + tmp = fsl_qspi_endian_xchg(q, *txbuf);
492 + memcpy(&tmp, txbuf, byts);
493 + tmp = fsl_qspi_endian_xchg(q, tmp);
496 qspi_writel(q, tmp, q->iobase + QUADSPI_TBDR);
501 /* fill the TXFIFO upto 16 bytes for i.MX7d */
502 @@ -642,11 +706,15 @@ static void fsl_qspi_set_map_addr(struct
504 int nor_size = q->nor_size;
505 void __iomem *base = q->iobase;
506 + u32 memmap_phyadd = q->memmap_phy;
508 + if (need_address_remap(q))
511 - qspi_writel(q, nor_size + q->memmap_phy, base + QUADSPI_SFA1AD);
512 - qspi_writel(q, nor_size * 2 + q->memmap_phy, base + QUADSPI_SFA2AD);
513 - qspi_writel(q, nor_size * 3 + q->memmap_phy, base + QUADSPI_SFB1AD);
514 - qspi_writel(q, nor_size * 4 + q->memmap_phy, base + QUADSPI_SFB2AD);
515 + qspi_writel(q, nor_size + memmap_phyadd, base + QUADSPI_SFA1AD);
516 + qspi_writel(q, nor_size * 2 + memmap_phyadd, base + QUADSPI_SFA2AD);
517 + qspi_writel(q, nor_size * 3 + memmap_phyadd, base + QUADSPI_SFB1AD);
518 + qspi_writel(q, nor_size * 4 + memmap_phyadd, base + QUADSPI_SFB2AD);
522 @@ -662,7 +730,7 @@ static void fsl_qspi_set_map_addr(struct
523 * causes the controller to clear the buffer, and use the sequence pointed
524 * by the QUADSPI_BFGENCR[SEQID] to initiate a read from the flash.
526 -static void fsl_qspi_init_abh_read(struct fsl_qspi *q)
527 +static void fsl_qspi_init_ahb_read(struct fsl_qspi *q)
529 void __iomem *base = q->iobase;
531 @@ -685,8 +753,8 @@ static void fsl_qspi_init_abh_read(struc
532 qspi_writel(q, 0, base + QUADSPI_BUF1IND);
533 qspi_writel(q, 0, base + QUADSPI_BUF2IND);
535 - /* Set the default lut sequence for AHB Read. */
536 - seqid = fsl_qspi_get_seqid(q, q->nor[0].read_opcode);
537 + /* Set dynamic LUT entry as lut sequence for AHB Read . */
538 + seqid = SEQID_LUT2_AHBREAD;
539 qspi_writel(q, seqid << QUADSPI_BFGENCR_SEQID_SHIFT,
540 q->iobase + QUADSPI_BFGENCR);
542 @@ -729,7 +797,6 @@ static int fsl_qspi_nor_setup(struct fsl
543 void __iomem *base = q->iobase;
547 /* disable and unprepare clock to avoid glitch pass to controller */
548 fsl_qspi_clk_disable_unprep(q);
550 @@ -747,9 +814,6 @@ static int fsl_qspi_nor_setup(struct fsl
554 - /* Init the LUT table. */
555 - fsl_qspi_init_lut(q);
557 /* Disable the module */
558 qspi_writel(q, QUADSPI_MCR_MDIS_MASK | QUADSPI_MCR_RESERVED_MASK,
560 @@ -770,6 +834,9 @@ static int fsl_qspi_nor_setup(struct fsl
561 /* enable the interrupt */
562 qspi_writel(q, QUADSPI_RSER_TFIE, q->iobase + QUADSPI_RSER);
564 + /* Init for AHB read */
565 + fsl_qspi_init_ahb_read(q);
570 @@ -792,12 +859,6 @@ static int fsl_qspi_nor_setup_last(struc
574 - /* Init the LUT table again. */
575 - fsl_qspi_init_lut(q);
577 - /* Init for AHB read */
578 - fsl_qspi_init_abh_read(q);
583 @@ -807,6 +868,7 @@ static const struct of_device_id fsl_qsp
584 { .compatible = "fsl,imx7d-qspi", .data = (void *)&imx7d_data, },
585 { .compatible = "fsl,imx6ul-qspi", .data = (void *)&imx6ul_data, },
586 { .compatible = "fsl,ls1021a-qspi", .data = (void *)&ls1021a_data, },
587 + { .compatible = "fsl,ls2080a-qspi", .data = &ls2080a_data, },
590 MODULE_DEVICE_TABLE(of, fsl_qspi_dt_ids);
591 @@ -821,6 +883,7 @@ static int fsl_qspi_read_reg(struct spi_
593 struct fsl_qspi *q = nor->priv;
595 + fsl_qspi_prepare_lut(nor, FSL_QSPI_OPS_READ_REG, opcode);
596 ret = fsl_qspi_runcmd(q, opcode, 0, len);
599 @@ -835,6 +898,8 @@ static int fsl_qspi_write_reg(struct spi
603 + /* Prepare LUT for WRITE_REG cmd with input BUF as NULL. */
604 + fsl_qspi_prepare_lut(nor, FSL_QSPI_OPS_WRITE_REG, opcode);
605 ret = fsl_qspi_runcmd(q, opcode, 0, 1);
608 @@ -843,6 +908,8 @@ static int fsl_qspi_write_reg(struct spi
611 } else if (len > 0) {
612 + /* Prepare LUT for WRITE_REG cmd with input BUF non-NULL. */
613 + fsl_qspi_prepare_lut(nor, FSL_QSPI_OPS_WRITE_BUF_REG, opcode);
614 ret = fsl_qspi_nor_write(q, nor, opcode, 0,
617 @@ -859,8 +926,11 @@ static ssize_t fsl_qspi_write(struct spi
618 size_t len, const u_char *buf)
620 struct fsl_qspi *q = nor->priv;
621 - ssize_t ret = fsl_qspi_nor_write(q, nor, nor->program_opcode, to,
625 + fsl_qspi_prepare_lut(nor, FSL_QSPI_OPS_WRITE, nor->program_opcode);
626 + ret = fsl_qspi_nor_write(q, nor, nor->program_opcode, to,
629 /* invalid the data in the AHB buffer. */
631 @@ -873,6 +943,8 @@ static ssize_t fsl_qspi_read(struct spi_
632 struct fsl_qspi *q = nor->priv;
633 u8 cmd = nor->read_opcode;
635 + fsl_qspi_prepare_lut(nor, FSL_QSPI_OPS_READ, nor->read_opcode);
637 /* if necessary,ioremap buffer before AHB read, */
639 q->memmap_offs = q->chip_base_addr + from;
640 @@ -907,8 +979,9 @@ static ssize_t fsl_qspi_read(struct spi_
643 /* Read out the data directly from the AHB buffer.*/
644 - memcpy(buf, q->ahb_addr + q->chip_base_addr + from - q->memmap_offs,
647 + q->ahb_addr + q->chip_base_addr + from - q->memmap_offs,
652 @@ -921,6 +994,7 @@ static int fsl_qspi_erase(struct spi_nor
653 dev_dbg(nor->dev, "%dKiB at 0x%08x:0x%08x\n",
654 nor->mtd.erasesize / 1024, q->chip_base_addr, (u32)offs);
656 + fsl_qspi_prepare_lut(nor, FSL_QSPI_OPS_ERASE, nor->erase_opcode);
657 ret = fsl_qspi_runcmd(q, nor->erase_opcode, offs, 0);
660 @@ -958,17 +1032,14 @@ static void fsl_qspi_unprep(struct spi_n
662 static int fsl_qspi_probe(struct platform_device *pdev)
664 - const struct spi_nor_hwcaps hwcaps = {
665 - .mask = SNOR_HWCAPS_READ_1_1_4 |
668 + struct spi_nor_hwcaps hwcaps;
669 struct device_node *np = pdev->dev.of_node;
670 struct device *dev = &pdev->dev;
672 struct resource *res;
674 struct mtd_info *mtd;
676 + int ret, i = 0, value;
678 q = devm_kzalloc(dev, sizeof(*q), GFP_KERNEL);
680 @@ -1041,6 +1112,10 @@ static int fsl_qspi_probe(struct platfor
682 /* iterate the subnodes. */
683 for_each_available_child_of_node(dev->of_node, np) {
684 + /* Reset hwcaps mask to minimal caps for the slave node. */
685 + hwcaps.mask = SNOR_HWCAPS_READ | SNOR_HWCAPS_PP;
689 if (!q->has_second_chip)
691 @@ -1070,6 +1145,51 @@ static int fsl_qspi_probe(struct platfor
692 /* set the chip address for READID */
693 fsl_qspi_set_base_addr(q, nor);
696 + * If spi-rx-bus-width and spi-tx-bus-width not defined assign
697 + * default hardware capabilities SNOR_HWCAPS_READ_1_1_4 and
698 + * SNOR_HWCAPS_PP supported by the Quad-SPI controller.
700 + if (!of_property_read_u32(np, "spi-rx-bus-width", &value)) {
703 + hwcaps.mask |= SNOR_HWCAPS_READ |
704 + SNOR_HWCAPS_READ_FAST;
707 + hwcaps.mask |= SNOR_HWCAPS_READ_1_1_2 |
708 + SNOR_HWCAPS_READ_1_2_2;
711 + hwcaps.mask |= SNOR_HWCAPS_READ_1_1_4 |
712 + SNOR_HWCAPS_READ_1_4_4;
716 + "spi-rx-bus-width %d not supported\n",
721 + hwcaps.mask |= SNOR_HWCAPS_READ_1_1_4;
723 + if (!of_property_read_u32(np, "spi-tx-bus-width", &value)) {
726 + hwcaps.mask |= SNOR_HWCAPS_PP;
729 + hwcaps.mask |= SNOR_HWCAPS_PP_1_1_4 |
730 + SNOR_HWCAPS_PP_1_4_4;
734 + "spi-tx-bus-width %d not supported\n",
740 ret = spi_nor_scan(nor, NULL, &hwcaps);
743 @@ -1098,6 +1218,8 @@ static int fsl_qspi_probe(struct platfor
744 if (nor->page_size > q->devtype_data->txfifo)
745 nor->page_size = q->devtype_data->txfifo;
747 + /*required for memory mapped AHB read*/
748 + fsl_qspi_prepare_lut(nor, FSL_QSPI_OPS_READ, nor->read_opcode);
752 @@ -1106,6 +1228,8 @@ static int fsl_qspi_probe(struct platfor
754 goto last_init_failed;
758 fsl_qspi_clk_disable_unprep(q);
761 --- a/drivers/mtd/spi-nor/spi-nor.c
762 +++ b/drivers/mtd/spi-nor/spi-nor.c
763 @@ -1147,6 +1147,11 @@ static const struct flash_info spi_nor_i
764 { "w25x40", INFO(0xef3013, 0, 64 * 1024, 8, SECT_4K) },
765 { "w25x80", INFO(0xef3014, 0, 64 * 1024, 16, SECT_4K) },
766 { "w25x16", INFO(0xef3015, 0, 64 * 1024, 32, SECT_4K) },
768 + "w25q16dw", INFO(0xef6015, 0, 64 * 1024, 32,
769 + SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ |
770 + SPI_NOR_HAS_LOCK | SPI_NOR_HAS_TB)
772 { "w25x32", INFO(0xef3016, 0, 64 * 1024, 64, SECT_4K) },
773 { "w25q20cl", INFO(0xef4012, 0, 64 * 1024, 4, SECT_4K) },
774 { "w25q20bw", INFO(0xef5012, 0, 64 * 1024, 4, SECT_4K) },