plu405.c 7.9 KB

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