nand.c 3.4 KB

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