nand.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /**
  2. * \file nand.h
  3. *
  4. * \brief Definitions used for NAND
  5. *
  6. * This file contains the nand middle layer API prototypes and macro definitions.
  7. */
  8. /*
  9. * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
  10. */
  11. /*
  12. * Redistribution and use in source and binary forms, with or without
  13. * modification, are permitted provided that the following conditions
  14. * are met:
  15. *
  16. * Redistributions of source code must retain the above copyright
  17. * notice, this list of conditions and the following disclaimer.
  18. *
  19. * Redistributions in binary form must reproduce the above copyright
  20. * notice, this list of conditions and the following disclaimer in the
  21. * documentation and/or other materials provided with the
  22. * distribution.
  23. *
  24. * Neither the name of Texas Instruments Incorporated nor the names of
  25. * its contributors may be used to endorse or promote products derived
  26. * from this software without specific prior written permission.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  29. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  30. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  31. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  32. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  33. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  34. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  35. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  36. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  37. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  38. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  39. *
  40. */
  41. #ifndef _NAND_H_
  42. #define _NAND_H__
  43. #ifdef __cplusplus
  44. extern "C" {
  45. #endif
  46. /*******************************************************************************
  47. * MACRO DEFINITIONS
  48. *******************************************************************************/
  49. /* Resister Location of NAND to communicate */
  50. #define AM1808
  51. #ifdef AM1808
  52. #define CS3_NAND_DATA_REG (0x62000000u)
  53. #define CS3_NAND_CMD_REG (0x62000010u)
  54. #define CS3_NAND_ADDR_REG (0x62000008u)
  55. #endif
  56. /* Macro to read the Data from Data Register */
  57. #define NANDDataRead (*(volatile unsigned char*)(CS3_NAND_DATA_REG))
  58. /* Macro to write the Address To NAND address Register */
  59. #define NANDAddressWrite(address) \
  60. (*(volatile unsigned char*)(CS3_NAND_ADDR_REG) = (address))
  61. /* Macro to write the Command To NAND Command Register */
  62. #define NANDCommandWrite(command) \
  63. (*(volatile unsigned char*)(CS3_NAND_CMD_REG) = (command))
  64. /* Macro to write the Data to Data Register */
  65. #define NANDDataWrite(data) \
  66. (*(volatile unsigned char*)(CS3_NAND_DATA_REG) = (data))
  67. #define NANDDataWrite16(data) \
  68. (*(volatile unsigned short*)(CS3_NAND_DATA_REG) = (data))
  69. /* Macro to read the Data from Data Register */
  70. #define NANDDataRead (*(volatile unsigned char*)(CS3_NAND_DATA_REG))
  71. #define NANDDataRead16 (*(volatile unsigned short*)(CS3_NAND_DATA_REG))
  72. /* Number Of Pages Per Blk */
  73. #define NAND_PAGES_PER_BLK (64)
  74. #define NAND_PAGE_SIZE (2048)
  75. #define NAND_RD_WR_SIZE (NAND_PAGE_SIZE)
  76. #define NAND_NUM_OF_TRNFS (4)
  77. #define NAND_BYTES_PER_TRNFS (NAND_RD_WR_SIZE / \
  78. NAND_NUM_OF_TRNFS)
  79. #define NAND_SPARE_AREA_BAD_BLOCK_MARK_OFFSET (2048)
  80. /* NAND STATUS VALUES */
  81. #define NAND_STATUS_CMD_PASSED (0)
  82. #define NAND_STATUS_CMD_FAILED (1)
  83. #define NAND_STATUS_WAIT_TIMEOUT (2)
  84. #define NAND_STATUS_WRITE_PROTECTED (3)
  85. #define NAND_1BIT_ECC (1)
  86. #define NAND_4BIT_ECC (2)
  87. #define NAND_ECC_CHECK_PASSED (0u)
  88. #define NAND_ECC_CHECK_FAILED (1u)
  89. #define NAND_ECC_CORRECTION_ECCSTATE_0 (0u)
  90. #define NAND_ECC_CORRECTION_ECCSTATE_2 (2u)
  91. #define NAND_ECC_CORRECTION_ECCSTATE_3 (3u)
  92. #define NAND_ECC_CORRECTION_NO_ERROR (0)
  93. #define NAND_ECC_ERROR_CORRECTED (1)
  94. #define NAND_ECC_CORRECTION_UNCORRECTABLE_ERROR (2)
  95. #define NAND_BLOCK_GOOD (0)
  96. #define NAND_BLOCK_BAD (1)
  97. #define NAND_BLOCK_SPARE_AREA_READ_FAILED (2)
  98. #define NAND_BLK_GOOD_MARK (0xFF)
  99. #define NAND_BLK_BAD_MARK (0)
  100. #ifdef NAND_ECC_TYPE_1BIT
  101. #define NAND_ECC_DATA_SIZE (12u)
  102. #else
  103. #define NAND_ECC_DATA_SIZE (40u)
  104. #endif
  105. #define NAND_ECC_BYTES_FOR_BYTES_PER_TRNFS (NAND_ECC_DATA_SIZE/ \
  106. NAND_NUM_OF_TRNFS)
  107. /***************************************************************************/
  108. /*
  109. ** Function Prototypes
  110. */
  111. extern unsigned int NANDIdRead();
  112. extern unsigned int NANDStatusGet();
  113. extern unsigned int NANDResetDevice();
  114. extern unsigned int NANDWaitUntilReady();
  115. extern unsigned int NANDPageWriteCmdEnd();
  116. extern void NANDDelay(volatile unsigned int delay);
  117. extern void NANDECCRead(unsigned char *ptrEccData,unsigned int eccType,
  118. unsigned int csNum);
  119. extern unsigned int NANDECCCheck(unsigned char *ptrEccData,
  120. unsigned int eccType, unsigned int csNum);
  121. extern unsigned int NANDBlockErase (unsigned int blkNum);
  122. extern void NANDECCSelectAndStart(unsigned int csNum,unsigned int eccType);
  123. extern unsigned int NANDBadBlockCheck(unsigned int blkNum);
  124. extern unsigned int NANDMarkBlockAsBad(unsigned int blkNum);
  125. extern unsigned int NANDECCCorrect(unsigned char * ptrData,unsigned eccType,
  126. unsigned int eccDiffVal);
  127. extern void NANDPageWriteCmdStart(unsigned int blkNum, unsigned int pageNum,
  128. unsigned int columnAddr);
  129. extern unsigned int NANDPageReadCmdSend(unsigned int blkNum,
  130. unsigned int pageNum,
  131. unsigned int columnAddr);
  132. extern unsigned int NANDSpareAreaWrite(unsigned int blkNum,
  133. unsigned int pageNum,
  134. unsigned int columnAddr,
  135. unsigned int numOfBytes,unsigned char *data);
  136. extern unsigned int NANDSpareAreaRead(unsigned int blkNum, unsigned int pageNum,
  137. unsigned int columnAddr,
  138. unsigned int numOfBytes,unsigned char *data);
  139. #ifdef __cplusplus
  140. }
  141. #endif
  142. #endif