lowlevel_init.S 10.0 KB

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