debris.c 4.5 KB

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