debris.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /*
  2. * (C) Copyright 2000
  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 <net.h>
  26. #include <pci.h>
  27. #include <i2c.h>
  28. #include <netdev.h>
  29. DECLARE_GLOBAL_DATA_PTR;
  30. int checkboard (void)
  31. {
  32. /*TODO: Check processor type */
  33. puts ( "Board: Debris "
  34. #ifdef CONFIG_MPC8240
  35. "8240"
  36. #endif
  37. #ifdef CONFIG_MPC8245
  38. "8245"
  39. #endif
  40. " ##Test not implemented yet##\n");
  41. return 0;
  42. }
  43. #if 0 /* NOT USED */
  44. int checkflash (void)
  45. {
  46. /* TODO: XXX XXX XXX */
  47. printf ("## Test not implemented yet ##\n");
  48. return (0);
  49. }
  50. #endif
  51. phys_size_t initdram (int board_type)
  52. {
  53. int m, row, col, bank, i;
  54. unsigned long start, end;
  55. uint32_t mccr1;
  56. uint32_t mear1 = 0, emear1 = 0, msar1 = 0, emsar1 = 0;
  57. uint32_t mear2 = 0, emear2 = 0, msar2 = 0, emsar2 = 0;
  58. uint8_t mber = 0;
  59. i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
  60. if (i2c_reg_read (0x50, 2) != 0x04) return 0; /* Memory type */
  61. m = i2c_reg_read (0x50, 5); /* # of physical banks */
  62. row = i2c_reg_read (0x50, 3); /* # of rows */
  63. col = i2c_reg_read (0x50, 4); /* # of columns */
  64. bank = i2c_reg_read (0x50, 17); /* # of logical banks */
  65. CONFIG_READ_WORD(MCCR1, mccr1);
  66. mccr1 &= 0xffff0000;
  67. start = CONFIG_SYS_SDRAM_BASE;
  68. end = start + (1 << (col + row + 3) ) * bank - 1;
  69. for (i = 0; i < m; i++) {
  70. mccr1 |= ((row == 13)? 2 : (bank == 4)? 0 : 3) << i * 2;
  71. if (i < 4) {
  72. msar1 |= ((start >> 20) & 0xff) << i * 8;
  73. emsar1 |= ((start >> 28) & 0xff) << i * 8;
  74. mear1 |= ((end >> 20) & 0xff) << i * 8;
  75. emear1 |= ((end >> 28) & 0xff) << i * 8;
  76. } else {
  77. msar2 |= ((start >> 20) & 0xff) << (i-4) * 8;
  78. emsar2 |= ((start >> 28) & 0xff) << (i-4) * 8;
  79. mear2 |= ((end >> 20) & 0xff) << (i-4) * 8;
  80. emear2 |= ((end >> 28) & 0xff) << (i-4) * 8;
  81. }
  82. mber |= 1 << i;
  83. start += (1 << (col + row + 3) ) * bank;
  84. end += (1 << (col + row + 3) ) * bank;
  85. }
  86. for (; i < 8; i++) {
  87. if (i < 4) {
  88. msar1 |= 0xff << i * 8;
  89. emsar1 |= 0x30 << i * 8;
  90. mear1 |= 0xff << i * 8;
  91. emear1 |= 0x30 << i * 8;
  92. } else {
  93. msar2 |= 0xff << (i-4) * 8;
  94. emsar2 |= 0x30 << (i-4) * 8;
  95. mear2 |= 0xff << (i-4) * 8;
  96. emear2 |= 0x30 << (i-4) * 8;
  97. }
  98. }
  99. CONFIG_WRITE_WORD(MCCR1, mccr1);
  100. CONFIG_WRITE_WORD(MSAR1, msar1);
  101. CONFIG_WRITE_WORD(EMSAR1, emsar1);
  102. CONFIG_WRITE_WORD(MEAR1, mear1);
  103. CONFIG_WRITE_WORD(EMEAR1, emear1);
  104. CONFIG_WRITE_WORD(MSAR2, msar2);
  105. CONFIG_WRITE_WORD(EMSAR2, emsar2);
  106. CONFIG_WRITE_WORD(MEAR2, mear2);
  107. CONFIG_WRITE_WORD(EMEAR2, emear2);
  108. CONFIG_WRITE_BYTE(MBER, mber);
  109. return (1 << (col + row + 3) ) * bank * m;
  110. }
  111. /*
  112. * Initialize PCI Devices, report devices found.
  113. */
  114. #ifndef CONFIG_PCI_PNP
  115. static struct pci_config_table pci_debris_config_table[] = {
  116. { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, 0x0f, PCI_ANY_ID,
  117. pci_cfgfunc_config_device, { PCI_ENET0_IOADDR,
  118. PCI_ENET0_MEMADDR,
  119. PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER }},
  120. { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, 0x10, PCI_ANY_ID,
  121. pci_cfgfunc_config_device, { PCI_ENET1_IOADDR,
  122. PCI_ENET1_MEMADDR,
  123. PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER }},
  124. { }
  125. };
  126. #endif
  127. struct pci_controller hose = {
  128. #ifndef CONFIG_PCI_PNP
  129. config_table: pci_debris_config_table,
  130. #endif
  131. };
  132. void pci_init_board(void)
  133. {
  134. pci_mpc824x_init(&hose);
  135. }
  136. void *nvram_read(void *dest, const long src, size_t count)
  137. {
  138. volatile uchar *d = (volatile uchar*) dest;
  139. volatile uchar *s = (volatile uchar*) src;
  140. while(count--) {
  141. *d++ = *s++;
  142. asm volatile("sync");
  143. }
  144. return dest;
  145. }
  146. void nvram_write(long dest, const void *src, size_t count)
  147. {
  148. volatile uchar *d = (volatile uchar*)dest;
  149. volatile uchar *s = (volatile uchar*)src;
  150. while(count--) {
  151. *d++ = *s++;
  152. asm volatile("sync");
  153. }
  154. }
  155. int misc_init_r(void)
  156. {
  157. uchar ethaddr[6];
  158. if (eth_getenv_enetaddr("ethaddr", ethaddr))
  159. /* Write ethernet addr in NVRAM for VxWorks */
  160. nvram_write(CONFIG_ENV_ADDR + CONFIG_SYS_NVRAM_VXWORKS_OFFS,
  161. ethaddr, 6);
  162. return 0;
  163. }
  164. int board_eth_init(bd_t *bis)
  165. {
  166. return pci_eth_init(bis);
  167. }