lowlevel_init.S 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. /*
  2. * Copyright (C) 2009, Emcraft Systems, Ilya Yanok <yanok@emcraft.com>
  3. *
  4. * Based on board/freescale/mx31ads/lowlevel_init.S
  5. * by Guennadi Liakhovetski.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  20. * MA 02111-1307 USA
  21. */
  22. #include <asm/arch/mx31-regs.h>
  23. .macro REG reg, val
  24. ldr r2, =\reg
  25. ldr r3, =\val
  26. str r3, [r2]
  27. .endm
  28. .macro REG8 reg, val
  29. ldr r2, =\reg
  30. ldr r3, =\val
  31. strb r3, [r2]
  32. .endm
  33. .macro DELAY loops
  34. ldr r2, =\loops
  35. 1:
  36. subs r2, r2, #1
  37. nop
  38. bcs 1b
  39. .endm
  40. .macro SETUP_RAM cfg, ctl
  41. /* B8xxxxxx - NAND, 8xxxxxxx - CSD0 RAM */
  42. REG 0xB8001010, 0x00000004
  43. ldr r3, =\cfg
  44. ldr r2, =WEIM_ESDCFG0
  45. str r3, [r2]
  46. REG 0xB8001000, 0x92100000
  47. REG 0x80000f00, 0x12344321
  48. REG 0xB8001000, 0xa2100000
  49. REG 0x80000000, 0x12344321
  50. REG 0x80000000, 0x12344321
  51. REG 0xB8001000, 0xb2100000
  52. REG8 0x80000033, 0xda
  53. REG8 0x81000000, 0xff
  54. ldr r3, =\ctl
  55. ldr r2, =WEIM_ESDCTL0
  56. str r3, [r2]
  57. REG 0x80000000, 0xDEADBEEF
  58. REG 0xB8001010, 0x0000000c
  59. .endm
  60. /* RedBoot: To support 133MHz DDR */
  61. .macro init_drive_strength
  62. /*
  63. * Disable maximum drive strength SDRAM/DDR lines by clearing DSE1 bits
  64. * in SW_PAD_CTL registers
  65. */
  66. /* SDCLK */
  67. ldr r1, =IOMUXC_SW_PAD_CTL(0x2b)
  68. ldr r0, [r1, #0x6C]
  69. bic r0, r0, #(1 << 12)
  70. str r0, [r1, #0x6C]
  71. /* CAS */
  72. ldr r0, [r1, #0x70]
  73. bic r0, r0, #(1 << 22)
  74. str r0, [r1, #0x70]
  75. /* RAS */
  76. ldr r0, [r1, #0x74]
  77. bic r0, r0, #(1 << 2)
  78. str r0, [r1, #0x74]
  79. /* CS2 (CSD0) */
  80. ldr r0, [r1, #0x7C]
  81. bic r0, r0, #(1 << 22)
  82. str r0, [r1, #0x7C]
  83. /* DQM3 */
  84. ldr r0, [r1, #0x84]
  85. bic r0, r0, #(1 << 22)
  86. str r0, [r1, #0x84]
  87. /* DQM2, DQM1, DQM0, SD31-SD0, A25-A0, MA10 (0x288..0x2DC) */
  88. ldr r2, =22 /* (0x2E0 - 0x288) / 4 = 22 */
  89. pad_loop:
  90. ldr r0, [r1, #0x88]
  91. bic r0, r0, #(1 << 22)
  92. bic r0, r0, #(1 << 12)
  93. bic r0, r0, #(1 << 2)
  94. str r0, [r1, #0x88]
  95. add r1, r1, #4
  96. subs r2, r2, #0x1
  97. bne pad_loop
  98. .endm /* init_drive_strength */
  99. .globl lowlevel_init
  100. lowlevel_init:
  101. init_drive_strength
  102. /* Image Processing Unit: */
  103. /* Too early to switch display on? */
  104. /* Switch on Display Interface */
  105. REG IPU_CONF, IPU_CONF_DI_EN
  106. /* Clock Control Module: */
  107. REG CCM_CCMR, 0x074B0BF5 /* Use CKIH, MCU PLL off */
  108. DELAY 0x40000
  109. REG CCM_CCMR, 0x074B0BF5 | CCMR_MPE /* MCU PLL on */
  110. /* Switch to MCU PLL */
  111. REG CCM_CCMR, (0x074B0BF5 | CCMR_MPE) & ~CCMR_MDS
  112. /* 399-133-66.5 */
  113. ldr r0, =CCM_BASE
  114. ldr r1, =0xFF871650
  115. /* PDR0 */
  116. str r1, [r0, #0x4]
  117. ldr r1, MPCTL_PARAM_399
  118. /* MPCTL */
  119. str r1, [r0, #0x10]
  120. /* Set UPLL=240MHz, USB=60MHz */
  121. ldr r1, =0x49FCFE7F
  122. /* PDR1 */
  123. str r1, [r0, #0x8]
  124. ldr r1, UPCTL_PARAM_240
  125. /* UPCTL */
  126. str r1, [r0, #0x14]
  127. /* default CLKO to 1/8 of the ARM core */
  128. mov r1, #0x00000208
  129. /* COSR */
  130. str r1, [r0, #0x1c]
  131. /* Default: 1, 4, 12, 1 */
  132. REG CCM_SPCTL, PLL_PD(1) | PLL_MFD(4) | PLL_MFI(12) | PLL_MFN(1)
  133. check_ddr_module:
  134. /* Set stackpointer in internal RAM to call get_ram_size */
  135. ldr sp, =(IRAM_BASE_ADDR + IRAM_SIZE - 16)
  136. stmfd sp!, {r0-r11, ip, lr}
  137. mov ip, lr /* save link reg across call */
  138. ldr r0,=0x08000000
  139. SETUP_RAM ESDCFG0_256MB, ESDCTL0_256MB
  140. ldr r0,=0x80000000
  141. ldr r1,=0x10000000
  142. bl get_ram_size
  143. ldr r1,=0x10000000
  144. cmp r0,r1
  145. beq restore_regs
  146. SETUP_RAM ESDCFG0_128MB, ESDCTL0_128MB
  147. ldr r0,=0x80000000
  148. ldr r1,=0x08000000
  149. bl get_ram_size
  150. ldr r1,=0x08000000
  151. cmp r0,r1
  152. beq restore_regs
  153. restore_regs:
  154. ldmfd sp!, {r0-r11, ip, lr}
  155. mov lr, ip /* restore link reg */
  156. mov pc, lr
  157. MPCTL_PARAM_399:
  158. .word (((1 - 1) << 26) + ((52 - 1) << 16) + (7 << 10) + (35 << 0))
  159. UPCTL_PARAM_240:
  160. .word (((2 - 1) << 26) + ((13 - 1) << 16) + (9 << 10) + (3 << 0))
  161. .equ ESDCFG0_128MB, \
  162. (0 << 21) + /* tXP */ \
  163. (1 << 20) + /* tWTR */ \
  164. (2 << 18) + /* tRP */ \
  165. (1 << 16) + /* tMRD */ \
  166. (0 << 15) + /* tWR */ \
  167. (5 << 12) + /* tRAS */ \
  168. (1 << 10) + /* tRRD */ \
  169. (3 << 8) + /* tCAS */ \
  170. (2 << 4) + /* tRCD */ \
  171. (0x0F << 0) /* tRC */
  172. .equ ESDCTL0_128MB, \
  173. (1 << 31) + /* enable */ \
  174. (0 << 28) + /* mode */ \
  175. (0 << 27) + /* supervisor protect */ \
  176. (2 << 24) + /* 13 rows */ \
  177. (2 << 20) + /* 10 cols */ \
  178. (2 << 16) + /* 32 bit */ \
  179. (3 << 13) + /* 7.81us (64ms/8192) */ \
  180. (0 << 10) + /* power down timer */ \
  181. (0 << 8) + /* full page */ \
  182. (1 << 7) + /* burst length */ \
  183. (0 << 0) /* precharge timer */
  184. .equ ESDCFG0_256MB, \
  185. (3 << 21) + /* tXP */ \
  186. (0 << 20) + /* tWTR */ \
  187. (2 << 18) + /* tRP */ \
  188. (1 << 16) + /* tMRD */ \
  189. (0 << 15) + /* tWR */ \
  190. (5 << 12) + /* tRAS */ \
  191. (1 << 10) + /* tRRD */ \
  192. (3 << 8) + /* tCAS */ \
  193. (2 << 4) + /* tRCD */ \
  194. (7 << 0) /* tRC */
  195. .equ ESDCTL0_256MB, \
  196. (1 << 31) + \
  197. (0 << 28) + \
  198. (0 << 27) + \
  199. (3 << 24) + /* 14 rows */ \
  200. (2 << 20) + /* 10 cols */ \
  201. (2 << 16) + \
  202. (4 << 13) + /* 3.91us (64ms/16384) */ \
  203. (0 << 10) + \
  204. (0 << 8) + \
  205. (1 << 7) + \
  206. (0 << 0)