mtk_nand.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603
  1. #ifndef __MTK_NAND_H
  2. #define __MTK_NAND_H
  3. #include <partition_define.h>
  4. #include <linux/mtd/partitions.h>
  5. /*******************************************************************************
  6. * NFI Register Definition
  7. *******************************************************************************/
  8. #ifdef CONFIG_OF
  9. #define NFI_BASE mtk_nfi_base
  10. #define NFIECC_BASE mtk_nfiecc_base
  11. #endif
  12. #define NFI_CNFG_REG16 ((volatile unsigned short *)(NFI_BASE+0x0000))
  13. #define NFI_PAGEFMT_REG32 ((volatile unsigned int *)(NFI_BASE+0x0004))
  14. #define NFI_CON_REG16 ((volatile unsigned int *)(NFI_BASE+0x0008))
  15. #define NFI_ACCCON_REG32 ((volatile unsigned int *)(NFI_BASE+0x000C))
  16. #define NFI_INTR_EN_REG16 ((volatile unsigned short *)(NFI_BASE+0x0010))
  17. #define NFI_INTR_REG16 ((volatile unsigned short *)(NFI_BASE+0x0014))
  18. #define NFI_CMD_REG16 ((volatile unsigned short *)(NFI_BASE+0x0020))
  19. #define NFI_ADDRNOB_REG16 ((volatile unsigned short *)(NFI_BASE+0x0030))
  20. #define NFI_COLADDR_REG32 ((volatile unsigned int *)(NFI_BASE+0x0034))
  21. #define NFI_ROWADDR_REG32 ((volatile unsigned int *)(NFI_BASE+0x0038))
  22. #define NFI_STRDATA_REG16 ((volatile unsigned short *)(NFI_BASE+0x0040))
  23. #define NFI_CNRNB_REG16 ((volatile unsigned short *)(NFI_BASE+0x0044))
  24. #define NFI_DATAW_REG32 ((volatile unsigned int *)(NFI_BASE+0x0050))
  25. #define NFI_DATAR_REG32 ((volatile unsigned int *)(NFI_BASE+0x0054))
  26. #define NFI_PIO_DIRDY_REG16 ((volatile unsigned short *)(NFI_BASE+0x0058))
  27. #define NFI_STA_REG32 ((volatile unsigned int *)(NFI_BASE+0x0060))
  28. #define NFI_FIFOSTA_REG16 ((volatile unsigned short *)(NFI_BASE+0x0064))
  29. /* #define NFI_LOCKSTA_REG16 ((volatile unsigned short *)(NFI_BASE+0x0068)) */
  30. #define NFI_ADDRCNTR_REG16 ((volatile unsigned int *)(NFI_BASE+0x0070))
  31. #define NFI_STRADDR_REG32 ((volatile unsigned int *)(NFI_BASE+0x0080))
  32. #define NFI_BYTELEN_REG16 ((volatile unsigned int *)(NFI_BASE+0x0084))
  33. #define NFI_CSEL_REG16 ((volatile unsigned short *)(NFI_BASE+0x0090))
  34. #define NFI_IOCON_REG16 ((volatile unsigned short *)(NFI_BASE+0x0094))
  35. #define NFI_FDM0L_REG32 ((volatile unsigned int *)(NFI_BASE+0x00A0))
  36. #define NFI_FDM0M_REG32 ((volatile unsigned int *)(NFI_BASE+0x00A4))
  37. #define NFI_LOCK_REG16 ((volatile unsigned short *)(NFI_BASE+0x0100))
  38. #define NFI_LOCKCON_REG32 ((volatile unsigned int *)(NFI_BASE+0x0104))
  39. #define NFI_LOCKANOB_REG16 ((volatile unsigned short *)(NFI_BASE+0x0108))
  40. #define NFI_LOCK00ADD_REG32 ((volatile unsigned int *)(NFI_BASE+0x0110))
  41. #define NFI_LOCK00FMT_REG32 ((volatile unsigned int *)(NFI_BASE+0x0114))
  42. #define NFI_LOCK01ADD_REG32 ((volatile unsigned int *)(NFI_BASE+0x0118))
  43. #define NFI_LOCK01FMT_REG32 ((volatile unsigned int *)(NFI_BASE+0x011C))
  44. #define NFI_LOCK02ADD_REG32 ((volatile unsigned int *)(NFI_BASE+0x0120))
  45. #define NFI_LOCK02FMT_REG32 ((volatile unsigned int *)(NFI_BASE+0x0124))
  46. #define NFI_LOCK03ADD_REG32 ((volatile unsigned int *)(NFI_BASE+0x0128))
  47. #define NFI_LOCK03FMT_REG32 ((volatile unsigned int *)(NFI_BASE+0x012C))
  48. #define NFI_LOCK04ADD_REG32 ((volatile unsigned int *)(NFI_BASE+0x0130))
  49. #define NFI_LOCK04FMT_REG32 ((volatile unsigned int *)(NFI_BASE+0x0134))
  50. #define NFI_LOCK05ADD_REG32 ((volatile unsigned int *)(NFI_BASE+0x0138))
  51. #define NFI_LOCK05FMT_REG32 ((volatile unsigned int *)(NFI_BASE+0x013C))
  52. #define NFI_LOCK06ADD_REG32 ((volatile unsigned int *)(NFI_BASE+0x0140))
  53. #define NFI_LOCK06FMT_REG32 ((volatile unsigned int *)(NFI_BASE+0x0144))
  54. #define NFI_LOCK07ADD_REG32 ((volatile unsigned int *)(NFI_BASE+0x0148))
  55. #define NFI_LOCK07FMT_REG32 ((volatile unsigned int *)(NFI_BASE+0x014C))
  56. #define NFI_LOCK08ADD_REG32 ((volatile unsigned int *)(NFI_BASE+0x0150))
  57. #define NFI_LOCK08FMT_REG32 ((volatile unsigned int *)(NFI_BASE+0x0154))
  58. #define NFI_LOCK09ADD_REG32 ((volatile unsigned int *)(NFI_BASE+0x0158))
  59. #define NFI_LOCK09FMT_REG32 ((volatile unsigned int *)(NFI_BASE+0x015C))
  60. #define NFI_LOCK10ADD_REG32 ((volatile unsigned int *)(NFI_BASE+0x0160))
  61. #define NFI_LOCK10FMT_REG32 ((volatile unsigned int *)(NFI_BASE+0x0164))
  62. #define NFI_LOCK11ADD_REG32 ((volatile unsigned int *)(NFI_BASE+0x0168))
  63. #define NFI_LOCK11FMT_REG32 ((volatile unsigned int *)(NFI_BASE+0x016C))
  64. #define NFI_LOCK12ADD_REG32 ((volatile unsigned int *)(NFI_BASE+0x0170))
  65. #define NFI_LOCK12FMT_REG32 ((volatile unsigned int *)(NFI_BASE+0x0174))
  66. #define NFI_LOCK13ADD_REG32 ((volatile unsigned int *)(NFI_BASE+0x0178))
  67. #define NFI_LOCK13FMT_REG32 ((volatile unsigned int *)(NFI_BASE+0x017C))
  68. #define NFI_LOCK14ADD_REG32 ((volatile unsigned int *)(NFI_BASE+0x0180))
  69. #define NFI_LOCK14FMT_REG32 ((volatile unsigned int *)(NFI_BASE+0x0184))
  70. #define NFI_LOCK15ADD_REG32 ((volatile unsigned int *)(NFI_BASE+0x0188))
  71. #define NFI_LOCK15FMT_REG32 ((volatile unsigned int *)(NFI_BASE+0x018C))
  72. #define NFI_FIFODATA0_REG32 ((volatile unsigned int *)(NFI_BASE+0x0190))
  73. #define NFI_FIFODATA1_REG32 ((volatile unsigned int *)(NFI_BASE+0x0194))
  74. #define NFI_FIFODATA2_REG32 ((volatile unsigned int *)(NFI_BASE+0x0198))
  75. #define NFI_FIFODATA3_REG32 ((volatile unsigned int *)(NFI_BASE+0x019C))
  76. #define NFI_DEBUG_CON1_REG16 ((volatile unsigned short *)(NFI_BASE+0x0220))
  77. #define NFI_MASTERSTA_REG16 ((volatile unsigned short *)(NFI_BASE+0x0224))
  78. #define NFI_MASTERRST_REG32 ((volatile unsigned short *)(NFI_BASE+0x0228))
  79. #define NFI_RANDOM_CNFG_REG32 ((volatile unsigned int *)(NFI_BASE+0x0238))
  80. #define NFI_ENMPTY_THRESH_REG32 ((volatile unsigned int *)(NFI_BASE+0x023C))
  81. #define NFI_NAND_TYPE_CNFG_REG32 ((volatile unsigned int *)(NFI_BASE+0x0240))
  82. #define NFI_ACCCON1_REG3 ((volatile unsigned int *)(NFI_BASE+0x0244))
  83. #define NFI_DLYCTRL_REG32 ((volatile unsigned int *)(NFI_BASE+0x0248))
  84. #define NFI_RANDOM_ENSEED01_TS_REG32 ((volatile unsigned int *)(NFI_BASE+0x024C))
  85. #define NFI_RANDOM_ENSEED02_TS_REG32 ((volatile unsigned int *)(NFI_BASE+0x0250))
  86. #define NFI_RANDOM_ENSEED03_TS_REG32 ((volatile unsigned int *)(NFI_BASE+0x0254))
  87. #define NFI_RANDOM_ENSEED04_TS_REG32 ((volatile unsigned int *)(NFI_BASE+0x0258))
  88. #define NFI_RANDOM_ENSEED05_TS_REG32 ((volatile unsigned int *)(NFI_BASE+0x025C))
  89. #define NFI_RANDOM_ENSEED06_TS_REG32 ((volatile unsigned int *)(NFI_BASE+0x0260))
  90. #define NFI_RANDOM_DESEED01_TS_REG32 ((volatile unsigned int *)(NFI_BASE+0x0264))
  91. #define NFI_RANDOM_DESEED02_TS_REG32 ((volatile unsigned int *)(NFI_BASE+0x0268))
  92. #define NFI_RANDOM_DESEED03_TS_REG32 ((volatile unsigned int *)(NFI_BASE+0x026C))
  93. #define NFI_RANDOM_DESEED04_TS_REG32 ((volatile unsigned int *)(NFI_BASE+0x0270))
  94. #define NFI_RANDOM_DESEED05_TS_REG32 ((volatile unsigned int *)(NFI_BASE+0x0274))
  95. #define NFI_RANDOM_DESEED06_TS_REG32 ((volatile unsigned int *)(NFI_BASE+0x0278))
  96. #define NFI_TLC_RD_WHR2_REG32 ((volatile unsigned int *)(NFI_BASE+0x0300))
  97. #define NFI_FLUSH_REG32 ((volatile unsigned int *)(NFI_BASE+0x0490))
  98. /*******************************************************************************
  99. * NFI Register Field Definition
  100. *******************************************************************************/
  101. /* NFI_DEBUG_CON1 */
  102. #define DEBUG_CON1_BYPASS_MASTER_EN (0x8000)
  103. /* NFI_MASTERSTA */
  104. #define MASTERSTA_MASK (0x0FFF)
  105. /* NFI_CNFG */
  106. #define CNFG_AHB (0x0001)
  107. #define CNFG_READ_EN (0x0002)
  108. #define CNFG_DMA_BURST_EN (0x0004)
  109. #define CNFG_BYTE_RW (0x0040)
  110. #define CNFG_HW_ECC_EN (0x0100)
  111. #define CNFG_AUTO_FMT_EN (0x0200)
  112. #define CNFG_OP_IDLE (0x0000)
  113. #define CNFG_OP_READ (0x1000)
  114. #define CNFG_OP_SRD (0x2000)
  115. #define CNFG_OP_PRGM (0x3000)
  116. #define CNFG_OP_ERASE (0x4000)
  117. #define CNFG_OP_RESET (0x5000)
  118. #define CNFG_OP_CUST (0x6000)
  119. #define CNFG_OP_MODE_MASK (0x7000)
  120. #define CNFG_OP_MODE_SHIFT (12)
  121. /* NFI_PAGEFMT */
  122. #define PAGEFMT_512 (0x0000)
  123. #define PAGEFMT_2K (0x0001)
  124. #define PAGEFMT_4K (0x0002)
  125. #define PAGEFMT_2K_1KS (0x0000)
  126. #define PAGEFMT_4K_1KS (0x0001)
  127. #define PAGEFMT_8K_1KS (0x0002)
  128. #define PAGEFMT_16K_1KS (0x0003)
  129. #define PAGEFMT_PAGE_MASK (0x0003)
  130. #define PAGEFMT_SEC_SEL_512 (0x0004)
  131. #define PAGEFMT_SECTOR_SEL (0x0004)
  132. #define PAGEFMT_DBYTE_EN (0x0008)
  133. #define PAGEFMT_SPARE_16 (0x0000)
  134. #define PAGEFMT_SPARE_26 (0x0001)
  135. #define PAGEFMT_SPARE_27 (0x0002)
  136. #define PAGEFMT_SPARE_28 (0x0003)
  137. #define PAGEFMT_SPARE_32 (0x0004)
  138. #define PAGEFMT_SPARE_36 (0x0005)
  139. #define PAGEFMT_SPARE_40 (0x0006)
  140. #define PAGEFMT_SPARE_44 (0x0007)
  141. #define PAGEFMT_SPARE_48 (0x0008)
  142. #define PAGEFMT_SPARE_49 (0x0009)
  143. #define PAGEFMT_SPARE_50 (0x000A)
  144. #define PAGEFMT_SPARE_51 (0x000B)
  145. #define PAGEFMT_SPARE_52 (0x000C)
  146. #define PAGEFMT_SPARE_62 (0x000D)
  147. #define PAGEFMT_SPARE_61 (0x000E)
  148. #define PAGEFMT_SPARE_63 (0x000F)
  149. #define PAGEFMT_SPARE_64 (0x0010)
  150. #define PAGEFMT_SPARE_67 (0x0011)
  151. #define PAGEFMT_SPARE_74 (0x0012)
  152. #define PAGEFMT_SPARE_32_1KS (0x0000)
  153. #define PAGEFMT_SPARE_52_1KS (0x0001)
  154. #define PAGEFMT_SPARE_54_1KS (0x0002)
  155. #define PAGEFMT_SPARE_56_1KS (0x0003)
  156. #define PAGEFMT_SPARE_64_1KS (0x0004)
  157. #define PAGEFMT_SPARE_72_1KS (0x0005)
  158. #define PAGEFMT_SPARE_80_1KS (0x0006)
  159. #define PAGEFMT_SPARE_88_1KS (0x0007)
  160. #define PAGEFMT_SPARE_96_1KS (0x0008)
  161. #define PAGEFMT_SPARE_98_1KS (0x0009)
  162. #define PAGEFMT_SPARE_100_1KS (0x000A)
  163. #define PAGEFMT_SPARE_102_1KS (0x000B)
  164. #define PAGEFMT_SPARE_104_1KS (0x000C)
  165. #define PAGEFMT_SPARE_124_1KS (0x000D)
  166. #define PAGEFMT_SPARE_122_1KS (0x000E)
  167. #define PAGEFMT_SPARE_126_1KS (0x000F)
  168. #define PAGEFMT_SPARE_128_1KS (0x0010)
  169. #define PAGEFMT_SPARE_134_1KS (0x0011)
  170. #define PAGEFMT_SPARE_148_1KS (0x0012)
  171. #define PAGEFMT_SPARE_MASK (0x1F0000) /* 5bit */
  172. #define PAGEFMT_SPARE_SHIFT (16)
  173. #define PAGEFMT_FDM_MASK (0x0F00)
  174. #define PAGEFMT_FDM_SHIFT (8)
  175. #define PAGEFMT_FDM_ECC_MASK (0xF000)
  176. #define PAGEFMT_FDM_ECC_SHIFT (12)
  177. /* NFI_CON */
  178. #define CON_FIFO_FLUSH (0x0001)
  179. #define CON_NFI_RST (0x0002)
  180. #define CON_NFI_SRD (0x0010)
  181. #define CON_NFI_NOB_MASK (0x00E0)
  182. #define CON_NFI_NOB_SHIFT (5)
  183. #define CON_NFI_BRD (0x0100)
  184. #define CON_NFI_BWR (0x0200)
  185. #define CON_NFI_SEC_MASK (0x1F000)
  186. #define CON_NFI_SEC_SHIFT (12)
  187. /*NFI_RANDOM_CFG*/
  188. #define SEED_MASK (0x7FFF)
  189. #define EN_SEED_SHIFT (0x1)
  190. #define DE_SEED_SHIFT (0x11)
  191. #define CNFG_RAN_SEC (0x0010)
  192. #define CNFG_RAN_SEL (0x0020)
  193. #define RAN_CNFG_ENCODE_EN (1 << 0)
  194. #define RAN_CNFG_DECODE_EN (1 << 16)
  195. #define RAN_CNFG_ENCODE_SEED(x) (((unsigned int)(x) & SEED_MASK) << 1)
  196. #define RAN_CNFG_DECODE_SEED(x) (((unsigned int)(x) & SEED_MASK) << 17)
  197. /* NFI_ACCCON */
  198. #define ACCCON_SETTING ()
  199. /* NFI_INTR_EN */
  200. #define INTR_RD_DONE_EN (0x0001)
  201. #define INTR_WR_DONE_EN (0x0002)
  202. #define INTR_RST_DONE_EN (0x0004)
  203. #define INTR_ERASE_DONE_EN (0x0008)
  204. #define INTR_BSY_RTN_EN (0x0010)
  205. #define INTR_ACC_LOCK_EN (0x0020)
  206. #define INTR_AHB_DONE_EN (0x0040)
  207. #define INTR_ALL_INTR_DE (0x0000)
  208. #define INTR_ALL_INTR_EN (0x007F)
  209. #define INTR_CUSTOM_PROG_DONE_INTR_EN (0x00000080)
  210. #define INTR_AUTO_PROG_DONE_INTR_EN (0x00000200)
  211. #define INTR_AUTO_BLKER_INTR_EN (0x00000800)
  212. /* NFI_INTR */
  213. #define INTR_RD_DONE (0x0001)
  214. #define INTR_WR_DONE (0x0002)
  215. #define INTR_RST_DONE (0x0004)
  216. #define INTR_ERASE_DONE (0x0008)
  217. #define INTR_BSY_RTN (0x0010)
  218. #define INTR_ACC_LOCK (0x0020)
  219. #define INTR_AHB_DONE (0x0040)
  220. /* NFI_ADDRNOB */
  221. #define ADDR_COL_NOB_MASK (0x0007)
  222. #define ADDR_COL_NOB_SHIFT (0)
  223. #define ADDR_ROW_NOB_MASK (0x0070)
  224. #define ADDR_ROW_NOB_SHIFT (4)
  225. /* NFI_STA */
  226. #define STA_READ_EMPTY (0x00001000)
  227. #define STA_ACC_LOCK (0x00000010)
  228. #define STA_CMD_STATE (0x00000001)
  229. #define STA_ADDR_STATE (0x00000002)
  230. #define STA_DATAR_STATE (0x00000004)
  231. #define STA_DATAW_STATE (0x00000008)
  232. #define STA_FLASH_MACRO_IDLE (0x00000020)
  233. #define STA_NAND_FSM_MASK (0x3F800000)
  234. #define STA_NAND_BUSY (0x00000100)
  235. #define STA_NAND_BUSY_RETURN (0x00000200)
  236. #define STA_NFI_FSM_MASK (0x000F0000)
  237. #define STA_NFI_OP_MASK (0x0000000F)
  238. /* NFI_FIFOSTA */
  239. #define FIFO_RD_EMPTY (0x0040)
  240. #define FIFO_RD_FULL (0x0080)
  241. #define FIFO_WR_FULL (0x8000)
  242. #define FIFO_WR_EMPTY (0x4000)
  243. #define FIFO_RD_REMAIN(x) (0x1F&(x))
  244. #define FIFO_WR_REMAIN(x) ((0x1F00&(x))>>8)
  245. /* NFI_ADDRCNTR */
  246. #define ADDRCNTR_CNTR(x) ((0x1F000&(x))>>12)
  247. #define ADDRCNTR_OFFSET(x) (0x0FFF&(x))
  248. /* NFI_LOCK */
  249. #define NFI_LOCK_ON (0x0001)
  250. /* NFI_LOCKANOB */
  251. #define PROG_RADD_NOB_MASK (0x7000)
  252. #define PROG_RADD_NOB_SHIFT (12)
  253. #define PROG_CADD_NOB_MASK (0x0300)
  254. #define PROG_CADD_NOB_SHIFT (8)
  255. #define ERASE_RADD_NOB_MASK (0x0070)
  256. #define ERASE_RADD_NOB_SHIFT (4)
  257. #define ERASE_CADD_NOB_MASK (0x0007)
  258. #define ERASE_CADD_NOB_SHIFT (0)
  259. /* NFI_DEBUG_CON1 */
  260. #define HWDCM_SWCON_ON (1<<1)
  261. #define WBUF_EN (1<<2)
  262. #define NFI_BYPASS 0x8000
  263. #define ECC_BYPASS 0x1
  264. #define PAD_MACRO_RST 2
  265. /*******************************************************************************
  266. * ECC Register Definition
  267. *******************************************************************************/
  268. #define ECC_ENCCON_REG16 ((volatile unsigned short *)(NFIECC_BASE+0x0000))
  269. #define ECC_ENCCNFG_REG32 ((volatile unsigned int *)(NFIECC_BASE+0x0004))
  270. #define ECC_ENCDIADDR_REG32 ((volatile unsigned int *)(NFIECC_BASE+0x0008))
  271. #define ECC_ENCIDLE_REG32 ((volatile unsigned int *)(NFIECC_BASE+0x000C))
  272. #define ECC_ENCPAR0_REG32 ((volatile unsigned int *)(NFIECC_BASE+0x0010))
  273. #define ECC_ENCPAR1_REG32 ((volatile unsigned int *)(NFIECC_BASE+0x0014))
  274. #define ECC_ENCPAR2_REG32 ((volatile unsigned int *)(NFIECC_BASE+0x0018))
  275. #define ECC_ENCPAR3_REG32 ((volatile unsigned int *)(NFIECC_BASE+0x001C))
  276. #define ECC_ENCPAR4_REG32 ((volatile unsigned int *)(NFIECC_BASE+0x0020))
  277. #define ECC_ENCPAR5_REG32 ((volatile unsigned int *)(NFIECC_BASE+0x0024))
  278. #define ECC_ENCPAR6_REG32 ((volatile unsigned int *)(NFIECC_BASE+0x0028))
  279. #define ECC_ENCSTA_REG32 ((volatile unsigned int *)(NFIECC_BASE+0x007C))
  280. #define ECC_ENCIRQEN_REG16 ((volatile unsigned short *)(NFIECC_BASE+0x0080))
  281. #define ECC_ENCIRQSTA_REG16 ((volatile unsigned short *)(NFIECC_BASE+0x0084))
  282. #define ECC_DECCON_REG16 ((volatile unsigned short *)(NFIECC_BASE+0x0100))
  283. #define ECC_DECCNFG_REG32 ((volatile unsigned int *)(NFIECC_BASE+0x0104))
  284. #define ECC_DECDIADDR_REG32 ((volatile unsigned int *)(NFIECC_BASE+0x0108))
  285. #define ECC_DECIDLE_REG16 ((volatile unsigned short *)(NFIECC_BASE+0x010C))
  286. #define ECC_DECFER_REG16 ((volatile unsigned short *)(NFIECC_BASE+0x0110))
  287. #define ECC_DECENUM0_REG32 ((volatile unsigned int *)(NFIECC_BASE+0x0114))
  288. #define ECC_DECENUM1_REG32 ((volatile unsigned int *)(NFIECC_BASE+0x0118))
  289. #define ECC_DECDONE_REG16 ((volatile unsigned short *)(NFIECC_BASE+0x0124))
  290. #define ECC_DECEL0_REG32 ((volatile unsigned int *)(NFIECC_BASE+0x0128))
  291. #define ECC_DECEL1_REG32 ((volatile unsigned int *)(NFIECC_BASE+0x012C))
  292. #define ECC_DECEL2_REG32 ((volatile unsigned int *)(NFIECC_BASE+0x0130))
  293. #define ECC_DECEL3_REG32 ((volatile unsigned int *)(NFIECC_BASE+0x0134))
  294. #define ECC_DECEL4_REG32 ((volatile unsigned int *)(NFIECC_BASE+0x0138))
  295. #define ECC_DECEL5_REG32 ((volatile unsigned int *)(NFIECC_BASE+0x013C))
  296. #define ECC_DECEL6_REG32 ((volatile unsigned int *)(NFIECC_BASE+0x0140))
  297. #define ECC_DECEL7_REG32 ((volatile unsigned int *)(NFIECC_BASE+0x0144))
  298. #define ECC_DECIRQEN_REG16 ((volatile unsigned short *)(NFIECC_BASE+0x0200))
  299. #define ECC_DECIRQSTA_REG16 ((volatile unsigned short *)(NFIECC_BASE+0x0204))
  300. /* #define ECC_FDMADDR_REG32 ((volatile unsigned int *)(NFIECC_BASE+0x0148)) */
  301. #define ECC_DECFSM_REG32 ((volatile unsigned int *)(NFIECC_BASE+0x0208))
  302. #define ECC_BYPASS_REG32 ((volatile unsigned int *)(NFIECC_BASE+0x020C))
  303. /* #define ECC_SYNSTA_REG32 ((volatile unsigned int *)(NFIECC_BASE+0x0150)) */
  304. /* #define ECC_DECNFIDI_REG32 ((volatile unsigned int *)(NFIECC_BASE+0x0154)) */
  305. /* #define ECC_SYN0_REG32 ((volatile unsigned int *)(NFIECC_BASE+0x0158)) */
  306. /*******************************************************************************
  307. * ECC register definition
  308. *******************************************************************************/
  309. /* ECC_ENCON */
  310. #define ECC_PARITY_BIT (14)
  311. #define ENC_EN (0x0001)
  312. #define ENC_DE (0x0000)
  313. /* ECC_ENCCNFG */
  314. #define ECC_CNFG_ECC4 (0x0000)
  315. #define ECC_CNFG_ECC6 (0x0001)
  316. #define ECC_CNFG_ECC8 (0x0002)
  317. #define ECC_CNFG_ECC10 (0x0003)
  318. #define ECC_CNFG_ECC12 (0x0004)
  319. #define ECC_CNFG_ECC14 (0x0005)
  320. #define ECC_CNFG_ECC16 (0x0006)
  321. #define ECC_CNFG_ECC18 (0x0007)
  322. #define ECC_CNFG_ECC20 (0x0008)
  323. #define ECC_CNFG_ECC22 (0x0009)
  324. #define ECC_CNFG_ECC24 (0x000A)
  325. #define ECC_CNFG_ECC28 (0x000B)
  326. #define ECC_CNFG_ECC32 (0x000C)
  327. #define ECC_CNFG_ECC36 (0x000D)
  328. #define ECC_CNFG_ECC40 (0x000E)
  329. #define ECC_CNFG_ECC44 (0x000F)
  330. #define ECC_CNFG_ECC48 (0x0010)
  331. #define ECC_CNFG_ECC52 (0x0011)
  332. #define ECC_CNFG_ECC56 (0x0012)
  333. #define ECC_CNFG_ECC60 (0x0013)
  334. #define ECC_CNFG_ECC68 (0x0014)
  335. #define ECC_CNFG_ECC72 (0x0015)
  336. #define ECC_CNFG_ECC80 (0x0016)
  337. #define ECC_CNFG_ECC_MASK (0x0000001F)
  338. #define ENC_CNFG_NFI (0x0020)
  339. #define ENC_CNFG_MODE_MASK (0x0060)
  340. #define ENC_CNFG_META6 (0x10300000)
  341. #define ENC_CNFG_META8 (0x10400000)
  342. #define ENC_CNFG_MSG_MASK (0x3FFF0000)
  343. #define ENC_CNFG_MSG_SHIFT (0x10)
  344. /* ECC_ENCIDLE */
  345. #define ENC_IDLE (0x0001)
  346. /* ECC_ENCSTA */
  347. #define STA_FSM (0x0007)
  348. #define STA_COUNT_PS (0xFF10)
  349. #define STA_COUNT_MS (0x3FFF0000)
  350. /* ECC_ENCIRQEN */
  351. #define ENC_IRQEN (0x0001)
  352. /* ECC_ENCIRQSTA */
  353. #define ENC_IRQSTA (0x0001)
  354. /* ECC_DECCON */
  355. #define DEC_EN (0x0001)
  356. #define DEC_DE (0x0000)
  357. /* ECC_ENCCNFG */
  358. #define DEC_CNFG_ECC4 (0x0000)
  359. /* #define DEC_CNFG_ECC6 (0x0001) */
  360. /* #define DEC_CNFG_ECC12 (0x0002) */
  361. #define DEC_CNFG_DEC_MODE_MASK (0x0060)
  362. #define DEC_CNFG_AHB (0x0000)
  363. #define DEC_CNFG_NFI (0x0020)
  364. /* #define DEC_CNFG_META6 (0x10300000) */
  365. /* #define DEC_CNFG_META8 (0x10400000) */
  366. #define DEC_CNFG_FER (0x01000)
  367. #define DEC_CNFG_EL (0x02000)
  368. #define DEC_CNFG_CORRECT (0x03000)
  369. #define DEC_CNFG_TYPE_MASK (0x03000)
  370. #define DEC_CNFG_EMPTY_EN (0x80000000)
  371. #define DEC_CNFG_DEC_BURST_EN (0x00000100)
  372. #define DEC_CNFG_CODE_MASK (0x3FFF0000)
  373. #define DEC_CNFG_CODE_SHIFT (0x10)
  374. /* ECC_DECIDLE */
  375. #define DEC_IDLE (0x0001)
  376. /* ECC_DECFER */
  377. #define DEC_FER0 (0x0001)
  378. #define DEC_FER1 (0x0002)
  379. #define DEC_FER2 (0x0004)
  380. #define DEC_FER3 (0x0008)
  381. #define DEC_FER4 (0x0010)
  382. #define DEC_FER5 (0x0020)
  383. #define DEC_FER6 (0x0040)
  384. #define DEC_FER7 (0x0080)
  385. /* ECC_DECENUM */
  386. #define ERR_NUM0 (0x0000007F)
  387. #define ERR_NUM1 (0x00007F00)
  388. #define ERR_NUM2 (0x007F0000)
  389. #define ERR_NUM3 (0x7F000000)
  390. #define ERR_NUM4 (0x0000007F)
  391. #define ERR_NUM5 (0x00007F00)
  392. #define ERR_NUM6 (0x007F0000)
  393. #define ERR_NUM7 (0x7F000000)
  394. /* ECC_DECDONE */
  395. #define DEC_DONE0 (0x0001)
  396. #define DEC_DONE1 (0x0002)
  397. #define DEC_DONE2 (0x0004)
  398. #define DEC_DONE3 (0x0008)
  399. #define DEC_DONE4 (0x0010)
  400. #define DEC_DONE5 (0x0020)
  401. #define DEC_DONE6 (0x0040)
  402. #define DEC_DONE7 (0x0080)
  403. /* ECC_DECIRQEN */
  404. #define DEC_IRQEN (0x0001)
  405. /* ECC_DECIRQSTA */
  406. #define DEC_IRQSTA (0x0001)
  407. #define CHIPVER_ECO_1 (0x8a00)
  408. #define CHIPVER_ECO_2 (0x8a01)
  409. /* #define NAND_PFM */
  410. /* ECC_DECFSM */
  411. #define ECC_DECFSM_IDLE (0x01011101)
  412. /*******************************************************************************
  413. * Data Structure Definition
  414. *******************************************************************************/
  415. struct nfi_saved_para {
  416. u8 suspend_flag;
  417. u16 sNFI_CNFG_REG16;
  418. u32 sNFI_PAGEFMT_REG32;
  419. u32 sNFI_CON_REG16;
  420. u32 sNFI_ACCCON_REG32;
  421. u16 sNFI_INTR_EN_REG16;
  422. u16 sNFI_IOCON_REG16;
  423. u16 sNFI_CSEL_REG16;
  424. u16 sNFI_DEBUG_CON1_REG16;
  425. u32 sECC_ENCCNFG_REG32;
  426. u32 sECC_FDMADDR_REG32;
  427. u32 sECC_DECCNFG_REG32;
  428. /* for sync mode */
  429. u32 sNFI_DLYCTRL_REG32;
  430. u32 sPERI_NFI_MAC_CTRL;
  431. u32 sNFI_NAND_TYPE_CNFG_REG32;
  432. u32 sNFI_ACCCON1_REG32;
  433. };
  434. struct mtk_nand_pl_test {
  435. suseconds_t last_erase_time;
  436. suseconds_t last_prog_time;
  437. u32 nand_program_wdt_enable;
  438. u32 nand_erase_wdt_enable;
  439. };
  440. #ifdef CONFIG_OF
  441. /* NAND driver */
  442. struct mtk_nand_host_hw {
  443. unsigned int nfi_bus_width; /* NFI_BUS_WIDTH */
  444. unsigned int nfi_access_timing; /* NFI_ACCESS_TIMING */
  445. unsigned int nfi_cs_num; /* NFI_CS_NUM */
  446. unsigned int nand_sec_size; /* NAND_SECTOR_SIZE */
  447. unsigned int nand_sec_shift; /* NAND_SECTOR_SHIFT */
  448. unsigned int nand_ecc_size;
  449. unsigned int nand_ecc_bytes;
  450. unsigned int nand_ecc_mode;
  451. };
  452. #endif
  453. struct mtk_nand_host {
  454. struct nand_chip nand_chip;
  455. struct mtd_info mtd;
  456. struct mtk_nand_host_hw *hw;
  457. #ifdef CONFIG_PM
  458. struct nfi_saved_para saved_para;
  459. #endif
  460. #ifdef CONFIG_PWR_LOSS_MTK_SPOH
  461. struct mtk_nand_pl_test pl;
  462. #endif
  463. struct mtd_erase_region_info erase_region[20];
  464. };
  465. struct NAND_CMD {
  466. u32 u4ColAddr;
  467. u32 u4RowAddr;
  468. u32 u4OOBRowAddr;
  469. u8 au1OOB[128];
  470. u8 *pDataBuf;
  471. #ifdef NAND_PFM
  472. u32 pureReadOOB;
  473. u32 pureReadOOBNum;
  474. #endif
  475. };
  476. /*
  477. * ECC layout control structure. Exported to userspace for
  478. * diagnosis and to allow creation of raw images
  479. struct nand_ecclayout {
  480. uint32_t eccbytes;
  481. uint32_t eccpos[64];
  482. uint32_t oobavail;
  483. struct nand_oobfree oobfree[MTD_MAX_OOBFREE_ENTRIES];
  484. };
  485. */
  486. #define __DEBUG_NAND 1 /* Debug information on/off */
  487. #ifndef CONFIG_MTK_LEGACY
  488. extern u32 get_devinfo_with_index(u32 index);
  489. #endif
  490. void show_stack(struct task_struct *tsk, unsigned long *sp);
  491. extern struct mtd_partition g_pasStatic_Partition[PART_MAX_COUNT];
  492. extern struct mtd_perf_log g_MtdPerfLog;
  493. extern int part_num;
  494. extern void nand_release_device(struct mtd_info *mtd);
  495. extern int nand_get_device(struct mtd_info *mtd, int new_state);
  496. bool mtk_nand_SetFeature(struct mtd_info *mtd, u16 cmd, u32 addr, u8 *value, u8 bytes);
  497. bool mtk_nand_GetFeature(struct mtd_info *mtd, u16 cmd, u32 addr, u8 *value, u8 bytes);
  498. u32 MICRON_TRANSFER(u32 pageNo);
  499. u32 SANDISK_TRANSFER(u32 pageNo);
  500. u32 HYNIX_TRANSFER(u32 pageNo);
  501. u32 hynix_pairpage_mapping(u32 page, bool high_to_low);
  502. u32 micron_pairpage_mapping(u32 page, bool high_to_low);
  503. u32 sandisk_pairpage_mapping(u32 page, bool high_to_low);
  504. extern u64 part_get_startaddress(u64 byte_address, u32 *idx);
  505. extern bool raw_partition(u32 index);
  506. #define PMT 1
  507. #ifdef PMT
  508. extern void part_init_pmt(struct mtd_info *mtd, u8 *buf);
  509. extern struct mtd_partition g_exist_Partition[];
  510. #endif
  511. #endif