fsl_lbc.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /* Freescale Local Bus Controller
  3. *
  4. * Copyright © 2006-2007, 2010 Freescale Semiconductor
  5. *
  6. * Authors: Nick Spence <[email protected]>,
  7. * Scott Wood <[email protected]>
  8. * Jack Lan <[email protected]>
  9. */
  10. #ifndef __ASM_FSL_LBC_H
  11. #define __ASM_FSL_LBC_H
  12. #include <linux/compiler.h>
  13. #include <linux/types.h>
  14. #include <linux/io.h>
  15. #include <linux/device.h>
  16. #include <linux/spinlock.h>
  17. struct fsl_lbc_bank {
  18. __be32 br; /**< Base Register */
  19. #define BR_BA 0xFFFF8000
  20. #define BR_BA_SHIFT 15
  21. #define BR_PS 0x00001800
  22. #define BR_PS_SHIFT 11
  23. #define BR_PS_8 0x00000800 /* Port Size 8 bit */
  24. #define BR_PS_16 0x00001000 /* Port Size 16 bit */
  25. #define BR_PS_32 0x00001800 /* Port Size 32 bit */
  26. #define BR_DECC 0x00000600
  27. #define BR_DECC_SHIFT 9
  28. #define BR_DECC_OFF 0x00000000 /* HW ECC checking and generation off */
  29. #define BR_DECC_CHK 0x00000200 /* HW ECC checking on, generation off */
  30. #define BR_DECC_CHK_GEN 0x00000400 /* HW ECC checking and generation on */
  31. #define BR_WP 0x00000100
  32. #define BR_WP_SHIFT 8
  33. #define BR_MSEL 0x000000E0
  34. #define BR_MSEL_SHIFT 5
  35. #define BR_MS_GPCM 0x00000000 /* GPCM */
  36. #define BR_MS_FCM 0x00000020 /* FCM */
  37. #define BR_MS_SDRAM 0x00000060 /* SDRAM */
  38. #define BR_MS_UPMA 0x00000080 /* UPMA */
  39. #define BR_MS_UPMB 0x000000A0 /* UPMB */
  40. #define BR_MS_UPMC 0x000000C0 /* UPMC */
  41. #define BR_V 0x00000001
  42. #define BR_V_SHIFT 0
  43. #define BR_RES ~(BR_BA|BR_PS|BR_DECC|BR_WP|BR_MSEL|BR_V)
  44. __be32 or; /**< Base Register */
  45. #define OR0 0x5004
  46. #define OR1 0x500C
  47. #define OR2 0x5014
  48. #define OR3 0x501C
  49. #define OR4 0x5024
  50. #define OR5 0x502C
  51. #define OR6 0x5034
  52. #define OR7 0x503C
  53. #define OR_FCM_AM 0xFFFF8000
  54. #define OR_FCM_AM_SHIFT 15
  55. #define OR_FCM_BCTLD 0x00001000
  56. #define OR_FCM_BCTLD_SHIFT 12
  57. #define OR_FCM_PGS 0x00000400
  58. #define OR_FCM_PGS_SHIFT 10
  59. #define OR_FCM_CSCT 0x00000200
  60. #define OR_FCM_CSCT_SHIFT 9
  61. #define OR_FCM_CST 0x00000100
  62. #define OR_FCM_CST_SHIFT 8
  63. #define OR_FCM_CHT 0x00000080
  64. #define OR_FCM_CHT_SHIFT 7
  65. #define OR_FCM_SCY 0x00000070
  66. #define OR_FCM_SCY_SHIFT 4
  67. #define OR_FCM_SCY_1 0x00000010
  68. #define OR_FCM_SCY_2 0x00000020
  69. #define OR_FCM_SCY_3 0x00000030
  70. #define OR_FCM_SCY_4 0x00000040
  71. #define OR_FCM_SCY_5 0x00000050
  72. #define OR_FCM_SCY_6 0x00000060
  73. #define OR_FCM_SCY_7 0x00000070
  74. #define OR_FCM_RST 0x00000008
  75. #define OR_FCM_RST_SHIFT 3
  76. #define OR_FCM_TRLX 0x00000004
  77. #define OR_FCM_TRLX_SHIFT 2
  78. #define OR_FCM_EHTR 0x00000002
  79. #define OR_FCM_EHTR_SHIFT 1
  80. #define OR_GPCM_AM 0xFFFF8000
  81. #define OR_GPCM_AM_SHIFT 15
  82. };
  83. struct fsl_lbc_regs {
  84. struct fsl_lbc_bank bank[12];
  85. u8 res0[0x8];
  86. __be32 mar; /**< UPM Address Register */
  87. u8 res1[0x4];
  88. __be32 mamr; /**< UPMA Mode Register */
  89. #define MxMR_OP_NO (0 << 28) /**< normal operation */
  90. #define MxMR_OP_WA (1 << 28) /**< write array */
  91. #define MxMR_OP_RA (2 << 28) /**< read array */
  92. #define MxMR_OP_RP (3 << 28) /**< run pattern */
  93. #define MxMR_MAD 0x3f /**< machine address */
  94. __be32 mbmr; /**< UPMB Mode Register */
  95. __be32 mcmr; /**< UPMC Mode Register */
  96. u8 res2[0x8];
  97. __be32 mrtpr; /**< Memory Refresh Timer Prescaler Register */
  98. __be32 mdr; /**< UPM Data Register */
  99. u8 res3[0x4];
  100. __be32 lsor; /**< Special Operation Initiation Register */
  101. __be32 lsdmr; /**< SDRAM Mode Register */
  102. u8 res4[0x8];
  103. __be32 lurt; /**< UPM Refresh Timer */
  104. __be32 lsrt; /**< SDRAM Refresh Timer */
  105. u8 res5[0x8];
  106. __be32 ltesr; /**< Transfer Error Status Register */
  107. #define LTESR_BM 0x80000000
  108. #define LTESR_FCT 0x40000000
  109. #define LTESR_PAR 0x20000000
  110. #define LTESR_WP 0x04000000
  111. #define LTESR_ATMW 0x00800000
  112. #define LTESR_ATMR 0x00400000
  113. #define LTESR_CS 0x00080000
  114. #define LTESR_UPM 0x00000002
  115. #define LTESR_CC 0x00000001
  116. #define LTESR_NAND_MASK (LTESR_FCT | LTESR_PAR | LTESR_CC)
  117. #define LTESR_MASK (LTESR_BM | LTESR_FCT | LTESR_PAR | LTESR_WP \
  118. | LTESR_ATMW | LTESR_ATMR | LTESR_CS | LTESR_UPM \
  119. | LTESR_CC)
  120. #define LTESR_CLEAR 0xFFFFFFFF
  121. #define LTECCR_CLEAR 0xFFFFFFFF
  122. #define LTESR_STATUS LTESR_MASK
  123. #define LTEIR_ENABLE LTESR_MASK
  124. #define LTEDR_ENABLE 0x00000000
  125. __be32 ltedr; /**< Transfer Error Disable Register */
  126. __be32 lteir; /**< Transfer Error Interrupt Register */
  127. __be32 lteatr; /**< Transfer Error Attributes Register */
  128. __be32 ltear; /**< Transfer Error Address Register */
  129. __be32 lteccr; /**< Transfer Error ECC Register */
  130. u8 res6[0x8];
  131. __be32 lbcr; /**< Configuration Register */
  132. #define LBCR_LDIS 0x80000000
  133. #define LBCR_LDIS_SHIFT 31
  134. #define LBCR_BCTLC 0x00C00000
  135. #define LBCR_BCTLC_SHIFT 22
  136. #define LBCR_AHD 0x00200000
  137. #define LBCR_LPBSE 0x00020000
  138. #define LBCR_LPBSE_SHIFT 17
  139. #define LBCR_EPAR 0x00010000
  140. #define LBCR_EPAR_SHIFT 16
  141. #define LBCR_BMT 0x0000FF00
  142. #define LBCR_BMT_SHIFT 8
  143. #define LBCR_BMTPS 0x0000000F
  144. #define LBCR_BMTPS_SHIFT 0
  145. #define LBCR_INIT 0x00040000
  146. __be32 lcrr; /**< Clock Ratio Register */
  147. #define LCRR_DBYP 0x80000000
  148. #define LCRR_DBYP_SHIFT 31
  149. #define LCRR_BUFCMDC 0x30000000
  150. #define LCRR_BUFCMDC_SHIFT 28
  151. #define LCRR_ECL 0x03000000
  152. #define LCRR_ECL_SHIFT 24
  153. #define LCRR_EADC 0x00030000
  154. #define LCRR_EADC_SHIFT 16
  155. #define LCRR_CLKDIV 0x0000000F
  156. #define LCRR_CLKDIV_SHIFT 0
  157. u8 res7[0x8];
  158. __be32 fmr; /**< Flash Mode Register */
  159. #define FMR_CWTO 0x0000F000
  160. #define FMR_CWTO_SHIFT 12
  161. #define FMR_BOOT 0x00000800
  162. #define FMR_ECCM 0x00000100
  163. #define FMR_AL 0x00000030
  164. #define FMR_AL_SHIFT 4
  165. #define FMR_OP 0x00000003
  166. #define FMR_OP_SHIFT 0
  167. __be32 fir; /**< Flash Instruction Register */
  168. #define FIR_OP0 0xF0000000
  169. #define FIR_OP0_SHIFT 28
  170. #define FIR_OP1 0x0F000000
  171. #define FIR_OP1_SHIFT 24
  172. #define FIR_OP2 0x00F00000
  173. #define FIR_OP2_SHIFT 20
  174. #define FIR_OP3 0x000F0000
  175. #define FIR_OP3_SHIFT 16
  176. #define FIR_OP4 0x0000F000
  177. #define FIR_OP4_SHIFT 12
  178. #define FIR_OP5 0x00000F00
  179. #define FIR_OP5_SHIFT 8
  180. #define FIR_OP6 0x000000F0
  181. #define FIR_OP6_SHIFT 4
  182. #define FIR_OP7 0x0000000F
  183. #define FIR_OP7_SHIFT 0
  184. #define FIR_OP_NOP 0x0 /* No operation and end of sequence */
  185. #define FIR_OP_CA 0x1 /* Issue current column address */
  186. #define FIR_OP_PA 0x2 /* Issue current block+page address */
  187. #define FIR_OP_UA 0x3 /* Issue user defined address */
  188. #define FIR_OP_CM0 0x4 /* Issue command from FCR[CMD0] */
  189. #define FIR_OP_CM1 0x5 /* Issue command from FCR[CMD1] */
  190. #define FIR_OP_CM2 0x6 /* Issue command from FCR[CMD2] */
  191. #define FIR_OP_CM3 0x7 /* Issue command from FCR[CMD3] */
  192. #define FIR_OP_WB 0x8 /* Write FBCR bytes from FCM buffer */
  193. #define FIR_OP_WS 0x9 /* Write 1 or 2 bytes from MDR[AS] */
  194. #define FIR_OP_RB 0xA /* Read FBCR bytes to FCM buffer */
  195. #define FIR_OP_RS 0xB /* Read 1 or 2 bytes to MDR[AS] */
  196. #define FIR_OP_CW0 0xC /* Wait then issue FCR[CMD0] */
  197. #define FIR_OP_CW1 0xD /* Wait then issue FCR[CMD1] */
  198. #define FIR_OP_RBW 0xE /* Wait then read FBCR bytes */
  199. #define FIR_OP_RSW 0xE /* Wait then read 1 or 2 bytes */
  200. __be32 fcr; /**< Flash Command Register */
  201. #define FCR_CMD0 0xFF000000
  202. #define FCR_CMD0_SHIFT 24
  203. #define FCR_CMD1 0x00FF0000
  204. #define FCR_CMD1_SHIFT 16
  205. #define FCR_CMD2 0x0000FF00
  206. #define FCR_CMD2_SHIFT 8
  207. #define FCR_CMD3 0x000000FF
  208. #define FCR_CMD3_SHIFT 0
  209. __be32 fbar; /**< Flash Block Address Register */
  210. #define FBAR_BLK 0x00FFFFFF
  211. __be32 fpar; /**< Flash Page Address Register */
  212. #define FPAR_SP_PI 0x00007C00
  213. #define FPAR_SP_PI_SHIFT 10
  214. #define FPAR_SP_MS 0x00000200
  215. #define FPAR_SP_CI 0x000001FF
  216. #define FPAR_SP_CI_SHIFT 0
  217. #define FPAR_LP_PI 0x0003F000
  218. #define FPAR_LP_PI_SHIFT 12
  219. #define FPAR_LP_MS 0x00000800
  220. #define FPAR_LP_CI 0x000007FF
  221. #define FPAR_LP_CI_SHIFT 0
  222. __be32 fbcr; /**< Flash Byte Count Register */
  223. #define FBCR_BC 0x00000FFF
  224. };
  225. /*
  226. * FSL UPM routines
  227. */
  228. struct fsl_upm {
  229. __be32 __iomem *mxmr;
  230. int width;
  231. };
  232. extern u32 fsl_lbc_addr(phys_addr_t addr_base);
  233. extern int fsl_lbc_find(phys_addr_t addr_base);
  234. extern int fsl_upm_find(phys_addr_t addr_base, struct fsl_upm *upm);
  235. /**
  236. * fsl_upm_start_pattern - start UPM patterns execution
  237. * @upm: pointer to the fsl_upm structure obtained via fsl_upm_find
  238. * @pat_offset: UPM pattern offset for the command to be executed
  239. *
  240. * This routine programmes UPM so the next memory access that hits an UPM
  241. * will trigger pattern execution, starting at pat_offset.
  242. */
  243. static inline void fsl_upm_start_pattern(struct fsl_upm *upm, u8 pat_offset)
  244. {
  245. clrsetbits_be32(upm->mxmr, MxMR_MAD, MxMR_OP_RP | pat_offset);
  246. }
  247. /**
  248. * fsl_upm_end_pattern - end UPM patterns execution
  249. * @upm: pointer to the fsl_upm structure obtained via fsl_upm_find
  250. *
  251. * This routine reverts UPM to normal operation mode.
  252. */
  253. static inline void fsl_upm_end_pattern(struct fsl_upm *upm)
  254. {
  255. clrbits32(upm->mxmr, MxMR_OP_RP);
  256. while (in_be32(upm->mxmr) & MxMR_OP_RP)
  257. cpu_relax();
  258. }
  259. /* overview of the fsl lbc controller */
  260. struct fsl_lbc_ctrl {
  261. /* device info */
  262. struct device *dev;
  263. struct fsl_lbc_regs __iomem *regs;
  264. int irq[2];
  265. wait_queue_head_t irq_wait;
  266. spinlock_t lock;
  267. void *nand;
  268. /* status read from LTESR by irq handler */
  269. unsigned int irq_status;
  270. #ifdef CONFIG_SUSPEND
  271. /* save regs when system go to deep-sleep */
  272. struct fsl_lbc_regs *saved_regs;
  273. #endif
  274. };
  275. extern int fsl_upm_run_pattern(struct fsl_upm *upm, void __iomem *io_base,
  276. u32 mar);
  277. extern struct fsl_lbc_ctrl *fsl_lbc_ctrl_dev;
  278. #endif /* __ASM_FSL_LBC_H */