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