Wolfgang Denk | 932394a | 2005-08-17 12:55:25 +0200 | [diff] [blame] | 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 | |
Jon Loeliger | d5be43d | 2007-06-11 19:02:10 -0500 | [diff] [blame] | 26 | #if ((CONFIG_COMMANDS & CFG_CMD_NAND) || defined(CONFIG_CMD_NAND)) && !defined(CFG_NAND_LEGACY) |
Wolfgang Denk | 932394a | 2005-08-17 12:55:25 +0200 | [diff] [blame] | 27 | |
| 28 | #include <nand.h> |
| 29 | |
| 30 | #ifndef CFG_NAND_BASE_LIST |
| 31 | #define CFG_NAND_BASE_LIST { CFG_NAND_BASE } |
| 32 | #endif |
| 33 | |
| 34 | int nand_curr_device = -1; |
| 35 | nand_info_t nand_info[CFG_MAX_NAND_DEVICE]; |
| 36 | |
| 37 | static struct nand_chip nand_chip[CFG_MAX_NAND_DEVICE]; |
| 38 | static ulong base_address[CFG_MAX_NAND_DEVICE] = CFG_NAND_BASE_LIST; |
| 39 | |
| 40 | static const char default_nand_name[] = "nand"; |
| 41 | |
Heiko Schocher | fa23044 | 2006-12-21 17:17:02 +0100 | [diff] [blame] | 42 | extern int board_nand_init(struct nand_chip *nand); |
Wolfgang Denk | 932394a | 2005-08-17 12:55:25 +0200 | [diff] [blame] | 43 | |
| 44 | static void nand_init_chip(struct mtd_info *mtd, struct nand_chip *nand, |
| 45 | ulong base_addr) |
| 46 | { |
| 47 | mtd->priv = nand; |
| 48 | |
Bartlomiej Sieka | 038ccac | 2006-02-24 09:37:22 +0100 | [diff] [blame] | 49 | nand->IO_ADDR_R = nand->IO_ADDR_W = (void __iomem *)base_addr; |
Heiko Schocher | fa23044 | 2006-12-21 17:17:02 +0100 | [diff] [blame] | 50 | if (board_nand_init(nand) == 0) { |
| 51 | if (nand_scan(mtd, 1) == 0) { |
| 52 | if (!mtd->name) |
| 53 | mtd->name = (char *)default_nand_name; |
| 54 | } else |
| 55 | mtd->name = NULL; |
| 56 | } else { |
Wolfgang Denk | 932394a | 2005-08-17 12:55:25 +0200 | [diff] [blame] | 57 | mtd->name = NULL; |
Heiko Schocher | fa23044 | 2006-12-21 17:17:02 +0100 | [diff] [blame] | 58 | mtd->size = 0; |
| 59 | } |
Wolfgang Denk | 932394a | 2005-08-17 12:55:25 +0200 | [diff] [blame] | 60 | |
| 61 | } |
| 62 | |
| 63 | void nand_init(void) |
| 64 | { |
| 65 | int i; |
Bartlomiej Sieka | 038ccac | 2006-02-24 09:37:22 +0100 | [diff] [blame] | 66 | unsigned int size = 0; |
Wolfgang Denk | 932394a | 2005-08-17 12:55:25 +0200 | [diff] [blame] | 67 | for (i = 0; i < CFG_MAX_NAND_DEVICE; i++) { |
| 68 | nand_init_chip(&nand_info[i], &nand_chip[i], base_address[i]); |
Bartlomiej Sieka | 038ccac | 2006-02-24 09:37:22 +0100 | [diff] [blame] | 69 | size += nand_info[i].size; |
Wolfgang Denk | 932394a | 2005-08-17 12:55:25 +0200 | [diff] [blame] | 70 | if (nand_curr_device == -1) |
| 71 | nand_curr_device = i; |
Stefan Roese | 43a2b0e | 2006-10-20 14:28:52 +0200 | [diff] [blame] | 72 | } |
Bartlomiej Sieka | 038ccac | 2006-02-24 09:37:22 +0100 | [diff] [blame] | 73 | printf("%lu MiB\n", size / (1024 * 1024)); |
Stefan Roese | 43a2b0e | 2006-10-20 14:28:52 +0200 | [diff] [blame] | 74 | |
| 75 | #ifdef CFG_NAND_SELECT_DEVICE |
| 76 | /* |
| 77 | * Select the chip in the board/cpu specific driver |
| 78 | */ |
| 79 | board_nand_select_device(nand_info[nand_curr_device].priv, nand_curr_device); |
| 80 | #endif |
Wolfgang Denk | 932394a | 2005-08-17 12:55:25 +0200 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | #endif |