2005-08-17 10:55:25 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2005
|
|
|
|
* 2N Telekomunikace, a.s. <www.2n.cz>
|
|
|
|
* Ladislav Michl <michl@2n.cz>
|
|
|
|
*
|
|
|
|
* See file CREDITS for list of people who contributed to this
|
|
|
|
* project.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* version 2 as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
|
|
|
* MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <nand.h>
|
|
|
|
|
2008-10-16 13:01:15 +00:00
|
|
|
#ifndef CONFIG_SYS_NAND_BASE_LIST
|
|
|
|
#define CONFIG_SYS_NAND_BASE_LIST { CONFIG_SYS_NAND_BASE }
|
2005-08-17 10:55:25 +00:00
|
|
|
#endif
|
|
|
|
|
2009-01-19 14:32:59 +00:00
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
2005-08-17 10:55:25 +00:00
|
|
|
int nand_curr_device = -1;
|
2008-10-16 13:01:15 +00:00
|
|
|
nand_info_t nand_info[CONFIG_SYS_MAX_NAND_DEVICE];
|
2005-08-17 10:55:25 +00:00
|
|
|
|
2008-10-16 13:01:15 +00:00
|
|
|
static struct nand_chip nand_chip[CONFIG_SYS_MAX_NAND_DEVICE];
|
|
|
|
static ulong base_address[CONFIG_SYS_MAX_NAND_DEVICE] = CONFIG_SYS_NAND_BASE_LIST;
|
2005-08-17 10:55:25 +00:00
|
|
|
|
|
|
|
static const char default_nand_name[] = "nand";
|
2009-04-24 13:59:35 +00:00
|
|
|
static __attribute__((unused)) char dev_name[CONFIG_SYS_MAX_NAND_DEVICE][8];
|
2005-08-17 10:55:25 +00:00
|
|
|
|
|
|
|
static void nand_init_chip(struct mtd_info *mtd, struct nand_chip *nand,
|
|
|
|
ulong base_addr)
|
|
|
|
{
|
2009-02-11 17:38:20 +00:00
|
|
|
int maxchips = CONFIG_SYS_NAND_MAX_CHIPS;
|
2009-04-24 13:59:35 +00:00
|
|
|
int __attribute__((unused)) i = 0;
|
2009-02-11 17:38:20 +00:00
|
|
|
|
|
|
|
if (maxchips < 1)
|
|
|
|
maxchips = 1;
|
2005-08-17 10:55:25 +00:00
|
|
|
mtd->priv = nand;
|
|
|
|
|
2006-02-24 08:37:22 +00:00
|
|
|
nand->IO_ADDR_R = nand->IO_ADDR_W = (void __iomem *)base_addr;
|
2006-12-21 16:17:02 +00:00
|
|
|
if (board_nand_init(nand) == 0) {
|
2009-02-11 17:38:20 +00:00
|
|
|
if (nand_scan(mtd, maxchips) == 0) {
|
2006-12-21 16:17:02 +00:00
|
|
|
if (!mtd->name)
|
|
|
|
mtd->name = (char *)default_nand_name;
|
2010-10-28 18:00:11 +00:00
|
|
|
#ifdef CONFIG_NEEDS_MANUAL_RELOC
|
2009-01-19 14:32:59 +00:00
|
|
|
else
|
|
|
|
mtd->name += gd->reloc_off;
|
2009-09-21 16:20:36 +00:00
|
|
|
#endif
|
2009-04-24 13:59:35 +00:00
|
|
|
|
2009-05-12 12:31:18 +00:00
|
|
|
#ifdef CONFIG_MTD_DEVICE
|
2009-04-24 13:59:35 +00:00
|
|
|
/*
|
|
|
|
* Add MTD device so that we can reference it later
|
|
|
|
* via the mtdcore infrastructure (e.g. ubi).
|
|
|
|
*/
|
|
|
|
sprintf(dev_name[i], "nand%d", i);
|
|
|
|
mtd->name = dev_name[i++];
|
|
|
|
add_mtd_device(mtd);
|
|
|
|
#endif
|
2006-12-21 16:17:02 +00:00
|
|
|
} else
|
|
|
|
mtd->name = NULL;
|
|
|
|
} else {
|
2005-08-17 10:55:25 +00:00
|
|
|
mtd->name = NULL;
|
2006-12-21 16:17:02 +00:00
|
|
|
mtd->size = 0;
|
|
|
|
}
|
2005-08-17 10:55:25 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void nand_init(void)
|
|
|
|
{
|
|
|
|
int i;
|
2006-02-24 08:37:22 +00:00
|
|
|
unsigned int size = 0;
|
2008-10-16 13:01:15 +00:00
|
|
|
for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++) {
|
2005-08-17 10:55:25 +00:00
|
|
|
nand_init_chip(&nand_info[i], &nand_chip[i], base_address[i]);
|
2008-09-19 09:32:49 +00:00
|
|
|
size += nand_info[i].size / 1024;
|
2005-08-17 10:55:25 +00:00
|
|
|
if (nand_curr_device == -1)
|
|
|
|
nand_curr_device = i;
|
2006-10-20 12:28:52 +00:00
|
|
|
}
|
2008-09-19 09:32:49 +00:00
|
|
|
printf("%u MiB\n", size / 1024);
|
2006-10-20 12:28:52 +00:00
|
|
|
|
2008-10-16 13:01:15 +00:00
|
|
|
#ifdef CONFIG_SYS_NAND_SELECT_DEVICE
|
2006-10-20 12:28:52 +00:00
|
|
|
/*
|
|
|
|
* Select the chip in the board/cpu specific driver
|
|
|
|
*/
|
|
|
|
board_nand_select_device(nand_info[nand_curr_device].priv, nand_curr_device);
|
|
|
|
#endif
|
2005-08-17 10:55:25 +00:00
|
|
|
}
|