lowlevel_init.S 6.3 KB

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