lowlevel_init.S 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Memory Setup stuff - taken from blob memsetup.S
  4. *
  5. * Copyright (C) 1999 2000 2001 Erik Mouw (J.A.K.Mouw@its.tudelft.nl) and
  6. * Jan-Derk Bakker (J.D.Bakker@its.tudelft.nl)
  7. *
  8. * Copyright (C) 2008 Ronetix Ilko Iliev (www.ronetix.at)
  9. * Copyright (C) 2009 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
  10. */
  11. #include <config.h>
  12. #include <asm/arch/hardware.h>
  13. #include <asm/arch/at91_pmc.h>
  14. #include <asm/arch/at91_wdt.h>
  15. #include <asm/arch/at91_pio.h>
  16. #include <asm/arch/at91_matrix.h>
  17. #include <asm/arch/at91sam9_sdramc.h>
  18. #include <asm/arch/at91sam9_smc.h>
  19. #include <asm/arch/at91_rstc.h>
  20. #ifdef CONFIG_ATMEL_LEGACY
  21. #include <asm/arch/at91sam9_matrix.h>
  22. #endif
  23. #ifndef CONFIG_SYS_MATRIX_EBICSA_VAL
  24. #define CONFIG_SYS_MATRIX_EBICSA_VAL CONFIG_SYS_MATRIX_EBI0CSA_VAL
  25. #endif
  26. .globl lowlevel_init
  27. .type lowlevel_init,function
  28. lowlevel_init:
  29. POS1:
  30. adr r5, POS1 /* r5 = POS1 run time */
  31. ldr r0, =POS1 /* r0 = POS1 compile */
  32. sub r5, r5, r0 /* r0 = CONFIG_SYS_TEXT_BASE-1 */
  33. /* memory control configuration 1 */
  34. ldr r0, =SMRDATA
  35. ldr r2, =SMRDATA1
  36. add r0, r0, r5
  37. add r2, r2, r5
  38. 0:
  39. /* the address */
  40. ldr r1, [r0], #4
  41. /* the value */
  42. ldr r3, [r0], #4
  43. str r3, [r1]
  44. cmp r2, r0
  45. bne 0b
  46. /* ----------------------------------------------------------------------------
  47. * PMC Init Step 1.
  48. * ----------------------------------------------------------------------------
  49. * - Check if the PLL is already initialized
  50. * ----------------------------------------------------------------------------
  51. */
  52. ldr r1, =(AT91_ASM_PMC_MCKR)
  53. ldr r0, [r1]
  54. and r0, r0, #3
  55. cmp r0, #0
  56. bne PLL_setup_end
  57. /* ---------------------------------------------------------------------------
  58. * - Enable the Main Oscillator
  59. * ---------------------------------------------------------------------------
  60. */
  61. ldr r1, =(AT91_ASM_PMC_MOR)
  62. ldr r2, =(AT91_ASM_PMC_SR)
  63. /* Main oscillator Enable register PMC_MOR: */
  64. ldr r0, =CONFIG_SYS_MOR_VAL
  65. str r0, [r1]
  66. /* Reading the PMC Status to detect when the Main Oscillator is enabled */
  67. mov r4, #AT91_PMC_IXR_MOSCS
  68. MOSCS_Loop:
  69. ldr r3, [r2]
  70. and r3, r4, r3
  71. cmp r3, #AT91_PMC_IXR_MOSCS
  72. bne MOSCS_Loop
  73. /* ----------------------------------------------------------------------------
  74. * PMC Init Step 2.
  75. * ----------------------------------------------------------------------------
  76. * Setup PLLA
  77. * ----------------------------------------------------------------------------
  78. */
  79. ldr r1, =(AT91_ASM_PMC_PLLAR)
  80. ldr r0, =CONFIG_SYS_PLLAR_VAL
  81. str r0, [r1]
  82. /* Reading the PMC Status register to detect when the PLLA is locked */
  83. mov r4, #AT91_PMC_IXR_LOCKA
  84. MOSCS_Loop1:
  85. ldr r3, [r2]
  86. and r3, r4, r3
  87. cmp r3, #AT91_PMC_IXR_LOCKA
  88. bne MOSCS_Loop1
  89. /* ----------------------------------------------------------------------------
  90. * PMC Init Step 3.
  91. * ----------------------------------------------------------------------------
  92. * - Switch on the Main Oscillator
  93. * ----------------------------------------------------------------------------
  94. */
  95. ldr r1, =(AT91_ASM_PMC_MCKR)
  96. /* -Master Clock Controller register PMC_MCKR */
  97. ldr r0, =CONFIG_SYS_MCKR1_VAL
  98. str r0, [r1]
  99. /* Reading the PMC Status to detect when the Master clock is ready */
  100. mov r4, #AT91_PMC_IXR_MCKRDY
  101. MCKRDY_Loop:
  102. ldr r3, [r2]
  103. and r3, r4, r3
  104. cmp r3, #AT91_PMC_IXR_MCKRDY
  105. bne MCKRDY_Loop
  106. ldr r0, =CONFIG_SYS_MCKR2_VAL
  107. str r0, [r1]
  108. /* Reading the PMC Status to detect when the Master clock is ready */
  109. mov r4, #AT91_PMC_IXR_MCKRDY
  110. MCKRDY_Loop1:
  111. ldr r3, [r2]
  112. and r3, r4, r3
  113. cmp r3, #AT91_PMC_IXR_MCKRDY
  114. bne MCKRDY_Loop1
  115. PLL_setup_end:
  116. /* ----------------------------------------------------------------------------
  117. * - memory control configuration 2
  118. * ----------------------------------------------------------------------------
  119. */
  120. ldr r0, =(AT91_ASM_SDRAMC_TR)
  121. ldr r1, [r0]
  122. cmp r1, #0
  123. bne SDRAM_setup_end
  124. ldr r0, =SMRDATA1
  125. ldr r2, =SMRDATA2
  126. add r0, r0, r5
  127. add r2, r2, r5
  128. 2:
  129. /* the address */
  130. ldr r1, [r0], #4
  131. /* the value */
  132. ldr r3, [r0], #4
  133. str r3, [r1]
  134. cmp r2, r0
  135. bne 2b
  136. SDRAM_setup_end:
  137. /* everything is fine now */
  138. mov pc, lr
  139. .ltorg
  140. SMRDATA:
  141. .word AT91_ASM_WDT_MR
  142. .word CONFIG_SYS_WDTC_WDMR_VAL
  143. /* configure PIOx as EBI0 D[16-31] */
  144. #if defined(CONFIG_AT91SAM9263)
  145. .word AT91_ASM_PIOD_PDR
  146. .word CONFIG_SYS_PIOD_PDR_VAL1
  147. .word AT91_ASM_PIOD_PUDR
  148. .word CONFIG_SYS_PIOD_PPUDR_VAL
  149. .word AT91_ASM_PIOD_ASR
  150. .word CONFIG_SYS_PIOD_PPUDR_VAL
  151. #elif defined(CONFIG_AT91SAM9260) || defined(CONFIG_AT91SAM9261) \
  152. || defined(CONFIG_AT91SAM9G20)
  153. .word AT91_ASM_PIOC_PDR
  154. .word CONFIG_SYS_PIOC_PDR_VAL1
  155. .word AT91_ASM_PIOC_PUDR
  156. .word CONFIG_SYS_PIOC_PPUDR_VAL
  157. #endif
  158. .word AT91_ASM_MATRIX_CSA0
  159. .word CONFIG_SYS_MATRIX_EBICSA_VAL
  160. /* flash */
  161. .word AT91_ASM_SMC_MODE0
  162. .word CONFIG_SYS_SMC0_MODE0_VAL
  163. .word AT91_ASM_SMC_CYCLE0
  164. .word CONFIG_SYS_SMC0_CYCLE0_VAL
  165. .word AT91_ASM_SMC_PULSE0
  166. .word CONFIG_SYS_SMC0_PULSE0_VAL
  167. .word AT91_ASM_SMC_SETUP0
  168. .word CONFIG_SYS_SMC0_SETUP0_VAL
  169. SMRDATA1:
  170. .word AT91_ASM_SDRAMC_MR
  171. .word CONFIG_SYS_SDRC_MR_VAL1
  172. .word AT91_ASM_SDRAMC_TR
  173. .word CONFIG_SYS_SDRC_TR_VAL1
  174. .word AT91_ASM_SDRAMC_CR
  175. .word CONFIG_SYS_SDRC_CR_VAL
  176. .word AT91_ASM_SDRAMC_MDR
  177. .word CONFIG_SYS_SDRC_MDR_VAL
  178. .word AT91_ASM_SDRAMC_MR
  179. .word CONFIG_SYS_SDRC_MR_VAL2
  180. .word CONFIG_SYS_SDRAM_BASE
  181. .word CONFIG_SYS_SDRAM_VAL1
  182. .word AT91_ASM_SDRAMC_MR
  183. .word CONFIG_SYS_SDRC_MR_VAL3
  184. .word CONFIG_SYS_SDRAM_BASE
  185. .word CONFIG_SYS_SDRAM_VAL2
  186. .word CONFIG_SYS_SDRAM_BASE
  187. .word CONFIG_SYS_SDRAM_VAL3
  188. .word CONFIG_SYS_SDRAM_BASE
  189. .word CONFIG_SYS_SDRAM_VAL4
  190. .word CONFIG_SYS_SDRAM_BASE
  191. .word CONFIG_SYS_SDRAM_VAL5
  192. .word CONFIG_SYS_SDRAM_BASE
  193. .word CONFIG_SYS_SDRAM_VAL6
  194. .word CONFIG_SYS_SDRAM_BASE
  195. .word CONFIG_SYS_SDRAM_VAL7
  196. .word CONFIG_SYS_SDRAM_BASE
  197. .word CONFIG_SYS_SDRAM_VAL8
  198. .word CONFIG_SYS_SDRAM_BASE
  199. .word CONFIG_SYS_SDRAM_VAL9
  200. .word AT91_ASM_SDRAMC_MR
  201. .word CONFIG_SYS_SDRC_MR_VAL4
  202. .word CONFIG_SYS_SDRAM_BASE
  203. .word CONFIG_SYS_SDRAM_VAL10
  204. .word AT91_ASM_SDRAMC_MR
  205. .word CONFIG_SYS_SDRC_MR_VAL5
  206. .word CONFIG_SYS_SDRAM_BASE
  207. .word CONFIG_SYS_SDRAM_VAL11
  208. .word AT91_ASM_SDRAMC_TR
  209. .word CONFIG_SYS_SDRC_TR_VAL2
  210. .word CONFIG_SYS_SDRAM_BASE
  211. .word CONFIG_SYS_SDRAM_VAL12
  212. /* User reset enable*/
  213. .word AT91_ASM_RSTC_MR
  214. .word CONFIG_SYS_RSTC_RMR_VAL
  215. #ifdef CONFIG_SYS_MATRIX_MCFG_REMAP
  216. /* MATRIX_MCFG - REMAP all masters */
  217. .word AT91_ASM_MATRIX_MCFG
  218. .word 0x1FF
  219. #endif
  220. SMRDATA2:
  221. .word 0