]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - drivers/mtd/nand/fsl_ifc_spl.c
sunxi_nand_spl: Remove NAND_SUNXI_SPL_SYNDROME_PARTITIONS_END
[karo-tx-uboot.git] / drivers / mtd / nand / fsl_ifc_spl.c
index 9fa5ccbc562651a2e10a0010b8898815a82ba890..fccbfb5129d788f5df0b3cc5cc16dad0143d68e0 100644 (file)
@@ -9,7 +9,7 @@
 
 #include <common.h>
 #include <asm/io.h>
-#include <asm/fsl_ifc.h>
+#include <fsl_ifc.h>
 #include <linux/mtd/nand.h>
 
 static inline int is_blank(uchar *addr, int page_size)
@@ -48,11 +48,25 @@ static inline int check_read_ecc(uchar *buf, u32 *eccstat,
        return 0;
 }
 
+static inline struct fsl_ifc_runtime *runtime_regs_address(void)
+{
+       struct fsl_ifc regs = {(void *)CONFIG_SYS_IFC_ADDR, NULL};
+       int ver = 0;
+
+       ver = ifc_in32(&regs.gregs->ifc_rev);
+       if (ver >= FSL_IFC_V2_0_0)
+               regs.rregs = (void *)CONFIG_SYS_IFC_ADDR + IFC_RREGS_64KOFFSET;
+       else
+               regs.rregs = (void *)CONFIG_SYS_IFC_ADDR + IFC_RREGS_4KOFFSET;
+
+       return regs.rregs;
+}
+
 static inline void nand_wait(uchar *buf, int bufnum, int page_size)
 {
-       struct fsl_ifc *ifc = IFC_BASE_ADDR;
+       struct fsl_ifc_runtime *ifc = runtime_regs_address();
        u32 status;
-       u32 eccstat[4];
+       u32 eccstat[8];
        int bufperpage = page_size / 512;
        int bufnum_end, i;
 
@@ -60,7 +74,7 @@ static inline void nand_wait(uchar *buf, int bufnum, int page_size)
        bufnum_end = bufnum + bufperpage - 1;
 
        do {
-               status = in_be32(&ifc->ifc_nand.nand_evter_stat);
+               status = ifc_in32(&ifc->ifc_nand.nand_evter_stat);
        } while (!(status & IFC_NAND_EVTER_STAT_OPC));
 
        if (status & IFC_NAND_EVTER_STAT_FTOER) {
@@ -70,14 +84,14 @@ static inline void nand_wait(uchar *buf, int bufnum, int page_size)
        }
 
        for (i = bufnum / 4; i <= bufnum_end / 4; i++)
-               eccstat[i] = in_be32(&ifc->ifc_nand.nand_eccstat[i]);
+               eccstat[i] = ifc_in32(&ifc->ifc_nand.nand_eccstat[i]);
 
        for (i = bufnum; i <= bufnum_end; i++) {
                if (check_read_ecc(buf, eccstat, i, page_size))
                        break;
        }
 
-       out_be32(&ifc->ifc_nand.nand_evter_stat, status);
+       ifc_out32(&ifc->ifc_nand.nand_evter_stat, status);
 }
 
 static inline int bad_block(uchar *marker, int port_size)
@@ -88,16 +102,17 @@ static inline int bad_block(uchar *marker, int port_size)
                return __raw_readw((u16 *)marker) != 0xffff;
 }
 
-static void nand_load(unsigned int offs, int uboot_size, uchar *dst)
+int nand_spl_load_image(uint32_t offs, unsigned int uboot_size, void *vdst)
 {
-       struct fsl_ifc *ifc = IFC_BASE_ADDR;
+       struct fsl_ifc_fcm *gregs = (void *)CONFIG_SYS_IFC_ADDR;
+       struct fsl_ifc_runtime *ifc = NULL;
        uchar *buf = (uchar *)CONFIG_SYS_NAND_BASE;
        int page_size;
        int port_size;
        int pages_per_blk;
        int blk_size;
        int bad_marker = 0;
-       int bufnum_mask, bufnum;
+       int bufnum_mask, bufnum, ver = 0;
 
        int csor, cspr;
        int pos = 0;
@@ -105,6 +120,9 @@ static void nand_load(unsigned int offs, int uboot_size, uchar *dst)
 
        int sram_addr;
        int pg_no;
+       uchar *dst = vdst;
+
+       ifc = runtime_regs_address();
 
        /* Get NAND Flash configuration */
        csor = CONFIG_SYS_NAND_CSOR;
@@ -129,44 +147,48 @@ static void nand_load(unsigned int offs, int uboot_size, uchar *dst)
                        bad_marker = 5;
        }
 
