icecube.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /*
  2. * (C) Copyright 2003
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #include <common.h>
  24. #include <mpc5xxx.h>
  25. #include <pci.h>
  26. #ifndef CFG_RAMBOOT
  27. static long int dram_size(long int *base, long int maxsize)
  28. {
  29. volatile long int *addr;
  30. ulong cnt, val;
  31. ulong save[32]; /* to make test non-destructive */
  32. unsigned char i = 0;
  33. for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {
  34. addr = base + cnt; /* pointer arith! */
  35. save[i++] = *addr;
  36. *addr = ~cnt;
  37. }
  38. /* write 0 to base address */
  39. addr = base;
  40. save[i] = *addr;
  41. *addr = 0;
  42. /* check at base address */
  43. if ((val = *addr) != 0) {
  44. *addr = save[i];
  45. return (0);
  46. }
  47. for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
  48. addr = base + cnt; /* pointer arith! */
  49. val = *addr;
  50. *addr = save[--i];
  51. if (val != (~cnt)) {
  52. return (cnt * sizeof (long));
  53. }
  54. }
  55. return (maxsize);
  56. }
  57. static void sdram_start (int hi_addr)
  58. {
  59. long hi_addr_bit = hi_addr ? 0x01000000 : 0;
  60. /* unlock mode register */
  61. *(vu_long *)MPC5XXX_SDRAM_CTRL = 0xd04f0000 | hi_addr_bit;
  62. /* precharge all banks */
  63. *(vu_long *)MPC5XXX_SDRAM_CTRL = 0xd04f0002 | hi_addr_bit;
  64. /* set mode register */
  65. #if defined(CONFIG_MPC5200)
  66. *(vu_long *)MPC5XXX_SDRAM_MODE = 0x408d0000;
  67. #elif defined(CONFIG_MGT5100)
  68. *(vu_long *)MPC5XXX_SDRAM_MODE = 0x008d0000;
  69. #endif
  70. /* precharge all banks */
  71. *(vu_long *)MPC5XXX_SDRAM_CTRL = 0xd04f0002 | hi_addr_bit;
  72. /* auto refresh */
  73. *(vu_long *)MPC5XXX_SDRAM_CTRL = 0xd04f0004 | hi_addr_bit;
  74. /* set mode register */
  75. *(vu_long *)MPC5XXX_SDRAM_MODE = 0x008d0000;
  76. /* normal operation */
  77. *(vu_long *)MPC5XXX_SDRAM_CTRL = 0x504f0000 | hi_addr_bit;
  78. }
  79. #endif
  80. long int initdram (int board_type)
  81. {
  82. ulong dramsize = 0;
  83. #ifndef CFG_RAMBOOT
  84. ulong test1, test2;
  85. /* configure SDRAM start/end */
  86. #if defined(CONFIG_MPC5200)
  87. *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x0000001e;/* 2G at 0x0 */
  88. *(vu_long *)MPC5XXX_SDRAM_CS1CFG = 0x80000000;/* disabled */
  89. /* setup config registers */
  90. *(vu_long *)MPC5XXX_SDRAM_CONFIG1 = 0xc2233a00;
  91. *(vu_long *)MPC5XXX_SDRAM_CONFIG2 = 0x88b70004;
  92. #elif defined(CONFIG_MGT5100)
  93. *(vu_long *)MPC5XXX_SDRAM_START = 0x00000000;
  94. *(vu_long *)MPC5XXX_SDRAM_STOP = 0x0000ffff;/* 2G */
  95. *(vu_long *)MPC5XXX_ADDECR |= (1 << 22); /* Enable SDRAM */
  96. /* setup config registers */
  97. *(vu_long *)MPC5XXX_SDRAM_CONFIG1 = 0xc2222600;
  98. *(vu_long *)MPC5XXX_SDRAM_CONFIG2 = 0x88b70004;
  99. /* address select register */
  100. *(vu_long *)MPC5XXX_SDRAM_XLBSEL = 0x03000000;
  101. #endif
  102. sdram_start(0);
  103. test1 = dram_size((ulong *)CFG_SDRAM_BASE, 0x80000000);
  104. sdram_start(1);
  105. test2 = dram_size((ulong *)CFG_SDRAM_BASE, 0x80000000);
  106. if (test1 > test2) {
  107. sdram_start(0);
  108. dramsize = test1;
  109. } else {
  110. dramsize = test2;
  111. }
  112. #if defined(CONFIG_MPC5200)
  113. *(vu_long *)MPC5XXX_SDRAM_CS0CFG =
  114. (0x13 + __builtin_ffs(dramsize >> 20) - 1);
  115. *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize; /* disabled */
  116. #elif defined(CONFIG_MGT5100)
  117. *(vu_long *)MPC5XXX_SDRAM_STOP = ((dramsize - 1) >> 15);
  118. #endif
  119. #else
  120. #ifdef CONFIG_MGT5100
  121. *(vu_long *)MPC5XXX_ADDECR |= (1 << 22); /* Enable SDRAM */
  122. dramsize = ((*(vu_long *)MPC5XXX_SDRAM_STOP + 1) << 15);
  123. #else
  124. dramsize = ((1 << (*(vu_long *)MPC5XXX_SDRAM_CS0CFG - 0x13)) << 20);
  125. #endif
  126. #endif /* CFG_RAMBOOT */
  127. /* return total ram size */
  128. return dramsize;
  129. }
  130. int checkboard (void)
  131. {
  132. #if defined(CONFIG_MPC5200)
  133. puts ("Board: Motorola MPC5200 (IceCube)\n");
  134. #elif defined(CONFIG_MGT5100)
  135. puts ("Board: Motorola MGT5100 (IceCube)\n");
  136. #endif
  137. return 0;
  138. }
  139. void flash_preinit(void)
  140. {
  141. /*
  142. * Now, when we are in RAM, enable flash write
  143. * access for detection process.
  144. * Note that CS_BOOT cannot be cleared when
  145. * executing in flash.
  146. */
  147. #if defined(CONFIG_MGT5100)
  148. *(vu_long *)MPC5XXX_ADDECR &= ~(1 << 25); /* disable CS_BOOT */
  149. *(vu_long *)MPC5XXX_ADDECR |= (1 << 16); /* enable CS0 */
  150. #endif
  151. *(vu_long *)MPC5XXX_BOOTCS_CFG &= ~0x1; /* clear RO */
  152. }
  153. void flash_afterinit(ulong size)
  154. {
  155. if (size == 0x800000) { /* adjust mapping */
  156. *(vu_long *)MPC5XXX_BOOTCS_START = *(vu_long *)MPC5XXX_CS0_START =
  157. START_REG(CFG_BOOTCS_START | size);
  158. *(vu_long *)MPC5XXX_BOOTCS_STOP = *(vu_long *)MPC5XXX_CS0_STOP =
  159. STOP_REG(CFG_BOOTCS_START | size, size);
  160. }
  161. }
  162. #ifdef CONFIG_PCI
  163. static struct pci_controller hose;
  164. extern void pci_mpc5xxx_init(struct pci_controller *);
  165. void pci_init_board(void)
  166. {
  167. pci_mpc5xxx_init(&hose);
  168. }
  169. #endif