nand.c 3.1 KB

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