lowlevel_init.S 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. /*
  2. * Copyright (C) 2007, Guennadi Liakhovetski <lg@denx.de>
  3. *
  4. * (C) Copyright 2009 Freescale Semiconductor, Inc.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License as
  8. * published by the Free Software Foundation; either version 2 of
  9. * the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  19. * MA 02111-1307 USA
  20. */
  21. #include <config.h>
  22. #include <asm/arch/imx-regs.h>
  23. #include <generated/asm-offsets.h>
  24. /*
  25. * L2CC Cache setup/invalidation/disable
  26. */
  27. .macro init_l2cc
  28. /* explicitly disable L2 cache */
  29. mrc 15, 0, r0, c1, c0, 1
  30. bic r0, r0, #0x2
  31. mcr 15, 0, r0, c1, c0, 1
  32. /* reconfigure L2 cache aux control reg */
  33. mov r0, #0xC0 /* tag RAM */
  34. add r0, r0, #0x4 /* data RAM */
  35. orr r0, r0, #(1 << 24) /* disable write allocate delay */
  36. orr r0, r0, #(1 << 23) /* disable write allocate combine */
  37. orr r0, r0, #(1 << 22) /* disable write allocate */
  38. #if defined(CONFIG_MX51)
  39. ldr r1, =0x0
  40. ldr r3, [r1, #ROM_SI_REV]
  41. cmp r3, #0x10
  42. /* disable write combine for TO 2 and lower revs */
  43. orrls r0, r0, #(1 << 25)
  44. #endif
  45. mcr 15, 1, r0, c9, c0, 2
  46. .endm /* init_l2cc */
  47. /* AIPS setup - Only setup MPROTx registers.
  48. * The PACR default values are good.*/
  49. .macro init_aips
  50. /*
  51. * Set all MPROTx to be non-bufferable, trusted for R/W,
  52. * not forced to user-mode.
  53. */
  54. ldr r0, =AIPS1_BASE_ADDR
  55. ldr r1, =0x77777777
  56. str r1, [r0, #0x0]
  57. str r1, [r0, #0x4]
  58. ldr r0, =AIPS2_BASE_ADDR
  59. str r1, [r0, #0x0]
  60. str r1, [r0, #0x4]
  61. /*
  62. * Clear the on and off peripheral modules Supervisor Protect bit
  63. * for SDMA to access them. Did not change the AIPS control registers
  64. * (offset 0x20) access type
  65. */
  66. .endm /* init_aips */
  67. /* M4IF setup */
  68. .macro init_m4if
  69. #ifdef CONFIG_MX51
  70. /* VPU and IPU given higher priority (0x4)
  71. * IPU accesses with ID=0x1 given highest priority (=0xA)
  72. */
  73. ldr r0, =M4IF_BASE_ADDR
  74. ldr r1, =0x00000203
  75. str r1, [r0, #0x40]
  76. ldr r1, =0x0
  77. str r1, [r0, #0x44]
  78. ldr r1, =0x00120125
  79. str r1, [r0, #0x9C]
  80. ldr r1, =0x001901A3
  81. str r1, [r0, #0x48]
  82. #endif
  83. .endm /* init_m4if */
  84. .macro setup_pll pll, freq
  85. ldr r0, =\pll
  86. ldr r1, =0x00001232
  87. str r1, [r0, #PLL_DP_CTL] /* Set DPLL ON (set UPEN bit): BRMO=1 */
  88. mov r1, #0x2
  89. str r1, [r0, #PLL_DP_CONFIG] /* Enable auto-restart AREN bit */
  90. ldr r1, W_DP_OP_\freq
  91. str r1, [r0, #PLL_DP_OP]
  92. str r1, [r0, #PLL_DP_HFS_OP]
  93. ldr r1, W_DP_MFD_\freq
  94. str r1, [r0, #PLL_DP_MFD]
  95. str r1, [r0, #PLL_DP_HFS_MFD]
  96. ldr r1, W_DP_MFN_\freq
  97. str r1, [r0, #PLL_DP_MFN]
  98. str r1, [r0, #PLL_DP_HFS_MFN]
  99. ldr r1, =0x00001232
  100. str r1, [r0, #PLL_DP_CTL]
  101. 1: ldr r1, [r0, #PLL_DP_CTL]
  102. ands r1, r1, #0x1
  103. beq 1b
  104. .endm
  105. .macro setup_pll_errata pll, freq
  106. ldr r2, =\pll
  107. mov r1, #0x0
  108. str r1, [r2, #PLL_DP_CONFIG] /* Disable auto-restart AREN bit */
  109. ldr r1, =0x00001236
  110. str r1, [r2, #PLL_DP_CTL] /* Restart PLL with PLM=1 */
  111. 1: ldr r1, [r2, #PLL_DP_CTL] /* Wait for lock */
  112. ands r1, r1, #0x1
  113. beq 1b
  114. ldr r5, \freq
  115. str r5, [r2, #PLL_DP_MFN] /* Modify MFN value */
  116. str r5, [r2, #PLL_DP_HFS_MFN]
  117. mov r1, #0x1
  118. str r1, [r2, #PLL_DP_CONFIG] /* Reload MFN value */
  119. 2: ldr r1, [r2, #PLL_DP_CONFIG]
  120. tst r1, #1
  121. bne 2b
  122. ldr r1, =100 /* Wait at least 4 us */
  123. 3: subs r1, r1, #1
  124. bge 3b
  125. mov r1, #0x2
  126. str r1, [r2, #PLL_DP_CONFIG] /* Enable auto-restart AREN bit */
  127. .endm
  128. .macro init_clock
  129. ldr r0, =CCM_BASE_ADDR
  130. #if defined(CONFIG_MX51)
  131. /* Gate of clocks to the peripherals first */
  132. ldr r1, =0x3FFFFFFF
  133. str r1, [r0, #CLKCTL_CCGR0]
  134. ldr r1, =0x0
  135. str r1, [r0, #CLKCTL_CCGR1]
  136. str r1, [r0, #CLKCTL_CCGR2]
  137. str r1, [r0, #CLKCTL_CCGR3]
  138. ldr r1, =0x00030000
  139. str r1, [r0, #CLKCTL_CCGR4]
  140. ldr r1, =0x00FFF030
  141. str r1, [r0, #CLKCTL_CCGR5]
  142. ldr r1, =0x00000300
  143. str r1, [r0, #CLKCTL_CCGR6]
  144. /* Disable IPU and HSC dividers */
  145. mov r1, #0x60000
  146. str r1, [r0, #CLKCTL_CCDR]
  147. /* Make sure to switch the DDR away from PLL 1 */
  148. ldr r1, =0x19239145
  149. str r1, [r0, #CLKCTL_CBCDR]
  150. /* make sure divider effective */
  151. 1: ldr r1, [r0, #CLKCTL_CDHIPR]
  152. cmp r1, #0x0
  153. bne 1b
  154. #endif
  155. /* Switch ARM to step clock */
  156. mov r1, #0x4
  157. str r1, [r0, #CLKCTL_CCSR]
  158. #if defined(CONFIG_MX51_PLL_ERRATA)
  159. setup_pll PLL1_BASE_ADDR, 864
  160. setup_pll_errata PLL1_BASE_ADDR, W_DP_MFN_800_DIT
  161. #else
  162. setup_pll PLL1_BASE_ADDR, 800
  163. #endif
  164. #if defined(CONFIG_MX51)
  165. setup_pll PLL3_BASE_ADDR, 665
  166. /* Switch peripheral to PLL 3 */
  167. ldr r0, =CCM_BASE_ADDR
  168. ldr r1, =0x000010C0
  169. orr r1,r1,#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
  179. orr r1,r1,#CONFIG_SYS_DDR_CLKSEL
  180. str r1, [r0, #CLKCTL_CBCMR]
  181. #endif
  182. setup_pll PLL3_BASE_ADDR, 216
  183. /* Set the platform clock dividers */
  184. ldr r0, =ARM_BASE_ADDR
  185. ldr r1, =0x00000725
  186. str r1, [r0, #0x14]
  187. ldr r0, =CCM_BASE_ADDR
  188. #if defined(CONFIG_MX51)
  189. /* Run 3.0 at Full speed, for other TO's wait till we increase VDDGP */
  190. ldr r1, =0x0
  191. ldr r3, [r1, #ROM_SI_REV]
  192. cmp r3, #0x10
  193. movls r1, #0x1
  194. movhi r1, #0
  195. #else
  196. mov r1, #0
  197. #endif
  198. str r1, [r0, #CLKCTL_CACRR]
  199. /* Switch ARM back to PLL 1 */
  200. mov r1, #0
  201. str r1, [r0, #CLKCTL_CCSR]
  202. #if defined(CONFIG_MX51)
  203. /* setup the rest */
  204. /* Use lp_apm (24MHz) source for perclk */
  205. ldr r1, =0x000020C2
  206. orr r1,r1,#CONFIG_SYS_DDR_CLKSEL
  207. str r1, [r0, #CLKCTL_CBCMR]
  208. /* ddr clock from PLL 1, all perclk dividers are 1 since using 24MHz */
  209. ldr r1, =CONFIG_SYS_CLKTL_CBCDR
  210. str r1, [r0, #CLKCTL_CBCDR]
  211. #endif
  212. /* Restore the default values in the Gate registers */
  213. ldr r1, =0xFFFFFFFF
  214. str r1, [r0, #CLKCTL_CCGR0]
  215. str r1, [r0, #CLKCTL_CCGR1]
  216. str r1, [r0, #CLKCTL_CCGR2]
  217. str r1, [r0, #CLKCTL_CCGR3]
  218. str r1, [r0, #CLKCTL_CCGR4]
  219. str r1, [r0, #CLKCTL_CCGR5]
  220. str r1, [r0, #CLKCTL_CCGR6]
  221. #if defined(CONFIG_MX53)
  222. str r1, [r0, #CLKCTL_CCGR7]
  223. #endif
  224. #if defined(CONFIG_MX51)
  225. /* Use PLL 2 for UART's, get 66.5MHz from it */
  226. ldr r1, =0xA5A2A020
  227. str r1, [r0, #CLKCTL_CSCMR1]
  228. ldr r1, =0x00C30321
  229. str r1, [r0, #CLKCTL_CSCDR1]
  230. #elif defined(CONFIG_MX53)
  231. ldr r1, [r0, #CLKCTL_CSCDR1]
  232. orr r1, r1, #0x3f
  233. eor r1, r1, #0x3f
  234. orr r1, r1, #0x21
  235. str r1, [r0, #CLKCTL_CSCDR1]
  236. #endif
  237. /* make sure divider effective */
  238. 1: ldr r1, [r0, #CLKCTL_CDHIPR]
  239. cmp r1, #0x0
  240. bne 1b
  241. mov r1, #0x0
  242. str r1, [r0, #CLKCTL_CCDR]
  243. /* for cko - for ARM div by 8 */
  244. mov r1, #0x000A0000
  245. add r1, r1, #0x00000F0
  246. str r1, [r0, #CLKCTL_CCOSR]
  247. .endm
  248. .macro setup_wdog
  249. ldr r0, =WDOG1_BASE_ADDR
  250. mov r1, #0x30
  251. strh r1, [r0]
  252. .endm
  253. .section ".text.init", "x"
  254. .globl lowlevel_init
  255. lowlevel_init:
  256. #if defined(CONFIG_MX51)
  257. ldr r0, =GPIO1_BASE_ADDR
  258. ldr r1, [r0, #0x0]
  259. orr r1, r1, #(1 << 23)
  260. str r1, [r0, #0x0]
  261. ldr r1, [r0, #0x4]
  262. orr r1, r1, #(1 << 23)
  263. str r1, [r0, #0x4]
  264. #endif
  265. init_l2cc
  266. init_aips
  267. init_m4if
  268. init_clock
  269. /* r12 saved upper lr*/
  270. mov pc,lr
  271. /* Board level setting value */
  272. W_DP_OP_864: .word DP_OP_864
  273. W_DP_MFD_864: .word DP_MFD_864
  274. W_DP_MFN_864: .word DP_MFN_864
  275. W_DP_MFN_800_DIT: .word DP_MFN_800_DIT
  276. W_DP_OP_800: .word DP_OP_800
  277. W_DP_MFD_800: .word DP_MFD_800
  278. W_DP_MFN_800: .word DP_MFN_800
  279. W_DP_OP_665: .word DP_OP_665
  280. W_DP_MFD_665: .word DP_MFD_665
  281. W_DP_MFN_665: .word DP_MFN_665
  282. W_DP_OP_216: .word DP_OP_216
  283. W_DP_MFD_216: .word DP_MFD_216
  284. W_DP_MFN_216: .word DP_MFN_216