icecube.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. static long int dram_size(long int *base, long int maxsize)
  27. {
  28. volatile long int *addr;
  29. ulong cnt, val;
  30. ulong save[32]; /* to make test non-destructive */
  31. unsigned char i = 0;
  32. for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {
  33. addr = base + cnt; /* pointer arith! */
  34. save[i++] = *addr;
  35. *addr = ~cnt;
  36. }
  37. /* write 0 to base address */
  38. addr = base;
  39. save[i] = *addr;
  40. *addr = 0;
  41. /* check at base address */
  42. if ((val = *addr) != 0) {
  43. *addr = save[i];
  44. return (0);
  45. }
  46. for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
  47. addr = base + cnt; /* pointer arith! */
  48. val = *addr;
  49. *addr = save[--i];
  50. if (val != (~cnt)) {
  51. return (cnt * sizeof (long));
  52. }
  53. }
  54. return (maxsize);
  55. }
  56. static void sdram_start (int hi_addr)
  57. {
  58. long hi_addr_bit = hi_addr ? 0x01000000 : 0;
  59. /* unlock mode register */
  60. *(vu_long *)MPC5XXX_SDRAM_CTRL = 0xd04f0000 | hi_addr_bit;
  61. /* precharge all banks */
  62. *(vu_long *)MPC5XXX_SDRAM_CTRL = 0xd04f0002 | hi_addr_bit;
  63. /* set mode register */
  64. #if defined(CONFIG_MPC5200)
  65. *(vu_long *)MPC5XXX_SDRAM_MODE = 0x408d0000;
  66. #elif defined(CONFIG_MGT5100)
  67. *(vu_long *)MPC5XXX_SDRAM_MODE = 0x008d0000;
  68. #endif
  69. /* precharge all banks */
  70. *(vu_long *)MPC5XXX_SDRAM_CTRL = 0xd04f0002 | hi_addr_bit;
  71. /* auto refresh */
  72. *(vu_long *)MPC5XXX_SDRAM_CTRL = 0xd04f0004 | hi_addr_bit;
  73. /* set mode register */
  74. *(vu_long *)MPC5XXX_SDRAM_MODE = 0x008d0000;
  75. /* normal operation */
  76. *(vu_long *)MPC5XXX_SDRAM_CTRL = 0x504f0000 | hi_addr_bit;
  77. }
  78. long int initdram (int board_type)
  79. {
  80. ulong test1, test2, dramsize = 0;
  81. #ifndef CFG_RAMBOOT
  82. /* configure SDRAM start/end */
  83. #if defined(CONFIG_MPC5200)
  84. *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x0000001e;/* 2G at 0x0 */
  85. *(vu_long *)MPC5XXX_SDRAM_CS1CFG = 0x80000000;/* disabled */
  86. /* setup config registers */
  87. *(vu_long *)MPC5XXX_SDRAM_CONFIG1 = 0xc2233a00;
  88. *(vu_long *)MPC5XXX_SDRAM_CONFIG2 = 0x88b70004;
  89. #elif defined(CONFIG_MGT5100)
  90. *(vu_long *)MPC5XXX_SDRAM_START = 0x00000000;
  91. *(vu_long *)MPC5XXX_SDRAM_STOP = 0x0000ffff;/* 2G */
  92. *(vu_long *)MPC5XXX_ADDECR |= (1 << 22); /* Enable SDRAM */
  93. /* setup config registers */
  94. *(vu_long *)MPC5XXX_SDRAM_CONFIG1 = 0xc2222600;
  95. *(vu_long *)MPC5XXX_SDRAM_CONFIG2 = 0x88b70004;
  96. /* address select register */
  97. *(vu_long *)MPC5XXX_SDRAM_XLBSEL = 0x03000000;
  98. #endif
  99. sdram_start(0);
  100. test1 = dram_size((ulong *)CFG_SDRAM_BASE, 0x80000000);
  101. sdram_start(1);
  102. test2 = dram_size((ulong *)CFG_SDRAM_BASE, 0x80000000);
  103. if (test1 > test2) {
  104. sdram_start(0);
  105. dramsize = test1;
  106. } else {
  107. dramsize = test2;
  108. }
  109. #if defined(CONFIG_MPC5200)
  110. *(vu_long *)MPC5XXX_SDRAM_CS0CFG =
  111. (0x13 + __builtin_ffs(dramsize >> 20) - 1);
  112. *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize; /* disabled */
  113. #elif defined(CONFIG_MGT5100)
  114. *(vu_long *)MPC5XXX_SDRAM_STOP = ((dramsize - 1) >> 15);
  115. #endif
  116. #else
  117. #ifdef CONFIG_MGT5100
  118. *(vu_long *)MPC5XXX_ADDECR |= (1 << 22); /* Enable SDRAM */
  119. #endif
  120. #endif
  121. /* return total ram size */
  122. return dramsize;
  123. }
  124. int checkboard (void)
  125. {
  126. #if defined(CONFIG_MPC5200)
  127. puts ("Board: Motorola MPC5200 (IceCube)\n");
  128. #elif defined(CONFIG_MGT5100)
  129. puts ("Board: Motorola MGT5100 (IceCube)\n");
  130. #endif
  131. return 0;
  132. }
  133. void flash_preinit(void)
  134. {
  135. /*
  136. * Now, when we are in RAM, enable flash write
  137. * access for detection process.
  138. * Note that CS_BOOT cannot be cleared when
  139. * executing in flash.
  140. */
  141. #if defined(CONFIG_MGT5100)
  142. *(vu_long *)MPC5XXX_ADDECR &= ~(1 << 25); /* disable CS_BOOT */
  143. *(vu_long *)MPC5XXX_ADDECR |= (1 << 16); /* enable CS0 */
  144. #endif
  145. *(vu_long *)MPC5XXX_BOOTCS_CFG &= ~0x1; /* clear RO */
  146. }
  147. #ifdef CONFIG_PCI
  148. static struct pci_controller hose;
  149. extern void pci_mpc5xxx_init(struct pci_controller *);
  150. void pci_init_board(void)
  151. {
  152. pci_mpc5xxx_init(&hose);
  153. }
  154. #endif