pdnb3.c 5.6 KB

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