plu405.c 9.2 KB

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