plu405.c 8.7 KB

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