dram_init.S 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /* $Id: dram_init.S,v 1.4 2005/04/24 18:48:32 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 r8 or r9 because they are used to
  7. * carry information from the decompresser to the kernel
  8. *
  9. * Copyright (C) 2000-2003 Axis Communications AB
  10. *
  11. * Authors: Mikael Starvik (starvik@axis.com)
  12. */
  13. /* Just to be certain the config file is included, we include it here
  14. * explicitely instead of depending on it being included in the file that
  15. * uses this code.
  16. */
  17. #include <asm/arch/hwregs/asm/reg_map_asm.h>
  18. #include <asm/arch/hwregs/asm/bif_core_defs_asm.h>
  19. ;; WARNING! The registers r8 and r9 are used as parameters carrying
  20. ;; information from the decompressor (if the kernel was compressed).
  21. ;; They should not be used in the code below.
  22. ; Refer to BIF MDS for a description of SDRAM initialization
  23. ; Bank configuration
  24. move.d REG_ADDR(bif_core, regi_bif_core, rw_sdram_cfg_grp0), $r0
  25. move.d CONFIG_ETRAX_SDRAM_GRP0_CONFIG, $r1
  26. move.d $r1, [$r0]
  27. move.d REG_ADDR(bif_core, regi_bif_core, rw_sdram_cfg_grp1), $r0
  28. move.d CONFIG_ETRAX_SDRAM_GRP1_CONFIG, $r1
  29. move.d $r1, [$r0]
  30. ; Calculate value of mrs_data
  31. ; CAS latency = 2 && bus_width = 32 => 0x40
  32. ; CAS latency = 3 && bus_width = 32 => 0x60
  33. ; CAS latency = 2 && bus_width = 16 => 0x20
  34. ; CAS latency = 3 && bus_width = 16 => 0x30
  35. ; Check if value is already supplied in kernel config
  36. move.d CONFIG_ETRAX_SDRAM_COMMAND, $r2
  37. bne _set_timing
  38. nop
  39. move.d 0x40, $r4 ; Assume 32 bits and CAS latency = 2
  40. move.d CONFIG_ETRAX_SDRAM_TIMING, $r1
  41. and.d 0x07, $r1 ; Get CAS latency
  42. cmpq 2, $r1 ; CL = 2 ?
  43. beq _bw_check
  44. nop
  45. move.d 0x60, $r4
  46. _bw_check:
  47. ; Assume that group 0 width is equal to group 1. This assumption
  48. ; is wrong for a group 1 only hardware (such as the grand old
  49. ; StorPoint+).
  50. move.d CONFIG_ETRAX_SDRAM_GRP0_CONFIG, $r1
  51. and.d 0x200, $r1 ; DRAM width is bit 9
  52. beq _set_timing
  53. lslq 2, $r4 ; mrs_data starts at bit 2
  54. lsrq 1, $r4 ; 16 bits. Shift down value.
  55. ; Set timing parameters (refresh off to avoid Guinness TR 83)
  56. _set_timing:
  57. move.d CONFIG_ETRAX_SDRAM_TIMING, $r1
  58. and.d ~(3 << reg_bif_core_rw_sdram_timing___ref___lsb), $r1
  59. move.d REG_ADDR(bif_core, regi_bif_core, rw_sdram_timing), $r0
  60. move.d $r1, [$r0]
  61. ; Issue NOP command
  62. move.d REG_ADDR(bif_core, regi_bif_core, rw_sdram_cmd), $r5
  63. moveq regk_bif_core_nop, $r1
  64. move.d $r1, [$r5]
  65. ; Wait 200us
  66. move.d 10000, $r2
  67. 1: bne 1b
  68. subq 1, $r2
  69. ; Issue initialization command sequence
  70. move.d _sdram_commands_start, $r2
  71. and.d 0x000fffff, $r2 ; Make sure commands are read from flash
  72. move.d _sdram_commands_end, $r3
  73. and.d 0x000fffff, $r3
  74. 1: clear.d $r6
  75. move.b [$r2+], $r6 ; Load command
  76. or.d $r4, $r6 ; Add calculated mrs
  77. move.d $r6, [$r5] ; Write rw_sdram_cmd
  78. ; Wait 80 ns between each command
  79. move.d 4000, $r7
  80. 2: bne 2b
  81. subq 1, $r7
  82. cmp.d $r2, $r3 ; Last command?
  83. bne 1b
  84. nop
  85. ; Start refresh
  86. move.d CONFIG_ETRAX_SDRAM_TIMING, $r1
  87. move.d REG_ADDR(bif_core, regi_bif_core, rw_sdram_timing), $r0
  88. move.d $r1, [$r0]
  89. ; Initialization finished
  90. ba _sdram_commands_end
  91. nop
  92. _sdram_commands_start:
  93. .byte regk_bif_core_pre ; Precharge
  94. .byte regk_bif_core_ref ; refresh
  95. .byte regk_bif_core_ref ; refresh
  96. .byte regk_bif_core_ref ; refresh
  97. .byte regk_bif_core_ref ; refresh
  98. .byte regk_bif_core_ref ; refresh
  99. .byte regk_bif_core_ref ; refresh
  100. .byte regk_bif_core_ref ; refresh
  101. .byte regk_bif_core_ref ; refresh
  102. .byte regk_bif_core_mrs ; mrs
  103. _sdram_commands_end: