lowlevel_init.S 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. /*
  2. * Copyright (C) 2010 Albert ARIBAUD <albert.aribaud@free.fr>
  3. *
  4. * (C) Copyright 2009
  5. * Marvell Semiconductor <www.marvell.com>
  6. * Written-by: Prafulla Wadaskar <prafulla@marvell.com>
  7. *
  8. * See file CREDITS for list of people who contributed to this
  9. * project.
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License as
  13. * published by the Free Software Foundation; either version 2 of
  14. * the License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  24. * MA 02110-1301 USA
  25. */
  26. #include <config.h>
  27. #include "asm/arch/orion5x.h"
  28. /*
  29. * Configuration values for SDRAM access setup
  30. */
  31. #define SDRAM_CONFIG 0x3148400
  32. #define SDRAM_MODE 0x62
  33. #define SDRAM_CONTROL 0x4041000
  34. #define SDRAM_TIME_CTRL_LOW 0x11602220
  35. #define SDRAM_TIME_CTRL_HI 0x40c
  36. #define SDRAM_OPEN_PAGE_EN 0x0
  37. /* DDR 1 2x 32M NANYA NT5DS16M16CS-6K ==> 64MB */
  38. #define SDRAM_BANK0_SIZE 0x3ff0001
  39. #define SDRAM_ADDR_CTRL 0x10
  40. #define SDRAM_OP_NOP 0x05
  41. #define SDRAM_OP_SETMODE 0x03
  42. #define SDRAM_PAD_CTRL_WR_EN 0x80000000
  43. #define SDRAM_PAD_CTRL_TUNE_EN 0x00010000
  44. #define SDRAM_PAD_CTRL_DRVN_MASK 0x0000003f
  45. #define SDRAM_PAD_CTRL_DRVP_MASK 0x00000fc0
  46. /*
  47. * For Guideline MEM-3 - Drive Strength value
  48. */
  49. #define DDR1_PAD_STRENGTH_DEFAULT 0x00001000
  50. #define SDRAM_PAD_CTRL_DRV_STR_MASK 0x00003000
  51. /*
  52. * For Guideline MEM-4 - DQS Reference Delay Tuning
  53. */
  54. #define MSAR_ARMDDRCLCK_MASK 0x000000f0
  55. #define MSAR_ARMDDRCLCK_H_MASK 0x00000100
  56. #define MSAR_ARMDDRCLCK_333_167 0x00000000
  57. #define MSAR_ARMDDRCLCK_500_167 0x00000030
  58. #define MSAR_ARMDDRCLCK_667_167 0x00000060
  59. #define MSAR_ARMDDRCLCK_400_200_1 0x000001E0
  60. #define MSAR_ARMDDRCLCK_400_200 0x00000010
  61. #define MSAR_ARMDDRCLCK_600_200 0x00000050
  62. #define MSAR_ARMDDRCLCK_800_200 0x00000070
  63. #define FTDLL_DDR1_166MHZ 0x0047F001
  64. #define FTDLL_DDR1_200MHZ 0x0044D001
  65. /*
  66. * Low-level init happens right after start.S has switched to SVC32,
  67. * flushed and disabled caches and disabled MMU. We're still running
  68. * from the boot chip select, so the first thing we should do is set
  69. * up RAM for us to relocate into.
  70. */
  71. .globl lowlevel_init
  72. lowlevel_init:
  73. /* Use 'r4 as the base for internal register accesses */
  74. ldr r4, =ORION5X_REGS_PHY_BASE
  75. /* move internal registers from the default 0xD0000000
  76. * to their intended location, defined by SoC */
  77. ldr r3, =0xD0000000
  78. add r3, r3, #0x20000
  79. str r4, [r3, #0x80]
  80. /* Use R3 as the base for DRAM registers */
  81. add r3, r4, #0x01000
  82. /*DDR SDRAM Initialization Control */
  83. ldr r6, =0x00000001
  84. str r6, [r3, #0x480]
  85. /* Use R3 as the base for PCI registers */
  86. add r3, r4, #0x31000
  87. /* Disable arbiter */
  88. ldr r6, =0x00000030
  89. str r6, [r3, #0xd00]
  90. /* Use R3 as the base for DRAM registers */
  91. add r3, r4, #0x01000
  92. /* set all dram windows to 0 */
  93. mov r6, #0
  94. str r6, [r3, #0x504]
  95. str r6, [r3, #0x50C]
  96. str r6, [r3, #0x514]
  97. str r6, [r3, #0x51C]
  98. /* 1) Configure SDRAM */
  99. ldr r6, =SDRAM_CONFIG
  100. str r6, [r3, #0x400]
  101. /* 2) Set SDRAM Control reg */
  102. ldr r6, =SDRAM_CONTROL
  103. str r6, [r3, #0x404]
  104. /* 3) Write SDRAM address control register */
  105. ldr r6, =SDRAM_ADDR_CTRL
  106. str r6, [r3, #0x410]
  107. /* 4) Write SDRAM bank 0 size register */
  108. ldr r6, =SDRAM_BANK0_SIZE
  109. str r6, [r3, #0x504]
  110. /* keep other banks disabled */
  111. /* 5) Write SDRAM open pages control register */
  112. ldr r6, =SDRAM_OPEN_PAGE_EN
  113. str r6, [r3, #0x414]
  114. /* 6) Write SDRAM timing Low register */
  115. ldr r6, =SDRAM_TIME_CTRL_LOW
  116. str r6, [r3, #0x408]
  117. /* 7) Write SDRAM timing High register */
  118. ldr r6, =SDRAM_TIME_CTRL_HI
  119. str r6, [r3, #0x40C]
  120. /* 8) Write SDRAM mode register */
  121. /* The CPU must not attempt to change the SDRAM Mode register setting */
  122. /* prior to DRAM controller completion of the DRAM initialization */
  123. /* sequence. To guarantee this restriction, it is recommended that */
  124. /* the CPU sets the SDRAM Operation register to NOP command, performs */
  125. /* read polling until the register is back in Normal operation value, */
  126. /* and then sets SDRAM Mode register to its new value. */
  127. /* 8.1 write 'nop' to SDRAM operation */
  128. ldr r6, =SDRAM_OP_NOP
  129. str r6, [r3, #0x418]
  130. /* 8.2 poll SDRAM operation until back in 'normal' mode. */
  131. 1:
  132. ldr r6, [r3, #0x418]
  133. cmp r6, #0
  134. bne 1b
  135. /* 8.3 Now its safe to write new value to SDRAM Mode register */
  136. ldr r6, =SDRAM_MODE
  137. str r6, [r3, #0x41C]
  138. /* 8.4 Set new mode */
  139. ldr r6, =SDRAM_OP_SETMODE
  140. str r6, [r3, #0x418]
  141. /* 8.5 poll SDRAM operation until back in 'normal' mode. */
  142. 2:
  143. ldr r6, [r3, #0x418]
  144. cmp r6, #0
  145. bne 2b
  146. /* DDR SDRAM Address/Control Pads Calibration */
  147. ldr r6, [r3, #0x4C0]
  148. /* Set Bit [31] to make the register writable */
  149. orr r6, r6, #SDRAM_PAD_CTRL_WR_EN
  150. str r6, [r3, #0x4C0]
  151. bic r6, r6, #SDRAM_PAD_CTRL_WR_EN
  152. bic r6, r6, #SDRAM_PAD_CTRL_TUNE_EN
  153. bic r6, r6, #SDRAM_PAD_CTRL_DRVN_MASK
  154. bic r6, r6, #SDRAM_PAD_CTRL_DRVP_MASK
  155. /* Get the final N locked value of driving strength [22:17] */
  156. mov r1, r6
  157. mov r1, r1, LSL #9
  158. mov r1, r1, LSR #26 /* r1[5:0]<DrvN> = r3[22:17]<LockN> */
  159. orr r1, r1, r1, LSL #6 /* r1[11:6]<DrvP> = r1[5:0]<DrvN> */
  160. /* Write to both <DrvN> bits [5:0] and <DrvP> bits [11:6] */
  161. orr r6, r6, r1
  162. str r6, [r3, #0x4C0]
  163. /* DDR SDRAM Data Pads Calibration */
  164. ldr r6, [r3, #0x4C4]
  165. /* Set Bit [31] to make the register writable */
  166. orr r6, r6, #SDRAM_PAD_CTRL_WR_EN
  167. str r6, [r3, #0x4C4]
  168. bic r6, r6, #SDRAM_PAD_CTRL_WR_EN
  169. bic r6, r6, #SDRAM_PAD_CTRL_TUNE_EN
  170. bic r6, r6, #SDRAM_PAD_CTRL_DRVN_MASK
  171. bic r6, r6, #SDRAM_PAD_CTRL_DRVP_MASK
  172. /* Get the final N locked value of driving strength [22:17] */
  173. mov r1, r6
  174. mov r1, r1, LSL #9
  175. mov r1, r1, LSR #26
  176. orr r1, r1, r1, LSL #6 /* r1[5:0] = r3[22:17]<LockN> */
  177. /* Write to both <DrvN> bits [5:0] and <DrvP> bits [11:6] */
  178. orr r6, r6, r1
  179. str r6, [r3, #0x4C4]
  180. /* Implement Guideline (GL# MEM-3) Drive Strength Value */
  181. /* Relevant for: 88F5181-A1/B0/B1 and 88F5281-A0/B0 */
  182. ldr r1, =DDR1_PAD_STRENGTH_DEFAULT
  183. /* Enable writes to DDR SDRAM Addr/Ctrl Pads Calibration register */
  184. ldr r6, [r3, #0x4C0]
  185. orr r6, r6, #SDRAM_PAD_CTRL_WR_EN
  186. str r6, [r3, #0x4C0]
  187. /* Correct strength and disable writes again */
  188. bic r6, r6, #SDRAM_PAD_CTRL_WR_EN
  189. bic r6, r6, #SDRAM_PAD_CTRL_DRV_STR_MASK
  190. orr r6, r6, r1
  191. str r6, [r3, #0x4C0]
  192. /* Enable writes to DDR SDRAM Data Pads Calibration register */
  193. ldr r6, [r3, #0x4C4]
  194. orr r6, r6, #SDRAM_PAD_CTRL_WR_EN
  195. str r6, [r3, #0x4C4]
  196. /* Correct strength and disable writes again */
  197. bic r6, r6, #SDRAM_PAD_CTRL_DRV_STR_MASK
  198. bic r6, r6, #SDRAM_PAD_CTRL_WR_EN
  199. orr r6, r6, r1
  200. str r6, [r3, #0x4C4]
  201. /* Implement Guideline (GL# MEM-4) DQS Reference Delay Tuning */
  202. /* Relevant for: 88F5181-A1/B0/B1 and 88F5281-A0/B0 */
  203. /* Get the "sample on reset" register for the DDR frequancy */
  204. ldr r3, =0x10000
  205. ldr r6, [r3, #0x010]
  206. ldr r1, =MSAR_ARMDDRCLCK_MASK
  207. and r1, r6, r1
  208. ldr r6, =FTDLL_DDR1_166MHZ
  209. cmp r1, #MSAR_ARMDDRCLCK_333_167
  210. beq 3f
  211. cmp r1, #MSAR_ARMDDRCLCK_500_167
  212. beq 3f
  213. cmp r1, #MSAR_ARMDDRCLCK_667_167
  214. beq 3f
  215. ldr r6, =FTDLL_DDR1_200MHZ
  216. cmp r1, #MSAR_ARMDDRCLCK_400_200_1
  217. beq 3f
  218. cmp r1, #MSAR_ARMDDRCLCK_400_200
  219. beq 3f
  220. cmp r1, #MSAR_ARMDDRCLCK_600_200
  221. beq 3f
  222. cmp r1, #MSAR_ARMDDRCLCK_800_200
  223. beq 3f
  224. ldr r6, =0
  225. 3:
  226. /* Use R3 as the base for DRAM registers */
  227. add r3, r4, #0x01000
  228. ldr r2, [r3, #0x484]
  229. orr r2, r2, r6
  230. str r2, [r3, #0x484]
  231. /* Return to U-boot via saved link register */
  232. mov pc, lr