pci405.c 6.4 KB

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