mxc_nand.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * (c) 2009 Magnus Lilja <lilja.magnus@gmail.com>
  4. */
  5. #ifndef __MXC_NAND_H
  6. #define __MXC_NAND_H
  7. /*
  8. * Register map and bit definitions for the Freescale NAND Flash Controller
  9. * present in various i.MX devices.
  10. *
  11. * MX31 and MX27 have version 1, which has:
  12. * 4 512-byte main buffers and
  13. * 4 16-byte spare buffers
  14. * to support up to 2K byte pagesize nand.
  15. * Reading or writing a 2K page requires 4 FDI/FDO cycles.
  16. *
  17. * MX25 and MX35 have version 2.1, and MX51 and MX53 have version 3.2, which
  18. * have:
  19. * 8 512-byte main buffers and
  20. * 8 64-byte spare buffers
  21. * to support up to 4K byte pagesize nand.
  22. * Reading or writing a 2K or 4K page requires only 1 FDI/FDO cycle.
  23. * Also some of registers are moved and/or changed meaning as seen below.
  24. */
  25. #if defined(CONFIG_MX27) || defined(CONFIG_MX31)
  26. #define MXC_NFC_V1
  27. #define is_mxc_nfc_1() 1
  28. #define is_mxc_nfc_21() 0
  29. #define is_mxc_nfc_32() 0
  30. #elif defined(CONFIG_MX25) || defined(CONFIG_MX35)
  31. #define MXC_NFC_V2_1
  32. #define is_mxc_nfc_1() 0
  33. #define is_mxc_nfc_21() 1
  34. #define is_mxc_nfc_32() 0
  35. #elif defined(CONFIG_MX51) || defined(CONFIG_MX53)
  36. #define MXC_NFC_V3
  37. #define MXC_NFC_V3_2
  38. #define is_mxc_nfc_1() 0
  39. #define is_mxc_nfc_21() 0
  40. #define is_mxc_nfc_32() 1
  41. #else
  42. #error "MXC NFC implementation not supported"
  43. #endif
  44. #define is_mxc_nfc_3() is_mxc_nfc_32()
  45. #if defined(MXC_NFC_V1)
  46. #define NAND_MXC_NR_BUFS 4
  47. #define NAND_MXC_SPARE_BUF_SIZE 16
  48. #define NAND_MXC_REG_OFFSET 0xe00
  49. #define NAND_MXC_2K_MULTI_CYCLE
  50. #elif defined(MXC_NFC_V2_1) || defined(MXC_NFC_V3_2)
  51. #define NAND_MXC_NR_BUFS 8
  52. #define NAND_MXC_SPARE_BUF_SIZE 64
  53. #define NAND_MXC_REG_OFFSET 0x1e00
  54. #endif
  55. struct mxc_nand_regs {
  56. u8 main_area[NAND_MXC_NR_BUFS][0x200];
  57. u8 spare_area[NAND_MXC_NR_BUFS][NAND_MXC_SPARE_BUF_SIZE];
  58. /*
  59. * reserved size is offset of nfc registers
  60. * minus total main and spare sizes
  61. */
  62. u8 reserved1[NAND_MXC_REG_OFFSET
  63. - NAND_MXC_NR_BUFS * (512 + NAND_MXC_SPARE_BUF_SIZE)];
  64. #if defined(MXC_NFC_V1)
  65. u16 buf_size;
  66. u16 reserved2;
  67. u16 buf_addr;
  68. u16 flash_addr;
  69. u16 flash_cmd;
  70. u16 config;
  71. u16 ecc_status_result;
  72. u16 rsltmain_area;
  73. u16 rsltspare_area;
  74. u16 wrprot;
  75. u16 unlockstart_blkaddr;
  76. u16 unlockend_blkaddr;
  77. u16 nf_wrprst;
  78. u16 config1;
  79. u16 config2;
  80. #elif defined(MXC_NFC_V2_1)
  81. u16 reserved2[2];
  82. u16 buf_addr;
  83. u16 flash_addr;
  84. u16 flash_cmd;
  85. u16 config;
  86. u32 ecc_status_result;
  87. u16 spare_area_size;
  88. u16 wrprot;
  89. u16 reserved3[2];
  90. u16 nf_wrprst;
  91. u16 config1;
  92. u16 config2;
  93. u16 reserved4;
  94. u16 unlockstart_blkaddr;
  95. u16 unlockend_blkaddr;
  96. u16 unlockstart_blkaddr1;
  97. u16 unlockend_blkaddr1;
  98. u16 unlockstart_blkaddr2;
  99. u16 unlockend_blkaddr2;
  100. u16 unlockstart_blkaddr3;
  101. u16 unlockend_blkaddr3;
  102. #elif defined(MXC_NFC_V3_2)
  103. u32 flash_cmd;
  104. u32 flash_addr[12];
  105. u32 config1;
  106. u32 ecc_status_result;
  107. u32 status_sum;
  108. u32 launch;
  109. #endif
  110. };
  111. #ifdef MXC_NFC_V3_2
  112. struct mxc_nand_ip_regs {
  113. u32 wrprot;
  114. u32 wrprot_unlock_blkaddr[8];
  115. u32 config2;
  116. u32 config3;
  117. u32 ipc;
  118. u32 err_addr;
  119. u32 delay_line;
  120. };
  121. #endif
  122. /* Set FCMD to 1, rest to 0 for Command operation */
  123. #define NFC_CMD 0x1
  124. /* Set FADD to 1, rest to 0 for Address operation */
  125. #define NFC_ADDR 0x2
  126. /* Set FDI to 1, rest to 0 for Input operation */
  127. #define NFC_INPUT 0x4
  128. /* Set FDO to 001, rest to 0 for Data Output operation */
  129. #define NFC_OUTPUT 0x8
  130. /* Set FDO to 010, rest to 0 for Read ID operation */
  131. #define NFC_ID 0x10
  132. /* Set FDO to 100, rest to 0 for Read Status operation */
  133. #define NFC_STATUS 0x20
  134. #if defined(MXC_NFC_V1) || defined(MXC_NFC_V2_1)
  135. #define NFC_CONFIG1_SP_EN (1 << 2)
  136. #define NFC_CONFIG1_RST (1 << 6)
  137. #define NFC_CONFIG1_CE (1 << 7)
  138. #elif defined(MXC_NFC_V3_2)
  139. #define NFC_CONFIG1_SP_EN (1 << 0)
  140. #define NFC_CONFIG1_CE (1 << 1)
  141. #define NFC_CONFIG1_RST (1 << 2)
  142. #endif
  143. #define NFC_V1_V2_CONFIG1_ECC_EN (1 << 3)
  144. #define NFC_V1_V2_CONFIG1_INT_MSK (1 << 4)
  145. #define NFC_V1_V2_CONFIG1_BIG (1 << 5)
  146. #define NFC_V2_CONFIG1_ECC_MODE_4 (1 << 0)
  147. #define NFC_V2_CONFIG1_ONE_CYCLE (1 << 8)
  148. #define NFC_V2_CONFIG1_FP_INT (1 << 11)
  149. #define NFC_V3_CONFIG1_RBA_MASK (0x7 << 4)
  150. #define NFC_V3_CONFIG1_RBA(x) (((x) & 0x7) << 4)
  151. #define NFC_V1_V2_CONFIG2_INT (1 << 15)
  152. #define NFC_V3_CONFIG2_PS_MASK (0x3 << 0)
  153. #define NFC_V3_CONFIG2_PS_512 (0 << 0)
  154. #define NFC_V3_CONFIG2_PS_2048 (1 << 0)
  155. #define NFC_V3_CONFIG2_PS_4096 (2 << 0)
  156. #define NFC_V3_CONFIG2_ONE_CYCLE (1 << 2)
  157. #define NFC_V3_CONFIG2_ECC_EN (1 << 3)
  158. #define NFC_V3_CONFIG2_2CMD_PHASES (1 << 4)
  159. #define NFC_V3_CONFIG2_NUM_ADDR_PH0 (1 << 5)
  160. #define NFC_V3_CONFIG2_ECC_MODE_8 (1 << 6)
  161. #define NFC_V3_CONFIG2_PPB_MASK (0x3 << 7)
  162. #define NFC_V3_CONFIG2_PPB(x) (((x) & 0x3) << 7)
  163. #define NFC_V3_CONFIG2_EDC_MASK (0x7 << 9)
  164. #define NFC_V3_CONFIG2_EDC(x) (((x) & 0x7) << 9)
  165. #define NFC_V3_CONFIG2_NUM_ADDR_PH1(x) (((x) & 0x3) << 12)
  166. #define NFC_V3_CONFIG2_INT_MSK (1 << 15)
  167. #define NFC_V3_CONFIG2_SPAS_MASK (0xff << 16)
  168. #define NFC_V3_CONFIG2_SPAS(x) (((x) & 0xff) << 16)
  169. #define NFC_V3_CONFIG2_ST_CMD_MASK (0xff << 24)
  170. #define NFC_V3_CONFIG2_ST_CMD(x) (((x) & 0xff) << 24)
  171. #define NFC_V3_CONFIG3_ADD_OP(x) (((x) & 0x3) << 0)
  172. #define NFC_V3_CONFIG3_FW8 (1 << 3)
  173. #define NFC_V3_CONFIG3_SBB(x) (((x) & 0x7) << 8)
  174. #define NFC_V3_CONFIG3_NUM_OF_DEVS(x) (((x) & 0x7) << 12)
  175. #define NFC_V3_CONFIG3_RBB_MODE (1 << 15)
  176. #define NFC_V3_CONFIG3_NO_SDMA (1 << 20)
  177. #define NFC_V3_WRPROT_UNLOCK (1 << 2)
  178. #define NFC_V3_WRPROT_BLS_UNLOCK (2 << 6)
  179. #define NFC_V3_IPC_CREQ (1 << 0)
  180. #define NFC_V3_IPC_INT (1 << 31)
  181. #if defined(MXC_NFC_V1) || defined(MXC_NFC_V2_1)
  182. #define operation config2
  183. #define readnfc readw
  184. #define writenfc writew
  185. #elif defined(MXC_NFC_V3_2)
  186. #define operation launch
  187. #define readnfc readl
  188. #define writenfc writel
  189. #endif
  190. #endif /* __MXC_NAND_H */