dram_init.S 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * DDR 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 r8 or r9 because they are used to
  6. * carry information from the decompressor to the kernel
  7. *
  8. * Copyright (C) 2005-2007 Axis Communications AB
  9. *
  10. * Authors: Mikael Starvik <starvik@axis.com>
  11. */
  12. /* Just to be certain the config file is included, we include it here
  13. * explicitly instead of depending on it being included in the file that
  14. * uses this code.
  15. */
  16. #include <hwregs/asm/reg_map_asm.h>
  17. #include <hwregs/asm/ddr2_defs_asm.h>
  18. ;; WARNING! The registers r8 and r9 are used as parameters carrying
  19. ;; information from the decompressor (if the kernel was compressed).
  20. ;; They should not be used in the code below.
  21. ;; Refer to ddr2 MDS for initialization sequence
  22. ; 2. Wait 200us
  23. move.d 10000, $r2
  24. 1: bne 1b
  25. subq 1, $r2
  26. ; Start clock
  27. move.d REG_ADDR(ddr2, regi_ddr2_ctrl, rw_phy_cfg), $r0
  28. move.d REG_STATE(ddr2, rw_phy_cfg, en, yes), $r1
  29. move.d $r1, [$r0]
  30. ; 2. Wait 200us
  31. move.d 10000, $r2
  32. 1: bne 1b
  33. subq 1, $r2
  34. ; Reset phy and start calibration
  35. move.d REG_ADDR(ddr2, regi_ddr2_ctrl, rw_phy_ctrl), $r0
  36. move.d REG_STATE(ddr2, rw_phy_ctrl, rst, yes) | \
  37. REG_STATE(ddr2, rw_phy_ctrl, cal_rst, yes), $r1
  38. move.d $r1, [$r0]
  39. move.d REG_STATE(ddr2, rw_phy_ctrl, cal_start, yes), $r1
  40. move.d $r1, [$r0]
  41. ; 2. Wait 200us
  42. move.d 10000, $r2
  43. 1: bne 1b
  44. subq 1, $r2
  45. ; Issue commands
  46. move.d REG_ADDR(ddr2, regi_ddr2_ctrl, rw_ctrl), $r0
  47. move.d sdram_commands_start, $r2
  48. command_loop:
  49. movu.b [$r2+], $r1
  50. movu.w [$r2+], $r3
  51. do_cmd:
  52. lslq 16, $r1
  53. or.d $r3, $r1
  54. move.d $r1, [$r0]
  55. ; 2. Wait 200us
  56. move.d 10000, $r4
  57. 1: bne 1b
  58. subq 1, $r4
  59. cmp.d sdram_commands_end, $r2
  60. blo command_loop
  61. nop
  62. ; Set timing
  63. move.d REG_ADDR(ddr2, regi_ddr2_ctrl, rw_timing), $r0
  64. move.d CONFIG_ETRAX_DDR2_TIMING, $r1
  65. move.d $r1, [$r0]
  66. ; Set latency
  67. move.d REG_ADDR(ddr2, regi_ddr2_ctrl, rw_latency), $r0
  68. move.d CONFIG_ETRAX_DDR2_LATENCY, $r1
  69. move.d $r1, [$r0]
  70. ; Set configuration
  71. move.d REG_ADDR(ddr2, regi_ddr2_ctrl, rw_cfg), $r0
  72. move.d CONFIG_ETRAX_DDR2_CONFIG, $r1
  73. move.d $r1, [$r0]
  74. ba after_sdram_commands
  75. nop
  76. sdram_commands_start:
  77. .byte regk_ddr2_deselect
  78. .word 0
  79. .byte regk_ddr2_pre
  80. .word regk_ddr2_pre_all
  81. .byte regk_ddr2_emrs2
  82. .word 0
  83. .byte regk_ddr2_emrs3
  84. .word 0
  85. .byte regk_ddr2_emrs
  86. .word regk_ddr2_dll_en
  87. .byte regk_ddr2_mrs
  88. .word regk_ddr2_dll_rst
  89. .byte regk_ddr2_pre
  90. .word regk_ddr2_pre_all
  91. .byte regk_ddr2_ref
  92. .word 0
  93. .byte regk_ddr2_ref
  94. .word 0
  95. .byte regk_ddr2_mrs
  96. .word CONFIG_ETRAX_DDR2_MRS & 0xffff
  97. .byte regk_ddr2_emrs
  98. .word regk_ddr2_ocd_default | regk_ddr2_dll_en
  99. .byte regk_ddr2_emrs
  100. .word regk_ddr2_ocd_exit | regk_ddr2_dll_en | (CONFIG_ETRAX_DDR2_MRS >> 16)
  101. sdram_commands_end:
  102. .align 1
  103. after_sdram_commands: