apc405.c 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  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 <command.h>
  26. #include <malloc.h>
  27. /* ------------------------------------------------------------------------- */
  28. #if 0
  29. #define FPGA_DEBUG
  30. #endif
  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. /* Prototypes */
  43. int gunzip(void *, int, unsigned char *, unsigned long *);
  44. #ifdef CONFIG_LCD_USED
  45. /* logo bitmap data - gzip compressed and generated by bin2c */
  46. unsigned char logo_bmp[] =
  47. {
  48. #include CFG_LCD_LOGO_NAME
  49. };
  50. /*
  51. * include common lcd code (for esd boards)
  52. */
  53. #include "../common/lcd.c"
  54. #include CFG_LCD_HEADER_NAME
  55. #endif /* CONFIG_LCD_USED */
  56. int board_revision(void)
  57. {
  58. unsigned long cntrl0Reg;
  59. unsigned long value;
  60. /*
  61. * Get version of APC405 board from GPIO's
  62. */
  63. /*
  64. * Setup GPIO pins (CS2/GPIO11 and CS3/GPIO12 as GPIO)
  65. */
  66. cntrl0Reg = mfdcr(cntrl0);
  67. mtdcr(cntrl0, cntrl0Reg | 0x03000000);
  68. out32(GPIO0_ODR, in32(GPIO0_ODR) & ~0x00180000);
  69. out32(GPIO0_TCR, in32(GPIO0_TCR) & ~0x00180000);
  70. udelay(1000); /* wait some time before reading input */
  71. value = in32(GPIO0_IR) & 0x00180000; /* get config bits */
  72. /*
  73. * Restore GPIO settings
  74. */
  75. mtdcr(cntrl0, cntrl0Reg);
  76. switch (value) {
  77. case 0x00180000:
  78. /* CS2==1 && CS3==1 -> version <= 1.2 */
  79. return 2;
  80. case 0x00080000:
  81. /* CS2==0 && CS3==1 -> version 1.3 */
  82. return 3;
  83. #if 0 /* not yet manufactured ! */
  84. case 0x00100000:
  85. /* CS2==1 && CS3==0 -> version 1.4 */
  86. return 4;
  87. case 0x00000000:
  88. /* CS2==0 && CS3==0 -> version 1.5 */
  89. return 5;
  90. #endif
  91. default:
  92. /* should not be reached! */
  93. return 0;
  94. }
  95. }
  96. int board_early_init_f (void)
  97. {
  98. /*
  99. * First pull fpga-prg pin low, to disable fpga logic (on version 2 board)
  100. */
  101. out32(GPIO0_ODR, 0x00000000); /* no open drain pins */
  102. out32(GPIO0_TCR, CFG_FPGA_PRG); /* setup for output */
  103. out32(GPIO0_OR, CFG_FPGA_PRG); /* set output pins to high */
  104. out32(GPIO0_OR, 0); /* pull prg low */
  105. /*
  106. * IRQ 0-15 405GP internally generated; active high; level sensitive
  107. * IRQ 16 405GP internally generated; active low; level sensitive
  108. * IRQ 17-24 RESERVED
  109. * IRQ 25 (EXT IRQ 0) CAN0; active low; level sensitive
  110. * IRQ 26 (EXT IRQ 1) SER0 ; active low; level sensitive
  111. * IRQ 27 (EXT IRQ 2) SER1; active low; level sensitive
  112. * IRQ 28 (EXT IRQ 3) FPGA 0; active low; level sensitive
  113. * IRQ 29 (EXT IRQ 4) FPGA 1; active low; level sensitive
  114. * IRQ 30 (EXT IRQ 5) PCI INTA; active low; level sensitive
  115. * IRQ 31 (EXT IRQ 6) COMPACT FLASH; active high; level sensitive
  116. */
  117. mtdcr(uicsr, 0xFFFFFFFF); /* clear all ints */
  118. mtdcr(uicer, 0x00000000); /* disable all ints */
  119. mtdcr(uiccr, 0x00000000); /* set all to be non-critical*/
  120. mtdcr(uicpr, 0xFFFFFF81); /* set int polarities */
  121. mtdcr(uictr, 0x10000000); /* set int trigger levels */
  122. mtdcr(uicvcr, 0x00000001); /* set vect base=0,INT0 highest priority*/
  123. mtdcr(uicsr, 0xFFFFFFFF); /* clear all ints */
  124. /*
  125. * EBC Configuration Register: set ready timeout to 512 ebc-clks -> ca. 15 us
  126. */
  127. #if 1 /* test-only */
  128. mtebc (epcr, 0xa8400000); /* ebc always driven */
  129. #else
  130. mtebc (epcr, 0x28400000); /* ebc in high-z */
  131. #endif
  132. return 0;
  133. }
  134. /* ------------------------------------------------------------------------- */
  135. int misc_init_f (void)
  136. {
  137. return 0; /* dummy implementation */
  138. }
  139. int misc_init_r (void)
  140. {
  141. DECLARE_GLOBAL_DATA_PTR;
  142. volatile unsigned short *fpga_mode =
  143. (unsigned short *)((ulong)CFG_FPGA_BASE_ADDR + CFG_FPGA_CTRL);
  144. volatile unsigned short *fpga_ctrl2 =
  145. (unsigned short *)((ulong)CFG_FPGA_BASE_ADDR + CFG_FPGA_CTRL2);
  146. volatile unsigned char *duart0_mcr =
  147. (unsigned char *)((ulong)DUART0_BA + 4);
  148. volatile unsigned char *duart1_mcr =
  149. (unsigned char *)((ulong)DUART1_BA + 4);
  150. volatile unsigned short *fuji_lcdbl_pwm =
  151. (unsigned short *)((ulong)0xf0100200 + 0xa0);
  152. unsigned char *dst;
  153. ulong len = sizeof(fpgadata);
  154. int status;
  155. int index;
  156. int i;
  157. unsigned long cntrl0Reg;
  158. /*
  159. * Setup GPIO pins (CS6+CS7 as GPIO)
  160. */
  161. cntrl0Reg = mfdcr(cntrl0);
  162. mtdcr(cntrl0, cntrl0Reg | 0x00300000);
  163. dst = malloc(CFG_FPGA_MAX_SIZE);
  164. if (gunzip (dst, CFG_FPGA_MAX_SIZE, (uchar *)fpgadata, &len) != 0) {
  165. printf ("GUNZIP ERROR - must RESET board to recover\n");
  166. do_reset (NULL, 0, 0, NULL);
  167. }
  168. status = fpga_boot(dst, len);
  169. if (status != 0) {
  170. printf("\nFPGA: Booting failed ");
  171. switch (status) {
  172. case ERROR_FPGA_PRG_INIT_LOW:
  173. printf("(Timeout: INIT not low after asserting PROGRAM*)\n ");
  174. break;
  175. case ERROR_FPGA_PRG_INIT_HIGH:
  176. printf("(Timeout: INIT not high after deasserting PROGRAM*)\n ");
  177. break;
  178. case ERROR_FPGA_PRG_DONE:
  179. printf("(Timeout: DONE not high after programming FPGA)\n ");
  180. break;
  181. }
  182. /* display infos on fpgaimage */
  183. index = 15;
  184. for (i=0; i<4; i++) {
  185. len = dst[index];
  186. printf("FPGA: %s\n", &(dst[index+1]));
  187. index += len+3;
  188. }
  189. putc ('\n');
  190. /* delayed reboot */
  191. for (i=20; i>0; i--) {
  192. printf("Rebooting in %2d seconds \r",i);
  193. for (index=0;index<1000;index++)
  194. udelay(1000);
  195. }
  196. putc ('\n');
  197. do_reset(NULL, 0, 0, NULL);
  198. }
  199. /* restore gpio/cs settings */
  200. mtdcr(cntrl0, cntrl0Reg);
  201. puts("FPGA: ");
  202. /* display infos on fpgaimage */
  203. index = 15;
  204. for (i=0; i<4; i++) {
  205. len = dst[index];
  206. printf("%s ", &(dst[index+1]));
  207. index += len+3;
  208. }
  209. putc ('\n');
  210. free(dst);
  211. /*
  212. * Reset FPGA via FPGA_DATA pin
  213. */
  214. SET_FPGA(FPGA_PRG | FPGA_CLK);
  215. udelay(1000); /* wait 1ms */
  216. SET_FPGA(FPGA_PRG | FPGA_CLK | FPGA_DATA);
  217. udelay(1000); /* wait 1ms */
  218. /*
  219. * Write board revision in FPGA
  220. */
  221. *fpga_ctrl2 = (*fpga_ctrl2 & 0xfff0) | (gd->board_type & 0x000f);
  222. /*
  223. * Enable power on PS/2 interface (with reset)
  224. */
  225. *fpga_mode |= CFG_FPGA_CTRL_PS2_RESET;
  226. for (i=0;i<100;i++)
  227. udelay(1000);
  228. udelay(1000);
  229. *fpga_mode &= ~CFG_FPGA_CTRL_PS2_RESET;
  230. /*
  231. * Enable interrupts in exar duart mcr[3]
  232. */
  233. *duart0_mcr = 0x08;
  234. *duart1_mcr = 0x08;
  235. /*
  236. * Init lcd interface and display logo
  237. */
  238. lcd_init((uchar *)CFG_LCD_BIG_REG, (uchar *)CFG_LCD_BIG_MEM,
  239. regs_13806_640_480_16bpp,
  240. sizeof(regs_13806_640_480_16bpp)/sizeof(regs_13806_640_480_16bpp[0]),
  241. logo_bmp, sizeof(logo_bmp));
  242. /*
  243. * Reset microcontroller and setup backlight PWM controller
  244. */
  245. *fpga_mode |= 0x0014;
  246. for (i=0;i<10;i++)
  247. udelay(1000);
  248. *fpga_mode |= 0x001c;
  249. *fuji_lcdbl_pwm = 0x00ff;
  250. return (0);
  251. }
  252. /*
  253. * Check Board Identity:
  254. */
  255. int checkboard (void)
  256. {
  257. DECLARE_GLOBAL_DATA_PTR;
  258. unsigned char str[64];
  259. int i = getenv_r ("serial#", str, sizeof(str));
  260. puts ("Board: ");
  261. if (i == -1) {
  262. puts ("### No HW ID - assuming APC405");
  263. } else {
  264. puts(str);
  265. }
  266. gd->board_type = board_revision();
  267. printf(", Rev 1.%ld\n", gd->board_type);
  268. /*
  269. * Disable sleep mode in LXT971
  270. */
  271. lxt971_no_sleep();
  272. return 0;
  273. }
  274. /* ------------------------------------------------------------------------- */
  275. long int initdram (int board_type)
  276. {
  277. unsigned long val;
  278. mtdcr(memcfga, mem_mb0cf);
  279. val = mfdcr(memcfgd);
  280. #if 0
  281. printf("\nmb0cf=%x\n", val); /* test-only */
  282. printf("strap=%x\n", mfdcr(strap)); /* test-only */
  283. #endif
  284. return (4*1024*1024 << ((val & 0x000e0000) >> 17));
  285. }
  286. /* ------------------------------------------------------------------------- */
  287. int testdram (void)
  288. {
  289. /* TODO: XXX XXX XXX */
  290. printf ("test: 16 MB - ok\n");
  291. return (0);
  292. }
  293. /* ------------------------------------------------------------------------- */
  294. #ifdef CONFIG_IDE_RESET
  295. void ide_set_reset(int on)
  296. {
  297. volatile unsigned short *fpga_mode =
  298. (unsigned short *)((ulong)CFG_FPGA_BASE_ADDR + CFG_FPGA_CTRL);
  299. /*
  300. * Assert or deassert CompactFlash Reset Pin
  301. */
  302. if (on) { /* assert RESET */
  303. *fpga_mode &= ~(CFG_FPGA_CTRL_CF_RESET);
  304. } else { /* release RESET */
  305. *fpga_mode |= CFG_FPGA_CTRL_CF_RESET;
  306. }
  307. }
  308. #endif /* CONFIG_IDE_RESET */
  309. /* ------------------------------------------------------------------------- */