dasa_sim.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /*
  2. * (C) Copyright 2001
  3. * Stefan Roese, esd gmbh germany, stefan.roese@esd-electronics.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 <netdev.h>
  25. #include "dasa_sim.h"
  26. /* ------------------------------------------------------------------------- */
  27. #undef FPGA_DEBUG
  28. #define _NOT_USED_ 0xFFFFFFFF
  29. /* ------------------------------------------------------------------------- */
  30. /* fpga configuration data - generated by bit2inc */
  31. static unsigned char fpgadata[] = {
  32. #include "fpgadata.c"
  33. };
  34. #define FPGA_PRG_SLEEP 32 /* fpga program sleep-time */
  35. #define LOAD_LONG(a) a
  36. /******************************************************************************
  37. *
  38. * sysFpgaBoot - Load fpga-image into fpga
  39. *
  40. */
  41. static int fpgaBoot (void)
  42. {
  43. int i, j, index, len;
  44. unsigned char b;
  45. int imageSize;
  46. imageSize = sizeof (fpgadata);
  47. /* display infos on fpgaimage */
  48. index = 15;
  49. for (i = 0; i < 4; i++) {
  50. len = fpgadata[index];
  51. index += len + 3;
  52. }
  53. /* search for preamble 0xFF2X */
  54. for (index = 0; index < imageSize - 1; index++) {
  55. if ((fpgadata[index] == 0xff)
  56. && ((fpgadata[index + 1] & 0xf0) == 0x20))
  57. break;
  58. }
  59. /* enable cs1 instead of user0... */
  60. *(unsigned long *) 0x50000084 &= ~0x00000002;
  61. #ifdef FPGA_DEBUG
  62. printf ("%s\n",
  63. ((in_be32 ((void *)0x50000084) & 0x00010000) == 0) ?
  64. "NOT DONE" : "DONE");
  65. #endif
  66. /* init fpga by asserting and deasserting PROGRAM* (USER2)... */
  67. *(unsigned long *) 0x50000084 &= ~0x00000400;
  68. udelay (FPGA_PRG_SLEEP * 1000);
  69. *(unsigned long *) 0x50000084 |= 0x00000400;
  70. udelay (FPGA_PRG_SLEEP * 1000);
  71. #ifdef FPGA_DEBUG
  72. printf ("%s\n",
  73. ((in_be32 ((void *)0x50000084) & 0x00010000) == 0) ?
  74. "NOT DONE" : "DONE");
  75. #endif
  76. /* cs1: disable burst, disable ready */
  77. *(unsigned long *) 0x50000114 &= ~0x00000300;
  78. /* cs1: set write timing */
  79. *(unsigned long *) 0x50000118 |= 0x00010900;
  80. /* write configuration-data into fpga... */
  81. for (i = index; i < imageSize; i++) {
  82. b = fpgadata[i];
  83. for (j = 0; j < 8; j++) {
  84. *(unsigned long *) 0x30000000 =
  85. ((b & 0x80) == 0x80)
  86. ? LOAD_LONG (0x03030101)
  87. : LOAD_LONG (0x02020000);
  88. b <<= 1;
  89. }
  90. }
  91. #ifdef FPGA_DEBUG
  92. printf ("%s\n",
  93. ((in_be32 ((void *)0x50000084) & 0x00010000) == 0) ?
  94. "NOT DONE" : "DONE");
  95. #endif
  96. /* set cs1 to 32 bit data-width, disable burst, enable ready */
  97. *(unsigned long *) 0x50000114 |= 0x00000202;
  98. *(unsigned long *) 0x50000114 &= ~0x00000100;
  99. /* cs1: set iop access to little endian */
  100. *(unsigned long *) 0x50000114 &= ~0x00000010;
  101. /* cs1: set read and write timing */
  102. *(unsigned long *) 0x50000118 = 0x00010000;
  103. *(unsigned long *) 0x5000011c = 0x00010001;
  104. #ifdef FPGA_DEBUG
  105. printf ("%s\n",
  106. ((in_be32 ((void *)0x50000084) & 0x00010000) == 0) ?
  107. "NOT DONE" : "DONE");
  108. #endif
  109. /* wait for 30 ms... */
  110. udelay (30 * 1000);
  111. /* check if fpga's DONE signal - correctly booted ? */
  112. if ((*(unsigned long *) 0x50000084 & 0x00010000) == 0)
  113. return -1;
  114. return 0;
  115. }
  116. int board_early_init_f (void)
  117. {
  118. /*
  119. * Init pci regs
  120. */
  121. *(unsigned long *) 0x50000304 = 0x02900007; /* enable mem/io/master bits */
  122. *(unsigned long *) 0x500001b4 = 0x00000000; /* disable pci interrupt output enable */
  123. *(unsigned long *) 0x50000354 = 0x00c05800; /* disable emun interrupt output enable */
  124. *(unsigned long *) 0x50000344 = 0x00000000; /* disable pme interrupt output enable */
  125. *(unsigned long *) 0x50000310 = 0x00000000; /* pcibar0 */
  126. *(unsigned long *) 0x50000314 = 0x00000000; /* pcibar1 */
  127. *(unsigned long *) 0x50000318 = 0x00000000; /* pcibar2 */
  128. return 0;
  129. }
  130. /*
  131. * Check Board Identity:
  132. */
  133. int checkboard (void)
  134. {
  135. int index;
  136. int len;
  137. char str[64];
  138. int i = getenv_r ("serial#", str, sizeof (str));
  139. int fpga;
  140. unsigned short val;
  141. puts ("Board: ");
  142. /*
  143. * Boot onboard FPGA
  144. */
  145. fpga = fpgaBoot ();
  146. if (!i || strncmp (str, "DASA_SIM", 8)) {
  147. puts ("### No HW ID - assuming DASA_SIM");
  148. }
  149. puts (str);
  150. if (fpga == 0) {
  151. val = *(unsigned short *) 0x30000202;
  152. printf (" (Id=%d Version=%d Revision=%d)",
  153. (val & 0x07f8) >> 3, val & 0x0001, (val & 0x0006) >> 1);
  154. puts ("\nFPGA: ");
  155. /* display infos on fpgaimage */
  156. index = 15;
  157. for (i = 0; i < 4; i++) {
  158. len = fpgadata[index];
  159. printf ("%s ", &(fpgadata[index + 1]));
  160. index += len + 3;
  161. }
  162. } else {
  163. puts ("\nFPGA: Booting failed!");
  164. }
  165. putc ('\n');
  166. return 0;
  167. }
  168. phys_size_t initdram (int board_type)
  169. {
  170. return (16 * 1024 * 1024);
  171. }