nand.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. #include <common.h>
  24. #include <nand.h>
  25. #ifndef CONFIG_SYS_NAND_BASE_LIST
  26. #define CONFIG_SYS_NAND_BASE_LIST { CONFIG_SYS_NAND_BASE }
  27. #endif
  28. DECLARE_GLOBAL_DATA_PTR;
  29. int nand_curr_device = -1;
  30. nand_info_t nand_info[CONFIG_SYS_MAX_NAND_DEVICE];
  31. static struct nand_chip nand_chip[CONFIG_SYS_MAX_NAND_DEVICE];
  32. static ulong base_address[CONFIG_SYS_MAX_NAND_DEVICE] = CONFIG_SYS_NAND_BASE_LIST;
  33. static const char default_nand_name[] = "nand";
  34. static void nand_init_chip(struct mtd_info *mtd, struct nand_chip *nand,
  35. ulong base_addr)
  36. {
  37. int maxchips = CONFIG_SYS_NAND_MAX_CHIPS;
  38. if (maxchips < 1)
  39. maxchips = 1;
  40. mtd->priv = nand;
  41. nand->IO_ADDR_R = nand->IO_ADDR_W = (void __iomem *)base_addr;
  42. if (board_nand_init(nand) == 0) {
  43. if (nand_scan(mtd, maxchips) == 0) {
  44. if (!mtd->name)
  45. mtd->name = (char *)default_nand_name;
  46. else
  47. mtd->name += gd->reloc_off;
  48. } else
  49. mtd->name = NULL;
  50. } else {
  51. mtd->name = NULL;
  52. mtd->size = 0;
  53. }
  54. }
  55. void nand_init(void)
  56. {
  57. int i;
  58. unsigned int size = 0;
  59. for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++) {
  60. nand_init_chip(&nand_info[i], &nand_chip[i], base_address[i]);
  61. size += nand_info[i].size / 1024;
  62. if (nand_curr_device == -1)
  63. nand_curr_device = i;
  64. }
  65. printf("%u MiB\n", size / 1024);
  66. #ifdef CONFIG_SYS_NAND_SELECT_DEVICE
  67. /*
  68. * Select the chip in the board/cpu specific driver
  69. */
  70. board_nand_select_device(nand_info[nand_curr_device].priv, nand_curr_device);
  71. #endif
  72. }