o2dnt.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. #include <netdev.h>
  30. #define SDRAM_MODE 0x00CD0000
  31. #define SDRAM_CONTROL 0x504F0000
  32. #define SDRAM_CONFIG1 0xD2322800
  33. #define SDRAM_CONFIG2 0x8AD70000
  34. static void sdram_start (int hi_addr)
  35. {
  36. long hi_addr_bit = hi_addr ? 0x01000000 : 0;
  37. /* unlock mode register */
  38. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000000 | hi_addr_bit;
  39. __asm__ volatile ("sync");
  40. /* precharge all banks */
  41. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit;
  42. __asm__ volatile ("sync");
  43. /* precharge all banks */
  44. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit;
  45. __asm__ volatile ("sync");
  46. /* auto refresh */
  47. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000004 | hi_addr_bit;
  48. __asm__ volatile ("sync");
  49. /* set mode register */
  50. *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE;
  51. __asm__ volatile ("sync");
  52. /* normal operation */
  53. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | hi_addr_bit;
  54. __asm__ volatile ("sync");
  55. }
  56. /*
  57. * ATTENTION: Although partially referenced initdram does NOT make real use
  58. * use of CONFIG_SYS_SDRAM_BASE. The code does not work if CONFIG_SYS_SDRAM_BASE
  59. * is something else than 0x00000000.
  60. */
  61. phys_size_t initdram (int board_type)
  62. {
  63. ulong dramsize = 0;
  64. ulong dramsize2 = 0;
  65. ulong test1, test2;
  66. /* setup SDRAM chip selects */
  67. *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x0000001e;/* 2G at 0x0 */
  68. *(vu_long *)MPC5XXX_SDRAM_CS1CFG = 0x80000000;/* disabled */
  69. __asm__ volatile ("sync");
  70. /* setup config registers */
  71. *(vu_long *)MPC5XXX_SDRAM_CONFIG1 = SDRAM_CONFIG1;
  72. *(vu_long *)MPC5XXX_SDRAM_CONFIG2 = SDRAM_CONFIG2;
  73. __asm__ volatile ("sync");
  74. /* find RAM size using SDRAM CS0 only */
  75. sdram_start(0);
  76. test1 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x80000000);
  77. sdram_start(1);
  78. test2 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x80000000);
  79. if (test1 > test2) {
  80. sdram_start(0);
  81. dramsize = test1;
  82. } else {
  83. dramsize = test2;
  84. }
  85. /* memory smaller than 1MB is impossible */
  86. if (dramsize < (1 << 20)) {
  87. dramsize = 0;
  88. }
  89. /* set SDRAM CS0 size according to the amount of RAM found */
  90. if (dramsize > 0)
  91. *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x13 + __builtin_ffs(dramsize >> 20) - 1;
  92. else
  93. *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0; /* disabled */
  94. /* let SDRAM CS1 start right after CS0 */
  95. *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize + 0x0000001e;/* 2G */
  96. /* find RAM size using SDRAM CS1 only */
  97. if (!dramsize)
  98. sdram_start(0);
  99. test2 = test1 = get_ram_size((long *)(CONFIG_SYS_SDRAM_BASE + dramsize), 0x80000000);
  100. if (!dramsize) {
  101. sdram_start(1);
  102. test2 = get_ram_size((long *)(CONFIG_SYS_SDRAM_BASE + dramsize), 0x80000000);
  103. }
  104. if (test1 > test2) {
  105. sdram_start(0);
  106. dramsize2 = test1;
  107. } else {
  108. dramsize2 = test2;
  109. }
  110. /* memory smaller than 1MB is impossible */
  111. if (dramsize2 < (1 << 20))
  112. dramsize2 = 0;
  113. /* set SDRAM CS1 size according to the amount of RAM found */
  114. if (dramsize2 > 0) {
  115. *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize
  116. | (0x13 + __builtin_ffs(dramsize2 >> 20) - 1);
  117. } else {
  118. *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize; /* disabled */
  119. }
  120. return dramsize + dramsize2;
  121. }
  122. int checkboard (void)
  123. {
  124. puts ("Board: O2DNT\n");
  125. return 0;
  126. }
  127. void flash_preinit(void)
  128. {
  129. /*
  130. * Now, when we are in RAM, enable flash write
  131. * access for detection process.
  132. * Note that CS_BOOT cannot be cleared when
  133. * executing in flash.
  134. */
  135. *(vu_long *)MPC5XXX_BOOTCS_CFG &= ~0x1; /* clear RO */
  136. }
  137. void flash_afterinit(ulong size)
  138. {
  139. if (size == 0x800000) { /* adjust mapping */
  140. *(vu_long *)MPC5XXX_BOOTCS_START = *(vu_long *)MPC5XXX_CS0_START =
  141. START_REG(CONFIG_SYS_BOOTCS_START | size);
  142. *(vu_long *)MPC5XXX_BOOTCS_STOP = *(vu_long *)MPC5XXX_CS0_STOP =
  143. STOP_REG(CONFIG_SYS_BOOTCS_START | size, size);
  144. }
  145. }
  146. #ifdef CONFIG_PCI
  147. static struct pci_controller hose;
  148. extern void pci_mpc5xxx_init(struct pci_controller *);
  149. void pci_init_board(void)
  150. {
  151. pci_mpc5xxx_init(&hose);
  152. }
  153. #endif
  154. int board_eth_init(bd_t *bis)
  155. {
  156. cpu_eth_init(bis); /* Built in FEC comes first */
  157. return pci_eth_init(bis);
  158. }