Merge with git://www.denx.de/git/u-boot.git
[platform/kernel/u-boot.git] / drivers / nand / nand.c
index bc85005..27b5792 100644 (file)
@@ -23,8 +23,7 @@
 
 #include <common.h>
 
-#ifdef CONFIG_NEW_NAND_CODE
-#if (CONFIG_COMMANDS & CFG_CMD_NAND)
+#if defined(CONFIG_CMD_NAND) && !defined(CFG_NAND_LEGACY)
 
 #include <nand.h>
 
@@ -40,7 +39,7 @@ static ulong base_address[CFG_MAX_NAND_DEVICE] = CFG_NAND_BASE_LIST;
 
 static const char default_nand_name[] = "nand";
 
-extern void board_nand_init(struct nand_chip *nand);
+extern int board_nand_init(struct nand_chip *nand);
 
 static void nand_init_chip(struct mtd_info *mtd, struct nand_chip *nand,
                           ulong base_addr)
@@ -48,13 +47,16 @@ static void nand_init_chip(struct mtd_info *mtd, struct nand_chip *nand,
        mtd->priv = nand;
 
        nand->IO_ADDR_R = nand->IO_ADDR_W = (void  __iomem *)base_addr;
-       board_nand_init(nand);
-
-       if (nand_scan(mtd, 1) == 0) {
-               if (!mtd->name)
-                       mtd->name = (char *)default_nand_name;
-       } else
+       if (board_nand_init(nand) == 0) {
+               if (nand_scan(mtd, 1) == 0) {
+                       if (!mtd->name)
+                               mtd->name = (char *)default_nand_name;
+               } else
+                       mtd->name = NULL;
+       } else {
                mtd->name = NULL;
+               mtd->size = 0;
+       }
 
 }
 
@@ -67,10 +69,15 @@ void nand_init(void)
                size += nand_info[i].size;
                if (nand_curr_device == -1)
                        nand_curr_device = i;
-}
+       }
        printf("%lu MiB\n", size / (1024 * 1024));
-}
 
+#ifdef CFG_NAND_SELECT_DEVICE
+       /*
+        * Select the chip in the board/cpu specific driver
+        */
+       board_nand_select_device(nand_info[nand_curr_device].priv, nand_curr_device);
 #endif
-#endif /* CONFIG_NEW_NAND_CODE */
+}
 
+#endif