X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=drivers%2Fmtd%2Fnand%2Fnand.c;h=6aa909fdd9751b3b5a853d7b70c8d5e977fe28ea;hb=c7c553f249f99ae282f1fa5c0e314aae0bce8a26;hp=f449316853924b9f91eb0dd6bfbc1e7577b55e95;hpb=cc749523ae1adec3856f2b7fe77a6d856da4652a;p=oweals%2Fu-boot.git diff --git a/drivers/mtd/nand/nand.c b/drivers/mtd/nand/nand.c index f449316853..6aa909fdd9 100644 --- a/drivers/mtd/nand/nand.c +++ b/drivers/mtd/nand/nand.c @@ -9,6 +9,7 @@ #include #include #include +#include #ifndef CONFIG_SYS_NAND_BASE_LIST #define CONFIG_SYS_NAND_BASE_LIST { CONFIG_SYS_NAND_BASE } @@ -18,8 +19,7 @@ DECLARE_GLOBAL_DATA_PTR; int nand_curr_device = -1; - -struct mtd_info *nand_info[CONFIG_SYS_MAX_NAND_DEVICE]; +static struct mtd_info *nand_info[CONFIG_SYS_MAX_NAND_DEVICE]; #ifndef CONFIG_SYS_NAND_SELF_INIT static struct nand_chip nand_chip[CONFIG_SYS_MAX_NAND_DEVICE]; @@ -30,12 +30,21 @@ static char dev_name[CONFIG_SYS_MAX_NAND_DEVICE][8]; static unsigned long total_nand_size; /* in kiB */ +struct mtd_info *get_nand_dev_by_index(int dev) +{ + if (dev < 0 || dev >= CONFIG_SYS_MAX_NAND_DEVICE || !nand_info[dev] || + !nand_info[dev]->name) + return NULL; + + return nand_info[dev]; +} + int nand_mtd_to_devnum(struct mtd_info *mtd) { int i; - for (i = 0; i < ARRAY_SIZE(nand_info); i++) { - if (mtd && nand_info[i] == mtd) + for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++) { + if (mtd && get_nand_dev_by_index(i) == mtd) return i; } @@ -92,8 +101,62 @@ static void nand_init_chip(int i) } #endif +#ifdef CONFIG_MTD_CONCAT +static void create_mtd_concat(void) +{ + struct mtd_info *nand_info_list[CONFIG_SYS_MAX_NAND_DEVICE]; + int nand_devices_found = 0; + int i; + + for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++) { + struct mtd_info *mtd = get_nand_dev_by_index(i); + if (mtd != NULL) { + nand_info_list[nand_devices_found] = mtd; + nand_devices_found++; + } + } + if (nand_devices_found > 1) { + struct mtd_info *mtd; + char c_mtd_name[16]; + + /* + * We detected multiple devices. Concatenate them together. + */ + sprintf(c_mtd_name, "nand%d", nand_devices_found); + mtd = mtd_concat_create(nand_info_list, nand_devices_found, + c_mtd_name); + + if (mtd == NULL) + return; + + nand_register(nand_devices_found, mtd); + } + + return; +} +#else +static void create_mtd_concat(void) +{ +} +#endif + +unsigned long nand_size(void) +{ + return total_nand_size; +} + void nand_init(void) { + static int initialized; + + /* + * Avoid initializing NAND Flash multiple times, + * otherwise it will calculate a wrong total size. + */ + if (initialized) + return; + initialized = 1; + #ifdef CONFIG_SYS_NAND_SELF_INIT board_nand_init(); #else @@ -103,13 +166,13 @@ void nand_init(void) nand_init_chip(i); #endif - printf("%lu MiB\n", total_nand_size / 1024); - #ifdef CONFIG_SYS_NAND_SELECT_DEVICE /* * Select the chip in the board/cpu specific driver */ - board_nand_select_device(mtd_to_nand(nand_info[nand_curr_device]), + board_nand_select_device(mtd_to_nand(get_nand_dev_by_index(nand_curr_device)), nand_curr_device); #endif + + create_mtd_concat(); }