+       ver = ifc_in32(&gregs->ifc_rev);
+       if (ver >= FSL_IFC_V2_0_0)
+               bufnum_mask = (bufnum_mask * 2) + 1;
+
        pages_per_blk =
                32 << ((csor & CSOR_NAND_PB_MASK) >> CSOR_NAND_PB_SHIFT);
 
        blk_size = pages_per_blk * page_size;
 
        /* Open Full SRAM mapping for spare are access */
-       out_be32(&ifc->ifc_nand.ncfgr, 0x0);
+       ifc_out32(&ifc->ifc_nand.ncfgr, 0x0);
 
        /* Clear Boot events */
-       out_be32(&ifc->ifc_nand.nand_evter_stat, 0xffffffff);
+       ifc_out32(&ifc->ifc_nand.nand_evter_stat, 0xffffffff);
 
        /* Program FIR/FCR for Large/Small page */
        if (page_size > 512) {
-               out_be32(&ifc->ifc_nand.nand_fir0,
-                        (IFC_FIR_OP_CW0 << IFC_NAND_FIR0_OP0_SHIFT) |
-                        (IFC_FIR_OP_CA0 << IFC_NAND_FIR0_OP1_SHIFT) |
-                        (IFC_FIR_OP_RA0 << IFC_NAND_FIR0_OP2_SHIFT) |
-                        (IFC_FIR_OP_CMD1 << IFC_NAND_FIR0_OP3_SHIFT) |
-                        (IFC_FIR_OP_BTRD << IFC_NAND_FIR0_OP4_SHIFT));
-               out_be32(&ifc->ifc_nand.nand_fir1, 0x0);
-
-               out_be32(&ifc->ifc_nand.nand_fcr0,
-                        (NAND_CMD_READ0 << IFC_NAND_FCR0_CMD0_SHIFT) |
-                        (NAND_CMD_READSTART << IFC_NAND_FCR0_CMD1_SHIFT));
+               ifc_out32(&ifc->ifc_nand.nand_fir0,
+                         (IFC_FIR_OP_CW0 << IFC_NAND_FIR0_OP0_SHIFT) |
+                         (IFC_FIR_OP_CA0 << IFC_NAND_FIR0_OP1_SHIFT) |
+                         (IFC_FIR_OP_RA0 << IFC_NAND_FIR0_OP2_SHIFT) |
+                         (IFC_FIR_OP_CMD1 << IFC_NAND_FIR0_OP3_SHIFT) |
+                         (IFC_FIR_OP_BTRD << IFC_NAND_FIR0_OP4_SHIFT));
+               ifc_out32(&ifc->ifc_nand.nand_fir1, 0x0);
+
+               ifc_out32(&ifc->ifc_nand.nand_fcr0,
+                         (NAND_CMD_READ0 << IFC_NAND_FCR0_CMD0_SHIFT) |
+                         (NAND_CMD_READSTART << IFC_NAND_FCR0_CMD1_SHIFT));
        } else {
-               out_be32(&ifc->ifc_nand.nand_fir0,
-                        (IFC_FIR_OP_CW0 << IFC_NAND_FIR0_OP0_SHIFT) |
-                        (IFC_FIR_OP_CA0 << IFC_NAND_FIR0_OP1_SHIFT) |
-                        (IFC_FIR_OP_RA0  << IFC_NAND_FIR0_OP2_SHIFT) |
-                        (IFC_FIR_OP_BTRD << IFC_NAND_FIR0_OP3_SHIFT));
-               out_be32(&ifc->ifc_nand.nand_fir1, 0x0);
-
-               out_be32(&ifc->ifc_nand.nand_fcr0,
-                        NAND_CMD_READ0 << IFC_NAND_FCR0_CMD0_SHIFT);
+               ifc_out32(&ifc->ifc_nand.nand_fir0,
+                         (IFC_FIR_OP_CW0 << IFC_NAND_FIR0_OP0_SHIFT) |
+                         (IFC_FIR_OP_CA0 << IFC_NAND_FIR0_OP1_SHIFT) |
+                         (IFC_FIR_OP_RA0  << IFC_NAND_FIR0_OP2_SHIFT) |
+                         (IFC_FIR_OP_BTRD << IFC_NAND_FIR0_OP3_SHIFT));
+               ifc_out32(&ifc->ifc_nand.nand_fir1, 0x0);
+
+               ifc_out32(&ifc->ifc_nand.nand_fcr0,
+                         NAND_CMD_READ0 << IFC_NAND_FCR0_CMD0_SHIFT);
        }
 
        /* Program FBCR = 0 for full page read */
