pci405.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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. unsigned int *ptr;
  88. unsigned int *magic;
  89. /*
  90. * On PCI-405 the environment is saved in eeprom!
  91. * FPGA can be gzip compressed (malloc) and booted this late.
  92. */
  93. dst = malloc(CFG_FPGA_MAX_SIZE);
  94. if (gunzip (dst, CFG_FPGA_MAX_SIZE, (uchar *)fpgadata, (int *)&len) != 0) {
  95. printf ("GUNZIP ERROR - must RESET board to recover\n");
  96. do_reset (NULL, 0, 0, NULL);
  97. }
  98. status = fpga_boot(dst, len);
  99. if (status != 0) {
  100. printf("\nFPGA: Booting failed ");
  101. switch (status) {
  102. case ERROR_FPGA_PRG_INIT_LOW:
  103. printf("(Timeout: INIT not low after asserting PROGRAM*)\n ");
  104. break;
  105. case ERROR_FPGA_PRG_INIT_HIGH:
  106. printf("(Timeout: INIT not high after deasserting PROGRAM*)\n ");
  107. break;
  108. case ERROR_FPGA_PRG_DONE:
  109. printf("(Timeout: DONE not high after programming FPGA)\n ");
  110. break;
  111. }
  112. /* display infos on fpgaimage */
  113. index = 15;
  114. for (i=0; i<4; i++) {
  115. len = dst[index];
  116. printf("FPGA: %s\n", &(dst[index+1]));
  117. index += len+3;
  118. }
  119. putc ('\n');
  120. /* delayed reboot */
  121. for (i=20; i>0; i--) {
  122. printf("Rebooting in %2d seconds \r",i);
  123. for (index=0;index<1000;index++)
  124. udelay(1000);
  125. }
  126. putc ('\n');
  127. do_reset(NULL, 0, 0, NULL);
  128. }
  129. puts("FPGA: ");
  130. /* display infos on fpgaimage */
  131. index = 15;
  132. for (i=0; i<4; i++) {
  133. len = dst[index];
  134. printf("%s ", &(dst[index+1]));
  135. index += len+3;
  136. }
  137. putc ('\n');
  138. /*
  139. * Reset FPGA via FPGA_DATA pin
  140. */
  141. SET_FPGA(FPGA_PRG | FPGA_CLK);
  142. udelay(1000); /* wait 1ms */
  143. SET_FPGA(FPGA_PRG | FPGA_CLK | FPGA_DATA);
  144. udelay(1000); /* wait 1ms */
  145. /*
  146. * Check if magic for pci reconfig is written
  147. */
  148. magic = (unsigned int *)0x00000004;
  149. if (*magic == PCI_RECONFIG_MAGIC) {
  150. /*
  151. * Rewrite pci config regs (only after soft-reset with magic set)
  152. */
  153. ptr = (unsigned int *)PCI_REGS_ADDR;
  154. if (crc32(0, (char *)PCI_REGS_ADDR+4, PCI_REGS_LEN-4) == *ptr) {
  155. puts("Restoring PCI Configurations Regs!\n");
  156. ptr = (unsigned int *)PCI_REGS_ADDR + 1;
  157. for (i=0; i<0x40; i+=4) {
  158. pci_write_config_dword(PCIDEVID_405GP, i, *ptr++);
  159. }
  160. }
  161. mtdcr(uicsr, 0xFFFFFFFF); /* clear all ints */
  162. *magic = 0; /* clear pci reconfig magic again */
  163. }
  164. free(dst);
  165. return (0);
  166. }
  167. /*
  168. * Check Board Identity:
  169. */
  170. int checkboard (void)
  171. {
  172. unsigned char str[64];
  173. int i = getenv_r ("serial#", str, sizeof(str));
  174. puts ("Board: ");
  175. if (i == -1) {
  176. puts ("### No HW ID - assuming PCI405");
  177. } else {
  178. puts (str);
  179. }
  180. putc ('\n');
  181. return 0;
  182. }
  183. /* ------------------------------------------------------------------------- */
  184. long int initdram (int board_type)
  185. {
  186. unsigned long val;
  187. mtdcr(memcfga, mem_mb0cf);
  188. val = mfdcr(memcfgd);
  189. #if 0
  190. printf("\nmb0cf=%x\n", val); /* test-only */
  191. printf("strap=%x\n", mfdcr(strap)); /* test-only */
  192. #endif
  193. #if 0 /* test-only: all PCI405 version must report 16mb */
  194. return (4*1024*1024 << ((val & 0x000e0000) >> 17));
  195. #else
  196. return (16*1024*1024);
  197. #endif
  198. }
  199. /* ------------------------------------------------------------------------- */
  200. int testdram (void)
  201. {
  202. /* TODO: XXX XXX XXX */
  203. printf ("test: 16 MB - ok\n");
  204. return (0);
  205. }
  206. /* ------------------------------------------------------------------------- */