nand.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * (C) Copyright 2006 Aubrey.Li, aubrey.li@analog.com
  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. #define CONCAT(a,b,c,d) a ## b ## c ## d
  27. #define PORT(a,b) CONCAT(pPORT,a,b,)
  28. #ifndef CONFIG_NAND_GPIO_PORT
  29. #define CONFIG_NAND_GPIO_PORT F
  30. #endif
  31. /*
  32. * hardware specific access to control-lines
  33. */
  34. static void bfin_hwcontrol(struct mtd_info *mtd, int cmd, unsigned int ctrl)
  35. {
  36. register struct nand_chip *this = mtd->priv;
  37. u32 IO_ADDR_W = (u32) this->IO_ADDR_W;
  38. if (ctrl & NAND_CTRL_CHANGE) {
  39. if( ctrl & NAND_CLE )
  40. IO_ADDR_W = CFG_NAND_BASE + BFIN_NAND_CLE;
  41. else
  42. IO_ADDR_W = CFG_NAND_BASE;
  43. if( ctrl & NAND_ALE )
  44. IO_ADDR_W = CFG_NAND_BASE + BFIN_NAND_ALE;
  45. else
  46. IO_ADDR_W = CFG_NAND_BASE;
  47. this->IO_ADDR_W = (void __iomem *) IO_ADDR_W;
  48. }
  49. this->IO_ADDR_R = this->IO_ADDR_W;
  50. /* Drain the writebuffer */
  51. SSYNC();
  52. if (cmd != NAND_CMD_NONE)
  53. writeb(cmd, this->IO_ADDR_W);
  54. }
  55. int bfin_device_ready(struct mtd_info *mtd)
  56. {
  57. int ret = (*PORT(CONFIG_NAND_GPIO_PORT, IO) & BFIN_NAND_READY) ? 1 : 0;
  58. SSYNC();
  59. return ret;
  60. }
  61. /*
  62. * Board-specific NAND initialization. The following members of the
  63. * argument are board-specific (per include/linux/mtd/nand.h):
  64. * - IO_ADDR_R?: address to read the 8 I/O lines of the flash device
  65. * - IO_ADDR_W?: address to write the 8 I/O lines of the flash device
  66. * - cmd_ctrl: hardwarespecific function for accesing control-lines
  67. * - dev_ready: hardwarespecific function for accesing device ready/busy line
  68. * - enable_hwecc?: function to enable (reset) hardware ecc generator. Must
  69. * only be provided if a hardware ECC is available
  70. * - ecc.mode: mode of ecc, see defines
  71. * - chip_delay: chip dependent delay for transfering data from array to
  72. * read regs (tR)
  73. * - options: various chip options. They can partly be set to inform
  74. * nand_scan about special functionality. See the defines for further
  75. * explanation
  76. * Members with a "?" were not set in the merged testing-NAND branch,
  77. * so they are not set here either.
  78. */
  79. void board_nand_init(struct nand_chip *nand)
  80. {
  81. *PORT(CONFIG_NAND_GPIO_PORT, _FER) &= ~BFIN_NAND_READY;
  82. *PORT(CONFIG_NAND_GPIO_PORT, IO_DIR) &= ~BFIN_NAND_READY;
  83. *PORT(CONFIG_NAND_GPIO_PORT, IO_INEN) |= BFIN_NAND_READY;
  84. nand->cmd_ctrl = bfin_hwcontrol;
  85. nand->ecc.mode = NAND_ECC_SOFT;
  86. nand->dev_ready = bfin_device_ready;
  87. nand->chip_delay = 30;
  88. }
  89. #endif