lowlevel_init.S 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  1. /*
  2. * Copyright (C) 2007, Guennadi Liakhovetski <lg@denx.de>
  3. *
  4. * (C) Copyright 2009 Freescale Semiconductor, Inc.
  5. *
  6. * SPDX-License-Identifier: GPL-2.0+
  7. */
  8. #include <config.h>
  9. #include <asm/arch/imx-regs.h>
  10. #include <generated/asm-offsets.h>
  11. #include <linux/linkage.h>
  12. .section ".text.init", "x"
  13. .macro init_arm_erratum
  14. /* ARM erratum ID #468414 */
  15. mrc 15, 0, r1, c1, c0, 1
  16. orr r1, r1, #(1 << 5) /* enable L1NEON bit */
  17. mcr 15, 0, r1, c1, c0, 1
  18. .endm
  19. /*
  20. * L2CC Cache setup/invalidation/disable
  21. */
  22. .macro init_l2cc
  23. /* explicitly disable L2 cache */
  24. mrc 15, 0, r0, c1, c0, 1
  25. bic r0, r0, #0x2
  26. mcr 15, 0, r0, c1, c0, 1
  27. /* reconfigure L2 cache aux control reg */
  28. ldr r0, =0xC0 | /* tag RAM */ \
  29. 0x4 | /* data RAM */ \
  30. 1 << 24 | /* disable write allocate delay */ \
  31. 1 << 23 | /* disable write allocate combine */ \
  32. 1 << 22 /* disable write allocate */
  33. #if defined(CONFIG_MX51)
  34. ldr r3, [r4, #ROM_SI_REV]
  35. cmp r3, #0x10
  36. /* disable write combine for TO 2 and lower revs */
  37. orrls r0, r0, #1 << 25
  38. #endif
  39. mcr 15, 1, r0, c9, c0, 2
  40. /* enable L2 cache */
  41. mrc 15, 0, r0, c1, c0, 1
  42. orr r0, r0, #2
  43. mcr 15, 0, r0, c1, c0, 1
  44. .endm /* init_l2cc */
  45. /* AIPS setup - Only setup MPROTx registers.
  46. * The PACR default values are good.*/
  47. .macro init_aips
  48. /*
  49. * Set all MPROTx to be non-bufferable, trusted for R/W,
  50. * not forced to user-mode.
  51. */
  52. ldr r0, =AIPS1_BASE_ADDR
  53. ldr r1, =0x77777777
  54. str r1, [r0, #0x0]
  55. str r1, [r0, #0x4]
  56. ldr r0, =AIPS2_BASE_ADDR
  57. str r1, [r0, #0x0]
  58. str r1, [r0, #0x4]
  59. /*
  60. * Clear the on and off peripheral modules Supervisor Protect bit
  61. * for SDMA to access them. Did not change the AIPS control registers
  62. * (offset 0x20) access type
  63. */
  64. .endm /* init_aips */
  65. /* M4IF setup */
  66. .macro init_m4if
  67. #ifdef CONFIG_MX51
  68. /* VPU and IPU given higher priority (0x4)
  69. * IPU accesses with ID=0x1 given highest priority (=0xA)
  70. */
  71. ldr r0, =M4IF_BASE_ADDR
  72. ldr r1, =0x00000203
  73. str r1, [r0, #0x40]
  74. str r4, [r0, #0x44]
  75. ldr r1, =0x00120125
  76. str r1, [r0, #0x9C]
  77. ldr r1, =0x001901A3
  78. str r1, [r0, #0x48]
  79. #endif
  80. .endm /* init_m4if */
  81. .macro setup_pll pll, freq
  82. ldr r0, =\pll
  83. adr r2, W_DP_\freq
  84. bl setup_pll_func
  85. .endm
  86. #define W_DP_OP 0
  87. #define W_DP_MFD 4
  88. #define W_DP_MFN 8
  89. setup_pll_func:
  90. ldr r1, =0x00001232
  91. str r1, [r0, #PLL_DP_CTL] /* Set DPLL ON (set UPEN bit): BRMO=1 */
  92. mov r1, #0x2
  93. str r1, [r0, #PLL_DP_CONFIG] /* Enable auto-restart AREN bit */
  94. ldr r1, [r2, #W_DP_OP]
  95. str r1, [r0, #PLL_DP_OP]
  96. str r1, [r0, #PLL_DP_HFS_OP]
  97. ldr r1, [r2, #W_DP_MFD]
  98. str r1, [r0, #PLL_DP_MFD]
  99. str r1, [r0, #PLL_DP_HFS_MFD]
  100. ldr r1, [r2, #W_DP_MFN]
  101. str r1, [r0, #PLL_DP_MFN]
  102. str r1, [r0, #PLL_DP_HFS_MFN]
  103. ldr r1, =0x00001232
  104. str r1, [r0, #PLL_DP_CTL]
  105. 1: ldr r1, [r0, #PLL_DP_CTL]
  106. ands r1, r1, #0x1
  107. beq 1b
  108. /* r10 saved upper lr */
  109. mov pc, lr
  110. .macro setup_pll_errata pll, freq
  111. ldr r2, =\pll
  112. str r4, [r2, #PLL_DP_CONFIG] /* Disable auto-restart AREN bit */
  113. ldr r1, =0x00001236
  114. str r1, [r2, #PLL_DP_CTL] /* Restart PLL with PLM=1 */
  115. 1: ldr r1, [r2, #PLL_DP_CTL] /* Wait for lock */
  116. ands r1, r1, #0x1
  117. beq 1b
  118. ldr r5, \freq
  119. str r5, [r2, #PLL_DP_MFN] /* Modify MFN value */
  120. str r5, [r2, #PLL_DP_HFS_MFN]
  121. mov r1, #0x1
  122. str r1, [r2, #PLL_DP_CONFIG] /* Reload MFN value */
  123. 2: ldr r1, [r2, #PLL_DP_CONFIG]
  124. tst r1, #1
  125. bne 2b
  126. ldr r1, =100 /* Wait at least 4 us */
  127. 3: subs r1, r1, #1
  128. bge 3b
  129. mov r1, #0x2
  130. str r1, [r2, #PLL_DP_CONFIG] /* Enable auto-restart AREN bit */
  131. .endm
  132. .macro init_clock
  133. #if defined (CONFIG_MX51)
  134. ldr r0, =CCM_BASE_ADDR
  135. /* Gate of clocks to the peripherals first */
  136. ldr r1, =0x3FFFFFFF
  137. str r1, [r0, #CLKCTL_CCGR0]
  138. str r4, [r0, #CLKCTL_CCGR1]
  139. str r4, [r0, #CLKCTL_CCGR2]
  140. str r4, [r0, #CLKCTL_CCGR3]
  141. ldr r1, =0x00030000
  142. str r1, [r0, #CLKCTL_CCGR4]
  143. ldr r1, =0x00FFF030
  144. str r1, [r0, #CLKCTL_CCGR5]
  145. ldr r1, =0x00000300
  146. str r1, [r0, #CLKCTL_CCGR6]
  147. /* Disable IPU and HSC dividers */
  148. mov r1, #0x60000
  149. str r1, [r0, #CLKCTL_CCDR]
  150. /* Make sure to switch the DDR away from PLL 1 */
  151. ldr r1, =0x19239145
  152. str r1, [r0, #CLKCTL_CBCDR]
  153. /* make sure divider effective */
  154. 1: ldr r1, [r0, #CLKCTL_CDHIPR]
  155. cmp r1, #0x0
  156. bne 1b
  157. /* Switch ARM to step clock */
  158. mov r1, #0x4
  159. str r1, [r0, #CLKCTL_CCSR]
  160. #if defined(CONFIG_MX51_PLL_ERRATA)
  161. setup_pll PLL1_BASE_ADDR, 864
  162. setup_pll_errata PLL1_BASE_ADDR, W_DP_MFN_800_DIT
  163. #else
  164. setup_pll PLL1_BASE_ADDR, 800
  165. #endif
  166. setup_pll PLL3_BASE_ADDR, 665
  167. /* Switch peripheral to PLL 3 */
  168. ldr r0, =CCM_BASE_ADDR
  169. ldr r1, =0x000010C0 | CONFIG_SYS_DDR_CLKSEL
  170. str r1, [r0, #CLKCTL_CBCMR]
  171. ldr r1, =0x13239145
  172. str r1, [r0, #CLKCTL_CBCDR]
  173. setup_pll PLL2_BASE_ADDR, 665
  174. /* Switch peripheral to PLL2 */
  175. ldr r0, =CCM_BASE_ADDR
  176. ldr r1, =0x19239145
  177. str r1, [r0, #CLKCTL_CBCDR]
  178. ldr r1, =0x000020C0 | CONFIG_SYS_DDR_CLKSEL
  179. str r1, [r0, #CLKCTL_CBCMR]
  180. setup_pll PLL3_BASE_ADDR, 216
  181. /* Set the platform clock dividers */
  182. ldr r0, =ARM_BASE_ADDR
  183. ldr r1, =0x00000725
  184. str r1, [r0, #0x14]
  185. ldr r0, =CCM_BASE_ADDR
  186. /* Run 3.0 at Full speed, for other TO's wait till we increase VDDGP */
  187. ldr r3, [r4, #ROM_SI_REV]
  188. cmp r3, #0x10
  189. movls r1, #0x1
  190. movhi r1, #0
  191. str r1, [r0, #CLKCTL_CACRR]
  192. /* Switch ARM back to PLL 1 */
  193. str r4, [r0, #CLKCTL_CCSR]
  194. /* setup the rest */
  195. /* Use lp_apm (24MHz) source for perclk */
  196. ldr r1, =0x000020C2 | CONFIG_SYS_DDR_CLKSEL
  197. str r1, [r0, #CLKCTL_CBCMR]
  198. /* ddr clock from PLL 1, all perclk dividers are 1 since using 24MHz */
  199. ldr r1, =CONFIG_SYS_CLKTL_CBCDR
  200. str r1, [r0, #CLKCTL_CBCDR]
  201. /* Restore the default values in the Gate registers */
  202. ldr r1, =0xFFFFFFFF
  203. str r1, [r0, #CLKCTL_CCGR0]
  204. str r1, [r0, #CLKCTL_CCGR1]
  205. str r1, [r0, #CLKCTL_CCGR2]
  206. str r1, [r0, #CLKCTL_CCGR3]
  207. str r1, [r0, #CLKCTL_CCGR4]
  208. str r1, [r0, #CLKCTL_CCGR5]
  209. str r1, [r0, #CLKCTL_CCGR6]
  210. /* Use PLL 2 for UART's, get 66.5MHz from it */
  211. ldr r1, =0xA5A2A020
  212. str r1, [r0, #CLKCTL_CSCMR1]
  213. ldr r1, =0x00C30321
  214. str r1, [r0, #CLKCTL_CSCDR1]
  215. /* make sure divider effective */
  216. 1: ldr r1, [r0, #CLKCTL_CDHIPR]
  217. cmp r1, #0x0
  218. bne 1b
  219. str r4, [r0, #CLKCTL_CCDR]
  220. /* for cko - for ARM div by 8 */
  221. mov r1, #0x000A0000
  222. add r1, r1, #0x00000F0
  223. str r1, [r0, #CLKCTL_CCOSR]
  224. #else /* CONFIG_MX53 */
  225. ldr r0, =CCM_BASE_ADDR
  226. /* Gate of clocks to the peripherals first */
  227. ldr r1, =0x3FFFFFFF
  228. str r1, [r0, #CLKCTL_CCGR0]
  229. str r4, [r0, #CLKCTL_CCGR1]
  230. str r4, [r0, #CLKCTL_CCGR2]
  231. str r4, [r0, #CLKCTL_CCGR3]
  232. str r4, [r0, #CLKCTL_CCGR7]
  233. ldr r1, =0x00030000
  234. str r1, [r0, #CLKCTL_CCGR4]
  235. ldr r1, =0x00FFF030
  236. str r1, [r0, #CLKCTL_CCGR5]
  237. ldr r1, =0x0F00030F
  238. str r1, [r0, #CLKCTL_CCGR6]
  239. /* Switch ARM to step clock */
  240. mov r1, #0x4
  241. str r1, [r0, #CLKCTL_CCSR]
  242. setup_pll PLL1_BASE_ADDR, 800
  243. setup_pll PLL3_BASE_ADDR, 400
  244. /* Switch peripheral to PLL3 */
  245. ldr r0, =CCM_BASE_ADDR
  246. ldr r1, =0x00015154
  247. str r1, [r0, #CLKCTL_CBCMR]
  248. ldr r1, =0x02898945
  249. str r1, [r0, #CLKCTL_CBCDR]
  250. /* make sure change is effective */
  251. 1: ldr r1, [r0, #CLKCTL_CDHIPR]
  252. cmp r1, #0x0
  253. bne 1b
  254. setup_pll PLL2_BASE_ADDR, 400
  255. /* Switch peripheral to PLL2 */
  256. ldr r0, =CCM_BASE_ADDR
  257. ldr r1, =0x00888945
  258. str r1, [r0, #CLKCTL_CBCDR]
  259. ldr r1, =0x00016154
  260. str r1, [r0, #CLKCTL_CBCMR]
  261. /*change uart clk parent to pll2*/
  262. ldr r1, [r0, #CLKCTL_CSCMR1]
  263. and r1, r1, #0xfcffffff
  264. orr r1, r1, #0x01000000
  265. str r1, [r0, #CLKCTL_CSCMR1]
  266. /* make sure change is effective */
  267. 1: ldr r1, [r0, #CLKCTL_CDHIPR]
  268. cmp r1, #0x0
  269. bne 1b
  270. setup_pll PLL3_BASE_ADDR, 216
  271. setup_pll PLL4_BASE_ADDR, 455
  272. /* Set the platform clock dividers */
  273. ldr r0, =ARM_BASE_ADDR
  274. ldr r1, =0x00000124
  275. str r1, [r0, #0x14]
  276. ldr r0, =CCM_BASE_ADDR
  277. mov r1, #0
  278. str r1, [r0, #CLKCTL_CACRR]
  279. /* Switch ARM back to PLL 1. */
  280. mov r1, #0x0
  281. str r1, [r0, #CLKCTL_CCSR]
  282. /* make uart div=6 */
  283. ldr r1, [r0, #CLKCTL_CSCDR1]
  284. and r1, r1, #0xffffffc0
  285. orr r1, r1, #0x0a
  286. str r1, [r0, #CLKCTL_CSCDR1]
  287. /* Restore the default values in the Gate registers */
  288. ldr r1, =0xFFFFFFFF
  289. str r1, [r0, #CLKCTL_CCGR0]
  290. str r1, [r0, #CLKCTL_CCGR1]
  291. str r1, [r0, #CLKCTL_CCGR2]
  292. str r1, [r0, #CLKCTL_CCGR3]
  293. str r1, [r0, #CLKCTL_CCGR4]
  294. str r1, [r0, #CLKCTL_CCGR5]
  295. str r1, [r0, #CLKCTL_CCGR6]
  296. str r1, [r0, #CLKCTL_CCGR7]
  297. mov r1, #0x00000
  298. str r1, [r0, #CLKCTL_CCDR]
  299. /* for cko - for ARM div by 8 */
  300. mov r1, #0x000A0000
  301. add r1, r1, #0x00000F0
  302. str r1, [r0, #CLKCTL_CCOSR]
  303. #endif /* CONFIG_MX53 */
  304. .endm
  305. ENTRY(lowlevel_init)
  306. mov r10, lr
  307. mov r4, #0 /* Fix R4 to 0 */
  308. #if defined(CONFIG_SYS_MAIN_PWR_ON)
  309. ldr r0, =GPIO1_BASE_ADDR
  310. ldr r1, [r0, #0x0]
  311. orr r1, r1, #1 << 23
  312. str r1, [r0, #0x0]
  313. ldr r1, [r0, #0x4]
  314. orr r1, r1, #1 << 23
  315. str r1, [r0, #0x4]
  316. #endif
  317. init_arm_erratum
  318. init_l2cc
  319. init_aips
  320. init_m4if
  321. init_clock
  322. mov pc, r10
  323. ENDPROC(lowlevel_init)
  324. /* Board level setting value */
  325. #if defined(CONFIG_MX51_PLL_ERRATA)
  326. W_DP_864: .word DP_OP_864
  327. .word DP_MFD_864
  328. .word DP_MFN_864
  329. W_DP_MFN_800_DIT: .word DP_MFN_800_DIT
  330. #else
  331. W_DP_800: .word DP_OP_800
  332. .word DP_MFD_800
  333. .word DP_MFN_800
  334. #endif
  335. #if defined(CONFIG_MX51)
  336. W_DP_665: .word DP_OP_665
  337. .word DP_MFD_665
  338. .word DP_MFN_665
  339. #endif
  340. W_DP_216: .word DP_OP_216
  341. .word DP_MFD_216
  342. .word DP_MFN_216
  343. W_DP_400: .word DP_OP_400
  344. .word DP_MFD_400
  345. .word DP_MFN_400
  346. W_DP_455: .word DP_OP_455
  347. .word DP_MFD_455
  348. .word DP_MFN_455