blob: dd80026fe02ec63850248bd0a8ac8bfa18a0c578 [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>
25
Bartlomiej Sieka582f1a32006-03-05 18:57:33 +010026#ifdef CFG_NAND_LEGACY
27#error CFG_NAND_LEGACY defined in a file not using the legacy NAND support!
28#endif
29
Wolfgang Denk2f9b7e42005-08-17 12:55:25 +020030#if (CONFIG_COMMANDS & CFG_CMD_NAND)
31
32#include <nand.h>
33
34#ifndef CFG_NAND_BASE_LIST
35#define CFG_NAND_BASE_LIST { CFG_NAND_BASE }
36#endif
37
38int nand_curr_device = -1;
39nand_info_t nand_info[CFG_MAX_NAND_DEVICE];
40
41static struct nand_chip nand_chip[CFG_MAX_NAND_DEVICE];
42static ulong base_address[CFG_MAX_NAND_DEVICE] = CFG_NAND_BASE_LIST;
43
44static const char default_nand_name[] = "nand";
45
46extern void board_nand_init(struct nand_chip *nand);
47
48static void nand_init_chip(struct mtd_info *mtd, struct nand_chip *nand,
49 ulong base_addr)
50{
51 mtd->priv = nand;
52
Bartlomiej Sieka6eed2ab2006-02-24 09:37:22 +010053 nand->IO_ADDR_R = nand->IO_ADDR_W = (void __iomem *)base_addr;
Wolfgang Denk2f9b7e42005-08-17 12:55:25 +020054 board_nand_init(nand);
55
56 if (nand_scan(mtd, 1) == 0) {
57 if (!mtd->name)
Bartlomiej Sieka6eed2ab2006-02-24 09:37:22 +010058 mtd->name = (char *)default_nand_name;
Wolfgang Denk2f9b7e42005-08-17 12:55:25 +020059 } else
60 mtd->name = NULL;
61
62}
63
64void nand_init(void)
65{
66 int i;
Bartlomiej Sieka6eed2ab2006-02-24 09:37:22 +010067 unsigned int size = 0;
Wolfgang Denk2f9b7e42005-08-17 12:55:25 +020068 for (i = 0; i < CFG_MAX_NAND_DEVICE; i++) {
69 nand_init_chip(&nand_info[i], &nand_chip[i], base_address[i]);
Bartlomiej Sieka6eed2ab2006-02-24 09:37:22 +010070 size += nand_info[i].size;
Wolfgang Denk2f9b7e42005-08-17 12:55:25 +020071 if (nand_curr_device == -1)
72 nand_curr_device = i;
Bartlomiej Sieka6eed2ab2006-02-24 09:37:22 +010073}
74 printf("%lu MiB\n", size / (1024 * 1024));
Wolfgang Denk2f9b7e42005-08-17 12:55:25 +020075}
76
77#endif