nand.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. * (C) Copyright 2006 DENX Software Engineering
  3. *
  4. * See file CREDITS for list of people who contributed to this
  5. * project.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  20. * MA 02111-1307 USA
  21. */
  22. #include <common.h>
  23. #if (CONFIG_COMMANDS & CFG_CMD_NAND)
  24. #ifdef CONFIG_NEW_NAND_CODE
  25. /* new NAND handling */
  26. #include <nand.h>
  27. /*
  28. * hardware specific access to control-lines
  29. * function borrowed from Linux 2.6 (drivers/mtd/nand/ppchameleonevb.c)
  30. */
  31. static void ppchameleonevb_hwcontrol(struct mtd_info *mtdinfo, int cmd)
  32. {
  33. struct nand_chip *this = mtdinfo->priv;
  34. ulong base = (ulong) this->IO_ADDR_W;
  35. switch(cmd) {
  36. case NAND_CTL_SETCLE:
  37. MACRO_NAND_CTL_SETCLE((unsigned long)base);
  38. break;
  39. case NAND_CTL_CLRCLE:
  40. MACRO_NAND_CTL_CLRCLE((unsigned long)base);
  41. break;
  42. case NAND_CTL_SETALE:
  43. MACRO_NAND_CTL_SETALE((unsigned long)base);
  44. break;
  45. case NAND_CTL_CLRALE:
  46. MACRO_NAND_CTL_CLRALE((unsigned long)base);
  47. break;
  48. case NAND_CTL_SETNCE:
  49. MACRO_NAND_ENABLE_CE((unsigned long)base);
  50. break;
  51. case NAND_CTL_CLRNCE:
  52. MACRO_NAND_DISABLE_CE((unsigned long)base);
  53. break;
  54. }
  55. }
  56. /*
  57. * read device ready pin
  58. * function +/- borrowed from Linux 2.6 (drivers/mtd/nand/ppchameleonevb.c)
  59. */
  60. static int ppchameleonevb_device_ready(struct mtd_info *mtdinfo)
  61. {
  62. struct nand_chip *this = mtdinfo->priv;
  63. ulong rb_gpio_pin;
  64. /* use the base addr to find out which chip are we dealing with */
  65. switch((ulong) this->IO_ADDR_W) {
  66. case CFG_NAND0_BASE:
  67. rb_gpio_pin = CFG_NAND0_RDY;
  68. break;
  69. case CFG_NAND1_BASE:
  70. rb_gpio_pin = CFG_NAND1_RDY;
  71. break;
  72. default: /* this should never happen */
  73. return 0;
  74. break;
  75. }
  76. if (in32(GPIO0_IR) & rb_gpio_pin)
  77. return 1;
  78. return 0;
  79. }
  80. /*
  81. * Board-specific NAND initialization. The following members of the
  82. * argument are board-specific (per include/linux/mtd/nand_new.h):
  83. * - IO_ADDR_R?: address to read the 8 I/O lines of the flash device
  84. * - IO_ADDR_W?: address to write the 8 I/O lines of the flash device
  85. * - hwcontrol: hardwarespecific function for accesing control-lines
  86. * - dev_ready: hardwarespecific function for accesing device ready/busy line
  87. * - enable_hwecc?: function to enable (reset) hardware ecc generator. Must
  88. * only be provided if a hardware ECC is available
  89. * - eccmode: mode of ecc, see defines
  90. * - chip_delay: chip dependent delay for transfering data from array to
  91. * read regs (tR)
  92. * - options: various chip options. They can partly be set to inform
  93. * nand_scan about special functionality. See the defines for further
  94. * explanation
  95. * Members with a "?" were not set in the merged testing-NAND branch,
  96. * so they are not set here either.
  97. */
  98. void board_nand_init(struct nand_chip *nand)
  99. {
  100. nand->hwcontrol = ppchameleonevb_hwcontrol;
  101. nand->dev_ready = ppchameleonevb_device_ready;
  102. nand->eccmode = NAND_ECC_SOFT;
  103. nand->chip_delay = NAND_BIG_DELAY_US;
  104. nand->options = NAND_SAMSUNG_LP_OPTIONS;
  105. }
  106. #else
  107. /* old NAND handling */
  108. extern ulong
  109. nand_probe(ulong physadr);
  110. void
  111. nand_init(void)
  112. {
  113. ulong totlen = 0;
  114. /*
  115. The HI model is equipped with a large block NAND chip not supported yet
  116. by U-Boot
  117. (CONFIG_PPCHAMELEON_MODULE_MODEL == CONFIG_PPCHAMELEON_MODULE_HI)
  118. */
  119. #if (CONFIG_PPCHAMELEON_MODULE_MODEL == CONFIG_PPCHAMELEON_MODULE_ME)
  120. debug ("Probing at 0x%.8x\n", CFG_NAND0_BASE);
  121. totlen += nand_probe (CFG_NAND0_BASE);
  122. #endif /* CONFIG_PPCHAMELEON_MODULE_ME, CONFIG_PPCHAMELEON_MODULE_HI */
  123. debug ("Probing at 0x%.8x\n", CFG_NAND1_BASE);
  124. totlen += nand_probe (CFG_NAND1_BASE);
  125. printf ("%3lu MB\n", totlen >>20);
  126. }
  127. #endif
  128. #endif