fsl_ifc.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917
  1. /* Freescale Integrated Flash Controller
  2. *
  3. * Copyright 2011 Freescale Semiconductor, Inc
  4. *
  5. * Author: Dipen Dudhat <dipen.dudhat@freescale.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. */
  21. #ifndef __ASM_FSL_IFC_H
  22. #define __ASM_FSL_IFC_H
  23. #include <linux/compiler.h>
  24. #include <linux/types.h>
  25. #include <linux/io.h>
  26. #include <linux/of_platform.h>
  27. #include <linux/interrupt.h>
  28. /*
  29. * The actual number of banks implemented depends on the IFC version
  30. * - IFC version 1.0 implements 4 banks.
  31. * - IFC version 1.1 onward implements 8 banks.
  32. */
  33. #define FSL_IFC_BANK_COUNT 8
  34. #define FSL_IFC_VERSION_MASK 0x0F0F0000
  35. #define FSL_IFC_VERSION_1_0_0 0x01000000
  36. #define FSL_IFC_VERSION_1_1_0 0x01010000
  37. #define FSL_IFC_VERSION_2_0_0 0x02000000
  38. #define PGOFFSET_64K (64*1024)
  39. #define PGOFFSET_4K (4*1024)
  40. /*
  41. * CSPR - Chip Select Property Register
  42. */
  43. #define CSPR_BA 0xFFFF0000
  44. #define CSPR_BA_SHIFT 16
  45. #define CSPR_PORT_SIZE 0x00000180
  46. #define CSPR_PORT_SIZE_SHIFT 7
  47. /* Port Size 8 bit */
  48. #define CSPR_PORT_SIZE_8 0x00000080
  49. /* Port Size 16 bit */
  50. #define CSPR_PORT_SIZE_16 0x00000100
  51. /* Port Size 32 bit */
  52. #define CSPR_PORT_SIZE_32 0x00000180
  53. /* Write Protect */
  54. #define CSPR_WP 0x00000040
  55. #define CSPR_WP_SHIFT 6
  56. /* Machine Select */
  57. #define CSPR_MSEL 0x00000006
  58. #define CSPR_MSEL_SHIFT 1
  59. /* NOR */
  60. #define CSPR_MSEL_NOR 0x00000000
  61. /* NAND */
  62. #define CSPR_MSEL_NAND 0x00000002
  63. /* GPCM */
  64. #define CSPR_MSEL_GPCM 0x00000004
  65. /* Bank Valid */
  66. #define CSPR_V 0x00000001
  67. #define CSPR_V_SHIFT 0
  68. /*
  69. * Address Mask Register
  70. */
  71. #define IFC_AMASK_MASK 0xFFFF0000
  72. #define IFC_AMASK_SHIFT 16
  73. #define IFC_AMASK(n) (IFC_AMASK_MASK << \
  74. (__ilog2(n) - IFC_AMASK_SHIFT))
  75. /*
  76. * Chip Select Option Register IFC_NAND Machine
  77. */
  78. /* Enable ECC Encoder */
  79. #define CSOR_NAND_ECC_ENC_EN 0x80000000
  80. #define CSOR_NAND_ECC_MODE_MASK 0x30000000
  81. /* 4 bit correction per 520 Byte sector */
  82. #define CSOR_NAND_ECC_MODE_4 0x00000000
  83. /* 8 bit correction per 528 Byte sector */
  84. #define CSOR_NAND_ECC_MODE_8 0x10000000
  85. /* Enable ECC Decoder */
  86. #define CSOR_NAND_ECC_DEC_EN 0x04000000
  87. /* Row Address Length */
  88. #define CSOR_NAND_RAL_MASK 0x01800000
  89. #define CSOR_NAND_RAL_SHIFT 20
  90. #define CSOR_NAND_RAL_1 0x00000000
  91. #define CSOR_NAND_RAL_2 0x00800000
  92. #define CSOR_NAND_RAL_3 0x01000000
  93. #define CSOR_NAND_RAL_4 0x01800000
  94. /* Page Size 512b, 2k, 4k */
  95. #define CSOR_NAND_PGS_MASK 0x00180000
  96. #define CSOR_NAND_PGS_SHIFT 16
  97. #define CSOR_NAND_PGS_512 0x00000000
  98. #define CSOR_NAND_PGS_2K 0x00080000
  99. #define CSOR_NAND_PGS_4K 0x00100000
  100. #define CSOR_NAND_PGS_8K 0x00180000
  101. /* Spare region Size */
  102. #define CSOR_NAND_SPRZ_MASK 0x0000E000
  103. #define CSOR_NAND_SPRZ_SHIFT 13
  104. #define CSOR_NAND_SPRZ_16 0x00000000
  105. #define CSOR_NAND_SPRZ_64 0x00002000
  106. #define CSOR_NAND_SPRZ_128 0x00004000
  107. #define CSOR_NAND_SPRZ_210 0x00006000
  108. #define CSOR_NAND_SPRZ_218 0x00008000
  109. #define CSOR_NAND_SPRZ_224 0x0000A000
  110. #define CSOR_NAND_SPRZ_CSOR_EXT 0x0000C000
  111. /* Pages Per Block */
  112. #define CSOR_NAND_PB_MASK 0x00000700
  113. #define CSOR_NAND_PB_SHIFT 8
  114. #define CSOR_NAND_PB(n) ((__ilog2(n) - 5) << CSOR_NAND_PB_SHIFT)
  115. /* Time for Read Enable High to Output High Impedance */
  116. #define CSOR_NAND_TRHZ_MASK 0x0000001C
  117. #define CSOR_NAND_TRHZ_SHIFT 2
  118. #define CSOR_NAND_TRHZ_20 0x00000000
  119. #define CSOR_NAND_TRHZ_40 0x00000004
  120. #define CSOR_NAND_TRHZ_60 0x00000008
  121. #define CSOR_NAND_TRHZ_80 0x0000000C
  122. #define CSOR_NAND_TRHZ_100 0x00000010
  123. /* Buffer control disable */
  124. #define CSOR_NAND_BCTLD 0x00000001
  125. /*
  126. * Chip Select Option Register - NOR Flash Mode
  127. */
  128. /* Enable Address shift Mode */
  129. #define CSOR_NOR_ADM_SHFT_MODE_EN 0x80000000
  130. /* Page Read Enable from NOR device */
  131. #define CSOR_NOR_PGRD_EN 0x10000000
  132. /* AVD Toggle Enable during Burst Program */
  133. #define CSOR_NOR_AVD_TGL_PGM_EN 0x01000000
  134. /* Address Data Multiplexing Shift */
  135. #define CSOR_NOR_ADM_MASK 0x0003E000
  136. #define CSOR_NOR_ADM_SHIFT_SHIFT 13
  137. #define CSOR_NOR_ADM_SHIFT(n) ((n) << CSOR_NOR_ADM_SHIFT_SHIFT)
  138. /* Type of the NOR device hooked */
  139. #define CSOR_NOR_NOR_MODE_AYSNC_NOR 0x00000000
  140. #define CSOR_NOR_NOR_MODE_AVD_NOR 0x00000020
  141. /* Time for Read Enable High to Output High Impedance */
  142. #define CSOR_NOR_TRHZ_MASK 0x0000001C
  143. #define CSOR_NOR_TRHZ_SHIFT 2
  144. #define CSOR_NOR_TRHZ_20 0x00000000
  145. #define CSOR_NOR_TRHZ_40 0x00000004
  146. #define CSOR_NOR_TRHZ_60 0x00000008
  147. #define CSOR_NOR_TRHZ_80 0x0000000C
  148. #define CSOR_NOR_TRHZ_100 0x00000010
  149. /* Buffer control disable */
  150. #define CSOR_NOR_BCTLD 0x00000001
  151. /*
  152. * Chip Select Option Register - GPCM Mode
  153. */
  154. /* GPCM Mode - Normal */
  155. #define CSOR_GPCM_GPMODE_NORMAL 0x00000000
  156. /* GPCM Mode - GenericASIC */
  157. #define CSOR_GPCM_GPMODE_ASIC 0x80000000
  158. /* Parity Mode odd/even */
  159. #define CSOR_GPCM_PARITY_EVEN 0x40000000
  160. /* Parity Checking enable/disable */
  161. #define CSOR_GPCM_PAR_EN 0x20000000
  162. /* GPCM Timeout Count */
  163. #define CSOR_GPCM_GPTO_MASK 0x0F000000
  164. #define CSOR_GPCM_GPTO_SHIFT 24
  165. #define CSOR_GPCM_GPTO(n) ((__ilog2(n) - 8) << CSOR_GPCM_GPTO_SHIFT)
  166. /* GPCM External Access Termination mode for read access */
  167. #define CSOR_GPCM_RGETA_EXT 0x00080000
  168. /* GPCM External Access Termination mode for write access */
  169. #define CSOR_GPCM_WGETA_EXT 0x00040000
  170. /* Address Data Multiplexing Shift */
  171. #define CSOR_GPCM_ADM_MASK 0x0003E000
  172. #define CSOR_GPCM_ADM_SHIFT_SHIFT 13
  173. #define CSOR_GPCM_ADM_SHIFT(n) ((n) << CSOR_GPCM_ADM_SHIFT_SHIFT)
  174. /* Generic ASIC Parity error indication delay */
  175. #define CSOR_GPCM_GAPERRD_MASK 0x00000180
  176. #define CSOR_GPCM_GAPERRD_SHIFT 7
  177. #define CSOR_GPCM_GAPERRD(n) (((n) - 1) << CSOR_GPCM_GAPERRD_SHIFT)
  178. /* Time for Read Enable High to Output High Impedance */
  179. #define CSOR_GPCM_TRHZ_MASK 0x0000001C
  180. #define CSOR_GPCM_TRHZ_20 0x00000000
  181. #define CSOR_GPCM_TRHZ_40 0x00000004
  182. #define CSOR_GPCM_TRHZ_60 0x00000008
  183. #define CSOR_GPCM_TRHZ_80 0x0000000C
  184. #define CSOR_GPCM_TRHZ_100 0x00000010
  185. /* Buffer control disable */
  186. #define CSOR_GPCM_BCTLD 0x00000001
  187. /*
  188. * Ready Busy Status Register (RB_STAT)
  189. */
  190. /* CSn is READY */
  191. #define IFC_RB_STAT_READY_CS0 0x80000000
  192. #define IFC_RB_STAT_READY_CS1 0x40000000
  193. #define IFC_RB_STAT_READY_CS2 0x20000000
  194. #define IFC_RB_STAT_READY_CS3 0x10000000
  195. /*
  196. * General Control Register (GCR)
  197. */
  198. #define IFC_GCR_MASK 0x8000F800
  199. /* reset all IFC hardware */
  200. #define IFC_GCR_SOFT_RST_ALL 0x80000000
  201. /* Turnaroud Time of external buffer */
  202. #define IFC_GCR_TBCTL_TRN_TIME 0x0000F800
  203. #define IFC_GCR_TBCTL_TRN_TIME_SHIFT 11
  204. /*
  205. * Common Event and Error Status Register (CM_EVTER_STAT)
  206. */
  207. /* Chip select error */
  208. #define IFC_CM_EVTER_STAT_CSER 0x80000000
  209. /*
  210. * Common Event and Error Enable Register (CM_EVTER_EN)
  211. */
  212. /* Chip select error checking enable */
  213. #define IFC_CM_EVTER_EN_CSEREN 0x80000000
  214. /*
  215. * Common Event and Error Interrupt Enable Register (CM_EVTER_INTR_EN)
  216. */
  217. /* Chip select error interrupt enable */
  218. #define IFC_CM_EVTER_INTR_EN_CSERIREN 0x80000000
  219. /*
  220. * Common Transfer Error Attribute Register-0 (CM_ERATTR0)
  221. */
  222. /* transaction type of error Read/Write */
  223. #define IFC_CM_ERATTR0_ERTYP_READ 0x80000000
  224. #define IFC_CM_ERATTR0_ERAID 0x0FF00000
  225. #define IFC_CM_ERATTR0_ERAID_SHIFT 20
  226. #define IFC_CM_ERATTR0_ESRCID 0x0000FF00
  227. #define IFC_CM_ERATTR0_ESRCID_SHIFT 8
  228. /*
  229. * Clock Control Register (CCR)
  230. */
  231. #define IFC_CCR_MASK 0x0F0F8800
  232. /* Clock division ratio */
  233. #define IFC_CCR_CLK_DIV_MASK 0x0F000000
  234. #define IFC_CCR_CLK_DIV_SHIFT 24
  235. #define IFC_CCR_CLK_DIV(n) ((n-1) << IFC_CCR_CLK_DIV_SHIFT)
  236. /* IFC Clock Delay */
  237. #define IFC_CCR_CLK_DLY_MASK 0x000F0000
  238. #define IFC_CCR_CLK_DLY_SHIFT 16
  239. #define IFC_CCR_CLK_DLY(n) ((n) << IFC_CCR_CLK_DLY_SHIFT)
  240. /* Invert IFC clock before sending out */
  241. #define IFC_CCR_INV_CLK_EN 0x00008000
  242. /* Fedback IFC Clock */
  243. #define IFC_CCR_FB_IFC_CLK_SEL 0x00000800
  244. /*
  245. * Clock Status Register (CSR)
  246. */
  247. /* Clk is stable */
  248. #define IFC_CSR_CLK_STAT_STABLE 0x80000000
  249. /*
  250. * IFC_NAND Machine Specific Registers
  251. */
  252. /*
  253. * NAND Configuration Register (NCFGR)
  254. */
  255. /* Auto Boot Mode */
  256. #define IFC_NAND_NCFGR_BOOT 0x80000000
  257. /* SRAM Initialization */
  258. #define IFC_NAND_NCFGR_SRAM_INIT_EN 0x20000000
  259. /* Addressing Mode-ROW0+n/COL0 */
  260. #define IFC_NAND_NCFGR_ADDR_MODE_RC0 0x00000000
  261. /* Addressing Mode-ROW0+n/COL0+n */
  262. #define IFC_NAND_NCFGR_ADDR_MODE_RC1 0x00400000
  263. /* Number of loop iterations of FIR sequences for multi page operations */
  264. #define IFC_NAND_NCFGR_NUM_LOOP_MASK 0x0000F000
  265. #define IFC_NAND_NCFGR_NUM_LOOP_SHIFT 12
  266. #define IFC_NAND_NCFGR_NUM_LOOP(n) ((n) << IFC_NAND_NCFGR_NUM_LOOP_SHIFT)
  267. /* Number of wait cycles */
  268. #define IFC_NAND_NCFGR_NUM_WAIT_MASK 0x000000FF
  269. #define IFC_NAND_NCFGR_NUM_WAIT_SHIFT 0
  270. /*
  271. * NAND Flash Command Registers (NAND_FCR0/NAND_FCR1)
  272. */
  273. /* General purpose FCM flash command bytes CMD0-CMD7 */
  274. #define IFC_NAND_FCR0_CMD0 0xFF000000
  275. #define IFC_NAND_FCR0_CMD0_SHIFT 24
  276. #define IFC_NAND_FCR0_CMD1 0x00FF0000
  277. #define IFC_NAND_FCR0_CMD1_SHIFT 16
  278. #define IFC_NAND_FCR0_CMD2 0x0000FF00
  279. #define IFC_NAND_FCR0_CMD2_SHIFT 8
  280. #define IFC_NAND_FCR0_CMD3 0x000000FF
  281. #define IFC_NAND_FCR0_CMD3_SHIFT 0
  282. #define IFC_NAND_FCR1_CMD4 0xFF000000
  283. #define IFC_NAND_FCR1_CMD4_SHIFT 24
  284. #define IFC_NAND_FCR1_CMD5 0x00FF0000
  285. #define IFC_NAND_FCR1_CMD5_SHIFT 16
  286. #define IFC_NAND_FCR1_CMD6 0x0000FF00
  287. #define IFC_NAND_FCR1_CMD6_SHIFT 8
  288. #define IFC_NAND_FCR1_CMD7 0x000000FF
  289. #define IFC_NAND_FCR1_CMD7_SHIFT 0
  290. /*
  291. * Flash ROW and COL Address Register (ROWn, COLn)
  292. */
  293. /* Main/spare region locator */
  294. #define IFC_NAND_COL_MS 0x80000000
  295. /* Column Address */
  296. #define IFC_NAND_COL_CA_MASK 0x00000FFF
  297. /*
  298. * NAND Flash Byte Count Register (NAND_BC)
  299. */
  300. /* Byte Count for read/Write */
  301. #define IFC_NAND_BC 0x000001FF
  302. /*
  303. * NAND Flash Instruction Registers (NAND_FIR0/NAND_FIR1/NAND_FIR2)
  304. */
  305. /* NAND Machine specific opcodes OP0-OP14*/
  306. #define IFC_NAND_FIR0_OP0 0xFC000000
  307. #define IFC_NAND_FIR0_OP0_SHIFT 26
  308. #define IFC_NAND_FIR0_OP1 0x03F00000
  309. #define IFC_NAND_FIR0_OP1_SHIFT 20
  310. #define IFC_NAND_FIR0_OP2 0x000FC000
  311. #define IFC_NAND_FIR0_OP2_SHIFT 14
  312. #define IFC_NAND_FIR0_OP3 0x00003F00
  313. #define IFC_NAND_FIR0_OP3_SHIFT 8
  314. #define IFC_NAND_FIR0_OP4 0x000000FC
  315. #define IFC_NAND_FIR0_OP4_SHIFT 2
  316. #define IFC_NAND_FIR1_OP5 0xFC000000
  317. #define IFC_NAND_FIR1_OP5_SHIFT 26
  318. #define IFC_NAND_FIR1_OP6 0x03F00000
  319. #define IFC_NAND_FIR1_OP6_SHIFT 20
  320. #define IFC_NAND_FIR1_OP7 0x000FC000
  321. #define IFC_NAND_FIR1_OP7_SHIFT 14
  322. #define IFC_NAND_FIR1_OP8 0x00003F00
  323. #define IFC_NAND_FIR1_OP8_SHIFT 8
  324. #define IFC_NAND_FIR1_OP9 0x000000FC
  325. #define IFC_NAND_FIR1_OP9_SHIFT 2
  326. #define IFC_NAND_FIR2_OP10 0xFC000000
  327. #define IFC_NAND_FIR2_OP10_SHIFT 26
  328. #define IFC_NAND_FIR2_OP11 0x03F00000
  329. #define IFC_NAND_FIR2_OP11_SHIFT 20
  330. #define IFC_NAND_FIR2_OP12 0x000FC000
  331. #define IFC_NAND_FIR2_OP12_SHIFT 14
  332. #define IFC_NAND_FIR2_OP13 0x00003F00
  333. #define IFC_NAND_FIR2_OP13_SHIFT 8
  334. #define IFC_NAND_FIR2_OP14 0x000000FC
  335. #define IFC_NAND_FIR2_OP14_SHIFT 2
  336. /*
  337. * Instruction opcodes to be programmed
  338. * in FIR registers- 6bits
  339. */
  340. enum ifc_nand_fir_opcodes {
  341. IFC_FIR_OP_NOP,
  342. IFC_FIR_OP_CA0,
  343. IFC_FIR_OP_CA1,
  344. IFC_FIR_OP_CA2,
  345. IFC_FIR_OP_CA3,
  346. IFC_FIR_OP_RA0,
  347. IFC_FIR_OP_RA1,
  348. IFC_FIR_OP_RA2,
  349. IFC_FIR_OP_RA3,
  350. IFC_FIR_OP_CMD0,
  351. IFC_FIR_OP_CMD1,
  352. IFC_FIR_OP_CMD2,
  353. IFC_FIR_OP_CMD3,
  354. IFC_FIR_OP_CMD4,
  355. IFC_FIR_OP_CMD5,
  356. IFC_FIR_OP_CMD6,
  357. IFC_FIR_OP_CMD7,
  358. IFC_FIR_OP_CW0,
  359. IFC_FIR_OP_CW1,
  360. IFC_FIR_OP_CW2,
  361. IFC_FIR_OP_CW3,
  362. IFC_FIR_OP_CW4,
  363. IFC_FIR_OP_CW5,
  364. IFC_FIR_OP_CW6,
  365. IFC_FIR_OP_CW7,
  366. IFC_FIR_OP_WBCD,
  367. IFC_FIR_OP_RBCD,
  368. IFC_FIR_OP_BTRD,
  369. IFC_FIR_OP_RDSTAT,
  370. IFC_FIR_OP_NWAIT,
  371. IFC_FIR_OP_WFR,
  372. IFC_FIR_OP_SBRD,
  373. IFC_FIR_OP_UA,
  374. IFC_FIR_OP_RB,
  375. };
  376. /*
  377. * NAND Chip Select Register (NAND_CSEL)
  378. */
  379. #define IFC_NAND_CSEL 0x0C000000
  380. #define IFC_NAND_CSEL_SHIFT 26
  381. #define IFC_NAND_CSEL_CS0 0x00000000
  382. #define IFC_NAND_CSEL_CS1 0x04000000
  383. #define IFC_NAND_CSEL_CS2 0x08000000
  384. #define IFC_NAND_CSEL_CS3 0x0C000000
  385. /*
  386. * NAND Operation Sequence Start (NANDSEQ_STRT)
  387. */
  388. /* NAND Flash Operation Start */
  389. #define IFC_NAND_SEQ_STRT_FIR_STRT 0x80000000
  390. /* Automatic Erase */
  391. #define IFC_NAND_SEQ_STRT_AUTO_ERS 0x00800000
  392. /* Automatic Program */
  393. #define IFC_NAND_SEQ_STRT_AUTO_PGM 0x00100000
  394. /* Automatic Copyback */
  395. #define IFC_NAND_SEQ_STRT_AUTO_CPB 0x00020000
  396. /* Automatic Read Operation */
  397. #define IFC_NAND_SEQ_STRT_AUTO_RD 0x00004000
  398. /* Automatic Status Read */
  399. #define IFC_NAND_SEQ_STRT_AUTO_STAT_RD 0x00000800
  400. /*
  401. * NAND Event and Error Status Register (NAND_EVTER_STAT)
  402. */
  403. /* Operation Complete */
  404. #define IFC_NAND_EVTER_STAT_OPC 0x80000000
  405. /* Flash Timeout Error */
  406. #define IFC_NAND_EVTER_STAT_FTOER 0x08000000
  407. /* Write Protect Error */
  408. #define IFC_NAND_EVTER_STAT_WPER 0x04000000
  409. /* ECC Error */
  410. #define IFC_NAND_EVTER_STAT_ECCER 0x02000000
  411. /* RCW Load Done */
  412. #define IFC_NAND_EVTER_STAT_RCW_DN 0x00008000
  413. /* Boot Loadr Done */
  414. #define IFC_NAND_EVTER_STAT_BOOT_DN 0x00004000
  415. /* Bad Block Indicator search select */
  416. #define IFC_NAND_EVTER_STAT_BBI_SRCH_SE 0x00000800
  417. /*
  418. * NAND Flash Page Read Completion Event Status Register
  419. * (PGRDCMPL_EVT_STAT)
  420. */
  421. #define PGRDCMPL_EVT_STAT_MASK 0xFFFF0000
  422. /* Small Page 0-15 Done */
  423. #define PGRDCMPL_EVT_STAT_SECTION_SP(n) (1 << (31 - (n)))
  424. /* Large Page(2K) 0-3 Done */
  425. #define PGRDCMPL_EVT_STAT_LP_2K(n) (0xF << (28 - (n)*4))
  426. /* Large Page(4K) 0-1 Done */
  427. #define PGRDCMPL_EVT_STAT_LP_4K(n) (0xFF << (24 - (n)*8))
  428. /*
  429. * NAND Event and Error Enable Register (NAND_EVTER_EN)
  430. */
  431. /* Operation complete event enable */
  432. #define IFC_NAND_EVTER_EN_OPC_EN 0x80000000
  433. /* Page read complete event enable */
  434. #define IFC_NAND_EVTER_EN_PGRDCMPL_EN 0x20000000
  435. /* Flash Timeout error enable */
  436. #define IFC_NAND_EVTER_EN_FTOER_EN 0x08000000
  437. /* Write Protect error enable */
  438. #define IFC_NAND_EVTER_EN_WPER_EN 0x04000000
  439. /* ECC error logging enable */
  440. #define IFC_NAND_EVTER_EN_ECCER_EN 0x02000000
  441. /*
  442. * NAND Event and Error Interrupt Enable Register (NAND_EVTER_INTR_EN)
  443. */
  444. /* Enable interrupt for operation complete */
  445. #define IFC_NAND_EVTER_INTR_OPCIR_EN 0x80000000
  446. /* Enable interrupt for Page read complete */
  447. #define IFC_NAND_EVTER_INTR_PGRDCMPLIR_EN 0x20000000
  448. /* Enable interrupt for Flash timeout error */
  449. #define IFC_NAND_EVTER_INTR_FTOERIR_EN 0x08000000
  450. /* Enable interrupt for Write protect error */
  451. #define IFC_NAND_EVTER_INTR_WPERIR_EN 0x04000000
  452. /* Enable interrupt for ECC error*/
  453. #define IFC_NAND_EVTER_INTR_ECCERIR_EN 0x02000000
  454. /*
  455. * NAND Transfer Error Attribute Register-0 (NAND_ERATTR0)
  456. */
  457. #define IFC_NAND_ERATTR0_MASK 0x0C080000
  458. /* Error on CS0-3 for NAND */
  459. #define IFC_NAND_ERATTR0_ERCS_CS0 0x00000000
  460. #define IFC_NAND_ERATTR0_ERCS_CS1 0x04000000
  461. #define IFC_NAND_ERATTR0_ERCS_CS2 0x08000000
  462. #define IFC_NAND_ERATTR0_ERCS_CS3 0x0C000000
  463. /* Transaction type of error Read/Write */
  464. #define IFC_NAND_ERATTR0_ERTTYPE_READ 0x00080000
  465. /*
  466. * NAND Flash Status Register (NAND_FSR)
  467. */
  468. /* First byte of data read from read status op */
  469. #define IFC_NAND_NFSR_RS0 0xFF000000
  470. /* Second byte of data read from read status op */
  471. #define IFC_NAND_NFSR_RS1 0x00FF0000
  472. /*
  473. * ECC Error Status Registers (ECCSTAT0-ECCSTAT3)
  474. */
  475. /* Number of ECC errors on sector n (n = 0-15) */
  476. #define IFC_NAND_ECCSTAT0_ERRCNT_SECTOR0_MASK 0x0F000000
  477. #define IFC_NAND_ECCSTAT0_ERRCNT_SECTOR0_SHIFT 24
  478. #define IFC_NAND_ECCSTAT0_ERRCNT_SECTOR1_MASK 0x000F0000
  479. #define IFC_NAND_ECCSTAT0_ERRCNT_SECTOR1_SHIFT 16
  480. #define IFC_NAND_ECCSTAT0_ERRCNT_SECTOR2_MASK 0x00000F00
  481. #define IFC_NAND_ECCSTAT0_ERRCNT_SECTOR2_SHIFT 8
  482. #define IFC_NAND_ECCSTAT0_ERRCNT_SECTOR3_MASK 0x0000000F
  483. #define IFC_NAND_ECCSTAT0_ERRCNT_SECTOR3_SHIFT 0
  484. #define IFC_NAND_ECCSTAT1_ERRCNT_SECTOR4_MASK 0x0F000000
  485. #define IFC_NAND_ECCSTAT1_ERRCNT_SECTOR4_SHIFT 24
  486. #define IFC_NAND_ECCSTAT1_ERRCNT_SECTOR5_MASK 0x000F0000
  487. #define IFC_NAND_ECCSTAT1_ERRCNT_SECTOR5_SHIFT 16
  488. #define IFC_NAND_ECCSTAT1_ERRCNT_SECTOR6_MASK 0x00000F00
  489. #define IFC_NAND_ECCSTAT1_ERRCNT_SECTOR6_SHIFT 8
  490. #define IFC_NAND_ECCSTAT1_ERRCNT_SECTOR7_MASK 0x0000000F
  491. #define IFC_NAND_ECCSTAT1_ERRCNT_SECTOR7_SHIFT 0
  492. #define IFC_NAND_ECCSTAT2_ERRCNT_SECTOR8_MASK 0x0F000000
  493. #define IFC_NAND_ECCSTAT2_ERRCNT_SECTOR8_SHIFT 24
  494. #define IFC_NAND_ECCSTAT2_ERRCNT_SECTOR9_MASK 0x000F0000
  495. #define IFC_NAND_ECCSTAT2_ERRCNT_SECTOR9_SHIFT 16
  496. #define IFC_NAND_ECCSTAT2_ERRCNT_SECTOR10_MASK 0x00000F00
  497. #define IFC_NAND_ECCSTAT2_ERRCNT_SECTOR10_SHIFT 8
  498. #define IFC_NAND_ECCSTAT2_ERRCNT_SECTOR11_MASK 0x0000000F
  499. #define IFC_NAND_ECCSTAT2_ERRCNT_SECTOR11_SHIFT 0
  500. #define IFC_NAND_ECCSTAT3_ERRCNT_SECTOR12_MASK 0x0F000000
  501. #define IFC_NAND_ECCSTAT3_ERRCNT_SECTOR12_SHIFT 24
  502. #define IFC_NAND_ECCSTAT3_ERRCNT_SECTOR13_MASK 0x000F0000
  503. #define IFC_NAND_ECCSTAT3_ERRCNT_SECTOR13_SHIFT 16
  504. #define IFC_NAND_ECCSTAT3_ERRCNT_SECTOR14_MASK 0x00000F00
  505. #define IFC_NAND_ECCSTAT3_ERRCNT_SECTOR14_SHIFT 8
  506. #define IFC_NAND_ECCSTAT3_ERRCNT_SECTOR15_MASK 0x0000000F
  507. #define IFC_NAND_ECCSTAT3_ERRCNT_SECTOR15_SHIFT 0
  508. /*
  509. * NAND Control Register (NANDCR)
  510. */
  511. #define IFC_NAND_NCR_FTOCNT_MASK 0x1E000000
  512. #define IFC_NAND_NCR_FTOCNT_SHIFT 25
  513. #define IFC_NAND_NCR_FTOCNT(n) ((_ilog2(n) - 8) << IFC_NAND_NCR_FTOCNT_SHIFT)
  514. /*
  515. * NAND_AUTOBOOT_TRGR
  516. */
  517. /* Trigger RCW load */
  518. #define IFC_NAND_AUTOBOOT_TRGR_RCW_LD 0x80000000
  519. /* Trigget Auto Boot */
  520. #define IFC_NAND_AUTOBOOT_TRGR_BOOT_LD 0x20000000
  521. /*
  522. * NAND_MDR
  523. */
  524. /* 1st read data byte when opcode SBRD */
  525. #define IFC_NAND_MDR_RDATA0 0xFF000000
  526. /* 2nd read data byte when opcode SBRD */
  527. #define IFC_NAND_MDR_RDATA1 0x00FF0000
  528. /*
  529. * NOR Machine Specific Registers
  530. */
  531. /*
  532. * NOR Event and Error Status Register (NOR_EVTER_STAT)
  533. */
  534. /* NOR Command Sequence Operation Complete */
  535. #define IFC_NOR_EVTER_STAT_OPC_NOR 0x80000000
  536. /* Write Protect Error */
  537. #define IFC_NOR_EVTER_STAT_WPER 0x04000000
  538. /* Command Sequence Timeout Error */
  539. #define IFC_NOR_EVTER_STAT_STOER 0x01000000
  540. /*
  541. * NOR Event and Error Enable Register (NOR_EVTER_EN)
  542. */
  543. /* NOR Command Seq complete event enable */
  544. #define IFC_NOR_EVTER_EN_OPCEN_NOR 0x80000000
  545. /* Write Protect Error Checking Enable */
  546. #define IFC_NOR_EVTER_EN_WPEREN 0x04000000
  547. /* Timeout Error Enable */
  548. #define IFC_NOR_EVTER_EN_STOEREN 0x01000000
  549. /*
  550. * NOR Event and Error Interrupt Enable Register (NOR_EVTER_INTR_EN)
  551. */
  552. /* Enable interrupt for OPC complete */
  553. #define IFC_NOR_EVTER_INTR_OPCEN_NOR 0x80000000
  554. /* Enable interrupt for write protect error */
  555. #define IFC_NOR_EVTER_INTR_WPEREN 0x04000000
  556. /* Enable interrupt for timeout error */
  557. #define IFC_NOR_EVTER_INTR_STOEREN 0x01000000
  558. /*
  559. * NOR Transfer Error Attribute Register-0 (NOR_ERATTR0)
  560. */
  561. /* Source ID for error transaction */
  562. #define IFC_NOR_ERATTR0_ERSRCID 0xFF000000
  563. /* AXI ID for error transation */
  564. #define IFC_NOR_ERATTR0_ERAID 0x000FF000
  565. /* Chip select corresponds to NOR error */
  566. #define IFC_NOR_ERATTR0_ERCS_CS0 0x00000000
  567. #define IFC_NOR_ERATTR0_ERCS_CS1 0x00000010
  568. #define IFC_NOR_ERATTR0_ERCS_CS2 0x00000020
  569. #define IFC_NOR_ERATTR0_ERCS_CS3 0x00000030
  570. /* Type of transaction read/write */
  571. #define IFC_NOR_ERATTR0_ERTYPE_READ 0x00000001
  572. /*
  573. * NOR Transfer Error Attribute Register-2 (NOR_ERATTR2)
  574. */
  575. #define IFC_NOR_ERATTR2_ER_NUM_PHASE_EXP 0x000F0000
  576. #define IFC_NOR_ERATTR2_ER_NUM_PHASE_PER 0x00000F00
  577. /*
  578. * NOR Control Register (NORCR)
  579. */
  580. #define IFC_NORCR_MASK 0x0F0F0000
  581. /* No. of Address/Data Phase */
  582. #define IFC_NORCR_NUM_PHASE_MASK 0x0F000000
  583. #define IFC_NORCR_NUM_PHASE_SHIFT 24
  584. #define IFC_NORCR_NUM_PHASE(n) ((n-1) << IFC_NORCR_NUM_PHASE_SHIFT)
  585. /* Sequence Timeout Count */
  586. #define IFC_NORCR_STOCNT_MASK 0x000F0000
  587. #define IFC_NORCR_STOCNT_SHIFT 16
  588. #define IFC_NORCR_STOCNT(n) ((__ilog2(n) - 8) << IFC_NORCR_STOCNT_SHIFT)
  589. /*
  590. * GPCM Machine specific registers
  591. */
  592. /*
  593. * GPCM Event and Error Status Register (GPCM_EVTER_STAT)
  594. */
  595. /* Timeout error */
  596. #define IFC_GPCM_EVTER_STAT_TOER 0x04000000
  597. /* Parity error */
  598. #define IFC_GPCM_EVTER_STAT_PER 0x01000000
  599. /*
  600. * GPCM Event and Error Enable Register (GPCM_EVTER_EN)
  601. */
  602. /* Timeout error enable */
  603. #define IFC_GPCM_EVTER_EN_TOER_EN 0x04000000
  604. /* Parity error enable */
  605. #define IFC_GPCM_EVTER_EN_PER_EN 0x01000000
  606. /*
  607. * GPCM Event and Error Interrupt Enable Register (GPCM_EVTER_INTR_EN)
  608. */
  609. /* Enable Interrupt for timeout error */
  610. #define IFC_GPCM_EEIER_TOERIR_EN 0x04000000
  611. /* Enable Interrupt for Parity error */
  612. #define IFC_GPCM_EEIER_PERIR_EN 0x01000000
  613. /*
  614. * GPCM Transfer Error Attribute Register-0 (GPCM_ERATTR0)
  615. */
  616. /* Source ID for error transaction */
  617. #define IFC_GPCM_ERATTR0_ERSRCID 0xFF000000
  618. /* AXI ID for error transaction */
  619. #define IFC_GPCM_ERATTR0_ERAID 0x000FF000
  620. /* Chip select corresponds to GPCM error */
  621. #define IFC_GPCM_ERATTR0_ERCS_CS0 0x00000000
  622. #define IFC_GPCM_ERATTR0_ERCS_CS1 0x00000040
  623. #define IFC_GPCM_ERATTR0_ERCS_CS2 0x00000080
  624. #define IFC_GPCM_ERATTR0_ERCS_CS3 0x000000C0
  625. /* Type of transaction read/Write */
  626. #define IFC_GPCM_ERATTR0_ERTYPE_READ 0x00000001
  627. /*
  628. * GPCM Transfer Error Attribute Register-2 (GPCM_ERATTR2)
  629. */
  630. /* On which beat of address/data parity error is observed */
  631. #define IFC_GPCM_ERATTR2_PERR_BEAT 0x00000C00
  632. /* Parity Error on byte */
  633. #define IFC_GPCM_ERATTR2_PERR_BYTE 0x000000F0
  634. /* Parity Error reported in addr or data phase */
  635. #define IFC_GPCM_ERATTR2_PERR_DATA_PHASE 0x00000001
  636. /*
  637. * GPCM Status Register (GPCM_STAT)
  638. */
  639. #define IFC_GPCM_STAT_BSY 0x80000000 /* GPCM is busy */
  640. /*
  641. * IFC Controller NAND Machine registers
  642. */
  643. struct fsl_ifc_nand {
  644. __be32 ncfgr;
  645. u32 res1[0x4];
  646. __be32 nand_fcr0;
  647. __be32 nand_fcr1;
  648. u32 res2[0x8];
  649. __be32 row0;
  650. u32 res3;
  651. __be32 col0;
  652. u32 res4;
  653. __be32 row1;
  654. u32 res5;
  655. __be32 col1;
  656. u32 res6;
  657. __be32 row2;
  658. u32 res7;
  659. __be32 col2;
  660. u32 res8;
  661. __be32 row3;
  662. u32 res9;
  663. __be32 col3;
  664. u32 res10[0x24];
  665. __be32 nand_fbcr;
  666. u32 res11;
  667. __be32 nand_fir0;
  668. __be32 nand_fir1;
  669. __be32 nand_fir2;
  670. u32 res12[0x10];
  671. __be32 nand_csel;
  672. u32 res13;
  673. __be32 nandseq_strt;
  674. u32 res14;
  675. __be32 nand_evter_stat;
  676. u32 res15;
  677. __be32 pgrdcmpl_evt_stat;
  678. u32 res16[0x2];
  679. __be32 nand_evter_en;
  680. u32 res17[0x2];
  681. __be32 nand_evter_intr_en;
  682. __be32 nand_vol_addr_stat;
  683. u32 res18;
  684. __be32 nand_erattr0;
  685. __be32 nand_erattr1;
  686. u32 res19[0x10];
  687. __be32 nand_fsr;
  688. u32 res20;
  689. __be32 nand_eccstat[8];
  690. u32 res21[0x1c];
  691. __be32 nanndcr;
  692. u32 res22[0x2];
  693. __be32 nand_autoboot_trgr;
  694. u32 res23;
  695. __be32 nand_mdr;
  696. u32 res24[0x1C];
  697. __be32 nand_dll_lowcfg0;
  698. __be32 nand_dll_lowcfg1;
  699. u32 res25;
  700. __be32 nand_dll_lowstat;
  701. u32 res26[0x3c];
  702. };
  703. /*
  704. * IFC controller NOR Machine registers
  705. */
  706. struct fsl_ifc_nor {
  707. __be32 nor_evter_stat;
  708. u32 res1[0x2];
  709. __be32 nor_evter_en;
  710. u32 res2[0x2];
  711. __be32 nor_evter_intr_en;
  712. u32 res3[0x2];
  713. __be32 nor_erattr0;
  714. __be32 nor_erattr1;
  715. __be32 nor_erattr2;
  716. u32 res4[0x4];
  717. __be32 norcr;
  718. u32 res5[0xEF];
  719. };
  720. /*
  721. * IFC controller GPCM Machine registers
  722. */
  723. struct fsl_ifc_gpcm {
  724. __be32 gpcm_evter_stat;
  725. u32 res1[0x2];
  726. __be32 gpcm_evter_en;
  727. u32 res2[0x2];
  728. __be32 gpcm_evter_intr_en;
  729. u32 res3[0x2];
  730. __be32 gpcm_erattr0;
  731. __be32 gpcm_erattr1;
  732. __be32 gpcm_erattr2;
  733. __be32 gpcm_stat;
  734. };
  735. /*
  736. * IFC Controller Registers
  737. */
  738. struct fsl_ifc_global {
  739. __be32 ifc_rev;
  740. u32 res1[0x2];
  741. struct {
  742. __be32 cspr_ext;
  743. __be32 cspr;
  744. u32 res2;
  745. } cspr_cs[FSL_IFC_BANK_COUNT];
  746. u32 res3[0xd];
  747. struct {
  748. __be32 amask;
  749. u32 res4[0x2];
  750. } amask_cs[FSL_IFC_BANK_COUNT];
  751. u32 res5[0xc];
  752. struct {
  753. __be32 csor;
  754. __be32 csor_ext;
  755. u32 res6;
  756. } csor_cs[FSL_IFC_BANK_COUNT];
  757. u32 res7[0xc];
  758. struct {
  759. __be32 ftim[4];
  760. u32 res8[0x8];
  761. } ftim_cs[FSL_IFC_BANK_COUNT];
  762. u32 res9[0x30];
  763. __be32 rb_stat;
  764. __be32 rb_map;
  765. __be32 wb_map;
  766. __be32 ifc_gcr;
  767. u32 res10[0x2];
  768. __be32 cm_evter_stat;
  769. u32 res11[0x2];
  770. __be32 cm_evter_en;
  771. u32 res12[0x2];
  772. __be32 cm_evter_intr_en;
  773. u32 res13[0x2];
  774. __be32 cm_erattr0;
  775. __be32 cm_erattr1;
  776. u32 res14[0x2];
  777. __be32 ifc_ccr;
  778. __be32 ifc_csr;
  779. __be32 ddr_ccr_low;
  780. };
  781. struct fsl_ifc_runtime {
  782. struct fsl_ifc_nand ifc_nand;
  783. struct fsl_ifc_nor ifc_nor;
  784. struct fsl_ifc_gpcm ifc_gpcm;
  785. };
  786. extern unsigned int convert_ifc_address(phys_addr_t addr_base);
  787. extern int fsl_ifc_find(phys_addr_t addr_base);
  788. /* overview of the fsl ifc controller */
  789. struct fsl_ifc_ctrl {
  790. /* device info */
  791. struct device *dev;
  792. struct fsl_ifc_global __iomem *gregs;
  793. struct fsl_ifc_runtime __iomem *rregs;
  794. int irq;
  795. int nand_irq;
  796. spinlock_t lock;
  797. void *nand;
  798. int version;
  799. int banks;
  800. u32 nand_stat;
  801. wait_queue_head_t nand_wait;
  802. bool little_endian;
  803. };
  804. extern struct fsl_ifc_ctrl *fsl_ifc_ctrl_dev;
  805. static inline u32 ifc_in32(void __iomem *addr)
  806. {
  807. u32 val;
  808. if (fsl_ifc_ctrl_dev->little_endian)
  809. val = ioread32(addr);
  810. else
  811. val = ioread32be(addr);
  812. return val;
  813. }
  814. static inline u16 ifc_in16(void __iomem *addr)
  815. {
  816. u16 val;
  817. if (fsl_ifc_ctrl_dev->little_endian)
  818. val = ioread16(addr);
  819. else
  820. val = ioread16be(addr);
  821. return val;
  822. }
  823. static inline u8 ifc_in8(void __iomem *addr)
  824. {
  825. return ioread8(addr);
  826. }
  827. static inline void ifc_out32(u32 val, void __iomem *addr)
  828. {
  829. if (fsl_ifc_ctrl_dev->little_endian)
  830. iowrite32(val, addr);
  831. else
  832. iowrite32be(val, addr);
  833. }
  834. static inline void ifc_out16(u16 val, void __iomem *addr)
  835. {
  836. if (fsl_ifc_ctrl_dev->little_endian)
  837. iowrite16(val, addr);
  838. else
  839. iowrite16be(val, addr);
  840. }
  841. static inline void ifc_out8(u8 val, void __iomem *addr)
  842. {
  843. iowrite8(val, addr);
  844. }
  845. #endif /* __ASM_FSL_IFC_H */