lowlevel_init.S 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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. * See file CREDITS for list of people who contributed to this
  11. * project.
  12. *
  13. * This program is free software; you can redistribute it and/or
  14. * modify it under the terms of the GNU General Public License as
  15. * published by the Free Software Foundation; either version 2 of
  16. * the License, or (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program; if not, write to the Free Software
  25. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  26. * MA 02111-1307 USA
  27. */
  28. #include <config.h>
  29. #include <version.h>
  30. #include <asm/arch/hardware.h>
  31. #include <asm/arch/at91_pmc.h>
  32. #include <asm/arch/at91_pio.h>
  33. #include <asm/arch/at91_rstc.h>
  34. #include <asm/arch/at91_wdt.h>
  35. #include <asm/arch/at91sam9_matrix.h>
  36. #include <asm/arch/at91sam9_sdramc.h>
  37. #include <asm/arch/at91sam9_smc.h>
  38. _TEXT_BASE:
  39. .word TEXT_BASE
  40. .globl lowlevel_init
  41. .type lowlevel_init,function
  42. lowlevel_init:
  43. mov r5, pc /* r5 = POS1 + 4 current */
  44. POS1:
  45. ldr r0, =POS1 /* r0 = POS1 compile */
  46. ldr r2, _TEXT_BASE
  47. sub r0, r0, r2 /* r0 = POS1-_TEXT_BASE (POS1 relative) */
  48. sub r5, r5, r0 /* r0 = TEXT_BASE-1 */
  49. sub r5, r5, #4 /* r1 = text base - current */
  50. /* memory control configuration 1 */
  51. ldr r0, =SMRDATA
  52. ldr r2, =SMRDATA1
  53. ldr r1, _TEXT_BASE
  54. sub r0, r0, r1
  55. sub r2, r2, r1
  56. add r0, r0, r5
  57. add r2, r2, r5
  58. 0:
  59. /* the address */
  60. ldr r1, [r0], #4
  61. /* the value */
  62. ldr r3, [r0], #4
  63. str r3, [r1]
  64. cmp r2, r0
  65. bne 0b
  66. /* ----------------------------------------------------------------------------
  67. * PMC Init Step 1.
  68. * ----------------------------------------------------------------------------
  69. * - Check if the PLL is already initialized
  70. * ----------------------------------------------------------------------------
  71. */
  72. ldr r1, =(AT91_BASE_SYS + AT91_PMC_MCKR)
  73. ldr r0, [r1]
  74. and r0, r0, #3
  75. cmp r0, #0
  76. bne PLL_setup_end
  77. /* ---------------------------------------------------------------------------
  78. * - Enable the Main Oscillator
  79. * ---------------------------------------------------------------------------
  80. */
  81. ldr r1, =(AT91_BASE_SYS + AT91_CKGR_MOR)
  82. ldr r2, =(AT91_BASE_SYS + AT91_PMC_SR)
  83. /* Main oscillator Enable register PMC_MOR: */
  84. ldr r0, =CONFIG_SYS_MOR_VAL
  85. str r0, [r1]
  86. /* Reading the PMC Status to detect when the Main Oscillator is enabled */
  87. mov r4, #AT91_PMC_MOSCS
  88. MOSCS_Loop:
  89. ldr r3, [r2]
  90. and r3, r4, r3
  91. cmp r3, #AT91_PMC_MOSCS
  92. bne MOSCS_Loop
  93. /* ----------------------------------------------------------------------------
  94. * PMC Init Step 2.
  95. * ----------------------------------------------------------------------------
  96. * Setup PLLA
  97. * ----------------------------------------------------------------------------
  98. */
  99. ldr r1, =(AT91_BASE_SYS + AT91_CKGR_PLLAR)
  100. ldr r0, =CONFIG_SYS_PLLAR_VAL
  101. str r0, [r1]
  102. /* Reading the PMC Status register to detect when the PLLA is locked */
  103. mov r4, #AT91_PMC_LOCKA
  104. MOSCS_Loop1:
  105. ldr r3, [r2]
  106. and r3, r4, r3
  107. cmp r3, #AT91_PMC_LOCKA
  108. bne MOSCS_Loop1
  109. /* ----------------------------------------------------------------------------
  110. * PMC Init Step 3.
  111. * ----------------------------------------------------------------------------
  112. * - Switch on the Main Oscillator
  113. * ----------------------------------------------------------------------------
  114. */
  115. ldr r1, =(AT91_BASE_SYS + AT91_PMC_MCKR)
  116. /* -Master Clock Controller register PMC_MCKR */
  117. ldr r0, =CONFIG_SYS_MCKR1_VAL
  118. str r0, [r1]
  119. /* Reading the PMC Status to detect when the Master clock is ready */
  120. mov r4, #AT91_PMC_MCKRDY
  121. MCKRDY_Loop:
  122. ldr r3, [r2]
  123. and r3, r4, r3
  124. cmp r3, #AT91_PMC_MCKRDY
  125. bne MCKRDY_Loop
  126. ldr r0, =CONFIG_SYS_MCKR2_VAL
  127. str r0, [r1]
  128. /* Reading the PMC Status to detect when the Master clock is ready */
  129. mov r4, #AT91_PMC_MCKRDY
  130. MCKRDY_Loop1:
  131. ldr r3, [r2]
  132. and r3, r4, r3
  133. cmp r3, #AT91_PMC_MCKRDY
  134. bne MCKRDY_Loop1
  135. PLL_setup_end:
  136. /* ----------------------------------------------------------------------------
  137. * - memory control configuration 2
  138. * ----------------------------------------------------------------------------
  139. */
  140. ldr r0, =(AT91_BASE_SYS + AT91_SDRAMC_TR)
  141. ldr r1, [r0]
  142. cmp r1, #0
  143. bne SDRAM_setup_end
  144. ldr r0, =SMRDATA1
  145. ldr r2, =SMRDATA2
  146. ldr r1, _TEXT_BASE
  147. sub r0, r0, r1
  148. sub r2, r2, r1
  149. add r0, r0, r5
  150. add r2, r2, r5
  151. 2:
  152. /* the address */
  153. ldr r1, [r0], #4
  154. /* the value */
  155. ldr r3, [r0], #4
  156. str r3, [r1]
  157. cmp r2, r0
  158. bne 2b
  159. SDRAM_setup_end:
  160. /* everything is fine now */
  161. mov pc, lr
  162. .ltorg
  163. SMRDATA:
  164. .word (AT91_BASE_SYS + AT91_WDT_MR)
  165. .word CONFIG_SYS_WDTC_WDMR_VAL
  166. /* configure PIOx as EBI0 D[16-31] */
  167. #if defined(CONFIG_AT91SAM9263)
  168. .word (AT91_BASE_SYS + AT91_PIOD + PIO_PDR)
  169. .word CONFIG_SYS_PIOD_PDR_VAL1
  170. .word (AT91_BASE_SYS + AT91_PIOD + PIO_PUDR)
  171. .word CONFIG_SYS_PIOD_PPUDR_VAL
  172. .word (AT91_BASE_SYS + AT91_PIOD + PIO_ASR)
  173. .word CONFIG_SYS_PIOD_PPUDR_VAL
  174. #elif defined(CONFIG_AT91SAM9261)
  175. .word (AT91_BASE_SYS + AT91_PIOC + PIO_PDR)
  176. .word CONFIG_SYS_PIOC_PDR_VAL1
  177. .word (AT91_BASE_SYS + AT91_PIOC + PIO_PUDR)
  178. .word CONFIG_SYS_PIOC_PPUDR_VAL
  179. #endif
  180. #if defined(AT91_MATRIX_EBI0CSA)
  181. .word (AT91_BASE_SYS + AT91_MATRIX_EBI0CSA)
  182. .word CONFIG_SYS_MATRIX_EBI0CSA_VAL
  183. #else /* AT91_MATRIX_EBICSA */
  184. .word (AT91_BASE_SYS + AT91_MATRIX_EBICSA)
  185. .word CONFIG_SYS_MATRIX_EBICSA_VAL
  186. #endif
  187. /* flash */
  188. .word (AT91_BASE_SYS + AT91_SMC_MODE(0))
  189. .word CONFIG_SYS_SMC0_MODE0_VAL
  190. .word (AT91_BASE_SYS + AT91_SMC_CYCLE(0))
  191. .word CONFIG_SYS_SMC0_CYCLE0_VAL
  192. .word (AT91_BASE_SYS + AT91_SMC_PULSE(0))
  193. .word CONFIG_SYS_SMC0_PULSE0_VAL
  194. .word (AT91_BASE_SYS + AT91_SMC_SETUP(0))
  195. .word CONFIG_SYS_SMC0_SETUP0_VAL
  196. SMRDATA1:
  197. .word (AT91_BASE_SYS + AT91_SDRAMC_MR)
  198. .word CONFIG_SYS_SDRC_MR_VAL1
  199. .word (AT91_BASE_SYS + AT91_SDRAMC_TR)
  200. .word CONFIG_SYS_SDRC_TR_VAL1
  201. .word (AT91_BASE_SYS + AT91_SDRAMC_CR)
  202. .word CONFIG_SYS_SDRC_CR_VAL
  203. .word (AT91_BASE_SYS + AT91_SDRAMC_MDR)
  204. .word CONFIG_SYS_SDRC_MDR_VAL
  205. .word (AT91_BASE_SYS + AT91_SDRAMC_MR)
  206. .word CONFIG_SYS_SDRC_MR_VAL2
  207. .word AT91_SDRAM_BASE
  208. .word CONFIG_SYS_SDRAM_VAL1
  209. .word (AT91_BASE_SYS + AT91_SDRAMC_MR)
  210. .word CONFIG_SYS_SDRC_MR_VAL3
  211. .word AT91_SDRAM_BASE
  212. .word CONFIG_SYS_SDRAM_VAL2
  213. .word AT91_SDRAM_BASE
  214. .word CONFIG_SYS_SDRAM_VAL3
  215. .word AT91_SDRAM_BASE
  216. .word CONFIG_SYS_SDRAM_VAL4
  217. .word AT91_SDRAM_BASE
  218. .word CONFIG_SYS_SDRAM_VAL5
  219. .word AT91_SDRAM_BASE
  220. .word CONFIG_SYS_SDRAM_VAL6
  221. .word AT91_SDRAM_BASE
  222. .word CONFIG_SYS_SDRAM_VAL7
  223. .word AT91_SDRAM_BASE
  224. .word CONFIG_SYS_SDRAM_VAL8
  225. .word AT91_SDRAM_BASE
  226. .word CONFIG_SYS_SDRAM_VAL9
  227. .word (AT91_BASE_SYS + AT91_SDRAMC_MR)
  228. .word CONFIG_SYS_SDRC_MR_VAL4
  229. .word AT91_SDRAM_BASE
  230. .word CONFIG_SYS_SDRAM_VAL10
  231. .word (AT91_BASE_SYS + AT91_SDRAMC_MR)
  232. .word CONFIG_SYS_SDRC_MR_VAL5
  233. .word AT91_SDRAM_BASE
  234. .word CONFIG_SYS_SDRAM_VAL11
  235. .word (AT91_BASE_SYS + AT91_SDRAMC_TR)
  236. .word CONFIG_SYS_SDRC_TR_VAL2
  237. .word AT91_SDRAM_BASE
  238. .word CONFIG_SYS_SDRAM_VAL12
  239. /* User reset enable*/
  240. .word (AT91_BASE_SYS + AT91_RSTC_MR)
  241. .word CONFIG_SYS_RSTC_RMR_VAL
  242. #ifdef CONFIG_SYS_MATRIX_MCFG_REMAP
  243. /* MATRIX_MCFG - REMAP all masters */
  244. .word (AT91_BASE_SYS + AT91_MATRIX_MCFG0)
  245. .word 0x1FF
  246. #endif
  247. SMRDATA2:
  248. .word 0