pdnb3.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /*
  2. * (C) Copyright 2006
  3. * Stefan Roese, DENX Software Engineering, sr@denx.de.
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #include <common.h>
  8. #include <command.h>
  9. #include <malloc.h>
  10. #include <asm/arch/ixp425.h>
  11. DECLARE_GLOBAL_DATA_PTR;
  12. /* predefine these here for FPGA programming (before including fpga.c) */
  13. #define SET_FPGA(data) *IXP425_GPIO_GPOUTR = (data)
  14. #define FPGA_DONE_STATE (*IXP425_GPIO_GPINR & CONFIG_SYS_FPGA_DONE)
  15. #define FPGA_INIT_STATE (*IXP425_GPIO_GPINR & CONFIG_SYS_FPGA_INIT)
  16. #define OLD_VAL old_val
  17. static unsigned long old_val = 0;
  18. /*
  19. * include common fpga code (for prodrive boards)
  20. */
  21. #include "../common/fpga.c"
  22. /*
  23. * Miscelaneous platform dependent initialisations
  24. */
  25. int board_init(void)
  26. {
  27. /* adress of boot parameters */
  28. gd->bd->bi_boot_params = 0x00000100;
  29. GPIO_OUTPUT_SET(CONFIG_SYS_GPIO_FPGA_RESET);
  30. GPIO_OUTPUT_ENABLE(CONFIG_SYS_GPIO_FPGA_RESET);
  31. GPIO_OUTPUT_SET(CONFIG_SYS_GPIO_SYS_RUNNING);
  32. GPIO_OUTPUT_ENABLE(CONFIG_SYS_GPIO_SYS_RUNNING);
  33. /*
  34. * Setup GPIO's for FPGA programming
  35. */
  36. GPIO_OUTPUT_CLEAR(CONFIG_SYS_GPIO_PRG);
  37. GPIO_OUTPUT_CLEAR(CONFIG_SYS_GPIO_CLK);
  38. GPIO_OUTPUT_CLEAR(CONFIG_SYS_GPIO_DATA);
  39. GPIO_OUTPUT_ENABLE(CONFIG_SYS_GPIO_PRG);
  40. GPIO_OUTPUT_ENABLE(CONFIG_SYS_GPIO_CLK);
  41. GPIO_OUTPUT_ENABLE(CONFIG_SYS_GPIO_DATA);
  42. GPIO_OUTPUT_DISABLE(CONFIG_SYS_GPIO_INIT);
  43. GPIO_OUTPUT_DISABLE(CONFIG_SYS_GPIO_DONE);
  44. /*
  45. * Setup GPIO's for interrupts
  46. */
  47. GPIO_OUTPUT_DISABLE(CONFIG_SYS_GPIO_PCI_INTA);
  48. GPIO_INT_ACT_LOW_SET(CONFIG_SYS_GPIO_PCI_INTA);
  49. GPIO_OUTPUT_DISABLE(CONFIG_SYS_GPIO_PCI_INTB);
  50. GPIO_INT_ACT_LOW_SET(CONFIG_SYS_GPIO_PCI_INTB);
  51. GPIO_OUTPUT_DISABLE(CONFIG_SYS_GPIO_RESTORE_INT);
  52. GPIO_INT_ACT_LOW_SET(CONFIG_SYS_GPIO_RESTORE_INT);
  53. GPIO_OUTPUT_DISABLE(CONFIG_SYS_GPIO_RESTART_INT);
  54. GPIO_INT_ACT_LOW_SET(CONFIG_SYS_GPIO_RESTART_INT);
  55. /*
  56. * Setup GPIO's for 33MHz clock output
  57. */
  58. *IXP425_GPIO_GPCLKR = 0x01FF0000;
  59. GPIO_OUTPUT_ENABLE(CONFIG_SYS_GPIO_CLK_33M);
  60. /*
  61. * Setup other chip select's
  62. */
  63. *IXP425_EXP_CS1 = CONFIG_SYS_EXP_CS1;
  64. return 0;
  65. }
  66. /*
  67. * Check Board Identity
  68. */
  69. int checkboard(void)
  70. {
  71. char buf[64];
  72. int i = getenv_f("serial#", buf, sizeof(buf));
  73. puts("Board: PDNB3");
  74. if (i > 0) {
  75. puts(", serial# ");
  76. puts(buf);
  77. }
  78. putc('\n');
  79. return (0);
  80. }
  81. int dram_init(void)
  82. {
  83. gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
  84. gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
  85. return (0);
  86. }
  87. int do_fpga_boot(unsigned char *fpgadata)
  88. {
  89. unsigned char *dst;
  90. int status;
  91. int index;
  92. int i;
  93. ulong len = CONFIG_SYS_MALLOC_LEN;
  94. /*
  95. * Setup GPIO's for FPGA programming
  96. */
  97. GPIO_OUTPUT_CLEAR(CONFIG_SYS_GPIO_PRG);
  98. GPIO_OUTPUT_CLEAR(CONFIG_SYS_GPIO_CLK);
  99. GPIO_OUTPUT_CLEAR(CONFIG_SYS_GPIO_DATA);
  100. /*
  101. * Save value so no readback is required upon programming
  102. */
  103. old_val = *IXP425_GPIO_GPOUTR;
  104. /*
  105. * First try to decompress fpga image (gzip compressed?)
  106. */
  107. dst = malloc(CONFIG_SYS_FPGA_MAX_SIZE);
  108. if (gunzip(dst, CONFIG_SYS_FPGA_MAX_SIZE, (uchar *)fpgadata, &len) != 0) {
  109. printf("Error: Image has to be gzipp'ed!\n");
  110. return -1;
  111. }
  112. status = fpga_boot(dst, len);
  113. if (status != 0) {
  114. printf("\nFPGA: Booting failed ");
  115. switch (status) {
  116. case ERROR_FPGA_PRG_INIT_LOW:
  117. printf("(Timeout: INIT not low after asserting PROGRAM*)\n ");
  118. break;
  119. case ERROR_FPGA_PRG_INIT_HIGH:
  120. printf("(Timeout: INIT not high after deasserting PROGRAM*)\n ");
  121. break;
  122. case ERROR_FPGA_PRG_DONE:
  123. printf("(Timeout: DONE not high after programming FPGA)\n ");
  124. break;
  125. }
  126. /* display infos on fpgaimage */
  127. index = 15;
  128. for (i=0; i<4; i++) {
  129. len = dst[index];
  130. printf("FPGA: %s\n", &(dst[index+1]));
  131. index += len+3;
  132. }
  133. putc ('\n');
  134. /* delayed reboot */
  135. for (i=5; i>0; i--) {
  136. printf("Rebooting in %2d seconds \r",i);
  137. for (index=0;index<1000;index++)
  138. udelay(1000);
  139. }
  140. putc('\n');
  141. do_reset(NULL, 0, 0, NULL);
  142. }
  143. puts("FPGA: ");
  144. /* display infos on fpgaimage */
  145. index = 15;
  146. for (i=0; i<4; i++) {
  147. len = dst[index];
  148. printf("%s ", &(dst[index+1]));
  149. index += len+3;
  150. }
  151. putc('\n');
  152. free(dst);
  153. /*
  154. * Reset FPGA
  155. */
  156. GPIO_OUTPUT_CLEAR(CONFIG_SYS_GPIO_FPGA_RESET);
  157. udelay(10);
  158. GPIO_OUTPUT_SET(CONFIG_SYS_GPIO_FPGA_RESET);
  159. return (0);
  160. }
  161. int do_fpga(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  162. {
  163. ulong addr;
  164. if (argc < 2)
  165. return cmd_usage(cmdtp);
  166. addr = simple_strtoul(argv[1], NULL, 16);
  167. return do_fpga_boot((unsigned char *)addr);
  168. }
  169. U_BOOT_CMD(
  170. fpga, 2, 0, do_fpga,
  171. "boot FPGA",
  172. "address size\n - boot FPGA with gzipped image at <address>"
  173. );
  174. #if defined(CONFIG_CMD_PCI) || defined(CONFIG_PCI)
  175. extern struct pci_controller hose;
  176. extern void pci_ixp_init(struct pci_controller * hose);
  177. void pci_init_board(void)
  178. {
  179. extern void pci_ixp_init (struct pci_controller *hose);
  180. pci_ixp_init(&hose);
  181. }
  182. #endif