-       out_be32(&ifc->ifc_nand.nand_fbcr, 0);
+       ifc_out32(&ifc->ifc_nand.nand_fbcr, 0);
 
        /* Read and copy u-boot on SDRAM from NAND device, In parallel
         * check for Bad block if found skip it and read continue to
@@ -179,11 +201,11 @@ static void nand_load(unsigned int offs, int uboot_size, uchar *dst)
                        bufnum = pg_no & bufnum_mask;
                        sram_addr = bufnum * page_size * 2;
 
-                       out_be32(&ifc->ifc_nand.row0, pg_no);
-                       out_be32(&ifc->ifc_nand.col0, 0);
+                       ifc_out32(&ifc->ifc_nand.row0, pg_no);
+                       ifc_out32(&ifc->ifc_nand.col0, 0);
                        /* start read */
-                       out_be32(&ifc->ifc_nand.nandseq_strt,
-                                IFC_NAND_SEQ_STRT_FIR_STRT);
+                       ifc_out32(&ifc->ifc_nand.nandseq_strt,
+                                 IFC_NAND_SEQ_STRT_FIR_STRT);
 
                        /* wait for read to complete */
                        nand_wait(&buf[sram_addr], bufnum, page_size);
@@ -208,6 +230,8 @@ static void nand_load(unsigned int offs, int uboot_size, uchar *dst)
                        offs += page_size;
                } while ((offs & (blk_size - 1)) && (pos < uboot_size));
        }
+
+       return 0;
 }
 
 /*
@@ -221,16 +245,17 @@ void nand_boot(void)
        /*
         * Load U-Boot image from NAND into RAM
         */
-       nand_load(CONFIG_SYS_NAND_U_BOOT_OFFS, CONFIG_SYS_NAND_U_BOOT_SIZE,
-                 (uchar *)CONFIG_SYS_NAND_U_BOOT_DST);
+       nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_OFFS,
+                           CONFIG_SYS_NAND_U_BOOT_SIZE,
+                           (uchar *)CONFIG_SYS_NAND_U_BOOT_DST);
 
 #ifdef CONFIG_NAND_ENV_DST
-       nand_load(CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE,
-                 (uchar *)CONFIG_NAND_ENV_DST);
+       nand_spl_load_image(CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE,
+                           (uchar *)CONFIG_NAND_ENV_DST);
 
 #ifdef CONFIG_ENV_OFFSET_REDUND
-       nand_load(CONFIG_ENV_OFFSET_REDUND, CONFIG_ENV_SIZE,
-                 (uchar *)CONFIG_NAND_ENV_DST + CONFIG_ENV_SIZE);
+       nand_spl_load_image(CONFIG_ENV_OFFSET_REDUND, CONFIG_ENV_SIZE,
+                           (uchar *)CONFIG_NAND_ENV_DST + CONFIG_ENV_SIZE);
 #endif
 #endif
        /*
@@ -246,3 +271,13 @@ void nand_boot(void)
        uboot = (void *)CONFIG_SYS_NAND_U_BOOT_START;
        uboot();
 }
+
+#ifndef CONFIG_SPL_NAND_INIT
+void nand_init(void)
+{
+}
+
+void nand_deselect(void)
+{
+}
+#endif