cmd_pci405.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /*
  2. * (C) Copyright 2002
  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 <malloc.h>
  25. #include <net.h>
  26. #include <asm/io.h>
  27. #include <pci.h>
  28. #include <405gp_pci.h>
  29. #include <cmd_bsp.h>
  30. #include "pci405.h"
  31. #if (CONFIG_COMMANDS & CFG_CMD_BSP)
  32. extern int do_bootm (cmd_tbl_t *, int, int, char *[]);
  33. #if 0 /* test-only */
  34. #include "../common/fpga.c"
  35. void error_print(void)
  36. {
  37. int i;
  38. volatile unsigned char *ptr;
  39. volatile unsigned long *ptr2;
  40. printf("\n 2nd SJA1000:\n");
  41. ptr = 0xf0000100;
  42. for (i=0; i<0x20; i++) {
  43. printf("%02x ", *ptr++);
  44. }
  45. ptr2 = 0xf0400008;
  46. printf("\nTimestamp = %x\n", *ptr2);
  47. udelay(1000);
  48. printf("Timestamp = %x\n", *ptr2);
  49. udelay(1000);
  50. printf("Timestamp = %x\n", *ptr2);
  51. #if 0 /* test-only */
  52. /*
  53. * Reset FPGA via FPGA_DATA pin
  54. */
  55. printf("Resetting FPGA...\n");
  56. SET_FPGA(FPGA_PRG | FPGA_CLK);
  57. udelay(1000); /* wait 1ms */
  58. SET_FPGA(FPGA_PRG | FPGA_CLK | FPGA_DATA);
  59. udelay(1000); /* wait 1ms */
  60. do_loadpci(NULL, 0,0, NULL);
  61. #endif
  62. }
  63. void read_loop(void)
  64. {
  65. int i;
  66. volatile unsigned char *ptr;
  67. volatile unsigned char val;
  68. volatile unsigned long *ptr2;
  69. printf("\nread loop on 1st sja1000...");
  70. while (1) {
  71. ptr = 0xf0000000;
  72. /* printf("\n1st SJA1000:\n");*/
  73. for (i=0; i<0x20; i++) {
  74. i = i;
  75. val = *ptr++;
  76. /* printf("%02x ", val);*/
  77. }
  78. /* Abort if ctrl-c was pressed */
  79. if (ctrlc()) {
  80. puts("\nAbort\n");
  81. return 0;
  82. }
  83. }
  84. }
  85. #endif
  86. /*
  87. * Command loadpci: wait for signal from host and boot image.
  88. */
  89. int do_loadpci(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  90. {
  91. unsigned int *ptr = 0;
  92. int count = 0;
  93. int count2 = 0;
  94. int status;
  95. int i;
  96. char addr[16];
  97. char str[] = "\\|/-";
  98. char *local_args[2];
  99. #if 0 /* test-only */
  100. puts("\nStarting sja1000 test...");
  101. {
  102. int count;
  103. volatile unsigned char *ptr;
  104. volatile unsigned char val;
  105. volatile unsigned char val2;
  106. #if 1 /* write test */
  107. ptr = 0xf0000014;
  108. for (i=1; i<11; i++)
  109. *ptr++ = i;
  110. #endif
  111. count = 0;
  112. while (1) {
  113. count++;
  114. #if 0 /* write test */
  115. ptr = 0xf0000014;
  116. for (i=1; i<11; i++)
  117. *ptr++ = i;
  118. #endif
  119. #if 1 /* read test */
  120. ptr = 0xf0000014;
  121. for (i=1; i<11; i++) {
  122. val = *ptr++;
  123. #if 1
  124. if (val != i) {
  125. ptr = 0xf0000100;
  126. val = *ptr; /* trigger las */
  127. ptr = 0xf0000014;
  128. val2 = *ptr;
  129. printf("\nERROR: count=%d: soll=%x ist=%x -> staring read loop on 1st sja1000...\n", count, i, val);
  130. printf("soll=%x ist=%x -> staring read loop on 1st sja1000...\n", 1, val2);
  131. return 0; /* test-only */
  132. udelay(1000);
  133. error_print();
  134. read_loop();
  135. return 0;
  136. }
  137. #endif
  138. }
  139. #endif
  140. /* Abort if ctrl-c was pressed */
  141. if (ctrlc()) {
  142. puts("\nAbort\n");
  143. return 0;
  144. }
  145. if (!(count % 100000)) {
  146. printf(".");
  147. }
  148. }
  149. }
  150. #endif
  151. /*
  152. * Mark sync address
  153. */
  154. ptr = 0;
  155. *ptr = 0xffffffff;
  156. puts("\nWaiting for image from pci host -");
  157. /*
  158. * Wait for host to write the start address
  159. */
  160. while (*ptr == 0xffffffff) {
  161. count++;
  162. if (!(count % 100)) {
  163. count2++;
  164. putc(0x08); /* backspace */
  165. putc(str[count2 % 4]);
  166. }
  167. /* Abort if ctrl-c was pressed */
  168. if (ctrlc()) {
  169. puts("\nAbort\n");
  170. return 0;
  171. }
  172. udelay(1000);
  173. }
  174. if (*ptr == PCI_RECONFIG_MAGIC) {
  175. /*
  176. * Save own pci configuration in PRAM
  177. */
  178. memset((char *)PCI_REGS_ADDR, 0, PCI_REGS_LEN);
  179. ptr = (unsigned int *)PCI_REGS_ADDR + 1;
  180. for (i=0; i<0x40; i+=4) {
  181. pci_read_config_dword(PCIDEVID_405GP, i, ptr++);
  182. }
  183. ptr = (unsigned int *)PCI_REGS_ADDR;
  184. *ptr = crc32(0, (char *)PCI_REGS_ADDR+4, PCI_REGS_LEN-4);
  185. printf("\nStoring PCI Configuration Regs...\n");
  186. } else {
  187. sprintf(addr, "%08x", *ptr);
  188. /*
  189. * Boot image
  190. */
  191. printf("\nBooting image at addr 0x%s ...\n", addr);
  192. setenv("loadaddr", addr);
  193. local_args[0] = argv[0];
  194. local_args[1] = NULL;
  195. status = do_bootm (cmdtp, 0, 1, local_args);
  196. }
  197. return 0;
  198. }
  199. #endif