dram_init.S 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*
  2. * DRAM/SDRAM initialization - alter with care
  3. * This file is intended to be included from other assembler files
  4. *
  5. * Note: This file may not modify r9 because r9 is used to carry
  6. * information from the decompresser to the kernel
  7. *
  8. * Copyright (C) 2000, 2001 Axis Communications AB
  9. *
  10. * Authors: Mikael Starvik (starvik@axis.com)
  11. *
  12. */
  13. /* Just to be certain the config file is included, we include it here
  14. * explicitly instead of depending on it being included in the file that
  15. * uses this code.
  16. */
  17. ;; WARNING! The registers r8 and r9 are used as parameters carrying
  18. ;; information from the decompressor (if the kernel was compressed).
  19. ;; They should not be used in the code below.
  20. #ifndef CONFIG_SVINTO_SIM
  21. move.d CONFIG_ETRAX_DEF_R_WAITSTATES, $r0
  22. move.d $r0, [R_WAITSTATES]
  23. move.d CONFIG_ETRAX_DEF_R_BUS_CONFIG, $r0
  24. move.d $r0, [R_BUS_CONFIG]
  25. #ifndef CONFIG_ETRAX_SDRAM
  26. move.d CONFIG_ETRAX_DEF_R_DRAM_CONFIG, $r0
  27. move.d $r0, [R_DRAM_CONFIG]
  28. move.d CONFIG_ETRAX_DEF_R_DRAM_TIMING, $r0
  29. move.d $r0, [R_DRAM_TIMING]
  30. #else
  31. ;; Samsung SDRAMs seem to require to be initialized twice to work properly.
  32. moveq 2, $r6
  33. _sdram_init:
  34. ; Refer to ETRAX 100LX Designers Reference for a description of SDRAM initialization
  35. ; Bank configuration
  36. move.d CONFIG_ETRAX_DEF_R_SDRAM_CONFIG, $r0
  37. move.d $r0, [R_SDRAM_CONFIG]
  38. ; Calculate value of mrs_data
  39. ; CAS latency = 2 && bus_width = 32 => 0x40
  40. ; CAS latency = 3 && bus_width = 32 => 0x60
  41. ; CAS latency = 2 && bus_width = 16 => 0x20
  42. ; CAS latency = 3 && bus_width = 16 => 0x30
  43. ; Check if value is already supplied in kernel config
  44. move.d CONFIG_ETRAX_DEF_R_SDRAM_TIMING, $r2
  45. and.d 0x00ff0000, $r2
  46. bne _set_timing
  47. lsrq 16, $r2
  48. move.d 0x40, $r2 ; Assume 32 bits and CAS latency = 2
  49. move.d CONFIG_ETRAX_DEF_R_SDRAM_TIMING, $r1
  50. move.d $r1, $r3
  51. and.d 0x03, $r1 ; Get CAS latency
  52. and.d 0x1000, $r3 ; 50 or 100 MHz?
  53. beq _speed_50
  54. nop
  55. _speed_100:
  56. cmp.d 0x00, $r1 ; CAS latency = 2?
  57. beq _bw_check
  58. nop
  59. or.d 0x20, $r2 ; CAS latency = 3
  60. ba _bw_check
  61. nop
  62. _speed_50:
  63. cmp.d 0x01, $r1 ; CAS latency = 2?
  64. beq _bw_check
  65. nop
  66. or.d 0x20, $r2 ; CAS latency = 3
  67. _bw_check:
  68. move.d CONFIG_ETRAX_DEF_R_SDRAM_CONFIG, $r1
  69. and.d 0x800000, $r1 ; DRAM width is bit 23
  70. bne _set_timing
  71. nop
  72. lsrq 1, $r2 ; 16 bits. Shift down value.
  73. ; Set timing parameters. Starts master clock
  74. _set_timing:
  75. move.d CONFIG_ETRAX_DEF_R_SDRAM_TIMING, $r1
  76. and.d 0x8000f9ff, $r1 ; Make sure mrs data and command is 0
  77. or.d 0x80000000, $r1 ; Make sure sdram enable bit is set
  78. move.d $r1, $r5
  79. or.d 0x0000c000, $r1 ; ref = disable
  80. lslq 16, $r2 ; mrs data starts at bit 16
  81. or.d $r2, $r1
  82. move.d $r1, [R_SDRAM_TIMING]
  83. ; Wait 200us
  84. move.d 10000, $r2
  85. 1: bne 1b
  86. subq 1, $r2
  87. ; Issue initialization command sequence
  88. move.d _sdram_commands_start, $r2
  89. and.d 0x000fffff, $r2 ; Make sure commands are read from flash
  90. move.d _sdram_commands_end, $r3
  91. and.d 0x000fffff, $r3
  92. 1: clear.d $r4
  93. move.b [$r2+], $r4
  94. lslq 9, $r4 ; Command starts at bit 9
  95. or.d $r1, $r4
  96. move.d $r4, [R_SDRAM_TIMING]
  97. nop ; Wait five nop cycles between each command
  98. nop
  99. nop
  100. nop
  101. nop
  102. cmp.d $r2, $r3
  103. bne 1b
  104. nop
  105. move.d $r5, [R_SDRAM_TIMING]
  106. subq 1, $r6
  107. bne _sdram_init
  108. nop
  109. ba _sdram_commands_end
  110. nop
  111. _sdram_commands_start:
  112. .byte 3 ; Precharge
  113. .byte 0 ; nop
  114. .byte 2 ; refresh
  115. .byte 0 ; nop
  116. .byte 2 ; refresh
  117. .byte 0 ; nop
  118. .byte 2 ; refresh
  119. .byte 0 ; nop
  120. .byte 2 ; refresh
  121. .byte 0 ; nop
  122. .byte 2 ; refresh
  123. .byte 0 ; nop
  124. .byte 2 ; refresh
  125. .byte 0 ; nop
  126. .byte 2 ; refresh
  127. .byte 0 ; nop
  128. .byte 2 ; refresh
  129. .byte 0 ; nop
  130. .byte 1 ; mrs
  131. .byte 0 ; nop
  132. _sdram_commands_end:
  133. #endif
  134. #endif