blob: ebd2acd02bf662bb7e5c614f4897a25a77d867c7 [file] [log] [blame]
Wolfgang Denk2f9b7e42005-08-17 12:55:25 +02001/*
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>
Wolfgang Denk2f9b7e42005-08-17 12:55:25 +020025#include <nand.h>
26
27#ifndef CFG_NAND_BASE_LIST
28#define CFG_NAND_BASE_LIST { CFG_NAND_BASE }
29#endif
30
31int nand_curr_device = -1;
32nand_info_t nand_info[CFG_MAX_NAND_DEVICE];
33
34static struct nand_chip nand_chip[CFG_MAX_NAND_DEVICE];
35static ulong base_address[CFG_MAX_NAND_DEVICE] = CFG_NAND_BASE_LIST;
36
37static const char default_nand_name[] = "nand";
38
Heiko Schocher3ec43662006-12-21 17:17:02 +010039extern int board_nand_init(struct nand_chip *nand);
Wolfgang Denk2f9b7e42005-08-17 12:55:25 +020040
41static void nand_init_chip(struct mtd_info *mtd, struct nand_chip *nand,
42 ulong base_addr)
43{
44 mtd->priv = nand;
45
Bartlomiej Sieka6eed2ab2006-02-24 09:37:22 +010046 nand->IO_ADDR_R = nand->IO_ADDR_W = (void __iomem *)base_addr;
Heiko Schocher3ec43662006-12-21 17:17:02 +010047 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 = NULL;
53 } else {
Wolfgang Denk2f9b7e42005-08-17 12:55:25 +020054 mtd->name = NULL;
Heiko Schocher3ec43662006-12-21 17:17:02 +010055 mtd->size = 0;
56 }
Wolfgang Denk2f9b7e42005-08-17 12:55:25 +020057
58}
59
60void nand_init(void)
61{
62 int i;
Bartlomiej Sieka6eed2ab2006-02-24 09:37:22 +010063 unsigned int size = 0;
Wolfgang Denk2f9b7e42005-08-17 12:55:25 +020064 for (i = 0; i < CFG_MAX_NAND_DEVICE; i++) {
65 nand_init_chip(&nand_info[i], &nand_chip[i], base_address[i]);
Bartlomiej Sieka6eed2ab2006-02-24 09:37:22 +010066 size += nand_info[i].size;
Wolfgang Denk2f9b7e42005-08-17 12:55:25 +020067 if (nand_curr_device == -1)
68 nand_curr_device = i;
Stefan Roese3cdd3fd2006-10-20 14:28:52 +020069 }
Stefan Roese3167d072008-07-10 10:10:54 +020070 printf("%u MiB\n", size / (1024 * 1024));
Stefan Roese3cdd3fd2006-10-20 14:28:52 +020071
72#ifdef CFG_NAND_SELECT_DEVICE
73 /*
74 * Select the chip in the board/cpu specific driver
75 */
76 board_nand_select_device(nand_info[nand_curr_device].priv, nand_curr_device);
77#endif
Wolfgang Denk2f9b7e42005-08-17 12:55:25 +020078}