ifc.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. /*
  2. * Copyright 2022 NXP
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #ifndef IFC_H
  7. #define IFC_H
  8. #include <endian.h>
  9. #include <mmio.h>
  10. #define NXP_IFC_RUN_TIME_ADDR U(0x1000)
  11. /* CPSR - Chip Select Property Register Offset */
  12. #define EXT_CSPR(n) (U(0x000C) + (n * 0xC))
  13. #define CSPR(n) (U(0x0010) + (n * 0xC))
  14. #define CSOR(n) (U(0x0130) + (n * 0xC))
  15. #define EXT_CSOR(n) (U(0x0134) + (n * 0xC))
  16. #define IFC_AMASK_CS0 U(0x00A0)
  17. /* NAND specific Registers Offset */
  18. #define NCFGR (NXP_IFC_RUN_TIME_ADDR + U(0x0000))
  19. #define NAND_FCR0 (NXP_IFC_RUN_TIME_ADDR + U(0x0014))
  20. #define ROW0 (NXP_IFC_RUN_TIME_ADDR + U(0x003C))
  21. #define ROW1 (NXP_IFC_RUN_TIME_ADDR + U(0x004C))
  22. #define COL0 (NXP_IFC_RUN_TIME_ADDR + U(0x0044))
  23. #define COL1 (NXP_IFC_RUN_TIME_ADDR + U(0x0054))
  24. #define NAND_BC (NXP_IFC_RUN_TIME_ADDR + U(0x0108))
  25. #define NAND_FIR0 (NXP_IFC_RUN_TIME_ADDR + U(0x0110))
  26. #define NAND_FIR1 (NXP_IFC_RUN_TIME_ADDR + U(0x0114))
  27. #define NAND_FIR2 (NXP_IFC_RUN_TIME_ADDR + U(0x0118))
  28. #define NAND_CSEL (NXP_IFC_RUN_TIME_ADDR + U(0x015C))
  29. #define NANDSEQ_STRT (NXP_IFC_RUN_TIME_ADDR + U(0x0164))
  30. #define NAND_EVTER_STAT (NXP_IFC_RUN_TIME_ADDR + U(0x016C))
  31. #define NAND_AUTOBOOT_TRGR (NXP_IFC_RUN_TIME_ADDR + U(0x0284))
  32. /* Size of SRAM Buffer */
  33. #define CSPR_PS U(0x00000180)
  34. #define CSPR_PS_SHIFT 7
  35. #define CSPR_PS_8 0x1 // Port Size 8 bit
  36. #define CSPR_PS_16 0x2 // Port Size 16 bit
  37. #define CSPR_PS_32 0x3 // Port Size 32 bit
  38. /* Chip Select Option Register NAND Machine */
  39. #define CSOR_NAND_PGS U(0x00380000)
  40. #define CSOR_NAND_PGS_SHIFT 19
  41. #define CSOR_NAND_PGS_512 U(0x00000000)
  42. #define CSOR_NAND_PGS_2K U(0x00080000)
  43. #define CSOR_NAND_PGS_4K U(0x00100000)
  44. #define CSOR_NAND_PGS_8K U(0x00180000)
  45. #define CSOR_NAND_PGS_16K U(0x00200000)
  46. #define CSOR_NAND_PB U(0x00000700)
  47. #define CSOR_NAND_PB_32 U(0x00000000)
  48. #define CSOR_NAND_PB_64 U(0x00000100)
  49. #define CSOR_NAND_PB_128 U(0x00000200)
  50. #define CSOR_NAND_PB_256 U(0x00000300)
  51. #define CSOR_NAND_PB_512 U(0x00000400)
  52. #define CSOR_NAND_PB_1024 U(0x00000500)
  53. #define CSOR_NAND_PB_2048 U(0x00000600)
  54. #define CSOR_NAND_PPB_32 32
  55. #define CSOR_NAND_PPB_64 64
  56. #define CSOR_NAND_PPB_128 128
  57. #define CSOR_NAND_PPB_256 256
  58. #define CSOR_NAND_PPB_512 512
  59. #define CSOR_NAND_PPB_1024 1024
  60. #define CSOR_NAND_PPB_2048 2048
  61. /* NAND Chip select register */
  62. #define NAND_CSEL_SHIFT 26
  63. #define NAND_COL_MS_SHIFT 31
  64. /* FCR - Flash Command Register */
  65. #define FCR_CMD0 U(0xFF000000)
  66. #define FCR_CMD0_SHIFT 24
  67. #define FCR_CMD1 U(0x00FF0000)
  68. #define FCR_CMD1_SHIFT 16
  69. #define FCR_CMD2 U(0x0000FF00)
  70. #define FCR_CMD2_SHIFT 8
  71. #define FCR_CMD3 U(0x000000FF)
  72. #define FCR_CMD3_SHIFT 0
  73. /* FIR - Flash Instruction Register Opcode */
  74. #define FIR_OP0 U(0xFC000000)
  75. #define FIR_OP0_SHIFT 26
  76. #define FIR_OP1 U(0x03F00000)
  77. #define FIR_OP1_SHIFT 20
  78. #define FIR_OP2 U(0x000FC000)
  79. #define FIR_OP2_SHIFT 14
  80. #define FIR_OP3 U(0x00003F00)
  81. #define FIR_OP3_SHIFT 8
  82. #define FIR_OP4 U(0x000000FC)
  83. #define FIR_OP4_SHIFT 2
  84. #define FIR_OP5 U(0xFC000000)
  85. #define FIR_OP5_SHIFT 26
  86. #define FIR_OP6 U(0x03F00000)
  87. #define FIR_OP6_SHIFT 20
  88. /* Instruction Opcode - 6 bits */
  89. #define FIR_OP_NOP 0x00
  90. #define FIR_OP_CA0 0x01 /* Issue current column address */
  91. #define FIR_OP_CA1 0x02 /* Issue current column address */
  92. #define FIR_OP_RA0 0x05 /* Issue current column address */
  93. #define FIR_OP_RA1 0x06 /* Issue current column address */
  94. #define FIR_OP_CMD0 0x09 /* Issue command from FCR[CMD0] */
  95. #define FIR_OP_CMD1 0x0a /* Issue command from FCR[CMD1] */
  96. #define FIR_OP_CMD2 0x0b /* Issue command from FCR[CMD2] */
  97. #define FIR_OP_CMD3 0x0c /* Issue command from FCR[CMD3] */
  98. #define FIR_OP_CW0 0x11 /* Wait then issue FCR[CMD0] */
  99. #define FIR_OP_CW1 0x12 /* Wait then issue FCR[CMD1] */
  100. #define FIR_OP_CW2 0x13 /* Wait then issue FCR[CMD1] */
  101. #define FIR_OP_CW3 0x14 /* Wait then issue FCR[CMD1] */
  102. #define FIR_OP_WBCD 0x19 /* Wait then read FBCR bytes */
  103. #define FIR_OP_RBCD 0x1a /* Wait then read 1 or 2 bytes */
  104. #define FIR_OP_BTRD 0x1b /* Wait then read 1 or 2 bytes */
  105. #define FIR_OP_RDSTAT 0x1c /* Wait then read 1 or 2 bytes */
  106. #define FIR_OP_NWAIT 0x1d /* Wait then read 1 or 2 bytes */
  107. #define FIR_OP_WFR 0x1e /* Wait then read 1 or 2 bytes */
  108. #define NAND_SEQ_STRT_FIR_STRT U(0x80000000)
  109. #define NAND_SEQ_STRT_FIR_STRT_SHIFT 31
  110. #define NAND_EVTER_STAT_FTOER U(0x08000000)
  111. #define NAND_EVTER_STAT_WPER U(0x04000000)
  112. #define NAND_EVTER_STAT_ECCER U(0x02000000)
  113. #define NAND_EVTER_STAT_DQSER U(0x01000000)
  114. #define NAND_EVTER_STAT_RCW_DN U(0x00008000)
  115. #define NAND_EVTER_STAT_BOOT_DN U(0x00004000)
  116. #define NAND_EVTER_STAT_RCW_DN U(0x00008000)
  117. #define NAND_EVTER_STAT_OPC_DN U(0x80000000)
  118. #define NAND_EVTER_STAT_BBI_SRCH_SEL U(0x00000800)
  119. #define NCFGR_BOOT U(0x80000000)
  120. #define NAND_AUTOBOOT_TRGR_RCW_LD U(0x80000000)
  121. #define NAND_AUTOBOOT_TRGR_BOOT_LD U(0x20000000)
  122. /* ECC ERROR STATUS Registers */
  123. #define NAND_RCW_LD U(0x80000000)
  124. #define NAND_BOOT_LD U(0x20000000)
  125. /*Other Temp Defines */
  126. /*256 bad Blocks supported */
  127. #define BBT_SIZE 256
  128. /*Standard NAND flash commands */
  129. #define NAND_CMD_READ0 0
  130. #define NAND_CMD_READ1 1
  131. #define NAND_CMD_READOOB 0x50
  132. /*Extended commands for large page devices */
  133. #define NAND_CMD_READSTART 0x30
  134. #define NAND_TIMEOUT_MS 40
  135. #define EMPTY_VAL_CHECK U(0xFFFFFFFF)
  136. #define EMPTY_VAL 0xFF
  137. #define MAIN 0
  138. #define SPARE 1
  139. #define GOOD_BLK 1
  140. #define BAD_BLK 0
  141. #define DIV_2 2
  142. #define ATTRIBUTE_PGSZ 0xa
  143. #define ATTRIBUTE_PPB 0xb
  144. #define CSPR_PORT_SIZE_8 (0x1 << 7)
  145. #define CSPR_PORT_SIZE_16 (0x2 << 7)
  146. #define CSPR_PORT_SIZE_32 (0x3 << 7)
  147. /* NAND specific */
  148. #define RCW_SRC_NAND_PORT_MASK U(0x00000080)
  149. #define NAND_DEFAULT_CSPR U(0x00000053)
  150. #define NAND_DEFAULT_CSOR U(0x0180C00C)
  151. #define NAND_DEFAULT_EXT_CSPR U(0x00000000)
  152. #define NAND_DEFAULT_EXT_CSOR U(0x00000000)
  153. #define NAND_DEFAULT_FTIM0 U(0x181c0c10)
  154. #define NAND_DEFAULT_FTIM1 U(0x5454141e)
  155. #define NAND_DEFAULT_FTIM2 U(0x03808034)
  156. #define NAND_DEFAULT_FTIM3 U(0x2c000000)
  157. #define NAND_CSOR_ECC_MODE_DISABLE U(0x00000000)
  158. #define NAND_CSOR_ECC_MODE0 U(0x84000000)
  159. #define NAND_CSOR_ECC_MODE1 U(0x94000000)
  160. #define NAND_CSOR_ECC_MODE2 U(0xa4000000)
  161. #define NAND_CSOR_ECC_MODE3 U(0xb4000000)
  162. #define NAND_CSOR_PAGE_SIZE_2K (0x1 << 19)
  163. #define NAND_CSOR_PAGE_SIZE_4K (0x2 << 19)
  164. #define NAND_CSOR_PAGE_SIZE_8K (0x3 << 19)
  165. #define NAND_CSOR_PAGE_SIZE_16K (0x4 << 19)
  166. #define NAND_CSOR_PPB_64 (0x1 << 8)
  167. #define NAND_CSOR_PPB_128 (0x2 << 8)
  168. #define NAND_CSOR_PPB_256 (0x3 << 8)
  169. #define NAND_CSOR_PPB_512 (0x4 << 8)
  170. /* BBI INDICATOR for NAND_2K(CFG_RCW_SRC[1]) for
  171. * devices greater than 2K page size(CFG_RCW_SRC[3])
  172. */
  173. #define RCW_SRC_NAND_BBI_MASK U(0x00000008)
  174. #define RCW_SRC_NAND_BBI_MASK_NAND_2K U(0x00000002)
  175. #define NAND_BBI_ONFI_2K (0x1 << 1)
  176. #define NAND_BBI_ONFI (0x1 << 3)
  177. #define RCW_SRC_NAND_PAGE_MASK U(0x00000070)
  178. #define RCW_SRC_NAND_PAGE_MASK_NAND_2K U(0x0000000C)
  179. #define NAND_2K_XXX 0x00
  180. #define NAND_2K_64 0x04
  181. #define NAND_2K_128 0x08
  182. #define NAND_4K_128 0x10
  183. #define NAND_4K_256 0x20
  184. #define NAND_4K_512 0x30
  185. #define NAND_8K_128 0x40
  186. #define NAND_8K_256 0x50
  187. #define NAND_8K_512 0x60
  188. #define NAND_16K_512 0x70
  189. #define BLOCK_LEN_2K 2048
  190. #define RCW_SRC_NAND_ECC_MASK U(0x00000007)
  191. #define RCW_SRC_NAND_ECC_MASK_NAND_2K U(0x00000001)
  192. #define NAND_ECC_DISABLE 0x0
  193. #define NAND_ECC_4_520 0x1
  194. #define NAND_ECC_8_528 0x5
  195. #define NAND_ECC_24_1K 0x6
  196. #define NAND_ECC_40_1K 0x7
  197. #define NAND_SPARE_2K U(0x00000040)
  198. #define NAND_SPARE_4K_ECC_M0 U(0x00000080)
  199. #define NAND_SPARE_4K_ECC_M1 U(0x000000D2)
  200. #define NAND_SPARE_4K_ECC_M2 U(0x000000B0)
  201. #define NAND_SPARE_4K_ECC_M3 U(0x00000120)
  202. #define NAND_SPARE_8K_ECC_M0 U(0x00000088)
  203. #define NAND_SPARE_8K_ECC_M1 U(0x00000108)
  204. #define NAND_SPARE_8K_ECC_M2 U(0x00000158)
  205. #define NAND_SPARE_8K_ECC_M3 U(0x00000238)
  206. #define NAND_SPARE_16K_ECC_M0 U(0x00000108)
  207. #define NAND_SPARE_16K_ECC_M1 U(0x00000208)
  208. #define NAND_SPARE_16K_ECC_M2 U(0x000002A8)
  209. #define NAND_SPARE_16K_ECC_M3 U(0x00000468)
  210. struct nand_info {
  211. uintptr_t ifc_register_addr;
  212. uintptr_t ifc_region_addr;
  213. uint32_t page_size;
  214. uint32_t port_size;
  215. uint32_t blk_size;
  216. uint32_t ppb;
  217. uint32_t pi_width; /* Bits Required to index a page in block */
  218. uint32_t ral;
  219. uint32_t ibr_flow;
  220. uint32_t bbt[BBT_SIZE];
  221. uint32_t lgb; /* Last Good Block */
  222. uint32_t bbt_max; /* Total entries in bbt */
  223. uint32_t bzero_good;
  224. uint8_t bbs;
  225. uint8_t bad_marker_loc;
  226. uint8_t onfi_dev_flag;
  227. uint8_t init_time_boot_flag;
  228. uint8_t *buf;
  229. };
  230. struct ifc_regs {
  231. uint32_t ext_cspr;
  232. uint32_t cspr;
  233. uint32_t csor;
  234. uint32_t ext_csor;
  235. };
  236. struct sec_nand_info {
  237. uint32_t cspr_port_size;
  238. uint32_t csor_ecc_mode;
  239. uint32_t csor_page_size;
  240. uint32_t csor_ppb;
  241. uint32_t ext_csor_spare_size;
  242. uint32_t onfi_flag;
  243. };
  244. struct sec_nor_info {
  245. uint32_t cspr_port_size;
  246. uint32_t csor_nor_mode;
  247. uint32_t csor_adm_shift;
  248. uint32_t port_size;
  249. uint32_t addr_bits;
  250. };
  251. enum ifc_chip_sel {
  252. IFC_CS0,
  253. IFC_CS1,
  254. IFC_CS2,
  255. IFC_CS3,
  256. IFC_CS4,
  257. IFC_CS5,
  258. IFC_CS6,
  259. IFC_CS7,
  260. };
  261. enum ifc_ftims {
  262. IFC_FTIM0,
  263. IFC_FTIM1,
  264. IFC_FTIM2,
  265. IFC_FTIM3,
  266. };
  267. #ifdef NXP_IFC_BE
  268. #define nand_in32(a) bswap32(mmio_read_32((uintptr_t)a))
  269. #define nand_out32(a, v) mmio_write_32((uintptr_t)a, bswap32(v))
  270. #else
  271. #define nand_in32(a) mmio_read_32((uintptr_t)a)
  272. #define nand_out32(a, v) mmio_write_32((uintptr_t)a, v)
  273. #endif
  274. /* Read Write on IFC registers */
  275. static inline void write_reg(struct nand_info *nand, uint32_t reg, uint32_t val)
  276. {
  277. nand_out32(nand->ifc_register_addr + reg, val);
  278. }
  279. static inline uint32_t read_reg(struct nand_info *nand, uint32_t reg)
  280. {
  281. return nand_in32(nand->ifc_register_addr + reg);
  282. }
  283. #endif /* IFC_H */