memsetup.S 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /*
  2. * Memory Setup - initialize memory controller(s) for devices required
  3. * to boot and relocate
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #include <config.h>
  24. #include <version.h>
  25. /* memory controller */
  26. #define BCRX_DEFAULT (0x0000fbe0)
  27. #define BCRX_MW_8 (0x00000000)
  28. #define BCRX_MW_16 (0x10000000)
  29. #define BCRX_MW_32 (0x20000000)
  30. #define BCRX_PME (0x08000000)
  31. #define BCRX_WP (0x04000000)
  32. #define BCRX_WST2_SHIFT (11)
  33. #define BCRX_WST1_SHIFT (5)
  34. #define BCRX_IDCY_SHIFT (0)
  35. /* Bank0 Async Flash */
  36. #define BCR0 (0x80002000)
  37. #define BCR0_FLASH (BCRX_MW_32 | (0x08<<BCRX_WST2_SHIFT) | (0x0E<<BCRX_WST1_SHIFT))
  38. /* Bank1 Open */
  39. #define BCR1 (0x80002004)
  40. /* Bank2 Not used (EEPROM?) */
  41. #define BCR2 (0x80002008)
  42. /* Bank3 Not used */
  43. #define BCR3 (0x8000200C)
  44. /* Bank4 PC Card1 */
  45. /* Bank5 PC Card2 */
  46. /* Bank6 CPLD IO Controller Peripherals (slow) */
  47. #define BCR6 (0x80002018)
  48. #define BCR6_CPLD_SLOW (BCRX_DEFAULT | BCRX_MW_16)
  49. /* Bank7 CPLD IO Controller Peripherals (fast) */
  50. #define BCR7 (0x8000201C)
  51. #define BCR7_CPLD_FAST (BCRX_MW_16 | (0x16<<BCRX_WST2_SHIFT) | (0x16<<BCRX_WST1_SHIFT) | (0x2<<BCRX_IDCY_SHIFT))
  52. /* SDRAM */
  53. #define GBLCNFG (0x80002404)
  54. #define GC_CKE (0x80000000)
  55. #define GC_CKSD (0x40000000)
  56. #define GC_LCR (0x00000040)
  57. #define GC_SMEMBURST (0x00000020)
  58. #define GC_MRS (0x00000002)
  59. #define GC_INIT (0x00000001)
  60. #define GC_CMD_NORMAL (GC_CKE)
  61. #define GC_CMD_MODE (GC_CKE | GC_MRS)
  62. #define GC_CMD_SYNCFLASH_LOAD (GC_CKE | GC_MRS | GC_LCR)
  63. #define GC_CMD_PRECHARGEALL (GC_CKE | GC_INIT)
  64. #define GC_CMD_NOP (GC_CKE | GC_INIT | GC_MRS)
  65. #define RFSHTMR (0x80002408)
  66. #define RFSHTMR_INIT (10) /* period=100 ns, HCLK=100Mhz, (2048+1-15.6*66) */
  67. #define RFSHTMR_NORMAL (1500) /* period=15.6 us, HCLK=100Mhz, (2048+1-15.6*66) */
  68. #define SDCSCX_BASE (0x80002410)
  69. #define SDCSCX_DEFAULT (0x01220008)
  70. #define SDCSCX_AUTOPC (0x01000000)
  71. #define SDCSCX_RAS2CAS_2 (0x00200000)
  72. #define SDCSCX_RAS2CAS_3 (0x00300000)
  73. #define SDCSCX_WBL (0x00080000)
  74. #define SDCSCX_CASLAT_8 (0x00070000)
  75. #define SDCSCX_CASLAT_7 (0x00060000)
  76. #define SDCSCX_CASLAT_6 (0x00050000)
  77. #define SDCSCX_CASLAT_5 (0x00040000)
  78. #define SDCSCX_CASLAT_4 (0x00030000)
  79. #define SDCSCX_CASLAT_3 (0x00020000)
  80. #define SDCSCX_CASLAT_2 (0x00010000)
  81. #define SDCSCX_2KPAGE (0x00000040)
  82. #define SDCSCX_SROMLL (0x00000020)
  83. #define SDCSCX_SROM512 (0x00000010)
  84. #define SDCSCX_4BNK (0x00000008)
  85. #define SDCSCX_2BNK (0x00000000)
  86. #define SDCSCX_EBW_16 (0x00000004)
  87. #define SDCSCX_EBW_32 (0x00000000)
  88. #define SDRAM_BASE (0xC0000000)
  89. #define SDCSC_BANK_OFFSET (0x10000000)
  90. /*
  91. * The SDRAM DEVICE MODE PROGRAMMING VALUE
  92. */
  93. #define BURST_LENGTH_4 (0x010 << 10)
  94. #define BURST_LENGTH_8 (0x011 << 10)
  95. #define WBURST_LENGTH_BL (0x01 << 19)
  96. #define WBURST_LENGTH_SINGLE (0x01 << 19)
  97. #define CAS_2 (0x010 << 14)
  98. #define CAS_3 (0x011 << 14)
  99. #define BAT_SEQUENTIAL (0 << 13)
  100. #define BAT_INTERLEAVED (1 << 13)
  101. #define OPM_NORMAL (0x00 << 17)
  102. #define SDRAM_DEVICE_MODE (WBURST_LENGTH_BL|OPM_NORMAL|CAS_3|BAT_SEQUENTIAL|BURST_LENGTH_4)
  103. #define TIMER1_BASE (0x80000C00)
  104. /*
  105. * special lookup flags
  106. */
  107. #define DO_MEM_DELAY 1
  108. #define DO_MEM_READ 2
  109. _TEXT_BASE:
  110. .word TEXT_BASE
  111. .globl memsetup
  112. memsetup:
  113. mov r9, lr @ save return address
  114. /* memory control configuration */
  115. /* make r0 relative the current location so that it */
  116. /* reads INITMEM_DATA out of FLASH rather than memory ! */
  117. /* r0 = current word pointer */
  118. /* r1 = end word location, one word past last actual word */
  119. /* r3 = address for writes, special lookup flags */
  120. /* r4 = value for writes, delay constants, or read addresses */
  121. /* r2 = location for mem reads */
  122. ldr r0, =INITMEM_DATA
  123. ldr r1, _TEXT_BASE
  124. sub r0, r0, r1
  125. add r1, r0, #112
  126. mem_loop:
  127. cmp r1, r0
  128. moveq pc, r9 @ Done
  129. ldr r3, [r0], #4 @ Fetch Destination Register Address, or 1 for delay
  130. ldr r4, [r0], #4 @ value
  131. cmp r3, #DO_MEM_DELAY
  132. bleq mem_delay
  133. beq mem_loop
  134. cmp r3, #DO_MEM_READ
  135. ldreq r2, [r4]
  136. beq mem_loop
  137. str r4, [r3] @ normal register/ram store
  138. b mem_loop
  139. mem_delay:
  140. ldr r5, =TIMER1_BASE
  141. mov r6, r4, LSR #1 @ timer resolution is ~2us
  142. str r6, [r5]
  143. mov r6, #0x88 @ using 508.469KHz clock, enable
  144. str r6, [r5, #8]
  145. 0: ldr r6, [r5, #4] @ timer value
  146. cmp r6, #0
  147. bne 0b
  148. mov r6, #0 @ disable timer
  149. str r6, [r5, #8]
  150. mov pc, lr
  151. .ltorg
  152. /* the literal pools origin */
  153. INITMEM_DATA:
  154. .word BCR0
  155. .word BCR0_FLASH
  156. .word BCR6
  157. .word BCR6_CPLD_SLOW
  158. .word BCR7
  159. .word BCR7_CPLD_FAST
  160. .word SDCSCX_BASE
  161. .word (SDCSCX_RAS2CAS_3 | SDCSCX_CASLAT_3 | SDCSCX_SROMLL | SDCSCX_4BNK | SDCSCX_EBW_32)
  162. .word GBLCNFG
  163. .word GC_CMD_NOP
  164. .word DO_MEM_DELAY
  165. .word 200
  166. .word GBLCNFG
  167. .word GC_CMD_PRECHARGEALL
  168. .word RFSHTMR
  169. .word RFSHTMR_INIT
  170. .word DO_MEM_DELAY
  171. .word 8
  172. .word RFSHTMR
  173. .word RFSHTMR_NORMAL
  174. .word GBLCNFG
  175. .word GC_CMD_MODE
  176. .word DO_MEM_READ
  177. .word (SDRAM_BASE | SDRAM_DEVICE_MODE)
  178. .word GBLCNFG
  179. .word GC_CMD_NORMAL
  180. .word SDCSCX_BASE
  181. .word (SDCSCX_AUTOPC | SDCSCX_RAS2CAS_3 | SDCSCX_CASLAT_3 | SDCSCX_SROMLL | SDCSCX_4BNK | SDCSCX_EBW_32)