o2dnt.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /*
  2. * (C) Copyright 2005
  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. * See file CREDITS for list of people who contributed to this
  9. * project.
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License as
  13. * published by the Free Software Foundation; either version 2 of
  14. * the License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  24. * MA 02111-1307 USA
  25. */
  26. #include <common.h>
  27. #include <mpc5xxx.h>
  28. #include <pci.h>
  29. #define SDRAM_MODE 0x00CD0000
  30. #define SDRAM_CONTROL 0x504F0000
  31. #define SDRAM_CONFIG1 0xD2322800
  32. #define SDRAM_CONFIG2 0x8AD70000
  33. static void sdram_start (int hi_addr)
  34. {
  35. long hi_addr_bit = hi_addr ? 0x01000000 : 0;
  36. /* unlock mode register */
  37. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000000 | hi_addr_bit;
  38. __asm__ volatile ("sync");
  39. /* precharge all banks */
  40. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit;
  41. __asm__ volatile ("sync");
  42. /* precharge all banks */
  43. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit;
  44. __asm__ volatile ("sync");
  45. /* auto refresh */
  46. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000004 | hi_addr_bit;
  47. __asm__ volatile ("sync");
  48. /* set mode register */
  49. *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE;
  50. __asm__ volatile ("sync");
  51. /* normal operation */
  52. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | hi_addr_bit;
  53. __asm__ volatile ("sync");
  54. }
  55. /*
  56. * ATTENTION: Although partially referenced initdram does NOT make real use
  57. * use of CFG_SDRAM_BASE. The code does not work if CFG_SDRAM_BASE
  58. * is something else than 0x00000000.
  59. */
  60. long int initdram (int board_type)
  61. {
  62. ulong dramsize = 0;
  63. ulong dramsize2 = 0;
  64. ulong test1, test2;
  65. /* setup SDRAM chip selects */
  66. *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x0000001e;/* 2G at 0x0 */
  67. *(vu_long *)MPC5XXX_SDRAM_CS1CFG = 0x80000000;/* disabled */
  68. __asm__ volatile ("sync");
  69. /* setup config registers */
  70. *(vu_long *)MPC5XXX_SDRAM_CONFIG1 = SDRAM_CONFIG1;
  71. *(vu_long *)MPC5XXX_SDRAM_CONFIG2 = SDRAM_CONFIG2;
  72. __asm__ volatile ("sync");
  73. /* find RAM size using SDRAM CS0 only */
  74. sdram_start(0);
  75. test1 = get_ram_size((long *)CFG_SDRAM_BASE, 0x80000000);
  76. sdram_start(1);
  77. test2 = get_ram_size((long *)CFG_SDRAM_BASE, 0x80000000);
  78. if (test1 > test2) {
  79. sdram_start(0);
  80. dramsize = test1;
  81. } else {
  82. dramsize = test2;
  83. }
  84. /* memory smaller than 1MB is impossible */
  85. if (dramsize < (1 << 20)) {
  86. dramsize = 0;
  87. }
  88. /* set SDRAM CS0 size according to the amount of RAM found */
  89. if (dramsize > 0)
  90. *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x13 + __builtin_ffs(dramsize >> 20) - 1;
  91. else
  92. *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0; /* disabled */
  93. /* let SDRAM CS1 start right after CS0 */
  94. *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize + 0x0000001e;/* 2G */
  95. /* find RAM size using SDRAM CS1 only */
  96. if (!dramsize)
  97. sdram_start(0);
  98. test2 = test1 = get_ram_size((long *)(CFG_SDRAM_BASE + dramsize), 0x80000000);
  99. if (!dramsize) {
  100. sdram_start(1);
  101. test2 = get_ram_size((long *)(CFG_SDRAM_BASE + dramsize), 0x80000000);
  102. }
  103. if (test1 > test2) {
  104. sdram_start(0);
  105. dramsize2 = test1;
  106. } else {
  107. dramsize2 = test2;
  108. }
  109. /* memory smaller than 1MB is impossible */
  110. if (dramsize2 < (1 << 20))
  111. dramsize2 = 0;
  112. /* set SDRAM CS1 size according to the amount of RAM found */
  113. if (dramsize2 > 0) {
  114. *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize
  115. | (0x13 + __builtin_ffs(dramsize2 >> 20) - 1);
  116. } else {
  117. *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize; /* disabled */
  118. }
  119. return dramsize + dramsize2;
  120. }
  121. int checkboard (void)
  122. {
  123. puts ("Board: O2DNT\n");
  124. return 0;
  125. }
  126. void flash_preinit(void)
  127. {
  128. /*
  129. * Now, when we are in RAM, enable flash write
  130. * access for detection process.
  131. * Note that CS_BOOT cannot be cleared when
  132. * executing in flash.
  133. */
  134. *(vu_long *)MPC5XXX_BOOTCS_CFG &= ~0x1; /* clear RO */
  135. }
  136. void flash_afterinit(ulong size)
  137. {
  138. if (size == 0x800000) { /* adjust mapping */
  139. *(vu_long *)MPC5XXX_BOOTCS_START = *(vu_long *)MPC5XXX_CS0_START =
  140. START_REG(CFG_BOOTCS_START | size);
  141. *(vu_long *)MPC5XXX_BOOTCS_STOP = *(vu_long *)MPC5XXX_CS0_STOP =
  142. STOP_REG(CFG_BOOTCS_START | size, size);
  143. }
  144. }
  145. #ifdef CONFIG_PCI
  146. static struct pci_controller hose;
  147. extern void pci_mpc5xxx_init(struct pci_controller *);
  148. void pci_init_board(void)
  149. {
  150. pci_mpc5xxx_init(&hose);
  151. }
  152. #endif