fsl_ifc.h 25 KB

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