lowlevel_init.S 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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 <asm/arch/hardware.h>
  30. #include <asm/arch/at91_pmc.h>
  31. #include <asm/arch/at91_wdt.h>
  32. #include <asm/arch/at91_pio.h>
  33. #include <asm/arch/at91_matrix.h>
  34. #include <asm/arch/at91sam9_sdramc.h>
  35. #include <asm/arch/at91sam9_smc.h>
  36. #include <asm/arch/at91_rstc.h>
  37. #ifdef CONFIG_AT91_LEGACY
  38. #include <asm/arch/at91sam9_matrix.h>
  39. #endif
  40. #ifndef CONFIG_SYS_MATRIX_EBICSA_VAL
  41. #define CONFIG_SYS_MATRIX_EBICSA_VAL CONFIG_SYS_MATRIX_EBI0CSA_VAL
  42. #endif
  43. _TEXT_BASE:
  44. .word CONFIG_SYS_TEXT_BASE
  45. .globl lowlevel_init
  46. .type lowlevel_init,function
  47. lowlevel_init:
  48. mov r5, pc /* r5 = POS1 + 4 current */
  49. POS1:
  50. ldr r0, =POS1 /* r0 = POS1 compile */
  51. ldr r2, _TEXT_BASE
  52. sub r0, r0, r2 /* r0 = POS1-_TEXT_BASE (POS1 relative) */
  53. sub r5, r5, r0 /* r0 = CONFIG_SYS_TEXT_BASE-1 */
  54. sub r5, r5, #4 /* r1 = text base - current */
  55. /* memory control configuration 1 */
  56. ldr r0, =SMRDATA
  57. ldr r2, =SMRDATA1
  58. ldr r1, _TEXT_BASE
  59. sub r0, r0, r1
  60. sub r2, r2, r1
  61. add r0, r0, r5
  62. add r2, r2, r5
  63. 0:
  64. /* the address */
  65. ldr r1, [r0], #4
  66. /* the value */
  67. ldr r3, [r0], #4
  68. str r3, [r1]
  69. cmp r2, r0
  70. bne 0b
  71. /* ----------------------------------------------------------------------------
  72. * PMC Init Step 1.
  73. * ----------------------------------------------------------------------------
  74. * - Check if the PLL is already initialized
  75. * ----------------------------------------------------------------------------
  76. */
  77. ldr r1, =(AT91_ASM_PMC_MCKR)
  78. ldr r0, [r1]
  79. and r0, r0, #3
  80. cmp r0, #0
  81. bne PLL_setup_end
  82. /* ---------------------------------------------------------------------------
  83. * - Enable the Main Oscillator
  84. * ---------------------------------------------------------------------------
  85. */
  86. ldr r1, =(AT91_ASM_PMC_MOR)
  87. ldr r2, =(AT91_ASM_PMC_SR)
  88. /* Main oscillator Enable register PMC_MOR: */
  89. ldr r0, =CONFIG_SYS_MOR_VAL
  90. str r0, [r1]
  91. /* Reading the PMC Status to detect when the Main Oscillator is enabled */
  92. mov r4, #AT91_PMC_IXR_MOSCS
  93. MOSCS_Loop:
  94. ldr r3, [r2]
  95. and r3, r4, r3
  96. cmp r3, #AT91_PMC_IXR_MOSCS
  97. bne MOSCS_Loop
  98. /* ----------------------------------------------------------------------------
  99. * PMC Init Step 2.
  100. * ----------------------------------------------------------------------------
  101. * Setup PLLA
  102. * ----------------------------------------------------------------------------
  103. */
  104. ldr r1, =(AT91_ASM_PMC_PLLAR)
  105. ldr r0, =CONFIG_SYS_PLLAR_VAL
  106. str r0, [r1]
  107. /* Reading the PMC Status register to detect when the PLLA is locked */
  108. mov r4, #AT91_PMC_IXR_LOCKA
  109. MOSCS_Loop1:
  110. ldr r3, [r2]
  111. and r3, r4, r3
  112. cmp r3, #AT91_PMC_IXR_LOCKA
  113. bne MOSCS_Loop1
  114. /* ----------------------------------------------------------------------------
  115. * PMC Init Step 3.
  116. * ----------------------------------------------------------------------------
  117. * - Switch on the Main Oscillator
  118. * ----------------------------------------------------------------------------
  119. */
  120. ldr r1, =(AT91_ASM_PMC_MCKR)
  121. /* -Master Clock Controller register PMC_MCKR */
  122. ldr r0, =CONFIG_SYS_MCKR1_VAL
  123. str r0, [r1]
  124. /* Reading the PMC Status to detect when the Master clock is ready */
  125. mov r4, #AT91_PMC_IXR_MCKRDY
  126. MCKRDY_Loop:
  127. ldr r3, [r2]
  128. and r3, r4, r3
  129. cmp r3, #AT91_PMC_IXR_MCKRDY
  130. bne MCKRDY_Loop
  131. ldr r0, =CONFIG_SYS_MCKR2_VAL
  132. str r0, [r1]
  133. /* Reading the PMC Status to detect when the Master clock is ready */
  134. mov r4, #AT91_PMC_IXR_MCKRDY
  135. MCKRDY_Loop1:
  136. ldr r3, [r2]
  137. and r3, r4, r3
  138. cmp r3, #AT91_PMC_IXR_MCKRDY
  139. bne MCKRDY_Loop1
  140. PLL_setup_end:
  141. /* ----------------------------------------------------------------------------
  142. * - memory control configuration 2
  143. * ----------------------------------------------------------------------------
  144. */
  145. ldr r0, =(AT91_ASM_SDRAMC_TR)
  146. ldr r1, [r0]
  147. cmp r1, #0
  148. bne SDRAM_setup_end
  149. ldr r0, =SMRDATA1
  150. ldr r2, =SMRDATA2
  151. ldr r1, _TEXT_BASE
  152. sub r0, r0, r1
  153. sub r2, r2, r1
  154. add r0, r0, r5
  155. add r2, r2, r5
  156. 2:
  157. /* the address */
  158. ldr r1, [r0], #4
  159. /* the value */
  160. ldr r3, [r0], #4
  161. str r3, [r1]
  162. cmp r2, r0
  163. bne 2b
  164. SDRAM_setup_end:
  165. /* everything is fine now */
  166. mov pc, lr
  167. .ltorg
  168. SMRDATA:
  169. .word AT91_ASM_WDT_MR
  170. .word CONFIG_SYS_WDTC_WDMR_VAL
  171. /* configure PIOx as EBI0 D[16-31] */
  172. #if defined(CONFIG_AT91SAM9263)
  173. .word AT91_ASM_PIOD_PDR
  174. .word CONFIG_SYS_PIOD_PDR_VAL1
  175. .word AT91_ASM_PIOD_PUDR
  176. .word CONFIG_SYS_PIOD_PPUDR_VAL
  177. .word AT91_ASM_PIOD_ASR
  178. .word CONFIG_SYS_PIOD_PPUDR_VAL
  179. #elif defined(CONFIG_AT91SAM9260) || defined(CONFIG_AT91SAM9261) \
  180. || defined(CONFIG_AT91SAM9G20)
  181. .word AT91_ASM_PIOC_PDR
  182. .word CONFIG_SYS_PIOC_PDR_VAL1
  183. .word AT91_ASM_PIOC_PUDR
  184. .word CONFIG_SYS_PIOC_PPUDR_VAL
  185. #endif
  186. .word AT91_ASM_MATRIX_CSA0
  187. .word CONFIG_SYS_MATRIX_EBICSA_VAL
  188. /* flash */
  189. .word AT91_ASM_SMC_MODE0
  190. .word CONFIG_SYS_SMC0_MODE0_VAL
  191. .word AT91_ASM_SMC_CYCLE0
  192. .word CONFIG_SYS_SMC0_CYCLE0_VAL
  193. .word AT91_ASM_SMC_PULSE0
  194. .word CONFIG_SYS_SMC0_PULSE0_VAL
  195. .word AT91_ASM_SMC_SETUP0
  196. .word CONFIG_SYS_SMC0_SETUP0_VAL
  197. SMRDATA1:
  198. .word AT91_ASM_SDRAMC_MR
  199. .word CONFIG_SYS_SDRC_MR_VAL1
  200. .word AT91_ASM_SDRAMC_TR
  201. .word CONFIG_SYS_SDRC_TR_VAL1
  202. .word AT91_ASM_SDRAMC_CR
  203. .word CONFIG_SYS_SDRC_CR_VAL
  204. .word AT91_ASM_SDRAMC_MDR
  205. .word CONFIG_SYS_SDRC_MDR_VAL
  206. .word AT91_ASM_SDRAMC_MR
  207. .word CONFIG_SYS_SDRC_MR_VAL2
  208. .word AT91_SDRAM_BASE
  209. .word CONFIG_SYS_SDRAM_VAL1
  210. .word AT91_ASM_SDRAMC_MR
  211. .word CONFIG_SYS_SDRC_MR_VAL3
  212. .word AT91_SDRAM_BASE
  213. .word CONFIG_SYS_SDRAM_VAL2
  214. .word AT91_SDRAM_BASE
  215. .word CONFIG_SYS_SDRAM_VAL3
  216. .word AT91_SDRAM_BASE
  217. .word CONFIG_SYS_SDRAM_VAL4
  218. .word AT91_SDRAM_BASE
  219. .word CONFIG_SYS_SDRAM_VAL5
  220. .word AT91_SDRAM_BASE
  221. .word CONFIG_SYS_SDRAM_VAL6
  222. .word AT91_SDRAM_BASE
  223. .word CONFIG_SYS_SDRAM_VAL7
  224. .word AT91_SDRAM_BASE
  225. .word CONFIG_SYS_SDRAM_VAL8
  226. .word AT91_SDRAM_BASE
  227. .word CONFIG_SYS_SDRAM_VAL9
  228. .word AT91_ASM_SDRAMC_MR
  229. .word CONFIG_SYS_SDRC_MR_VAL4
  230. .word AT91_SDRAM_BASE
  231. .word CONFIG_SYS_SDRAM_VAL10
  232. .word AT91_ASM_SDRAMC_MR
  233. .word CONFIG_SYS_SDRC_MR_VAL5
  234. .word AT91_SDRAM_BASE
  235. .word CONFIG_SYS_SDRAM_VAL11
  236. .word AT91_ASM_SDRAMC_TR
  237. .word CONFIG_SYS_SDRC_TR_VAL2
  238. .word AT91_SDRAM_BASE
  239. .word CONFIG_SYS_SDRAM_VAL12
  240. /* User reset enable*/
  241. .word AT91_ASM_RSTC_MR
  242. .word CONFIG_SYS_RSTC_RMR_VAL
  243. #ifdef CONFIG_SYS_MATRIX_MCFG_REMAP
  244. /* MATRIX_MCFG - REMAP all masters */
  245. .word AT91_ASM_MATRIX_MCFG
  246. .word 0x1FF
  247. #endif
  248. SMRDATA2:
  249. .word 0