nand.c 2.0 KB

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