kb9202_nand.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*
  2. * (C) Copyright 2006
  3. * KwikByte <kb9200_dev@kwikbyte.com>
  4. *
  5. * (C) Copyright 2009
  6. * Matthias Kaehlcke <matthias@kaehlcke.net>
  7. *
  8. * See file CREDITS for list of people who contributed to this
  9. * project.
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License as
  13. * published by the Free Software Foundation; either version 2 of
  14. * the License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  24. * MA 02111-1307 USA
  25. */
  26. #include <common.h>
  27. #include <asm/io.h>
  28. #include <asm/arch/AT91RM9200.h>
  29. #include <asm/arch/hardware.h>
  30. #include <nand.h>
  31. /*
  32. * hardware specific access to control-lines
  33. */
  34. #define MASK_ALE (1 << 22) /* our ALE is A22 */
  35. #define MASK_CLE (1 << 21) /* our CLE is A21 */
  36. #define KB9202_NAND_NCE (1 << 28) /* EN* on D28 */
  37. #define KB9202_NAND_BUSY (1 << 29) /* RB* on D29 */
  38. #define KB9202_SMC2_NWS (1 << 2)
  39. #define KB9202_SMC2_TDF (1 << 8)
  40. #define KB9202_SMC2_RWSETUP (1 << 24)
  41. #define KB9202_SMC2_RWHOLD (1 << 29)
  42. /*
  43. * Board-specific function to access device control signals
  44. */
  45. static void kb9202_nand_hwcontrol(struct mtd_info *mtd, int cmd, unsigned int ctrl)
  46. {
  47. struct nand_chip *this = mtd->priv;
  48. if (ctrl & NAND_CTRL_CHANGE) {
  49. ulong IO_ADDR_W = (ulong) this->IO_ADDR_W;
  50. /* clear ALE and CLE bits */
  51. IO_ADDR_W &= ~(MASK_ALE | MASK_CLE);
  52. if (ctrl & NAND_CLE)
  53. IO_ADDR_W |= MASK_CLE;
  54. if (ctrl & NAND_ALE)
  55. IO_ADDR_W |= MASK_ALE;
  56. this->IO_ADDR_W = (void *) IO_ADDR_W;
  57. if (ctrl & NAND_NCE)
  58. writel(KB9202_NAND_NCE, AT91C_PIOC_CODR);
  59. else
  60. writel(KB9202_NAND_NCE, AT91C_PIOC_SODR);
  61. }
  62. if (cmd != NAND_CMD_NONE)
  63. writeb(cmd, this->IO_ADDR_W);
  64. }
  65. /*
  66. * Board-specific function to access the device ready signal.
  67. */
  68. static int kb9202_nand_ready(struct mtd_info *mtd)
  69. {
  70. return readl(AT91C_PIOC_PDSR) & KB9202_NAND_BUSY;
  71. }
  72. /*
  73. * Board-specific NAND init. Copied from include/linux/mtd/nand.h for reference.
  74. *
  75. * struct nand_chip - NAND Private Flash Chip Data
  76. * @IO_ADDR_R: [BOARDSPECIFIC] address to read the 8 I/O lines of the flash device
  77. * @IO_ADDR_W: [BOARDSPECIFIC] address to write the 8 I/O lines of the flash device
  78. * @hwcontrol: [BOARDSPECIFIC] hardwarespecific function for accesing control-lines
  79. * @dev_ready: [BOARDSPECIFIC] hardwarespecific function for accesing device ready/busy line
  80. * If set to NULL no access to ready/busy is available and the ready/busy information
  81. * is read from the chip status register
  82. * @enable_hwecc: [BOARDSPECIFIC] function to enable (reset) hardware ecc generator. Must only
  83. * be provided if a hardware ECC is available
  84. * @eccmode: [BOARDSPECIFIC] mode of ecc, see defines
  85. * @chip_delay: [BOARDSPECIFIC] chip dependent delay for transfering data from array to read regs (tR)
  86. * @options: [BOARDSPECIFIC] various chip options. They can partly be set to inform nand_scan about
  87. * special functionality. See the defines for further explanation
  88. */
  89. /*
  90. * This routine initializes controller and GPIOs.
  91. */
  92. int board_nand_init(struct nand_chip *nand)
  93. {
  94. unsigned int value;
  95. nand->ecc.mode = NAND_ECC_SOFT;
  96. nand->cmd_ctrl = kb9202_nand_hwcontrol;
  97. nand->dev_ready = kb9202_nand_ready;
  98. /* in case running outside of bootloader */
  99. writel(1 << AT91C_ID_PIOC, AT91C_PMC_PCER);
  100. /* setup nand flash access (allow ample margin) */
  101. /* 4 wait states, 1 setup, 1 hold, 1 float for 8-bit device */
  102. writel(AT91C_SMC2_WSEN | KB9202_SMC2_NWS | KB9202_SMC2_TDF |
  103. AT91C_SMC2_DBW_8 | KB9202_SMC2_RWSETUP | KB9202_SMC2_RWHOLD,
  104. AT91C_SMC_CSR3);
  105. /* enable internal NAND controller */
  106. value = readl(AT91C_EBI_CSA);
  107. value |= AT91C_EBI_CS3A_SMC_SmartMedia;
  108. writel(value, AT91C_EBI_CSA);
  109. /* enable SMOE/SMWE */
  110. writel(AT91C_PC1_BFRDY_SMOE | AT91C_PC3_BFBAA_SMWE, AT91C_PIOC_ASR);
  111. writel(AT91C_PC1_BFRDY_SMOE | AT91C_PC3_BFBAA_SMWE, AT91C_PIOC_PDR);
  112. writel(AT91C_PC1_BFRDY_SMOE | AT91C_PC3_BFBAA_SMWE, AT91C_PIOC_OER);
  113. /* set NCE to high */
  114. writel(KB9202_NAND_NCE, AT91C_PIOC_SODR);
  115. /* disable output on pin connected to the busy line of the NAND */
  116. writel(KB9202_NAND_BUSY, AT91C_PIOC_ODR);
  117. /* enable the PIO to control NCE and BUSY */
  118. writel(KB9202_NAND_NCE | KB9202_NAND_BUSY, AT91C_PIOC_PER);
  119. /* enable output for NCE */
  120. writel(KB9202_NAND_NCE, AT91C_PIOC_OER);
  121. return (0);
  122. }