lowlevel_init.S 8.3 KB

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