]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - drivers/mtd/nand/mxc_nand.c
Merge branch 'master' of git://git.denx.de/u-boot-video
[karo-tx-uboot.git] / drivers / mtd / nand / mxc_nand.c
index 62d8c6b38cfb1b041609c7d1bd88ab9900adabda..d0ded483e2a41342387be2a19f0e1a086cbad92c 100644 (file)
@@ -77,7 +77,7 @@ static struct nand_ecclayout nand_hw_eccoob2k = {
        .oobfree = { {2, 4}, {11, 11}, {27, 11}, {43, 11}, {59, 5} },
 };
 #endif
-#elif defined(MXC_NFC_V1_1)
+#elif defined(MXC_NFC_V2_1)
 #ifndef CONFIG_SYS_NAND_LARGEPAGE
 static struct nand_ecclayout nand_hw_eccoob = {
        .eccbytes = 9,
@@ -213,7 +213,7 @@ static void send_prog_page(struct mxc_nand_host *host, uint8_t buf_id,
        if (spare_only)
                MTDDEBUG(MTD_DEBUG_LEVEL1, "send_prog_page (%d)\n", spare_only);
 
-       if (is_mxc_nfc_11()) {
+       if (is_mxc_nfc_21()) {
                int i;
                /*
                 *  The controller copies the 64 bytes of spare data from
@@ -273,7 +273,7 @@ static void send_read_page(struct mxc_nand_host *host, uint8_t buf_id,
        /* Wait for operation to complete */
        wait_op_done(host, TROP_US_DELAY, spare_only);
 
-       if (is_mxc_nfc_11()) {
+       if (is_mxc_nfc_21()) {
                int i;
 
                /*
@@ -355,16 +355,6 @@ static int mxc_nand_dev_ready(struct mtd_info *mtd)
        return 1;
 }
 
-#ifdef CONFIG_MXC_NAND_HWECC
-static void mxc_nand_enable_hwecc(struct mtd_info *mtd, int mode)
-{
-       /*
-        * If HW ECC is enabled, we turn it on during init. There is
-        * no need to enable again here.
-        */
-}
-
-#ifdef MXC_NFC_V1_1
 static void _mxc_nand_enable_hwecc(struct mtd_info *mtd, int on)
 {
        struct nand_chip *nand_chip = mtd->priv;
@@ -378,6 +368,16 @@ static void _mxc_nand_enable_hwecc(struct mtd_info *mtd, int on)
        writew(tmp, &host->regs->config1);
 }
 
+#ifdef CONFIG_MXC_NAND_HWECC
+static void mxc_nand_enable_hwecc(struct mtd_info *mtd, int mode)
+{
+       /*
+        * If HW ECC is enabled, we turn it on during init. There is
+        * no need to enable again here.
+        */
+}
+
+#ifdef MXC_NFC_V2_1
 static int mxc_nand_read_oob_syndrome(struct mtd_info *mtd,
                                      struct nand_chip *chip,
                                      int page, int sndcmd)
@@ -470,7 +470,7 @@ static int mxc_nand_read_page_raw_syndrome(struct mtd_info *mtd,
        size = mtd->oobsize - (oob - chip->oob_poi);
        if (size)
                chip->read_buf(mtd, oob, size);
-       _mxc_nand_enable_hwecc(mtd, 0);
+       _mxc_nand_enable_hwecc(mtd, 1);
 
        return 0;
 }
@@ -653,7 +653,7 @@ static int mxc_nand_correct_data(struct mtd_info *mtd, u_char *dat,
 {
        struct nand_chip *nand_chip = mtd->priv;
        struct mxc_nand_host *host = nand_chip->priv;
-       uint16_t ecc_status = readw(&host->regs->ecc_status_result);
+       uint32_t ecc_status = readl(&host->regs->ecc_status_result);
        int subpages = mtd->writesize / nand_chip->subpagesize;
        int pg2blk_shift = nand_chip->phys_erase_shift -
                           nand_chip->page_shift;
@@ -1061,7 +1061,7 @@ void mxc_nand_command(struct mtd_info *mtd, unsigned command,
        case NAND_CMD_PAGEPROG:
                send_prog_page(host, 0, host->spare_only);
 
-               if (host->pagesize_2k && !is_mxc_nfc_11()) {
+               if (host->pagesize_2k && is_mxc_nfc_1()) {
                        /* data in 4 areas */
                        send_prog_page(host, 1, host->spare_only);
                        send_prog_page(host, 2, host->spare_only);
@@ -1111,7 +1111,7 @@ void mxc_nand_command(struct mtd_info *mtd, unsigned command,
                        send_cmd(host, NAND_CMD_READSTART);
                        /* read for each AREA */
                        send_read_page(host, 0, host->spare_only);
-                       if (!is_mxc_nfc_11()) {
+                       if (is_mxc_nfc_1()) {
                                send_read_page(host, 1, host->spare_only);
                                send_read_page(host, 2, host->spare_only);
                                send_read_page(host, 3, host->spare_only);
@@ -1137,24 +1137,6 @@ void mxc_nand_command(struct mtd_info *mtd, unsigned command,
        }
 }
 
-#ifdef MXC_NFC_V1_1
-static void mxc_setup_config1(void)
-{
-       uint16_t tmp;
-
-       tmp = readw(&host->regs->config1);
-       tmp |= NFC_ONE_CYCLE;
-       tmp |= NFC_4_8N_ECC;
-       writew(tmp, &host->regs->config1);
-       if (host->pagesize_2k)
-               writew(64/2, &host->regs->spare_area_size);
-       else
-               writew(16/2, &host->regs->spare_area_size);
-}
-#else
-#define mxc_setup_config1()
-#endif
-
 #ifdef CONFIG_SYS_NAND_USE_FLASH_BBT
 
 static u8 bbt_pattern[] = {'B', 'b', 't', '0' };
@@ -1185,7 +1167,9 @@ static struct nand_bbt_descr bbt_mirror_descr = {
 int board_nand_init(struct nand_chip *this)
 {
        struct mtd_info *mtd;
+#ifdef MXC_NFC_V2_1
        uint16_t tmp;
+#endif
 
 #ifdef CONFIG_SYS_NAND_USE_FLASH_BBT
        this->options |= NAND_USE_FLASH_BBT;
@@ -1218,7 +1202,7 @@ int board_nand_init(struct nand_chip *this)
        this->ecc.calculate = mxc_nand_calculate_ecc;
        this->ecc.hwctl = mxc_nand_enable_hwecc;
        this->ecc.correct = mxc_nand_correct_data;
-       if (is_mxc_nfc_11()) {
+       if (is_mxc_nfc_21()) {
                this->ecc.mode = NAND_ECC_HW_SYNDROME;
                this->ecc.read_page = mxc_nand_read_page_syndrome;
                this->ecc.read_page_raw = mxc_nand_read_page_raw_syndrome;
@@ -1235,19 +1219,38 @@ int board_nand_init(struct nand_chip *this)
        host->pagesize_2k = 0;
 
        this->ecc.size = 512;
-       tmp = readw(&host->regs->config1);
-       tmp |= NFC_ECC_EN;
-       writew(tmp, &host->regs->config1);
+       _mxc_nand_enable_hwecc(mtd, 1);
 #else
        this->ecc.layout = &nand_soft_eccoob;
        this->ecc.mode = NAND_ECC_SOFT;
-       tmp = readw(&host->regs->config1);
-       tmp &= ~NFC_ECC_EN;
-       writew(tmp, &host->regs->config1);
+       _mxc_nand_enable_hwecc(mtd, 0);
 #endif
        /* Reset NAND */
        this->cmdfunc(mtd, NAND_CMD_RESET, -1, -1);
 
+       /* NAND bus width determines access functions used by upper layer */
+       if (is_16bit_nand())
+               this->options |= NAND_BUSWIDTH_16;
+
+#ifdef CONFIG_SYS_NAND_LARGEPAGE
+       host->pagesize_2k = 1;
+       this->ecc.layout = &nand_hw_eccoob2k;
+#else
+       host->pagesize_2k = 0;
+       this->ecc.layout = &nand_hw_eccoob;
+#endif
+
+#ifdef MXC_NFC_V2_1
+       tmp = readw(&host->regs->config1);
+       tmp |= NFC_ONE_CYCLE;
+       tmp |= NFC_4_8N_ECC;
+       writew(tmp, &host->regs->config1);
+       if (host->pagesize_2k)
+               writew(64/2, &host->regs->spare_area_size);
+       else
+               writew(16/2, &host->regs->spare_area_size);
+#endif
+
        /*
         * preset operation
         * Unlock the internal RAM Buffer
@@ -1272,17 +1275,5 @@ int board_nand_init(struct nand_chip *this)
        /* Unlock Block Command for given address range */
        writew(0x4, &host->regs->wrprot);
 
-       /* NAND bus width determines access functions used by upper layer */
-       if (is_16bit_nand())
-               this->options |= NAND_BUSWIDTH_16;
-
-#ifdef CONFIG_SYS_NAND_LARGEPAGE
-       host->pagesize_2k = 1;
-       this->ecc.layout = &nand_hw_eccoob2k;
-#else
-       host->pagesize_2k = 0;
-       this->ecc.layout = &nand_hw_eccoob;
-#endif
-       mxc_setup_config1();
        return 0;
 }