nand.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 defined(CONFIG_CMD_NAND)
  24. #include <nand.h>
  25. /*
  26. * hardware specific access to control-lines
  27. * function borrowed from Linux 2.6 (drivers/mtd/nand/ppchameleonevb.c)
  28. */
  29. static void ppchameleonevb_hwcontrol(struct mtd_info *mtdinfo, int cmd)
  30. {
  31. struct nand_chip *this = mtdinfo->priv;
  32. ulong base = (ulong) this->IO_ADDR_W;
  33. switch(cmd) {
  34. case NAND_CTL_SETCLE:
  35. MACRO_NAND_CTL_SETCLE((unsigned long)base);
  36. break;
  37. case NAND_CTL_CLRCLE:
  38. MACRO_NAND_CTL_CLRCLE((unsigned long)base);
  39. break;
  40. case NAND_CTL_SETALE:
  41. MACRO_NAND_CTL_SETALE((unsigned long)base);
  42. break;
  43. case NAND_CTL_CLRALE:
  44. MACRO_NAND_CTL_CLRALE((unsigned long)base);
  45. break;
  46. case NAND_CTL_SETNCE:
  47. MACRO_NAND_ENABLE_CE((unsigned long)base);
  48. break;
  49. case NAND_CTL_CLRNCE:
  50. MACRO_NAND_DISABLE_CE((unsigned long)base);
  51. break;
  52. }
  53. }
  54. /*
  55. * read device ready pin
  56. * function +/- borrowed from Linux 2.6 (drivers/mtd/nand/ppchameleonevb.c)
  57. */
  58. static int ppchameleonevb_device_ready(struct mtd_info *mtdinfo)
  59. {
  60. struct nand_chip *this = mtdinfo->priv;
  61. ulong rb_gpio_pin;
  62. /* use the base addr to find out which chip are we dealing with */
  63. switch((ulong) this->IO_ADDR_W) {
  64. case CFG_NAND0_BASE:
  65. rb_gpio_pin = CFG_NAND0_RDY;
  66. break;
  67. case CFG_NAND1_BASE:
  68. rb_gpio_pin = CFG_NAND1_RDY;
  69. break;
  70. default: /* this should never happen */
  71. return 0;
  72. break;
  73. }
  74. if (in32(GPIO0_IR) & rb_gpio_pin)
  75. return 1;
  76. return 0;
  77. }
  78. /*
  79. * Board-specific NAND initialization. The following members of the
  80. * argument are board-specific (per include/linux/mtd/nand.h):
  81. * - IO_ADDR_R?: address to read the 8 I/O lines of the flash device
  82. * - IO_ADDR_W?: address to write the 8 I/O lines of the flash device
  83. * - hwcontrol: hardwarespecific function for accesing control-lines
  84. * - dev_ready: hardwarespecific function for accesing device ready/busy line
  85. * - enable_hwecc?: function to enable (reset) hardware ecc generator. Must
  86. * only be provided if a hardware ECC is available
  87. * - eccmode: mode of ecc, see defines
  88. * - chip_delay: chip dependent delay for transfering data from array to
  89. * read regs (tR)
  90. * - options: various chip options. They can partly be set to inform
  91. * nand_scan about special functionality. See the defines for further
  92. * explanation
  93. * Members with a "?" were not set in the merged testing-NAND branch,
  94. * so they are not set here either.
  95. */
  96. int board_nand_init(struct nand_chip *nand)
  97. {
  98. nand->hwcontrol = ppchameleonevb_hwcontrol;
  99. nand->dev_ready = ppchameleonevb_device_ready;
  100. nand->eccmode = NAND_ECC_SOFT;
  101. nand->chip_delay = NAND_BIG_DELAY_US;
  102. nand->options = NAND_SAMSUNG_LP_OPTIONS;
  103. return 0;
  104. }
  105. #endif