plu405.c 8.6 KB

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