Wolfgang Denk | 2f9b7e4 | 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> |
Wolfgang Denk | 2f9b7e4 | 2005-08-17 12:55:25 +0200 | [diff] [blame] | 25 | #include <nand.h> |
| 26 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 27 | #ifndef CONFIG_SYS_NAND_BASE_LIST |
| 28 | #define CONFIG_SYS_NAND_BASE_LIST { CONFIG_SYS_NAND_BASE } |
Wolfgang Denk | 2f9b7e4 | 2005-08-17 12:55:25 +0200 | [diff] [blame] | 29 | #endif |
| 30 | |
Valeriy Glushkov | 1d01207 | 2009-01-19 16:32:59 +0200 | [diff] [blame] | 31 | DECLARE_GLOBAL_DATA_PTR; |
| 32 | |
Wolfgang Denk | 2f9b7e4 | 2005-08-17 12:55:25 +0200 | [diff] [blame] | 33 | int nand_curr_device = -1; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 34 | nand_info_t nand_info[CONFIG_SYS_MAX_NAND_DEVICE]; |
Wolfgang Denk | 2f9b7e4 | 2005-08-17 12:55:25 +0200 | [diff] [blame] | 35 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 36 | static struct nand_chip nand_chip[CONFIG_SYS_MAX_NAND_DEVICE]; |
| 37 | static ulong base_address[CONFIG_SYS_MAX_NAND_DEVICE] = CONFIG_SYS_NAND_BASE_LIST; |
Wolfgang Denk | 2f9b7e4 | 2005-08-17 12:55:25 +0200 | [diff] [blame] | 38 | |
| 39 | static const char default_nand_name[] = "nand"; |
Stefan Roese | 4157c63 | 2009-04-24 15:59:35 +0200 | [diff] [blame^] | 40 | static __attribute__((unused)) char dev_name[CONFIG_SYS_MAX_NAND_DEVICE][8]; |
Wolfgang Denk | 2f9b7e4 | 2005-08-17 12:55:25 +0200 | [diff] [blame] | 41 | |
Wolfgang Denk | 2f9b7e4 | 2005-08-17 12:55:25 +0200 | [diff] [blame] | 42 | static void nand_init_chip(struct mtd_info *mtd, struct nand_chip *nand, |
| 43 | ulong base_addr) |
| 44 | { |
Wolfgang Grandegger | b325d7e | 2009-02-11 18:38:20 +0100 | [diff] [blame] | 45 | int maxchips = CONFIG_SYS_NAND_MAX_CHIPS; |
Stefan Roese | 4157c63 | 2009-04-24 15:59:35 +0200 | [diff] [blame^] | 46 | int __attribute__((unused)) i = 0; |
Wolfgang Grandegger | b325d7e | 2009-02-11 18:38:20 +0100 | [diff] [blame] | 47 | |
| 48 | if (maxchips < 1) |
| 49 | maxchips = 1; |
Wolfgang Denk | 2f9b7e4 | 2005-08-17 12:55:25 +0200 | [diff] [blame] | 50 | mtd->priv = nand; |
| 51 | |
Bartlomiej Sieka | 6eed2ab | 2006-02-24 09:37:22 +0100 | [diff] [blame] | 52 | nand->IO_ADDR_R = nand->IO_ADDR_W = (void __iomem *)base_addr; |
Heiko Schocher | 3ec4366 | 2006-12-21 17:17:02 +0100 | [diff] [blame] | 53 | if (board_nand_init(nand) == 0) { |
Wolfgang Grandegger | b325d7e | 2009-02-11 18:38:20 +0100 | [diff] [blame] | 54 | if (nand_scan(mtd, maxchips) == 0) { |
Heiko Schocher | 3ec4366 | 2006-12-21 17:17:02 +0100 | [diff] [blame] | 55 | if (!mtd->name) |
| 56 | mtd->name = (char *)default_nand_name; |
Valeriy Glushkov | 1d01207 | 2009-01-19 16:32:59 +0200 | [diff] [blame] | 57 | else |
| 58 | mtd->name += gd->reloc_off; |
Stefan Roese | 4157c63 | 2009-04-24 15:59:35 +0200 | [diff] [blame^] | 59 | |
| 60 | #ifdef CONFIG_MTD_PARTITIONS |
| 61 | /* |
| 62 | * Add MTD device so that we can reference it later |
| 63 | * via the mtdcore infrastructure (e.g. ubi). |
| 64 | */ |
| 65 | sprintf(dev_name[i], "nand%d", i); |
| 66 | mtd->name = dev_name[i++]; |
| 67 | add_mtd_device(mtd); |
| 68 | #endif |
Heiko Schocher | 3ec4366 | 2006-12-21 17:17:02 +0100 | [diff] [blame] | 69 | } else |
| 70 | mtd->name = NULL; |
| 71 | } else { |
Wolfgang Denk | 2f9b7e4 | 2005-08-17 12:55:25 +0200 | [diff] [blame] | 72 | mtd->name = NULL; |
Heiko Schocher | 3ec4366 | 2006-12-21 17:17:02 +0100 | [diff] [blame] | 73 | mtd->size = 0; |
| 74 | } |
Wolfgang Denk | 2f9b7e4 | 2005-08-17 12:55:25 +0200 | [diff] [blame] | 75 | |
| 76 | } |
| 77 | |
| 78 | void nand_init(void) |
| 79 | { |
| 80 | int i; |
Bartlomiej Sieka | 6eed2ab | 2006-02-24 09:37:22 +0100 | [diff] [blame] | 81 | unsigned int size = 0; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 82 | for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++) { |
Wolfgang Denk | 2f9b7e4 | 2005-08-17 12:55:25 +0200 | [diff] [blame] | 83 | nand_init_chip(&nand_info[i], &nand_chip[i], base_address[i]); |
Jason Jin | 3f08806 | 2008-09-19 17:32:49 +0800 | [diff] [blame] | 84 | size += nand_info[i].size / 1024; |
Wolfgang Denk | 2f9b7e4 | 2005-08-17 12:55:25 +0200 | [diff] [blame] | 85 | if (nand_curr_device == -1) |
| 86 | nand_curr_device = i; |
Stefan Roese | 3cdd3fd | 2006-10-20 14:28:52 +0200 | [diff] [blame] | 87 | } |
Jason Jin | 3f08806 | 2008-09-19 17:32:49 +0800 | [diff] [blame] | 88 | printf("%u MiB\n", size / 1024); |
Stefan Roese | 3cdd3fd | 2006-10-20 14:28:52 +0200 | [diff] [blame] | 89 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 90 | #ifdef CONFIG_SYS_NAND_SELECT_DEVICE |
Stefan Roese | 3cdd3fd | 2006-10-20 14:28:52 +0200 | [diff] [blame] | 91 | /* |
| 92 | * Select the chip in the board/cpu specific driver |
| 93 | */ |
| 94 | board_nand_select_device(nand_info[nand_curr_device].priv, nand_curr_device); |
| 95 | #endif |
Wolfgang Denk | 2f9b7e4 | 2005-08-17 12:55:25 +0200 | [diff] [blame] | 96 | } |