dasa_sim.c 5.3 KB

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