pci405.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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 <asm/processor.h>
  25. #include <command.h>
  26. #include <cmd_boot.h>
  27. #include <malloc.h>
  28. #include <pci.h>
  29. #include <405gp_pci.h>
  30. #include "pci405.h"
  31. /* ------------------------------------------------------------------------- */
  32. #if 0
  33. #define FPGA_DEBUG
  34. #endif
  35. /* fpga configuration data - generated by bin2cc */
  36. const unsigned char fpgadata[] =
  37. {
  38. #include "fpgadata.c"
  39. };
  40. /*
  41. * include common fpga code (for esd boards)
  42. */
  43. #include "../common/fpga.c"
  44. /* Prototypes */
  45. int gunzip(void *, int, unsigned char *, int *);
  46. int board_pre_init (void)
  47. {
  48. unsigned long cntrl0Reg;
  49. /*
  50. * IRQ 0-15 405GP internally generated; active high; level sensitive
  51. * IRQ 16 405GP internally generated; active low; level sensitive
  52. * IRQ 17-24 RESERVED
  53. * IRQ 25 (EXT IRQ 0) CAN0; active low; level sensitive
  54. * IRQ 26 (EXT IRQ 1) CAN1; active low; level sensitive
  55. * IRQ 27 (EXT IRQ 2) CAN2; active low; level sensitive
  56. * IRQ 28 (EXT IRQ 3) CAN3; active low; level sensitive
  57. * IRQ 29 (EXT IRQ 4) unused; active low; level sensitive
  58. * IRQ 30 (EXT IRQ 5) FPGA Timestamp; active low; level sensitive
  59. * IRQ 31 (EXT IRQ 6) PCI Reset; active low; level sensitive
  60. */
  61. mtdcr(uicsr, 0xFFFFFFFF); /* clear all ints */
  62. mtdcr(uicer, 0x00000000); /* disable all ints */
  63. mtdcr(uiccr, 0x00000000); /* set all to be non-critical*/
  64. mtdcr(uicpr, 0xFFFFFF80); /* set int polarities */
  65. mtdcr(uictr, 0x10000000); /* set int trigger levels */
  66. mtdcr(uicvcr, 0x00000001); /* set vect base=0,INT0 highest priority*/
  67. mtdcr(uicsr, 0xFFFFFFFF); /* clear all ints */
  68. /*
  69. * Setup GPIO pins (IRQ4/GPIO21 as GPIO)
  70. */
  71. cntrl0Reg = mfdcr(cntrl0);
  72. mtdcr(cntrl0, cntrl0Reg | 0x00008000);
  73. return 0;
  74. }
  75. /* ------------------------------------------------------------------------- */
  76. int misc_init_f (void)
  77. {
  78. return 0; /* dummy implementation */
  79. }
  80. int misc_init_r (void)
  81. {
  82. unsigned char *dst;
  83. ulong len = sizeof(fpgadata);
  84. int status;
  85. int index;
  86. int i;
  87. struct pci_config_regs *pci_regs;
  88. unsigned int *ptr;
  89. unsigned int *magic;
  90. /*
  91. * On PCI-405 the environment is saved in eeprom!
  92. * FPGA can be gzip compressed (malloc) and booted this late.
  93. */
  94. dst = malloc(CFG_FPGA_MAX_SIZE);
  95. if (gunzip (dst, CFG_FPGA_MAX_SIZE, (uchar *)fpgadata, (int *)&len) != 0) {
  96. printf ("GUNZIP ERROR - must RESET board to recover\n");
  97. do_reset (NULL, 0, 0, NULL);
  98. }
  99. status = fpga_boot(dst, len);
  100. if (status != 0) {
  101. printf("\nFPGA: Booting failed ");
  102. switch (status) {
  103. case ERROR_FPGA_PRG_INIT_LOW:
  104. printf("(Timeout: INIT not low after asserting PROGRAM*)\n ");
  105. break;
  106. case ERROR_FPGA_PRG_INIT_HIGH:
  107. printf("(Timeout: INIT not high after deasserting PROGRAM*)\n ");
  108. break;
  109. case ERROR_FPGA_PRG_DONE:
  110. printf("(Timeout: DONE not high after programming FPGA)\n ");
  111. break;
  112. }
  113. /* display infos on fpgaimage */
  114. index = 15;
  115. for (i=0; i<4; i++) {
  116. len = dst[index];
  117. printf("FPGA: %s\n", &(dst[index+1]));
  118. index += len+3;
  119. }
  120. putc ('\n');
  121. /* delayed reboot */
  122. for (i=20; i>0; i--) {
  123. printf("Rebooting in %2d seconds \r",i);
  124. for (index=0;index<1000;index++)
  125. udelay(1000);
  126. }
  127. putc ('\n');
  128. do_reset(NULL, 0, 0, NULL);
  129. }
  130. puts("FPGA: ");
  131. /* display infos on fpgaimage */
  132. index = 15;
  133. for (i=0; i<4; i++) {
  134. len = dst[index];
  135. printf("%s ", &(dst[index+1]));
  136. index += len+3;
  137. }
  138. putc ('\n');
  139. /*
  140. * Reset FPGA via FPGA_DATA pin
  141. */
  142. SET_FPGA(FPGA_PRG | FPGA_CLK);
  143. udelay(1000); /* wait 1ms */
  144. SET_FPGA(FPGA_PRG | FPGA_CLK | FPGA_DATA);
  145. udelay(1000); /* wait 1ms */
  146. /*
  147. * Check if magic for pci reconfig is written
  148. */
  149. magic = (unsigned int *)0x00000004;
  150. if (*magic == PCI_RECONFIG_MAGIC) {
  151. /*
  152. * Rewrite pci config regs (only after soft-reset with magic set)
  153. */
  154. ptr = (unsigned int *)PCI_REGS_ADDR;
  155. if (crc32(0, (char *)PCI_REGS_ADDR+4, PCI_REGS_LEN-4) == *ptr) {
  156. puts("Restoring PCI Configurations Regs!\n");
  157. ptr = (unsigned int *)PCI_REGS_ADDR + 1;
  158. for (i=0; i<0x40; i+=4) {
  159. pci_write_config_dword(PCIDEVID_405GP, i, *ptr++);
  160. }
  161. }
  162. mtdcr(uicsr, 0xFFFFFFFF); /* clear all ints */
  163. *magic = 0; /* clear pci reconfig magic again */
  164. }
  165. free(dst);
  166. return (0);
  167. }
  168. /*
  169. * Check Board Identity:
  170. */
  171. int checkboard (void)
  172. {
  173. unsigned char str[64];
  174. int i = getenv_r ("serial#", str, sizeof(str));
  175. puts ("Board: ");
  176. if (i == -1) {
  177. puts ("### No HW ID - assuming PCI405");
  178. } else {
  179. puts (str);
  180. }
  181. putc ('\n');
  182. return 0;
  183. }
  184. /* ------------------------------------------------------------------------- */
  185. long int initdram (int board_type)
  186. {
  187. unsigned long val;
  188. mtdcr(memcfga, mem_mb0cf);
  189. val = mfdcr(memcfgd);
  190. #if 0
  191. printf("\nmb0cf=%x\n", val); /* test-only */
  192. printf("strap=%x\n", mfdcr(strap)); /* test-only */
  193. #endif
  194. #if 0 /* test-only: all PCI405 version must report 16mb */
  195. return (4*1024*1024 << ((val & 0x000e0000) >> 17));
  196. #else
  197. return (16*1024*1024);
  198. #endif
  199. }
  200. /* ------------------------------------------------------------------------- */
  201. int testdram (void)
  202. {
  203. /* TODO: XXX XXX XXX */
  204. printf ("test: 16 MB - ok\n");
  205. return (0);
  206. }
  207. /* ------------------------------------------------------------------------- */