dram_init.S 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /* $Id: dram_init.S,v 1.4 2003/09/22 09:21:59 starvik Exp $
  2. *
  3. * DRAM/SDRAM initialization - alter with care
  4. * This file is intended to be included from other assembler files
  5. *
  6. * Note: This file may not modify r9 because r9 is used to carry
  7. * information from the decompresser to the kernel
  8. *
  9. * Copyright (C) 2000, 2001 Axis Communications AB
  10. *
  11. * Authors: Mikael Starvik (starvik@axis.com)
  12. *
  13. * $Log: dram_init.S,v $
  14. * Revision 1.4 2003/09/22 09:21:59 starvik
  15. * Decompresser is linked to 0x407xxxxx and sdram commands are at 0x000xxxxx
  16. * so we need to mask off 12 bits.
  17. *
  18. * Revision 1.3 2003/03/31 09:38:37 starvik
  19. * Corrected calculation of end of sdram init commands
  20. *
  21. * Revision 1.2 2002/11/19 13:33:29 starvik
  22. * Changes from Linux 2.4
  23. *
  24. * Revision 1.13 2002/10/30 07:42:28 starvik
  25. * Always read SDRAM command sequence from flash
  26. *
  27. * Revision 1.12 2002/08/09 11:37:37 orjanf
  28. * Added double initialization work-around for Samsung SDRAMs.
  29. *
  30. * Revision 1.11 2002/06/04 11:43:21 starvik
  31. * Check if mrs_data is specified in kernelconfig (necessary for MCM)
  32. *
  33. * Revision 1.10 2001/10/04 12:00:21 martinnn
  34. * Added missing underscores.
  35. *
  36. * Revision 1.9 2001/10/01 14:47:35 bjornw
  37. * Added register prefixes and removed underscores
  38. *
  39. * Revision 1.8 2001/05/15 07:12:45 hp
  40. * Copy warning from head.S about r8 and r9
  41. *
  42. * Revision 1.7 2001/04/18 12:05:39 bjornw
  43. * Fixed comments, and explicitely include config.h to be sure its there
  44. *
  45. * Revision 1.6 2001/04/10 06:20:16 starvik
  46. * Delay should be 200us, not 200ns
  47. *
  48. * Revision 1.5 2001/04/09 06:01:13 starvik
  49. * Added support for 100 MHz SDRAMs
  50. *
  51. * Revision 1.4 2001/03/26 14:24:01 bjornw
  52. * Namechange of some config options
  53. *
  54. * Revision 1.3 2001/03/23 08:29:41 starvik
  55. * Corrected calculation of mrs_data
  56. *
  57. * Revision 1.2 2001/02/08 15:20:00 starvik
  58. * Corrected SDRAM initialization
  59. * Should now be included as inline
  60. *
  61. * Revision 1.1 2001/01/29 13:08:02 starvik
  62. * Initial version
  63. * This file should be included from all assembler files that needs to
  64. * initialize DRAM/SDRAM.
  65. *
  66. */
  67. /* Just to be certain the config file is included, we include it here
  68. * explicitely instead of depending on it being included in the file that
  69. * uses this code.
  70. */
  71. #include <linux/config.h>
  72. ;; WARNING! The registers r8 and r9 are used as parameters carrying
  73. ;; information from the decompressor (if the kernel was compressed).
  74. ;; They should not be used in the code below.
  75. #ifndef CONFIG_SVINTO_SIM
  76. move.d CONFIG_ETRAX_DEF_R_WAITSTATES, $r0
  77. move.d $r0, [R_WAITSTATES]
  78. move.d CONFIG_ETRAX_DEF_R_BUS_CONFIG, $r0
  79. move.d $r0, [R_BUS_CONFIG]
  80. #ifndef CONFIG_ETRAX_SDRAM
  81. move.d CONFIG_ETRAX_DEF_R_DRAM_CONFIG, $r0
  82. move.d $r0, [R_DRAM_CONFIG]
  83. move.d CONFIG_ETRAX_DEF_R_DRAM_TIMING, $r0
  84. move.d $r0, [R_DRAM_TIMING]
  85. #else
  86. ;; Samsung SDRAMs seem to require to be initialized twice to work properly.
  87. moveq 2, $r6
  88. _sdram_init:
  89. ; Refer to ETRAX 100LX Designers Reference for a description of SDRAM initialization
  90. ; Bank configuration
  91. move.d CONFIG_ETRAX_DEF_R_SDRAM_CONFIG, $r0
  92. move.d $r0, [R_SDRAM_CONFIG]
  93. ; Calculate value of mrs_data
  94. ; CAS latency = 2 && bus_width = 32 => 0x40
  95. ; CAS latency = 3 && bus_width = 32 => 0x60
  96. ; CAS latency = 2 && bus_width = 16 => 0x20
  97. ; CAS latency = 3 && bus_width = 16 => 0x30
  98. ; Check if value is already supplied in kernel config
  99. move.d CONFIG_ETRAX_DEF_R_SDRAM_TIMING, $r2
  100. and.d 0x00ff0000, $r2
  101. bne _set_timing
  102. lsrq 16, $r2
  103. move.d 0x40, $r2 ; Assume 32 bits and CAS latency = 2
  104. move.d CONFIG_ETRAX_DEF_R_SDRAM_TIMING, $r1
  105. move.d $r1, $r3
  106. and.d 0x03, $r1 ; Get CAS latency
  107. and.d 0x1000, $r3 ; 50 or 100 MHz?
  108. beq _speed_50
  109. nop
  110. _speed_100:
  111. cmp.d 0x00, $r1 ; CAS latency = 2?
  112. beq _bw_check
  113. nop
  114. or.d 0x20, $r2 ; CAS latency = 3
  115. ba _bw_check
  116. nop
  117. _speed_50:
  118. cmp.d 0x01, $r1 ; CAS latency = 2?
  119. beq _bw_check
  120. nop
  121. or.d 0x20, $r2 ; CAS latency = 3
  122. _bw_check:
  123. move.d CONFIG_ETRAX_DEF_R_SDRAM_CONFIG, $r1
  124. and.d 0x800000, $r1 ; DRAM width is bit 23
  125. bne _set_timing
  126. nop
  127. lsrq 1, $r2 ; 16 bits. Shift down value.
  128. ; Set timing parameters. Starts master clock
  129. _set_timing:
  130. move.d CONFIG_ETRAX_DEF_R_SDRAM_TIMING, $r1
  131. and.d 0x8000f9ff, $r1 ; Make sure mrs data and command is 0
  132. or.d 0x80000000, $r1 ; Make sure sdram enable bit is set
  133. move.d $r1, $r5
  134. or.d 0x0000c000, $r1 ; ref = disable
  135. lslq 16, $r2 ; mrs data starts at bit 16
  136. or.d $r2, $r1
  137. move.d $r1, [R_SDRAM_TIMING]
  138. ; Wait 200us
  139. move.d 10000, $r2
  140. 1: bne 1b
  141. subq 1, $r2
  142. ; Issue initialization command sequence
  143. move.d _sdram_commands_start, $r2
  144. and.d 0x000fffff, $r2 ; Make sure commands are read from flash
  145. move.d _sdram_commands_end, $r3
  146. and.d 0x000fffff, $r3
  147. 1: clear.d $r4
  148. move.b [$r2+], $r4
  149. lslq 9, $r4 ; Command starts at bit 9
  150. or.d $r1, $r4
  151. move.d $r4, [R_SDRAM_TIMING]
  152. nop ; Wait five nop cycles between each command
  153. nop
  154. nop
  155. nop
  156. nop
  157. cmp.d $r2, $r3
  158. bne 1b
  159. nop
  160. move.d $r5, [R_SDRAM_TIMING]
  161. subq 1, $r6
  162. bne _sdram_init
  163. nop
  164. ba _sdram_commands_end
  165. nop
  166. _sdram_commands_start:
  167. .byte 3 ; Precharge
  168. .byte 0 ; nop
  169. .byte 2 ; refresh
  170. .byte 0 ; nop
  171. .byte 2 ; refresh
  172. .byte 0 ; nop
  173. .byte 2 ; refresh
  174. .byte 0 ; nop
  175. .byte 2 ; refresh
  176. .byte 0 ; nop
  177. .byte 2 ; refresh
  178. .byte 0 ; nop
  179. .byte 2 ; refresh
  180. .byte 0 ; nop
  181. .byte 2 ; refresh
  182. .byte 0 ; nop
  183. .byte 2 ; refresh
  184. .byte 0 ; nop
  185. .byte 1 ; mrs
  186. .byte 0 ; nop
  187. _sdram_commands_end:
  188. #endif
  189. #endif