plu405.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  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. #if 0
  28. #define FPGA_DEBUG
  29. #endif
  30. extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
  31. extern void lxt971_no_sleep(void);
  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. /*
  42. * include common auto-update code (for esd boards)
  43. */
  44. #include "../common/auto_update.h"
  45. au_image_t au_image[] = {
  46. {"plu405/preinst.img", 0, -1, AU_SCRIPT},
  47. {"plu405/u-boot.img", 0xfffc0000, 0x00040000, AU_FIRMWARE},
  48. {"plu405/pImage_${bd_type}", 0x00000000, 0x00100000, AU_NAND},
  49. {"plu405/pImage.initrd", 0x00100000, 0x00200000, AU_NAND},
  50. {"plu405/yaffsmt2.img", 0x00300000, 0x01c00000, AU_NAND},
  51. {"plu405/postinst.img", 0, 0, AU_SCRIPT},
  52. };
  53. int N_AU_IMAGES = (sizeof(au_image) / sizeof(au_image[0]));
  54. /* Prototypes */
  55. int gunzip(void *, int, unsigned char *, unsigned long *);
  56. int board_early_init_f (void)
  57. {
  58. /*
  59. * IRQ 0-15 405GP internally generated; active high; level sensitive
  60. * IRQ 16 405GP internally generated; active low; level sensitive
  61. * IRQ 17-24 RESERVED
  62. * IRQ 25 (EXT IRQ 0) CAN0; active low; level sensitive
  63. * IRQ 26 (EXT IRQ 1) SER0 ; active low; level sensitive
  64. * IRQ 27 (EXT IRQ 2) SER1; active low; level sensitive
  65. * IRQ 28 (EXT IRQ 3) FPGA 0; active low; level sensitive
  66. * IRQ 29 (EXT IRQ 4) FPGA 1; active low; level sensitive
  67. * IRQ 30 (EXT IRQ 5) PCI INTA; active low; level sensitive
  68. * IRQ 31 (EXT IRQ 6) COMPACT FLASH; active high; level sensitive
  69. */
  70. mtdcr(uicsr, 0xFFFFFFFF); /* clear all ints */
  71. mtdcr(uicer, 0x00000000); /* disable all ints */
  72. mtdcr(uiccr, 0x00000000); /* set all to be non-critical*/
  73. mtdcr(uicpr, 0xFFFFFF99); /* set int polarities */
  74. mtdcr(uictr, 0x10000000); /* set int trigger levels */
  75. mtdcr(uicvcr, 0x00000001); /* set vect base=0,INT0 highest priority*/
  76. mtdcr(uicsr, 0xFFFFFFFF); /* clear all ints */
  77. /*
  78. * EBC Configuration Register: set ready timeout to 512 ebc-clks -> ca. 15 us
  79. */
  80. mtebc (epcr, 0xa8400000); /* ebc always driven */
  81. return 0;
  82. }
  83. int misc_init_f (void)
  84. {
  85. return 0; /* dummy implementation */
  86. }
  87. int misc_init_r (void)
  88. {
  89. volatile unsigned char *duart0_mcr = (unsigned char *)((ulong)DUART0_BA + 4);
  90. volatile unsigned char *duart1_mcr = (unsigned char *)((ulong)DUART1_BA + 4);
  91. unsigned char *dst;
  92. ulong len = sizeof(fpgadata);
  93. int status;
  94. int index;
  95. int i;
  96. dst = malloc(CFG_FPGA_MAX_SIZE);
  97. if (gunzip (dst, CFG_FPGA_MAX_SIZE, (uchar *)fpgadata, &len) != 0) {
  98. printf ("GUNZIP ERROR - must RESET board to recover\n");
  99. do_reset (NULL, 0, 0, NULL);
  100. }
  101. status = fpga_boot(dst, len);
  102. if (status != 0) {
  103. printf("\nFPGA: Booting failed ");
  104. switch (status) {
  105. case ERROR_FPGA_PRG_INIT_LOW:
  106. printf("(Timeout: INIT not low after asserting PROGRAM*)\n ");
  107. break;
  108. case ERROR_FPGA_PRG_INIT_HIGH:
  109. printf("(Timeout: INIT not high after deasserting PROGRAM*)\n ");
  110. break;
  111. case ERROR_FPGA_PRG_DONE:
  112. printf("(Timeout: DONE not high after programming FPGA)\n ");
  113. break;
  114. }
  115. /* display infos on fpgaimage */
  116. index = 15;
  117. for (i=0; i<4; i++) {
  118. len = dst[index];
  119. printf("FPGA: %s\n", &(dst[index+1]));
  120. index += len+3;
  121. }
  122. putc ('\n');
  123. /* delayed reboot */
  124. for (i=20; i>0; i--) {
  125. printf("Rebooting in %2d seconds \r",i);
  126. for (index=0;index<1000;index++)
  127. udelay(1000);
  128. }
  129. putc ('\n');
  130. do_reset(NULL, 0, 0, NULL);
  131. }
  132. puts("FPGA: ");
  133. /* display infos on fpgaimage */
  134. index = 15;
  135. for (i=0; i<4; i++) {
  136. len = dst[index];
  137. printf("%s ", &(dst[index+1]));
  138. index += len+3;
  139. }
  140. putc ('\n');
  141. free(dst);
  142. /*
  143. * Reset FPGA via FPGA_DATA pin
  144. */
  145. SET_FPGA(FPGA_PRG | FPGA_CLK);
  146. udelay(1000); /* wait 1ms */
  147. SET_FPGA(FPGA_PRG | FPGA_CLK | FPGA_DATA);
  148. udelay(1000); /* wait 1ms */
  149. /*
  150. * Reset external DUARTs
  151. */
  152. out32(GPIO0_OR, in32(GPIO0_OR) | CFG_DUART_RST); /* set reset to high */
  153. udelay(10); /* wait 10us */
  154. out32(GPIO0_OR, in32(GPIO0_OR) & ~CFG_DUART_RST); /* set reset to low */
  155. udelay(1000); /* wait 1ms */
  156. /*
  157. * Set NAND-FLASH GPIO signals to default
  158. */
  159. out32(GPIO0_OR, in32(GPIO0_OR) & ~(CFG_NAND_CLE | CFG_NAND_ALE));
  160. out32(GPIO0_OR, in32(GPIO0_OR) | CFG_NAND_CE);
  161. /*
  162. * Enable interrupts in exar duart mcr[3]
  163. */
  164. *duart0_mcr = 0x08;
  165. *duart1_mcr = 0x08;
  166. return (0);
  167. }
  168. /*
  169. * Check Board Identity:
  170. */
  171. int checkboard (void)
  172. {
  173. char str[64];
  174. int i = getenv_r ("serial#", str, sizeof(str));
  175. puts ("Board: ");
  176. if (i == -1) {
  177. puts ("### No HW ID - assuming PLU405");
  178. } else {
  179. puts(str);
  180. }
  181. putc ('\n');
  182. return 0;
  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. return (4*1024*1024 << ((val & 0x000e0000) >> 17));
  194. }
  195. int testdram (void)
  196. {
  197. /* TODO: XXX XXX XXX */
  198. printf ("test: 16 MB - ok\n");
  199. return (0);
  200. }
  201. #ifdef CONFIG_IDE_RESET
  202. void ide_set_reset(int on)
  203. {
  204. volatile unsigned short *fpga_mode =
  205. (unsigned short *)((ulong)CFG_FPGA_BASE_ADDR + CFG_FPGA_CTRL);
  206. /*
  207. * Assert or deassert CompactFlash Reset Pin
  208. */
  209. if (on) { /* assert RESET */
  210. *fpga_mode &= ~(CFG_FPGA_CTRL_CF_RESET);
  211. } else { /* release RESET */
  212. *fpga_mode |= CFG_FPGA_CTRL_CF_RESET;
  213. }
  214. }
  215. #endif /* CONFIG_IDE_RESET */
  216. #if (CONFIG_COMMANDS & CFG_CMD_NAND)
  217. #include <linux/mtd/nand_legacy.h>
  218. extern struct nand_chip nand_dev_desc[CFG_MAX_NAND_DEVICE];
  219. void nand_init(void)
  220. {
  221. nand_probe(CFG_NAND_BASE);
  222. if (nand_dev_desc[0].ChipID != NAND_ChipID_UNKNOWN) {
  223. print_size(nand_dev_desc[0].totlen, "\n");
  224. }
  225. }
  226. #endif
  227. #ifdef CONFIG_AUTO_UPDATE_SHOW
  228. void board_auto_update_show(int au_active)
  229. {
  230. if (au_active) {
  231. printf("\n Dies ist die board-funktion: Updating!!!\n");
  232. } else {
  233. printf("\n Dies ist die board-funktion: Updating done!!!\n");
  234. }
  235. }
  236. #endif
  237. void reset_phy(void)
  238. {
  239. #ifdef CONFIG_LXT971_NO_SLEEP
  240. /*
  241. * Disable sleep mode in LXT971
  242. */
  243. lxt971_no_sleep();
  244. #endif
  245. }