lowlevel_init.S 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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 <asm/arch/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. cmp r3, #0x10 /* r3 contains the silicon rev */
  39. /* disable write combine for TO 2 and lower revs */
  40. orrls r0, r0, #(1 << 25)
  41. mcr 15, 1, r0, c9, c0, 2
  42. .endm /* init_l2cc */
  43. /* AIPS setup - Only setup MPROTx registers.
  44. * The PACR default values are good.*/
  45. .macro init_aips
  46. /*
  47. * Set all MPROTx to be non-bufferable, trusted for R/W,
  48. * not forced to user-mode.
  49. */
  50. ldr r0, =AIPS1_BASE_ADDR
  51. ldr r1, =0x77777777
  52. str r1, [r0, #0x0]
  53. str r1, [r0, #0x4]
  54. ldr r0, =AIPS2_BASE_ADDR
  55. str r1, [r0, #0x0]
  56. str r1, [r0, #0x4]
  57. /*
  58. * Clear the on and off peripheral modules Supervisor Protect bit
  59. * for SDMA to access them. Did not change the AIPS control registers
  60. * (offset 0x20) access type
  61. */
  62. .endm /* init_aips */
  63. /* M4IF setup */
  64. .macro init_m4if
  65. /* VPU and IPU given higher priority (0x4)
  66. * IPU accesses with ID=0x1 given highest priority (=0xA)
  67. */
  68. ldr r0, =M4IF_BASE_ADDR
  69. ldr r1, =0x00000203
  70. str r1, [r0, #0x40]
  71. ldr r1, =0x0
  72. str r1, [r0, #0x44]
  73. ldr r1, =0x00120125
  74. str r1, [r0, #0x9C]
  75. ldr r1, =0x001901A3
  76. str r1, [r0, #0x48]
  77. .endm /* init_m4if */
  78. .macro setup_pll pll, freq
  79. ldr r2, =\pll
  80. ldr r1, =0x00001232
  81. str r1, [r2, #PLL_DP_CTL] /* Set DPLL ON (set UPEN bit): BRMO=1 */
  82. mov r1, #0x2
  83. str r1, [r2, #PLL_DP_CONFIG] /* Enable auto-restart AREN bit */
  84. str r3, [r2, #PLL_DP_OP]
  85. str r3, [r2, #PLL_DP_HFS_OP]
  86. str r4, [r2, #PLL_DP_MFD]
  87. str r4, [r2, #PLL_DP_HFS_MFD]
  88. str r5, [r2, #PLL_DP_MFN]
  89. str r5, [r2, #PLL_DP_HFS_MFN]
  90. ldr r1, =0x00001232
  91. str r1, [r2, #PLL_DP_CTL]
  92. 1: ldr r1, [r2, #PLL_DP_CTL]
  93. ands r1, r1, #0x1
  94. beq 1b
  95. .endm
  96. .macro init_clock
  97. ldr r0, =CCM_BASE_ADDR
  98. /* Gate of clocks to the peripherals first */
  99. ldr r1, =0x3FFFFFFF
  100. str r1, [r0, #CLKCTL_CCGR0]
  101. ldr r1, =0x0
  102. str r1, [r0, #CLKCTL_CCGR1]
  103. str r1, [r0, #CLKCTL_CCGR2]
  104. str r1, [r0, #CLKCTL_CCGR3]
  105. ldr r1, =0x00030000
  106. str r1, [r0, #CLKCTL_CCGR4]
  107. ldr r1, =0x00FFF030
  108. str r1, [r0, #CLKCTL_CCGR5]
  109. ldr r1, =0x00000300
  110. str r1, [r0, #CLKCTL_CCGR6]
  111. /* Disable IPU and HSC dividers */
  112. mov r1, #0x60000
  113. str r1, [r0, #CLKCTL_CCDR]
  114. /* Make sure to switch the DDR away from PLL 1 */
  115. ldr r1, =0x19239145
  116. str r1, [r0, #CLKCTL_CBCDR]
  117. /* make sure divider effective */
  118. 1: ldr r1, [r0, #CLKCTL_CDHIPR]
  119. cmp r1, #0x0
  120. bne 1b
  121. /* Switch ARM to step clock */
  122. mov r1, #0x4
  123. str r1, [r0, #CLKCTL_CCSR]
  124. mov r3, #DP_OP_800
  125. mov r4, #DP_MFD_800
  126. mov r5, #DP_MFN_800
  127. setup_pll PLL1_BASE_ADDR
  128. mov r3, #DP_OP_665
  129. mov r4, #DP_MFD_665
  130. mov r5, #DP_MFN_665
  131. setup_pll PLL3_BASE_ADDR
  132. /* Switch peripheral to PLL 3 */
  133. ldr r0, =CCM_BASE_ADDR
  134. ldr r1, =0x000010C0
  135. orr r1,r1,#CONFIG_SYS_DDR_CLKSEL
  136. str r1, [r0, #CLKCTL_CBCMR]
  137. ldr r1, =0x13239145
  138. str r1, [r0, #CLKCTL_CBCDR]
  139. mov r3, #DP_OP_665
  140. mov r4, #DP_MFD_665
  141. mov r5, #DP_MFN_665
  142. setup_pll PLL2_BASE_ADDR
  143. /* Switch peripheral to PLL2 */
  144. ldr r0, =CCM_BASE_ADDR
  145. ldr r1, =0x19239145
  146. str r1, [r0, #CLKCTL_CBCDR]
  147. ldr r1, =0x000020C0
  148. orr r1,r1,#CONFIG_SYS_DDR_CLKSEL
  149. str r1, [r0, #CLKCTL_CBCMR]
  150. mov r3, #DP_OP_216
  151. mov r4, #DP_MFD_216
  152. mov r5, #DP_MFN_216
  153. setup_pll PLL3_BASE_ADDR
  154. /* Set the platform clock dividers */
  155. ldr r0, =ARM_BASE_ADDR
  156. ldr r1, =0x00000725
  157. str r1, [r0, #0x14]
  158. ldr r0, =CCM_BASE_ADDR
  159. /* Run 3.0 at Full speed, for other TO's wait till we increase VDDGP */
  160. ldr r1, =0x0
  161. ldr r3, [r1, #ROM_SI_REV]
  162. cmp r3, #0x10
  163. movls r1, #0x1
  164. movhi r1, #0
  165. str r1, [r0, #CLKCTL_CACRR]
  166. /* Switch ARM back to PLL 1 */
  167. mov r1, #0
  168. str r1, [r0, #CLKCTL_CCSR]
  169. /* setup the rest */
  170. /* Use lp_apm (24MHz) source for perclk */
  171. ldr r1, =0x000020C2
  172. orr r1,r1,#CONFIG_SYS_DDR_CLKSEL
  173. str r1, [r0, #CLKCTL_CBCMR]
  174. /* ddr clock from PLL 1, all perclk dividers are 1 since using 24MHz */
  175. ldr r1, =CONFIG_SYS_CLKTL_CBCDR
  176. str r1, [r0, #CLKCTL_CBCDR]
  177. /* Restore the default values in the Gate registers */
  178. ldr r1, =0xFFFFFFFF
  179. str r1, [r0, #CLKCTL_CCGR0]
  180. str r1, [r0, #CLKCTL_CCGR1]
  181. str r1, [r0, #CLKCTL_CCGR2]
  182. str r1, [r0, #CLKCTL_CCGR3]
  183. str r1, [r0, #CLKCTL_CCGR4]
  184. str r1, [r0, #CLKCTL_CCGR5]
  185. str r1, [r0, #CLKCTL_CCGR6]
  186. /* Use PLL 2 for UART's, get 66.5MHz from it */
  187. ldr r1, =0xA5A2A020
  188. str r1, [r0, #CLKCTL_CSCMR1]
  189. ldr r1, =0x00C30321
  190. str r1, [r0, #CLKCTL_CSCDR1]
  191. /* make sure divider effective */
  192. 1: ldr r1, [r0, #CLKCTL_CDHIPR]
  193. cmp r1, #0x0
  194. bne 1b
  195. mov r1, #0x0
  196. str r1, [r0, #CLKCTL_CCDR]
  197. /* for cko - for ARM div by 8 */
  198. mov r1, #0x000A0000
  199. add r1, r1, #0x00000F0
  200. str r1, [r0, #CLKCTL_CCOSR]
  201. .endm
  202. .macro setup_wdog
  203. ldr r0, =WDOG1_BASE_ADDR
  204. mov r1, #0x30
  205. strh r1, [r0]
  206. .endm
  207. .section ".text.init", "x"
  208. .globl lowlevel_init
  209. lowlevel_init:
  210. ldr r0, =GPIO1_BASE_ADDR
  211. ldr r1, [r0, #0x0]
  212. orr r1, r1, #(1 << 23)
  213. str r1, [r0, #0x0]
  214. ldr r1, [r0, #0x4]
  215. orr r1, r1, #(1 << 23)
  216. str r1, [r0, #0x4]
  217. #ifdef ENABLE_IMPRECISE_ABORT
  218. mrs r1, spsr /* save old spsr */
  219. mrs r0, cpsr /* read out the cpsr */
  220. bic r0, r0, #0x100 /* clear the A bit */
  221. msr spsr, r0 /* update spsr */
  222. add lr, pc, #0x8 /* update lr */
  223. movs pc, lr /* update cpsr */
  224. nop
  225. nop
  226. nop
  227. nop
  228. msr spsr, r1 /* restore old spsr */
  229. #endif
  230. init_l2cc
  231. init_aips
  232. init_m4if
  233. init_clock
  234. /* r12 saved upper lr*/
  235. mov pc,lr
  236. /* Board level setting value */
  237. DDR_PERCHARGE_CMD: .word 0x04008008
  238. DDR_REFRESH_CMD: .word 0x00008010
  239. DDR_LMR1_W: .word 0x00338018
  240. DDR_LMR_CMD: .word 0xB2220000
  241. DDR_TIMING_W: .word 0xB02567A9
  242. DDR_MISC_W: .word 0x000A0104