plu405.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. /*
  2. * (C) Copyright 2001-2003
  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 <malloc.h>
  27. /* ------------------------------------------------------------------------- */
  28. #if 0
  29. #define FPGA_DEBUG
  30. #endif
  31. extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
  32. /* fpga configuration data - gzip compressed and generated by bin2c */
  33. const unsigned char fpgadata[] =
  34. {
  35. #include "fpgadata.c"
  36. };
  37. /*
  38. * include common fpga code (for esd boards)
  39. */
  40. #include "../common/fpga.c"
  41. /* Prototypes */
  42. int gunzip(void *, int, unsigned char *, unsigned long *);
  43. int board_early_init_f (void)
  44. {
  45. /*
  46. * IRQ 0-15 405GP internally generated; active high; level sensitive
  47. * IRQ 16 405GP internally generated; active low; level sensitive
  48. * IRQ 17-24 RESERVED
  49. * IRQ 25 (EXT IRQ 0) CAN0; active low; level sensitive
  50. * IRQ 26 (EXT IRQ 1) SER0 ; active low; level sensitive
  51. * IRQ 27 (EXT IRQ 2) SER1; active low; level sensitive
  52. * IRQ 28 (EXT IRQ 3) FPGA 0; active low; level sensitive
  53. * IRQ 29 (EXT IRQ 4) FPGA 1; active low; level sensitive
  54. * IRQ 30 (EXT IRQ 5) PCI INTA; active low; level sensitive
  55. * IRQ 31 (EXT IRQ 6) COMPACT FLASH; active high; level sensitive
  56. */
  57. mtdcr(uicsr, 0xFFFFFFFF); /* clear all ints */
  58. mtdcr(uicer, 0x00000000); /* disable all ints */
  59. mtdcr(uiccr, 0x00000000); /* set all to be non-critical*/
  60. mtdcr(uicpr, 0xFFFFFF99); /* set int polarities */
  61. mtdcr(uictr, 0x10000000); /* set int trigger levels */
  62. mtdcr(uicvcr, 0x00000001); /* set vect base=0,INT0 highest priority*/
  63. mtdcr(uicsr, 0xFFFFFFFF); /* clear all ints */
  64. /*
  65. * EBC Configuration Register: set ready timeout to 512 ebc-clks -> ca. 15 us
  66. */
  67. mtebc (epcr, 0xa8400000); /* ebc always driven */
  68. return 0;
  69. }
  70. /* ------------------------------------------------------------------------- */
  71. int misc_init_f (void)
  72. {
  73. return 0; /* dummy implementation */
  74. }
  75. int misc_init_r (void)
  76. {
  77. volatile unsigned char *duart0_mcr = (unsigned char *)((ulong)DUART0_BA + 4);
  78. volatile unsigned char *duart1_mcr = (unsigned char *)((ulong)DUART1_BA + 4);
  79. unsigned char *dst;
  80. ulong len = sizeof(fpgadata);
  81. int status;
  82. int index;
  83. int i;
  84. #if 1 /* test-only */
  85. dst = malloc(CFG_FPGA_MAX_SIZE);
  86. if (gunzip (dst, CFG_FPGA_MAX_SIZE, (uchar *)fpgadata, &len) != 0) {
  87. printf ("GUNZIP ERROR - must RESET board to recover\n");
  88. do_reset (NULL, 0, 0, NULL);
  89. }
  90. status = fpga_boot(dst, len);
  91. if (status != 0) {
  92. printf("\nFPGA: Booting failed ");
  93. switch (status) {
  94. case ERROR_FPGA_PRG_INIT_LOW:
  95. printf("(Timeout: INIT not low after asserting PROGRAM*)\n ");
  96. break;
  97. case ERROR_FPGA_PRG_INIT_HIGH:
  98. printf("(Timeout: INIT not high after deasserting PROGRAM*)\n ");
  99. break;
  100. case ERROR_FPGA_PRG_DONE:
  101. printf("(Timeout: DONE not high after programming FPGA)\n ");
  102. break;
  103. }
  104. /* display infos on fpgaimage */
  105. index = 15;
  106. for (i=0; i<4; i++) {
  107. len = dst[index];
  108. printf("FPGA: %s\n", &(dst[index+1]));
  109. index += len+3;
  110. }
  111. putc ('\n');
  112. /* delayed reboot */
  113. for (i=20; i>0; i--) {
  114. printf("Rebooting in %2d seconds \r",i);
  115. for (index=0;index<1000;index++)
  116. udelay(1000);
  117. }
  118. putc ('\n');
  119. do_reset(NULL, 0, 0, NULL);
  120. }
  121. puts("FPGA: ");
  122. /* display infos on fpgaimage */
  123. index = 15;
  124. for (i=0; i<4; i++) {
  125. len = dst[index];
  126. printf("%s ", &(dst[index+1]));
  127. index += len+3;
  128. }
  129. putc ('\n');
  130. free(dst);
  131. /*
  132. * Reset FPGA via FPGA_DATA pin
  133. */
  134. SET_FPGA(FPGA_PRG | FPGA_CLK);
  135. udelay(1000); /* wait 1ms */
  136. SET_FPGA(FPGA_PRG | FPGA_CLK | FPGA_DATA);
  137. udelay(1000); /* wait 1ms */
  138. /*
  139. * Reset external DUARTs
  140. */
  141. out32(GPIO0_OR, in32(GPIO0_OR) | CFG_DUART_RST); /* set reset to high */
  142. udelay(10); /* wait 10us */
  143. out32(GPIO0_OR, in32(GPIO0_OR) & ~CFG_DUART_RST); /* set reset to low */
  144. udelay(1000); /* wait 1ms */
  145. /*
  146. * Set NAND-FLASH GPIO signals to default
  147. */
  148. out32(GPIO0_OR, in32(GPIO0_OR) & ~(CFG_NAND_CLE | CFG_NAND_ALE));
  149. out32(GPIO0_OR, in32(GPIO0_OR) | CFG_NAND_CE);
  150. /*
  151. * Enable interrupts in exar duart mcr[3]
  152. */
  153. *duart0_mcr = 0x08;
  154. *duart1_mcr = 0x08;
  155. #endif
  156. return (0);
  157. }
  158. /*
  159. * Check Board Identity:
  160. */
  161. int checkboard (void)
  162. {
  163. unsigned char str[64];
  164. int i = getenv_r ("serial#", str, sizeof(str));
  165. puts ("Board: ");
  166. if (i == -1) {
  167. puts ("### No HW ID - assuming PLU405");
  168. } else {
  169. puts(str);
  170. }
  171. putc ('\n');
  172. return 0;
  173. }
  174. /* ------------------------------------------------------------------------- */
  175. long int initdram (int board_type)
  176. {
  177. unsigned long val;
  178. mtdcr(memcfga, mem_mb0cf);
  179. val = mfdcr(memcfgd);
  180. #if 0
  181. printf("\nmb0cf=%x\n", val); /* test-only */
  182. printf("strap=%x\n", mfdcr(strap)); /* test-only */
  183. #endif
  184. return (4*1024*1024 << ((val & 0x000e0000) >> 17));
  185. }
  186. /* ------------------------------------------------------------------------- */
  187. int testdram (void)
  188. {
  189. /* TODO: XXX XXX XXX */
  190. printf ("test: 16 MB - ok\n");
  191. return (0);
  192. }
  193. /* ------------------------------------------------------------------------- */
  194. #ifdef CONFIG_IDE_RESET
  195. void ide_set_reset(int on)
  196. {
  197. volatile unsigned short *fpga_mode =
  198. (unsigned short *)((ulong)CFG_FPGA_BASE_ADDR + CFG_FPGA_CTRL);
  199. /*
  200. * Assert or deassert CompactFlash Reset Pin
  201. */
  202. if (on) { /* assert RESET */
  203. *fpga_mode &= ~(CFG_FPGA_CTRL_CF_RESET);
  204. } else { /* release RESET */
  205. *fpga_mode |= CFG_FPGA_CTRL_CF_RESET;
  206. }
  207. }
  208. #endif /* CONFIG_IDE_RESET */
  209. #if (CONFIG_COMMANDS & CFG_CMD_NAND)
  210. #include <linux/mtd/nand.h>
  211. extern struct nand_chip nand_dev_desc[CFG_MAX_NAND_DEVICE];
  212. void nand_init(void)
  213. {
  214. nand_probe(CFG_NAND_BASE);
  215. if (nand_dev_desc[0].ChipID != NAND_ChipID_UNKNOWN) {
  216. print_size(nand_dev_desc[0].totlen, "\n");
  217. }
  218. }
  219. #endif