start.S 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. /*
  2. * armboot - Startup Code for OMAP3530/ARM Cortex CPU-core
  3. *
  4. * Copyright (c) 2004 Texas Instruments <r-woodruff2@ti.com>
  5. *
  6. * Copyright (c) 2001 Marius Gröger <mag@sysgo.de>
  7. * Copyright (c) 2002 Alex Züpke <azu@sysgo.de>
  8. * Copyright (c) 2002 Gary Jennejohn <garyj@denx.de>
  9. * Copyright (c) 2003 Richard Woodruff <r-woodruff2@ti.com>
  10. * Copyright (c) 2003 Kshitij <kshitij@ti.com>
  11. * Copyright (c) 2006-2008 Syed Mohammed Khasim <x0khasim@ti.com>
  12. *
  13. * SPDX-License-Identifier: GPL-2.0+
  14. */
  15. #include <asm-offsets.h>
  16. #include <config.h>
  17. #include <asm/system.h>
  18. #include <linux/linkage.h>
  19. /*************************************************************************
  20. *
  21. * Startup Code (reset vector)
  22. *
  23. * Do important init only if we don't start from memory!
  24. * Setup memory and board specific bits prior to relocation.
  25. * Relocate armboot to ram. Setup stack.
  26. *
  27. *************************************************************************/
  28. .globl reset
  29. .globl save_boot_params_ret
  30. reset:
  31. /* Allow the board to save important registers */
  32. b save_boot_params
  33. save_boot_params_ret:
  34. /*
  35. * disable interrupts (FIQ and IRQ), also set the cpu to SVC32 mode,
  36. * except if in HYP mode already
  37. */
  38. mrs r0, cpsr
  39. and r1, r0, #0x1f @ mask mode bits
  40. teq r1, #0x1a @ test for HYP mode
  41. bicne r0, r0, #0x1f @ clear all mode bits
  42. orrne r0, r0, #0x13 @ set SVC mode
  43. orr r0, r0, #0xc0 @ disable FIQ and IRQ
  44. msr cpsr,r0
  45. /*
  46. * Setup vector:
  47. * (OMAP4 spl TEXT_BASE is not 32 byte aligned.
  48. * Continue to use ROM code vector only in OMAP4 spl)
  49. */
  50. #if !(defined(CONFIG_OMAP44XX) && defined(CONFIG_SPL_BUILD))
  51. /* Set V=0 in CP15 SCTLR register - for VBAR to point to vector */
  52. mrc p15, 0, r0, c1, c0, 0 @ Read CP15 SCTLR Register
  53. bic r0, #CR_V @ V = 0
  54. mcr p15, 0, r0, c1, c0, 0 @ Write CP15 SCTLR Register
  55. /* Set vector address in CP15 VBAR register */
  56. ldr r0, =_start
  57. mcr p15, 0, r0, c12, c0, 0 @Set VBAR
  58. #endif
  59. /* the mask ROM code should have PLL and others stable */
  60. #ifndef CONFIG_SKIP_LOWLEVEL_INIT
  61. bl cpu_init_cp15
  62. bl cpu_init_crit
  63. #endif
  64. bl _main
  65. /*------------------------------------------------------------------------------*/
  66. ENTRY(c_runtime_cpu_setup)
  67. /*
  68. * If I-cache is enabled invalidate it
  69. */
  70. #ifndef CONFIG_SYS_ICACHE_OFF
  71. mcr p15, 0, r0, c7, c5, 0 @ invalidate icache
  72. mcr p15, 0, r0, c7, c10, 4 @ DSB
  73. mcr p15, 0, r0, c7, c5, 4 @ ISB
  74. #endif
  75. bx lr
  76. ENDPROC(c_runtime_cpu_setup)
  77. /*************************************************************************
  78. *
  79. * void save_boot_params(u32 r0, u32 r1, u32 r2, u32 r3)
  80. * __attribute__((weak));
  81. *
  82. * Stack pointer is not yet initialized at this moment
  83. * Don't save anything to stack even if compiled with -O0
  84. *
  85. *************************************************************************/
  86. ENTRY(save_boot_params)
  87. b save_boot_params_ret @ back to my caller
  88. ENDPROC(save_boot_params)
  89. .weak save_boot_params
  90. /*************************************************************************
  91. *
  92. * cpu_init_cp15
  93. *
  94. * Setup CP15 registers (cache, MMU, TLBs). The I-cache is turned on unless
  95. * CONFIG_SYS_ICACHE_OFF is defined.
  96. *
  97. *************************************************************************/
  98. ENTRY(cpu_init_cp15)
  99. /*
  100. * Invalidate L1 I/D
  101. */
  102. mov r0, #0 @ set up for MCR
  103. mcr p15, 0, r0, c8, c7, 0 @ invalidate TLBs
  104. mcr p15, 0, r0, c7, c5, 0 @ invalidate icache
  105. mcr p15, 0, r0, c7, c5, 6 @ invalidate BP array
  106. mcr p15, 0, r0, c7, c10, 4 @ DSB
  107. mcr p15, 0, r0, c7, c5, 4 @ ISB
  108. /*
  109. * disable MMU stuff and caches
  110. */
  111. mrc p15, 0, r0, c1, c0, 0
  112. bic r0, r0, #0x00002000 @ clear bits 13 (--V-)
  113. bic r0, r0, #0x00000007 @ clear bits 2:0 (-CAM)
  114. orr r0, r0, #0x00000002 @ set bit 1 (--A-) Align
  115. orr r0, r0, #0x00000800 @ set bit 11 (Z---) BTB
  116. #ifdef CONFIG_SYS_ICACHE_OFF
  117. bic r0, r0, #0x00001000 @ clear bit 12 (I) I-cache
  118. #else
  119. orr r0, r0, #0x00001000 @ set bit 12 (I) I-cache
  120. #endif
  121. mcr p15, 0, r0, c1, c0, 0
  122. #ifdef CONFIG_ARM_ERRATA_716044
  123. mrc p15, 0, r0, c1, c0, 0 @ read system control register
  124. orr r0, r0, #1 << 11 @ set bit #11
  125. mcr p15, 0, r0, c1, c0, 0 @ write system control register
  126. #endif
  127. #if (defined(CONFIG_ARM_ERRATA_742230) || defined(CONFIG_ARM_ERRATA_794072))
  128. mrc p15, 0, r0, c15, c0, 1 @ read diagnostic register
  129. orr r0, r0, #1 << 4 @ set bit #4
  130. mcr p15, 0, r0, c15, c0, 1 @ write diagnostic register
  131. #endif
  132. #ifdef CONFIG_ARM_ERRATA_743622
  133. mrc p15, 0, r0, c15, c0, 1 @ read diagnostic register
  134. orr r0, r0, #1 << 6 @ set bit #6
  135. mcr p15, 0, r0, c15, c0, 1 @ write diagnostic register
  136. #endif
  137. #ifdef CONFIG_ARM_ERRATA_751472
  138. mrc p15, 0, r0, c15, c0, 1 @ read diagnostic register
  139. orr r0, r0, #1 << 11 @ set bit #11
  140. mcr p15, 0, r0, c15, c0, 1 @ write diagnostic register
  141. #endif
  142. #ifdef CONFIG_ARM_ERRATA_761320
  143. mrc p15, 0, r0, c15, c0, 1 @ read diagnostic register
  144. orr r0, r0, #1 << 21 @ set bit #21
  145. mcr p15, 0, r0, c15, c0, 1 @ write diagnostic register
  146. #endif
  147. mov r5, lr @ Store my Caller
  148. mrc p15, 0, r1, c0, c0, 0 @ r1 has Read Main ID Register (MIDR)
  149. mov r3, r1, lsr #20 @ get variant field
  150. and r3, r3, #0xf @ r3 has CPU variant
  151. and r4, r1, #0xf @ r4 has CPU revision
  152. mov r2, r3, lsl #4 @ shift variant field for combined value
  153. orr r2, r4, r2 @ r2 has combined CPU variant + revision
  154. #ifdef CONFIG_ARM_ERRATA_798870
  155. cmp r2, #0x30 @ Applies to lower than R3p0
  156. bge skip_errata_798870 @ skip if not affected rev
  157. cmp r2, #0x20 @ Applies to including and above R2p0
  158. blt skip_errata_798870 @ skip if not affected rev
  159. mrc p15, 1, r0, c15, c0, 0 @ read l2 aux ctrl reg
  160. orr r0, r0, #1 << 7 @ Enable hazard-detect timeout
  161. push {r1-r5} @ Save the cpu info registers
  162. bl v7_arch_cp15_set_l2aux_ctrl
  163. isb @ Recommended ISB after l2actlr update
  164. pop {r1-r5} @ Restore the cpu info - fall through
  165. skip_errata_798870:
  166. #endif
  167. #ifdef CONFIG_ARM_ERRATA_454179
  168. cmp r2, #0x21 @ Only on < r2p1
  169. bge skip_errata_454179
  170. mrc p15, 0, r0, c1, c0, 1 @ Read ACR
  171. orr r0, r0, #(0x3 << 6) @ Set DBSM(BIT7) and IBE(BIT6) bits
  172. push {r1-r5} @ Save the cpu info registers
  173. bl v7_arch_cp15_set_acr
  174. pop {r1-r5} @ Restore the cpu info - fall through
  175. skip_errata_454179:
  176. #endif
  177. #ifdef CONFIG_ARM_ERRATA_430973
  178. cmp r2, #0x21 @ Only on < r2p1
  179. bge skip_errata_430973
  180. mrc p15, 0, r0, c1, c0, 1 @ Read ACR
  181. orr r0, r0, #(0x1 << 6) @ Set IBE bit
  182. push {r1-r5} @ Save the cpu info registers
  183. bl v7_arch_cp15_set_acr
  184. pop {r1-r5} @ Restore the cpu info - fall through
  185. skip_errata_430973:
  186. #endif
  187. #ifdef CONFIG_ARM_ERRATA_621766
  188. cmp r2, #0x21 @ Only on < r2p1
  189. bge skip_errata_621766
  190. mrc p15, 0, r0, c1, c0, 1 @ Read ACR
  191. orr r0, r0, #(0x1 << 5) @ Set L1NEON bit
  192. push {r1-r5} @ Save the cpu info registers
  193. bl v7_arch_cp15_set_acr
  194. pop {r1-r5} @ Restore the cpu info - fall through
  195. skip_errata_621766:
  196. #endif
  197. mov pc, r5 @ back to my caller
  198. ENDPROC(cpu_init_cp15)
  199. #ifndef CONFIG_SKIP_LOWLEVEL_INIT
  200. /*************************************************************************
  201. *
  202. * CPU_init_critical registers
  203. *
  204. * setup important registers
  205. * setup memory timing
  206. *
  207. *************************************************************************/
  208. ENTRY(cpu_init_crit)
  209. /*
  210. * Jump to board specific initialization...
  211. * The Mask ROM will have already initialized
  212. * basic memory. Go here to bump up clock rate and handle
  213. * wake up conditions.
  214. */
  215. b lowlevel_init @ go setup pll,mux,memory
  216. ENDPROC(cpu_init_crit)
  217. #endif