fsl_ifc.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918
  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. /* Addressing Mode-ROW0+n/COL0 */
  258. #define IFC_NAND_NCFGR_ADDR_MODE_RC0 0x00000000
  259. /* Addressing Mode-ROW0+n/COL0+n */
  260. #define IFC_NAND_NCFGR_ADDR_MODE_RC1 0x00400000
  261. /* Number of loop iterations of FIR sequences for multi page operations */
  262. #define IFC_NAND_NCFGR_NUM_LOOP_MASK 0x0000F000
  263. #define IFC_NAND_NCFGR_NUM_LOOP_SHIFT 12
  264. #define IFC_NAND_NCFGR_NUM_LOOP(n) ((n) << IFC_NAND_NCFGR_NUM_LOOP_SHIFT)
  265. /* Number of wait cycles */
  266. #define IFC_NAND_NCFGR_NUM_WAIT_MASK 0x000000FF
  267. #define IFC_NAND_NCFGR_NUM_WAIT_SHIFT 0
  268. /*
  269. * NAND Flash Command Registers (NAND_FCR0/NAND_FCR1)
  270. */
  271. /* General purpose FCM flash command bytes CMD0-CMD7 */
  272. #define IFC_NAND_FCR0_CMD0 0xFF000000
  273. #define IFC_NAND_FCR0_CMD0_SHIFT 24
  274. #define IFC_NAND_FCR0_CMD1 0x00FF0000
  275. #define IFC_NAND_FCR0_CMD1_SHIFT 16
  276. #define IFC_NAND_FCR0_CMD2 0x0000FF00
  277. #define IFC_NAND_FCR0_CMD2_SHIFT 8
  278. #define IFC_NAND_FCR0_CMD3 0x000000FF
  279. #define IFC_NAND_FCR0_CMD3_SHIFT 0
  280. #define IFC_NAND_FCR1_CMD4 0xFF000000
  281. #define IFC_NAND_FCR1_CMD4_SHIFT 24
  282. #define IFC_NAND_FCR1_CMD5 0x00FF0000
  283. #define IFC_NAND_FCR1_CMD5_SHIFT 16
  284. #define IFC_NAND_FCR1_CMD6 0x0000FF00
  285. #define IFC_NAND_FCR1_CMD6_SHIFT 8
  286. #define IFC_NAND_FCR1_CMD7 0x000000FF
  287. #define IFC_NAND_FCR1_CMD7_SHIFT 0
  288. /*
  289. * Flash ROW and COL Address Register (ROWn, COLn)
  290. */
  291. /* Main/spare region locator */
  292. #define IFC_NAND_COL_MS 0x80000000
  293. /* Column Address */
  294. #define IFC_NAND_COL_CA_MASK 0x00000FFF
  295. /*
  296. * NAND Flash Byte Count Register (NAND_BC)
  297. */
  298. /* Byte Count for read/Write */
  299. #define IFC_NAND_BC 0x000001FF
  300. /*
  301. * NAND Flash Instruction Registers (NAND_FIR0/NAND_FIR1/NAND_FIR2)
  302. */
  303. /* NAND Machine specific opcodes OP0-OP14*/
  304. #define IFC_NAND_FIR0_OP0 0xFC000000
  305. #define IFC_NAND_FIR0_OP0_SHIFT 26
  306. #define IFC_NAND_FIR0_OP1 0x03F00000
  307. #define IFC_NAND_FIR0_OP1_SHIFT 20
  308. #define IFC_NAND_FIR0_OP2 0x000FC000
  309. #define IFC_NAND_FIR0_OP2_SHIFT 14
  310. #define IFC_NAND_FIR0_OP3 0x00003F00
  311. #define IFC_NAND_FIR0_OP3_SHIFT 8
  312. #define IFC_NAND_FIR0_OP4 0x000000FC
  313. #define IFC_NAND_FIR0_OP4_SHIFT 2
  314. #define IFC_NAND_FIR1_OP5 0xFC000000
  315. #define IFC_NAND_FIR1_OP5_SHIFT 26
  316. #define IFC_NAND_FIR1_OP6 0x03F00000
  317. #define IFC_NAND_FIR1_OP6_SHIFT 20
  318. #define IFC_NAND_FIR1_OP7 0x000FC000
  319. #define IFC_NAND_FIR1_OP7_SHIFT 14
  320. #define IFC_NAND_FIR1_OP8 0x00003F00
  321. #define IFC_NAND_FIR1_OP8_SHIFT 8
  322. #define IFC_NAND_FIR1_OP9 0x000000FC
  323. #define IFC_NAND_FIR1_OP9_SHIFT 2
  324. #define IFC_NAND_FIR2_OP10 0xFC000000
  325. #define IFC_NAND_FIR2_OP10_SHIFT 26
  326. #define IFC_NAND_FIR2_OP11 0x03F00000
  327. #define IFC_NAND_FIR2_OP11_SHIFT 20
  328. #define IFC_NAND_FIR2_OP12 0x000FC000
  329. #define IFC_NAND_FIR2_OP12_SHIFT 14
  330. #define IFC_NAND_FIR2_OP13 0x00003F00
  331. #define IFC_NAND_FIR2_OP13_SHIFT 8
  332. #define IFC_NAND_FIR2_OP14 0x000000FC
  333. #define IFC_NAND_FIR2_OP14_SHIFT 2
  334. /*
  335. * Instruction opcodes to be programmed
  336. * in FIR registers- 6bits
  337. */
  338. enum ifc_nand_fir_opcodes {
  339. IFC_FIR_OP_NOP,
  340. IFC_FIR_OP_CA0,
  341. IFC_FIR_OP_CA1,
  342. IFC_FIR_OP_CA2,
  343. IFC_FIR_OP_CA3,
  344. IFC_FIR_OP_RA0,
  345. IFC_FIR_OP_RA1,
  346. IFC_FIR_OP_RA2,
  347. IFC_FIR_OP_RA3,
  348. IFC_FIR_OP_CMD0,
  349. IFC_FIR_OP_CMD1,
  350. IFC_FIR_OP_CMD2,
  351. IFC_FIR_OP_CMD3,
  352. IFC_FIR_OP_CMD4,
  353. IFC_FIR_OP_CMD5,
  354. IFC_FIR_OP_CMD6,
  355. IFC_FIR_OP_CMD7,
  356. IFC_FIR_OP_CW0,
  357. IFC_FIR_OP_CW1,
  358. IFC_FIR_OP_CW2,
  359. IFC_FIR_OP_CW3,
  360. IFC_FIR_OP_CW4,
  361. IFC_FIR_OP_CW5,
  362. IFC_FIR_OP_CW6,
  363. IFC_FIR_OP_CW7,
  364. IFC_FIR_OP_WBCD,
  365. IFC_FIR_OP_RBCD,
  366. IFC_FIR_OP_BTRD,
  367. IFC_FIR_OP_RDSTAT,
  368. IFC_FIR_OP_NWAIT,
  369. IFC_FIR_OP_WFR,
  370. IFC_FIR_OP_SBRD,
  371. IFC_FIR_OP_UA,
  372. IFC_FIR_OP_RB,
  373. };
  374. /*
  375. * NAND Chip Select Register (NAND_CSEL)
  376. */
  377. #define IFC_NAND_CSEL 0x0C000000
  378. #define IFC_NAND_CSEL_SHIFT 26
  379. #define IFC_NAND_CSEL_CS0 0x00000000
  380. #define IFC_NAND_CSEL_CS1 0x04000000
  381. #define IFC_NAND_CSEL_CS2 0x08000000
  382. #define IFC_NAND_CSEL_CS3 0x0C000000
  383. /*
  384. * NAND Operation Sequence Start (NANDSEQ_STRT)
  385. */
  386. /* NAND Flash Operation Start */
  387. #define IFC_NAND_SEQ_STRT_FIR_STRT 0x80000000
  388. /* Automatic Erase */
  389. #define IFC_NAND_SEQ_STRT_AUTO_ERS 0x00800000
  390. /* Automatic Program */
  391. #define IFC_NAND_SEQ_STRT_AUTO_PGM 0x00100000
  392. /* Automatic Copyback */
  393. #define IFC_NAND_SEQ_STRT_AUTO_CPB 0x00020000
  394. /* Automatic Read Operation */
  395. #define IFC_NAND_SEQ_STRT_AUTO_RD 0x00004000
  396. /* Automatic Status Read */
  397. #define IFC_NAND_SEQ_STRT_AUTO_STAT_RD 0x00000800
  398. /*
  399. * NAND Event and Error Status Register (NAND_EVTER_STAT)
  400. */
  401. /* Operation Complete */
  402. #define IFC_NAND_EVTER_STAT_OPC 0x80000000
  403. /* Flash Timeout Error */
  404. #define IFC_NAND_EVTER_STAT_FTOER 0x08000000
  405. /* Write Protect Error */
  406. #define IFC_NAND_EVTER_STAT_WPER 0x04000000
  407. /* ECC Error */
  408. #define IFC_NAND_EVTER_STAT_ECCER 0x02000000
  409. /* RCW Load Done */
  410. #define IFC_NAND_EVTER_STAT_RCW_DN 0x00008000
  411. /* Boot Loadr Done */
  412. #define IFC_NAND_EVTER_STAT_BOOT_DN 0x00004000
  413. /* Bad Block Indicator search select */
  414. #define IFC_NAND_EVTER_STAT_BBI_SRCH_SE 0x00000800
  415. /*
  416. * NAND Flash Page Read Completion Event Status Register
  417. * (PGRDCMPL_EVT_STAT)
  418. */
  419. #define PGRDCMPL_EVT_STAT_MASK 0xFFFF0000
  420. /* Small Page 0-15 Done */
  421. #define PGRDCMPL_EVT_STAT_SECTION_SP(n) (1 << (31 - (n)))
  422. /* Large Page(2K) 0-3 Done */
  423. #define PGRDCMPL_EVT_STAT_LP_2K(n) (0xF << (28 - (n)*4))
  424. /* Large Page(4K) 0-1 Done */
  425. #define PGRDCMPL_EVT_STAT_LP_4K(n) (0xFF << (24 - (n)*8))
  426. /*
  427. * NAND Event and Error Enable Register (NAND_EVTER_EN)
  428. */
  429. /* Operation complete event enable */
  430. #define IFC_NAND_EVTER_EN_OPC_EN 0x80000000
  431. /* Page read complete event enable */
  432. #define IFC_NAND_EVTER_EN_PGRDCMPL_EN 0x20000000
  433. /* Flash Timeout error enable */
  434. #define IFC_NAND_EVTER_EN_FTOER_EN 0x08000000
  435. /* Write Protect error enable */
  436. #define IFC_NAND_EVTER_EN_WPER_EN 0x04000000
  437. /* ECC error logging enable */
  438. #define IFC_NAND_EVTER_EN_ECCER_EN 0x02000000
  439. /*
  440. * NAND Event and Error Interrupt Enable Register (NAND_EVTER_INTR_EN)
  441. */
  442. /* Enable interrupt for operation complete */
  443. #define IFC_NAND_EVTER_INTR_OPCIR_EN 0x80000000
  444. /* Enable interrupt for Page read complete */
  445. #define IFC_NAND_EVTER_INTR_PGRDCMPLIR_EN 0x20000000
  446. /* Enable interrupt for Flash timeout error */
  447. #define IFC_NAND_EVTER_INTR_FTOERIR_EN 0x08000000
  448. /* Enable interrupt for Write protect error */
  449. #define IFC_NAND_EVTER_INTR_WPERIR_EN 0x04000000
  450. /* Enable interrupt for ECC error*/
  451. #define IFC_NAND_EVTER_INTR_ECCERIR_EN 0x02000000
  452. /*
  453. * NAND Transfer Error Attribute Register-0 (NAND_ERATTR0)
  454. */
  455. #define IFC_NAND_ERATTR0_MASK 0x0C080000
  456. /* Error on CS0-3 for NAND */
  457. #define IFC_NAND_ERATTR0_ERCS_CS0 0x00000000
  458. #define IFC_NAND_ERATTR0_ERCS_CS1 0x04000000
  459. #define IFC_NAND_ERATTR0_ERCS_CS2 0x08000000
  460. #define IFC_NAND_ERATTR0_ERCS_CS3 0x0C000000
  461. /* Transaction type of error Read/Write */
  462. #define IFC_NAND_ERATTR0_ERTTYPE_READ 0x00080000
  463. /*
  464. * NAND Flash Status Register (NAND_FSR)
  465. */
  466. /* First byte of data read from read status op */
  467. #define IFC_NAND_NFSR_RS0 0xFF000000
  468. /* Second byte of data read from read status op */
  469. #define IFC_NAND_NFSR_RS1 0x00FF0000
  470. /*
  471. * ECC Error Status Registers (ECCSTAT0-ECCSTAT3)
  472. */
  473. /* Number of ECC errors on sector n (n = 0-15) */
  474. #define IFC_NAND_ECCSTAT0_ERRCNT_SECTOR0_MASK 0x0F000000
  475. #define IFC_NAND_ECCSTAT0_ERRCNT_SECTOR0_SHIFT 24
  476. #define IFC_NAND_ECCSTAT0_ERRCNT_SECTOR1_MASK 0x000F0000
  477. #define IFC_NAND_ECCSTAT0_ERRCNT_SECTOR1_SHIFT 16
  478. #define IFC_NAND_ECCSTAT0_ERRCNT_SECTOR2_MASK 0x00000F00
  479. #define IFC_NAND_ECCSTAT0_ERRCNT_SECTOR2_SHIFT 8
  480. #define IFC_NAND_ECCSTAT0_ERRCNT_SECTOR3_MASK 0x0000000F
  481. #define IFC_NAND_ECCSTAT0_ERRCNT_SECTOR3_SHIFT 0
  482. #define IFC_NAND_ECCSTAT1_ERRCNT_SECTOR4_MASK 0x0F000000
  483. #define IFC_NAND_ECCSTAT1_ERRCNT_SECTOR4_SHIFT 24
  484. #define IFC_NAND_ECCSTAT1_ERRCNT_SECTOR5_MASK 0x000F0000
  485. #define IFC_NAND_ECCSTAT1_ERRCNT_SECTOR5_SHIFT 16
  486. #define IFC_NAND_ECCSTAT1_ERRCNT_SECTOR6_MASK 0x00000F00
  487. #define IFC_NAND_ECCSTAT1_ERRCNT_SECTOR6_SHIFT 8
  488. #define IFC_NAND_ECCSTAT1_ERRCNT_SECTOR7_MASK 0x0000000F
  489. #define IFC_NAND_ECCSTAT1_ERRCNT_SECTOR7_SHIFT 0
  490. #define IFC_NAND_ECCSTAT2_ERRCNT_SECTOR8_MASK 0x0F000000
  491. #define IFC_NAND_ECCSTAT2_ERRCNT_SECTOR8_SHIFT 24
  492. #define IFC_NAND_ECCSTAT2_ERRCNT_SECTOR9_MASK 0x000F0000
  493. #define IFC_NAND_ECCSTAT2_ERRCNT_SECTOR9_SHIFT 16
  494. #define IFC_NAND_ECCSTAT2_ERRCNT_SECTOR10_MASK 0x00000F00
  495. #define IFC_NAND_ECCSTAT2_ERRCNT_SECTOR10_SHIFT 8
  496. #define IFC_NAND_ECCSTAT2_ERRCNT_SECTOR11_MASK 0x0000000F
  497. #define IFC_NAND_ECCSTAT2_ERRCNT_SECTOR11_SHIFT 0
  498. #define IFC_NAND_ECCSTAT3_ERRCNT_SECTOR12_MASK 0x0F000000
  499. #define IFC_NAND_ECCSTAT3_ERRCNT_SECTOR12_SHIFT 24
  500. #define IFC_NAND_ECCSTAT3_ERRCNT_SECTOR13_MASK 0x000F0000
  501. #define IFC_NAND_ECCSTAT3_ERRCNT_SECTOR13_SHIFT 16
  502. #define IFC_NAND_ECCSTAT3_ERRCNT_SECTOR14_MASK 0x00000F00
  503. #define IFC_NAND_ECCSTAT3_ERRCNT_SECTOR14_SHIFT 8
  504. #define IFC_NAND_ECCSTAT3_ERRCNT_SECTOR15_MASK 0x0000000F
  505. #define IFC_NAND_ECCSTAT3_ERRCNT_SECTOR15_SHIFT 0
  506. /*
  507. * NAND Control Register (NANDCR)
  508. */
  509. #define IFC_NAND_NCR_FTOCNT_MASK 0x1E000000
  510. #define IFC_NAND_NCR_FTOCNT_SHIFT 25
  511. #define IFC_NAND_NCR_FTOCNT(n) ((_ilog2(n) - 8) << IFC_NAND_NCR_FTOCNT_SHIFT)
  512. /*
  513. * NAND_AUTOBOOT_TRGR
  514. */
  515. /* Trigger RCW load */
  516. #define IFC_NAND_AUTOBOOT_TRGR_RCW_LD 0x80000000
  517. /* Trigget Auto Boot */
  518. #define IFC_NAND_AUTOBOOT_TRGR_BOOT_LD 0x20000000
  519. /*
  520. * NAND_MDR
  521. */
  522. /* 1st read data byte when opcode SBRD */
  523. #define IFC_NAND_MDR_RDATA0 0xFF000000
  524. /* 2nd read data byte when opcode SBRD */
  525. #define IFC_NAND_MDR_RDATA1 0x00FF0000
  526. /*
  527. * NOR Machine Specific Registers
  528. */
  529. /*
  530. * NOR Event and Error Status Register (NOR_EVTER_STAT)
  531. */
  532. /* NOR Command Sequence Operation Complete */
  533. #define IFC_NOR_EVTER_STAT_OPC_NOR 0x80000000
  534. /* Write Protect Error */
  535. #define IFC_NOR_EVTER_STAT_WPER 0x04000000
  536. /* Command Sequence Timeout Error */
  537. #define IFC_NOR_EVTER_STAT_STOER 0x01000000
  538. /*
  539. * NOR Event and Error Enable Register (NOR_EVTER_EN)
  540. */
  541. /* NOR Command Seq complete event enable */
  542. #define IFC_NOR_EVTER_EN_OPCEN_NOR 0x80000000
  543. /* Write Protect Error Checking Enable */
  544. #define IFC_NOR_EVTER_EN_WPEREN 0x04000000
  545. /* Timeout Error Enable */
  546. #define IFC_NOR_EVTER_EN_STOEREN 0x01000000
  547. /*
  548. * NOR Event and Error Interrupt Enable Register (NOR_EVTER_INTR_EN)
  549. */
  550. /* Enable interrupt for OPC complete */
  551. #define IFC_NOR_EVTER_INTR_OPCEN_NOR 0x80000000
  552. /* Enable interrupt for write protect error */
  553. #define IFC_NOR_EVTER_INTR_WPEREN 0x04000000
  554. /* Enable interrupt for timeout error */
  555. #define IFC_NOR_EVTER_INTR_STOEREN 0x01000000
  556. /*
  557. * NOR Transfer Error Attribute Register-0 (NOR_ERATTR0)
  558. */
  559. /* Source ID for error transaction */
  560. #define IFC_NOR_ERATTR0_ERSRCID 0xFF000000
  561. /* AXI ID for error transation */
  562. #define IFC_NOR_ERATTR0_ERAID 0x000FF000
  563. /* Chip select corresponds to NOR error */
  564. #define IFC_NOR_ERATTR0_ERCS_CS0 0x00000000
  565. #define IFC_NOR_ERATTR0_ERCS_CS1 0x00000010
  566. #define IFC_NOR_ERATTR0_ERCS_CS2 0x00000020
  567. #define IFC_NOR_ERATTR0_ERCS_CS3 0x00000030
  568. /* Type of transaction read/write */
  569. #define IFC_NOR_ERATTR0_ERTYPE_READ 0x00000001
  570. /*
  571. * NOR Transfer Error Attribute Register-2 (NOR_ERATTR2)
  572. */
  573. #define IFC_NOR_ERATTR2_ER_NUM_PHASE_EXP 0x000F0000
  574. #define IFC_NOR_ERATTR2_ER_NUM_PHASE_PER 0x00000F00
  575. /*
  576. * NOR Control Register (NORCR)
  577. */
  578. #define IFC_NORCR_MASK 0x0F0F0000
  579. /* No. of Address/Data Phase */
  580. #define IFC_NORCR_NUM_PHASE_MASK 0x0F000000
  581. #define IFC_NORCR_NUM_PHASE_SHIFT 24
  582. #define IFC_NORCR_NUM_PHASE(n) ((n-1) << IFC_NORCR_NUM_PHASE_SHIFT)
  583. /* Sequence Timeout Count */
  584. #define IFC_NORCR_STOCNT_MASK 0x000F0000
  585. #define IFC_NORCR_STOCNT_SHIFT 16
  586. #define IFC_NORCR_STOCNT(n) ((__ilog2(n) - 8) << IFC_NORCR_STOCNT_SHIFT)
  587. /*
  588. * GPCM Machine specific registers
  589. */
  590. /*
  591. * GPCM Event and Error Status Register (GPCM_EVTER_STAT)
  592. */
  593. /* Timeout error */
  594. #define IFC_GPCM_EVTER_STAT_TOER 0x04000000
  595. /* Parity error */
  596. #define IFC_GPCM_EVTER_STAT_PER 0x01000000
  597. /*
  598. * GPCM Event and Error Enable Register (GPCM_EVTER_EN)
  599. */
  600. /* Timeout error enable */
  601. #define IFC_GPCM_EVTER_EN_TOER_EN 0x04000000
  602. /* Parity error enable */
  603. #define IFC_GPCM_EVTER_EN_PER_EN 0x01000000
  604. /*
  605. * GPCM Event and Error Interrupt Enable Register (GPCM_EVTER_INTR_EN)
  606. */
  607. /* Enable Interrupt for timeout error */
  608. #define IFC_GPCM_EEIER_TOERIR_EN 0x04000000
  609. /* Enable Interrupt for Parity error */
  610. #define IFC_GPCM_EEIER_PERIR_EN 0x01000000
  611. /*
  612. * GPCM Transfer Error Attribute Register-0 (GPCM_ERATTR0)
  613. */
  614. /* Source ID for error transaction */
  615. #define IFC_GPCM_ERATTR0_ERSRCID 0xFF000000
  616. /* AXI ID for error transaction */
  617. #define IFC_GPCM_ERATTR0_ERAID 0x000FF000
  618. /* Chip select corresponds to GPCM error */
  619. #define IFC_GPCM_ERATTR0_ERCS_CS0 0x00000000
  620. #define IFC_GPCM_ERATTR0_ERCS_CS1 0x00000040
  621. #define IFC_GPCM_ERATTR0_ERCS_CS2 0x00000080
  622. #define IFC_GPCM_ERATTR0_ERCS_CS3 0x000000C0
  623. /* Type of transaction read/Write */
  624. #define IFC_GPCM_ERATTR0_ERTYPE_READ 0x00000001
  625. /*
  626. * GPCM Transfer Error Attribute Register-2 (GPCM_ERATTR2)
  627. */
  628. /* On which beat of address/data parity error is observed */
  629. #define IFC_GPCM_ERATTR2_PERR_BEAT 0x00000C00
  630. /* Parity Error on byte */
  631. #define IFC_GPCM_ERATTR2_PERR_BYTE 0x000000F0
  632. /* Parity Error reported in addr or data phase */
  633. #define IFC_GPCM_ERATTR2_PERR_DATA_PHASE 0x00000001
  634. /*
  635. * GPCM Status Register (GPCM_STAT)
  636. */
  637. #define IFC_GPCM_STAT_BSY 0x80000000 /* GPCM is busy */
  638. /*
  639. * IFC Controller NAND Machine registers
  640. */
  641. struct fsl_ifc_nand {
  642. __be32 ncfgr;
  643. u32 res1[0x4];
  644. __be32 nand_fcr0;
  645. __be32 nand_fcr1;
  646. u32 res2[0x8];
  647. __be32 row0;
  648. u32 res3;
  649. __be32 col0;
  650. u32 res4;
  651. __be32 row1;
  652. u32 res5;
  653. __be32 col1;
  654. u32 res6;
  655. __be32 row2;
  656. u32 res7;
  657. __be32 col2;
  658. u32 res8;
  659. __be32 row3;
  660. u32 res9;
  661. __be32 col3;
  662. u32 res10[0x24];
  663. __be32 nand_fbcr;
  664. u32 res11;
  665. __be32 nand_fir0;
  666. __be32 nand_fir1;
  667. __be32 nand_fir2;
  668. u32 res12[0x10];
  669. __be32 nand_csel;
  670. u32 res13;
  671. __be32 nandseq_strt;
  672. u32 res14;
  673. __be32 nand_evter_stat;
  674. u32 res15;
  675. __be32 pgrdcmpl_evt_stat;
  676. u32 res16[0x2];
  677. __be32 nand_evter_en;
  678. u32 res17[0x2];
  679. __be32 nand_evter_intr_en;
  680. __be32 nand_vol_addr_stat;
  681. u32 res18;
  682. __be32 nand_erattr0;
  683. __be32 nand_erattr1;
  684. u32 res19[0x10];
  685. __be32 nand_fsr;
  686. u32 res20;
  687. /* The V1 nand_eccstat is actually 4 words that overlaps the
  688. * V2 nand_eccstat.
  689. */
  690. __be32 v1_nand_eccstat[2];
  691. __be32 v2_nand_eccstat[6];
  692. u32 res21[0x1c];
  693. __be32 nanndcr;
  694. u32 res22[0x2];
  695. __be32 nand_autoboot_trgr;
  696. u32 res23;
  697. __be32 nand_mdr;
  698. u32 res24[0x1C];
  699. __be32 nand_dll_lowcfg0;
  700. __be32 nand_dll_lowcfg1;
  701. u32 res25;
  702. __be32 nand_dll_lowstat;
  703. u32 res26[0x3c];
  704. };
  705. /*
  706. * IFC controller NOR Machine registers
  707. */
  708. struct fsl_ifc_nor {
  709. __be32 nor_evter_stat;
  710. u32 res1[0x2];
  711. __be32 nor_evter_en;
  712. u32 res2[0x2];
  713. __be32 nor_evter_intr_en;
  714. u32 res3[0x2];
  715. __be32 nor_erattr0;
  716. __be32 nor_erattr1;
  717. __be32 nor_erattr2;
  718. u32 res4[0x4];
  719. __be32 norcr;
  720. u32 res5[0xEF];
  721. };
  722. /*
  723. * IFC controller GPCM Machine registers
  724. */
  725. struct fsl_ifc_gpcm {
  726. __be32 gpcm_evter_stat;
  727. u32 res1[0x2];
  728. __be32 gpcm_evter_en;
  729. u32 res2[0x2];
  730. __be32 gpcm_evter_intr_en;
  731. u32 res3[0x2];
  732. __be32 gpcm_erattr0;
  733. __be32 gpcm_erattr1;
  734. __be32 gpcm_erattr2;
  735. __be32 gpcm_stat;
  736. };
  737. /*
  738. * IFC Controller Registers
  739. */
  740. struct fsl_ifc_global {
  741. __be32 ifc_rev;
  742. u32 res1[0x2];
  743. struct {
  744. __be32 cspr_ext;
  745. __be32 cspr;
  746. u32 res2;
  747. } cspr_cs[FSL_IFC_BANK_COUNT];
  748. u32 res3[0xd];
  749. struct {
  750. __be32 amask;
  751. u32 res4[0x2];
  752. } amask_cs[FSL_IFC_BANK_COUNT];
  753. u32 res5[0xc];
  754. struct {
  755. __be32 csor;
  756. __be32 csor_ext;
  757. u32 res6;
  758. } csor_cs[FSL_IFC_BANK_COUNT];
  759. u32 res7[0xc];
  760. struct {
  761. __be32 ftim[4];
  762. u32 res8[0x8];
  763. } ftim_cs[FSL_IFC_BANK_COUNT];
  764. u32 res9[0x30];
  765. __be32 rb_stat;
  766. __be32 rb_map;
  767. __be32 wb_map;
  768. __be32 ifc_gcr;
  769. u32 res10[0x2];
  770. __be32 cm_evter_stat;
  771. u32 res11[0x2];
  772. __be32 cm_evter_en;
  773. u32 res12[0x2];
  774. __be32 cm_evter_intr_en;
  775. u32 res13[0x2];
  776. __be32 cm_erattr0;
  777. __be32 cm_erattr1;
  778. u32 res14[0x2];
  779. __be32 ifc_ccr;
  780. __be32 ifc_csr;
  781. __be32 ddr_ccr_low;
  782. };
  783. struct fsl_ifc_runtime {
  784. struct fsl_ifc_nand ifc_nand;
  785. struct fsl_ifc_nor ifc_nor;
  786. struct fsl_ifc_gpcm ifc_gpcm;
  787. };
  788. extern unsigned int convert_ifc_address(phys_addr_t addr_base);
  789. extern int fsl_ifc_find(phys_addr_t addr_base);
  790. /* overview of the fsl ifc controller */
  791. struct fsl_ifc_ctrl {
  792. /* device info */
  793. struct device *dev;
  794. struct fsl_ifc_global __iomem *gregs;
  795. struct fsl_ifc_runtime __iomem *rregs;
  796. int irq;
  797. int nand_irq;
  798. spinlock_t lock;
  799. void *nand;
  800. int version;
  801. int banks;
  802. u32 nand_stat;
  803. wait_queue_head_t nand_wait;
  804. bool little_endian;
  805. };
  806. extern struct fsl_ifc_ctrl *fsl_ifc_ctrl_dev;
  807. static inline u32 ifc_in32(void __iomem *addr)
  808. {
  809. u32 val;
  810. if (fsl_ifc_ctrl_dev->little_endian)
  811. val = ioread32(addr);
  812. else
  813. val = ioread32be(addr);
  814. return val;
  815. }
  816. static inline u16 ifc_in16(void __iomem *addr)
  817. {
  818. u16 val;
  819. if (fsl_ifc_ctrl_dev->little_endian)
  820. val = ioread16(addr);
  821. else
  822. val = ioread16be(addr);
  823. return val;
  824. }
  825. static inline u8 ifc_in8(void __iomem *addr)
  826. {
  827. return ioread8(addr);
  828. }
  829. static inline void ifc_out32(u32 val, void __iomem *addr)
  830. {
  831. if (fsl_ifc_ctrl_dev->little_endian)
  832. iowrite32(val, addr);
  833. else
  834. iowrite32be(val, addr);
  835. }
  836. static inline void ifc_out16(u16 val, void __iomem *addr)
  837. {
  838. if (fsl_ifc_ctrl_dev->little_endian)
  839. iowrite16(val, addr);
  840. else
  841. iowrite16be(val, addr);
  842. }
  843. static inline void ifc_out8(u8 val, void __iomem *addr)
  844. {
  845. iowrite8(val, addr);
  846. }
  847. #endif /* __ASM_FSL_IFC_H */