Merge branch 'master' of git://git.denx.de/u-boot-mpc85xx
[platform/kernel/u-boot.git] / drivers / mtd / nand / nand.c
index 70b605f..d987f4c 100644 (file)
@@ -37,19 +37,37 @@ static struct nand_chip nand_chip[CONFIG_SYS_MAX_NAND_DEVICE];
 static ulong base_address[CONFIG_SYS_MAX_NAND_DEVICE] = CONFIG_SYS_NAND_BASE_LIST;
 
 static const char default_nand_name[] = "nand";
+static __attribute__((unused)) char dev_name[CONFIG_SYS_MAX_NAND_DEVICE][8];
 
 static void nand_init_chip(struct mtd_info *mtd, struct nand_chip *nand,
                           ulong base_addr)
 {
+       int maxchips = CONFIG_SYS_NAND_MAX_CHIPS;
+       static int __attribute__((unused)) i = 0;
+
+       if (maxchips < 1)
+               maxchips = 1;
        mtd->priv = nand;
 
        nand->IO_ADDR_R = nand->IO_ADDR_W = (void  __iomem *)base_addr;
        if (board_nand_init(nand) == 0) {
-               if (nand_scan(mtd, 1) == 0) {
+               if (nand_scan(mtd, maxchips) == 0) {
                        if (!mtd->name)
                                mtd->name = (char *)default_nand_name;
+#ifdef CONFIG_NEEDS_MANUAL_RELOC
                        else
                                mtd->name += gd->reloc_off;
+#endif
+
+#ifdef CONFIG_MTD_DEVICE
+                       /*
+                        * Add MTD device so that we can reference it later
+                        * via the mtdcore infrastructure (e.g. ubi).
+                        */
+                       sprintf(dev_name[i], "nand%d", i);
+                       mtd->name = dev_name[i++];
+                       add_mtd_device(mtd);
+#endif
                } else
                        mtd->name = NULL;
        } else {