plu405.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  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 <asm/io.h>
  26. #include <command.h>
  27. #include <malloc.h>
  28. #if 0
  29. #define FPGA_DEBUG
  30. #endif
  31. DECLARE_GLOBAL_DATA_PTR;
  32. extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
  33. extern void lxt971_no_sleep(void);
  34. /* fpga configuration data - gzip compressed and generated by bin2c */
  35. const unsigned char fpgadata[] =
  36. {
  37. #include "fpgadata.c"
  38. };
  39. /*
  40. * include common fpga code (for esd boards)
  41. */
  42. #include "../common/fpga.c"
  43. /*
  44. * include common auto-update code (for esd boards)
  45. */
  46. #include "../common/auto_update.h"
  47. au_image_t au_image[] = {
  48. {"plu405/preinst.img", 0, -1, AU_SCRIPT},
  49. {"plu405/u-boot.img", 0xfffc0000, 0x00040000, AU_FIRMWARE},
  50. {"plu405/pImage_${bd_type}", 0x00000000, 0x00100000, AU_NAND},
  51. {"plu405/pImage.initrd", 0x00100000, 0x00200000, AU_NAND},
  52. {"plu405/yaffsmt2.img", 0x00300000, 0x01c00000, AU_NAND},
  53. {"plu405/postinst.img", 0, 0, AU_SCRIPT},
  54. };
  55. int N_AU_IMAGES = (sizeof(au_image) / sizeof(au_image[0]));
  56. /* Prototypes */
  57. int gunzip(void *, int, unsigned char *, unsigned long *);
  58. int board_early_init_f (void)
  59. {
  60. /*
  61. * IRQ 0-15 405GP internally generated; active high; level sensitive
  62. * IRQ 16 405GP internally generated; active low; level sensitive
  63. * IRQ 17-24 RESERVED
  64. * IRQ 25 (EXT IRQ 0) CAN0; active low; level sensitive
  65. * IRQ 26 (EXT IRQ 1) SER0 ; active low; level sensitive
  66. * IRQ 27 (EXT IRQ 2) SER1; active low; level sensitive
  67. * IRQ 28 (EXT IRQ 3) FPGA 0; active low; level sensitive
  68. * IRQ 29 (EXT IRQ 4) FPGA 1; active low; level sensitive
  69. * IRQ 30 (EXT IRQ 5) PCI INTA; active low; level sensitive
  70. * IRQ 31 (EXT IRQ 6) COMPACT FLASH; active high; level sensitive
  71. */
  72. mtdcr(uicsr, 0xFFFFFFFF); /* clear all ints */
  73. mtdcr(uicer, 0x00000000); /* disable all ints */
  74. mtdcr(uiccr, 0x00000000); /* set all to be non-critical*/
  75. mtdcr(uicpr, 0xFFFFFF99); /* set int polarities */
  76. mtdcr(uictr, 0x10000000); /* set int trigger levels */
  77. mtdcr(uicvcr, 0x00000001); /* set vect base=0,INT0 highest prio */
  78. mtdcr(uicsr, 0xFFFFFFFF); /* clear all ints */
  79. /*
  80. * EBC Configuration Register: set ready timeout to
  81. * 512 ebc-clks -> ca. 15 us
  82. */
  83. mtebc (epcr, 0xa8400000); /* ebc always driven */
  84. return 0;
  85. }
  86. int misc_init_r (void)
  87. {
  88. unsigned char *duart0_mcr = (unsigned char *)((ulong)DUART0_BA + 4);
  89. unsigned char *duart1_mcr = (unsigned char *)((ulong)DUART1_BA + 4);
  90. unsigned char *dst;
  91. ulong len = sizeof(fpgadata);
  92. int status;
  93. int index;
  94. int i;
  95. /* adjust flash start and offset */
  96. gd->bd->bi_flashstart = 0 - gd->bd->bi_flashsize;
  97. gd->bd->bi_flashoffset = 0;
  98. dst = malloc(CFG_FPGA_MAX_SIZE);
  99. if (gunzip (dst, CFG_FPGA_MAX_SIZE, (uchar *)fpgadata, &len) != 0) {
  100. printf ("GUNZIP ERROR - must RESET board to recover\n");
  101. do_reset (NULL, 0, 0, NULL);
  102. }
  103. status = fpga_boot(dst, len);
  104. if (status != 0) {
  105. printf("\nFPGA: Booting failed ");
  106. switch (status) {
  107. case ERROR_FPGA_PRG_INIT_LOW:
  108. printf("(Timeout: INIT not low "
  109. "after asserting PROGRAM*)\n");
  110. break;
  111. case ERROR_FPGA_PRG_INIT_HIGH:
  112. printf("(Timeout: INIT not high "
  113. "after deasserting PROGRAM*)\n");
  114. break;
  115. case ERROR_FPGA_PRG_DONE:
  116. printf("(Timeout: DONE not high "
  117. "after programming FPGA)\n");
  118. break;
  119. }
  120. /* display infos on fpgaimage */
  121. index = 15;
  122. for (i=0; i<4; i++) {
  123. len = dst[index];
  124. printf("FPGA: %s\n", &(dst[index+1]));
  125. index += len+3;
  126. }
  127. putc ('\n');
  128. /* delayed reboot */
  129. for (i=20; i>0; i--) {
  130. printf("Rebooting in %2d seconds \r",i);
  131. for (index=0;index<1000;index++)
  132. udelay(1000);
  133. }
  134. putc ('\n');
  135. do_reset(NULL, 0, 0, NULL);
  136. }
  137. puts("FPGA: ");
  138. /* display infos on fpgaimage */
  139. index = 15;
  140. for (i=0; i<4; i++) {
  141. len = dst[index];
  142. printf("%s ", &(dst[index+1]));
  143. index += len+3;
  144. }
  145. putc ('\n');
  146. free(dst);
  147. /*
  148. * Reset FPGA via FPGA_DATA pin
  149. */
  150. SET_FPGA(FPGA_PRG | FPGA_CLK);
  151. udelay(1000); /* wait 1ms */
  152. SET_FPGA(FPGA_PRG | FPGA_CLK | FPGA_DATA);
  153. udelay(1000); /* wait 1ms */
  154. /*
  155. * Reset external DUARTs
  156. */
  157. out_be32((void*)GPIO0_OR, in_be32((void*)GPIO0_OR) | CFG_DUART_RST);
  158. udelay(10);
  159. out_be32((void*)GPIO0_OR, in_be32((void*)GPIO0_OR) & ~CFG_DUART_RST);
  160. udelay(1000);
  161. /*
  162. * Set NAND-FLASH GPIO signals to default
  163. */
  164. out_be32((void*)GPIO0_OR,
  165. in_be32((void*)GPIO0_OR) & ~(CFG_NAND_CLE | CFG_NAND_ALE));
  166. out_be32((void*)GPIO0_OR, in_be32((void*)GPIO0_OR) | CFG_NAND_CE);
  167. /*
  168. * Setup EEPROM write protection
  169. */
  170. out_be32((void*)GPIO0_OR, in_be32((void*)GPIO0_OR) | CFG_EEPROM_WP);
  171. out_be32((void*)GPIO0_TCR, in_be32((void*)GPIO0_TCR) | CFG_EEPROM_WP);
  172. /*
  173. * Enable interrupts in exar duart mcr[3]
  174. */
  175. out_8(duart0_mcr, 0x08);
  176. out_8(duart1_mcr, 0x08);
  177. return (0);
  178. }
  179. /*
  180. * Check Board Identity:
  181. */
  182. int checkboard (void)
  183. {
  184. char str[64];
  185. int i = getenv_r ("serial#", str, sizeof(str));
  186. puts ("Board: ");
  187. if (i == -1) {
  188. puts ("### No HW ID - assuming PLU405");
  189. } else {
  190. puts(str);
  191. }
  192. putc ('\n');
  193. return 0;
  194. }
  195. #ifdef CONFIG_IDE_RESET
  196. void ide_set_reset(int on)
  197. {
  198. volatile unsigned short *fpga_mode =
  199. (unsigned short *)((ulong)CFG_FPGA_BASE_ADDR + CFG_FPGA_CTRL);
  200. /*
  201. * Assert or deassert CompactFlash Reset Pin
  202. */
  203. if (on) { /* assert RESET */
  204. *fpga_mode &= ~(CFG_FPGA_CTRL_CF_RESET);
  205. } else { /* release RESET */
  206. *fpga_mode |= CFG_FPGA_CTRL_CF_RESET;
  207. }
  208. }
  209. #endif /* CONFIG_IDE_RESET */
  210. void reset_phy(void)
  211. {
  212. #ifdef CONFIG_LXT971_NO_SLEEP
  213. /*
  214. * Disable sleep mode in LXT971
  215. */
  216. lxt971_no_sleep();
  217. #endif
  218. }
  219. #if defined(CFG_EEPROM_WREN)
  220. /* Input: <dev_addr> I2C address of EEPROM device to enable.
  221. * <state> -1: deliver current state
  222. * 0: disable write
  223. * 1: enable write
  224. * Returns: -1: wrong device address
  225. * 0: dis-/en- able done
  226. * 0/1: current state if <state> was -1.
  227. */
  228. int eeprom_write_enable (unsigned dev_addr, int state)
  229. {
  230. if (CFG_I2C_EEPROM_ADDR != dev_addr) {
  231. return -1;
  232. } else {
  233. switch (state) {
  234. case 1:
  235. /* Enable write access, clear bit GPIO0. */
  236. out_be32((void*)GPIO0_OR,
  237. in_be32((void*)GPIO0_OR) & ~CFG_EEPROM_WP);
  238. state = 0;
  239. break;
  240. case 0:
  241. /* Disable write access, set bit GPIO0. */
  242. out_be32((void*)GPIO0_OR,
  243. in_be32((void*)GPIO0_OR) | CFG_EEPROM_WP);
  244. state = 0;
  245. break;
  246. default:
  247. /* Read current status back. */
  248. state = (0 == (in_be32((void*)GPIO0_OR) &
  249. CFG_EEPROM_WP));
  250. break;
  251. }
  252. }
  253. return state;
  254. }
  255. int do_eep_wren (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  256. {
  257. int query = argc == 1;
  258. int state = 0;
  259. if (query) {
  260. /* Query write access state. */
  261. state = eeprom_write_enable (CFG_I2C_EEPROM_ADDR, -1);
  262. if (state < 0) {
  263. puts ("Query of write access state failed.\n");
  264. } else {
  265. printf ("Write access for device 0x%0x is %sabled.\n",
  266. CFG_I2C_EEPROM_ADDR, state ? "en" : "dis");
  267. state = 0;
  268. }
  269. } else {
  270. if ('0' == argv[1][0]) {
  271. /* Disable write access. */
  272. state = eeprom_write_enable (CFG_I2C_EEPROM_ADDR, 0);
  273. } else {
  274. /* Enable write access. */
  275. state = eeprom_write_enable (CFG_I2C_EEPROM_ADDR, 1);
  276. }
  277. if (state < 0) {
  278. puts ("Setup of write access state failed.\n");
  279. }
  280. }
  281. return state;
  282. }
  283. U_BOOT_CMD(eepwren, 2, 0, do_eep_wren,
  284. "eepwren - Enable / disable / query EEPROM write access\n",
  285. NULL);
  286. #endif /* #if defined(CFG_EEPROM_WREN) */