ENGR00318895-7 mtd: fsl-quadspi: use the information stored in spi-nor{}
authorHuang Shijie <b32955@freescale.com>
Tue, 22 Apr 2014 09:47:14 +0000 (17:47 +0800)
committerNitin Garg <nitin.garg@nxp.com>
Mon, 19 Mar 2018 19:49:21 +0000 (14:49 -0500)
We can get the read/write/erase opcode from the spi nor framework now.
What's more is that we can get the correct dummy cycles.

This patch uses the information stored in the spi_nor{} to remove the
hardcode in the fsl_qspi_init_lut().

Signed-off-by: Huang Shijie <b32955@freescale.com>
(cherry picked from commit 3a9f46be2a6d358924d69757858ec816764222d4)

drivers/mtd/spi-nor/fsl-quadspi.c

index 5c82e4e..39e7975 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Freescale QuadSPI driver.
  *
- * Copyright (C) 2013 Freescale Semiconductor, Inc.
+ * Copyright (C) 2013-2015 Freescale Semiconductor, Inc.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -372,8 +372,10 @@ static void fsl_qspi_init_lut(struct fsl_qspi *q)
 {
        void __iomem *base = q->iobase;
        int rxfifo = q->devtype_data->rxfifo;
+       struct spi_nor *nor = &q->nor[0];
+       u8 addrlen = (nor->addr_width == 3) ? ADDR24BIT : ADDR32BIT;
        u32 lut_base;
-       u8 cmd, addrlen, dummy;
+       u8 op, dm;
        int i;
 
        fsl_qspi_unlock_lut(q);
@@ -384,23 +386,21 @@ static void fsl_qspi_init_lut(struct fsl_qspi *q)
 
        /* Quad Read */
        lut_base = SEQID_QUAD_READ * 4;
-
-       if (q->nor_size <= SZ_16M) {
-               cmd = SPINOR_OP_READ_1_1_4;
-               addrlen = ADDR24BIT;
-               dummy = 8;
-       } else {
-               /* use the 4-byte address */
-               cmd = SPINOR_OP_READ_1_1_4;
-               addrlen = ADDR32BIT;
-               dummy = 8;
+       op = nor->read_opcode;
+       dm = nor->read_dummy;
+       if (nor->flash_read == SPI_NOR_QUAD) {
+               if (op == SPINOR_OP_READ_1_1_4 || op == SPINOR_OP_READ4_1_1_4) {
+                       /* read mode : 1-1-4 */
+                       qspi_writel(q, LUT0(CMD, PAD1, op) | LUT1(ADDR, PAD1, addrlen),
+                                   base + QUADSPI_LUT(lut_base));
+
+                       qspi_writel(q, LUT0(DUMMY, PAD1, dm) | LUT1(FSL_READ, PAD4, rxfifo),
+                                   base + QUADSPI_LUT(lut_base + 1));
+               } else {
+                       dev_err(nor->dev, "Unsupported opcode : 0x%.2x\n", op);
+               }
        }
 
-       qspi_writel(q, LUT0(CMD, PAD1, cmd) | LUT1(ADDR, PAD1, addrlen),
-                       base + QUADSPI_LUT(lut_base));
-       qspi_writel(q, LUT0(DUMMY, PAD1, dummy) | LUT1(FSL_READ, PAD4, rxfifo),
-                       base + QUADSPI_LUT(lut_base + 1));
-
        /* Write enable */
        lut_base = SEQID_WREN * 4;
        qspi_writel(q, LUT0(CMD, PAD1, SPINOR_OP_WREN),
@@ -408,18 +408,8 @@ static void fsl_qspi_init_lut(struct fsl_qspi *q)
 
        /* Page Program */
        lut_base = SEQID_PP * 4;
-
-       if (q->nor_size <= SZ_16M) {
-               cmd = SPINOR_OP_PP;
-               addrlen = ADDR24BIT;
-       } else {
-               /* use the 4-byte address */
-               cmd = SPINOR_OP_PP;
-               addrlen = ADDR32BIT;
-       }
-
-       qspi_writel(q, LUT0(CMD, PAD1, cmd) | LUT1(ADDR, PAD1, addrlen),
-                       base + QUADSPI_LUT(lut_base));
+       qspi_writel(q, LUT0(CMD, PAD1, nor->program_opcode) | LUT1(ADDR, PAD1, addrlen),
+                   base + QUADSPI_LUT(lut_base));
        qspi_writel(q, LUT0(FSL_WRITE, PAD1, 0),
                        base + QUADSPI_LUT(lut_base + 1));
 
@@ -431,12 +421,8 @@ static void fsl_qspi_init_lut(struct fsl_qspi *q)
 
        /* Erase a sector */
        lut_base = SEQID_SE * 4;
-
-       cmd = q->nor[0].erase_opcode;
-       addrlen = q->nor_size <= SZ_16M ? ADDR24BIT : ADDR32BIT;
-
-       qspi_writel(q, LUT0(CMD, PAD1, cmd) | LUT1(ADDR, PAD1, addrlen),
-                       base + QUADSPI_LUT(lut_base));
+       qspi_writel(q, LUT0(CMD, PAD1, nor->erase_opcode) | LUT1(ADDR, PAD1, addrlen),
+                   base + QUADSPI_LUT(lut_base));
 
        /* Erase the whole chip */
        lut_base = SEQID_CHIP_ERASE * 4;
@@ -491,6 +477,7 @@ static int fsl_qspi_get_seqid(struct fsl_qspi *q, u8 cmd)
                return SEQID_WRDI;
        case SPINOR_OP_RDSR:
                return SEQID_RDSR;
+       case SPINOR_OP_BE_4K:
        case SPINOR_OP_SE:
                return SEQID_SE;
        case SPINOR_OP_CHIP_ERASE: