init.S 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*
  2. * Copyright (c) 2008 Nuovation System Designs, LLC
  3. * Grant Erickson <gerickson@nuovations.com>
  4. *
  5. * (C) Copyright 2007-2008
  6. * Stefan Roese, DENX Software Engineering, sr@denx.de.
  7. *
  8. * Originally based on code provided from UDTech and AMCC
  9. *
  10. * See file CREDITS for list of people who contributed to this
  11. * project.
  12. *
  13. * This program is free software; you can redistribute it and/or
  14. * modify it under the terms of the GNU General Public License as
  15. * published by the Free Software Foundation; either version 2 of
  16. * the License, or (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program; if not, write to the Free Software
  25. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  26. * MA 02111-1307 USA
  27. */
  28. #include <config.h>
  29. #include <ppc4xx.h>
  30. #include <ppc_asm.tmpl>
  31. #include <ppc_defs.h>
  32. #define mtsdram_as(reg, value) \
  33. addi r4,0,reg ; \
  34. mtdcr memcfga,r4 ; \
  35. addis r4,0,value@h ; \
  36. ori r4,r4,value@l ; \
  37. mtdcr memcfgd,r4 ;
  38. #if defined(CONFIG_DDR_ECC)
  39. .extern ecc_init
  40. #endif /* defined(CONFIG_DDR_ECC) */
  41. .globl ext_bus_cntlr_init
  42. ext_bus_cntlr_init:
  43. #if !defined(CFG_INIT_DCACHE_CS)
  44. #if !defined(CONFIG_NAND_U_BOOT) || defined(CONFIG_NAND_SPL)
  45. /*
  46. * DDR2 SDRAM Controller Setup
  47. */
  48. /* Set Memory Bank Configuration Registers */
  49. mtsdram_as(SDRAM_MB0CF, CFG_SDRAM0_MB0CF);
  50. mtsdram_as(SDRAM_MB1CF, CFG_SDRAM0_MB1CF);
  51. mtsdram_as(SDRAM_MB2CF, CFG_SDRAM0_MB2CF);
  52. mtsdram_as(SDRAM_MB3CF, CFG_SDRAM0_MB3CF);
  53. /* Set Memory Clock Timing Register */
  54. mtsdram_as(SDRAM_CLKTR, CFG_SDRAM0_CLKTR);
  55. /* Set Refresh Time Register */
  56. mtsdram_as(SDRAM_RTR, CFG_SDRAM0_RTR);
  57. /* Set SDRAM Timing Registers */
  58. mtsdram_as(SDRAM_SDTR1, CFG_SDRAM0_SDTR1);
  59. mtsdram_as(SDRAM_SDTR2, CFG_SDRAM0_SDTR2);
  60. mtsdram_as(SDRAM_SDTR3, CFG_SDRAM0_SDTR3);
  61. /* Set Mode and Extended Mode Registers */
  62. mtsdram_as(SDRAM_MMODE, CFG_SDRAM0_MMODE);
  63. mtsdram_as(SDRAM_MEMODE, CFG_SDRAM0_MEMODE);
  64. /* Set Memory Controller Options 1 Register */
  65. mtsdram_as(SDRAM_MCOPT1, CFG_SDRAM0_MCOPT1);
  66. /* Set Manual Initialization Control Registers */
  67. mtsdram_as(SDRAM_INITPLR0, CFG_SDRAM0_INITPLR0);
  68. mtsdram_as(SDRAM_INITPLR1, CFG_SDRAM0_INITPLR1);
  69. mtsdram_as(SDRAM_INITPLR2, CFG_SDRAM0_INITPLR2);
  70. mtsdram_as(SDRAM_INITPLR3, CFG_SDRAM0_INITPLR3);
  71. mtsdram_as(SDRAM_INITPLR4, CFG_SDRAM0_INITPLR4);
  72. mtsdram_as(SDRAM_INITPLR5, CFG_SDRAM0_INITPLR5);
  73. mtsdram_as(SDRAM_INITPLR6, CFG_SDRAM0_INITPLR6);
  74. mtsdram_as(SDRAM_INITPLR7, CFG_SDRAM0_INITPLR7);
  75. mtsdram_as(SDRAM_INITPLR8, CFG_SDRAM0_INITPLR8);
  76. mtsdram_as(SDRAM_INITPLR9, CFG_SDRAM0_INITPLR9);
  77. mtsdram_as(SDRAM_INITPLR10, CFG_SDRAM0_INITPLR10);
  78. mtsdram_as(SDRAM_INITPLR11, CFG_SDRAM0_INITPLR11);
  79. mtsdram_as(SDRAM_INITPLR12, CFG_SDRAM0_INITPLR12);
  80. mtsdram_as(SDRAM_INITPLR13, CFG_SDRAM0_INITPLR13);
  81. mtsdram_as(SDRAM_INITPLR14, CFG_SDRAM0_INITPLR14);
  82. mtsdram_as(SDRAM_INITPLR15, CFG_SDRAM0_INITPLR15);
  83. /* Set On-Die Termination Registers */
  84. mtsdram_as(SDRAM_CODT, CFG_SDRAM0_CODT);
  85. mtsdram_as(SDRAM_MODT0, CFG_SDRAM0_MODT0);
  86. mtsdram_as(SDRAM_MODT1, CFG_SDRAM0_MODT1);
  87. /* Set Write Timing Register */
  88. mtsdram_as(SDRAM_WRDTR, CFG_SDRAM0_WRDTR);
  89. /*
  90. * Start Initialization by SDRAM0_MCOPT2[SREN] = 0 and
  91. * SDRAM0_MCOPT2[IPTR] = 1
  92. */
  93. mtsdram_as(SDRAM_MCOPT2, SDRAM_MCOPT2_SREN_EXIT | \
  94. SDRAM_MCOPT2_IPTR_EXECUTE);
  95. /*
  96. * Poll SDRAM0_MCSTAT[MIC] for assertion to indicate the
  97. * completion of initialization.
  98. *
  99. * do {
  100. * mfsdram(SDRAM_MCSTAT, val);
  101. * } while ((val & SDRAM_MCSTAT_MIC_MASK) != SDRAM_MCSTAT_MIC_COMP);
  102. */
  103. li r4,SDRAM_MCSTAT
  104. lis r2,SDRAM_MCSTAT_MIC_COMP@h
  105. ori r2,r2,SDRAM_MCSTAT_MIC_COMP@l
  106. 0: mtdcr memcfga,r4
  107. mfdcr r3,memcfgd
  108. clrrwi r3,r3,31
  109. cmpw cr7,r3,r2
  110. bne+ cr7,0b
  111. /* Set Delay Control Registers */
  112. mtsdram_as(SDRAM_DLCR, CFG_SDRAM0_DLCR);
  113. mtsdram_as(SDRAM_RDCC, CFG_SDRAM0_RDCC);
  114. mtsdram_as(SDRAM_RQDC, CFG_SDRAM0_RQDC);
  115. mtsdram_as(SDRAM_RFDC, CFG_SDRAM0_RFDC);
  116. /*
  117. * Enable Controller by SDRAM0_MCOPT2[DCEN] = 1:
  118. *
  119. * mcopt2 = mfsdram(SDRAM_MCOPT2);
  120. */
  121. li r4,SDRAM_MCOPT2
  122. mtdcr memcfga,r4
  123. mfdcr r3,memcfgd
  124. /*
  125. * mtsdram(SDRAM_MCOPT2, mcopt2 | SDRAM_MCOPT2_DCEN_ENABLE);
  126. */
  127. mtdcr memcfga,r4
  128. oris r3,r3,SDRAM_MCOPT2_DCEN_ENABLE@h
  129. ori r3,r3,SDRAM_MCOPT2_DCEN_ENABLE@l
  130. mtdcr memcfgd,r3
  131. #if defined(CONFIG_DDR_ECC)
  132. /*
  133. * ecc_init(CFG_SDRAM_BASE, CFG_MBYTES_SDRAM << 20);
  134. */
  135. mflr r13
  136. lis r3,CFG_SDRAM_BASE@h
  137. ori r3,r3,CFG_SDRAM_BASE@l
  138. lis r4,(CFG_MBYTES_SDRAM << 20)@h
  139. ori r4,r4,(CFG_MBYTES_SDRAM << 20)@l
  140. bl ecc_init
  141. mtlr r13
  142. #endif /* defined(CONFIG_DDR_ECC) */
  143. #endif /* !defined(CONFIG_NAND_U_BOOT) || defined(CONFIG_NAND_SPL) */
  144. #endif /* !defined(CFG_INIT_DCACHE_CS) */
  145. blr