nand.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. #ifdef CONFIG_NEW_NAND_CODE
  25. #if (CONFIG_COMMANDS & CFG_CMD_NAND)
  26. #include <nand.h>
  27. #ifndef CFG_NAND_BASE_LIST
  28. #define CFG_NAND_BASE_LIST { CFG_NAND_BASE }
  29. #endif
  30. int nand_curr_device = -1;
  31. nand_info_t nand_info[CFG_MAX_NAND_DEVICE];
  32. static struct nand_chip nand_chip[CFG_MAX_NAND_DEVICE];
  33. static ulong base_address[CFG_MAX_NAND_DEVICE] = CFG_NAND_BASE_LIST;
  34. static const char default_nand_name[] = "nand";
  35. extern void board_nand_init(struct nand_chip *nand);
  36. static void nand_init_chip(struct mtd_info *mtd, struct nand_chip *nand,
  37. ulong base_addr)
  38. {
  39. mtd->priv = nand;
  40. nand->IO_ADDR_R = nand->IO_ADDR_W = (void __iomem *)base_addr;
  41. board_nand_init(nand);
  42. if (nand_scan(mtd, 1) == 0) {
  43. if (!mtd->name)
  44. mtd->name = (char *)default_nand_name;
  45. } else
  46. mtd->name = NULL;
  47. }
  48. void nand_init(void)
  49. {
  50. int i;
  51. unsigned int size = 0;
  52. for (i = 0; i < CFG_MAX_NAND_DEVICE; i++) {
  53. nand_init_chip(&nand_info[i], &nand_chip[i], base_address[i]);
  54. size += nand_info[i].size;
  55. if (nand_curr_device == -1)
  56. nand_curr_device = i;
  57. }
  58. printf("%lu MiB\n", size / (1024 * 1024));
  59. }
  60. #endif
  61. #endif /* CONFIG_NEW_NAND_CODE */