dram_init.S 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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 r8 or r9 because they are used to
  6. * carry information from the decompressor to the kernel
  7. *
  8. * Copyright (C) 2000-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/bif_core_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 BIF MDS for a description of SDRAM initialization
  22. ; Bank configuration
  23. move.d REG_ADDR(bif_core, regi_bif_core, rw_sdram_cfg_grp0), $r0
  24. move.d CONFIG_ETRAX_SDRAM_GRP0_CONFIG, $r1
  25. move.d $r1, [$r0]
  26. move.d REG_ADDR(bif_core, regi_bif_core, rw_sdram_cfg_grp1), $r0
  27. move.d CONFIG_ETRAX_SDRAM_GRP1_CONFIG, $r1
  28. move.d $r1, [$r0]
  29. ; Calculate value of mrs_data
  30. ; CAS latency = 2 && bus_width = 32 => 0x40
  31. ; CAS latency = 3 && bus_width = 32 => 0x60
  32. ; CAS latency = 2 && bus_width = 16 => 0x20
  33. ; CAS latency = 3 && bus_width = 16 => 0x30
  34. ; Check if value is already supplied in kernel config
  35. move.d CONFIG_ETRAX_SDRAM_COMMAND, $r2
  36. bne _set_timing
  37. nop
  38. move.d 0x40, $r4 ; Assume 32 bits and CAS latency = 2
  39. move.d CONFIG_ETRAX_SDRAM_TIMING, $r1
  40. and.d 0x07, $r1 ; Get CAS latency
  41. cmpq 2, $r1 ; CL = 2 ?
  42. beq _bw_check
  43. nop
  44. move.d 0x60, $r4
  45. _bw_check:
  46. ; Assume that group 0 width is equal to group 1. This assumption
  47. ; is wrong for a group 1 only hardware (such as the grand old
  48. ; StorPoint+).
  49. move.d CONFIG_ETRAX_SDRAM_GRP0_CONFIG, $r1
  50. and.d 0x200, $r1 ; DRAM width is bit 9
  51. beq _set_timing
  52. lslq 2, $r4 ; mrs_data starts at bit 2
  53. lsrq 1, $r4 ; 16 bits. Shift down value.
  54. ; Set timing parameters (refresh off to avoid Guinness TR 83)
  55. _set_timing:
  56. move.d CONFIG_ETRAX_SDRAM_TIMING, $r1
  57. and.d ~(3 << reg_bif_core_rw_sdram_timing___ref___lsb), $r1
  58. move.d REG_ADDR(bif_core, regi_bif_core, rw_sdram_timing), $r0
  59. move.d $r1, [$r0]
  60. ; Issue NOP command
  61. move.d REG_ADDR(bif_core, regi_bif_core, rw_sdram_cmd), $r5
  62. moveq regk_bif_core_nop, $r1
  63. move.d $r1, [$r5]
  64. ; Wait 200us
  65. move.d 10000, $r2
  66. 1: bne 1b
  67. subq 1, $r2
  68. ; Issue initialization command sequence
  69. lapc _sdram_commands_start, $r2
  70. lapc _sdram_commands_end, $r3
  71. 1: clear.d $r6
  72. move.b [$r2+], $r6 ; Load command
  73. or.d $r4, $r6 ; Add calculated mrs
  74. move.d $r6, [$r5] ; Write rw_sdram_cmd
  75. ; Wait 80 ns between each command
  76. move.d 4000, $r7
  77. 2: bne 2b
  78. subq 1, $r7
  79. cmp.d $r2, $r3 ; Last command?
  80. bne 1b
  81. nop
  82. ; Start refresh
  83. move.d CONFIG_ETRAX_SDRAM_TIMING, $r1
  84. move.d REG_ADDR(bif_core, regi_bif_core, rw_sdram_timing), $r0
  85. move.d $r1, [$r0]
  86. ; Initialization finished
  87. ba _sdram_commands_end
  88. nop
  89. _sdram_commands_start:
  90. .byte regk_bif_core_pre ; Precharge
  91. .byte regk_bif_core_ref ; refresh
  92. .byte regk_bif_core_ref ; refresh
  93. .byte regk_bif_core_ref ; refresh
  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_mrs ; mrs
  100. _sdram_commands_end: