1/* 2 * (C) Copyright 2005 3 * 2N Telekomunikace, a.s. <www.2n.cz> 4 * Ladislav Michl <michl@2n.cz> 5 * 6 * See file CREDITS for list of people who contributed to this 7 * project. 8 * 9 * This program is free software; you can redistribute it and/or 10 * modify it under the terms of the GNU General Public License 11 * version 2 as published by the Free Software Foundation. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 21 * MA 02111-1307 USA 22 */ 23 24#include <common.h> 25#include <nand.h> 26 27#ifndef CONFIG_SYS_NAND_BASE_LIST 28#define CONFIG_SYS_NAND_BASE_LIST { CONFIG_SYS_NAND_BASE } 29#endif 30 31DECLARE_GLOBAL_DATA_PTR; 32 33int nand_curr_device = -1; 34nand_info_t nand_info[CONFIG_SYS_MAX_NAND_DEVICE]; 35 36static struct nand_chip nand_chip[CONFIG_SYS_MAX_NAND_DEVICE]; 37static ulong base_address[CONFIG_SYS_MAX_NAND_DEVICE] = CONFIG_SYS_NAND_BASE_LIST; 38 39static const char default_nand_name[] = "nand"; 40 41static void nand_init_chip(struct mtd_info *mtd, struct nand_chip *nand, 42 ulong base_addr) 43{ 44 mtd->priv = nand; 45 46 nand->IO_ADDR_R = nand->IO_ADDR_W = (void __iomem *)base_addr; 47 if (board_nand_init(nand) == 0) { 48 if (nand_scan(mtd, 1) == 0) { 49 if (!mtd->name) 50 mtd->name = (char *)default_nand_name; 51 else 52 mtd->name += gd->reloc_off; 53 } else 54 mtd->name = NULL; 55 } else { 56 mtd->name = NULL; 57 mtd->size = 0; 58 } 59 60} 61 62void nand_init(void) 63{ 64 int i; 65 unsigned int size = 0; 66 for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++) { 67 nand_init_chip(&nand_info[i], &nand_chip[i], base_address[i]); 68 size += nand_info[i].size / 1024; 69 if (nand_curr_device == -1) 70 nand_curr_device = i; 71 } 72 printf("%u MiB\n", size / 1024); 73 74#ifdef CONFIG_SYS_NAND_SELECT_DEVICE 75 /* 76 * Select the chip in the board/cpu specific driver 77 */ 78 board_nand_select_device(nand_info[nand_curr_device].priv, nand_curr_device); 79#endif 80} 81