dram_init.S 3.7 KB

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