lowlevel_init.S 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. /*
  2. * Copyright (C) 2008, Guennadi Liakhovetski <lg@denx.de>
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <asm/arch/imx-regs.h>
  7. .macro REG reg, val
  8. ldr r2, =\reg
  9. ldr r3, =\val
  10. str r3, [r2]
  11. .endm
  12. .macro REG8 reg, val
  13. ldr r2, =\reg
  14. ldr r3, =\val
  15. strb r3, [r2]
  16. .endm
  17. .macro DELAY loops
  18. ldr r2, =\loops
  19. 1:
  20. subs r2, r2, #1
  21. nop
  22. bcs 1b
  23. .endm
  24. /* RedBoot: AIPS setup - Only setup MPROTx registers.
  25. * The PACR default values are good.*/
  26. .macro init_aips
  27. /*
  28. * Set all MPROTx to be non-bufferable, trusted for R/W,
  29. * not forced to user-mode.
  30. */
  31. ldr r0, =0x43F00000
  32. ldr r1, =0x77777777
  33. str r1, [r0, #0x00]
  34. str r1, [r0, #0x04]
  35. ldr r0, =0x53F00000
  36. str r1, [r0, #0x00]
  37. str r1, [r0, #0x04]
  38. /*
  39. * Clear the on and off peripheral modules Supervisor Protect bit
  40. * for SDMA to access them. Did not change the AIPS control registers
  41. * (offset 0x20) access type
  42. */
  43. ldr r0, =0x43F00000
  44. ldr r1, =0x0
  45. str r1, [r0, #0x40]
  46. str r1, [r0, #0x44]
  47. str r1, [r0, #0x48]
  48. str r1, [r0, #0x4C]
  49. ldr r1, [r0, #0x50]
  50. and r1, r1, #0x00FFFFFF
  51. str r1, [r0, #0x50]
  52. ldr r0, =0x53F00000
  53. ldr r1, =0x0
  54. str r1, [r0, #0x40]
  55. str r1, [r0, #0x44]
  56. str r1, [r0, #0x48]
  57. str r1, [r0, #0x4C]
  58. ldr r1, [r0, #0x50]
  59. and r1, r1, #0x00FFFFFF
  60. str r1, [r0, #0x50]
  61. .endm /* init_aips */
  62. /* RedBoot: MAX (Multi-Layer AHB Crossbar Switch) setup */
  63. .macro init_max
  64. ldr r0, =0x43F04000
  65. /* MPR - priority is M4 > M2 > M3 > M5 > M0 > M1 */
  66. ldr r1, =0x00302154
  67. str r1, [r0, #0x000] /* for S0 */
  68. str r1, [r0, #0x100] /* for S1 */
  69. str r1, [r0, #0x200] /* for S2 */
  70. str r1, [r0, #0x300] /* for S3 */
  71. str r1, [r0, #0x400] /* for S4 */
  72. /* SGPCR - always park on last master */
  73. ldr r1, =0x10
  74. str r1, [r0, #0x010] /* for S0 */
  75. str r1, [r0, #0x110] /* for S1 */
  76. str r1, [r0, #0x210] /* for S2 */
  77. str r1, [r0, #0x310] /* for S3 */
  78. str r1, [r0, #0x410] /* for S4 */
  79. /* MGPCR - restore default values */
  80. ldr r1, =0x0
  81. str r1, [r0, #0x800] /* for M0 */
  82. str r1, [r0, #0x900] /* for M1 */
  83. str r1, [r0, #0xA00] /* for M2 */
  84. str r1, [r0, #0xB00] /* for M3 */
  85. str r1, [r0, #0xC00] /* for M4 */
  86. str r1, [r0, #0xD00] /* for M5 */
  87. .endm /* init_max */
  88. /* RedBoot: M3IF setup */
  89. .macro init_m3if
  90. /* Configure M3IF registers */
  91. ldr r1, =0xB8003000
  92. /*
  93. * M3IF Control Register (M3IFCTL)
  94. * MRRP[0] = L2CC0 not on priority list (0 << 0) = 0x00000000
  95. * MRRP[1] = L2CC1 not on priority list (0 << 0) = 0x00000000
  96. * MRRP[2] = MBX not on priority list (0 << 0) = 0x00000000
  97. * MRRP[3] = MAX1 not on priority list (0 << 0) = 0x00000000
  98. * MRRP[4] = SDMA not on priority list (0 << 0) = 0x00000000
  99. * MRRP[5] = MPEG4 not on priority list (0 << 0) = 0x00000000
  100. * MRRP[6] = IPU1 on priority list (1 << 6) = 0x00000040
  101. * MRRP[7] = IPU2 not on priority list (0 << 0) = 0x00000000
  102. * ------------
  103. * 0x00000040
  104. */
  105. ldr r0, =0x00000040
  106. str r0, [r1] /* M3IF control reg */
  107. .endm /* init_m3if */
  108. /* RedBoot: To support 133MHz DDR */
  109. .macro init_drive_strength
  110. /*
  111. * Disable maximum drive strength SDRAM/DDR lines by clearing DSE1 bits
  112. * in SW_PAD_CTL registers
  113. */
  114. /* SDCLK */
  115. ldr r1, =0x43FAC200
  116. ldr r0, [r1, #0x6C]
  117. bic r0, r0, #(1 << 12)
  118. str r0, [r1, #0x6C]
  119. /* CAS */
  120. ldr r0, [r1, #0x70]
  121. bic r0, r0, #(1 << 22)
  122. str r0, [r1, #0x70]
  123. /* RAS */
  124. ldr r0, [r1, #0x74]
  125. bic r0, r0, #(1 << 2)
  126. str r0, [r1, #0x74]
  127. /* CS2 (CSD0) */
  128. ldr r0, [r1, #0x7C]
  129. bic r0, r0, #(1 << 22)
  130. str r0, [r1, #0x7C]
  131. /* DQM3 */
  132. ldr r0, [r1, #0x84]
  133. bic r0, r0, #(1 << 22)
  134. str r0, [r1, #0x84]
  135. /* DQM2, DQM1, DQM0, SD31-SD0, A25-A0, MA10 (0x288..0x2DC) */
  136. ldr r2, =22 /* (0x2E0 - 0x288) / 4 = 22 */
  137. pad_loop:
  138. ldr r0, [r1, #0x88]
  139. bic r0, r0, #(1 << 22)
  140. bic r0, r0, #(1 << 12)
  141. bic r0, r0, #(1 << 2)
  142. str r0, [r1, #0x88]
  143. add r1, r1, #4
  144. subs r2, r2, #0x1
  145. bne pad_loop
  146. .endm /* init_drive_strength */
  147. /* CPLD on CS4 setup */
  148. .macro init_cs4
  149. ldr r0, =WEIM_BASE
  150. ldr r1, =0x0000D843
  151. str r1, [r0, #0x40]
  152. ldr r1, =0x22252521
  153. str r1, [r0, #0x44]
  154. ldr r1, =0x22220A00
  155. str r1, [r0, #0x48]
  156. .endm /* init_cs4 */
  157. .globl lowlevel_init
  158. lowlevel_init:
  159. /* Redboot initializes very early AIPS, what for?
  160. * Then it also initializes Multi-Layer AHB Crossbar Switch,
  161. * M3IF */
  162. /* Also setup the Peripheral Port Remap register inside the core */
  163. ldr r0, =0x40000015 /* start from AIPS 2GB region */
  164. mcr p15, 0, r0, c15, c2, 4
  165. init_aips
  166. init_max
  167. init_m3if
  168. init_drive_strength
  169. init_cs4
  170. /* Image Processing Unit: */
  171. /* Too early to switch display on? */
  172. REG IPU_CONF, IPU_CONF_DI_EN /* Switch on Display Interface */
  173. /* Clock Control Module: */
  174. REG CCM_CCMR, 0x074B0BF5 /* Use CKIH, MCU PLL off */
  175. DELAY 0x40000
  176. REG CCM_CCMR, 0x074B0BF5 | CCMR_MPE /* MCU PLL on */
  177. REG CCM_CCMR, (0x074B0BF5 | CCMR_MPE) & ~CCMR_MDS /* Switch to MCU PLL */
  178. /* PBC CPLD on CS4 */
  179. mov r1, #CS4_BASE
  180. ldrh r1, [r1, #0x2]
  181. /* Is 27MHz switch set? */
  182. ands r1, r1, #0x10
  183. /* 532-133-66.5 */
  184. ldr r0, =CCM_BASE
  185. ldr r1, =0xFF871D58
  186. /* PDR0 */
  187. str r1, [r0, #0x4]
  188. ldreq r1, MPCTL_PARAM_532
  189. ldrne r1, MPCTL_PARAM_532_27
  190. /* MPCTL */
  191. str r1, [r0, #0x10]
  192. /* Set UPLL=240MHz, USB=60MHz */
  193. ldr r1, =0x49FCFE7F
  194. /* PDR1 */
  195. str r1, [r0, #0x8]
  196. ldreq r1, UPCTL_PARAM_240
  197. ldrne r1, UPCTL_PARAM_240_27
  198. /* UPCTL */
  199. str r1, [r0, #0x14]
  200. /* default CLKO to 1/8 of the ARM core */
  201. mov r1, #0x000002C0
  202. add r1, r1, #0x00000006
  203. /* COSR */
  204. str r1, [r0, #0x1c]
  205. /* RedBoot sets 0x3f, 7, 7, 3, 5, 1, 3, 0 */
  206. /* REG CCM_PDR0, PDR0_CSI_PODF(0x3f) | PDR0_CSI_PRDF(7) | PDR0_PER_PODF(7) | PDR0_HSP_PODF(2) | PDR0_NFC_PODF(6) | PDR0_IPG_PODF(1) | PDR0_MAX_PODF(2) | PDR0_MCU_PODF(0)*/
  207. /* Redboot: 0, 51, 10, 12 / 0, 14, 9, 13 */
  208. /* REG CCM_MPCTL, PLL_PD(0) | PLL_MFD(0x33) | PLL_MFI(7) | PLL_MFN(0x23)*/
  209. /* Default: 1, 4, 12, 1 */
  210. REG CCM_SPCTL, PLL_PD(1) | PLL_MFD(4) | PLL_MFI(12) | PLL_MFN(1)
  211. /* B8xxxxxx - NAND, 8xxxxxxx - CSD0 RAM */
  212. REG 0xB8001010, 0x00000004
  213. REG 0xB8001004, 0x006ac73a
  214. REG 0xB8001000, 0x92100000
  215. REG 0x80000f00, 0x12344321
  216. REG 0xB8001000, 0xa2100000
  217. REG 0x80000000, 0x12344321
  218. REG 0x80000000, 0x12344321
  219. REG 0xB8001000, 0xb2100000
  220. REG8 0x80000033, 0xda
  221. REG8 0x81000000, 0xff
  222. REG 0xB8001000, 0x82226080
  223. REG 0x80000000, 0xDEADBEEF
  224. REG 0xB8001010, 0x0000000c
  225. mov pc, lr
  226. MPCTL_PARAM_532:
  227. .word (((1-1) << 26) + ((52-1) << 16) + (10 << 10) + (12 << 0))
  228. MPCTL_PARAM_532_27:
  229. .word (((1-1) << 26) + ((15-1) << 16) + (9 << 10) + (13 << 0))
  230. UPCTL_PARAM_240:
  231. .word (((2-1) << 26) + ((13-1) << 16) + (9 << 10) + (3 << 0))
  232. UPCTL_PARAM_240_27:
  233. .word (((2-1) << 26) + ((9 -1) << 16) + (8 << 10) + (8 << 0))