3 * 2N Telekomunikace, a.s. <www.2n.cz>
4 * Ladislav Michl <michl@2n.cz>
6 * SPDX-License-Identifier: GPL-2.0
13 #ifndef CONFIG_SYS_NAND_BASE_LIST
14 #define CONFIG_SYS_NAND_BASE_LIST { CONFIG_SYS_NAND_BASE }
17 DECLARE_GLOBAL_DATA_PTR;
19 int nand_curr_device = -1;
22 nand_info_t nand_info[CONFIG_SYS_MAX_NAND_DEVICE];
24 #ifndef CONFIG_SYS_NAND_SELF_INIT
25 static struct nand_chip nand_chip[CONFIG_SYS_MAX_NAND_DEVICE];
26 static ulong base_address[CONFIG_SYS_MAX_NAND_DEVICE] = CONFIG_SYS_NAND_BASE_LIST;
29 static char dev_name[CONFIG_SYS_MAX_NAND_DEVICE][8];
31 static unsigned long total_nand_size; /* in kiB */
33 /* Register an initialized NAND mtd device with the U-Boot NAND command. */
34 int nand_register(int devnum)
38 if (devnum >= CONFIG_SYS_MAX_NAND_DEVICE)
41 mtd = &nand_info[devnum];
43 sprintf(dev_name[devnum], "nand%d", devnum);
44 mtd->name = dev_name[devnum];
46 #ifdef CONFIG_MTD_DEVICE
48 * Add MTD device so that we can reference it later
49 * via the mtdcore infrastructure (e.g. ubi).
54 total_nand_size += mtd->size / 1024;
56 if (nand_curr_device == -1)
57 nand_curr_device = devnum;
62 #ifndef CONFIG_SYS_NAND_SELF_INIT
63 static void nand_init_chip(int i)
65 struct mtd_info *mtd = &nand_info[i];
66 struct nand_chip *nand = &nand_chip[i];
67 ulong base_addr = base_address[i];
68 int maxchips = CONFIG_SYS_NAND_MAX_CHIPS;
74 nand->IO_ADDR_R = nand->IO_ADDR_W = (void __iomem *)base_addr;
76 if (board_nand_init(nand))
79 if (nand_scan(mtd, maxchips))
88 #ifdef CONFIG_SYS_NAND_SELF_INIT
93 for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++)
97 printf("%lu MiB\n", total_nand_size / 1024);
99 #ifdef CONFIG_SYS_NAND_SELECT_DEVICE
101 * Select the chip in the board/cpu specific driver
103 board_nand_select_device(nand_info[nand_curr_device].priv, nand_curr_device);