hmi1001.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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. #ifndef CFG_RAMBOOT
  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. #if SDRAM_DDR
  43. /* set mode register: extended mode */
  44. *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_EMODE;
  45. __asm__ volatile ("sync");
  46. /* set mode register: reset DLL */
  47. *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE | 0x04000000;
  48. __asm__ volatile ("sync");
  49. #endif
  50. /* precharge all banks */
  51. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit;
  52. __asm__ volatile ("sync");
  53. /* auto refresh */
  54. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000004 | hi_addr_bit;
  55. __asm__ volatile ("sync");
  56. /* set mode register */
  57. *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE;
  58. __asm__ volatile ("sync");
  59. /* normal operation */
  60. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | hi_addr_bit;
  61. __asm__ volatile ("sync");
  62. }
  63. #endif
  64. /*
  65. * ATTENTION: Although partially referenced initdram does NOT make real use
  66. * use of CFG_SDRAM_BASE. The code does not work if CFG_SDRAM_BASE
  67. * is something else than 0x00000000.
  68. */
  69. long int initdram (int board_type)
  70. {
  71. ulong dramsize = 0;
  72. #ifndef CFG_RAMBOOT
  73. ulong test1, test2;
  74. /* setup SDRAM chip selects */
  75. *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x0000001c; /* 512MB at 0x0 */
  76. *(vu_long *)MPC5XXX_SDRAM_CS1CFG = 0x40000000; /* disabled */
  77. __asm__ volatile ("sync");
  78. /* setup config registers */
  79. *(vu_long *)MPC5XXX_SDRAM_CONFIG1 = SDRAM_CONFIG1;
  80. *(vu_long *)MPC5XXX_SDRAM_CONFIG2 = SDRAM_CONFIG2;
  81. __asm__ volatile ("sync");
  82. #if SDRAM_DDR
  83. /* set tap delay */
  84. *(vu_long *)MPC5XXX_CDM_PORCFG = SDRAM_TAPDELAY;
  85. __asm__ volatile ("sync");
  86. #endif
  87. /* find RAM size using SDRAM CS0 only */
  88. sdram_start(0);
  89. test1 = get_ram_size((ulong *)CFG_SDRAM_BASE, 0x20000000);
  90. sdram_start(1);
  91. test2 = get_ram_size((ulong *)CFG_SDRAM_BASE, 0x20000000);
  92. if (test1 > test2) {
  93. sdram_start(0);
  94. dramsize = test1;
  95. } else {
  96. dramsize = test2;
  97. }
  98. /* memory smaller than 1MB is impossible */
  99. if (dramsize < (1 << 20)) {
  100. dramsize = 0;
  101. }
  102. /* set SDRAM CS0 size according to the amount of RAM found */
  103. if (dramsize > 0) {
  104. *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x13 +
  105. __builtin_ffs(dramsize >> 20) - 1;
  106. } else {
  107. *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0; /* disabled */
  108. }
  109. *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize; /* disabled */
  110. #else /* CFG_RAMBOOT */
  111. /* retrieve size of memory connected to SDRAM CS0 */
  112. dramsize = *(vu_long *)MPC5XXX_SDRAM_CS0CFG & 0xFF;
  113. if (dramsize >= 0x13) {
  114. dramsize = (1 << (dramsize - 0x13)) << 20;
  115. } else {
  116. dramsize = 0;
  117. }
  118. /* retrieve size of memory connected to SDRAM CS1 */
  119. dramsize2 = *(vu_long *)MPC5XXX_SDRAM_CS1CFG & 0xFF;
  120. if (dramsize2 >= 0x13) {
  121. dramsize2 = (1 << (dramsize2 - 0x13)) << 20;
  122. } else {
  123. dramsize2 = 0;
  124. }
  125. #endif /* CFG_RAMBOOT */
  126. /* return dramsize + dramsize2; */
  127. return dramsize;
  128. }
  129. int checkboard (void)
  130. {
  131. puts ("Board: HMI1001\n");
  132. return 0;
  133. }
  134. int misc_init_f (void)
  135. {
  136. return 0;
  137. }
  138. int board_early_init_r (void)
  139. {
  140. *(vu_long *)MPC5XXX_BOOTCS_CFG &= ~0x1; /* clear RO */
  141. *(vu_long *)MPC5XXX_BOOTCS_START =
  142. *(vu_long *)MPC5XXX_CS0_START = START_REG(CFG_FLASH_BASE);
  143. *(vu_long *)MPC5XXX_BOOTCS_STOP =
  144. *(vu_long *)MPC5XXX_CS0_STOP = STOP_REG(CFG_FLASH_BASE, CFG_FLASH_SIZE);
  145. return 0;
  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