init.S 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. * (C) Copyright 2007-2008
  3. * Stefan Roese, DENX Software Engineering, sr@denx.de.
  4. *
  5. * Based on code provided from UDTech and AMCC
  6. *
  7. * See file CREDITS for list of people who contributed to this
  8. * project.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License as
  12. * published by the Free Software Foundation; either version 2 of
  13. * the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  23. * MA 02111-1307 USA
  24. */
  25. #include <config.h>
  26. #include <ppc4xx.h>
  27. #include <ppc_asm.tmpl>
  28. #include <ppc_defs.h>
  29. #define mtsdram_as(reg, value) \
  30. addi r4,0,reg ; \
  31. mtdcr memcfga,r4 ; \
  32. addis r4,0,value@h ; \
  33. ori r4,r4,value@l ; \
  34. mtdcr memcfgd,r4 ;
  35. .globl ext_bus_cntlr_init
  36. ext_bus_cntlr_init:
  37. #if !defined(CONFIG_NAND_U_BOOT) || defined(CONFIG_NAND_SPL)
  38. /*
  39. * DDR2 setup
  40. */
  41. /* Following the DDR Core Manual, here is the initialization */
  42. /* Step 1 */
  43. /* Step 2 */
  44. /* Step 3 */
  45. /* base=00000000, size=256MByte (6), mode=7 (n*10*8) */
  46. mtsdram_as(SDRAM_MB0CF, 0x00006701);
  47. /* SET SDRAM_MB1CF - Not enabled */
  48. mtsdram_as(SDRAM_MB1CF, 0x00000000);
  49. /* SET SDRAM_MB2CF - Not enabled */
  50. mtsdram_as(SDRAM_MB2CF, 0x00000000);
  51. /* SET SDRAM_MB3CF - Not enabled */
  52. mtsdram_as(SDRAM_MB3CF, 0x00000000);
  53. /* SDRAM_CLKTR: Adv Addr clock by 180 deg */
  54. mtsdram_as(SDRAM_CLKTR, 0x80000000);
  55. /* Refresh Time register (0x30) Refresh every 7.8125uS */
  56. mtsdram_as(SDRAM_RTR, 0x06180000);
  57. /* SDRAM_SDTR1 */
  58. mtsdram_as(SDRAM_SDTR1, 0x80201000);
  59. /* SDRAM_SDTR2 */
  60. mtsdram_as(SDRAM_SDTR2, 0x32204232);
  61. /* SDRAM_SDTR3 */
  62. mtsdram_as(SDRAM_SDTR3, 0x080b0d1a);
  63. mtsdram_as(SDRAM_MMODE, 0x00000442);
  64. mtsdram_as(SDRAM_MEMODE, 0x00000404);
  65. /* SDRAM0_MCOPT1 (0X20) No ECC Gen */
  66. mtsdram_as(SDRAM_MCOPT1, 0x04322000);
  67. /* NOP */
  68. mtsdram_as(SDRAM_INITPLR0, 0xa8380000);
  69. /* precharge 3 DDR clock cycle */
  70. mtsdram_as(SDRAM_INITPLR1, 0x81900400);
  71. /* EMR2 twr = 2tck */
  72. mtsdram_as(SDRAM_INITPLR2, 0x81020000);
  73. /* EMR3 twr = 2tck */
  74. mtsdram_as(SDRAM_INITPLR3, 0x81030000);
  75. /* EMR DLL ENABLE twr = 2tck */
  76. mtsdram_as(SDRAM_INITPLR4, 0x81010404);
  77. /* MR w/ DLL reset
  78. * Note: 5 is CL. May need to be changed
  79. */
  80. mtsdram_as(SDRAM_INITPLR5, 0x81000542);
  81. /* precharge 3 DDR clock cycle */
  82. mtsdram_as(SDRAM_INITPLR6, 0x81900400);
  83. /* Auto-refresh trfc = 26tck */
  84. mtsdram_as(SDRAM_INITPLR7, 0x8D080000);
  85. /* Auto-refresh trfc = 26tck */
  86. mtsdram_as(SDRAM_INITPLR8, 0x8D080000);
  87. /* Auto-refresh */
  88. mtsdram_as(SDRAM_INITPLR9, 0x8D080000);
  89. /* Auto-refresh */
  90. mtsdram_as(SDRAM_INITPLR10, 0x8D080000);
  91. /* MRS - normal operation; wait 2 cycle (set wait to tMRD) */
  92. mtsdram_as(SDRAM_INITPLR11, 0x81000442);
  93. mtsdram_as(SDRAM_INITPLR12, 0x81010780);
  94. mtsdram_as(SDRAM_INITPLR13, 0x81010400);
  95. mtsdram_as(SDRAM_INITPLR14, 0x00000000);
  96. mtsdram_as(SDRAM_INITPLR15, 0x00000000);
  97. /* SET MCIF0_CODT Die Termination On */
  98. mtsdram_as(SDRAM_CODT, 0x0080f837);
  99. mtsdram_as(SDRAM_MODT0, 0x01800000);
  100. mtsdram_as(SDRAM_MODT1, 0x00000000);
  101. mtsdram_as(SDRAM_WRDTR, 0x00000000);
  102. /* SDRAM0_MCOPT2 (0X21) Start initialization */
  103. mtsdram_as(SDRAM_MCOPT2, 0x20000000);
  104. /* Step 5 */
  105. lis r3,0x1 /* 400000 = wait 100ms */
  106. mtctr r3
  107. pll_wait:
  108. bdnz pll_wait
  109. /* Step 6 */
  110. /* SDRAM_DLCR */
  111. mtsdram_as(SDRAM_DLCR, 0x030000a5);
  112. /* SDRAM_RDCC */
  113. mtsdram_as(SDRAM_RDCC, 0x40000000);
  114. /* SDRAM_RQDC */
  115. mtsdram_as(SDRAM_RQDC, 0x80000038);
  116. /* SDRAM_RFDC */
  117. mtsdram_as(SDRAM_RFDC, 0x00000209);
  118. /* Enable memory controller */
  119. mtsdram_as(SDRAM_MCOPT2, 0x28000000);
  120. #endif /* #ifndef CONFIG_NAND_U_BOOT */
  121. blr