lowlevel_init.S 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. /*
  2. * Copyright (C) 2008, Guennadi Liakhovetski <lg@denx.de>
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 2 of
  7. * the License, or (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  17. * MA 02111-1307 USA
  18. */
  19. #include <asm/arch/mx31-regs.h>
  20. .macro REG reg, val
  21. ldr r2, =\reg
  22. ldr r3, =\val
  23. str r3, [r2]
  24. .endm
  25. .macro REG8 reg, val
  26. ldr r2, =\reg
  27. ldr r3, =\val
  28. strb r3, [r2]
  29. .endm
  30. .macro DELAY loops
  31. ldr r2, =\loops
  32. 1:
  33. subs r2, r2, #1
  34. nop
  35. bcs 1b
  36. .endm
  37. /* RedBoot: AIPS setup - Only setup MPROTx registers.
  38. * The PACR default values are good.*/
  39. .macro init_aips
  40. /*
  41. * Set all MPROTx to be non-bufferable, trusted for R/W,
  42. * not forced to user-mode.
  43. */
  44. ldr r0, =0x43F00000
  45. ldr r1, =0x77777777
  46. str r1, [r0, #0x00]
  47. str r1, [r0, #0x04]
  48. ldr r0, =0x53F00000
  49. str r1, [r0, #0x00]
  50. str r1, [r0, #0x04]
  51. /*
  52. * Clear the on and off peripheral modules Supervisor Protect bit
  53. * for SDMA to access them. Did not change the AIPS control registers
  54. * (offset 0x20) access type
  55. */
  56. ldr r0, =0x43F00000
  57. ldr r1, =0x0
  58. str r1, [r0, #0x40]
  59. str r1, [r0, #0x44]
  60. str r1, [r0, #0x48]
  61. str r1, [r0, #0x4C]
  62. ldr r1, [r0, #0x50]
  63. and r1, r1, #0x00FFFFFF
  64. str r1, [r0, #0x50]
  65. ldr r0, =0x53F00000
  66. ldr r1, =0x0
  67. str r1, [r0, #0x40]
  68. str r1, [r0, #0x44]
  69. str r1, [r0, #0x48]
  70. str r1, [r0, #0x4C]
  71. ldr r1, [r0, #0x50]
  72. and r1, r1, #0x00FFFFFF
  73. str r1, [r0, #0x50]
  74. .endm /* init_aips */
  75. /* RedBoot: MAX (Multi-Layer AHB Crossbar Switch) setup */
  76. .macro init_max
  77. ldr r0, =0x43F04000
  78. /* MPR - priority is M4 > M2 > M3 > M5 > M0 > M1 */
  79. ldr r1, =0x00302154
  80. str r1, [r0, #0x000] /* for S0 */
  81. str r1, [r0, #0x100] /* for S1 */
  82. str r1, [r0, #0x200] /* for S2 */
  83. str r1, [r0, #0x300] /* for S3 */
  84. str r1, [r0, #0x400] /* for S4 */
  85. /* SGPCR - always park on last master */
  86. ldr r1, =0x10
  87. str r1, [r0, #0x010] /* for S0 */
  88. str r1, [r0, #0x110] /* for S1 */
  89. str r1, [r0, #0x210] /* for S2 */
  90. str r1, [r0, #0x310] /* for S3 */
  91. str r1, [r0, #0x410] /* for S4 */
  92. /* MGPCR - restore default values */
  93. ldr r1, =0x0
  94. str r1, [r0, #0x800] /* for M0 */
  95. str r1, [r0, #0x900] /* for M1 */
  96. str r1, [r0, #0xA00] /* for M2 */
  97. str r1, [r0, #0xB00] /* for M3 */
  98. str r1, [r0, #0xC00] /* for M4 */
  99. str r1, [r0, #0xD00] /* for M5 */
  100. .endm /* init_max */
  101. /* RedBoot: M3IF setup */
  102. .macro init_m3if
  103. /* Configure M3IF registers */
  104. ldr r1, =0xB8003000
  105. /*
  106. * M3IF Control Register (M3IFCTL)
  107. * MRRP[0] = L2CC0 not on priority list (0 << 0) = 0x00000000
  108. * MRRP[1] = L2CC1 not on priority list (0 << 0) = 0x00000000
  109. * MRRP[2] = MBX not on priority list (0 << 0) = 0x00000000
  110. * MRRP[3] = MAX1 not on priority list (0 << 0) = 0x00000000
  111. * MRRP[4] = SDMA not on priority list (0 << 0) = 0x00000000
  112. * MRRP[5] = MPEG4 not on priority list (0 << 0) = 0x00000000
  113. * MRRP[6] = IPU1 on priority list (1 << 6) = 0x00000040
  114. * MRRP[7] = IPU2 not on priority list (0 << 0) = 0x00000000
  115. * ------------
  116. * 0x00000040
  117. */
  118. ldr r0, =0x00000040
  119. str r0, [r1] /* M3IF control reg */
  120. .endm /* init_m3if */
  121. /* RedBoot: To support 133MHz DDR */
  122. .macro init_drive_strength
  123. /*
  124. * Disable maximum drive strength SDRAM/DDR lines by clearing DSE1 bits
  125. * in SW_PAD_CTL registers
  126. */
  127. /* SDCLK */
  128. ldr r1, =0x43FAC200
  129. ldr r0, [r1, #0x6C]
  130. bic r0, r0, #(1 << 12)
  131. str r0, [r1, #0x6C]
  132. /* CAS */
  133. ldr r0, [r1, #0x70]
  134. bic r0, r0, #(1 << 22)
  135. str r0, [r1, #0x70]
  136. /* RAS */
  137. ldr r0, [r1, #0x74]
  138. bic r0, r0, #(1 << 2)
  139. str r0, [r1, #0x74]
  140. /* CS2 (CSD0) */
  141. ldr r0, [r1, #0x7C]
  142. bic r0, r0, #(1 << 22)
  143. str r0, [r1, #0x7C]
  144. /* DQM3 */
  145. ldr r0, [r1, #0x84]
  146. bic r0, r0, #(1 << 22)
  147. str r0, [r1, #0x84]
  148. /* DQM2, DQM1, DQM0, SD31-SD0, A25-A0, MA10 (0x288..0x2DC) */
  149. ldr r2, =22 /* (0x2E0 - 0x288) / 4 = 22 */
  150. pad_loop:
  151. ldr r0, [r1, #0x88]
  152. bic r0, r0, #(1 << 22)
  153. bic r0, r0, #(1 << 12)
  154. bic r0, r0, #(1 << 2)
  155. str r0, [r1, #0x88]
  156. add r1, r1, #4
  157. subs r2, r2, #0x1
  158. bne pad_loop
  159. .endm /* init_drive_strength */
  160. /* CPLD on CS4 setup */
  161. .macro init_cs4
  162. ldr r0, =WEIM_BASE
  163. ldr r1, =0x0000D843
  164. str r1, [r0, #0x40]
  165. ldr r1, =0x22252521
  166. str r1, [r0, #0x44]
  167. ldr r1, =0x22220A00
  168. str r1, [r0, #0x48]
  169. .endm /* init_cs4 */
  170. .globl lowlevel_init
  171. lowlevel_init:
  172. /* Redboot initializes very early AIPS, what for?
  173. * Then it also initializes Multi-Layer AHB Crossbar Switch,
  174. * M3IF */
  175. /* Also setup the Peripheral Port Remap register inside the core */
  176. ldr r0, =0x40000015 /* start from AIPS 2GB region */
  177. mcr p15, 0, r0, c15, c2, 4
  178. init_aips
  179. init_max
  180. init_m3if
  181. init_drive_strength
  182. init_cs4
  183. /* Image Processing Unit: */
  184. /* Too early to switch display on? */
  185. REG IPU_CONF, IPU_CONF_DI_EN /* Switch on Display Interface */
  186. /* Clock Control Module: */
  187. REG CCM_CCMR, 0x074B0BF5 /* Use CKIH, MCU PLL off */
  188. DELAY 0x40000
  189. REG CCM_CCMR, 0x074B0BF5 | CCMR_MPE /* MCU PLL on */
  190. REG CCM_CCMR, (0x074B0BF5 | CCMR_MPE) & ~CCMR_MDS /* Switch to MCU PLL */
  191. /* PBC CPLD on CS4 */
  192. mov r1, #CS4_BASE
  193. ldrh r1, [r1, #0x2]
  194. /* Is 27MHz switch set? */
  195. ands r1, r1, #0x10
  196. /* 532-133-66.5 */
  197. ldr r0, =CCM_BASE
  198. ldr r1, =0xFF871D58
  199. /* PDR0 */
  200. str r1, [r0, #0x4]
  201. ldreq r1, MPCTL_PARAM_532
  202. ldrne r1, MPCTL_PARAM_532_27
  203. /* MPCTL */
  204. str r1, [r0, #0x10]
  205. /* Set UPLL=240MHz, USB=60MHz */
  206. ldr r1, =0x49FCFE7F
  207. /* PDR1 */
  208. str r1, [r0, #0x8]
  209. ldreq r1, UPCTL_PARAM_240
  210. ldrne r1, UPCTL_PARAM_240_27
  211. /* UPCTL */
  212. str r1, [r0, #0x14]
  213. /* default CLKO to 1/8 of the ARM core */
  214. mov r1, #0x000002C0
  215. add r1, r1, #0x00000006
  216. /* COSR */
  217. str r1, [r0, #0x1c]
  218. /* RedBoot sets 0x1ff, 7, 3, 5, 1, 3, 0 */
  219. /* REG CCM_PDR0, PDR0_CSI_PODF(0x1ff) | PDR0_PER_PODF(7) | PDR0_HSP_PODF(2) | PDR0_NFC_PODF(6) | PDR0_IPG_PODF(1) | PDR0_MAX_PODF(2) | PDR0_MCU_PODF(0)*/
  220. /* Redboot: 0, 51, 10, 12 / 0, 14, 9, 13 */
  221. /* REG CCM_MPCTL, PLL_PD(0) | PLL_MFD(0x33) | PLL_MFI(7) | PLL_MFN(0x23)*/
  222. /* Default: 1, 4, 12, 1 */
  223. REG CCM_SPCTL, PLL_PD(1) | PLL_MFD(4) | PLL_MFI(12) | PLL_MFN(1)
  224. /* B8xxxxxx - NAND, 8xxxxxxx - CSD0 RAM */
  225. REG 0xB8001010, 0x00000004
  226. REG 0xB8001004, 0x006ac73a
  227. REG 0xB8001000, 0x92100000
  228. REG 0x80000f00, 0x12344321
  229. REG 0xB8001000, 0xa2100000
  230. REG 0x80000000, 0x12344321
  231. REG 0x80000000, 0x12344321
  232. REG 0xB8001000, 0xb2100000
  233. REG8 0x80000033, 0xda
  234. REG8 0x81000000, 0xff
  235. REG 0xB8001000, 0x82226080
  236. REG 0x80000000, 0xDEADBEEF
  237. REG 0xB8001010, 0x0000000c
  238. mov pc, lr
  239. MPCTL_PARAM_532:
  240. .word (((1-1) << 26) + ((52-1) << 16) + (10 << 10) + (12 << 0))
  241. MPCTL_PARAM_532_27:
  242. .word (((1-1) << 26) + ((15-1) << 16) + (9 << 10) + (13 << 0))
  243. UPCTL_PARAM_240:
  244. .word (((2-1) << 26) + ((13-1) << 16) + (9 << 10) + (3 << 0))
  245. UPCTL_PARAM_240_27:
  246. .word (((2-1) << 26) + ((9 -1) << 16) + (8 << 10) + (8 << 0))