inka4x0.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /*
  2. * (C) Copyright 2003-2004
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * (C) Copyright 2004
  6. * Mark Jonas, Freescale Semiconductor, mark.jonas@motorola.com.
  7. *
  8. * (C) Copyright 2004
  9. * Martin Krause, TQ-Systems GmbH, martin.krause@tqs.de
  10. *
  11. * See file CREDITS for list of people who contributed to this
  12. * project.
  13. *
  14. * This program is free software; you can redistribute it and/or
  15. * modify it under the terms of the GNU General Public License as
  16. * published by the Free Software Foundation; either version 2 of
  17. * the License, or (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  27. * MA 02111-1307 USA
  28. */
  29. #include <common.h>
  30. #include <mpc5xxx.h>
  31. #include <pci.h>
  32. #if defined(CONFIG_MPC5200_DDR)
  33. #include "mt46v16m16-75.h"
  34. #else
  35. #include "mt48lc16m16a2-75.h"
  36. #endif
  37. #ifndef CFG_RAMBOOT
  38. static void sdram_start (int hi_addr)
  39. {
  40. long hi_addr_bit = hi_addr ? 0x01000000 : 0;
  41. /* unlock mode register */
  42. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000000 |
  43. hi_addr_bit;
  44. __asm__ volatile ("sync");
  45. /* precharge all banks */
  46. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 |
  47. hi_addr_bit;
  48. __asm__ volatile ("sync");
  49. #if SDRAM_DDR
  50. /* set mode register: extended mode */
  51. *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_EMODE;
  52. __asm__ volatile ("sync");
  53. /* set mode register: reset DLL */
  54. *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE | 0x04000000;
  55. __asm__ volatile ("sync");
  56. #endif
  57. /* precharge all banks */
  58. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 |
  59. hi_addr_bit;
  60. __asm__ volatile ("sync");
  61. /* auto refresh */
  62. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000004 |
  63. hi_addr_bit;
  64. __asm__ volatile ("sync");
  65. /* set mode register */
  66. *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE;
  67. __asm__ volatile ("sync");
  68. /* normal operation */
  69. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | hi_addr_bit;
  70. __asm__ volatile ("sync");
  71. }
  72. #endif
  73. /*
  74. * ATTENTION: Although partially referenced initdram does NOT make real use
  75. * use of CFG_SDRAM_BASE. The code does not work if CFG_SDRAM_BASE
  76. * is something else than 0x00000000.
  77. */
  78. long int initdram (int board_type)
  79. {
  80. ulong dramsize = 0;
  81. #ifndef CFG_RAMBOOT
  82. ulong test1, test2;
  83. /* setup SDRAM chip selects */
  84. *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x0000001c; /* 512MB at 0x0 */
  85. *(vu_long *)MPC5XXX_SDRAM_CS1CFG = 0x40000000; /* disabled */
  86. __asm__ volatile ("sync");
  87. /* setup config registers */
  88. *(vu_long *)MPC5XXX_SDRAM_CONFIG1 = SDRAM_CONFIG1;
  89. *(vu_long *)MPC5XXX_SDRAM_CONFIG2 = SDRAM_CONFIG2;
  90. __asm__ volatile ("sync");
  91. #if SDRAM_DDR
  92. /* set tap delay */
  93. *(vu_long *)MPC5XXX_CDM_PORCFG = SDRAM_TAPDELAY;
  94. __asm__ volatile ("sync");
  95. #endif
  96. /* find RAM size using SDRAM CS0 only */
  97. sdram_start(0);
  98. test1 = get_ram_size((ulong *)CFG_SDRAM_BASE, 0x20000000);
  99. sdram_start(1);
  100. test2 = get_ram_size((ulong *)CFG_SDRAM_BASE, 0x20000000);
  101. if (test1 > test2) {
  102. sdram_start(0);
  103. dramsize = test1;
  104. } else {
  105. dramsize = test2;
  106. }
  107. /* memory smaller than 1MB is impossible */
  108. if (dramsize < (1 << 20)) {
  109. dramsize = 0;
  110. }
  111. /* set SDRAM CS0 size according to the amount of RAM found */
  112. if (dramsize > 0) {
  113. *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x13 +
  114. __builtin_ffs(dramsize >> 20) - 1;
  115. } else {
  116. *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0; /* disabled */
  117. }
  118. *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize; /* disabled */
  119. #else /* CFG_RAMBOOT */
  120. /* retrieve size of memory connected to SDRAM CS0 */
  121. dramsize = *(vu_long *)MPC5XXX_SDRAM_CS0CFG & 0xFF;
  122. if (dramsize >= 0x13) {
  123. dramsize = (1 << (dramsize - 0x13)) << 20;
  124. } else {
  125. dramsize = 0;
  126. }
  127. /* retrieve size of memory connected to SDRAM CS1 */
  128. dramsize2 = *(vu_long *)MPC5XXX_SDRAM_CS1CFG & 0xFF;
  129. if (dramsize2 >= 0x13) {
  130. dramsize2 = (1 << (dramsize2 - 0x13)) << 20;
  131. } else {
  132. dramsize2 = 0;
  133. }
  134. #endif /* CFG_RAMBOOT */
  135. /* return dramsize + dramsize2; */
  136. return dramsize;
  137. }
  138. int checkboard (void)
  139. {
  140. puts ("Board: INKA 4X0 (Indatec GmbH & Co. KG)\n");
  141. return 0;
  142. }
  143. void flash_preinit(void)
  144. {
  145. /*
  146. * Now, when we are in RAM, enable flash write
  147. * access for detection process.
  148. * Note that CS_BOOT cannot be cleared when
  149. * executing in flash.
  150. */
  151. *(vu_long *)MPC5XXX_BOOTCS_CFG &= ~0x1; /* clear RO */
  152. }