plu405.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  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. #undef FPGA_DEBUG
  29. DECLARE_GLOBAL_DATA_PTR;
  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. /* 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(UIC0SR, 0xFFFFFFFF); /* clear all ints */
  58. mtdcr(UIC0ER, 0x00000000); /* disable all ints */
  59. mtdcr(UIC0CR, 0x00000000); /* set all to be non-critical*/
  60. mtdcr(UIC0PR, 0xFFFFFF99); /* set int polarities */
  61. mtdcr(UIC0TR, 0x10000000); /* set int trigger levels */
  62. mtdcr(UIC0VCR, 0x00000001); /* set vect base=0,INT0 highest prio */
  63. mtdcr(UIC0SR, 0xFFFFFFFF); /* clear all ints */
  64. /*
  65. * EBC Configuration Register: set ready timeout to
  66. * 512 ebc-clks -> ca. 15 us
  67. */
  68. mtebc(EBC0_CFG, 0xa8400000); /* ebc always driven */
  69. return 0;
  70. }
  71. int misc_init_r(void)
  72. {
  73. unsigned char *dst;
  74. unsigned char fctr;
  75. ulong len = sizeof(fpgadata);
  76. int status;
  77. int index;
  78. int i;
  79. /* adjust flash start and offset */
  80. gd->bd->bi_flashstart = 0 - gd->bd->bi_flashsize;
  81. gd->bd->bi_flashoffset = 0;
  82. dst = malloc(CONFIG_SYS_FPGA_MAX_SIZE);
  83. if (gunzip(dst, CONFIG_SYS_FPGA_MAX_SIZE,
  84. (uchar *)fpgadata, &len) != 0) {
  85. printf("GUNZIP ERROR - must RESET board to recover\n");
  86. do_reset(NULL, 0, 0, NULL);
  87. }
  88. status = fpga_boot(dst, len);
  89. if (status != 0) {
  90. printf("\nFPGA: Booting failed ");
  91. switch (status) {
  92. case ERROR_FPGA_PRG_INIT_LOW:
  93. printf("(Timeout: INIT not low "
  94. "after asserting PROGRAM*)\n");
  95. break;
  96. case ERROR_FPGA_PRG_INIT_HIGH:
  97. printf("(Timeout: INIT not high "
  98. "after deasserting PROGRAM*)\n");
  99. break;
  100. case ERROR_FPGA_PRG_DONE:
  101. printf("(Timeout: DONE not high "
  102. "after programming FPGA)\n");
  103. break;
  104. }
  105. /* display infos on fpgaimage */
  106. index = 15;
  107. for (i=0; i<4; i++) {
  108. len = dst[index];
  109. printf("FPGA: %s\n", &(dst[index+1]));
  110. index += len+3;
  111. }
  112. putc ('\n');
  113. /* delayed reboot */
  114. for (i=20; i>0; i--) {
  115. printf("Rebooting in %2d seconds \r",i);
  116. for (index=0;index<1000;index++)
  117. udelay(1000);
  118. }
  119. putc('\n');
  120. do_reset(NULL, 0, 0, NULL);
  121. }
  122. puts("FPGA: ");
  123. /* display infos on fpgaimage */
  124. index = 15;
  125. for (i=0; i<4; i++) {
  126. len = dst[index];
  127. printf("%s ", &(dst[index+1]));
  128. index += len+3;
  129. }
  130. putc('\n');
  131. free(dst);
  132. /*
  133. * Reset FPGA via FPGA_DATA pin
  134. */
  135. SET_FPGA(FPGA_PRG | FPGA_CLK);
  136. udelay(1000); /* wait 1ms */
  137. SET_FPGA(FPGA_PRG | FPGA_CLK | FPGA_DATA);
  138. udelay(1000); /* wait 1ms */
  139. /*
  140. * Reset external DUARTs
  141. */
  142. out_be32((void*)GPIO0_OR,
  143. in_be32((void*)GPIO0_OR) | CONFIG_SYS_DUART_RST);
  144. udelay(10);
  145. out_be32((void*)GPIO0_OR,
  146. in_be32((void*)GPIO0_OR) & ~CONFIG_SYS_DUART_RST);
  147. udelay(1000);
  148. /*
  149. * Set NAND-FLASH GPIO signals to default
  150. */
  151. out_be32((void*)GPIO0_OR,
  152. in_be32((void*)GPIO0_OR) &
  153. ~(CONFIG_SYS_NAND_CLE | CONFIG_SYS_NAND_ALE));
  154. out_be32((void*)GPIO0_OR,
  155. in_be32((void*)GPIO0_OR) | CONFIG_SYS_NAND_CE);
  156. /*
  157. * Setup EEPROM write protection
  158. */
  159. out_be32((void*)GPIO0_OR,
  160. in_be32((void*)GPIO0_OR) | CONFIG_SYS_EEPROM_WP);
  161. out_be32((void*)GPIO0_TCR,
  162. in_be32((void*)GPIO0_TCR) | CONFIG_SYS_EEPROM_WP);
  163. /*
  164. * Enable interrupts in exar duart mcr[3]
  165. */
  166. out_8((void *)DUART0_BA + 4, 0x08);
  167. out_8((void *)DUART1_BA + 4, 0x08);
  168. /*
  169. * Enable auto RS485 mode in 2nd external uart
  170. */
  171. out_8((void *)DUART1_BA + 3, 0xbf); /* write LCR */
  172. fctr = in_8((void *)DUART1_BA + 1); /* read FCTR */
  173. fctr |= 0x08; /* enable RS485 mode */
  174. out_8((void *)DUART1_BA + 1, fctr); /* write FCTR */
  175. out_8((void *)DUART1_BA + 3, 0); /* write LCR */
  176. return 0;
  177. }
  178. /*
  179. * Check Board Identity:
  180. */
  181. int checkboard(void)
  182. {
  183. char str[64];
  184. int i = getenv_r("serial#", str, sizeof(str));
  185. puts("Board: ");
  186. if (i == -1)
  187. puts("### No HW ID - assuming PLU405");
  188. else
  189. puts(str);
  190. putc('\n');
  191. return 0;
  192. }
  193. #ifdef CONFIG_IDE_RESET
  194. #define FPGA_CTRL (CONFIG_SYS_FPGA_BASE_ADDR + CONFIG_SYS_FPGA_CTRL)
  195. void ide_set_reset(int on)
  196. {
  197. /*
  198. * Assert or deassert CompactFlash Reset Pin
  199. */
  200. if (on) { /* assert RESET */
  201. out_be16((void *)FPGA_CTRL,
  202. in_be16((void *)FPGA_CTRL) &
  203. ~CONFIG_SYS_FPGA_CTRL_CF_RESET);
  204. } else { /* release RESET */
  205. out_be16((void *)FPGA_CTRL,
  206. in_be16((void *)FPGA_CTRL) |
  207. CONFIG_SYS_FPGA_CTRL_CF_RESET);
  208. }
  209. }
  210. #endif /* CONFIG_IDE_RESET */
  211. void reset_phy(void)
  212. {
  213. #ifdef CONFIG_LXT971_NO_SLEEP
  214. /*
  215. * Disable sleep mode in LXT971
  216. */
  217. lxt971_no_sleep();
  218. #endif
  219. }
  220. #if defined(CONFIG_SYS_EEPROM_WREN)
  221. /* Input: <dev_addr> I2C address of EEPROM device to enable.
  222. * <state> -1: deliver current state
  223. * 0: disable write
  224. * 1: enable write
  225. * Returns: -1: wrong device address
  226. * 0: dis-/en- able done
  227. * 0/1: current state if <state> was -1.
  228. */
  229. int eeprom_write_enable(unsigned dev_addr, int state)
  230. {
  231. if (CONFIG_SYS_I2C_EEPROM_ADDR != dev_addr) {
  232. return -1;
  233. } else {
  234. switch (state) {
  235. case 1:
  236. /* Enable write access, clear bit GPIO0. */
  237. out_be32((void*)GPIO0_OR,
  238. in_be32((void*)GPIO0_OR) &
  239. ~CONFIG_SYS_EEPROM_WP);
  240. state = 0;
  241. break;
  242. case 0:
  243. /* Disable write access, set bit GPIO0. */
  244. out_be32((void*)GPIO0_OR,
  245. in_be32((void*)GPIO0_OR) |
  246. CONFIG_SYS_EEPROM_WP);
  247. state = 0;
  248. break;
  249. default:
  250. /* Read current status back. */
  251. state = ((in_be32((void*)GPIO0_OR) &
  252. CONFIG_SYS_EEPROM_WP) == 0);
  253. break;
  254. }
  255. }
  256. return state;
  257. }
  258. int do_eep_wren(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  259. {
  260. int query = argc == 1;
  261. int state = 0;
  262. if (query) {
  263. /* Query write access state. */
  264. state = eeprom_write_enable(CONFIG_SYS_I2C_EEPROM_ADDR, -1);
  265. if (state < 0) {
  266. puts("Query of write access state failed.\n");
  267. } else {
  268. printf("Write access for device 0x%0x is %sabled.\n",
  269. CONFIG_SYS_I2C_EEPROM_ADDR,
  270. state ? "en" : "dis");
  271. state = 0;
  272. }
  273. } else {
  274. if (argv[1][0] == '0') {
  275. /* Disable write access. */
  276. state = eeprom_write_enable(CONFIG_SYS_I2C_EEPROM_ADDR,
  277. 0);
  278. } else {
  279. /* Enable write access. */
  280. state = eeprom_write_enable(CONFIG_SYS_I2C_EEPROM_ADDR,
  281. 1);
  282. }
  283. if (state < 0)
  284. puts("Setup of write access state failed.\n");
  285. }
  286. return state;
  287. }
  288. U_BOOT_CMD(eepwren, 2, 0, do_eep_wren,
  289. "Enable / disable / query EEPROM write access",
  290. ""
  291. );
  292. #endif /* #if defined(CONFIG_SYS_EEPROM_WREN) */