cpci405.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  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 <cmd_boot.h>
  27. #include <malloc.h>
  28. /* ------------------------------------------------------------------------- */
  29. #if 0
  30. #define FPGA_DEBUG
  31. #endif
  32. /* fpga configuration data - generated by bin2cc */
  33. const unsigned char fpgadata[] =
  34. {
  35. #ifdef CONFIG_CPCI405_VER2
  36. # include "fpgadata_cpci4052.c"
  37. #else
  38. # include "fpgadata_cpci405.c"
  39. #endif
  40. };
  41. /*
  42. * include common fpga code (for esd boards)
  43. */
  44. #include "../common/fpga.c"
  45. /* Prototypes */
  46. int cpci405_version(void);
  47. int gunzip(void *, int, unsigned char *, int *);
  48. int board_pre_init (void)
  49. {
  50. #ifndef CONFIG_CPCI405_VER2
  51. int index, len, i;
  52. int status;
  53. #endif
  54. #ifdef FPGA_DEBUG
  55. DECLARE_GLOBAL_DATA_PTR;
  56. /* set up serial port with default baudrate */
  57. (void) get_clocks ();
  58. gd->baudrate = CONFIG_BAUDRATE;
  59. serial_init ();
  60. console_init_f();
  61. #endif
  62. /*
  63. * First pull fpga-prg pin low, to disable fpga logic (on version 2 board)
  64. */
  65. out32(IBM405GP_GPIO0_ODR, 0x00000000); /* no open drain pins */
  66. out32(IBM405GP_GPIO0_TCR, CFG_FPGA_PRG); /* setup for output */
  67. out32(IBM405GP_GPIO0_OR, CFG_FPGA_PRG); /* set output pins to high */
  68. out32(IBM405GP_GPIO0_OR, 0); /* pull prg low */
  69. /*
  70. * Boot onboard FPGA
  71. */
  72. #ifndef CONFIG_CPCI405_VER2
  73. if (cpci405_version() == 1) {
  74. status = fpga_boot((unsigned char *)fpgadata, sizeof(fpgadata));
  75. if (status != 0) {
  76. /* booting FPGA failed */
  77. #ifndef FPGA_DEBUG
  78. DECLARE_GLOBAL_DATA_PTR;
  79. /* set up serial port with default baudrate */
  80. (void) get_clocks ();
  81. gd->baudrate = CONFIG_BAUDRATE;
  82. serial_init ();
  83. console_init_f();
  84. #endif
  85. printf("\nFPGA: Booting failed ");
  86. switch (status) {
  87. case ERROR_FPGA_PRG_INIT_LOW:
  88. printf("(Timeout: INIT not low after asserting PROGRAM*)\n ");
  89. break;
  90. case ERROR_FPGA_PRG_INIT_HIGH:
  91. printf("(Timeout: INIT not high after deasserting PROGRAM*)\n ");
  92. break;
  93. case ERROR_FPGA_PRG_DONE:
  94. printf("(Timeout: DONE not high after programming FPGA)\n ");
  95. break;
  96. }
  97. /* display infos on fpgaimage */
  98. index = 15;
  99. for (i=0; i<4; i++) {
  100. len = fpgadata[index];
  101. printf("FPGA: %s\n", &(fpgadata[index+1]));
  102. index += len+3;
  103. }
  104. putc ('\n');
  105. /* delayed reboot */
  106. for (i=20; i>0; i--) {
  107. printf("Rebooting in %2d seconds \r",i);
  108. for (index=0;index<1000;index++)
  109. udelay(1000);
  110. }
  111. putc ('\n');
  112. do_reset(NULL, 0, 0, NULL);
  113. }
  114. }
  115. #endif /* !CONFIG_CPCI405_VER2 */
  116. /*
  117. * IRQ 0-15 405GP internally generated; active high; level sensitive
  118. * IRQ 16 405GP internally generated; active low; level sensitive
  119. * IRQ 17-24 RESERVED
  120. * IRQ 25 (EXT IRQ 0) CAN0; active low; level sensitive
  121. * IRQ 26 (EXT IRQ 1) CAN1 (+FPGA on CPCI4052) ; active low; level sensitive
  122. * IRQ 27 (EXT IRQ 2) PCI SLOT 0; active low; level sensitive
  123. * IRQ 28 (EXT IRQ 3) PCI SLOT 1; active low; level sensitive
  124. * IRQ 29 (EXT IRQ 4) PCI SLOT 2; active low; level sensitive
  125. * IRQ 30 (EXT IRQ 5) PCI SLOT 3; active low; level sensitive
  126. * IRQ 31 (EXT IRQ 6) COMPACT FLASH; active high; level sensitive
  127. */
  128. mtdcr(uicsr, 0xFFFFFFFF); /* clear all ints */
  129. mtdcr(uicer, 0x00000000); /* disable all ints */
  130. mtdcr(uiccr, 0x00000000); /* set all to be non-critical*/
  131. if (cpci405_version() == 3) {
  132. mtdcr(uicpr, 0xFFFFFF99); /* set int polarities */
  133. } else {
  134. mtdcr(uicpr, 0xFFFFFF81); /* set int polarities */
  135. }
  136. mtdcr(uictr, 0x10000000); /* set int trigger levels */
  137. mtdcr(uicvcr, 0x00000001); /* set vect base=0,INT0 highest priority*/
  138. mtdcr(uicsr, 0xFFFFFFFF); /* clear all ints */
  139. return 0;
  140. }
  141. /* ------------------------------------------------------------------------- */
  142. int ctermm2(void)
  143. {
  144. #ifdef CONFIG_CPCI405_VER2
  145. return 0; /* no, board is cpci405 */
  146. #else
  147. if ((*(unsigned char *)0xf0000400 == 0x00) &&
  148. (*(unsigned char *)0xf0000401 == 0x01))
  149. return 0; /* no, board is cpci405 */
  150. else
  151. return -1; /* yes, board is cterm-m2 */
  152. #endif
  153. }
  154. int cpci405_host(void)
  155. {
  156. if (mfdcr(strap) & PSR_PCI_ARBIT_EN)
  157. return -1; /* yes, board is cpci405 host */
  158. else
  159. return 0; /* no, board is cpci405 adapter */
  160. }
  161. int cpci405_version(void)
  162. {
  163. unsigned long cntrl0Reg;
  164. unsigned long value;
  165. /*
  166. * Setup GPIO pins (CS2/GPIO11 and CS3/GPIO12 as GPIO)
  167. */
  168. cntrl0Reg = mfdcr(cntrl0);
  169. mtdcr(cntrl0, cntrl0Reg | 0x03000000);
  170. out32(IBM405GP_GPIO0_ODR, in32(IBM405GP_GPIO0_ODR) & ~0x00180000);
  171. out32(IBM405GP_GPIO0_TCR, in32(IBM405GP_GPIO0_TCR) & ~0x00180000);
  172. udelay(1000); /* wait some time before reading input */
  173. value = in32(IBM405GP_GPIO0_IR) & 0x00180000; /* get config bits */
  174. /*
  175. * Restore GPIO settings
  176. */
  177. mtdcr(cntrl0, cntrl0Reg);
  178. switch (value) {
  179. case 0x00180000:
  180. /* CS2==1 && CS3==1 -> version 1 */
  181. return 1;
  182. case 0x00080000:
  183. /* CS2==0 && CS3==1 -> version 2 */
  184. return 2;
  185. case 0x00100000:
  186. /* CS2==1 && CS3==0 -> version 3 */
  187. return 3;
  188. case 0x00000000:
  189. /* CS2==0 && CS3==0 -> version 4 */
  190. return 4;
  191. default:
  192. /* should not be reached! */
  193. return 2;
  194. }
  195. }
  196. int misc_init_f (void)
  197. {
  198. return 0; /* dummy implementation */
  199. }
  200. int misc_init_r (void)
  201. {
  202. DECLARE_GLOBAL_DATA_PTR;
  203. bd_t *bd = gd->bd;
  204. char * tmp; /* Temporary char pointer */
  205. #ifdef CONFIG_CPCI405_VER2
  206. unsigned char *dst;
  207. ulong len = sizeof(fpgadata);
  208. int status;
  209. int index;
  210. int i;
  211. unsigned long cntrl0Reg;
  212. /*
  213. * On CPCI-405 version 2 the environment is saved in eeprom!
  214. * FPGA can be gzip compressed (malloc) and booted this late.
  215. */
  216. if (cpci405_version() >= 2) {
  217. /*
  218. * Setup GPIO pins (CS6+CS7 as GPIO)
  219. */
  220. cntrl0Reg = mfdcr(cntrl0);
  221. mtdcr(cntrl0, cntrl0Reg | 0x00300000);
  222. dst = malloc(CFG_FPGA_MAX_SIZE);
  223. if (gunzip (dst, CFG_FPGA_MAX_SIZE, (uchar *)fpgadata, (int *)&len) != 0) {
  224. printf ("GUNZIP ERROR - must RESET board to recover\n");
  225. do_reset (NULL, 0, 0, NULL);
  226. }
  227. status = fpga_boot(dst, len);
  228. if (status != 0) {
  229. printf("\nFPGA: Booting failed ");
  230. switch (status) {
  231. case ERROR_FPGA_PRG_INIT_LOW:
  232. printf("(Timeout: INIT not low after asserting PROGRAM*)\n ");
  233. break;
  234. case ERROR_FPGA_PRG_INIT_HIGH:
  235. printf("(Timeout: INIT not high after deasserting PROGRAM*)\n ");
  236. break;
  237. case ERROR_FPGA_PRG_DONE:
  238. printf("(Timeout: DONE not high after programming FPGA)\n ");
  239. break;
  240. }
  241. /* display infos on fpgaimage */
  242. index = 15;
  243. for (i=0; i<4; i++) {
  244. len = dst[index];
  245. printf("FPGA: %s\n", &(dst[index+1]));
  246. index += len+3;
  247. }
  248. putc ('\n');
  249. /* delayed reboot */
  250. for (i=20; i>0; i--) {
  251. printf("Rebooting in %2d seconds \r",i);
  252. for (index=0;index<1000;index++)
  253. udelay(1000);
  254. }
  255. putc ('\n');
  256. do_reset(NULL, 0, 0, NULL);
  257. }
  258. /* restore gpio/cs settings */
  259. mtdcr(cntrl0, cntrl0Reg);
  260. puts("FPGA: ");
  261. /* display infos on fpgaimage */
  262. index = 15;
  263. for (i=0; i<4; i++) {
  264. len = dst[index];
  265. printf("%s ", &(dst[index+1]));
  266. index += len+3;
  267. }
  268. putc ('\n');
  269. free(dst);
  270. /*
  271. * Reset FPGA via FPGA_DATA pin
  272. */
  273. SET_FPGA(FPGA_PRG | FPGA_CLK);
  274. udelay(1000); /* wait 1ms */
  275. SET_FPGA(FPGA_PRG | FPGA_CLK | FPGA_DATA);
  276. udelay(1000); /* wait 1ms */
  277. if (cpci405_version() == 3) {
  278. volatile unsigned short *fpga_mode = (unsigned short *)CFG_FPGA_BASE_ADDR;
  279. volatile unsigned char *leds = (unsigned char *)CFG_LED_ADDR;
  280. /*
  281. * Enable outputs in fpga on version 3 board
  282. */
  283. *fpga_mode |= CFG_FPGA_MODE_ENABLE_OUTPUT;
  284. /*
  285. * Set outputs to 0
  286. */
  287. *leds = 0x00;
  288. /*
  289. * Reset external DUART
  290. */
  291. *fpga_mode |= CFG_FPGA_MODE_DUART_RESET;
  292. udelay(100);
  293. *fpga_mode &= ~(CFG_FPGA_MODE_DUART_RESET);
  294. }
  295. }
  296. else {
  297. puts("\n*** U-Boot Version does not match Board Version!\n");
  298. puts("*** CPCI-405 Version 1.x detected!\n");
  299. puts("*** Please use correct U-Boot version (CPCI405 instead of CPCI4052)!\n\n");
  300. }
  301. #else /* CONFIG_CPCI405_VER2 */
  302. /*
  303. * Generate last byte of ip-addr from code-plug @ 0xf0000400
  304. */
  305. if (ctermm2()) {
  306. char str[32];
  307. unsigned char ipbyte = *(unsigned char *)0xf0000400;
  308. /*
  309. * Only overwrite ip-addr with allowed values
  310. */
  311. if ((ipbyte != 0x00) && (ipbyte != 0xff)) {
  312. bd->bi_ip_addr = (bd->bi_ip_addr & 0xffffff00) | ipbyte;
  313. sprintf(str, "%ld.%ld.%ld.%ld",
  314. (bd->bi_ip_addr & 0xff000000) >> 24,
  315. (bd->bi_ip_addr & 0x00ff0000) >> 16,
  316. (bd->bi_ip_addr & 0x0000ff00) >> 8,
  317. (bd->bi_ip_addr & 0x000000ff));
  318. setenv("ipaddr", str);
  319. }
  320. }
  321. if (cpci405_version() >= 2) {
  322. puts("\n*** U-Boot Version does not match Board Version!\n");
  323. puts("*** CPCI-405 Board Version 2.x detected!\n");
  324. puts("*** Please use correct U-Boot version (CPCI4052 instead of CPCI405)!\n\n");
  325. }
  326. #endif /* CONFIG_CPCI405_VER2 */
  327. /*
  328. * Write ethernet addr in NVRAM for VxWorks
  329. */
  330. tmp = (char *)CFG_NVRAM_BASE_ADDR + CFG_NVRAM_VXWORKS_OFFS;
  331. memcpy( (char *)tmp, (char *)&bd->bi_enetaddr[0], 6 );
  332. return (0);
  333. }
  334. /*
  335. * Check Board Identity:
  336. */
  337. int checkboard (void)
  338. {
  339. #ifndef CONFIG_CPCI405_VER2
  340. int index;
  341. int len;
  342. #endif
  343. unsigned char str[64];
  344. int i = getenv_r ("serial#", str, sizeof(str));
  345. unsigned short ver;
  346. puts ("Board: ");
  347. if (i == -1) {
  348. puts ("### No HW ID - assuming CPCI405");
  349. } else {
  350. puts(str);
  351. }
  352. ver = cpci405_version();
  353. printf(" (Ver %d.x, ", ver);
  354. #if 0 /* test-only */
  355. if (ver >= 2) {
  356. volatile u16 *fpga_status = (u16 *)CFG_FPGA_BASE_ADDR + 1;
  357. if (*fpga_status & CFG_FPGA_STATUS_FLASH) {
  358. puts ("FLASH Bank B, ");
  359. } else {
  360. puts ("FLASH Bank A, ");
  361. }
  362. }
  363. #endif
  364. if (ctermm2()) {
  365. printf("CTERM-M2 - Id=0x%02x)", *(unsigned char *)0xf0000400);
  366. } else {
  367. if (cpci405_host()) {
  368. puts ("PCI Host Version)");
  369. } else {
  370. puts ("PCI Adapter Version)");
  371. }
  372. }
  373. #ifndef CONFIG_CPCI405_VER2
  374. puts ("\nFPGA: ");
  375. /* display infos on fpgaimage */
  376. index = 15;
  377. for (i=0; i<4; i++) {
  378. len = fpgadata[index];
  379. printf("%s ", &(fpgadata[index+1]));
  380. index += len+3;
  381. }
  382. #endif
  383. putc ('\n');
  384. return 0;
  385. }
  386. /* ------------------------------------------------------------------------- */
  387. long int initdram (int board_type)
  388. {
  389. unsigned long val;
  390. mtdcr(memcfga, mem_mb0cf);
  391. val = mfdcr(memcfgd);
  392. #if 0
  393. printf("\nmb0cf=%x\n", val); /* test-only */
  394. printf("strap=%x\n", mfdcr(strap)); /* test-only */
  395. #endif
  396. return (4*1024*1024 << ((val & 0x000e0000) >> 17));
  397. }
  398. /* ------------------------------------------------------------------------- */
  399. int testdram (void)
  400. {
  401. /* TODO: XXX XXX XXX */
  402. printf ("test: 16 MB - ok\n");
  403. return (0);
  404. }
  405. /* ------------------------------------------------------------------------- */
  406. #ifdef CONFIG_CPCI405_VER2
  407. #ifdef CONFIG_IDE_RESET
  408. void ide_set_reset(int on)
  409. {
  410. volatile unsigned short *fpga_mode = (unsigned short *)CFG_FPGA_BASE_ADDR;
  411. /*
  412. * Assert or deassert CompactFlash Reset Pin
  413. */
  414. if (on) { /* assert RESET */
  415. *fpga_mode &= ~(CFG_FPGA_MODE_CF_RESET);
  416. } else { /* release RESET */
  417. *fpga_mode |= CFG_FPGA_MODE_CF_RESET;
  418. }
  419. }
  420. #endif /* CONFIG_IDE_RESET */
  421. #endif /* CONFIG_CPCI405_VER2 */
  422. /* ------------------------------------------------------------------------- */