]> bbs.cooldavid.org Git - net-next-2.6.git/blobdiff - drivers/mtd/nand/mxc_nand.c
Merge git://git.infradead.org/mtd-2.6
[net-next-2.6.git] / drivers / mtd / nand / mxc_nand.c
index 5130a853102418399b1e20f601c9d07525c5e437..fcf8ceb277d44cd3e78b5c5e0249ec1b40d7ab33 100644 (file)
 
 #define nfc_is_v21()           (cpu_is_mx25() || cpu_is_mx35())
 #define nfc_is_v1()            (cpu_is_mx31() || cpu_is_mx27() || cpu_is_mx21())
+#define nfc_is_v3_2()          cpu_is_mx51()
+#define nfc_is_v3()            nfc_is_v3_2()
 
 /* Addresses for NFC registers */
-#define NFC_BUF_SIZE                   0x00
-#define NFC_BUF_ADDR                   0x04
-#define NFC_FLASH_ADDR                 0x06
-#define NFC_FLASH_CMD                  0x08
-#define NFC_CONFIG                     0x0a
-#define NFC_ECC_STATUS_RESULT          0x0c
-#define NFC_RSLTMAIN_AREA              0x0e
-#define NFC_RSLTSPARE_AREA             0x10
-#define NFC_WRPROT                     0x12
-#define NFC_V1_UNLOCKSTART_BLKADDR     0x14
-#define NFC_V1_UNLOCKEND_BLKADDR       0x16
-#define NFC_V21_UNLOCKSTART_BLKADDR    0x20
-#define NFC_V21_UNLOCKEND_BLKADDR      0x22
-#define NFC_NF_WRPRST                  0x18
-#define NFC_CONFIG1                    0x1a
-#define NFC_CONFIG2                    0x1c
-
-/* Set INT to 0, FCMD to 1, rest to 0 in NFC_CONFIG2 Register
- * for Command operation */
-#define NFC_CMD            0x1
-
-/* Set INT to 0, FADD to 1, rest to 0 in NFC_CONFIG2 Register
- * for Address operation */
-#define NFC_ADDR           0x2
-
-/* Set INT to 0, FDI to 1, rest to 0 in NFC_CONFIG2 Register
- * for Input operation */
-#define NFC_INPUT          0x4
-
-/* Set INT to 0, FDO to 001, rest to 0 in NFC_CONFIG2 Register
- * for Data Output operation */
-#define NFC_OUTPUT         0x8
-
-/* Set INT to 0, FD0 to 010, rest to 0 in NFC_CONFIG2 Register
- * for Read ID operation */
-#define NFC_ID             0x10
-
-/* Set INT to 0, FDO to 100, rest to 0 in NFC_CONFIG2 Register
- * for Read Status operation */
-#define NFC_STATUS         0x20
-
-/* Set INT to 1, rest to 0 in NFC_CONFIG2 Register for Read
- * Status operation */
-#define NFC_INT            0x8000
-
-#define NFC_SP_EN           (1 << 2)
-#define NFC_ECC_EN          (1 << 3)
-#define NFC_INT_MSK         (1 << 4)
-#define NFC_BIG             (1 << 5)
-#define NFC_RST             (1 << 6)
-#define NFC_CE              (1 << 7)
-#define NFC_ONE_CYCLE       (1 << 8)
+#define NFC_V1_V2_BUF_SIZE             (host->regs + 0x00)
+#define NFC_V1_V2_BUF_ADDR             (host->regs + 0x04)
+#define NFC_V1_V2_FLASH_ADDR           (host->regs + 0x06)
+#define NFC_V1_V2_FLASH_CMD            (host->regs + 0x08)
+#define NFC_V1_V2_CONFIG               (host->regs + 0x0a)
+#define NFC_V1_V2_ECC_STATUS_RESULT    (host->regs + 0x0c)
+#define NFC_V1_V2_RSLTMAIN_AREA                (host->regs + 0x0e)
+#define NFC_V1_V2_RSLTSPARE_AREA       (host->regs + 0x10)
+#define NFC_V1_V2_WRPROT               (host->regs + 0x12)
+#define NFC_V1_UNLOCKSTART_BLKADDR     (host->regs + 0x14)
+#define NFC_V1_UNLOCKEND_BLKADDR       (host->regs + 0x16)
+#define NFC_V21_UNLOCKSTART_BLKADDR    (host->regs + 0x20)
+#define NFC_V21_UNLOCKEND_BLKADDR      (host->regs + 0x22)
+#define NFC_V1_V2_NF_WRPRST            (host->regs + 0x18)
+#define NFC_V1_V2_CONFIG1              (host->regs + 0x1a)
+#define NFC_V1_V2_CONFIG2              (host->regs + 0x1c)
+
+#define NFC_V2_CONFIG1_ECC_MODE_4      (1 << 0)
+#define NFC_V1_V2_CONFIG1_SP_EN                (1 << 2)
+#define NFC_V1_V2_CONFIG1_ECC_EN       (1 << 3)
+#define NFC_V1_V2_CONFIG1_INT_MSK      (1 << 4)
+#define NFC_V1_V2_CONFIG1_BIG          (1 << 5)
+#define NFC_V1_V2_CONFIG1_RST          (1 << 6)
+#define NFC_V1_V2_CONFIG1_CE           (1 << 7)
+#define NFC_V1_V2_CONFIG1_ONE_CYCLE    (1 << 8)
+
+#define NFC_V1_V2_CONFIG2_INT          (1 << 15)
+
+/*
+ * Operation modes for the NFC. Valid for v1, v2 and v3
+ * type controllers.
+ */
+#define NFC_CMD                                (1 << 0)
+#define NFC_ADDR                       (1 << 1)
+#define NFC_INPUT                      (1 << 2)
+#define NFC_OUTPUT                     (1 << 3)
+#define NFC_ID                         (1 << 4)
+#define NFC_STATUS                     (1 << 5)
+
+#define NFC_V3_FLASH_CMD               (host->regs_axi + 0x00)
+#define NFC_V3_FLASH_ADDR0             (host->regs_axi + 0x04)
+
+#define NFC_V3_CONFIG1                 (host->regs_axi + 0x34)
+#define NFC_V3_CONFIG1_SP_EN           (1 << 0)
+#define NFC_V3_CONFIG1_RBA(x)          (((x) & 0x7 ) << 4)
+
+#define NFC_V3_ECC_STATUS_RESULT       (host->regs_axi + 0x38)
+
+#define NFC_V3_LAUNCH                  (host->regs_axi + 0x40)
+
+#define NFC_V3_WRPROT                  (host->regs_ip + 0x0)
+#define NFC_V3_WRPROT_LOCK_TIGHT       (1 << 0)
+#define NFC_V3_WRPROT_LOCK             (1 << 1)
+#define NFC_V3_WRPROT_UNLOCK           (1 << 2)
+#define NFC_V3_WRPROT_BLS_UNLOCK       (2 << 6)
+
+#define NFC_V3_WRPROT_UNLOCK_BLK_ADD0   (host->regs_ip + 0x04)
+
+#define NFC_V3_CONFIG2                 (host->regs_ip + 0x24)
+#define NFC_V3_CONFIG2_PS_512                  (0 << 0)
+#define NFC_V3_CONFIG2_PS_2048                 (1 << 0)
+#define NFC_V3_CONFIG2_PS_4096                 (2 << 0)
+#define NFC_V3_CONFIG2_ONE_CYCLE               (1 << 2)
+#define NFC_V3_CONFIG2_ECC_EN                  (1 << 3)
+#define NFC_V3_CONFIG2_2CMD_PHASES             (1 << 4)
+#define NFC_V3_CONFIG2_NUM_ADDR_PHASE0         (1 << 5)
+#define NFC_V3_CONFIG2_ECC_MODE_8              (1 << 6)
+#define NFC_V3_CONFIG2_PPB(x)                  (((x) & 0x3) << 7)
+#define NFC_V3_CONFIG2_NUM_ADDR_PHASE1(x)      (((x) & 0x3) << 12)
+#define NFC_V3_CONFIG2_INT_MSK                 (1 << 15)
+#define NFC_V3_CONFIG2_ST_CMD(x)               (((x) & 0xff) << 24)
+#define NFC_V3_CONFIG2_SPAS(x)                 (((x) & 0xff) << 16)
+
+#define NFC_V3_CONFIG3                         (host->regs_ip + 0x28)
+#define NFC_V3_CONFIG3_ADD_OP(x)               (((x) & 0x3) << 0)
+#define NFC_V3_CONFIG3_FW8                     (1 << 3)
+#define NFC_V3_CONFIG3_SBB(x)                  (((x) & 0x7) << 8)
+#define NFC_V3_CONFIG3_NUM_OF_DEVICES(x)       (((x) & 0x7) << 12)
+#define NFC_V3_CONFIG3_RBB_MODE                        (1 << 15)
+#define NFC_V3_CONFIG3_NO_SDMA                 (1 << 20)
+
+#define NFC_V3_IPC                     (host->regs_ip + 0x2C)
+#define NFC_V3_IPC_CREQ                        (1 << 0)
+#define NFC_V3_IPC_INT                 (1 << 31)
+
+#define NFC_V3_DELAY_LINE              (host->regs_ip + 0x34)
 
 struct mxc_nand_host {
        struct mtd_info         mtd;
@@ -105,10 +141,13 @@ struct mxc_nand_host {
 
        void __iomem            *base;
        void __iomem            *regs;
+       void __iomem            *regs_axi;
+       void __iomem            *regs_ip;
        int                     status_request;
        struct clk              *clk;
        int                     clk_act;
        int                     irq;
+       int                     eccsize;
 
        wait_queue_head_t       irq_waitq;
 
@@ -122,6 +161,7 @@ struct mxc_nand_host {
        void                    (*send_page)(struct mtd_info *, unsigned int);
        void                    (*send_read_id)(struct mxc_nand_host *);
        uint16_t                (*get_dev_status)(struct mxc_nand_host *);
+       int                     (*check_int)(struct mxc_nand_host *);
 };
 
 /* OOB placement block for use with hardware ecc generation */
@@ -181,34 +221,52 @@ static irqreturn_t mxc_nfc_irq(int irq, void *dev_id)
        return IRQ_HANDLED;
 }
 
+static int check_int_v3(struct mxc_nand_host *host)
+{
+       uint32_t tmp;
+
+       tmp = readl(NFC_V3_IPC);
+       if (!(tmp & NFC_V3_IPC_INT))
+               return 0;
+
+       tmp &= ~NFC_V3_IPC_INT;
+       writel(tmp, NFC_V3_IPC);
+
+       return 1;
+}
+
+static int check_int_v1_v2(struct mxc_nand_host *host)
+{
+       uint32_t tmp;
+
+       tmp = readw(NFC_V1_V2_CONFIG2);
+       if (!(tmp & NFC_V1_V2_CONFIG2_INT))
+               return 0;
+
+       writew(tmp & ~NFC_V1_V2_CONFIG2_INT, NFC_V1_V2_CONFIG2);
+
+       return 1;
+}
+
 /* This function polls the NANDFC to wait for the basic operation to
  * complete by checking the INT bit of config2 register.
  */
 static void wait_op_done(struct mxc_nand_host *host, int useirq)
 {
-       uint16_t tmp;
        int max_retries = 8000;
 
        if (useirq) {
-               if ((readw(host->regs + NFC_CONFIG2) & NFC_INT) == 0) {
+               if (!host->check_int(host)) {
 
                        enable_irq(host->irq);
 
-                       wait_event(host->irq_waitq,
-                               readw(host->regs + NFC_CONFIG2) & NFC_INT);
-
-                       tmp = readw(host->regs + NFC_CONFIG2);
-                       tmp  &= ~NFC_INT;
-                       writew(tmp, host->regs + NFC_CONFIG2);
+                       wait_event(host->irq_waitq, host->check_int(host));
                }
        } else {
                while (max_retries-- > 0) {
-                       if (readw(host->regs + NFC_CONFIG2) & NFC_INT) {
-                               tmp = readw(host->regs + NFC_CONFIG2);
-                               tmp  &= ~NFC_INT;
-                               writew(tmp, host->regs + NFC_CONFIG2);
+                       if (host->check_int(host))
                                break;
-                       }
+
                        udelay(1);
                }
                if (max_retries < 0)
@@ -217,21 +275,33 @@ static void wait_op_done(struct mxc_nand_host *host, int useirq)
        }
 }
 
+static void send_cmd_v3(struct mxc_nand_host *host, uint16_t cmd, int useirq)
+{
+       /* fill command */
+       writel(cmd, NFC_V3_FLASH_CMD);
+
+       /* send out command */
+       writel(NFC_CMD, NFC_V3_LAUNCH);
+
+       /* Wait for operation to complete */
+       wait_op_done(host, useirq);
+}
+
 /* This function issues the specified command to the NAND device and
  * waits for completion. */
 static void send_cmd_v1_v2(struct mxc_nand_host *host, uint16_t cmd, int useirq)
 {
        DEBUG(MTD_DEBUG_LEVEL3, "send_cmd(host, 0x%x, %d)\n", cmd, useirq);
 
-       writew(cmd, host->regs + NFC_FLASH_CMD);
-       writew(NFC_CMD, host->regs + NFC_CONFIG2);
+       writew(cmd, NFC_V1_V2_FLASH_CMD);
+       writew(NFC_CMD, NFC_V1_V2_CONFIG2);
 
        if (cpu_is_mx21() && (cmd == NAND_CMD_RESET)) {
                int max_retries = 100;
                /* Reset completion is indicated by NFC_CONFIG2 */
                /* being set to 0 */
                while (max_retries-- > 0) {
-                       if (readw(host->regs + NFC_CONFIG2) == 0) {
+                       if (readw(NFC_V1_V2_CONFIG2) == 0) {
                                break;
                        }
                        udelay(1);
@@ -245,6 +315,17 @@ static void send_cmd_v1_v2(struct mxc_nand_host *host, uint16_t cmd, int useirq)
        }
 }
 
+static void send_addr_v3(struct mxc_nand_host *host, uint16_t addr, int islast)
+{
+       /* fill address */
+       writel(addr, NFC_V3_FLASH_ADDR0);
+
+       /* send out address */
+       writel(NFC_ADDR, NFC_V3_LAUNCH);
+
+       wait_op_done(host, 0);
+}
+
 /* This function sends an address (or partial address) to the
  * NAND device. The address is used to select the source/destination for
  * a NAND command. */
@@ -252,13 +333,29 @@ static void send_addr_v1_v2(struct mxc_nand_host *host, uint16_t addr, int islas
 {
        DEBUG(MTD_DEBUG_LEVEL3, "send_addr(host, 0x%x %d)\n", addr, islast);
 
-       writew(addr, host->regs + NFC_FLASH_ADDR);
-       writew(NFC_ADDR, host->regs + NFC_CONFIG2);
+       writew(addr, NFC_V1_V2_FLASH_ADDR);
+       writew(NFC_ADDR, NFC_V1_V2_CONFIG2);
 
        /* Wait for operation to complete */
        wait_op_done(host, islast);
 }
 
+static void send_page_v3(struct mtd_info *mtd, unsigned int ops)
+{
+       struct nand_chip *nand_chip = mtd->priv;
+       struct mxc_nand_host *host = nand_chip->priv;
+       uint32_t tmp;
+
+       tmp = readl(NFC_V3_CONFIG1);
+       tmp &= ~(7 << 4);
+       writel(tmp, NFC_V3_CONFIG1);
+
+       /* transfer data from NFC ram to nand */
+       writel(ops, NFC_V3_LAUNCH);
+
+       wait_op_done(host, false);
+}
+
 static void send_page_v1_v2(struct mtd_info *mtd, unsigned int ops)
 {
        struct nand_chip *nand_chip = mtd->priv;
@@ -273,24 +370,34 @@ static void send_page_v1_v2(struct mtd_info *mtd, unsigned int ops)
        for (i = 0; i < bufs; i++) {
 
                /* NANDFC buffer 0 is used for page read/write */
-               writew(i, host->regs + NFC_BUF_ADDR);
+               writew(i, NFC_V1_V2_BUF_ADDR);
 
-               writew(ops, host->regs + NFC_CONFIG2);
+               writew(ops, NFC_V1_V2_CONFIG2);
 
                /* Wait for operation to complete */
                wait_op_done(host, true);
        }
 }
 
+static void send_read_id_v3(struct mxc_nand_host *host)
+{
+       /* Read ID into main buffer */
+       writel(NFC_ID, NFC_V3_LAUNCH);
+
+       wait_op_done(host, true);
+
+       memcpy(host->data_buf, host->main_area0, 16);
+}
+
 /* Request the NANDFC to perform a read of the NAND device ID. */
 static void send_read_id_v1_v2(struct mxc_nand_host *host)
 {
        struct nand_chip *this = &host->nand;
 
        /* NANDFC buffer 0 is used for device ID output */
-       writew(0x0, host->regs + NFC_BUF_ADDR);
+       writew(0x0, NFC_V1_V2_BUF_ADDR);
 
-       writew(NFC_ID, host->regs + NFC_CONFIG2);
+       writew(NFC_ID, NFC_V1_V2_CONFIG2);
 
        /* Wait for operation to complete */
        wait_op_done(host, true);
@@ -307,6 +414,14 @@ static void send_read_id_v1_v2(struct mxc_nand_host *host)
        memcpy(host->data_buf, host->main_area0, 16);
 }
 
+static uint16_t get_dev_status_v3(struct mxc_nand_host *host)
+{
+       writew(NFC_STATUS, NFC_V3_LAUNCH);
+       wait_op_done(host, true);
+
+       return readl(NFC_V3_CONFIG1) >> 16;
+}
+
 /* This function requests the NANDFC to perform a read of the
  * NAND device status and returns the current status. */
 static uint16_t get_dev_status_v1_v2(struct mxc_nand_host *host)
@@ -324,7 +439,7 @@ static uint16_t get_dev_status_v1_v2(struct mxc_nand_host *host)
         */
        store = readl(main_buf);
 
-       writew(NFC_STATUS, host->regs + NFC_CONFIG2);
+       writew(NFC_STATUS, NFC_V1_V2_CONFIG2);
        wait_op_done(host, true);
 
        ret = readw(main_buf);
@@ -352,7 +467,7 @@ static void mxc_nand_enable_hwecc(struct mtd_info *mtd, int mode)
         */
 }
 
-static int mxc_nand_correct_data(struct mtd_info *mtd, u_char *dat,
+static int mxc_nand_correct_data_v1(struct mtd_info *mtd, u_char *dat,
                                 u_char *read_ecc, u_char *calc_ecc)
 {
        struct nand_chip *nand_chip = mtd->priv;
@@ -363,7 +478,7 @@ static int mxc_nand_correct_data(struct mtd_info *mtd, u_char *dat,
         * additional correction.  2-Bit errors cannot be corrected by
         * HW ECC, so we need to return failure
         */
-       uint16_t ecc_status = readw(host->regs + NFC_ECC_STATUS_RESULT);
+       uint16_t ecc_status = readw(NFC_V1_V2_ECC_STATUS_RESULT);
 
        if (((ecc_status & 0x3) == 2) || ((ecc_status >> 2) == 2)) {
                DEBUG(MTD_DEBUG_LEVEL0,
@@ -374,6 +489,43 @@ static int mxc_nand_correct_data(struct mtd_info *mtd, u_char *dat,
        return 0;
 }
 
+static int mxc_nand_correct_data_v2_v3(struct mtd_info *mtd, u_char *dat,
+                                u_char *read_ecc, u_char *calc_ecc)
+{
+       struct nand_chip *nand_chip = mtd->priv;
+       struct mxc_nand_host *host = nand_chip->priv;
+       u32 ecc_stat, err;
+       int no_subpages = 1;
+       int ret = 0;
+       u8 ecc_bit_mask, err_limit;
+
+       ecc_bit_mask = (host->eccsize == 4) ? 0x7 : 0xf;
+       err_limit = (host->eccsize == 4) ? 0x4 : 0x8;
+
+       no_subpages = mtd->writesize >> 9;
+
+       if (nfc_is_v21())
+               ecc_stat = readl(NFC_V1_V2_ECC_STATUS_RESULT);
+       else
+               ecc_stat = readl(NFC_V3_ECC_STATUS_RESULT);
+
+       do {
+               err = ecc_stat & ecc_bit_mask;
+               if (err > err_limit) {
+                       printk(KERN_WARNING "UnCorrectable RS-ECC Error\n");
+                       return -1;
+               } else {
+                       ret += err;
+               }
+               ecc_stat >>= 4;
+       } while (--no_subpages);
+
+       mtd->ecc_stats.corrected += ret;
+       pr_debug("%d Symbol Correctable RS-ECC Error\n", ret);
+
+       return ret;
+}
+
 static int mxc_nand_calculate_ecc(struct mtd_info *mtd, const u_char *dat,
                                  u_char *ecc_code)
 {
@@ -556,6 +708,23 @@ static void mxc_do_addr_cycle(struct mtd_info *mtd, int column, int page_addr)
        }
 }
 
+/*
+ * v2 and v3 type controllers can do 4bit or 8bit ecc depending
+ * on how much oob the nand chip has. For 8bit ecc we need at least
+ * 26 bytes of oob data per 512 byte block.
+ */
+static int get_eccsize(struct mtd_info *mtd)
+{
+       int oobbytes_per_512 = 0;
+
+       oobbytes_per_512 = mtd->oobsize * 512 / mtd->writesize;
+
+       if (oobbytes_per_512 < 26)
+               return 4;
+       else
+               return 8;
+}
+
 static void preset_v1_v2(struct mtd_info *mtd)
 {
        struct nand_chip *nand_chip = mtd->priv;
@@ -563,32 +732,107 @@ static void preset_v1_v2(struct mtd_info *mtd)
        uint16_t tmp;
 
        /* enable interrupt, disable spare enable */
-       tmp = readw(host->regs + NFC_CONFIG1);
-       tmp &= ~NFC_INT_MSK;
-       tmp &= ~NFC_SP_EN;
+       tmp = readw(NFC_V1_V2_CONFIG1);
+       tmp &= ~NFC_V1_V2_CONFIG1_INT_MSK;
+       tmp &= ~NFC_V1_V2_CONFIG1_SP_EN;
        if (nand_chip->ecc.mode == NAND_ECC_HW) {
-               tmp |= NFC_ECC_EN;
+               tmp |= NFC_V1_V2_CONFIG1_ECC_EN;
        } else {
-               tmp &= ~NFC_ECC_EN;
+               tmp &= ~NFC_V1_V2_CONFIG1_ECC_EN;
        }
-       writew(tmp, host->regs + NFC_CONFIG1);
+
+       if (nfc_is_v21() && mtd->writesize) {
+               host->eccsize = get_eccsize(mtd);
+               if (host->eccsize == 4)
+                       tmp |= NFC_V2_CONFIG1_ECC_MODE_4;
+       } else {
+               host->eccsize = 1;
+       }
+
+       writew(tmp, NFC_V1_V2_CONFIG1);
        /* preset operation */
 
        /* Unlock the internal RAM Buffer */
-       writew(0x2, host->regs + NFC_CONFIG);
+       writew(0x2, NFC_V1_V2_CONFIG);
 
        /* Blocks to be unlocked */
        if (nfc_is_v21()) {
-               writew(0x0, host->regs + NFC_V21_UNLOCKSTART_BLKADDR);
-               writew(0xffff, host->regs + NFC_V21_UNLOCKEND_BLKADDR);
+               writew(0x0, NFC_V21_UNLOCKSTART_BLKADDR);
+               writew(0xffff, NFC_V21_UNLOCKEND_BLKADDR);
        } else if (nfc_is_v1()) {
-               writew(0x0, host->regs + NFC_V1_UNLOCKSTART_BLKADDR);
-               writew(0x4000, host->regs + NFC_V1_UNLOCKEND_BLKADDR);
+               writew(0x0, NFC_V1_UNLOCKSTART_BLKADDR);
+               writew(0x4000, NFC_V1_UNLOCKEND_BLKADDR);
        } else
                BUG();
 
        /* Unlock Block Command for given address range */
-       writew(0x4, host->regs + NFC_WRPROT);
+       writew(0x4, NFC_V1_V2_WRPROT);
+}
+
+static void preset_v3(struct mtd_info *mtd)
+{
+       struct nand_chip *chip = mtd->priv;
+       struct mxc_nand_host *host = chip->priv;
+       uint32_t config2, config3;
+       int i, addr_phases;
+
+       writel(NFC_V3_CONFIG1_RBA(0), NFC_V3_CONFIG1);
+       writel(NFC_V3_IPC_CREQ, NFC_V3_IPC);
+
+       /* Unlock the internal RAM Buffer */
+       writel(NFC_V3_WRPROT_BLS_UNLOCK | NFC_V3_WRPROT_UNLOCK,
+                       NFC_V3_WRPROT);
+
+       /* Blocks to be unlocked */
+       for (i = 0; i < NAND_MAX_CHIPS; i++)
+               writel(0x0 |    (0xffff << 16),
+                               NFC_V3_WRPROT_UNLOCK_BLK_ADD0 + (i << 2));
+
+       writel(0, NFC_V3_IPC);
+
+       config2 = NFC_V3_CONFIG2_ONE_CYCLE |
+               NFC_V3_CONFIG2_2CMD_PHASES |
+               NFC_V3_CONFIG2_SPAS(mtd->oobsize >> 1) |
+               NFC_V3_CONFIG2_ST_CMD(0x70) |
+               NFC_V3_CONFIG2_NUM_ADDR_PHASE0;
+
+       if (chip->ecc.mode == NAND_ECC_HW)
+               config2 |= NFC_V3_CONFIG2_ECC_EN;
+
+       addr_phases = fls(chip->pagemask) >> 3;
+
+       if (mtd->writesize == 2048) {
+               config2 |= NFC_V3_CONFIG2_PS_2048;
+               config2 |= NFC_V3_CONFIG2_NUM_ADDR_PHASE1(addr_phases);
+       } else if (mtd->writesize == 4096) {
+               config2 |= NFC_V3_CONFIG2_PS_4096;
+               config2 |= NFC_V3_CONFIG2_NUM_ADDR_PHASE1(addr_phases);
+       } else {
+               config2 |= NFC_V3_CONFIG2_PS_512;
+               config2 |= NFC_V3_CONFIG2_NUM_ADDR_PHASE1(addr_phases - 1);
+       }
+
+       if (mtd->writesize) {
+               config2 |= NFC_V3_CONFIG2_PPB(ffs(mtd->erasesize / mtd->writesize) - 6);
+               host->eccsize = get_eccsize(mtd);
+               if (host->eccsize == 8)
+                       config2 |= NFC_V3_CONFIG2_ECC_MODE_8;
+       }
+
+       writel(config2, NFC_V3_CONFIG2);
+
+       config3 = NFC_V3_CONFIG3_NUM_OF_DEVICES(0) |
+                       NFC_V3_CONFIG3_NO_SDMA |
+                       NFC_V3_CONFIG3_RBB_MODE |
+                       NFC_V3_CONFIG3_SBB(6) | /* Reset default */
+                       NFC_V3_CONFIG3_ADD_OP(0);
+
+       if (!(chip->options & NAND_BUSWIDTH_16))
+               config3 |= NFC_V3_CONFIG3_FW8;
+
+       writel(config3, NFC_V3_CONFIG3);
+
+       writel(0, NFC_V3_DELAY_LINE);
 }
 
 /* Used by the upper layer to write command to NAND Flash for
@@ -774,6 +1018,7 @@ static int __init mxcnd_probe(struct platform_device *pdev)
                host->send_page = send_page_v1_v2;
                host->send_read_id = send_read_id_v1_v2;
                host->get_dev_status = get_dev_status_v1_v2;
+               host->check_int = check_int_v1_v2;
        }
 
        if (nfc_is_v21()) {
@@ -790,6 +1035,30 @@ static int __init mxcnd_probe(struct platform_device *pdev)
                oob_smallpage = &nandv1_hw_eccoob_smallpage;
                oob_largepage = &nandv1_hw_eccoob_largepage;
                this->ecc.bytes = 3;
+               host->eccsize = 1;
+       } else if (nfc_is_v3_2()) {
+               res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
+               if (!res) {
+                       err = -ENODEV;
+                       goto eirq;
+               }
+               host->regs_ip = ioremap(res->start, resource_size(res));
+               if (!host->regs_ip) {
+                       err = -ENOMEM;
+                       goto eirq;
+               }
+               host->regs_axi = host->base + 0x1e00;
+               host->spare0 = host->base + 0x1000;
+               host->spare_len = 64;
+               host->preset = preset_v3;
+               host->send_cmd = send_cmd_v3;
+               host->send_addr = send_addr_v3;
+               host->send_page = send_page_v3;
+               host->send_read_id = send_read_id_v3;
+               host->check_int = check_int_v3;
+               host->get_dev_status = get_dev_status_v3;
+               oob_smallpage = &nandv2_hw_eccoob_smallpage;
+               oob_largepage = &nandv2_hw_eccoob_largepage;
        } else
                BUG();
 
@@ -799,7 +1068,10 @@ static int __init mxcnd_probe(struct platform_device *pdev)
        if (pdata->hw_ecc) {
                this->ecc.calculate = mxc_nand_calculate_ecc;
                this->ecc.hwctl = mxc_nand_enable_hwecc;
-               this->ecc.correct = mxc_nand_correct_data;
+               if (nfc_is_v1())
+                       this->ecc.correct = mxc_nand_correct_data_v1;
+               else
+                       this->ecc.correct = mxc_nand_correct_data_v2_v3;
                this->ecc.mode = NAND_ECC_HW;
        } else {
                this->ecc.mode = NAND_ECC_SOFT;
@@ -830,6 +1102,9 @@ static int __init mxcnd_probe(struct platform_device *pdev)
                goto escan;
        }
 
+       /* Call preset again, with correct writesize this time */
+       host->preset(mtd);
+
        if (mtd->writesize == 2048)
                this->ecc.layout = oob_largepage;
 
@@ -845,6 +1120,8 @@ static int __init mxcnd_probe(struct platform_device *pdev)
            parse_mtd_partitions(mtd, part_probes, &host->parts, 0);
        if (nr_parts > 0)
                add_mtd_partitions(mtd, host->parts, nr_parts);
+       else if (pdata->parts)
+               add_mtd_partitions(mtd, pdata->parts, pdata->nr_parts);
        else
 #endif
        {
@@ -859,6 +1136,8 @@ static int __init mxcnd_probe(struct platform_device *pdev)
 escan:
        free_irq(host->irq, host);
 eirq:
+       if (host->regs_ip)
+               iounmap(host->regs_ip);
        iounmap(host->base);
 eres:
        clk_put(host->clk);
@@ -878,6 +1157,8 @@ static int __devexit mxcnd_remove(struct platform_device *pdev)
 
        nand_release(&host->mtd);
        free_irq(host->irq, host);
+       if (host->regs_ip)
+               iounmap(host->regs_ip);
        iounmap(host->base);
        kfree(host);