kvme080.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /*
  2. * (C) Copyright 2005
  3. * Sangmoon Kim, Etin Systems. dogoil@etinsys.com.
  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 <mpc824x.h>
  25. #include <pci.h>
  26. #include <i2c.h>
  27. #include <netdev.h>
  28. #include <asm/processor.h>
  29. #include <asm/mmu.h>
  30. int checkboard(void)
  31. {
  32. puts ("Board: KVME080\n");
  33. return 0;
  34. }
  35. unsigned long setdram(int m, int row, int col, int bank)
  36. {
  37. int i;
  38. unsigned long start, end;
  39. uint32_t mccr1;
  40. uint32_t mear1 = 0, emear1 = 0, msar1 = 0, emsar1 = 0;
  41. uint32_t mear2 = 0, emear2 = 0, msar2 = 0, emsar2 = 0;
  42. uint8_t mber = 0;
  43. CONFIG_READ_WORD(MCCR1, mccr1);
  44. mccr1 &= 0xffff0000;
  45. start = CONFIG_SYS_SDRAM_BASE;
  46. end = start + (1 << (col + row + 3) ) * bank - 1;
  47. for (i = 0; i < m; i++) {
  48. mccr1 |= ((row == 13)? 2 : (bank == 4)? 0 : 3) << i * 2;
  49. if (i < 4) {
  50. msar1 |= ((start >> 20) & 0xff) << i * 8;
  51. emsar1 |= ((start >> 28) & 0xff) << i * 8;
  52. mear1 |= ((end >> 20) & 0xff) << i * 8;
  53. emear1 |= ((end >> 28) & 0xff) << i * 8;
  54. } else {
  55. msar2 |= ((start >> 20) & 0xff) << (i-4) * 8;
  56. emsar2 |= ((start >> 28) & 0xff) << (i-4) * 8;
  57. mear2 |= ((end >> 20) & 0xff) << (i-4) * 8;
  58. emear2 |= ((end >> 28) & 0xff) << (i-4) * 8;
  59. }
  60. mber |= 1 << i;
  61. start += (1 << (col + row + 3) ) * bank;
  62. end += (1 << (col + row + 3) ) * bank;
  63. }
  64. for (; i < 8; i++) {
  65. if (i < 4) {
  66. msar1 |= 0xff << i * 8;
  67. emsar1 |= 0x30 << i * 8;
  68. mear1 |= 0xff << i * 8;
  69. emear1 |= 0x30 << i * 8;
  70. } else {
  71. msar2 |= 0xff << (i-4) * 8;
  72. emsar2 |= 0x30 << (i-4) * 8;
  73. mear2 |= 0xff << (i-4) * 8;
  74. emear2 |= 0x30 << (i-4) * 8;
  75. }
  76. }
  77. CONFIG_WRITE_WORD(MCCR1, mccr1);
  78. CONFIG_WRITE_WORD(MSAR1, msar1);
  79. CONFIG_WRITE_WORD(EMSAR1, emsar1);
  80. CONFIG_WRITE_WORD(MEAR1, mear1);
  81. CONFIG_WRITE_WORD(EMEAR1, emear1);
  82. CONFIG_WRITE_WORD(MSAR2, msar2);
  83. CONFIG_WRITE_WORD(EMSAR2, emsar2);
  84. CONFIG_WRITE_WORD(MEAR2, mear2);
  85. CONFIG_WRITE_WORD(EMEAR2, emear2);
  86. CONFIG_WRITE_BYTE(MBER, mber);
  87. return (1 << (col + row + 3) ) * bank * m;
  88. }
  89. phys_size_t initdram(int board_type)
  90. {
  91. unsigned int msr;
  92. long int size = 0;
  93. msr = mfmsr();
  94. mtmsr(msr & ~(MSR_IR | MSR_DR));
  95. mtspr(IBAT2L, CONFIG_SYS_IBAT0L + 0x10000000);
  96. mtspr(IBAT2U, CONFIG_SYS_IBAT0U + 0x10000000);
  97. mtspr(DBAT2L, CONFIG_SYS_DBAT0L + 0x10000000);
  98. mtspr(DBAT2U, CONFIG_SYS_DBAT0U + 0x10000000);
  99. mtmsr(msr);
  100. if (setdram(2,13,10,4) == get_ram_size(CONFIG_SYS_SDRAM_BASE, 0x20000000))
  101. size = 0x20000000; /* 512MB */
  102. else if (setdram(1,13,10,4) == get_ram_size(CONFIG_SYS_SDRAM_BASE, 0x10000000))
  103. size = 0x10000000; /* 256MB */
  104. else if (setdram(2,13,9,4) == get_ram_size(CONFIG_SYS_SDRAM_BASE, 0x10000000))
  105. size = 0x10000000; /* 256MB */
  106. else if (setdram(1,13,9,4) == get_ram_size(CONFIG_SYS_SDRAM_BASE, 0x08000000))
  107. size = 0x08000000; /* 128MB */
  108. else if (setdram(2,12,9,4) == get_ram_size(CONFIG_SYS_SDRAM_BASE, 0x08000000))
  109. size = 0x08000000; /* 128MB */
  110. else if (setdram(1,12,9,4) == get_ram_size(CONFIG_SYS_SDRAM_BASE, 0x04000000))
  111. size = 0x04000000; /* 64MB */
  112. msr = mfmsr();
  113. mtmsr(msr & ~(MSR_IR | MSR_DR));
  114. mtspr(IBAT2L, CONFIG_SYS_IBAT2L);
  115. mtspr(IBAT2U, CONFIG_SYS_IBAT2U);
  116. mtspr(DBAT2L, CONFIG_SYS_DBAT2L);
  117. mtspr(DBAT2U, CONFIG_SYS_DBAT2U);
  118. mtmsr(msr);
  119. return size;
  120. }
  121. struct pci_controller hose;
  122. void pci_init_board(void)
  123. {
  124. pci_mpc824x_init(&hose);
  125. }
  126. int board_early_init_f(void)
  127. {
  128. *(volatile unsigned char *)(0xff080120) = 0xfb;
  129. return 0;
  130. }
  131. int board_early_init_r(void)
  132. {
  133. unsigned int msr;
  134. CONFIG_WRITE_WORD(ERCR1, 0x95ff8000);
  135. CONFIG_WRITE_WORD(ERCR3, 0x0c00000e);
  136. CONFIG_WRITE_WORD(ERCR4, 0x0800000e);
  137. msr = mfmsr();
  138. mtmsr(msr & ~(MSR_IR | MSR_DR));
  139. mtspr(IBAT1L, 0x70000000 | BATL_PP_10 | BATL_CACHEINHIBIT);
  140. mtspr(IBAT1U, 0x70000000 | BATU_BL_256M | BATU_VS | BATU_VP);
  141. mtspr(DBAT1L, 0x70000000 | BATL_PP_10 | BATL_CACHEINHIBIT);
  142. mtspr(DBAT1U, 0x70000000 | BATU_BL_256M | BATU_VS | BATU_VP);
  143. mtmsr(msr);
  144. return 0;
  145. }
  146. extern int multiverse_init(void);
  147. int misc_init_r(void)
  148. {
  149. multiverse_init();
  150. return 0;
  151. }
  152. void *nvram_read(void *dest, const long src, size_t count)
  153. {
  154. volatile uchar *d = (volatile uchar*) dest;
  155. volatile uchar *s = (volatile uchar*) src;
  156. while(count--) {
  157. *d++ = *s++;
  158. asm volatile("sync");
  159. }
  160. return dest;
  161. }
  162. void nvram_write(long dest, const void *src, size_t count)
  163. {
  164. volatile uchar *d = (volatile uchar*)dest;
  165. volatile uchar *s = (volatile uchar*)src;
  166. while(count--) {
  167. *d++ = *s++;
  168. asm volatile("sync");
  169. }
  170. }
  171. int board_eth_init(bd_t *bis)
  172. {
  173. return pci_eth_init(bis);
  174. }